Skip to content

Commit

Permalink
Merge pull request #789 from orbitjs/strict-2
Browse files Browse the repository at this point in the history
Further improvements in typings
  • Loading branch information
dgeb committed Sep 28, 2020
2 parents 826b4f1 + 1b7d16d commit e510859
Show file tree
Hide file tree
Showing 118 changed files with 1,609 additions and 1,952 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -15,9 +15,11 @@ jobs:

include:
- stage: tests
name: "Linting"
name: "Lint"
script: yarn lint
- name: "Tests"
- name: "Compile"
script: yarn compile
- name: "Test"
script: yarn test

notifications:
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -16,6 +16,7 @@
"scripts": {
"postinstall": "lerna bootstrap",
"build": "lerna run build",
"compile": "lerna run build && lerna run compile",
"test": "lerna run build && lerna run --concurrency 1 test",
"lint": "lerna run lint",
"typedoc": "typedoc"
Expand Down
3 changes: 0 additions & 3 deletions packages/@orbit/coordinator/.eslintrc.js
Expand Up @@ -15,9 +15,6 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'prefer-const': ['off'],
'prefer-rest-params': ['off'],
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/coordinator/.npmignore
@@ -1,3 +1,4 @@
dist/full
docs
node_modules
test
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/coordinator/package.json
Expand Up @@ -20,6 +20,7 @@
"build": "rm -rf ./dist && yarn build:modules && yarn build:commonjs",
"build:modules": "tsc --project ./tsconfig.modules.json",
"build:commonjs": "tsc --project ./tsconfig.commonjs.json",
"compile": "tsc",
"clean": "git clean -x -f",
"lint": "eslint . --ext .ts",
"prepare": "yarn build",
Expand Down
Expand Up @@ -15,12 +15,12 @@ module('ConnectionStrategy', function (hooks) {
const t = new TransformBuilder();
const tA = buildTransform(
[t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
null,
undefined,
'a'
);
const tB = buildTransform(
[t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
null,
undefined,
'b'
);

Expand Down Expand Up @@ -167,8 +167,11 @@ module('ConnectionStrategy', function (hooks) {
target: 's2',
on: 'update',
action: 'push',
filter(transform: Transform) {
assert.strictEqual(this, strategy, 'context is the strategy');
filter(transform): boolean {
assert.ok(
this instanceof ConnectionStrategy,
'context is the strategy'
);
return transform === tB;
}
});
Expand Down
Expand Up @@ -8,22 +8,22 @@ module('LogTruncationStrategy', function (hooks) {
const t = new TransformBuilder();
const tA = buildTransform(
[t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
null,
undefined,
'a'
);
const tB = buildTransform(
[t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
null,
undefined,
'b'
);
const tC = buildTransform(
[t.addRecord({ type: 'planet', id: 'c', attributes: { name: 'c' } })],
null,
undefined,
'c'
);
const tD = buildTransform(
[t.addRecord({ type: 'planet', id: 'd', attributes: { name: 'd' } })],
null,
undefined,
'd'
);

Expand Down
Expand Up @@ -15,12 +15,12 @@ module('RequestStrategy', function (hooks) {
const t = new TransformBuilder();
const tA = buildTransform(
[t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
null,
undefined,
'a'
);
const tB = buildTransform(
[t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
null,
undefined,
'b'
);

Expand Down Expand Up @@ -214,8 +214,8 @@ module('RequestStrategy', function (hooks) {
target: 's2',
on: 'update',
action: 'push',
filter(transform: Transform): boolean {
assert.strictEqual(this, strategy, 'context is the strategy');
filter(transform): boolean {
assert.ok(this instanceof RequestStrategy, 'context is the strategy');
return transform === tB;
}
});
Expand Down Expand Up @@ -250,7 +250,7 @@ module('RequestStrategy', function (hooks) {
target: 's2',
on: 'update',
action: 'push',
blocking(transform: Transform): boolean {
blocking(transform): boolean {
assert.ok(
this instanceof RequestStrategy,
'it is bound to the strategy'
Expand Down Expand Up @@ -297,30 +297,34 @@ module('RequestStrategy', function (hooks) {
strategy = new RequestStrategy({
source: 's1',
on: 'updateFail',
async action(transform: Transform, e: Error): Promise<void> {
async action(transform, e): Promise<void> {
assert.ok(
this instanceof RequestStrategy,
'`action` is bound to the strategy'
);
assert.strictEqual(transform, tA, 'transform is passed to `action`');
assert.equal(e.message, ':(', 'error is passed to `action`');
assert.equal((e as Error).message, ':(', 'error is passed to `action`');
},
blocking(transform: Transform, e: Error): boolean {
blocking(transform, e): boolean {
assert.ok(
this instanceof RequestStrategy,
'`blocking` is bound to the strategy'
);
assert.strictEqual(transform, tA, 'transform is passed to `blocking`');
assert.equal(e.message, ':(', 'error is passed to `blocking`');
assert.equal(
(e as Error).message,
':(',
'error is passed to `blocking`'
);
return false;
},
filter(transform: Transform, e: Error): boolean {
filter(transform, e): boolean {
assert.ok(
this instanceof RequestStrategy,
'`filter` is bound to the strategy'
);
assert.strictEqual(transform, tA, 'transform is passed to `filter`');
assert.equal(e.message, ':(', 'error is passed to `filter`');
assert.equal((e as Error).message, ':(', 'error is passed to `filter`');
return true;
}
});
Expand Down
Expand Up @@ -15,12 +15,12 @@ module('SyncStrategy', function (hooks) {
const t = new TransformBuilder();
const tA = buildTransform(
[t.addRecord({ type: 'planet', id: 'a', attributes: { name: 'a' } })],
null,
undefined,
'a'
);
const tB = buildTransform(
[t.addRecord({ type: 'planet', id: 'b', attributes: { name: 'b' } })],
null,
undefined,
'b'
);

Expand Down Expand Up @@ -137,7 +137,7 @@ module('SyncStrategy', function (hooks) {
source: 's1',
target: 's2',
filter(transform: Transform): boolean {
assert.strictEqual(this, strategy, 'context is the strategy');
assert.ok(this instanceof SyncStrategy, 'context is the strategy');
return transform === tB;
}
});
Expand Down Expand Up @@ -174,7 +174,7 @@ module('SyncStrategy', function (hooks) {
tA,
'argument to catch is expected Transform'
);
assert.strictEqual(this, strategy, 'context is the strategy');
assert.ok(this instanceof SyncStrategy, 'context is the strategy');
}
});

Expand Down Expand Up @@ -213,7 +213,7 @@ module('SyncStrategy', function (hooks) {
tA,
'argument to catch is expected Transform'
);
assert.strictEqual(this, strategy, 'context is the strategy');
assert.ok(this instanceof SyncStrategy, 'context is the strategy');
throw e;
}
});
Expand Down
5 changes: 0 additions & 5 deletions packages/@orbit/coordinator/test/strategy-test.ts
Expand Up @@ -21,11 +21,6 @@ module('Strategy', function (hooks) {
coordinator = new Coordinator({ sources: [s1, s2, s3] });
});

hooks.afterEach(function () {
coordinator = null;
s1 = s2 = s3 = null;
});

test('can be instantiated with a name', function (assert) {
class CustomStrategy extends Strategy {}

Expand Down
3 changes: 3 additions & 0 deletions packages/@orbit/coordinator/tsconfig.json
@@ -1,5 +1,8 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"outDir": "./dist/full"
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
Expand Down
3 changes: 0 additions & 3 deletions packages/@orbit/core/.eslintrc.js
Expand Up @@ -15,9 +15,6 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'prefer-const': ['off'],
'prefer-rest-params': ['off'],
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/core/.npmignore
@@ -1,3 +1,4 @@
dist/full
docs
node_modules
test
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/core/package.json
Expand Up @@ -20,6 +20,7 @@
"build": "rm -rf ./dist && yarn build:modules && yarn build:commonjs",
"build:modules": "tsc --project ./tsconfig.modules.json",
"build:commonjs": "tsc --project ./tsconfig.commonjs.json",
"compile": "tsc",
"clean": "git clean -x -f",
"lint": "eslint . --ext .ts",
"prepare": "yarn build",
Expand Down
3 changes: 3 additions & 0 deletions packages/@orbit/core/tsconfig.json
@@ -1,5 +1,8 @@
{
"extends": "../../../tsconfig",
"compilerOptions": {
"outDir": "./dist/full"
},
"include": [
"src/**/*.ts",
"test/**/*.ts"
Expand Down
3 changes: 0 additions & 3 deletions packages/@orbit/data/.eslintrc.js
Expand Up @@ -15,9 +15,6 @@ module.exports = {
},
rules: {
'@typescript-eslint/no-empty-function': ['off'],
'@typescript-eslint/no-use-before-define': ['off'],
'@typescript-eslint/explicit-function-return-type': ['off'],
'@typescript-eslint/explicit-member-accessibility': ['off'],
'@typescript-eslint/no-explicit-any': ['off'],
'prefer-const': ['off'],
'prefer-rest-params': ['off'],
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/data/.npmignore
@@ -1,3 +1,4 @@
dist/full
docs
node_modules
test
Expand Down
1 change: 1 addition & 0 deletions packages/@orbit/data/package.json
Expand Up @@ -20,6 +20,7 @@
"build": "rm -rf ./dist && yarn build:modules && yarn build:commonjs",
"build:modules": "tsc --project ./tsconfig.modules.json",
"build:commonjs": "tsc --project ./tsconfig.commonjs.json",
"compile": "tsc",
"clean": "git clean -x -f",
"lint": "eslint . --ext .ts",
"prepare": "yarn build",
Expand Down
4 changes: 2 additions & 2 deletions packages/@orbit/data/src/key-map.ts
@@ -1,5 +1,5 @@
import { deepGet, deepSet, firstResult, Dict } from '@orbit/utils';
import { Record } from './record';
import { Record, UninitializedRecord } from './record';

/**
* Maintains a map between records' ids and keys.
Expand Down Expand Up @@ -37,7 +37,7 @@ export class KeyMap {
/**
* Store the id and key values of a record in this key map.
*/
pushRecord(record: Record): void {
pushRecord(record: Record | UninitializedRecord): void {
const { type, id, keys } = record;

if (!keys || !id) {
Expand Down
12 changes: 6 additions & 6 deletions packages/@orbit/data/src/record.ts
@@ -1,4 +1,4 @@
import { Dict, isObject, isNone, clone, merge } from '@orbit/utils';
import { Dict, isNone, clone } from '@orbit/utils';

export interface LinkObject {
href: string;
Expand Down Expand Up @@ -53,13 +53,13 @@ export function cloneRecordIdentity(identity: RecordIdentity): RecordIdentity {
}

export function equalRecordIdentities(
record1: RecordIdentity,
record2: RecordIdentity
record1?: RecordIdentity | null,
record2?: RecordIdentity | null
): boolean {
return (
(isNone(record1) && isNone(record2)) ||
(isObject(record1) &&
isObject(record2) &&
(!!record1 &&
!!record2 &&
record1.type === record2.type &&
record1.id === record2.id)
);
Expand Down Expand Up @@ -153,7 +153,7 @@ function mergeRecordSection(
if (replacementDepth === 0) {
record[section] = clone(update[section]);
} else if (replacementDepth === 1) {
record[section] = merge({}, current[section], update[section]);
record[section] = Object.assign({}, current[section], update[section]);
} else {
record[section] = {};
for (let name of Object.keys(current[section])) {
Expand Down
26 changes: 13 additions & 13 deletions packages/@orbit/data/src/source.ts
Expand Up @@ -187,16 +187,6 @@ export abstract class Source implements Evented, Performer {
this._activated = undefined;
}

protected async _activate(): Promise<void> {
await this._transformLog.reified;
await this._syncQueue.activate();
await this._requestQueue.activate();
}

/////////////////////////////////////////////////////////////////////////////
// Private methods
/////////////////////////////////////////////////////////////////////////////

/**
* Notifies listeners that this source has been transformed by emitting the
* `transform` event.
Expand All @@ -205,7 +195,7 @@ export abstract class Source implements Evented, Performer {
*
* Also, adds an entry to the Source's `transformLog` for each transform.
*/
protected async transformed(transforms: Transform[]): Promise<Transform[]> {
async transformed(transforms: Transform[]): Promise<Transform[]> {
await this.activated;
return transforms
.reduce((chain, transform) => {
Expand All @@ -222,11 +212,21 @@ export abstract class Source implements Evented, Performer {
.then(() => transforms);
}

private _enqueueRequest(type: string, data: any): Promise<unknown> {
/////////////////////////////////////////////////////////////////////////////
// Protected methods
/////////////////////////////////////////////////////////////////////////////

protected async _activate(): Promise<void> {
await this._transformLog.reified;
await this._syncQueue.activate();
await this._requestQueue.activate();
}

protected _enqueueRequest(type: string, data: unknown): Promise<unknown> {
return this._requestQueue.push({ type, data });
}

private _enqueueSync(type: string, data: any): Promise<unknown> {
protected _enqueueSync(type: string, data: unknown): Promise<unknown> {
return this._syncQueue.push({ type, data });
}
}

0 comments on commit e510859

Please sign in to comment.