From 7d0c9a2d00f3211830c9dacdd4555e89c20af7cc Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Sun, 27 Sep 2020 12:59:12 -0400 Subject: [PATCH 1/3] Introduce `compile` task that runs tsc for everything Only `src` is compiled in the `build` task. By compiling `test` as well, we can let `tsc` catch any errors in tests. --- .travis.yml | 6 ++++-- package.json | 1 + packages/@orbit/coordinator/.npmignore | 1 + packages/@orbit/coordinator/package.json | 1 + packages/@orbit/coordinator/tsconfig.json | 3 +++ packages/@orbit/core/.npmignore | 1 + packages/@orbit/core/package.json | 1 + packages/@orbit/core/tsconfig.json | 3 +++ packages/@orbit/data/.npmignore | 1 + packages/@orbit/data/package.json | 1 + packages/@orbit/data/tsconfig.json | 3 +++ packages/@orbit/identity-map/.npmignore | 1 + packages/@orbit/identity-map/package.json | 1 + packages/@orbit/identity-map/tsconfig.json | 3 +++ packages/@orbit/immutable/.npmignore | 1 + packages/@orbit/immutable/package.json | 1 + packages/@orbit/immutable/tsconfig.json | 3 +++ packages/@orbit/indexeddb-bucket/.npmignore | 1 + packages/@orbit/indexeddb-bucket/package.json | 1 + packages/@orbit/indexeddb-bucket/tsconfig.json | 3 +++ packages/@orbit/indexeddb/.npmignore | 1 + packages/@orbit/indexeddb/package.json | 1 + packages/@orbit/indexeddb/tsconfig.json | 3 +++ packages/@orbit/integration-tests/.npmignore | 1 + packages/@orbit/integration-tests/package.json | 1 + packages/@orbit/integration-tests/tsconfig.json | 3 +++ packages/@orbit/jsonapi/.npmignore | 1 + packages/@orbit/jsonapi/package.json | 1 + packages/@orbit/jsonapi/tsconfig.json | 3 +++ packages/@orbit/local-storage-bucket/.npmignore | 1 + packages/@orbit/local-storage-bucket/package.json | 1 + packages/@orbit/local-storage-bucket/tsconfig.json | 3 +++ packages/@orbit/local-storage/.npmignore | 1 + packages/@orbit/local-storage/package.json | 1 + packages/@orbit/local-storage/tsconfig.json | 3 +++ packages/@orbit/memory/.npmignore | 1 + packages/@orbit/memory/package.json | 1 + packages/@orbit/memory/tsconfig.json | 3 +++ packages/@orbit/record-cache/.npmignore | 1 + packages/@orbit/record-cache/package.json | 1 + packages/@orbit/record-cache/tsconfig.json | 3 +++ packages/@orbit/serializers/.npmignore | 1 + packages/@orbit/serializers/package.json | 1 + packages/@orbit/serializers/tsconfig.json | 3 +++ packages/@orbit/utils/.npmignore | 1 + packages/@orbit/utils/package.json | 1 + packages/@orbit/utils/tsconfig.json | 3 +++ 47 files changed, 80 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 570d2cb70..cf660fe5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/package.json b/package.json index 8cace65a3..eeea9d22a 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/packages/@orbit/coordinator/.npmignore b/packages/@orbit/coordinator/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/coordinator/.npmignore +++ b/packages/@orbit/coordinator/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/coordinator/package.json b/packages/@orbit/coordinator/package.json index 82a809453..34f004b1f 100644 --- a/packages/@orbit/coordinator/package.json +++ b/packages/@orbit/coordinator/package.json @@ -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", diff --git a/packages/@orbit/coordinator/tsconfig.json b/packages/@orbit/coordinator/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/coordinator/tsconfig.json +++ b/packages/@orbit/coordinator/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/core/.npmignore b/packages/@orbit/core/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/core/.npmignore +++ b/packages/@orbit/core/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/core/package.json b/packages/@orbit/core/package.json index 005b972fa..540aff36e 100644 --- a/packages/@orbit/core/package.json +++ b/packages/@orbit/core/package.json @@ -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", diff --git a/packages/@orbit/core/tsconfig.json b/packages/@orbit/core/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/core/tsconfig.json +++ b/packages/@orbit/core/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/data/.npmignore b/packages/@orbit/data/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/data/.npmignore +++ b/packages/@orbit/data/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/data/package.json b/packages/@orbit/data/package.json index 051147f41..990cc0168 100644 --- a/packages/@orbit/data/package.json +++ b/packages/@orbit/data/package.json @@ -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", diff --git a/packages/@orbit/data/tsconfig.json b/packages/@orbit/data/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/data/tsconfig.json +++ b/packages/@orbit/data/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/identity-map/.npmignore b/packages/@orbit/identity-map/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/identity-map/.npmignore +++ b/packages/@orbit/identity-map/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/identity-map/package.json b/packages/@orbit/identity-map/package.json index a972db82a..ee98b3da7 100644 --- a/packages/@orbit/identity-map/package.json +++ b/packages/@orbit/identity-map/package.json @@ -21,6 +21,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", diff --git a/packages/@orbit/identity-map/tsconfig.json b/packages/@orbit/identity-map/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/identity-map/tsconfig.json +++ b/packages/@orbit/identity-map/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/immutable/.npmignore b/packages/@orbit/immutable/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/immutable/.npmignore +++ b/packages/@orbit/immutable/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/immutable/package.json b/packages/@orbit/immutable/package.json index 6f2b3ab68..649b85489 100644 --- a/packages/@orbit/immutable/package.json +++ b/packages/@orbit/immutable/package.json @@ -19,6 +19,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", diff --git a/packages/@orbit/immutable/tsconfig.json b/packages/@orbit/immutable/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/immutable/tsconfig.json +++ b/packages/@orbit/immutable/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/indexeddb-bucket/.npmignore b/packages/@orbit/indexeddb-bucket/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/indexeddb-bucket/.npmignore +++ b/packages/@orbit/indexeddb-bucket/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/indexeddb-bucket/package.json b/packages/@orbit/indexeddb-bucket/package.json index 385864f33..a4754dd42 100644 --- a/packages/@orbit/indexeddb-bucket/package.json +++ b/packages/@orbit/indexeddb-bucket/package.json @@ -19,6 +19,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", diff --git a/packages/@orbit/indexeddb-bucket/tsconfig.json b/packages/@orbit/indexeddb-bucket/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/indexeddb-bucket/tsconfig.json +++ b/packages/@orbit/indexeddb-bucket/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/indexeddb/.npmignore b/packages/@orbit/indexeddb/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/indexeddb/.npmignore +++ b/packages/@orbit/indexeddb/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/indexeddb/package.json b/packages/@orbit/indexeddb/package.json index 5e0f50aec..02c828608 100644 --- a/packages/@orbit/indexeddb/package.json +++ b/packages/@orbit/indexeddb/package.json @@ -19,6 +19,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", diff --git a/packages/@orbit/indexeddb/tsconfig.json b/packages/@orbit/indexeddb/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/indexeddb/tsconfig.json +++ b/packages/@orbit/indexeddb/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/integration-tests/.npmignore b/packages/@orbit/integration-tests/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/integration-tests/.npmignore +++ b/packages/@orbit/integration-tests/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/integration-tests/package.json b/packages/@orbit/integration-tests/package.json index 6013779f3..f04e94fc7 100644 --- a/packages/@orbit/integration-tests/package.json +++ b/packages/@orbit/integration-tests/package.json @@ -9,6 +9,7 @@ "repository": "https://github.com/orbitjs/orbit", "license": "MIT", "scripts": { + "compile": "tsc", "clean": "git clean -x -f", "lint": "eslint . --ext .ts", "start": "node ../build dev && snowpack dev", diff --git a/packages/@orbit/integration-tests/tsconfig.json b/packages/@orbit/integration-tests/tsconfig.json index 34ff71742..4bedffb9b 100644 --- a/packages/@orbit/integration-tests/tsconfig.json +++ b/packages/@orbit/integration-tests/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "test/**/*.ts" ] diff --git a/packages/@orbit/jsonapi/.npmignore b/packages/@orbit/jsonapi/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/jsonapi/.npmignore +++ b/packages/@orbit/jsonapi/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/jsonapi/package.json b/packages/@orbit/jsonapi/package.json index 485595970..ed6c528a4 100644 --- a/packages/@orbit/jsonapi/package.json +++ b/packages/@orbit/jsonapi/package.json @@ -22,6 +22,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", diff --git a/packages/@orbit/jsonapi/tsconfig.json b/packages/@orbit/jsonapi/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/jsonapi/tsconfig.json +++ b/packages/@orbit/jsonapi/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/local-storage-bucket/.npmignore b/packages/@orbit/local-storage-bucket/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/local-storage-bucket/.npmignore +++ b/packages/@orbit/local-storage-bucket/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/local-storage-bucket/package.json b/packages/@orbit/local-storage-bucket/package.json index 124c8388f..1234b865f 100644 --- a/packages/@orbit/local-storage-bucket/package.json +++ b/packages/@orbit/local-storage-bucket/package.json @@ -19,6 +19,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", diff --git a/packages/@orbit/local-storage-bucket/tsconfig.json b/packages/@orbit/local-storage-bucket/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/local-storage-bucket/tsconfig.json +++ b/packages/@orbit/local-storage-bucket/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/local-storage/.npmignore b/packages/@orbit/local-storage/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/local-storage/.npmignore +++ b/packages/@orbit/local-storage/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/local-storage/package.json b/packages/@orbit/local-storage/package.json index cd0b04806..adb51de10 100644 --- a/packages/@orbit/local-storage/package.json +++ b/packages/@orbit/local-storage/package.json @@ -19,6 +19,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", diff --git a/packages/@orbit/local-storage/tsconfig.json b/packages/@orbit/local-storage/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/local-storage/tsconfig.json +++ b/packages/@orbit/local-storage/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/memory/.npmignore b/packages/@orbit/memory/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/memory/.npmignore +++ b/packages/@orbit/memory/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/memory/package.json b/packages/@orbit/memory/package.json index 62565ec0f..bb6a3f8dd 100644 --- a/packages/@orbit/memory/package.json +++ b/packages/@orbit/memory/package.json @@ -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", diff --git a/packages/@orbit/memory/tsconfig.json b/packages/@orbit/memory/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/memory/tsconfig.json +++ b/packages/@orbit/memory/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/record-cache/.npmignore b/packages/@orbit/record-cache/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/record-cache/.npmignore +++ b/packages/@orbit/record-cache/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/record-cache/package.json b/packages/@orbit/record-cache/package.json index 1d4d67bf0..d431045e1 100644 --- a/packages/@orbit/record-cache/package.json +++ b/packages/@orbit/record-cache/package.json @@ -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", diff --git a/packages/@orbit/record-cache/tsconfig.json b/packages/@orbit/record-cache/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/record-cache/tsconfig.json +++ b/packages/@orbit/record-cache/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/serializers/.npmignore b/packages/@orbit/serializers/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/serializers/.npmignore +++ b/packages/@orbit/serializers/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/serializers/package.json b/packages/@orbit/serializers/package.json index 959caa36a..514211ec9 100644 --- a/packages/@orbit/serializers/package.json +++ b/packages/@orbit/serializers/package.json @@ -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", diff --git a/packages/@orbit/serializers/tsconfig.json b/packages/@orbit/serializers/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/serializers/tsconfig.json +++ b/packages/@orbit/serializers/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" diff --git a/packages/@orbit/utils/.npmignore b/packages/@orbit/utils/.npmignore index 7649bcdf8..4ecb7cefc 100644 --- a/packages/@orbit/utils/.npmignore +++ b/packages/@orbit/utils/.npmignore @@ -1,3 +1,4 @@ +dist/full docs node_modules test diff --git a/packages/@orbit/utils/package.json b/packages/@orbit/utils/package.json index c6476749b..92568083d 100644 --- a/packages/@orbit/utils/package.json +++ b/packages/@orbit/utils/package.json @@ -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", diff --git a/packages/@orbit/utils/tsconfig.json b/packages/@orbit/utils/tsconfig.json index 0aa1c16fc..bd603fcf7 100644 --- a/packages/@orbit/utils/tsconfig.json +++ b/packages/@orbit/utils/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "../../../tsconfig", + "compilerOptions": { + "outDir": "./dist/full" + }, "include": [ "src/**/*.ts", "test/**/*.ts" From c871b92b3959fe5572fb4fe72776cf417100c002 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Sun, 27 Sep 2020 13:14:25 -0400 Subject: [PATCH 2/3] Streamline eslint settings --- packages/@orbit/coordinator/.eslintrc.js | 3 --- packages/@orbit/core/.eslintrc.js | 3 --- packages/@orbit/data/.eslintrc.js | 3 --- packages/@orbit/identity-map/.eslintrc.js | 3 --- packages/@orbit/immutable/.eslintrc.js | 3 --- packages/@orbit/indexeddb-bucket/.eslintrc.js | 3 --- packages/@orbit/indexeddb/.eslintrc.js | 3 --- packages/@orbit/integration-tests/.eslintrc.js | 3 --- packages/@orbit/jsonapi/.eslintrc.js | 3 --- packages/@orbit/local-storage-bucket/.eslintrc.js | 3 --- packages/@orbit/local-storage/.eslintrc.js | 3 --- packages/@orbit/memory/.eslintrc.js | 3 --- packages/@orbit/record-cache/.eslintrc.js | 3 --- packages/@orbit/serializers/.eslintrc.js | 3 --- packages/@orbit/utils/.eslintrc.js | 15 +++++++-------- 15 files changed, 7 insertions(+), 50 deletions(-) diff --git a/packages/@orbit/coordinator/.eslintrc.js b/packages/@orbit/coordinator/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/coordinator/.eslintrc.js +++ b/packages/@orbit/coordinator/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/core/.eslintrc.js b/packages/@orbit/core/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/core/.eslintrc.js +++ b/packages/@orbit/core/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/data/.eslintrc.js b/packages/@orbit/data/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/data/.eslintrc.js +++ b/packages/@orbit/data/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/identity-map/.eslintrc.js b/packages/@orbit/identity-map/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/identity-map/.eslintrc.js +++ b/packages/@orbit/identity-map/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/immutable/.eslintrc.js b/packages/@orbit/immutable/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/immutable/.eslintrc.js +++ b/packages/@orbit/immutable/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/indexeddb-bucket/.eslintrc.js b/packages/@orbit/indexeddb-bucket/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/indexeddb-bucket/.eslintrc.js +++ b/packages/@orbit/indexeddb-bucket/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/indexeddb/.eslintrc.js b/packages/@orbit/indexeddb/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/indexeddb/.eslintrc.js +++ b/packages/@orbit/indexeddb/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/integration-tests/.eslintrc.js b/packages/@orbit/integration-tests/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/integration-tests/.eslintrc.js +++ b/packages/@orbit/integration-tests/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/jsonapi/.eslintrc.js b/packages/@orbit/jsonapi/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/jsonapi/.eslintrc.js +++ b/packages/@orbit/jsonapi/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/local-storage-bucket/.eslintrc.js b/packages/@orbit/local-storage-bucket/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/local-storage-bucket/.eslintrc.js +++ b/packages/@orbit/local-storage-bucket/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/local-storage/.eslintrc.js b/packages/@orbit/local-storage/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/local-storage/.eslintrc.js +++ b/packages/@orbit/local-storage/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/memory/.eslintrc.js b/packages/@orbit/memory/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/memory/.eslintrc.js +++ b/packages/@orbit/memory/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/record-cache/.eslintrc.js b/packages/@orbit/record-cache/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/record-cache/.eslintrc.js +++ b/packages/@orbit/record-cache/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/serializers/.eslintrc.js b/packages/@orbit/serializers/.eslintrc.js index 8439cca7a..bcf664de5 100644 --- a/packages/@orbit/serializers/.eslintrc.js +++ b/packages/@orbit/serializers/.eslintrc.js @@ -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'], diff --git a/packages/@orbit/utils/.eslintrc.js b/packages/@orbit/utils/.eslintrc.js index 34c16d3a7..bcf664de5 100644 --- a/packages/@orbit/utils/.eslintrc.js +++ b/packages/@orbit/utils/.eslintrc.js @@ -15,18 +15,17 @@ 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'], 'prefer-spread': ['off'] }, - overrides: [{ - files: ['test/**/*.ts'], - rules: { - '@typescript-eslint/no-unused-vars': ['off'] + overrides: [ + { + files: ['test/**/*.ts'], + rules: { + '@typescript-eslint/no-unused-vars': ['off'] + } } - }] + ] }; From 1b7d16d87957a4b252a8f4479ecfea61b1587f50 Mon Sep 17 00:00:00 2001 From: Dan Gebhardt Date: Sun, 27 Sep 2020 13:24:43 -0400 Subject: [PATCH 3/3] Fix typing and linting issues --- .../strategies/connection-strategy-test.ts | 11 +- .../log-truncation-strategy-test.ts | 8 +- .../test/strategies/request-strategy-test.ts | 26 +- .../test/strategies/sync-strategy-test.ts | 10 +- .../@orbit/coordinator/test/strategy-test.ts | 5 - packages/@orbit/data/src/key-map.ts | 4 +- packages/@orbit/data/src/record.ts | 12 +- packages/@orbit/data/src/source.ts | 26 +- packages/@orbit/data/test/key-map-test.ts | 7 +- .../@orbit/data/test/query-builder-test.ts | 6 +- packages/@orbit/data/test/query-test.ts | 7 +- packages/@orbit/data/test/schema-test.ts | 6 +- .../test/source-interfaces/pullable-test.ts | 8 +- .../test/source-interfaces/pushable-test.ts | 8 +- .../test/source-interfaces/queryable-test.ts | 8 +- .../test/source-interfaces/syncable-test.ts | 8 +- .../test/source-interfaces/updatable-test.ts | 8 +- packages/@orbit/data/test/transform-test.ts | 7 +- packages/@orbit/identity-map/package.json | 3 +- .../identity-map/test/identity-map-test.ts | 4 - .../test/record-identity-serializer-test.ts | 4 - .../indexeddb/test/indexeddb-source-test.ts | 12 +- .../test/memory-bucket-test.ts | 2 - ...store-jsonapi-clientid-pessimistic-test.ts | 2 - .../store-jsonapi-remoteid-optimistic-test.ts | 2 - ...store-jsonapi-remoteid-pessimistic-test.ts | 2 - .../jsonapi/src/jsonapi-request-processor.ts | 2 +- .../@orbit/jsonapi/src/lib/query-params.ts | 8 +- packages/@orbit/jsonapi/src/resources.ts | 3 +- .../test/jsonapi-request-processor-test.ts | 1 - .../jsonapi-serializer-operations-test.ts | 4 - .../jsonapi/test/jsonapi-serializer-test.ts | 20 +- .../jsonapi/test/jsonapi-source-test.ts | 1147 +++++++---------- ...ce-with-legacy-serializer-settings-test.ts | 1140 +++++++--------- .../jsonapi/test/jsonapi-url-builder-test.ts | 4 - .../jsonapi/test/lib/query-requests-test.ts | 3 +- .../test/lib/transform-requests-test.ts | 1 - .../jsonapi-document-serializer-test.ts | 16 +- .../jsonapi-operation-serializer-test.ts | 12 - ...api-operations-document-serializer-test.ts | 4 - ...onapi-resource-identity-serializer-test.ts | 12 - .../jsonapi-resource-serializer-test.ts | 12 - .../@orbit/jsonapi/test/support/jsonapi.ts | 2 +- .../test/local-storage-source-test.ts | 13 +- .../@orbit/memory/test/memory-cache-test.ts | 92 +- .../@orbit/memory/test/memory-source-test.ts | 72 +- .../test/async-record-cache-test.ts | 350 ++--- .../cache-integrity-processor-test.ts | 6 - .../schema-consistency-processor-test.ts | 6 - .../schema-validation-processor-test.ts | 5 - .../support/example-async-record-cache.ts | 10 +- .../test/support/example-sync-record-cache.ts | 8 +- .../test/sync-record-cache-test.ts | 243 ++-- packages/@orbit/serializers/src/serializer.ts | 2 +- .../serializers/test/date-serializer-test.ts | 2 +- .../test/date-time-serializer-test.ts | 2 +- .../test/serializer-builders-test.ts | 14 +- 57 files changed, 1522 insertions(+), 1900 deletions(-) diff --git a/packages/@orbit/coordinator/test/strategies/connection-strategy-test.ts b/packages/@orbit/coordinator/test/strategies/connection-strategy-test.ts index 8c15267b0..8ca668f96 100644 --- a/packages/@orbit/coordinator/test/strategies/connection-strategy-test.ts +++ b/packages/@orbit/coordinator/test/strategies/connection-strategy-test.ts @@ -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' ); @@ -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; } }); diff --git a/packages/@orbit/coordinator/test/strategies/log-truncation-strategy-test.ts b/packages/@orbit/coordinator/test/strategies/log-truncation-strategy-test.ts index 5ee1cb504..d8ab80cdf 100644 --- a/packages/@orbit/coordinator/test/strategies/log-truncation-strategy-test.ts +++ b/packages/@orbit/coordinator/test/strategies/log-truncation-strategy-test.ts @@ -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' ); diff --git a/packages/@orbit/coordinator/test/strategies/request-strategy-test.ts b/packages/@orbit/coordinator/test/strategies/request-strategy-test.ts index cdbd4a156..48d82daa7 100644 --- a/packages/@orbit/coordinator/test/strategies/request-strategy-test.ts +++ b/packages/@orbit/coordinator/test/strategies/request-strategy-test.ts @@ -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' ); @@ -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; } }); @@ -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' @@ -297,30 +297,34 @@ module('RequestStrategy', function (hooks) { strategy = new RequestStrategy({ source: 's1', on: 'updateFail', - async action(transform: Transform, e: Error): Promise { + async action(transform, e): Promise { 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; } }); diff --git a/packages/@orbit/coordinator/test/strategies/sync-strategy-test.ts b/packages/@orbit/coordinator/test/strategies/sync-strategy-test.ts index b921c70bb..cf574b4d4 100644 --- a/packages/@orbit/coordinator/test/strategies/sync-strategy-test.ts +++ b/packages/@orbit/coordinator/test/strategies/sync-strategy-test.ts @@ -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' ); @@ -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; } }); @@ -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'); } }); @@ -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; } }); diff --git a/packages/@orbit/coordinator/test/strategy-test.ts b/packages/@orbit/coordinator/test/strategy-test.ts index 9ea48fbdd..01e17e93f 100644 --- a/packages/@orbit/coordinator/test/strategy-test.ts +++ b/packages/@orbit/coordinator/test/strategy-test.ts @@ -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 {} diff --git a/packages/@orbit/data/src/key-map.ts b/packages/@orbit/data/src/key-map.ts index 9ae4290ce..3f337e591 100644 --- a/packages/@orbit/data/src/key-map.ts +++ b/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. @@ -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) { diff --git a/packages/@orbit/data/src/record.ts b/packages/@orbit/data/src/record.ts index 5e4960bde..1a8299e8f 100644 --- a/packages/@orbit/data/src/record.ts +++ b/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; @@ -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) ); @@ -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])) { diff --git a/packages/@orbit/data/src/source.ts b/packages/@orbit/data/src/source.ts index c0b430ecd..c376b852b 100644 --- a/packages/@orbit/data/src/source.ts +++ b/packages/@orbit/data/src/source.ts @@ -187,16 +187,6 @@ export abstract class Source implements Evented, Performer { this._activated = undefined; } - protected async _activate(): Promise { - 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. @@ -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 { + async transformed(transforms: Transform[]): Promise { await this.activated; return transforms .reduce((chain, transform) => { @@ -222,11 +212,21 @@ export abstract class Source implements Evented, Performer { .then(() => transforms); } - private _enqueueRequest(type: string, data: any): Promise { + ///////////////////////////////////////////////////////////////////////////// + // Protected methods + ///////////////////////////////////////////////////////////////////////////// + + protected async _activate(): Promise { + await this._transformLog.reified; + await this._syncQueue.activate(); + await this._requestQueue.activate(); + } + + protected _enqueueRequest(type: string, data: unknown): Promise { return this._requestQueue.push({ type, data }); } - private _enqueueSync(type: string, data: any): Promise { + protected _enqueueSync(type: string, data: unknown): Promise { return this._syncQueue.push({ type, data }); } } diff --git a/packages/@orbit/data/test/key-map-test.ts b/packages/@orbit/data/test/key-map-test.ts index 2327bd23d..e00f0dbf5 100644 --- a/packages/@orbit/data/test/key-map-test.ts +++ b/packages/@orbit/data/test/key-map-test.ts @@ -41,10 +41,13 @@ module('KeyMap', function (hooks) { test('#pushRecord does not set incomplete records', function (assert) { let keyMap = new KeyMap(); - keyMap.pushRecord({ type: 'planet', id: null, keys: { remoteId: 'a' } }); + keyMap.pushRecord({ type: 'planet', keys: { remoteId: 'a' } }); assert.strictEqual(keyMap.keyToId('planet', 'remoteId', 'a'), undefined); - keyMap.pushRecord({ type: 'planet', id: '1', keys: { remoteId: null } }); + keyMap.pushRecord({ + type: 'planet', + id: '1' + }); assert.strictEqual(keyMap.idToKey('planet', 'remoteId', '1'), undefined); }); diff --git a/packages/@orbit/data/test/query-builder-test.ts b/packages/@orbit/data/test/query-builder-test.ts index da43b3119..c843d7587 100644 --- a/packages/@orbit/data/test/query-builder-test.ts +++ b/packages/@orbit/data/test/query-builder-test.ts @@ -366,7 +366,7 @@ module('QueryBuilder', function (hooks) { test('findRecords + sort (invalid sort expression)', function (assert) { assert.throws(() => { - oqb.findRecords('planet').sort(null); + oqb.findRecords('planet').sort(null as any); }, new Error('Unrecognized sort param.')); }); @@ -813,7 +813,9 @@ module('QueryBuilder', function (hooks) { test('findRelatedRecords + sort (invalid sort expression)', function (assert) { assert.throws(() => { - oqb.findRelatedRecords({ type: 'planet', id: '123' }, 'moons').sort(null); + oqb + .findRelatedRecords({ type: 'planet', id: '123' }, 'moons') + .sort(null as any); }, new Error('Unrecognized sort param.')); }); diff --git a/packages/@orbit/data/test/query-test.ts b/packages/@orbit/data/test/query-test.ts index 44aba9c95..a752f0eeb 100644 --- a/packages/@orbit/data/test/query-test.ts +++ b/packages/@orbit/data/test/query-test.ts @@ -114,7 +114,12 @@ module('buildQuery', function () { op: 'findRecords', type: 'planet' }; - let query = buildQuery((q) => q.findRecords('planet'), null, null, qb); + let query = buildQuery( + (q) => q.findRecords('planet'), + undefined, + undefined, + qb + ); assert.deepEqual( query.expressions[0], expression, diff --git a/packages/@orbit/data/test/schema-test.ts b/packages/@orbit/data/test/schema-test.ts index 1e3f24fc8..dc1bbabd6 100644 --- a/packages/@orbit/data/test/schema-test.ts +++ b/packages/@orbit/data/test/schema-test.ts @@ -1,5 +1,5 @@ import { Schema } from '../src/schema'; -import { Record } from '../src'; +import { Record, UninitializedRecord } from '../src'; import './test-helper'; const { module, test } = QUnit; @@ -31,7 +31,7 @@ module('Schema', function () { assert.equal(version, 2, 'version is passed as argument'); assert.equal(schema.version, 2, 'version === 2'); assert.ok( - schema.getModel('planet').attributes.name, + schema.getModel('planet').attributes?.name, 'model attribute has been added' ); done(); @@ -245,7 +245,7 @@ module('Schema', function () { } }); - let moon: Record = { type: 'moon', id: undefined }; + let moon: UninitializedRecord = { type: 'moon' }; schema.initializeRecord(moon); assert.equal(moon.id, 'moon-123', 'generates an ID if `id` is undefined'); diff --git a/packages/@orbit/data/test/source-interfaces/pullable-test.ts b/packages/@orbit/data/test/source-interfaces/pullable-test.ts index 833ccb687..01bbe7564 100644 --- a/packages/@orbit/data/test/source-interfaces/pullable-test.ts +++ b/packages/@orbit/data/test/source-interfaces/pullable-test.ts @@ -14,12 +14,12 @@ const { module, test } = QUnit; module('@pullable', function (hooks) { @pullable class MySource extends Source implements Pullable { - pull: ( + pull!: ( queryOrExpressions: QueryOrExpressions, options?: RequestOptions, id?: string ) => Promise; - _pull: (query: Query, hints?: any) => Promise; + _pull!: (query: Query, hints?: any) => Promise; } let source: MySource; @@ -28,10 +28,6 @@ module('@pullable', function (hooks) { source = new MySource(); }); - hooks.afterEach(function () { - source = null; - }); - test('isPullable - tests for the application of the @pullable decorator', function (assert) { assert.ok(isPullable(source)); }); diff --git a/packages/@orbit/data/test/source-interfaces/pushable-test.ts b/packages/@orbit/data/test/source-interfaces/pushable-test.ts index d24f1652e..9d66520ad 100644 --- a/packages/@orbit/data/test/source-interfaces/pushable-test.ts +++ b/packages/@orbit/data/test/source-interfaces/pushable-test.ts @@ -17,12 +17,12 @@ const { module, test } = QUnit; module('@pushable', function (hooks) { @pushable class MySource extends Source implements Pushable { - push: ( + push!: ( transformOrOperations: TransformOrOperations, options?: RequestOptions, id?: string ) => Promise; - _push: (transform: Transform, hints?: any) => Promise; + _push!: (transform: Transform, hints?: any) => Promise; } let source: MySource; @@ -31,10 +31,6 @@ module('@pushable', function (hooks) { source = new MySource({ name: 'src1' }); }); - hooks.afterEach(function () { - source = null; - }); - test('isPushable - tests for the application of the @pushable decorator', function (assert) { assert.ok(isPushable(source)); }); diff --git a/packages/@orbit/data/test/source-interfaces/queryable-test.ts b/packages/@orbit/data/test/source-interfaces/queryable-test.ts index 3b453f408..41e73b181 100644 --- a/packages/@orbit/data/test/source-interfaces/queryable-test.ts +++ b/packages/@orbit/data/test/source-interfaces/queryable-test.ts @@ -13,12 +13,12 @@ const { module, test } = QUnit; module('@queryable', function (hooks) { @queryable class MySource extends Source implements Queryable { - query: ( + query!: ( queryOrExpressions: QueryOrExpressions, options?: RequestOptions, id?: string ) => Promise; - _query: (query: Query, hints?: any) => Promise; + _query!: (query: Query, hints?: any) => Promise; } let source: MySource; @@ -27,10 +27,6 @@ module('@queryable', function (hooks) { source = new MySource({ name: 'src1' }); }); - hooks.afterEach(function () { - source = null; - }); - test('isQueryable - tests for the application of the @queryable decorator', function (assert) { assert.ok(isQueryable(source)); }); diff --git a/packages/@orbit/data/test/source-interfaces/syncable-test.ts b/packages/@orbit/data/test/source-interfaces/syncable-test.ts index 722eb23b3..d4ec4db36 100644 --- a/packages/@orbit/data/test/source-interfaces/syncable-test.ts +++ b/packages/@orbit/data/test/source-interfaces/syncable-test.ts @@ -12,8 +12,8 @@ const { module, test } = QUnit; module('@syncable', function (hooks) { @syncable class MySource extends Source implements Syncable { - sync: (transformOrTransforms: Transform | Transform[]) => Promise; - _sync: (transform: Transform) => Promise; + sync!: (transformOrTransforms: Transform | Transform[]) => Promise; + _sync!: (transform: Transform) => Promise; } let source: MySource; @@ -22,10 +22,6 @@ module('@syncable', function (hooks) { source = new MySource({ name: 'src1' }); }); - hooks.afterEach(function () { - source = null; - }); - test('isSyncable - tests for the application of the @syncable decorator', function (assert) { assert.ok(isSyncable(source)); }); diff --git a/packages/@orbit/data/test/source-interfaces/updatable-test.ts b/packages/@orbit/data/test/source-interfaces/updatable-test.ts index df2134a10..f671b90ba 100644 --- a/packages/@orbit/data/test/source-interfaces/updatable-test.ts +++ b/packages/@orbit/data/test/source-interfaces/updatable-test.ts @@ -17,12 +17,12 @@ const { module, test } = QUnit; module('@updatable', function (hooks) { @updatable class MySource extends Source implements Updatable { - update: ( + update!: ( transformOrOperations: TransformOrOperations, options?: RequestOptions, id?: string ) => Promise; - _update: (transform: Transform, hints?: any) => Promise; + _update!: (transform: Transform, hints?: any) => Promise; } let source: MySource; @@ -31,10 +31,6 @@ module('@updatable', function (hooks) { source = new MySource({ name: 'src1' }); }); - hooks.afterEach(function () { - source = null; - }); - test('isUpdatable - tests for the application of the @updatable decorator', function (assert) { assert.ok(isUpdatable(source)); }); diff --git a/packages/@orbit/data/test/transform-test.ts b/packages/@orbit/data/test/transform-test.ts index 90f25ff32..5d51abd7c 100644 --- a/packages/@orbit/data/test/transform-test.ts +++ b/packages/@orbit/data/test/transform-test.ts @@ -109,7 +109,12 @@ module('buildTransform', function () { record: planet }; - let query = buildTransform((t) => t.addRecord(planet), null, null, tb); + let query = buildTransform( + (t) => t.addRecord(planet), + undefined, + undefined, + tb + ); assert.deepEqual(query.operations, [operation], 'operations was populated'); }); }); diff --git a/packages/@orbit/identity-map/package.json b/packages/@orbit/identity-map/package.json index ee98b3da7..31a439c0a 100644 --- a/packages/@orbit/identity-map/package.json +++ b/packages/@orbit/identity-map/package.json @@ -30,7 +30,8 @@ "test": "node ../build ci && snowpack build && testem ci" }, "devDependencies": { - "@orbit/build": "^0.17.0-beta.7" + "@orbit/build": "^0.17.0-beta.7", + "@orbit/data": "^0.17.0-beta.8" }, "prettier": "@orbit/prettier-config" } diff --git a/packages/@orbit/identity-map/test/identity-map-test.ts b/packages/@orbit/identity-map/test/identity-map-test.ts index 397b8c316..00d35fdb7 100644 --- a/packages/@orbit/identity-map/test/identity-map-test.ts +++ b/packages/@orbit/identity-map/test/identity-map-test.ts @@ -13,10 +13,6 @@ module('IdentityMap', function (hooks) { identityMap = new IdentityMap({ serializer }); }); - hooks.afterEach(function () { - identityMap = null; - }); - test('it exists', function (assert) { assert.ok(identityMap); }); diff --git a/packages/@orbit/identity-map/test/record-identity-serializer-test.ts b/packages/@orbit/identity-map/test/record-identity-serializer-test.ts index 8627d796f..c90cdfe6c 100644 --- a/packages/@orbit/identity-map/test/record-identity-serializer-test.ts +++ b/packages/@orbit/identity-map/test/record-identity-serializer-test.ts @@ -10,10 +10,6 @@ module('RecordIdentitySerializer', function (hooks) { serializer = new RecordIdentitySerializer(); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); diff --git a/packages/@orbit/indexeddb/test/indexeddb-source-test.ts b/packages/@orbit/indexeddb/test/indexeddb-source-test.ts index ce5a4bf11..d88d317d2 100644 --- a/packages/@orbit/indexeddb/test/indexeddb-source-test.ts +++ b/packages/@orbit/indexeddb/test/indexeddb-source-test.ts @@ -412,12 +412,12 @@ module('IndexedDBSource', function (hooks) { ]); let moons = (await getRecordFromIndexedDB(source.cache, planet)) - .relationships.moons.data as RecordIdentity[]; + ?.relationships?.moons.data as RecordIdentity[]; assert.deepEqual(moons.length, 2, 'record has 2 moons'); await source.push((t) => t.removeRecord(moon1)); moons = (await getRecordFromIndexedDB(source.cache, planet)).relationships - .moons.data as RecordIdentity[]; + ?.moons.data as RecordIdentity[]; assert.deepEqual(moons.length, 1, 'record has 1 moon'); }); @@ -1133,7 +1133,9 @@ module('IndexedDBSource', function (hooks) { 'operations match expectations' ); assert.deepEqual( - transforms[0].operations.map((o: AddRecordOperation) => o.record.type), + transforms[0].operations.map( + (o) => (o as AddRecordOperation)?.record?.type + ), ['planet', 'planet'], 'operations match expectations' ); @@ -1189,7 +1191,9 @@ module('IndexedDBSource', function (hooks) { 'operations match expectations' ); assert.deepEqual( - transforms[0].operations.map((o: AddRecordOperation) => o.record.type), + transforms[0].operations.map( + (o) => (o as AddRecordOperation).record.type + ), ['planet', 'moon'], 'operations match expectations' ); diff --git a/packages/@orbit/integration-tests/test/memory-bucket-test.ts b/packages/@orbit/integration-tests/test/memory-bucket-test.ts index 94eaf25ae..d73ef25e8 100644 --- a/packages/@orbit/integration-tests/test/memory-bucket-test.ts +++ b/packages/@orbit/integration-tests/test/memory-bucket-test.ts @@ -29,12 +29,10 @@ module('MemorySource + IndexdDBBucket', function (hooks) { hooks.afterEach(() => { bucket.deleteDB(); - schema = memory = bucket = null; }); test('push before pull', async function (assert) { const theMoon = { - id: undefined as any, type: 'moon', attributes: { name: 'The Moon' diff --git a/packages/@orbit/integration-tests/test/store-jsonapi-clientid-pessimistic-test.ts b/packages/@orbit/integration-tests/test/store-jsonapi-clientid-pessimistic-test.ts index f0327109f..fefaad93b 100644 --- a/packages/@orbit/integration-tests/test/store-jsonapi-clientid-pessimistic-test.ts +++ b/packages/@orbit/integration-tests/test/store-jsonapi-clientid-pessimistic-test.ts @@ -102,8 +102,6 @@ module( }); hooks.afterEach(() => { - schema = remote = memory = coordinator = null; - fetchStub.restore(); }); diff --git a/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-optimistic-test.ts b/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-optimistic-test.ts index b2ec05159..f410021b8 100644 --- a/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-optimistic-test.ts +++ b/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-optimistic-test.ts @@ -117,8 +117,6 @@ module( }); hooks.afterEach(() => { - keyMap = schema = remote = memory = coordinator = null; - fetchStub.restore(); }); diff --git a/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-pessimistic-test.ts b/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-pessimistic-test.ts index a3666c0dc..3acf239a4 100644 --- a/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-pessimistic-test.ts +++ b/packages/@orbit/integration-tests/test/store-jsonapi-remoteid-pessimistic-test.ts @@ -118,8 +118,6 @@ module( }); hooks.afterEach(() => { - keyMap = schema = remote = memory = coordinator = null; - fetchStub.restore(); }); diff --git a/packages/@orbit/jsonapi/src/jsonapi-request-processor.ts b/packages/@orbit/jsonapi/src/jsonapi-request-processor.ts index 2de1f80a1..8581d17d1 100644 --- a/packages/@orbit/jsonapi/src/jsonapi-request-processor.ts +++ b/packages/@orbit/jsonapi/src/jsonapi-request-processor.ts @@ -161,7 +161,7 @@ export class JSONAPIRequestProcessor { // console.log('fetch', fullUrl, settings, 'polyfill', fetchFn.polyfill); - if (settings.timeout) { + if (settings.timeout !== undefined && settings.timeout > 0) { let timeout = settings.timeout; delete settings.timeout; diff --git a/packages/@orbit/jsonapi/src/lib/query-params.ts b/packages/@orbit/jsonapi/src/lib/query-params.ts index e230544b3..b6981c542 100644 --- a/packages/@orbit/jsonapi/src/lib/query-params.ts +++ b/packages/@orbit/jsonapi/src/lib/query-params.ts @@ -2,7 +2,7 @@ import { Dict } from '@orbit/utils'; interface RawParam { path: string[]; - val: string; + val: any; } export interface Param { @@ -37,12 +37,16 @@ function flattenObjectToParams(obj: any, path: string[] = []): RawParam[] { return params; } -export function encodeQueryParams(obj: Dict): string { +export function encodeQueryParams(obj: Dict): string { return flattenObjectToParams(obj) .map((rawParam) => { let path: string; let val = rawParam.val; + if (val === null) { + val = 'null'; + } + if (rawParam.path.length === 1) { path = rawParam.path[0]; } else { diff --git a/packages/@orbit/jsonapi/src/resources.ts b/packages/@orbit/jsonapi/src/resources.ts index 6437b7a98..3916a289c 100644 --- a/packages/@orbit/jsonapi/src/resources.ts +++ b/packages/@orbit/jsonapi/src/resources.ts @@ -35,7 +35,8 @@ export type PrimaryResourceData = | Resource | Resource[] | ResourceIdentity - | ResourceIdentity[]; + | ResourceIdentity[] + | null; export interface ResourceDocument { data: PrimaryResourceData; diff --git a/packages/@orbit/jsonapi/test/jsonapi-request-processor-test.ts b/packages/@orbit/jsonapi/test/jsonapi-request-processor-test.ts index 1cacadff6..02c6a6b83 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-request-processor-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-request-processor-test.ts @@ -70,7 +70,6 @@ module('JSONAPIRequestProcessor', function (hooks) { }); hooks.afterEach(() => { - keyMap = schema = processor = null; fetchStub.restore(); }); diff --git a/packages/@orbit/jsonapi/test/jsonapi-serializer-operations-test.ts b/packages/@orbit/jsonapi/test/jsonapi-serializer-operations-test.ts index fe007a93f..e8bcb1e8f 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-serializer-operations-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-serializer-operations-test.ts @@ -133,10 +133,6 @@ module('JSONAPISerializer', function (hooks) { serializer = new JSONAPISerializer({ schema }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('deserializeOperationsDocument', function (assert) { const operations = serializer.deserializeOperationsDocument( operationsDocument diff --git a/packages/@orbit/jsonapi/test/jsonapi-serializer-test.ts b/packages/@orbit/jsonapi/test/jsonapi-serializer-test.ts index 7c6dcac26..dadc567cc 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-serializer-test.ts @@ -48,10 +48,6 @@ module('JSONAPISerializer', function (hooks) { serializer = new JSONAPISerializer({ schema }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -302,10 +298,6 @@ module('JSONAPISerializer', function (hooks) { }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('serializer is assigned some standard serializers by default, and any custom serializers passed as settings', function (assert) { // default serializers assert.ok(serializer.serializerFor('boolean')); @@ -446,10 +438,6 @@ module('JSONAPISerializer', function (hooks) { serializer = new JSONAPISerializer({ schema }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -831,10 +819,6 @@ module('JSONAPISerializer', function (hooks) { }; }); - hooks.afterEach(function () { - keyMap = serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -1173,8 +1157,8 @@ module('JSONAPISerializer', function (hooks) { }); let planet = result.data as Record; - let moon = result.included[0]; - let solarSystem = result.included[1]; + let moon = result.included?.[0] as Record; + let solarSystem = result.included?.[1] as Record; assert.deepEqual( result, diff --git a/packages/@orbit/jsonapi/test/jsonapi-source-test.ts b/packages/@orbit/jsonapi/test/jsonapi-source-test.ts index 2dec9777a..fdce6c9e2 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-source-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-source-test.ts @@ -23,6 +23,10 @@ import { Resource, ResourceDocument } from '../src/resources'; import { SinonStub } from 'sinon'; import * as sinon from 'sinon'; import { JSONAPISerializers } from '../src/serializers/jsonapi-serializers'; +import { + JSONAPIResourceIdentitySerializer, + JSONAPIResourceSerializer +} from '../src'; const { module, test } = QUnit; @@ -31,6 +35,7 @@ module('JSONAPISource', function () { let keyMap: KeyMap; let schema: Schema; let source: JSONAPISource; + let resourceSerializer: JSONAPIResourceSerializer; module('with a secondary key', function (hooks) { hooks.beforeEach(() => { @@ -95,10 +100,12 @@ module('JSONAPISource', function () { schema, keyMap }); + resourceSerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.Resource + ) as JSONAPIResourceSerializer; }); hooks.afterEach(() => { - keyMap = schema = source = null; fetchStub.restore(); }); @@ -173,7 +180,7 @@ module('JSONAPISource', function () { headers: { Accept: 'application/json' }, - timeout: null + timeout: 0 } }); assert.deepEqual(customSource.requestProcessor.defaultFetchSettings, { @@ -181,7 +188,7 @@ module('JSONAPISource', function () { Accept: 'application/json', 'Content-Type': 'application/vnd.api+json' }, - timeout: null + timeout: 0 }); }); @@ -190,12 +197,10 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -284,12 +289,10 @@ module('JSONAPISource', function () { test('#push - will not issue fetch if beforePush listener logs transform', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; const t = buildTransform({ op: 'addRecord', @@ -311,12 +314,10 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -369,7 +370,7 @@ module('JSONAPISource', function () { } else if (transformCount === 3) { let operationsWithoutId = transform.operations.map((op) => { let clonedOp = Object.assign({}, op) as RecordOperation; - delete clonedOp.record.id; + delete (clonedOp as any).record.id; return clonedOp; }); assert.deepEqual( @@ -432,12 +433,10 @@ module('JSONAPISource', function () { test('#push - options can be passed in at the root level or source-specific level', async function (assert) { assert.expect(1); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; fetchStub.withArgs('/planets?include=moons').returns( jsonapiResponse(201, { @@ -471,16 +470,14 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let replacePlanetOp = { op: 'updateRecord', @@ -553,16 +550,14 @@ module('JSONAPISource', function () { test('#push - can replace a single attribute', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(204)); @@ -601,16 +596,14 @@ module('JSONAPISource', function () { test('#push - can accept remote changes', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns( jsonapiResponse(200, { @@ -633,8 +626,9 @@ module('JSONAPISource', function () { transforms[1].operations.map((o) => o.op), ['replaceAttribute', 'replaceKey'] ); + const ops = transforms[1].operations as ReplaceKeyOperation[]; assert.deepEqual( - transforms[1].operations.map((o: ReplaceKeyOperation) => o.value), + ops.map((o) => o.value), ['Mars', 'remote-id-123'] ); }); @@ -642,12 +636,10 @@ module('JSONAPISource', function () { test('#push - can delete records', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -670,19 +662,15 @@ module('JSONAPISource', function () { test('#push - can add a hasMany relationship with POST', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -712,19 +700,15 @@ module('JSONAPISource', function () { test('#push - can remove a relationship with DELETE', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -751,19 +735,15 @@ module('JSONAPISource', function () { test('#push - can update a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -806,12 +786,10 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } } as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/planets').returns( jsonapiResponse(201, { @@ -861,12 +839,10 @@ module('JSONAPISource', function () { test('#push - can clear a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -901,19 +877,15 @@ module('JSONAPISource', function () { test('#push - can replace a hasMany relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -950,18 +922,14 @@ module('JSONAPISource', function () { test('#push - a single transform can result in multiple requests', async function (assert) { assert.expect(6); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planet', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planet', + id: '2' + }) as Record; fetchStub.withArgs('/planets/1').returns(jsonapiResponse(200)); @@ -1002,18 +970,14 @@ module('JSONAPISource', function () { test('#push - source can limit the number of allowed requests per transform with `maxRequestsPerTransform`', async function (assert) { assert.expect(1); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planet', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planet', + id: '2' + }) as Record; source.maxRequestsPerTransform = 1; @@ -1033,16 +997,14 @@ module('JSONAPISource', function () { test('#push - request can timeout', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -1065,16 +1027,14 @@ module('JSONAPISource', function () { test('#push - allowed timeout can be specified per-request', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; const options = { sources: { @@ -1105,16 +1065,14 @@ module('JSONAPISource', function () { test('#push - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -1132,16 +1090,14 @@ module('JSONAPISource', function () { test('#push - response can trigger a ClientError', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let errors = [ { @@ -1171,12 +1127,10 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -1261,12 +1215,10 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -1319,7 +1271,7 @@ module('JSONAPISource', function () { } else if (transformCount === 3) { let operationsWithoutId = transform.operations.map((op) => { let clonedOp = Object.assign({}, op) as RecordOperation; - delete clonedOp.record.id; + delete (clonedOp as any).record.id; return clonedOp; }); assert.deepEqual( @@ -1384,16 +1336,14 @@ module('JSONAPISource', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let replacePlanetOp = { op: 'updateRecord', @@ -1466,16 +1416,14 @@ module('JSONAPISource', function () { test('#update - can replace a single attribute', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(204)); @@ -1514,16 +1462,14 @@ module('JSONAPISource', function () { test('#update - can accept remote changes', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns( jsonapiResponse(200, { @@ -1552,7 +1498,7 @@ module('JSONAPISource', function () { ['replaceAttribute', 'replaceKey'] ); assert.deepEqual( - transforms[1].operations.map((o: ReplaceKeyOperation) => o.value), + transforms[1].operations.map((o) => (o as ReplaceKeyOperation).value), ['Mars', 'remote-id-123'] ); assert.deepEqual(data, { @@ -1571,12 +1517,10 @@ module('JSONAPISource', function () { test('#update - can delete records', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -1599,19 +1543,15 @@ module('JSONAPISource', function () { test('#update - can add a hasMany relationship with POST', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -1641,19 +1581,15 @@ module('JSONAPISource', function () { test('#update - can remove a relationship with DELETE', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -1680,19 +1616,15 @@ module('JSONAPISource', function () { test('#update - can update a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -1737,12 +1669,10 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/planets').returns( jsonapiResponse(201, { @@ -1792,12 +1722,10 @@ module('JSONAPISource', function () { test('#update - can clear a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -1832,19 +1760,15 @@ module('JSONAPISource', function () { test('#update - can replace a hasMany relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moon', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moon', + id: '987' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -1881,18 +1805,14 @@ module('JSONAPISource', function () { test('#update - a single transform can result in multiple requests', async function (assert) { assert.expect(6); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planet', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planet', + id: '2' + }) as Record; fetchStub.withArgs('/planets/1').returns(jsonapiResponse(200)); @@ -1933,18 +1853,14 @@ module('JSONAPISource', function () { test('#update - source can limit the number of allowed requests per transform with `maxRequestsPerTransform`', async function (assert) { assert.expect(1); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planet', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planet', + id: '2' + }) as Record; source.maxRequestsPerTransform = 1; @@ -1964,16 +1880,14 @@ module('JSONAPISource', function () { test('#update - request can timeout', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -1996,16 +1910,14 @@ module('JSONAPISource', function () { test('#update - allowed timeout can be specified per-request', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; const options = { sources: { @@ -2036,16 +1948,14 @@ module('JSONAPISource', function () { test('#update - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -2063,16 +1973,14 @@ module('JSONAPISource', function () { test('#update - response can trigger a ClientError', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let errors = [ { @@ -2106,12 +2014,10 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -2132,7 +2038,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter'] ); @@ -2148,12 +2054,10 @@ module('JSONAPISource', function () { test('#pull - record (with a 304 response)', async function (assert) { assert.expect(3); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(304)); @@ -2180,12 +2084,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -2215,12 +2117,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; const options = { sources: { @@ -2251,12 +2151,10 @@ module('JSONAPISource', function () { test('#pull - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -2281,12 +2179,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; const options = { sources: { @@ -2346,7 +2242,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Earth', 'Saturn'] ); @@ -2405,7 +2301,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth'] ); @@ -2459,7 +2355,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth'] ); @@ -2508,7 +2404,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Moon'] ); @@ -2580,7 +2476,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Moon', 'Phobos', 'Deimos'] ); @@ -2642,7 +2538,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Mars'] ); @@ -2692,7 +2588,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth', 'Jupiter', 'Saturn'] ); @@ -2742,7 +2638,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Saturn', 'Jupiter', 'Earth'] ); @@ -2804,7 +2700,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Saturn', 'Earth'] ); @@ -2858,7 +2754,7 @@ module('JSONAPISource', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Earth', 'Saturn'] ); @@ -2874,12 +2770,10 @@ module('JSONAPISource', function () { test('#pull - related records with attribute filter', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -2926,7 +2820,7 @@ module('JSONAPISource', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Earth'); + assert.equal(op1.record.attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -2939,12 +2833,10 @@ module('JSONAPISource', function () { test('#pull - related records with attribute filters', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -2985,7 +2877,7 @@ module('JSONAPISource', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Earth'); + assert.equal(op1.record.attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -2998,12 +2890,10 @@ module('JSONAPISource', function () { test('#pull - records with relatedRecord filter (single value)', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3043,7 +2933,7 @@ module('JSONAPISource', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Moon'); + assert.equal(op1.record.attributes?.name, 'Moon'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3056,12 +2946,10 @@ module('JSONAPISource', function () { test('#pull - records with relatedRecord filter (multiple values)', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3130,7 +3018,7 @@ module('JSONAPISource', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -3145,12 +3033,10 @@ module('JSONAPISource', function () { test('#pull - records with relatedRecords filter', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3199,7 +3085,7 @@ module('JSONAPISource', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Mars'); + assert.equal(op1.record.attributes?.name, 'Mars'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3212,12 +3098,10 @@ module('JSONAPISource', function () { test('#pull - records with sort by an attribute in ascending order', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3264,7 +3148,7 @@ module('JSONAPISource', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -3279,12 +3163,10 @@ module('JSONAPISource', function () { test('#pull - records with sort by an attribute in descending order', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3331,7 +3213,7 @@ module('JSONAPISource', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -3346,12 +3228,10 @@ module('JSONAPISource', function () { test('#pull - records with sort by multiple fields', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3414,7 +3294,7 @@ module('JSONAPISource', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -3429,12 +3309,10 @@ module('JSONAPISource', function () { test('#pull - records with pagination', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3487,7 +3365,7 @@ module('JSONAPISource', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -3554,12 +3432,10 @@ module('JSONAPISource', function () { test('#pull - relatedRecord', async function (assert) { assert.expect(13); - const planetRecord = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: 'jupiter' - }) as Record; + const planetRecord = resourceSerializer.deserialize({ + type: 'planet', + id: 'jupiter' + }) as Record; const data: Resource = { type: 'solarSystem', @@ -3595,14 +3471,14 @@ module('JSONAPISource', function () { const op1 = operations[0] as UpdateRecordOperation; assert.equal(op1.record.type, 'solarSystem'); assert.equal(op1.record.id, ssId); - assert.equal(op1.record.attributes.name, 'Our Solar System'); + assert.equal(op1.record.attributes?.name, 'Our Solar System'); const op2 = operations[1] as ReplaceRelatedRecordOperation; assert.equal(op2.record.type, 'planet'); assert.equal(op2.record.id, planetId); assert.equal(op2.relationship, 'solarSystem'); - assert.equal(op2.relatedRecord.type, 'solarSystem'); - assert.equal(op2.relatedRecord.id, ssId); + assert.equal(op2.relatedRecord?.type, 'solarSystem'); + assert.equal(op2.relatedRecord?.id, ssId); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3615,12 +3491,10 @@ module('JSONAPISource', function () { test('#pull - relatedRecords', async function (assert) { assert.expect(9); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: 'jupiter' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: 'jupiter' + }) as Record; let data = [ { @@ -3651,7 +3525,7 @@ module('JSONAPISource', function () { ); const op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Io'); + assert.equal(op1.record.attributes?.name, 'Io'); const op2 = transforms[0].operations[1] as ReplaceRelatedRecordsOperation; assert.equal(op2.record.id, planet.id); @@ -3672,12 +3546,14 @@ module('JSONAPISource', function () { test('#pull - relatedRecords with include', async function (assert) { assert.expect(2); - const planetRecord = source.requestProcessor - .serializerFor(JSONAPISerializers.ResourceIdentity) - .deserialize({ - type: 'planet', - id: 'jupiter' - }) as RecordIdentity; + const resourceIdentitySerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.ResourceIdentity + ) as JSONAPIResourceIdentitySerializer; + + const planetRecord = resourceIdentitySerializer.deserialize({ + type: 'planet', + id: 'jupiter' + }) as RecordIdentity; const options = { sources: { @@ -3713,12 +3589,10 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3732,7 +3606,7 @@ module('JSONAPISource', function () { !Array.isArray(record), 'only a single primary record returned' ); - assert.equal((record as Record).attributes.name, 'Jupiter'); + assert.equal((record as Record).attributes?.name, 'Jupiter'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3745,12 +3619,10 @@ module('JSONAPISource', function () { test('#query - record (304 response)', async function (assert) { assert.expect(3); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(304)); @@ -3777,12 +3649,10 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter' } }; - const planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet1 = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; const data2: Resource = { type: 'planet', @@ -3790,12 +3660,10 @@ module('JSONAPISource', function () { attributes: { name: 'Earth' } }; - const planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '1234' - }) as Record; + const planet2 = resourceSerializer.deserialize({ + type: 'planet', + id: '1234' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3804,14 +3672,14 @@ module('JSONAPISource', function () { .withArgs('/planets/1234') .returns(jsonapiResponse(200, { data: data2 })); - let records = await source.query((q) => [ + let records = (await source.query((q) => [ q.findRecord({ type: 'planet', id: planet1.id }), q.findRecord({ type: 'planet', id: planet2.id }) - ]); + ])) as Record[]; assert.ok(Array.isArray(records), 'multiple primary records returned'); - assert.equal((records[0] as Record).attributes.name, 'Jupiter'); - assert.equal((records[1] as Record).attributes.name, 'Earth'); + assert.equal(records[0].attributes?.name, 'Jupiter'); + assert.equal(records[1].attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 2, 'fetch called once'); assert.equal( @@ -3839,12 +3707,10 @@ module('JSONAPISource', function () { }; let responseDoc = { data, meta }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3878,12 +3744,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -3913,12 +3777,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; const options = { sources: { @@ -3949,12 +3811,10 @@ module('JSONAPISource', function () { test('#query - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -3979,12 +3839,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; const options = { sources: { @@ -4021,12 +3879,10 @@ module('JSONAPISource', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planet', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345?include=moons') @@ -4070,7 +3926,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4124,7 +3980,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth'] ); @@ -4164,7 +4020,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon'] ); @@ -4227,7 +4083,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -4280,7 +4136,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Mars'] ); @@ -4321,7 +4177,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -4362,7 +4218,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -4415,7 +4271,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -4460,7 +4316,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4475,12 +4331,10 @@ module('JSONAPISource', function () { test('#query - related records with attribute filter', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4518,7 +4372,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth'] ); @@ -4533,12 +4387,10 @@ module('JSONAPISource', function () { test('#query - related records with relatedRecord filter (single value)', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4569,7 +4421,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon'] ); @@ -4584,12 +4436,10 @@ module('JSONAPISource', function () { test('#query - related records with relatedRecord filter (multiple values)', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4639,7 +4489,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -4654,12 +4504,10 @@ module('JSONAPISource', function () { test('#query - related records with relatedRecords filter', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4699,7 +4547,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Mars'] ); @@ -4714,12 +4562,10 @@ module('JSONAPISource', function () { test('#query - related records with sort by an attribute in ascending order', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4747,7 +4593,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -4762,12 +4608,10 @@ module('JSONAPISource', function () { test('#query - related records with sort by an attribute in descending order', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4795,7 +4639,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -4810,12 +4654,10 @@ module('JSONAPISource', function () { test('#query - related records with sort by multiple fields', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4859,7 +4701,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -4874,12 +4716,10 @@ module('JSONAPISource', function () { test('#query - related records with pagination', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4913,7 +4753,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4932,12 +4772,10 @@ module('JSONAPISource', function () { .withArgs('/planets/earth/solar-system') .returns(jsonapiResponse(304)); - const earth = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: 'earth' - }) as Record; + const earth = resourceSerializer.deserialize({ + type: 'planet', + id: 'earth' + }) as Record; let records = await source.query((q) => q.findRelatedRecord({ type: 'planet', id: earth.id }, 'solarSystem') @@ -4960,12 +4798,10 @@ module('JSONAPISource', function () { .withArgs('/solar-systems/sun/planets') .returns(jsonapiResponse(304)); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solarSystem', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solarSystem', + id: 'sun' + }) as Record; let records = await source.query((q) => q.findRelatedRecords( @@ -5052,7 +4888,7 @@ module('JSONAPISource', function () { ['planet', 'planet'] ); assert.deepEqual( - records.map((planet) => planet.keys.remoteId), + records.map((planet) => planet.keys?.remoteId), ['1', '2'], 'returned IDs match primary data (including sorting)' ); @@ -5118,12 +4954,10 @@ module('JSONAPISource', function () { test('#query - relatedRecords', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planet', - id: 'jupiter' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planet', + id: 'jupiter' + }) as Record; let data = [ { @@ -5146,7 +4980,7 @@ module('JSONAPISource', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Io'] ); @@ -5161,12 +4995,14 @@ module('JSONAPISource', function () { test('#query - relatedRecords with include', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.ResourceIdentity) - .deserialize({ - type: 'planet', - id: 'jupiter' - }) as RecordIdentity; + const resourceIdentitySerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.ResourceIdentity + ) as JSONAPIResourceIdentitySerializer; + + const planet = resourceIdentitySerializer.deserialize({ + type: 'planet', + id: 'jupiter' + }) as RecordIdentity; const options = { sources: { @@ -5221,7 +5057,6 @@ module('JSONAPISource', function () { }); hooks.afterEach(function () { - schema = source = null; fetchStub.restore(); }); @@ -5305,9 +5140,7 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize(planetResource) as Record; + const planet = resourceSerializer.deserialize(planetResource) as Record; fetchStub.withArgs('/custom/path/here').returns( jsonapiResponse(201, { @@ -5433,9 +5266,7 @@ module('JSONAPISource', function () { attributes: { name: 'Jupiter' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize(planetResource) as Record; + const planet = resourceSerializer.deserialize(planetResource) as Record; fetchStub.withArgs('/custom/path/here').returns( jsonapiResponse(200, { diff --git a/packages/@orbit/jsonapi/test/jsonapi-source-with-legacy-serializer-settings-test.ts b/packages/@orbit/jsonapi/test/jsonapi-source-with-legacy-serializer-settings-test.ts index 72c83a481..5f24776b9 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-source-with-legacy-serializer-settings-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-source-with-legacy-serializer-settings-test.ts @@ -24,6 +24,8 @@ import { SinonStub } from 'sinon'; import * as sinon from 'sinon'; import { JSONAPISerializers } from '../src/serializers/jsonapi-serializers'; import { buildSerializerSettingsFor } from '@orbit/serializers'; +import { JSONAPIResourceSerializer } from '../src/serializers/jsonapi-resource-serializer'; +import { JSONAPIResourceIdentitySerializer } from '../src/serializers/jsonapi-resource-identity-serializer'; const { module, test } = QUnit; @@ -32,6 +34,7 @@ module('JSONAPISource with legacy serialization settings', function () { let keyMap: KeyMap; let schema: Schema; let source: JSONAPISource; + let resourceSerializer: JSONAPIResourceSerializer; const serializerSettingsFor = buildSerializerSettingsFor({ settingsByType: { @@ -117,10 +120,12 @@ module('JSONAPISource with legacy serialization settings', function () { keyMap, serializerSettingsFor }); + resourceSerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.Resource + ) as JSONAPIResourceSerializer; }); hooks.afterEach(() => { - keyMap = schema = source = null; fetchStub.restore(); }); @@ -195,7 +200,7 @@ module('JSONAPISource with legacy serialization settings', function () { headers: { Accept: 'application/json' }, - timeout: null + timeout: 0 } }); assert.deepEqual(customSource.requestProcessor.defaultFetchSettings, { @@ -203,7 +208,7 @@ module('JSONAPISource with legacy serialization settings', function () { Accept: 'application/json', 'Content-Type': 'application/vnd.api+json' }, - timeout: null + timeout: 0 }); }); @@ -212,12 +217,10 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -306,12 +309,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - will not issue fetch if beforePush listener logs transform', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; const t = buildTransform({ op: 'addRecord', @@ -333,12 +334,10 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -391,7 +390,7 @@ module('JSONAPISource with legacy serialization settings', function () { } else if (transformCount === 3) { let operationsWithoutId = transform.operations.map((op) => { let clonedOp = Object.assign({}, op) as RecordOperation; - delete clonedOp.record.id; + delete (clonedOp as any).record.id; return clonedOp; }); assert.deepEqual( @@ -454,12 +453,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - options can be passed in at the root level or source-specific level', async function (assert) { assert.expect(1); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; fetchStub.withArgs('/planets?include=moons').returns( jsonapiResponse(201, { @@ -493,16 +490,14 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let replacePlanetOp = { op: 'updateRecord', @@ -575,16 +570,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can replace a single attribute', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(204)); @@ -623,16 +616,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can accept remote changes', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns( jsonapiResponse(200, { @@ -656,7 +647,7 @@ module('JSONAPISource with legacy serialization settings', function () { ['replaceAttribute', 'replaceKey'] ); assert.deepEqual( - transforms[1].operations.map((o: ReplaceKeyOperation) => o.value), + transforms[1].operations.map((o) => (o as ReplaceKeyOperation).value), ['Mars', 'remote-id-123'] ); }); @@ -664,12 +655,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can delete records', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -692,19 +681,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can add a hasMany relationship with POST', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -734,19 +719,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can remove a relationship with DELETE', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -773,19 +754,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can update a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -828,12 +805,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } } as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/planets').returns( jsonapiResponse(201, { @@ -883,12 +858,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can clear a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -923,19 +896,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - can replace a hasMany relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -972,18 +941,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - a single transform can result in multiple requests', async function (assert) { assert.expect(6); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planets', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planets', + id: '2' + }) as Record; fetchStub.withArgs('/planets/1').returns(jsonapiResponse(200)); @@ -1024,18 +989,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - source can limit the number of allowed requests per transform with `maxRequestsPerTransform`', async function (assert) { assert.expect(1); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planets', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planets', + id: '2' + }) as Record; source.maxRequestsPerTransform = 1; @@ -1055,16 +1016,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - request can timeout', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -1087,16 +1046,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - allowed timeout can be specified per-request', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; const options = { sources: { @@ -1127,16 +1084,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -1154,16 +1109,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#push - response can trigger a ClientError', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let errors = [ { @@ -1193,12 +1146,10 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -1283,12 +1234,10 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - attributes: { name: 'Jupiter', classification: 'gas giant' } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + attributes: { name: 'Jupiter', classification: 'gas giant' } + }) as Record; let addPlanetOp = { op: 'addRecord', @@ -1341,7 +1290,7 @@ module('JSONAPISource with legacy serialization settings', function () { } else if (transformCount === 3) { let operationsWithoutId = transform.operations.map((op) => { let clonedOp = Object.assign({}, op) as RecordOperation; - delete clonedOp.record.id; + delete (clonedOp as any).record.id; return clonedOp; }); assert.deepEqual( @@ -1406,16 +1355,14 @@ module('JSONAPISource with legacy serialization settings', function () { let transformCount = 0; - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let replacePlanetOp = { op: 'updateRecord', @@ -1488,16 +1435,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can replace a single attribute', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(204)); @@ -1536,16 +1481,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can accept remote changes', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns( jsonapiResponse(200, { @@ -1574,7 +1517,7 @@ module('JSONAPISource with legacy serialization settings', function () { ['replaceAttribute', 'replaceKey'] ); assert.deepEqual( - transforms[1].operations.map((o: ReplaceKeyOperation) => o.value), + transforms[1].operations.map((o) => (o as ReplaceKeyOperation).value), ['Mars', 'remote-id-123'] ); assert.deepEqual(data, { @@ -1593,12 +1536,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can delete records', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -1621,19 +1562,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can add a hasMany relationship with POST', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -1663,19 +1600,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can remove a relationship with DELETE', async function (assert) { assert.expect(4); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub .withArgs('/planets/12345/relationships/moons') @@ -1702,19 +1635,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can update a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -1759,12 +1688,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/planets').returns( jsonapiResponse(201, { @@ -1814,12 +1741,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can clear a hasOne relationship with PATCH', async function (assert) { assert.expect(5); - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/moons/987').returns(jsonapiResponse(200)); @@ -1854,19 +1779,15 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - can replace a hasMany relationship with PATCH', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; - let moon = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'moons', - id: '987' - }) as Record; + let moon = resourceSerializer.deserialize({ + type: 'moons', + id: '987' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(200)); @@ -1903,18 +1824,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - a single transform can result in multiple requests', async function (assert) { assert.expect(6); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planets', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planets', + id: '2' + }) as Record; fetchStub.withArgs('/planets/1').returns(jsonapiResponse(200)); @@ -1955,18 +1872,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - source can limit the number of allowed requests per transform with `maxRequestsPerTransform`', async function (assert) { assert.expect(1); - let planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '1' - }) as Record; - let planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '2' - }) as Record; + let planet1 = resourceSerializer.deserialize({ + type: 'planets', + id: '1' + }) as Record; + let planet2 = resourceSerializer.deserialize({ + type: 'planets', + id: '2' + }) as Record; source.maxRequestsPerTransform = 1; @@ -1986,16 +1899,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - request can timeout', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -2018,16 +1929,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - allowed timeout can be specified per-request', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; const options = { sources: { @@ -2058,16 +1967,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -2085,16 +1992,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#update - response can trigger a ClientError', async function (assert) { assert.expect(3); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345', - attributes: { - name: 'Jupiter', - classification: 'gas giant' - } - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345', + attributes: { + name: 'Jupiter', + classification: 'gas giant' + } + }) as Record; let errors = [ { @@ -2128,12 +2033,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -2154,7 +2057,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter'] ); @@ -2170,12 +2073,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - record (with a 304 response)', async function (assert) { assert.expect(3); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(304)); @@ -2202,12 +2103,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -2237,12 +2136,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; const options = { sources: { @@ -2273,12 +2170,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -2303,12 +2198,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; const options = { sources: { @@ -2368,7 +2261,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Earth', 'Saturn'] ); @@ -2427,7 +2320,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth'] ); @@ -2481,7 +2374,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth'] ); @@ -2530,7 +2423,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Moon'] ); @@ -2602,7 +2495,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Moon', 'Phobos', 'Deimos'] ); @@ -2664,7 +2557,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Mars'] ); @@ -2714,7 +2607,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Earth', 'Jupiter', 'Saturn'] ); @@ -2764,7 +2657,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Saturn', 'Jupiter', 'Earth'] ); @@ -2826,7 +2719,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Saturn', 'Earth'] ); @@ -2880,7 +2773,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); assert.deepEqual( transforms[0].operations.map( - (o: UpdateRecordOperation) => o.record.attributes.name + (o) => (o as UpdateRecordOperation).record.attributes?.name ), ['Jupiter', 'Earth', 'Saturn'] ); @@ -2896,12 +2789,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - related records with attribute filter', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -2948,7 +2839,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Earth'); + assert.equal(op1.record.attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -2961,12 +2852,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - related records with attribute filters', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3007,7 +2896,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Earth'); + assert.equal(op1.record.attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3020,12 +2909,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with relatedRecord filter (single value)', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3065,7 +2952,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Moon'); + assert.equal(op1.record.attributes?.name, 'Moon'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3078,12 +2965,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with relatedRecord filter (multiple values)', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3152,7 +3037,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -3167,12 +3052,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with relatedRecords filter', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3221,7 +3104,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Mars'); + assert.equal(op1.record.attributes?.name, 'Mars'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3234,12 +3117,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with sort by an attribute in ascending order', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3286,7 +3167,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -3301,12 +3182,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with sort by an attribute in descending order', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3353,7 +3232,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -3368,12 +3247,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with sort by multiple fields', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3436,7 +3313,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -3451,12 +3328,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - records with pagination', async function (assert) { assert.expect(6); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -3509,7 +3384,7 @@ module('JSONAPISource with legacy serialization settings', function () { let op3 = transforms[0].operations[2] as UpdateRecordOperation; assert.deepEqual( - [op1, op2, op3].map((o) => o.record.attributes.name), + [op1, op2, op3].map((o) => o.record.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -3576,12 +3451,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - relatedRecord', async function (assert) { assert.expect(13); - const planetRecord = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: 'jupiter' - }) as Record; + const planetRecord = resourceSerializer.deserialize({ + type: 'planets', + id: 'jupiter' + }) as Record; const data: Resource = { type: 'solar-systems', @@ -3617,14 +3490,14 @@ module('JSONAPISource with legacy serialization settings', function () { const op1 = operations[0] as UpdateRecordOperation; assert.equal(op1.record.type, 'solarSystem'); assert.equal(op1.record.id, ssId); - assert.equal(op1.record.attributes.name, 'Our Solar System'); + assert.equal(op1.record.attributes?.name, 'Our Solar System'); const op2 = operations[1] as ReplaceRelatedRecordOperation; assert.equal(op2.record.type, 'planet'); assert.equal(op2.record.id, planetId); assert.equal(op2.relationship, 'solarSystem'); - assert.equal(op2.relatedRecord.type, 'solarSystem'); - assert.equal(op2.relatedRecord.id, ssId); + assert.equal(op2.relatedRecord?.type, 'solarSystem'); + assert.equal(op2.relatedRecord?.id, ssId); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3637,12 +3510,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - relatedRecords', async function (assert) { assert.expect(9); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: 'jupiter' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: 'jupiter' + }) as Record; let data = [ { @@ -3673,7 +3544,7 @@ module('JSONAPISource with legacy serialization settings', function () { ); const op1 = transforms[0].operations[0] as UpdateRecordOperation; - assert.equal(op1.record.attributes.name, 'Io'); + assert.equal(op1.record.attributes?.name, 'Io'); const op2 = transforms[0].operations[1] as ReplaceRelatedRecordsOperation; assert.equal(op2.record.id, planet.id); @@ -3694,12 +3565,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#pull - relatedRecords with include', async function (assert) { assert.expect(2); - const planetRecord = source.requestProcessor - .serializerFor(JSONAPISerializers.ResourceIdentity) - .deserialize({ - type: 'planets', - id: 'jupiter' - }) as RecordIdentity; + const resourceIdentitySerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.ResourceIdentity + ) as JSONAPIResourceIdentitySerializer; + + const planetRecord = resourceIdentitySerializer.deserialize({ + type: 'planets', + id: 'jupiter' + }) as RecordIdentity; const options = { sources: { @@ -3735,12 +3608,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter', classification: 'gas giant' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3754,7 +3625,7 @@ module('JSONAPISource with legacy serialization settings', function () { !Array.isArray(record), 'only a single primary record returned' ); - assert.equal((record as Record).attributes.name, 'Jupiter'); + assert.equal((record as Record).attributes?.name, 'Jupiter'); assert.equal(fetchStub.callCount, 1, 'fetch called once'); assert.equal( @@ -3767,12 +3638,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - record (304 response)', async function (assert) { assert.expect(3); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(jsonapiResponse(304)); @@ -3799,12 +3668,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter' } }; - const planet1 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet1 = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; const data2: Resource = { type: 'planets', @@ -3812,12 +3679,10 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Earth' } }; - const planet2 = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '1234' - }) as Record; + const planet2 = resourceSerializer.deserialize({ + type: 'planets', + id: '1234' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3832,8 +3697,8 @@ module('JSONAPISource with legacy serialization settings', function () { ]); assert.ok(Array.isArray(records), 'multiple primary records returned'); - assert.equal((records[0] as Record).attributes.name, 'Jupiter'); - assert.equal((records[1] as Record).attributes.name, 'Earth'); + assert.equal((records[0] as Record).attributes?.name, 'Jupiter'); + assert.equal((records[1] as Record).attributes?.name, 'Earth'); assert.equal(fetchStub.callCount, 2, 'fetch called once'); assert.equal( @@ -3861,12 +3726,10 @@ module('JSONAPISource with legacy serialization settings', function () { }; let responseDoc = { data, meta }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345') @@ -3900,12 +3763,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; // 10ms timeout source.requestProcessor.defaultFetchSettings.timeout = 10; @@ -3935,12 +3796,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; const options = { sources: { @@ -3971,12 +3830,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - fetch can reject with a NetworkError', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub.withArgs('/planets/12345').returns(Promise.reject(':(')); @@ -4001,12 +3858,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; const options = { sources: { @@ -4043,12 +3898,10 @@ module('JSONAPISource with legacy serialization settings', function () { relationships: { moons: { data: [] } } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: '12345' - }) as Record; + const planet = resourceSerializer.deserialize({ + type: 'planets', + id: '12345' + }) as Record; fetchStub .withArgs('/planets/12345?include=moons') @@ -4092,7 +3945,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4146,7 +3999,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth'] ); @@ -4186,7 +4039,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon'] ); @@ -4249,7 +4102,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -4302,7 +4155,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Mars'] ); @@ -4343,7 +4196,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -4384,7 +4237,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -4437,7 +4290,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -4482,7 +4335,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4497,12 +4350,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with attribute filter', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4540,7 +4391,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth'] ); @@ -4555,12 +4406,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with relatedRecord filter (single value)', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4591,7 +4440,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon'] ); @@ -4606,12 +4455,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with relatedRecord filter (multiple values)', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4661,7 +4508,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Moon', 'Phobos', 'Deimos'] ); @@ -4676,12 +4523,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with relatedRecords filter', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4721,7 +4566,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Mars'] ); @@ -4736,12 +4581,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with sort by an attribute in ascending order', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4769,7 +4612,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Earth', 'Jupiter', 'Saturn'] ); @@ -4784,12 +4627,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with sort by an attribute in descending order', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4817,7 +4658,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Saturn', 'Jupiter', 'Earth'] ); @@ -4832,12 +4673,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with sort by multiple fields', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4881,7 +4720,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Saturn', 'Earth'] ); @@ -4896,12 +4735,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - related records with pagination', async function (assert) { assert.expect(5); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; const data: Resource[] = [ { @@ -4935,7 +4772,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 3, 'three objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Jupiter', 'Earth', 'Saturn'] ); @@ -4954,12 +4791,10 @@ module('JSONAPISource with legacy serialization settings', function () { .withArgs('/planets/earth/solar-system') .returns(jsonapiResponse(304)); - const earth = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: 'earth' - }) as Record; + const earth = resourceSerializer.deserialize({ + type: 'planets', + id: 'earth' + }) as Record; let records = await source.query((q) => q.findRelatedRecord({ type: 'planet', id: earth.id }, 'solarSystem') @@ -4982,12 +4817,10 @@ module('JSONAPISource with legacy serialization settings', function () { .withArgs('/solar-systems/sun/planets') .returns(jsonapiResponse(304)); - const solarSystem = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'solar-systems', - id: 'sun' - }) as Record; + const solarSystem = resourceSerializer.deserialize({ + type: 'solar-systems', + id: 'sun' + }) as Record; let records = await source.query((q) => q.findRelatedRecords( @@ -5074,7 +4907,7 @@ module('JSONAPISource with legacy serialization settings', function () { ['planet', 'planet'] ); assert.deepEqual( - records.map((planet) => planet.keys.remoteId), + records.map((planet) => planet.keys?.remoteId), ['1', '2'], 'returned IDs match primary data (including sorting)' ); @@ -5140,12 +4973,10 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - relatedRecords', async function (assert) { assert.expect(5); - let planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize({ - type: 'planets', - id: 'jupiter' - }) as Record; + let planet = resourceSerializer.deserialize({ + type: 'planets', + id: 'jupiter' + }) as Record; let data = [ { @@ -5168,7 +4999,7 @@ module('JSONAPISource with legacy serialization settings', function () { assert.ok(Array.isArray(records), 'returned an array of data'); assert.equal(records.length, 1, 'one objects in data returned'); assert.deepEqual( - records.map((o) => o.attributes.name), + records.map((o) => o.attributes?.name), ['Io'] ); @@ -5183,12 +5014,14 @@ module('JSONAPISource with legacy serialization settings', function () { test('#query - relatedRecords with include', async function (assert) { assert.expect(2); - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.ResourceIdentity) - .deserialize({ - type: 'planets', - id: 'jupiter' - }) as RecordIdentity; + const resourceIdentitySerializer = source.requestProcessor.serializerFor( + JSONAPISerializers.ResourceIdentity + ) as JSONAPIResourceIdentitySerializer; + + const planet = resourceIdentitySerializer.deserialize({ + type: 'planets', + id: 'jupiter' + }) as RecordIdentity; const options = { sources: { @@ -5243,7 +5076,6 @@ module('JSONAPISource with legacy serialization settings', function () { }); hooks.afterEach(function () { - schema = source = null; fetchStub.restore(); }); @@ -5327,9 +5159,7 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize(planetResource) as Record; + const planet = resourceSerializer.deserialize(planetResource) as Record; fetchStub.withArgs('/custom/path/here').returns( jsonapiResponse(201, { @@ -5455,9 +5285,7 @@ module('JSONAPISource with legacy serialization settings', function () { attributes: { name: 'Jupiter' } }; - const planet = source.requestProcessor - .serializerFor(JSONAPISerializers.Resource) - .deserialize(planetResource) as Record; + const planet = resourceSerializer.deserialize(planetResource) as Record; fetchStub.withArgs('/custom/path/here').returns( jsonapiResponse(200, { diff --git a/packages/@orbit/jsonapi/test/jsonapi-url-builder-test.ts b/packages/@orbit/jsonapi/test/jsonapi-url-builder-test.ts index a1e46bd45..d5af763d2 100644 --- a/packages/@orbit/jsonapi/test/jsonapi-url-builder-test.ts +++ b/packages/@orbit/jsonapi/test/jsonapi-url-builder-test.ts @@ -65,10 +65,6 @@ module('JSONAPIURLBuilder', function (hooks) { urlBuilder = new JSONAPIURLBuilder({ serializerFor, keyMap }); }); - hooks.afterEach(() => { - keyMap = urlBuilder = null; - }); - test('it exists', function (assert) { assert.ok(urlBuilder); }); diff --git a/packages/@orbit/jsonapi/test/lib/query-requests-test.ts b/packages/@orbit/jsonapi/test/lib/query-requests-test.ts index 1d621e292..43f07c51c 100644 --- a/packages/@orbit/jsonapi/test/lib/query-requests-test.ts +++ b/packages/@orbit/jsonapi/test/lib/query-requests-test.ts @@ -60,7 +60,7 @@ module('QueryRequests', function (hooks) { }); requestProcessor = new JSONAPIRequestProcessor({ - keyMap: null, + keyMap: undefined, schema, sourceName: 'foo' }); @@ -69,7 +69,6 @@ module('QueryRequests', function (hooks) { }); hooks.afterEach(() => { - schema = requestProcessor = null; fetchStub.restore(); }); diff --git a/packages/@orbit/jsonapi/test/lib/transform-requests-test.ts b/packages/@orbit/jsonapi/test/lib/transform-requests-test.ts index b3e7dff50..c94e27c91 100644 --- a/packages/@orbit/jsonapi/test/lib/transform-requests-test.ts +++ b/packages/@orbit/jsonapi/test/lib/transform-requests-test.ts @@ -72,7 +72,6 @@ module('TransformRequests', function (/* hooks */) { }); hooks.afterEach(() => { - schema = requestProcessor = null; fetchStub.restore(); }); diff --git a/packages/@orbit/jsonapi/test/serializers/jsonapi-document-serializer-test.ts b/packages/@orbit/jsonapi/test/serializers/jsonapi-document-serializer-test.ts index 283a31084..bd88737f6 100644 --- a/packages/@orbit/jsonapi/test/serializers/jsonapi-document-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/serializers/jsonapi-document-serializer-test.ts @@ -55,10 +55,6 @@ module('JSONAPIDocumentSerializer', function (hooks) { serializer = new JSONAPIDocumentSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -611,10 +607,6 @@ module('JSONAPIDocumentSerializer', function (hooks) { serializer = new JSONAPIDocumentSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('serializer is assigned some standard serializers by default, and any custom serializers passed as settings', function (assert) { // default serializers assert.ok(serializer.serializerFor('boolean')); @@ -804,10 +796,6 @@ module('JSONAPIDocumentSerializer', function (hooks) { }); }); - hooks.afterEach(function () { - keyMap = serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -1077,8 +1065,8 @@ module('JSONAPIDocumentSerializer', function (hooks) { }); let planet = result.data as Record; - let moon = result.included[0]; - let solarSystem = result.included[1]; + let moon = result?.included?.[0] as Record; + let solarSystem = result?.included?.[1] as Record; assert.deepEqual( result, diff --git a/packages/@orbit/jsonapi/test/serializers/jsonapi-operation-serializer-test.ts b/packages/@orbit/jsonapi/test/serializers/jsonapi-operation-serializer-test.ts index 0afe2f100..6aa5324ee 100644 --- a/packages/@orbit/jsonapi/test/serializers/jsonapi-operation-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/serializers/jsonapi-operation-serializer-test.ts @@ -55,10 +55,6 @@ module('JSONAPIOperationSerializer', function (hooks) { serializer = new JSONAPIOperationSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -559,10 +555,6 @@ module('JSONAPIOperationSerializer', function (hooks) { serializer = new JSONAPIOperationSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('serializer is assigned some standard serializers by default, and any custom serializers passed as settings', function (assert) { // default serializers assert.ok(serializer.serializerFor('boolean')); @@ -707,10 +699,6 @@ module('JSONAPIOperationSerializer', function (hooks) { }); }); - hooks.afterEach(function () { - keyMap = serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); diff --git a/packages/@orbit/jsonapi/test/serializers/jsonapi-operations-document-serializer-test.ts b/packages/@orbit/jsonapi/test/serializers/jsonapi-operations-document-serializer-test.ts index 3de1c6513..d9994a97b 100644 --- a/packages/@orbit/jsonapi/test/serializers/jsonapi-operations-document-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/serializers/jsonapi-operations-document-serializer-test.ts @@ -52,10 +52,6 @@ module('JSONAPIOperationsDocumentSerializer', function (hooks) { }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); diff --git a/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-identity-serializer-test.ts b/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-identity-serializer-test.ts index b113d7930..901dba490 100644 --- a/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-identity-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-identity-serializer-test.ts @@ -54,10 +54,6 @@ module('JSONAPIResourceIdentitySerializer', function (hooks) { }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -104,10 +100,6 @@ module('JSONAPIResourceIdentitySerializer', function (hooks) { }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('#serialize - will use custom inflectors', function (assert) { assert.deepEqual( serializer.serialize({ @@ -192,10 +184,6 @@ module('JSONAPIResourceIdentitySerializer', function (hooks) { }); }); - hooks.afterEach(function () { - keyMap = serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); diff --git a/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-serializer-test.ts b/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-serializer-test.ts index 380e3fb54..5b4d30a5b 100644 --- a/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-serializer-test.ts +++ b/packages/@orbit/jsonapi/test/serializers/jsonapi-resource-serializer-test.ts @@ -58,10 +58,6 @@ module('JSONAPIResourceSerializer', function (hooks) { serializer = new JSONAPIResourceSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); @@ -557,10 +553,6 @@ module('JSONAPIResourceSerializer', function (hooks) { serializer = new JSONAPIResourceSerializer({ schema, serializerFor }); }); - hooks.afterEach(function () { - serializer = null; - }); - test('serializer is assigned some standard serializers by default, and any custom serializers passed as settings', function (assert) { // default serializers assert.ok(serializer.serializerFor('boolean')); @@ -743,10 +735,6 @@ module('JSONAPIResourceSerializer', function (hooks) { }); }); - hooks.afterEach(function () { - keyMap = serializer = null; - }); - test('it exists', function (assert) { assert.ok(serializer); }); diff --git a/packages/@orbit/jsonapi/test/support/jsonapi.ts b/packages/@orbit/jsonapi/test/support/jsonapi.ts index 3409ad090..cf61ec43f 100644 --- a/packages/@orbit/jsonapi/test/support/jsonapi.ts +++ b/packages/@orbit/jsonapi/test/support/jsonapi.ts @@ -38,7 +38,7 @@ export function jsonapiResponse( } } -function statusText(code: number): string { +function statusText(code: number): string | undefined { switch (code) { case 200: return 'OK'; diff --git a/packages/@orbit/local-storage/test/local-storage-source-test.ts b/packages/@orbit/local-storage/test/local-storage-source-test.ts index dd29515dc..1ff1959f4 100644 --- a/packages/@orbit/local-storage/test/local-storage-source-test.ts +++ b/packages/@orbit/local-storage/test/local-storage-source-test.ts @@ -51,7 +51,6 @@ module('LocalStorageSource', function (hooks) { hooks.afterEach(() => { return source.reset().then(() => { - schema = source = keyMap = null; Orbit.globals.localStorage.removeItem('orbit-bucket/foo'); }); }); @@ -354,13 +353,13 @@ module('LocalStorageSource', function (hooks) { t.addRecord(planet) ]); - let moons = (await getRecordFromLocalStorage(source, planet)).relationships - .moons.data as RecordIdentity[]; + let moons = (await getRecordFromLocalStorage(source, planet))?.relationships + ?.moons.data as RecordIdentity[]; assert.deepEqual(moons.length, 2, 'record has 2 moons'); await source.push((t) => t.removeRecord(moon1)); - moons = (await getRecordFromLocalStorage(source, planet)).relationships - .moons.data as RecordIdentity[]; + moons = (await getRecordFromLocalStorage(source, planet))?.relationships + ?.moons.data as RecordIdentity[]; assert.deepEqual(moons.length, 1, 'record has 1 moon'); }); @@ -1090,7 +1089,9 @@ module('LocalStorageSource', function (hooks) { 'operations match expectations' ); assert.deepEqual( - transforms[0].operations.map((o: AddRecordOperation) => o.record.type), + transforms[0].operations.map( + (o) => (o as AddRecordOperation)?.record?.type + ), ['planet', 'moon'], 'operations match expectations' ); diff --git a/packages/@orbit/memory/test/memory-cache-test.ts b/packages/@orbit/memory/test/memory-cache-test.ts index 4ad0d222a..5030c27ac 100644 --- a/packages/@orbit/memory/test/memory-cache-test.ts +++ b/packages/@orbit/memory/test/memory-cache-test.ts @@ -5,7 +5,8 @@ import { Schema, equalRecordIdentities, recordsInclude, - recordsIncludeAll + recordsIncludeAll, + RecordIdentity } from '@orbit/data'; import { clone } from '@orbit/utils'; import { MemoryCache } from '../src/memory-cache'; @@ -42,11 +43,6 @@ module('MemoryCache', function (hooks) { keyMap = new KeyMap(); }); - hooks.afterEach(function () { - schema = null; - keyMap = null; - }); - test('it exists', function (assert) { let cache = new MemoryCache({ schema }); @@ -210,7 +206,7 @@ module('MemoryCache', function (hooks) { cache1.reset(cache2); assert.strictEqual( - cache1.getRecordSync({ type: 'planet', id: '1' }).attributes.name, + cache1.getRecordSync({ type: 'planet', id: '1' })?.attributes?.name, 'Jupiter' ); }); @@ -308,12 +304,14 @@ module('MemoryCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + cache.getRecordSync({ type: 'moon', id: 'm1' })?.relationships?.planet + .data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm2' }).relationships.planet.data, + cache.getRecordSync({ type: 'moon', id: 'm2' })?.relationships?.planet + .data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Europa' ); @@ -327,12 +325,14 @@ module('MemoryCache', function (hooks) { ); assert.equal( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + cache.getRecordSync({ type: 'moon', id: 'm1' })?.relationships?.planet + .data, undefined, 'Jupiter has been cleared from Io' ); assert.equal( - cache.getRecordSync({ type: 'moon', id: 'm2' }).relationships.planet.data, + cache.getRecordSync({ type: 'moon', id: 'm2' })?.relationships?.planet + .data, undefined, 'Jupiter has been cleared from Europa' ); @@ -374,7 +374,7 @@ module('MemoryCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons + cache.getRecordSync({ type: 'planet', id: 'p1' })?.relationships?.moons .data, [ { type: 'moon', id: 'm1' }, @@ -383,10 +383,10 @@ module('MemoryCache', function (hooks) { 'Jupiter has been assigned to Io and Europa' ); assert.ok( - recordsIncludeAll(cache.getRelatedRecordsSync(jupiter, 'moons'), [ - io, - europa - ]), + recordsIncludeAll( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + [io, europa] + ), 'Jupiter has been assigned to Io and Europa' ); @@ -590,7 +590,10 @@ module('MemoryCache', function (hooks) { ); assert.ok( - recordsInclude(cache.getRelatedRecordsSync(jupiter, 'moons'), callisto), + recordsInclude( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + callisto + ), 'moon added' ); @@ -602,7 +605,10 @@ module('MemoryCache', function (hooks) { ); assert.notOk( - recordsInclude(cache.getRelatedRecordsSync(jupiter, 'moons'), callisto), + recordsInclude( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + callisto + ), 'moon removed' ); }); @@ -627,7 +633,7 @@ module('MemoryCache', function (hooks) { assert.ok( equalRecordIdentities( - cache.getRelatedRecordSync(callisto, 'planet'), + cache.getRelatedRecordSync(callisto, 'planet') as RecordIdentity, jupiter ), 'relationship added' @@ -637,7 +643,7 @@ module('MemoryCache', function (hooks) { assert.notOk( equalRecordIdentities( - cache.getRelatedRecordSync(callisto, 'planet'), + cache.getRelatedRecordSync(callisto, 'planet') as RecordIdentity, jupiter ), 'relationship cleared' @@ -729,17 +735,17 @@ module('MemoryCache', function (hooks) { }) ]); - const one = cache.getRecordSync({ type: 'one', id: '1' }); - const two = cache.getRecordSync({ type: 'two', id: '2' }); + const one = cache.getRecordSync({ type: 'one', id: '1' }) as Record; + const two = cache.getRecordSync({ type: 'two', id: '2' }) as Record; assert.ok(one, 'one exists'); assert.ok(two, 'two exists'); assert.deepEqual( - one.relationships.two.data, + one.relationships?.two.data, { type: 'two', id: '2' }, 'one links to two' ); assert.deepEqual( - two.relationships.one.data, + two.relationships?.one.data, { type: 'one', id: '1' }, 'two links to one' ); @@ -747,7 +753,7 @@ module('MemoryCache', function (hooks) { cache.patch((t) => t.removeRecord(two)); assert.equal( - cache.getRecordSync({ type: 'one', id: '1' }).relationships.two.data, + cache.getRecordSync({ type: 'one', id: '1' })?.relationships?.two.data, null, 'ones link to two got removed' ); @@ -1040,7 +1046,7 @@ module('MemoryCache', function (hooks) { assert, cache.query((q) => q.findRecords('planet').filter({ attribute: 'name', value: 'Jupiter' }) - ), + ) as Record[], [jupiter] ); }); @@ -1101,7 +1107,7 @@ module('MemoryCache', function (hooks) { cache.query((q) => { let tmp = q.findRecords('planet'); return tmp.filter({ attribute: 'sequence', value: 2, op: 'gt' }); - }), + }) as Record[], [earth, jupiter] ); arrayMembershipMatches( @@ -1109,7 +1115,7 @@ module('MemoryCache', function (hooks) { cache.query((q) => { let tmp = q.findRecords('planet'); return tmp.filter({ attribute: 'sequence', value: 2, op: 'gte' }); - }), + }) as Record[], [venus, earth, jupiter] ); arrayMembershipMatches( @@ -1117,7 +1123,7 @@ module('MemoryCache', function (hooks) { cache.query((q) => { let tmp = q.findRecords('planet'); return tmp.filter({ attribute: 'sequence', value: 2, op: 'lt' }); - }), + }) as Record[], [mercury] ); arrayMembershipMatches( @@ -1125,7 +1131,7 @@ module('MemoryCache', function (hooks) { cache.query((q) => { let tmp = q.findRecords('planet'); return tmp.filter({ attribute: 'sequence', value: 2, op: 'lte' }); - }), + }) as Record[], [venus, mercury] ); }); @@ -1254,7 +1260,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [theMoon], op: 'equal' }) - ), + ) as Record[], [earth] ); arrayMembershipMatches( @@ -1263,7 +1269,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'equal' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -1272,7 +1278,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'all' }) - ), + ) as Record[], [mars] ); arrayMembershipMatches( @@ -1281,7 +1287,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos, callisto], op: 'all' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -1292,7 +1298,7 @@ module('MemoryCache', function (hooks) { records: [phobos, callisto], op: 'some' }) - ), + ) as Record[], [mars, jupiter] ); arrayMembershipMatches( @@ -1301,7 +1307,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [titan], op: 'some' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -1310,7 +1316,7 @@ module('MemoryCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [ganymede], op: 'none' }) - ), + ) as Record[], [earth, mars] ); }); @@ -1437,21 +1443,21 @@ module('MemoryCache', function (hooks) { assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: earth }) - ), + ) as Record[], [theMoon] ); arrayMembershipMatches( assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: jupiter }) - ), + ) as Record[], [europa, ganymede, callisto] ); arrayMembershipMatches( assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: mercury }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -1460,7 +1466,7 @@ module('MemoryCache', function (hooks) { q .findRecords('moon') .filter({ relation: 'planet', record: [earth, mars] }) - ), + ) as Record[], [theMoon, phobos, deimos] ); }); @@ -1521,7 +1527,7 @@ module('MemoryCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); @@ -1574,7 +1580,7 @@ module('MemoryCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); diff --git a/packages/@orbit/memory/test/memory-source-test.ts b/packages/@orbit/memory/test/memory-source-test.ts index 1a71fa8ff..00bc7341a 100644 --- a/packages/@orbit/memory/test/memory-source-test.ts +++ b/packages/@orbit/memory/test/memory-source-test.ts @@ -221,7 +221,7 @@ module('MemorySource', function (hooks) { type: 'planetarySystem' }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star1.id, 'The original related record is in place.' ); @@ -236,7 +236,7 @@ module('MemorySource', function (hooks) { type: 'planetarySystem' }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star2.id, 'The related record was replaced.' ); @@ -260,7 +260,7 @@ module('MemorySource', function (hooks) { source.cache.patch((t) => t.addRecord(earth)); source.on('beforeUpdate', (transform: Transform, hints: any) => { - if (transform.options.customizeResults) { + if (transform?.options?.customizeResults) { hints.data = earth; } }); @@ -300,7 +300,7 @@ module('MemorySource', function (hooks) { }; source.on('beforeUpdate', (transform: Transform, hints: any) => { - if (transform.options.customizeResults) { + if (transform?.options?.customizeResults) { hints.data = [ { type: 'planet', id: 'uranus' }, { type: 'planet', id: 'jupiter' } @@ -350,7 +350,7 @@ module('MemorySource', function (hooks) { }; source.on('beforeUpdate', (transform: Transform, hints: any) => { - if (transform.options.customizeResults) { + if (transform?.options?.customizeResults) { hints.data = [ [ { type: 'planet', id: 'uranus' }, @@ -459,7 +459,7 @@ module('MemorySource', function (hooks) { source.on('beforeQuery', (query: Query, hints: any) => { if ( query.expressions[0].op === 'findRecords' && - query.options.sources.remote.customFilter === 'distantPlanets' + query.options?.sources?.remote.customFilter === 'distantPlanets' ) { hints.data = [ { type: 'planet', id: 'uranus' }, @@ -969,19 +969,25 @@ module('MemorySource', function (hooks) { // 4. make sure updates were successful assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); - assert.equal(source.cache.getRecordSync(id).attributes.name, 'Gassy Giant'); + assert.equal( + source.cache.getRecordSync(id)?.attributes?.name, + 'Gassy Giant' + ); // 5. do the rebase child.rebase(); assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); - assert.equal(source.cache.getRecordSync(id).attributes.name, 'Gassy Giant'); + assert.equal( + source.cache.getRecordSync(id)?.attributes?.name, + 'Gassy Giant' + ); }); test('#rebase - calling rebase multiple times', async function (assert) { @@ -1016,22 +1022,28 @@ module('MemorySource', function (hooks) { await source.update((t) => t.replaceAttribute(id, 'name', 'Gassy Giant')); // 4. make sure updates were successful assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); - assert.equal(source.cache.getRecordSync(id).attributes.name, 'Gassy Giant'); + assert.equal( + source.cache.getRecordSync(id)?.attributes?.name, + 'Gassy Giant' + ); // 5. do the rebase child.rebase(); assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); - assert.equal(source.cache.getRecordSync(id).attributes.name, 'Gassy Giant'); + assert.equal( + source.cache.getRecordSync(id)?.attributes?.name, + 'Gassy Giant' + ); // 6. do a second update to the parent source assert.equal( - source.cache.getRecordSync(id).attributes.classification, + source.cache.getRecordSync(id)?.attributes?.classification, 'gas giant' ); await source.update((t) => @@ -1045,15 +1057,15 @@ module('MemorySource', function (hooks) { ); // 7. make sure updates were successful assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); assert.equal( - source.cache.getRecordSync(id).attributes.name, + source.cache.getRecordSync(id)?.attributes?.name, 'Gassy Giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.classification, + source.cache.getRecordSync(id)?.attributes?.classification, 'gas giant II' ); @@ -1061,19 +1073,19 @@ module('MemorySource', function (hooks) { // make sure that changes from the child are still winning child.rebase(); assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); assert.equal( - child.cache.getRecordSync(id).attributes.classification, + child.cache.getRecordSync(id)?.attributes?.classification, 'gas giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.name, + source.cache.getRecordSync(id)?.attributes?.name, 'Gassy Giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.classification, + source.cache.getRecordSync(id)?.attributes?.classification, 'gas giant II' ); @@ -1083,19 +1095,19 @@ module('MemorySource', function (hooks) { ); // 10. make sure updates were successful assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); assert.equal( - child.cache.getRecordSync(id).attributes.classification, + child.cache.getRecordSync(id)?.attributes?.classification, 'gas giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.name, + source.cache.getRecordSync(id)?.attributes?.name, 'Gassy Giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.classification, + source.cache.getRecordSync(id)?.attributes?.classification, 'gas giant III' ); @@ -1103,20 +1115,20 @@ module('MemorySource', function (hooks) { // make sure that transforms from the parent are applied in correct order child.rebase(); assert.equal( - child.cache.getRecordSync(id).attributes.name, + child.cache.getRecordSync(id)?.attributes?.name, 'The Gas Giant' ); assert.equal( - child.cache.getRecordSync(id).attributes.classification, + child.cache.getRecordSync(id)?.attributes?.classification, 'gas giant III', 'classification has not been touched in child source => should be the same as in parent source' ); assert.equal( - source.cache.getRecordSync(id).attributes.name, + source.cache.getRecordSync(id)?.attributes?.name, 'Gassy Giant II' ); assert.equal( - source.cache.getRecordSync(id).attributes.classification, + source.cache.getRecordSync(id)?.attributes?.classification, 'gas giant III' ); }); diff --git a/packages/@orbit/record-cache/test/async-record-cache-test.ts b/packages/@orbit/record-cache/test/async-record-cache-test.ts index 275935d63..148d953b7 100644 --- a/packages/@orbit/record-cache/test/async-record-cache-test.ts +++ b/packages/@orbit/record-cache/test/async-record-cache-test.ts @@ -5,7 +5,8 @@ import { Schema, equalRecordIdentities, recordsInclude, - recordsIncludeAll + recordsIncludeAll, + RecordIdentity } from '@orbit/data'; import { AsyncSchemaValidationProcessor } from '../src/operation-processors/async-schema-validation-processor'; import { ExampleAsyncRecordCache } from './support/example-async-record-cache'; @@ -72,11 +73,6 @@ module('AsyncRecordCache', function (hooks) { keyMap = new KeyMap(); }); - hooks.afterEach(function () { - schema = null; - keyMap = null; - }); - test('it exists', async function (assert) { const cache = new ExampleAsyncRecordCache({ schema }); @@ -90,7 +86,8 @@ module('AsyncRecordCache', function (hooks) { test('it requires a schema', function (assert) { assert.expect(1); - assert.throws(() => new ExampleAsyncRecordCache({ schema: null })); + let schema = (undefined as unknown) as Schema; + assert.throws(() => new ExampleAsyncRecordCache({ schema })); }); test('can be assigned processors', async function (assert) { @@ -256,14 +253,16 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ + type: 'planet', + id: 'p1' + })) as Record)?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -283,14 +282,14 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -314,14 +313,14 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -345,14 +344,14 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -377,14 +376,14 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [], 'Jupiter has no moons' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, null, 'Jupiter has been cleared to Io' ); @@ -409,14 +408,14 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [], 'Io has been cleared from Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, null, 'Io has no planet' ); @@ -452,8 +451,8 @@ module('AsyncRecordCache', function (hooks) { ]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'star', id: 's1' })).relationships - .celestialObjects.data, + ((await cache.getRecordAsync({ type: 'star', id: 's1' })) as Record) + ?.relationships?.celestialObjects.data, [ { type: 'planet', id: 'p1' }, { type: 'moon', id: 'm1' } @@ -461,14 +460,14 @@ module('AsyncRecordCache', function (hooks) { 'Jupiter and Io has been assigned to Sun' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .star.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .star.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Io' ); @@ -498,8 +497,8 @@ module('AsyncRecordCache', function (hooks) { ]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'star', id: 's1' })).relationships - .celestialObjects.data, + ((await cache.getRecordAsync({ type: 'star', id: 's1' })) as Record) + ?.relationships?.celestialObjects.data, [ { type: 'planet', id: 'p1' }, { type: 'moon', id: 'm1' } @@ -507,14 +506,14 @@ module('AsyncRecordCache', function (hooks) { 'Jupiter and Io has been assigned to Sun' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .star.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Jupiter' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .star.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Io' ); @@ -549,14 +548,14 @@ module('AsyncRecordCache', function (hooks) { ]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'moon', id: 'm2' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm2' })) as Record) + ?.relationships?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Europa' ); @@ -570,14 +569,14 @@ module('AsyncRecordCache', function (hooks) { ); assert.equal( - (await cache.getRecordAsync({ type: 'moon', id: 'm1' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm1' })) as Record) + ?.relationships?.planet.data, undefined, 'Jupiter has been cleared from Io' ); assert.equal( - (await cache.getRecordAsync({ type: 'moon', id: 'm2' })).relationships - .planet.data, + ((await cache.getRecordAsync({ type: 'moon', id: 'm2' })) as Record) + ?.relationships?.planet.data, undefined, 'Jupiter has been cleared from Europa' ); @@ -619,8 +618,8 @@ module('AsyncRecordCache', function (hooks) { ]); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [ { type: 'moon', id: 'm1' }, { type: 'moon', id: 'm2' } @@ -628,10 +627,13 @@ module('AsyncRecordCache', function (hooks) { 'Jupiter has been assigned to Io and Europa' ); assert.ok( - recordsIncludeAll(await cache.getRelatedRecordsAsync(jupiter, 'moons'), [ - io, - europa - ]), + recordsIncludeAll( + (await cache.getRelatedRecordsAsync( + jupiter, + 'moons' + )) as RecordIdentity[], + [io, europa] + ), 'Jupiter has been assigned to Io and Europa' ); @@ -682,8 +684,8 @@ module('AsyncRecordCache', function (hooks) { ); assert.deepEqual( - (await cache.getRecordAsync({ type: 'planet', id: 'p1' })).relationships - .moons.data, + ((await cache.getRecordAsync({ type: 'planet', id: 'p1' })) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'relationship was added' ); @@ -853,7 +855,10 @@ module('AsyncRecordCache', function (hooks) { assert.ok( recordsInclude( - await cache.getRelatedRecordsAsync(jupiter, 'moons'), + (await cache.getRelatedRecordsAsync( + jupiter, + 'moons' + )) as RecordIdentity[], callisto ), 'moon added' @@ -868,7 +873,10 @@ module('AsyncRecordCache', function (hooks) { assert.notOk( recordsInclude( - await cache.getRelatedRecordsAsync(jupiter, 'moons'), + (await cache.getRelatedRecordsAsync( + jupiter, + 'moons' + )) as RecordIdentity[], callisto ), 'moon removed' @@ -895,7 +903,10 @@ module('AsyncRecordCache', function (hooks) { assert.ok( equalRecordIdentities( - await cache.getRelatedRecordAsync(callisto, 'planet'), + (await cache.getRelatedRecordAsync( + callisto, + 'planet' + )) as RecordIdentity, jupiter ), 'relationship added' @@ -905,7 +916,10 @@ module('AsyncRecordCache', function (hooks) { assert.notOk( equalRecordIdentities( - await cache.getRelatedRecordAsync(callisto, 'planet'), + (await cache.getRelatedRecordAsync( + callisto, + 'planet' + )) as RecordIdentity, jupiter ), 'relationship cleared' @@ -997,17 +1011,23 @@ module('AsyncRecordCache', function (hooks) { }) ]); - const one = await cache.getRecordAsync({ type: 'one', id: '1' }); - const two = await cache.getRecordAsync({ type: 'two', id: '2' }); + const one = (await cache.getRecordAsync({ + type: 'one', + id: '1' + })) as Record; + const two = (await cache.getRecordAsync({ + type: 'two', + id: '2' + })) as Record; assert.ok(one, 'one exists'); assert.ok(two, 'two exists'); assert.deepEqual( - one.relationships.two.data, + one.relationships?.two.data, { type: 'two', id: '2' }, 'one links to two' ); assert.deepEqual( - two.relationships.one.data, + two.relationships?.one.data, { type: 'one', id: '1' }, 'two links to one' ); @@ -1015,8 +1035,8 @@ module('AsyncRecordCache', function (hooks) { await cache.patch((t) => t.removeRecord(two)); assert.equal( - (await cache.getRecordAsync({ type: 'one', id: '1' })).relationships.two - .data, + ((await cache.getRecordAsync({ type: 'one', id: '1' })) as Record) + ?.relationships?.two.data, null, 'ones link to two got removed' ); @@ -1476,7 +1496,7 @@ module('AsyncRecordCache', function (hooks) { const planet = await cache.getRecordAsync({ type: 'planet', id: '1' }); assert.ok(planet, 'planet exists'); assert.deepEqual( - planet.relationships.moons.data, + planet?.relationships?.moons.data, [], 'planet has empty moons relationship' ); @@ -1527,7 +1547,7 @@ module('AsyncRecordCache', function (hooks) { const planet = await cache.getRecordAsync({ type: 'planet', id: '1' }); assert.ok(planet, 'planet exists'); assert.deepEqual( - planet.relationships.moons.data, + planet?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'planet has a moons relationship' ); @@ -1572,7 +1592,7 @@ module('AsyncRecordCache', function (hooks) { type: 'planetarySystem' }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star1.id, 'The original related record is in place.' ); @@ -1595,7 +1615,7 @@ module('AsyncRecordCache', function (hooks) { }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star2.id, 'The related record was replaced.' ); @@ -1702,7 +1722,7 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => q.findRecords('planet')), + (await cache.query((q) => q.findRecords('planet'))) as Record[], [jupiter, earth, venus, mercury] ); }); @@ -1756,13 +1776,13 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords([ { type: 'planet', id: 'jupiter' }, { type: 'planet', id: 'venus' }, { type: 'planet', id: 'FAKE' } ]) - ), + )) as Record[], [jupiter, venus] ); }); @@ -1816,9 +1836,9 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('planet').filter({ attribute: 'name', value: 'Jupiter' }) - ), + )) as Record[], [jupiter] ); }); @@ -1875,50 +1895,50 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'gt' }) - ), + )) as Record[], [earth, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'gte' }) - ), + )) as Record[], [venus, earth, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'lt' }) - ), + )) as Record[], [mercury] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'lte' }) - ), + )) as Record[], [venus, mercury] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter( { attribute: 'sequence', value: 2, op: 'gte' }, { attribute: 'sequence', value: 4, op: 'lt' } ) - ), + )) as Record[], [venus, earth] ); }); @@ -2042,67 +2062,67 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [theMoon], op: 'equal' }) - ), + )) as Record[], [earth] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'equal' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'all' }) - ), + )) as Record[], [mars] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [phobos, callisto], op: 'all' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('planet').filter({ relation: 'moons', records: [phobos, callisto], op: 'some' }) - ), + )) as Record[], [mars, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [titan], op: 'some' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter({ relation: 'moons', records: [ganymede], op: 'none' }) - ), + )) as Record[], [earth, mars] ); }); @@ -2226,39 +2246,39 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: null }) - ), + )) as Record[], [titan] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: earth }) - ), + )) as Record[], [theMoon] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: jupiter }) - ), + )) as Record[], [europa, ganymede, callisto] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: mercury }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('moon') .filter({ relation: 'planet', record: [earth, mars] }) - ), + )) as Record[], [theMoon, phobos, deimos] ); }); @@ -2312,14 +2332,14 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter( { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + )) as Record[], [earth, venus] ); }); @@ -2365,14 +2385,14 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRecords('planet') .filter( { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + )) as Record[], [earth, venus] ); }); @@ -2935,11 +2955,11 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'name', value: 'Jupiter' }) - ), + )) as Record[], [jupiter] ); }); @@ -3016,38 +3036,38 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'gt' }) - ), + )) as Record[], [earth, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'gte' }) - ), + )) as Record[], [venus, earth, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'lt' }) - ), + )) as Record[], [mercury] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'lte' }) - ), + )) as Record[], [venus, mercury] ); }); @@ -3193,67 +3213,67 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [theMoon], op: 'equal' }) - ), + )) as Record[], [earth] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos], op: 'equal' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos], op: 'all' }) - ), + )) as Record[], [mars] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos, callisto], op: 'all' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q.findRelatedRecords(sun, 'celestialObjects').filter({ relation: 'moons', records: [phobos, callisto], op: 'some' }) - ), + )) as Record[], [mars, jupiter] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [titan], op: 'some' }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [ganymede], op: 'none' }) - ), + )) as Record[], [earth, mars] ); }); @@ -3426,47 +3446,47 @@ module('AsyncRecordCache', function (hooks) { ]); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'planet', record: null }) - ), + )) as Record[], [titan] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(earth, 'moons') .filter({ relation: 'planet', record: earth }) - ), + )) as Record[], [theMoon] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(jupiter, 'moons') .filter({ relation: 'planet', record: jupiter }) - ), + )) as Record[], [europa, ganymede, callisto] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(mercury, 'moons') .filter({ relation: 'planet', record: mercury }) - ), + )) as Record[], [] ); arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'planet', record: [earth, mars] }) - ), + )) as Record[], [theMoon, phobos, deimos] ); }); @@ -3540,14 +3560,14 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter( { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + )) as Record[], [earth, venus] ); }); @@ -3616,14 +3636,14 @@ module('AsyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - await cache.query((q) => + (await cache.query((q) => q .findRelatedRecords(sun, 'celestialObjects') .filter( { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + )) as Record[], [earth, venus] ); }); @@ -4126,7 +4146,7 @@ module('AsyncRecordCache', function (hooks) { resolve?: () => void; reject?: (message: string) => void; } - function defer() { + function defer(): Deferred { let defer: Deferred = {}; defer.promise = new Promise((resolve, reject) => { defer.resolve = resolve; @@ -4142,16 +4162,16 @@ module('AsyncRecordCache', function (hooks) { function next() { if (n === 1 && i === 1 && j === 0 && k === 0) { - jupiterAdded.resolve(); + jupiterAdded.resolve?.(); } if (n === 2 && i === 2 && j === 0 && k === 0) { - jupiterUpdated.resolve(); + jupiterUpdated.resolve?.(); } if (n === 3 && i === 3 && j === 1 && k === 1) { - callistoAdded.resolve(); + callistoAdded.resolve?.(); } if (n === 4 && i === 4 && j === 2 && k === 2) { - jupiterRemoved.resolve(); + jupiterRemoved.resolve?.(); } } @@ -4278,10 +4298,10 @@ module('AsyncRecordCache', function (hooks) { }); setTimeout(() => { - jupiterAdded.reject('reject jupiterAdded'); - jupiterUpdated.reject('reject jupiterUpdated'); - callistoAdded.reject('reject callistoAdded'); - jupiterRemoved.reject('reject jupiterRemoved'); + jupiterAdded.reject?.('reject jupiterAdded'); + jupiterUpdated.reject?.('reject jupiterUpdated'); + callistoAdded.reject?.('reject callistoAdded'); + jupiterRemoved.reject?.('reject jupiterRemoved'); }, 500); await cache.patch((t) => t.addRecord(jupiter)); @@ -4455,13 +4475,13 @@ module('AsyncRecordCache', function (hooks) { const done = assert.async(); livePlanets.subscribe(async (update) => { - const result = await update.query(); + const result = (await update.query()) as Record[]; arrayMembershipMatches(assert, result, [venus, earth]); done(); }); // liveQuery results are initially empty - arrayMembershipMatches(assert, await livePlanets.query(), []); + arrayMembershipMatches(assert, (await livePlanets.query()) as Record[], []); // adding records should update liveQuery results cache.patch((t) => [ diff --git a/packages/@orbit/record-cache/test/operation-processors/cache-integrity-processor-test.ts b/packages/@orbit/record-cache/test/operation-processors/cache-integrity-processor-test.ts index 415be8ce3..8ae139e7d 100644 --- a/packages/@orbit/record-cache/test/operation-processors/cache-integrity-processor-test.ts +++ b/packages/@orbit/record-cache/test/operation-processors/cache-integrity-processor-test.ts @@ -74,12 +74,6 @@ module('CacheIntegrityProcessor', function (hooks) { processor = cache.processors[0] as SyncCacheIntegrityProcessor; }); - hooks.afterEach(function () { - schema = null; - cache = null; - processor = null; - }); - test('reset empty cache', function (assert) { const saturn = { type: 'planet', diff --git a/packages/@orbit/record-cache/test/operation-processors/schema-consistency-processor-test.ts b/packages/@orbit/record-cache/test/operation-processors/schema-consistency-processor-test.ts index 87fa8c399..962d1983b 100644 --- a/packages/@orbit/record-cache/test/operation-processors/schema-consistency-processor-test.ts +++ b/packages/@orbit/record-cache/test/operation-processors/schema-consistency-processor-test.ts @@ -70,12 +70,6 @@ module('SchemaConsistencyProcessor', function (hooks) { processor = cache.processors[1] as SyncSchemaConsistencyProcessor; }); - hooks.afterEach(function () { - schema = null; - cache = null; - processor = null; - }); - test('add to hasOne => hasMany', function (assert) { const saturn = { type: 'planet', diff --git a/packages/@orbit/record-cache/test/operation-processors/schema-validation-processor-test.ts b/packages/@orbit/record-cache/test/operation-processors/schema-validation-processor-test.ts index c7fdc2028..1ce3fa49b 100644 --- a/packages/@orbit/record-cache/test/operation-processors/schema-validation-processor-test.ts +++ b/packages/@orbit/record-cache/test/operation-processors/schema-validation-processor-test.ts @@ -68,11 +68,6 @@ module('SchemaValidationProcessor', function (hooks) { }); }); - hooks.afterEach(function () { - schema = null; - cache = null; - }); - test('addRecord with an unknown model type', (assert) => { assert.throws(() => { cache.patch((t) => t.addRecord(unknown)); diff --git a/packages/@orbit/record-cache/test/support/example-async-record-cache.ts b/packages/@orbit/record-cache/test/support/example-async-record-cache.ts index 0762c0478..b9bd2f926 100644 --- a/packages/@orbit/record-cache/test/support/example-async-record-cache.ts +++ b/packages/@orbit/record-cache/test/support/example-async-record-cache.ts @@ -26,8 +26,8 @@ export class ExampleAsyncRecordCache extends AsyncRecordCache { }); } - async getRecordAsync(identity: RecordIdentity): Promise { - return deepGet(this._records, [identity.type, identity.id]) || null; + async getRecordAsync(identity: RecordIdentity): Promise { + return deepGet(this._records, [identity.type, identity.id]); } async getRecordsAsync( @@ -45,6 +45,8 @@ export class ExampleAsyncRecordCache extends AsyncRecordCache { } } return records; + } else { + throw new Error('typeOrIdentities must be specified in getRecordsAsync'); } } @@ -60,13 +62,13 @@ export class ExampleAsyncRecordCache extends AsyncRecordCache { async removeRecordAsync( recordIdentity: RecordIdentity - ): Promise { + ): Promise { const record = await this.getRecordAsync(recordIdentity); if (record) { delete this._records[recordIdentity.type][recordIdentity.id]; return record; } else { - return null; + return undefined; } } diff --git a/packages/@orbit/record-cache/test/support/example-sync-record-cache.ts b/packages/@orbit/record-cache/test/support/example-sync-record-cache.ts index 72e104967..c64a435fc 100644 --- a/packages/@orbit/record-cache/test/support/example-sync-record-cache.ts +++ b/packages/@orbit/record-cache/test/support/example-sync-record-cache.ts @@ -26,7 +26,7 @@ export class ExampleSyncRecordCache extends SyncRecordCache { }); } - getRecordSync(identity: RecordIdentity): Record | null { + getRecordSync(identity: RecordIdentity): Record | undefined { return deepGet(this._records, [identity.type, identity.id]) || null; } @@ -43,6 +43,8 @@ export class ExampleSyncRecordCache extends SyncRecordCache { } } return records; + } else { + throw new Error('typeOrIdentities must be specified in getRecordsSync'); } } @@ -56,13 +58,13 @@ export class ExampleSyncRecordCache extends SyncRecordCache { } } - removeRecordSync(recordIdentity: RecordIdentity): Record | null { + removeRecordSync(recordIdentity: RecordIdentity): Record | undefined { const record = this.getRecordSync(recordIdentity); if (record) { delete this._records[recordIdentity.type][recordIdentity.id]; return record; } else { - return null; + return undefined; } } diff --git a/packages/@orbit/record-cache/test/sync-record-cache-test.ts b/packages/@orbit/record-cache/test/sync-record-cache-test.ts index 4e7c4e2ae..11f10e8a7 100644 --- a/packages/@orbit/record-cache/test/sync-record-cache-test.ts +++ b/packages/@orbit/record-cache/test/sync-record-cache-test.ts @@ -5,7 +5,8 @@ import { equalRecordIdentities, recordsInclude, recordsIncludeAll, - Record + Record, + RecordIdentity } from '@orbit/data'; import { SyncSchemaValidationProcessor } from '../src/operation-processors/sync-schema-validation-processor'; import { ExampleSyncRecordCache } from './support/example-sync-record-cache'; @@ -72,11 +73,6 @@ module('SyncRecordCache', function (hooks) { keyMap = new KeyMap(); }); - hooks.afterEach(function () { - schema = null; - keyMap = null; - }); - test('it exists', function (assert) { const cache = new ExampleSyncRecordCache({ schema }); @@ -90,7 +86,8 @@ module('SyncRecordCache', function (hooks) { test('it requires a schema', function (assert) { assert.expect(1); - assert.throws(() => new ExampleSyncRecordCache({ schema: null })); + let schema = (undefined as unknown) as Schema; + assert.throws(() => new ExampleSyncRecordCache({ schema })); }); test('can be assigned processors', function (assert) { @@ -253,13 +250,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -279,13 +277,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -309,13 +308,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -339,13 +339,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'Io has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); @@ -370,13 +371,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(io), t.updateRecord(jupiter)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [], 'Jupiter has no moons' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, null, 'Jupiter has been cleared from Io' ); @@ -401,13 +403,14 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => [t.updateRecord(jupiter), t.updateRecord(io)]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [], 'Io has been cleared from Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, null, 'Io has no planet' ); @@ -443,8 +446,8 @@ module('SyncRecordCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'star', id: 's1' }).relationships - .celestialObjects.data, + (cache.getRecordSync({ type: 'star', id: 's1' }) as Record)?.relationships + ?.celestialObjects.data, [ { type: 'planet', id: 'p1' }, { type: 'moon', id: 'm1' } @@ -452,12 +455,14 @@ module('SyncRecordCache', function (hooks) { 'Jupiter and Io has been assigned to Sun' ); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.star.data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.star.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Io' ); @@ -487,8 +492,8 @@ module('SyncRecordCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'star', id: 's1' }).relationships - .celestialObjects.data, + (cache.getRecordSync({ type: 'star', id: 's1' }) as Record)?.relationships + ?.celestialObjects.data, [ { type: 'planet', id: 'p1' }, { type: 'moon', id: 'm1' } @@ -496,12 +501,14 @@ module('SyncRecordCache', function (hooks) { 'Jupiter and Io has been assigned to Sun' ); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.star.data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Jupiter' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.star.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.star.data, { type: 'star', id: 's1' }, 'Sun has been assigned to Io' ); @@ -536,12 +543,14 @@ module('SyncRecordCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Io' ); assert.deepEqual( - cache.getRecordSync({ type: 'moon', id: 'm2' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm2' }) as Record)?.relationships + ?.planet.data, { type: 'planet', id: 'p1' }, 'Jupiter has been assigned to Europa' ); @@ -555,12 +564,14 @@ module('SyncRecordCache', function (hooks) { ); assert.equal( - cache.getRecordSync({ type: 'moon', id: 'm1' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm1' }) as Record)?.relationships + ?.planet.data, undefined, 'Jupiter has been cleared from Io' ); assert.equal( - cache.getRecordSync({ type: 'moon', id: 'm2' }).relationships.planet.data, + (cache.getRecordSync({ type: 'moon', id: 'm2' }) as Record)?.relationships + ?.planet.data, undefined, 'Jupiter has been cleared from Europa' ); @@ -602,8 +613,8 @@ module('SyncRecordCache', function (hooks) { ]); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [ { type: 'moon', id: 'm1' }, { type: 'moon', id: 'm2' } @@ -611,10 +622,10 @@ module('SyncRecordCache', function (hooks) { 'Jupiter has been assigned to Io and Europa' ); assert.ok( - recordsIncludeAll(cache.getRelatedRecordsSync(jupiter, 'moons'), [ - io, - europa - ]), + recordsIncludeAll( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + [io, europa] + ), 'Jupiter has been assigned to Io and Europa' ); @@ -635,7 +646,10 @@ module('SyncRecordCache', function (hooks) { ); assert.deepEqual( - cache.getRelatedRecordsSync({ type: 'planet', id: 'p1' }, 'moons'), + cache.getRelatedRecordsSync( + { type: 'planet', id: 'p1' }, + 'moons' + ) as RecordIdentity[], [], 'moons have been cleared from Jupiter' ); @@ -659,8 +673,8 @@ module('SyncRecordCache', function (hooks) { ); assert.deepEqual( - cache.getRecordSync({ type: 'planet', id: 'p1' }).relationships.moons - .data, + (cache.getRecordSync({ type: 'planet', id: 'p1' }) as Record) + ?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'relationship was added' ); @@ -826,7 +840,10 @@ module('SyncRecordCache', function (hooks) { ); assert.ok( - recordsInclude(cache.getRelatedRecordsSync(jupiter, 'moons'), callisto), + recordsInclude( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + callisto + ), 'moon added' ); @@ -838,7 +855,10 @@ module('SyncRecordCache', function (hooks) { ); assert.notOk( - recordsInclude(cache.getRelatedRecordsSync(jupiter, 'moons'), callisto), + recordsInclude( + cache.getRelatedRecordsSync(jupiter, 'moons') as RecordIdentity[], + callisto + ), 'moon removed' ); }); @@ -863,7 +883,7 @@ module('SyncRecordCache', function (hooks) { assert.ok( equalRecordIdentities( - cache.getRelatedRecordSync(callisto, 'planet'), + cache.getRelatedRecordSync(callisto, 'planet') as RecordIdentity, jupiter ), 'relationship added' @@ -873,7 +893,7 @@ module('SyncRecordCache', function (hooks) { assert.notOk( equalRecordIdentities( - cache.getRelatedRecordSync(callisto, 'planet'), + cache.getRelatedRecordSync(callisto, 'planet') as RecordIdentity, jupiter ), 'relationship cleared' @@ -965,17 +985,17 @@ module('SyncRecordCache', function (hooks) { }) ]); - const one = cache.getRecordSync({ type: 'one', id: '1' }); - const two = cache.getRecordSync({ type: 'two', id: '2' }); + const one = cache.getRecordSync({ type: 'one', id: '1' }) as Record; + const two = cache.getRecordSync({ type: 'two', id: '2' }) as Record; assert.ok(one, 'one exists'); assert.ok(two, 'two exists'); assert.deepEqual( - one.relationships.two.data, + one.relationships?.two.data, { type: 'two', id: '2' }, 'one links to two' ); assert.deepEqual( - two.relationships.one.data, + two.relationships?.one.data, { type: 'one', id: '1' }, 'two links to one' ); @@ -983,7 +1003,8 @@ module('SyncRecordCache', function (hooks) { cache.patch((t) => t.removeRecord(two)); assert.equal( - cache.getRecordSync({ type: 'one', id: '1' }).relationships.two.data, + (cache.getRecordSync({ type: 'one', id: '1' }) as Record).relationships + ?.two.data, null, 'ones link to two got removed' ); @@ -1443,7 +1464,7 @@ module('SyncRecordCache', function (hooks) { const planet = cache.getRecordSync({ type: 'planet', id: '1' }); assert.ok(planet, 'planet exists'); assert.deepEqual( - planet.relationships.moons.data, + planet?.relationships?.moons.data, [], 'planet has empty moons relationship' ); @@ -1494,7 +1515,7 @@ module('SyncRecordCache', function (hooks) { const planet = cache.getRecordSync({ type: 'planet', id: '1' }); assert.ok(planet, 'planet exists'); assert.deepEqual( - planet.relationships.moons.data, + planet?.relationships?.moons.data, [{ type: 'moon', id: 'm1' }], 'planet has a moons relationship' ); @@ -1539,7 +1560,7 @@ module('SyncRecordCache', function (hooks) { type: 'planetarySystem' }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star1.id, 'The original related record is in place.' ); @@ -1562,7 +1583,7 @@ module('SyncRecordCache', function (hooks) { }); assert.deepEqual( - (latestHome.relationships.star.data as Record).id, + (latestHome?.relationships?.star.data as Record).id, star2.id, 'The related record was replaced.' ); @@ -1669,7 +1690,7 @@ module('SyncRecordCache', function (hooks) { arrayMembershipMatches( assert, - cache.query((q) => q.findRecords('planet')), + cache.query((q) => q.findRecords('planet')) as Record[], [jupiter, earth, venus, mercury] ); }); @@ -1729,7 +1750,7 @@ module('SyncRecordCache', function (hooks) { { type: 'planet', id: 'venus' }, { type: 'planet', id: 'FAKE' } ]) - ), + ) as Record[], [jupiter, venus] ); }); @@ -1785,7 +1806,7 @@ module('SyncRecordCache', function (hooks) { assert, cache.query((q) => q.findRecords('planet').filter({ attribute: 'name', value: 'Jupiter' }) - ), + ) as Record[], [jupiter] ); }); @@ -1846,7 +1867,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'gt' }) - ), + ) as Record[], [earth, jupiter] ); arrayMembershipMatches( @@ -1855,7 +1876,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'gte' }) - ), + ) as Record[], [venus, earth, jupiter] ); arrayMembershipMatches( @@ -1864,7 +1885,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'lt' }) - ), + ) as Record[], [mercury] ); arrayMembershipMatches( @@ -1873,7 +1894,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ attribute: 'sequence', value: 2, op: 'lte' }) - ), + ) as Record[], [venus, mercury] ); arrayMembershipMatches( @@ -1885,7 +1906,7 @@ module('SyncRecordCache', function (hooks) { { attribute: 'sequence', value: 2, op: 'gte' }, { attribute: 'sequence', value: 4, op: 'lt' } ) - ), + ) as Record[], [venus, earth] ); }); @@ -2013,7 +2034,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [theMoon], op: 'equal' }) - ), + ) as Record[], [earth] ); arrayMembershipMatches( @@ -2022,7 +2043,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'equal' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -2031,7 +2052,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos], op: 'all' }) - ), + ) as Record[], [mars] ); arrayMembershipMatches( @@ -2040,7 +2061,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [phobos, callisto], op: 'all' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -2051,7 +2072,7 @@ module('SyncRecordCache', function (hooks) { records: [phobos, callisto], op: 'some' }) - ), + ) as Record[], [mars, jupiter] ); arrayMembershipMatches( @@ -2060,7 +2081,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [titan], op: 'some' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -2069,7 +2090,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('planet') .filter({ relation: 'moons', records: [ganymede], op: 'none' }) - ), + ) as Record[], [earth, mars] ); }); @@ -2195,28 +2216,28 @@ module('SyncRecordCache', function (hooks) { assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: null }) - ), + ) as Record[], [titan] ); arrayMembershipMatches( assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: earth }) - ), + ) as Record[], [theMoon] ); arrayMembershipMatches( assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: jupiter }) - ), + ) as Record[], [europa, ganymede, callisto] ); arrayMembershipMatches( assert, cache.query((q) => q.findRecords('moon').filter({ relation: 'planet', record: mercury }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -2225,7 +2246,7 @@ module('SyncRecordCache', function (hooks) { q .findRecords('moon') .filter({ relation: 'planet', record: [earth, mars] }) - ), + ) as Record[], [theMoon, phobos, deimos] ); }); @@ -2286,7 +2307,7 @@ module('SyncRecordCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); @@ -2339,7 +2360,7 @@ module('SyncRecordCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); @@ -2906,7 +2927,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'name', value: 'Jupiter' }) - ), + ) as Record[], [jupiter] ); }); @@ -2987,7 +3008,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'gt' }) - ), + ) as Record[], [earth, jupiter] ); arrayMembershipMatches( @@ -2996,7 +3017,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'gte' }) - ), + ) as Record[], [venus, earth, jupiter] ); arrayMembershipMatches( @@ -3005,7 +3026,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'lt' }) - ), + ) as Record[], [mercury] ); arrayMembershipMatches( @@ -3014,7 +3035,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ attribute: 'sequence', value: 2, op: 'lte' }) - ), + ) as Record[], [venus, mercury] ); }); @@ -3164,7 +3185,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [theMoon], op: 'equal' }) - ), + ) as Record[], [earth] ); arrayMembershipMatches( @@ -3173,7 +3194,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos], op: 'equal' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -3182,7 +3203,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos], op: 'all' }) - ), + ) as Record[], [mars] ); arrayMembershipMatches( @@ -3191,7 +3212,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [phobos, callisto], op: 'all' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -3202,7 +3223,7 @@ module('SyncRecordCache', function (hooks) { records: [phobos, callisto], op: 'some' }) - ), + ) as Record[], [mars, jupiter] ); arrayMembershipMatches( @@ -3211,7 +3232,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [titan], op: 'some' }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -3220,7 +3241,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'moons', records: [ganymede], op: 'none' }) - ), + ) as Record[], [earth, mars] ); }); @@ -3397,7 +3418,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'planet', record: null }) - ), + ) as Record[], [titan] ); arrayMembershipMatches( @@ -3406,7 +3427,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(earth, 'moons') .filter({ relation: 'planet', record: earth }) - ), + ) as Record[], [theMoon] ); arrayMembershipMatches( @@ -3415,7 +3436,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(jupiter, 'moons') .filter({ relation: 'planet', record: jupiter }) - ), + ) as Record[], [europa, ganymede, callisto] ); arrayMembershipMatches( @@ -3424,7 +3445,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(mercury, 'moons') .filter({ relation: 'planet', record: mercury }) - ), + ) as Record[], [] ); arrayMembershipMatches( @@ -3433,7 +3454,7 @@ module('SyncRecordCache', function (hooks) { q .findRelatedRecords(sun, 'celestialObjects') .filter({ relation: 'planet', record: [earth, mars] }) - ), + ) as Record[], [theMoon, phobos, deimos] ); }); @@ -3514,7 +3535,7 @@ module('SyncRecordCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); @@ -3590,7 +3611,7 @@ module('SyncRecordCache', function (hooks) { { attribute: 'atmosphere', value: true }, { attribute: 'classification', value: 'terrestrial' } ) - ), + ) as Record[], [earth, venus] ); }); @@ -4093,7 +4114,7 @@ module('SyncRecordCache', function (hooks) { resolve?: () => void; reject?: (message: string) => void; } - function defer() { + function defer(): Deferred { let defer: Deferred = {}; defer.promise = new Promise((resolve, reject) => { defer.resolve = resolve; @@ -4109,16 +4130,16 @@ module('SyncRecordCache', function (hooks) { function next() { if (n === 1 && i === 1 && j === 0 && k === 0) { - jupiterAdded.resolve(); + jupiterAdded.resolve?.(); } if (n === 2 && i === 2 && j === 0 && k === 0) { - jupiterUpdated.resolve(); + jupiterUpdated.resolve?.(); } if (n === 3 && i === 3 && j === 1 && k === 1) { - callistoAdded.resolve(); + callistoAdded.resolve?.(); } if (n === 4 && i === 4 && j === 2 && k === 2) { - jupiterRemoved.resolve(); + jupiterRemoved.resolve?.(); } } @@ -4237,10 +4258,10 @@ module('SyncRecordCache', function (hooks) { }); setTimeout(() => { - jupiterAdded.reject('reject jupiterAdded'); - jupiterUpdated.reject('reject jupiterUpdated'); - callistoAdded.reject('reject callistoAdded'); - jupiterRemoved.reject('reject jupiterRemoved'); + jupiterAdded.reject?.('reject jupiterAdded'); + jupiterUpdated.reject?.('reject jupiterUpdated'); + callistoAdded.reject?.('reject callistoAdded'); + jupiterRemoved.reject?.('reject jupiterRemoved'); }, 500); cache.patch((t) => t.addRecord(jupiter)); @@ -4414,13 +4435,13 @@ module('SyncRecordCache', function (hooks) { const done = assert.async(); livePlanets.subscribe((update) => { - const result = update.query(); + const result = update.query() as Record[]; arrayMembershipMatches(assert, result, [venus, earth]); done(); }); // liveQuery results are initially empty - arrayMembershipMatches(assert, livePlanets.query(), []); + arrayMembershipMatches(assert, livePlanets.query() as Record[], []); // adding records should update liveQuery results cache.patch((t) => [ diff --git a/packages/@orbit/serializers/src/serializer.ts b/packages/@orbit/serializers/src/serializer.ts index 6a3d00f0b..f647cc4ce 100644 --- a/packages/@orbit/serializers/src/serializer.ts +++ b/packages/@orbit/serializers/src/serializer.ts @@ -10,5 +10,5 @@ export interface Serializer< export type UnknownSerializer = Serializer; export type UnknownSerializerClass = new ( - options?: unknown + settings?: unknown ) => UnknownSerializer; diff --git a/packages/@orbit/serializers/test/date-serializer-test.ts b/packages/@orbit/serializers/test/date-serializer-test.ts index 89424f7b1..cc5bc8b16 100644 --- a/packages/@orbit/serializers/test/date-serializer-test.ts +++ b/packages/@orbit/serializers/test/date-serializer-test.ts @@ -16,7 +16,7 @@ module('DateSerializer', function (hooks) { test('#deserialize returns a Date', function (assert) { assert.equal( - serializer.deserialize('2017-12-31').toISOString(), + serializer.deserialize('2017-12-31')?.toISOString(), new Date(2017, 11, 31).toISOString() ); }); diff --git a/packages/@orbit/serializers/test/date-time-serializer-test.ts b/packages/@orbit/serializers/test/date-time-serializer-test.ts index 61509849d..a4712898b 100644 --- a/packages/@orbit/serializers/test/date-time-serializer-test.ts +++ b/packages/@orbit/serializers/test/date-time-serializer-test.ts @@ -19,7 +19,7 @@ module('DateTimeSerializer', function (hooks) { test('#deserialize returns a Date, with a time set', function (assert) { assert.equal( - serializer.deserialize(dateString).toISOString(), + serializer.deserialize(dateString)?.toISOString(), date.toISOString() ); }); diff --git a/packages/@orbit/serializers/test/serializer-builders-test.ts b/packages/@orbit/serializers/test/serializer-builders-test.ts index 0e92d40bc..d6f15cfdc 100644 --- a/packages/@orbit/serializers/test/serializer-builders-test.ts +++ b/packages/@orbit/serializers/test/serializer-builders-test.ts @@ -1,5 +1,6 @@ import { NoopSerializer } from '../src/noop-serializer'; import { BooleanSerializer } from '../src/boolean-serializer'; +import { UnknownSerializerClass } from '../src/serializer'; import { buildSerializerClassFor, buildSerializerSettingsFor, @@ -11,11 +12,14 @@ const { module, test } = QUnit; module('Serializer builders', function (hooks) { test('buildSerializerClassFor returns fn that returns serializer classes', function (assert) { const serializerClassFor = buildSerializerClassFor({ - boolean: BooleanSerializer, + boolean: BooleanSerializer as UnknownSerializerClass, noop: NoopSerializer }); - assert.strictEqual(serializerClassFor('boolean'), BooleanSerializer); + assert.strictEqual( + serializerClassFor('boolean'), + BooleanSerializer as UnknownSerializerClass + ); assert.strictEqual(serializerClassFor('noop'), NoopSerializer); assert.strictEqual(serializerClassFor('unrecognized'), undefined); }); @@ -63,7 +67,7 @@ module('Serializer builders', function (hooks) { test('buildSerializerFor returns fn that returns serializer', function (assert) { const serializerClassFor = buildSerializerClassFor({ - boolean: BooleanSerializer, + boolean: BooleanSerializer as UnknownSerializerClass, noop: NoopSerializer }); @@ -95,13 +99,13 @@ module('Serializer builders', function (hooks) { }); assert.strictEqual( - serializerFor('boolean').serialize(true), + (serializerFor('boolean') as BooleanSerializer).serialize(true), true, 'serializerFor returns a serializer created from a provided class' ); assert.throws(() => { - serializerFor('boolean').serialize(null); + (serializerFor('boolean') as BooleanSerializer).serialize(null); }, 'type-specific settings (such as disallowNull) will be passed into the constructor'); assert.strictEqual(