Skip to content

Commit

Permalink
Separate internal APIs from public ones (hazelcast#568)
Browse files Browse the repository at this point in the history
Includes the following:
* Marks internal modules and class members with @internal tag which is supported by both tsc and typedoc
* Fixes typedoc flags, so that it now ignores internal stuff
* Excludes internal modules and members from tsc output
* Excludes source maps from tsc output
* Moves typings for long and bluebird into non-dev dependencies, as TS users need them (see hazelcast#537)
* Adds test for declarations produced by tsc
* Also includes some code improvements, like reformatting, interface extraction, etc.
  • Loading branch information
puzpuzpuz authored Aug 14, 2020
1 parent 441d841 commit c7a804c
Show file tree
Hide file tree
Showing 382 changed files with 1,416 additions and 509 deletions.
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
.vscode/
.nyc_output/
benchmark/
code_samples/
Expand All @@ -7,6 +8,8 @@ docs/
scripts/
src/
test/
tsconfig.json
typedoc.json
.editorconfig
.eslintignore
.eslintrc.js
Expand All @@ -15,6 +18,5 @@ test/
DOCUMENTATION.md
download-remote-controller.js
*.iml
.editorconfig
*.jar
*.log
6 changes: 3 additions & 3 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2694,7 +2694,7 @@ An example configuration is shown below.
```javascript
const readFile = util.promisify(fs.readFile);

class SSLFactory {
class SSLOptionsFactory {
async init(properties) {
const promises = [];
this.keepOrder = properties.userDefinedProperty1;
Expand Down Expand Up @@ -2732,7 +2732,7 @@ const cfg = {
network: {
ssl: {
enabled: true,
sslOptionsFactory: new SSLFactory(),
sslOptionsFactory: new SSLOptionsFactory(),
sslOptionsFactoryProperties: {
caPath: 'ca.pem',
keyPath: 'key.pem',
Expand All @@ -2744,7 +2744,7 @@ const cfg = {
};
```

The client calls the method `init` with the properties section defined in the configuration. Then the client calls the method `getSSLOptions` of `SSLFactory` to create the `options` object.
The client calls the `init()` method with the `properties` configuration option. Then the client calls the `getSSLOptions()` method of `SSLOptionsFactory` to create the `options` object.

## 8.2. Credentials

Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"version": "4.0.0",
"description": "Hazelcast - open source In-Memory Data Grid - client for Node.js",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"dependencies": {
"bluebird": "3.7.2",
"long": "4.0.0"
"@types/bluebird": "3.5.32",
"long": "4.0.0",
"@types/long": "4.0.1"
},
"devDependencies": {
"@types/bluebird": "^3.5.32",
"@types/long": "^4.0.1",
"@types/node": "^8.10.60",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
Expand All @@ -24,6 +25,7 @@
"rimraf": "^3.0.2",
"sinon": "^9.0.2",
"thrift": "^0.12.0",
"typedoc": "^0.18.0",
"typescript": "^3.9.5",
"winston": "^3.2.1"
},
Expand All @@ -35,10 +37,11 @@
"compile": "tsc",
"pretest": "node download-remote-controller.js",
"test": "mocha --recursive",
"validate-user-code": "tsc --build test/user_code/tsconfig.json",
"precoverage": "node download-remote-controller.js",
"coverage": "rimraf coverage && nyc node_modules/mocha/bin/_mocha -- --recursive --reporter-options mochaFile=report.xml --reporter mocha-junit-reporter",
"pregenerate-docs": "rimraf docs",
"generate-docs": "typedoc --out docs/ --exclude **/codec/**/* src/ --excludeExternals --ignoreCompilerErrors --excludePrivate",
"generate-docs": "typedoc --options typedoc.json",
"lint": "eslint --ext .ts ."
},
"repository": {
Expand All @@ -57,6 +60,5 @@
"bugs": {
"url": "https://github.com/hazelcast/hazelcast-nodejs-client/issues"
},
"homepage": "https://github.com/hazelcast/hazelcast-nodejs-client#readme",
"typings": "./lib/index"
"homepage": "https://github.com/hazelcast/hazelcast-nodejs-client#readme"
}
27 changes: 25 additions & 2 deletions src/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,30 @@ import {CLUSTER_DATA_FACTORY_ID, CLUSTER_DATA_ADDRESS_CLASS_ID} from './ClusterD
import {DataInput, DataOutput} from './serialization/Data';
import {IdentifiedDataSerializable} from './serialization/Serializable';

export class Address implements IdentifiedDataSerializable {
/**
* Represents a network address (e.g. of the client or a cluster member).
*/
export interface Address {

/**
* Host name or IP address.
*/
host: string;

/**
* Port number.
*/
port: number;

/**
* Returns string representation of the address.
*/
toString(): string;

}

/** @internal */
export class AddressImpl implements Address, IdentifiedDataSerializable {

factoryId = CLUSTER_DATA_FACTORY_ID;
classId = CLUSTER_DATA_ADDRESS_CLASS_ID;
Expand Down Expand Up @@ -49,7 +72,7 @@ export class Address implements IdentifiedDataSerializable {
output.writeUTF(this.host);
}

equals(other: Address): boolean {
equals(other: AddressImpl): boolean {
if (other === this) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/BitsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

/** @internal */
export class BitsUtil {
static BYTE_SIZE_IN_BYTES = 1;
static BOOLEAN_SIZE_IN_BYTES = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/BuildInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

const clientVersion = require('../package.json').version;

/** @internal */
export class BuildInfo {

public static readonly UNKNOWN_VERSION_ID = -1;
Expand Down
4 changes: 4 additions & 0 deletions src/ClientInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import {Address} from './Address';
import {UUID} from './core/UUID';

/**
* Local information of the client.
*/
export class ClientInfo {

/**
Expand All @@ -43,4 +46,5 @@ export class ClientInfo {
* Set of all labels of this client.
*/
labels: Set<string>;

}
10 changes: 10 additions & 0 deletions src/ClientMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

import {BitsUtil} from './BitsUtil';
import {ClientConnection} from './network/ClientConnection';
import {FixSizedTypesCodec} from './codec/builtin/FixSizedTypesCodec';

const MESSAGE_TYPE_OFFSET = 0;
const CORRELATION_ID_OFFSET = MESSAGE_TYPE_OFFSET + BitsUtil.INT_SIZE_IN_BYTES;
/** @internal */
export const RESPONSE_BACKUP_ACKS_OFFSET = CORRELATION_ID_OFFSET + BitsUtil.LONG_SIZE_IN_BYTES;
/** @internal */
export const PARTITION_ID_OFFSET = CORRELATION_ID_OFFSET + BitsUtil.LONG_SIZE_IN_BYTES;
const FRAGMENTATION_ID_OFFSET = 0;

/** @internal */
export const DEFAULT_FLAGS = 0;
const BEGIN_FRAGMENT_FLAG = 1 << 15;
const END_FRAGMENT_FLAG = 1 << 14;
Expand All @@ -34,8 +38,10 @@ const END_DATA_STRUCTURE_FLAG = 1 << 11;
const IS_NULL_FLAG = 1 << 10;
const IS_EVENT_FLAG = 1 << 9;

/** @internal */
export const SIZE_OF_FRAME_LENGTH_AND_FLAGS = BitsUtil.INT_SIZE_IN_BYTES + BitsUtil.SHORT_SIZE_IN_BYTES;

/** @internal */
export class Frame {
content: Buffer;
flags: number;
Expand Down Expand Up @@ -105,10 +111,14 @@ export class Frame {
}
}

/** @internal */
export const NULL_FRAME = new Frame(Buffer.allocUnsafe(0), IS_NULL_FLAG);
/** @internal */
export const BEGIN_FRAME = new Frame(Buffer.allocUnsafe(0), BEGIN_DATA_STRUCTURE_FLAG);
/** @internal */
export const END_FRAME = new Frame(Buffer.allocUnsafe(0), END_DATA_STRUCTURE_FLAG);

/** @internal */
export class ClientMessage {
startFrame: Frame;
endFrame: Frame;
Expand Down
8 changes: 6 additions & 2 deletions src/ClusterDataFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

import {IdentifiedDataSerializable} from './serialization/Serializable';
import {Address} from './Address';
import {AddressImpl} from './Address';

/** @internal */
export const CLUSTER_DATA_FACTORY_ID = 0;
/** @internal */
export const CLUSTER_DATA_ADDRESS_CLASS_ID = 1;

/** @internal */
export function clusterDataFactory(classId: number): IdentifiedDataSerializable {
if (classId === CLUSTER_DATA_ADDRESS_CLASS_ID) {
return new Address();
return new AddressImpl();
}
return null;
}
2 changes: 2 additions & 0 deletions src/DataStoreHashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

import {Data} from './serialization/Data';

/** @internal */
export class DataKeyedHashMap<T> {

size: number;
Expand Down
2 changes: 2 additions & 0 deletions src/DistributedObjectInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @ignore *//** */

/** @internal */
export class DistributedObjectInfo {
serviceName: string;
name: string;
Expand Down
Loading

0 comments on commit c7a804c

Please sign in to comment.