@warp-drive/core 5.8.0-alpha.4 → 5.8.0-alpha.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -38
- package/declarations/build-config.d.ts +18 -1
- package/declarations/graph/-private/-edge-definition.d.ts +12 -2
- package/declarations/index.d.ts +90 -8
- package/declarations/reactive/-private/document.d.ts +58 -46
- package/declarations/reactive/-private/record.d.ts +10 -1
- package/declarations/reactive/-private/schema.d.ts +77 -4
- package/declarations/reactive/-private.d.ts +1 -0
- package/declarations/reactive.d.ts +13 -7
- package/declarations/request/-private/types.d.ts +1 -1
- package/declarations/request.d.ts +47 -0
- package/declarations/store/-private/caches/instance-cache.d.ts +5 -6
- package/declarations/store/-private/default-cache-policy.d.ts +147 -129
- package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/-private/managers/cache-key-manager.d.ts +26 -8
- package/declarations/store/-private/managers/cache-manager.d.ts +6 -4
- package/declarations/store/-private/managers/notification-manager.d.ts +1 -1
- package/declarations/store/-private/new-core-tmp/promise-state.d.ts +1 -0
- package/declarations/store/-private/new-core-tmp/request-state.d.ts +1 -1
- package/declarations/store/-private/store-service.d.ts +43 -64
- package/declarations/store/-private.d.ts +0 -1
- package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
- package/declarations/store/deprecated/-private.d.ts +1 -1
- package/declarations/store/deprecated/store.d.ts +33 -32
- package/declarations/store.d.ts +1 -0
- package/declarations/types/cache.d.ts +8 -6
- package/declarations/types/record.d.ts +132 -0
- package/declarations/types/request.d.ts +26 -14
- package/declarations/types/schema/fields.d.ts +33 -9
- package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +15 -13
- package/declarations/types/spec/document.d.ts +34 -0
- package/declarations/types/symbols.d.ts +2 -2
- package/declarations/types.d.ts +1 -1
- package/dist/build-config.js +1 -1
- package/dist/default-cache-policy-D7_u4YRH.js +572 -0
- package/dist/graph/-private.js +13 -4
- package/dist/{request-state-CUuZzgvE.js → index-BKcD4JZK.js} +10018 -8847
- package/dist/index.js +6 -382
- package/dist/reactive.js +4 -778
- package/dist/{context-C_7OLieY.js → request-oqoLC9rz.js} +219 -172
- package/dist/request.js +1 -1
- package/dist/store/-private.js +1 -1
- package/dist/store.js +1 -533
- package/dist/types/-private.js +1 -1
- package/dist/types/record.js +127 -0
- package/dist/types/request.js +14 -12
- package/dist/types/schema/fields.js +14 -0
- package/dist/types/schema/schema-service.js +0 -0
- package/dist/types/symbols.js +2 -2
- package/dist/unpkg/dev/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/dev/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev/build-config/debugging.js +1 -0
- package/dist/unpkg/dev/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev/build-config/env.js +1 -0
- package/dist/unpkg/dev/build-config/macros.js +1 -0
- package/dist/unpkg/dev/build-config.js +1 -0
- package/dist/unpkg/dev/configure-BC66sfNO.js +183 -0
- package/dist/unpkg/dev/configure.js +1 -0
- package/dist/unpkg/dev/graph/-private.js +3131 -0
- package/dist/unpkg/dev/index-DqhXrNZ_.js +11160 -0
- package/dist/unpkg/dev/index.js +6 -0
- package/dist/unpkg/dev/reactive/-private.js +1 -0
- package/dist/unpkg/dev/reactive.js +127 -0
- package/dist/unpkg/dev/request-CA9K0gXq.js +719 -0
- package/dist/unpkg/dev/request.js +1 -0
- package/dist/unpkg/dev/runtime-DGG4CvlW.js +135 -0
- package/dist/unpkg/dev/store/-private.js +56 -0
- package/dist/unpkg/dev/store.js +558 -0
- package/dist/unpkg/dev/types/-private.js +69 -0
- package/dist/unpkg/dev/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev/types/cache/change.js +0 -0
- package/dist/unpkg/dev/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev/types/cache/operations.js +0 -0
- package/dist/unpkg/dev/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev/types/cache.js +0 -0
- package/dist/unpkg/dev/types/graph.js +0 -0
- package/dist/unpkg/dev/types/identifier.js +61 -0
- package/dist/unpkg/dev/types/json/raw.js +0 -0
- package/dist/unpkg/dev/types/params.js +0 -0
- package/dist/unpkg/dev/types/record.js +191 -0
- package/dist/unpkg/dev/types/request.js +77 -0
- package/dist/unpkg/dev/types/runtime.js +34 -0
- package/dist/unpkg/dev/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev/types/schema/fields.js +505 -0
- package/dist/unpkg/dev/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev/types/spec/document.js +0 -0
- package/dist/unpkg/dev/types/spec/error.js +0 -0
- package/dist/unpkg/dev/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev/types/symbols.js +84 -0
- package/dist/unpkg/dev/types/utils.js +0 -0
- package/dist/unpkg/dev/types.js +0 -0
- package/dist/unpkg/dev/utils/string.js +91 -0
- package/dist/unpkg/dev-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/dev-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/dev-deprecated/build-config.js +1 -0
- package/dist/unpkg/dev-deprecated/configure-BC66sfNO.js +183 -0
- package/dist/unpkg/dev-deprecated/configure.js +1 -0
- package/dist/unpkg/dev-deprecated/graph/-private.js +3326 -0
- package/dist/unpkg/dev-deprecated/index-BBlq5is_.js +11775 -0
- package/dist/unpkg/dev-deprecated/index.js +5 -0
- package/dist/unpkg/dev-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/reactive.js +127 -0
- package/dist/unpkg/dev-deprecated/request-CA9K0gXq.js +719 -0
- package/dist/unpkg/dev-deprecated/request.js +1 -0
- package/dist/unpkg/dev-deprecated/runtime-DfhJzpZH.js +135 -0
- package/dist/unpkg/dev-deprecated/store/-private.js +2 -0
- package/dist/unpkg/dev-deprecated/store.js +558 -0
- package/dist/unpkg/dev-deprecated/types/-private.js +69 -0
- package/dist/unpkg/dev-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/dev-deprecated/types/cache.js +0 -0
- package/dist/unpkg/dev-deprecated/types/graph.js +0 -0
- package/dist/unpkg/dev-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/dev-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/params.js +0 -0
- package/dist/unpkg/dev-deprecated/types/record.js +191 -0
- package/dist/unpkg/dev-deprecated/types/request.js +77 -0
- package/dist/unpkg/dev-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/dev-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/dev-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/dev-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/dev-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/dev-deprecated/types/utils.js +0 -0
- package/dist/unpkg/dev-deprecated/types.js +0 -0
- package/dist/unpkg/dev-deprecated/utils/string.js +91 -0
- package/dist/unpkg/prod/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/prod/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod/build-config/debugging.js +1 -0
- package/dist/unpkg/prod/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod/build-config/env.js +1 -0
- package/dist/unpkg/prod/build-config/macros.js +1 -0
- package/dist/unpkg/prod/build-config.js +1 -0
- package/dist/unpkg/prod/configure-C0C1LpG6.js +158 -0
- package/dist/unpkg/prod/configure.js +1 -0
- package/dist/unpkg/prod/graph/-private.js +2234 -0
- package/dist/unpkg/prod/handler-LAyD1Y5l.js +1619 -0
- package/dist/unpkg/prod/hooks-BfiqDg3O.js +26 -0
- package/dist/unpkg/prod/index.js +481 -0
- package/dist/unpkg/prod/promise-state-ipG60SdD.js +6738 -0
- package/dist/unpkg/prod/reactive/-private.js +1 -0
- package/dist/unpkg/prod/reactive.js +127 -0
- package/dist/unpkg/prod/request-CN2LxbYX.js +437 -0
- package/dist/unpkg/prod/request.js +1 -0
- package/dist/unpkg/prod/store/-private.js +127 -0
- package/dist/unpkg/prod/store.js +437 -0
- package/dist/unpkg/prod/types/-private.js +49 -0
- package/dist/unpkg/prod/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod/types/cache/change.js +0 -0
- package/dist/unpkg/prod/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod/types/cache/operations.js +0 -0
- package/dist/unpkg/prod/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod/types/cache.js +0 -0
- package/dist/unpkg/prod/types/graph.js +0 -0
- package/dist/unpkg/prod/types/identifier.js +61 -0
- package/dist/unpkg/prod/types/json/raw.js +0 -0
- package/dist/unpkg/prod/types/params.js +0 -0
- package/dist/unpkg/prod/types/record.js +191 -0
- package/dist/unpkg/prod/types/request.js +77 -0
- package/dist/unpkg/prod/types/runtime.js +34 -0
- package/dist/unpkg/prod/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod/types/schema/fields.js +505 -0
- package/dist/unpkg/prod/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod/types/spec/document.js +0 -0
- package/dist/unpkg/prod/types/spec/error.js +0 -0
- package/dist/unpkg/prod/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod/types/symbols.js +84 -0
- package/dist/unpkg/prod/types/utils.js +0 -0
- package/dist/unpkg/prod/types.js +0 -0
- package/dist/unpkg/prod/utils/string.js +72 -0
- package/dist/unpkg/prod-deprecated/-private-3C1OkYtZ.js +39 -0
- package/dist/unpkg/prod-deprecated/build-config/babel-macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/canary-features.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/debugging.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/deprecations.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/env.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config/macros.js +1 -0
- package/dist/unpkg/prod-deprecated/build-config.js +1 -0
- package/dist/unpkg/prod-deprecated/configure-BQ8CpIcW.js +158 -0
- package/dist/unpkg/prod-deprecated/configure.js +1 -0
- package/dist/unpkg/prod-deprecated/graph/-private.js +2407 -0
- package/dist/unpkg/prod-deprecated/handler-D639oFvl.js +334 -0
- package/dist/unpkg/prod-deprecated/hooks-DGvi9teJ.js +26 -0
- package/dist/unpkg/prod-deprecated/index.js +481 -0
- package/dist/unpkg/prod-deprecated/promise-state-CYvoIPna.js +8458 -0
- package/dist/unpkg/prod-deprecated/reactive/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/reactive.js +126 -0
- package/dist/unpkg/prod-deprecated/request-CN2LxbYX.js +437 -0
- package/dist/unpkg/prod-deprecated/request.js +1 -0
- package/dist/unpkg/prod-deprecated/store/-private.js +89 -0
- package/dist/unpkg/prod-deprecated/store.js +437 -0
- package/dist/unpkg/prod-deprecated/types/-private.js +49 -0
- package/dist/unpkg/prod-deprecated/types/cache/aliases.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/change.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/mutations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/operations.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache/relationship.js +0 -0
- package/dist/unpkg/prod-deprecated/types/cache.js +0 -0
- package/dist/unpkg/prod-deprecated/types/graph.js +0 -0
- package/dist/unpkg/prod-deprecated/types/identifier.js +61 -0
- package/dist/unpkg/prod-deprecated/types/json/raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/params.js +0 -0
- package/dist/unpkg/prod-deprecated/types/record.js +191 -0
- package/dist/unpkg/prod-deprecated/types/request.js +77 -0
- package/dist/unpkg/prod-deprecated/types/runtime.js +34 -0
- package/dist/unpkg/prod-deprecated/types/schema/concepts.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.js +505 -0
- package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js +0 -0
- package/dist/unpkg/prod-deprecated/types/schema/schema-service.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/document.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/error.js +0 -0
- package/dist/unpkg/prod-deprecated/types/spec/json-api-raw.js +0 -0
- package/dist/unpkg/prod-deprecated/types/symbols.js +84 -0
- package/dist/unpkg/prod-deprecated/types/utils.js +0 -0
- package/dist/unpkg/prod-deprecated/types.js +0 -0
- package/dist/unpkg/prod-deprecated/utils/string.js +72 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +11 -3
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
package/dist/reactive.js
CHANGED
|
@@ -1,784 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export { O as checkout, P as commit } from "./request-state-CUuZzgvE.js";
|
|
3
|
-
import { isResourceSchema } from './types/schema/fields.js';
|
|
4
|
-
import { D as Destroy, C as Context } from "./symbols-sql1_mdx.js";
|
|
1
|
+
export { N as SchemaService, K as checkout, T as commit, p as createRequestSubscription, P as fromIdentity, U as getPromiseState, q as getRequestState, L as instantiateRecord, Q as registerDerivations, M as teardownRecord, O as withDefaults } from "./index-BKcD4JZK.js";
|
|
5
2
|
export { a as Checkout } from "./symbols-sql1_mdx.js";
|
|
6
|
-
import { macroCondition, getGlobalConfig } from '@embroider/macros';
|
|
7
|
-
import { warn, deprecate } from '@ember/debug';
|
|
8
|
-
import './index.js';
|
|
9
3
|
import './types/request.js';
|
|
4
|
+
import '@embroider/macros';
|
|
5
|
+
import '@ember/debug';
|
|
10
6
|
import './utils/string.js';
|
|
11
7
|
import "./configure-C3x8YXzL.js";
|
|
12
|
-
import { getOrSetGlobal } from './types/-private.js';
|
|
13
|
-
import { Type } from './types/symbols.js';
|
|
14
|
-
function instantiateRecord(store, identifier, createArgs) {
|
|
15
|
-
const schema = store.schema;
|
|
16
|
-
const resourceSchema = schema.resource(identifier);
|
|
17
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
18
|
-
if (!test) {
|
|
19
|
-
throw new Error(`Expected a resource schema`);
|
|
20
|
-
}
|
|
21
|
-
})(isResourceSchema(resourceSchema)) : {};
|
|
22
|
-
const legacy = resourceSchema?.legacy ?? false;
|
|
23
|
-
const editable = legacy;
|
|
24
|
-
const record = new ReactiveResource({
|
|
25
|
-
store,
|
|
26
|
-
resourceKey: identifier,
|
|
27
|
-
modeName: legacy ? 'legacy' : 'polaris',
|
|
28
|
-
legacy: legacy,
|
|
29
|
-
editable: editable,
|
|
30
|
-
path: null,
|
|
31
|
-
field: null,
|
|
32
|
-
value: null
|
|
33
|
-
});
|
|
34
|
-
if (createArgs && editable) {
|
|
35
|
-
Object.assign(record, createArgs);
|
|
36
|
-
}
|
|
37
|
-
return record;
|
|
38
|
-
}
|
|
39
|
-
function assertReactiveResource(record) {
|
|
40
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
41
|
-
if (!test) {
|
|
42
|
-
throw new Error('Expected a ReactiveResource');
|
|
43
|
-
}
|
|
44
|
-
})(record && typeof record === 'object' && Destroy in record) : {};
|
|
45
|
-
}
|
|
46
|
-
function teardownRecord(record) {
|
|
47
|
-
assertReactiveResource(record);
|
|
48
|
-
record[Destroy]();
|
|
49
|
-
}
|
|
50
|
-
const Support = getOrSetGlobal('Support', new WeakMap());
|
|
51
|
-
const ConstructorField = {
|
|
52
|
-
type: '@constructor',
|
|
53
|
-
name: 'constructor',
|
|
54
|
-
kind: 'derived'
|
|
55
|
-
};
|
|
56
|
-
const TypeField = {
|
|
57
|
-
type: '@identity',
|
|
58
|
-
name: '$type',
|
|
59
|
-
kind: 'derived',
|
|
60
|
-
options: {
|
|
61
|
-
key: 'type'
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const DefaultIdentityField = {
|
|
65
|
-
name: 'id',
|
|
66
|
-
kind: '@id'
|
|
67
|
-
};
|
|
68
|
-
function _constructor(record) {
|
|
69
|
-
let state = Support.get(record);
|
|
70
|
-
if (!state) {
|
|
71
|
-
state = {};
|
|
72
|
-
Support.set(record, state);
|
|
73
|
-
}
|
|
74
|
-
return state._constructor = state._constructor || {
|
|
75
|
-
name: `ReactiveResource<${recordIdentifierFor(record).type}>`,
|
|
76
|
-
get modelName() {
|
|
77
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
78
|
-
{
|
|
79
|
-
throw new Error(`record.constructor.modelName is not available outside of legacy mode`);
|
|
80
|
-
}
|
|
81
|
-
})() : {};
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
_constructor[Type] = '@constructor';
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Extensions allow providing non-schema driven behaviors to
|
|
90
|
-
* reactive resources and arrays.
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
const BannedKeys = ['constructor', '__proto__'];
|
|
94
|
-
function processExtension(extension) {
|
|
95
|
-
const {
|
|
96
|
-
kind,
|
|
97
|
-
name
|
|
98
|
-
} = extension;
|
|
99
|
-
const features = new Map();
|
|
100
|
-
const baseFeatures = typeof extension.features === 'function' ? extension.features.prototype : extension.features;
|
|
101
|
-
for (const key of Object.getOwnPropertyNames(baseFeatures)) {
|
|
102
|
-
if (BannedKeys.includes(key)) continue;
|
|
103
|
-
const decl = Object.getOwnPropertyDescriptor(baseFeatures, key);
|
|
104
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
105
|
-
if (!test) {
|
|
106
|
-
throw new Error(`Expected to find a declaration for ${key} on extension ${name}`);
|
|
107
|
-
}
|
|
108
|
-
})(decl) : {};
|
|
109
|
-
if (decl.value) {
|
|
110
|
-
const {
|
|
111
|
-
value
|
|
112
|
-
} = decl;
|
|
113
|
-
features.set(key, typeof value === 'function' ? {
|
|
114
|
-
kind: 'method',
|
|
115
|
-
fn: value
|
|
116
|
-
} : decl.writable ? {
|
|
117
|
-
kind: 'mutable-value',
|
|
118
|
-
value
|
|
119
|
-
} : {
|
|
120
|
-
kind: 'readonly-value',
|
|
121
|
-
value
|
|
122
|
-
});
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
if (decl.get || decl.set) {
|
|
126
|
-
const {
|
|
127
|
-
get,
|
|
128
|
-
set
|
|
129
|
-
} = decl;
|
|
130
|
-
features.set(key,
|
|
131
|
-
// prettier-ignore
|
|
132
|
-
get && set ? {
|
|
133
|
-
kind: 'mutable-field',
|
|
134
|
-
get,
|
|
135
|
-
set
|
|
136
|
-
} : get ? {
|
|
137
|
-
kind: 'readonly-field',
|
|
138
|
-
get
|
|
139
|
-
} : {
|
|
140
|
-
kind: 'writeonly-field',
|
|
141
|
-
set: set
|
|
142
|
-
});
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
146
|
-
{
|
|
147
|
-
throw new Error(`The feature ${key} on extension ${name} is of an unknown variety.`);
|
|
148
|
-
}
|
|
149
|
-
})() : {};
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
kind,
|
|
153
|
-
name,
|
|
154
|
-
features
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
function getExt(extCache, type, extName) {
|
|
158
|
-
const ext = extCache[type].get(extName);
|
|
159
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
160
|
-
if (!test) {
|
|
161
|
-
throw new Error(`expected to have an extension named ${String(extName)} available for ${type}s`);
|
|
162
|
-
}
|
|
163
|
-
})(ext) : {};
|
|
164
|
-
return ext?.features ?? null;
|
|
165
|
-
}
|
|
166
|
-
function hasObjectSchema(field) {
|
|
167
|
-
return 'kind' in field && (field.kind === 'schema-array' || field.kind === 'schema-object');
|
|
168
|
-
}
|
|
169
|
-
function processExtensions(schema, field, scenario, resolvedType) {
|
|
170
|
-
// if we're looking up extensions for a resource, there is no
|
|
171
|
-
// merging required so if we have no objectExtensions
|
|
172
|
-
// we are done.
|
|
173
|
-
if (scenario === 'resource') {
|
|
174
|
-
if (!('objectExtensions' in field || !field.objectExtensions?.length)) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const type = scenario === 'resource' ? 'object' : scenario;
|
|
179
|
-
const extCache = schema._extensions;
|
|
180
|
-
const fieldCache = schema._cachedFieldExtensionsByField;
|
|
181
|
-
if (fieldCache[type].has(field)) {
|
|
182
|
-
return fieldCache[type].get(field);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// prettier-ignore
|
|
186
|
-
const extensions = (scenario === 'resource' ? field.objectExtensions : scenario === 'object' ? field.options?.objectExtensions : field.options?.arrayExtensions) || null;
|
|
187
|
-
|
|
188
|
-
// if we are a resource scenario, we know from the first check we do have extensions
|
|
189
|
-
// if we are an object scenario, we can now return the resource scenario.
|
|
190
|
-
// if we are an array scenario, there is nothing more to process.
|
|
191
|
-
if (!extensions) {
|
|
192
|
-
if (scenario === 'array') return null;
|
|
193
|
-
if (!hasObjectSchema(field)) {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
return schema.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resolvedType ? {
|
|
197
|
-
type: resolvedType
|
|
198
|
-
} : field);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// if we have made it here, we have extensions, lets check if there's
|
|
202
|
-
// a cached version we can use
|
|
203
|
-
const baseExtensions = scenario === 'resource' && hasObjectSchema(field) ? schema.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(field) : scenario === 'object' && hasObjectSchema(field) ? schema.CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resolvedType ? {
|
|
204
|
-
type: resolvedType
|
|
205
|
-
} : field) : null;
|
|
206
|
-
if (!baseExtensions && extensions.length === 1) {
|
|
207
|
-
const value = getExt(extCache, type, extensions[0]);
|
|
208
|
-
fieldCache[type].set(field, value);
|
|
209
|
-
return value;
|
|
210
|
-
}
|
|
211
|
-
const features = new Map(baseExtensions);
|
|
212
|
-
for (const extName of extensions) {
|
|
213
|
-
const value = getExt(extCache, type, extName);
|
|
214
|
-
if (value) {
|
|
215
|
-
for (const [feature, desc] of value) {
|
|
216
|
-
features.set(feature, desc);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
const value = features.size ? features : null;
|
|
221
|
-
fieldCache[type].set(field, value);
|
|
222
|
-
return value;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Utility for constructing a ResourceSchema with the recommended
|
|
227
|
-
* fields for the PolarisMode experience.
|
|
228
|
-
*
|
|
229
|
-
* Using this requires registering the PolarisMode derivations
|
|
230
|
-
*
|
|
231
|
-
* ```ts
|
|
232
|
-
* import { registerDerivations } from '@warp-drive/schema-record';
|
|
233
|
-
*
|
|
234
|
-
* registerDerivations(schema);
|
|
235
|
-
* ```
|
|
236
|
-
*
|
|
237
|
-
* @public
|
|
238
|
-
* @param schema
|
|
239
|
-
* @return {PolarisResourceSchema}
|
|
240
|
-
*/
|
|
241
|
-
function withDefaults(schema) {
|
|
242
|
-
schema.identity = schema.identity || DefaultIdentityField;
|
|
243
|
-
|
|
244
|
-
// because fields gets iterated in definition order,
|
|
245
|
-
// we add TypeField to the beginning so that it will
|
|
246
|
-
// appear right next to the identity field
|
|
247
|
-
schema.fields.unshift(TypeField);
|
|
248
|
-
schema.fields.push(ConstructorField);
|
|
249
|
-
return schema;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* A derivation that computes its value from the
|
|
253
|
-
* record's identity.
|
|
254
|
-
*
|
|
255
|
-
* It can be used via a derived field definition like:
|
|
256
|
-
*
|
|
257
|
-
* ```ts
|
|
258
|
-
* {
|
|
259
|
-
* kind: 'derived',
|
|
260
|
-
* name: 'id',
|
|
261
|
-
* type: '@identity',
|
|
262
|
-
* options: { key: 'id' }
|
|
263
|
-
* }
|
|
264
|
-
* ```
|
|
265
|
-
*
|
|
266
|
-
* Valid keys are `'id'`, `'lid'`, `'type'`, and `'^'`.
|
|
267
|
-
*
|
|
268
|
-
* `^` returns the entire identifier object.
|
|
269
|
-
*
|
|
270
|
-
* @public
|
|
271
|
-
*/
|
|
272
|
-
const fromIdentity = (record, options, key) => {
|
|
273
|
-
const context = record[Context];
|
|
274
|
-
const identifier = context.resourceKey;
|
|
275
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
276
|
-
if (!test) {
|
|
277
|
-
throw new Error(`Cannot compute @identity for a record without an identifier`);
|
|
278
|
-
}
|
|
279
|
-
})(identifier) : {};
|
|
280
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
281
|
-
if (!test) {
|
|
282
|
-
throw new Error(`Expected to receive a key to compute @identity, but got ${String(options)}`);
|
|
283
|
-
}
|
|
284
|
-
})(options?.key && ['lid', 'id', 'type', '^'].includes(options.key)) : {};
|
|
285
|
-
return options.key === '^' ? identifier : identifier[options.key];
|
|
286
|
-
};
|
|
287
|
-
fromIdentity[Type] = '@identity';
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Registers the default derivations for records that want
|
|
291
|
-
* to use the PolarisMode defaults provided by
|
|
292
|
-
*
|
|
293
|
-
* ```ts
|
|
294
|
-
* import { withDefaults } from '@warp-drive/schema-record';
|
|
295
|
-
* ```
|
|
296
|
-
*
|
|
297
|
-
* @public
|
|
298
|
-
*/
|
|
299
|
-
function registerDerivations(schema) {
|
|
300
|
-
schema.registerDerivation(fromIdentity);
|
|
301
|
-
schema.registerDerivation(_constructor);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Wraps a derivation in a new function with Derivation signature but that looks
|
|
305
|
-
* up the value in the cache before recomputing.
|
|
306
|
-
*
|
|
307
|
-
* @internal
|
|
308
|
-
*/
|
|
309
|
-
function makeCachedDerivation(derivation) {
|
|
310
|
-
const memoizedDerivation = (record, options, prop) => {
|
|
311
|
-
const signals = withSignalStore(record);
|
|
312
|
-
let signal = signals.get(prop);
|
|
313
|
-
if (!signal) {
|
|
314
|
-
signal = createInternalMemo(signals, record, prop, () => {
|
|
315
|
-
return derivation(record, options, prop);
|
|
316
|
-
}); // a total lie, for convenience of reusing the storage
|
|
317
|
-
}
|
|
318
|
-
return signal();
|
|
319
|
-
};
|
|
320
|
-
memoizedDerivation[Type] = derivation[Type];
|
|
321
|
-
return memoizedDerivation;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* A SchemaService designed to work with dynamically registered schemas.
|
|
325
|
-
*
|
|
326
|
-
* @public
|
|
327
|
-
*/
|
|
328
|
-
class SchemaService {
|
|
329
|
-
/** @internal */
|
|
330
|
-
|
|
331
|
-
/** @internal */
|
|
332
|
-
|
|
333
|
-
/** @internal */
|
|
334
|
-
|
|
335
|
-
/** @internal */
|
|
336
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
337
|
-
|
|
338
|
-
/** @internal */
|
|
339
|
-
|
|
340
|
-
/** @internal */
|
|
341
|
-
|
|
342
|
-
/** @internal */
|
|
343
|
-
|
|
344
|
-
/** @internal */
|
|
345
|
-
|
|
346
|
-
constructor() {
|
|
347
|
-
this._schemas = new Map();
|
|
348
|
-
this._transforms = new Map();
|
|
349
|
-
this._hashFns = new Map();
|
|
350
|
-
this._derivations = new Map();
|
|
351
|
-
this._traits = new Map();
|
|
352
|
-
this._modes = new Map();
|
|
353
|
-
this._extensions = {
|
|
354
|
-
object: new Map(),
|
|
355
|
-
array: new Map()
|
|
356
|
-
};
|
|
357
|
-
this._cachedFieldExtensionsByField = {
|
|
358
|
-
object: new Map(),
|
|
359
|
-
array: new Map()
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
resourceTypes() {
|
|
363
|
-
return Array.from(this._schemas.keys());
|
|
364
|
-
}
|
|
365
|
-
hasTrait(type) {
|
|
366
|
-
return this._traits.has(type);
|
|
367
|
-
}
|
|
368
|
-
resourceHasTrait(resource, trait) {
|
|
369
|
-
return this._schemas.get(resource.type).traits.has(trait);
|
|
370
|
-
}
|
|
371
|
-
transformation(field) {
|
|
372
|
-
const kind = 'kind' in field ? field.kind : '<unknown kind>';
|
|
373
|
-
const name = 'name' in field ? field.name : '<unknown name>';
|
|
374
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
375
|
-
if (!test) {
|
|
376
|
-
throw new Error(`'${kind}' fields cannot be transformed. Only fields of kind 'field' 'object' or 'array' can specify a transformation. Attempted to find '${field.type ?? '<unknown type>'}' on field '${name}'.`);
|
|
377
|
-
}
|
|
378
|
-
})(!('kind' in field) || ['field', 'object', 'array'].includes(kind)) : {};
|
|
379
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
380
|
-
if (!test) {
|
|
381
|
-
throw new Error(`Expected the '${kind}' field '${name}' to specify a transformation via 'field.type', but none was present`);
|
|
382
|
-
}
|
|
383
|
-
})(field.type) : {};
|
|
384
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
385
|
-
if (!test) {
|
|
386
|
-
throw new Error(`No transformation registered with name '${field.type}' for '${kind}' field '${name}'`);
|
|
387
|
-
}
|
|
388
|
-
})(this._transforms.has(field.type)) : {};
|
|
389
|
-
return this._transforms.get(field.type);
|
|
390
|
-
}
|
|
391
|
-
derivation(field) {
|
|
392
|
-
const kind = 'kind' in field ? field.kind : '<unknown kind>';
|
|
393
|
-
const name = 'name' in field ? field.name : '<unknown name>';
|
|
394
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
395
|
-
if (!test) {
|
|
396
|
-
throw new Error(`The '${kind}' field '${name}' is not derived and so cannot be used to lookup a derivation`);
|
|
397
|
-
}
|
|
398
|
-
})(!('kind' in field) || kind === 'derived') : {};
|
|
399
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
400
|
-
if (!test) {
|
|
401
|
-
throw new Error(`Expected the '${kind}' field '${name}' to specify a derivation via 'field.type', but no value was present`);
|
|
402
|
-
}
|
|
403
|
-
})(field.type) : {};
|
|
404
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
405
|
-
if (!test) {
|
|
406
|
-
throw new Error(`No '${field.type}' derivation registered for use by the '${kind}' field '${name}'`);
|
|
407
|
-
}
|
|
408
|
-
})(this._derivations.has(field.type)) : {};
|
|
409
|
-
return this._derivations.get(field.type);
|
|
410
|
-
}
|
|
411
|
-
hashFn(field) {
|
|
412
|
-
const kind = 'kind' in field ? field.kind : '<unknown kind>';
|
|
413
|
-
const name = 'name' in field ? field.name : '<unknown name>';
|
|
414
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
415
|
-
if (!test) {
|
|
416
|
-
throw new Error(`The '${kind}' field '${name}' is not a HashField and so cannot be used to lookup a hash function`);
|
|
417
|
-
}
|
|
418
|
-
})(!('kind' in field) || kind === '@hash') : {};
|
|
419
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
420
|
-
if (!test) {
|
|
421
|
-
throw new Error(`Expected the '${kind}' field '${name}' to specify a hash function via 'field.type', but no value was present`);
|
|
422
|
-
}
|
|
423
|
-
})(field.type) : {};
|
|
424
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
425
|
-
if (!test) {
|
|
426
|
-
throw new Error(`No '${field.type}' hash function is registered for use by the '${kind}' field '${name}'`);
|
|
427
|
-
}
|
|
428
|
-
})(this._hashFns.has(field.type)) : {};
|
|
429
|
-
return this._hashFns.get(field.type);
|
|
430
|
-
}
|
|
431
|
-
resource(resource) {
|
|
432
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
433
|
-
if (!test) {
|
|
434
|
-
throw new Error(`No resource registered with name '${resource.type}'`);
|
|
435
|
-
}
|
|
436
|
-
})(this._schemas.has(resource.type)) : {};
|
|
437
|
-
return this._schemas.get(resource.type).original;
|
|
438
|
-
}
|
|
439
|
-
registerResources(schemas) {
|
|
440
|
-
schemas.forEach(schema => {
|
|
441
|
-
this.registerResource(schema);
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
registerResource(schema) {
|
|
445
|
-
const fields = new Map();
|
|
446
|
-
const relationships = {};
|
|
447
|
-
const attributes = {};
|
|
448
|
-
for (const field of schema.fields) {
|
|
449
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
450
|
-
if (!test) {
|
|
451
|
-
throw new Error(`${field.kind} is not valid inside a ResourceSchema's fields.`);
|
|
452
|
-
}
|
|
453
|
-
})(
|
|
454
|
-
// @ts-expect-error we are checking for mistakes at runtime
|
|
455
|
-
field.kind !== '@id' && field.kind !== '@hash') : {};
|
|
456
|
-
fields.set(field.name, field);
|
|
457
|
-
if (field.kind === 'attribute') {
|
|
458
|
-
attributes[field.name] = field;
|
|
459
|
-
} else if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
|
|
460
|
-
relationships[field.name] = field;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
const cacheFields = null;
|
|
464
|
-
const traits = new Set(isResourceSchema(schema) ? schema.traits : []);
|
|
465
|
-
const finalized = traits.size === 0;
|
|
466
|
-
const internalSchema = {
|
|
467
|
-
original: schema,
|
|
468
|
-
finalized,
|
|
469
|
-
fields,
|
|
470
|
-
cacheFields,
|
|
471
|
-
relationships,
|
|
472
|
-
attributes,
|
|
473
|
-
traits
|
|
474
|
-
};
|
|
475
|
-
if (traits.size === 0) {
|
|
476
|
-
internalSchema.cacheFields = getCacheFields(internalSchema);
|
|
477
|
-
}
|
|
478
|
-
this._schemas.set(schema.type, internalSchema);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* Registers a {@link Trait} for use by resource schemas.
|
|
483
|
-
*
|
|
484
|
-
* Traits are re-usable collections of fields that can be composed to
|
|
485
|
-
* build up a resource schema. Often they represent polymorphic behaviors
|
|
486
|
-
* a resource should exhibit.
|
|
487
|
-
*
|
|
488
|
-
* When we finalize a resource, we walk its traits and apply their fields
|
|
489
|
-
* to the resource's fields. All specified traits must be registered by
|
|
490
|
-
* this time or an error will be thrown.
|
|
491
|
-
*
|
|
492
|
-
* Traits are applied left-to-right, with traits of traits being applied in the same
|
|
493
|
-
* way. Thus for the most part, application of traits is a post-order graph traversal
|
|
494
|
-
* problem.
|
|
495
|
-
*
|
|
496
|
-
* A trait is only ever processed once. If multiple traits (A, B, C) have the same
|
|
497
|
-
* trait (D) as a dependency, D will be included only once when first encountered by
|
|
498
|
-
* A.
|
|
499
|
-
*
|
|
500
|
-
* If a cycle exists such that trait A has trait B which has Trait A, trait A will
|
|
501
|
-
* be applied *after* trait B in production. In development a cycle error will be thrown.
|
|
502
|
-
*
|
|
503
|
-
* Fields are finalized on a "last wins principle". Thus traits appearing higher in
|
|
504
|
-
* the tree and further to the right of a traits array take precedence, with the
|
|
505
|
-
* resource's fields always being applied last and winning out.
|
|
506
|
-
*
|
|
507
|
-
* @public
|
|
508
|
-
*/
|
|
509
|
-
registerTrait(trait) {
|
|
510
|
-
const internalTrait = Object.assign({}, trait, {
|
|
511
|
-
fields: new Map()
|
|
512
|
-
});
|
|
513
|
-
for (const field of trait.fields) {
|
|
514
|
-
internalTrait.fields.set(field.name, field);
|
|
515
|
-
}
|
|
516
|
-
this._traits.set(trait.name, internalTrait);
|
|
517
|
-
}
|
|
518
|
-
registerTransformation(transformation) {
|
|
519
|
-
this._transforms.set(transformation[Type], transformation);
|
|
520
|
-
}
|
|
521
|
-
registerDerivation(derivation) {
|
|
522
|
-
this._derivations.set(derivation[Type], makeCachedDerivation(derivation));
|
|
523
|
-
}
|
|
524
|
-
CAUTION_MEGA_DANGER_ZONE_registerExtension(extension) {
|
|
525
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
526
|
-
if (!test) {
|
|
527
|
-
throw new Error(`an extension named ${extension.name} for ${extension.kind} already exists!`);
|
|
528
|
-
}
|
|
529
|
-
})(!this._extensions[extension.kind].has(extension.name)) : {};
|
|
530
|
-
this._extensions[extension.kind].set(extension.name, processExtension(extension));
|
|
531
|
-
}
|
|
532
|
-
CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource) {
|
|
533
|
-
const schema = this.resource(resource);
|
|
534
|
-
return processExtensions(this, schema, 'resource', null);
|
|
535
|
-
}
|
|
536
|
-
CAUTION_MEGA_DANGER_ZONE_objectExtensions(field, resolvedType) {
|
|
537
|
-
return processExtensions(this, field, 'object', resolvedType);
|
|
538
|
-
}
|
|
539
|
-
CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field) {
|
|
540
|
-
return processExtensions(this, field, 'array', null);
|
|
541
|
-
}
|
|
542
|
-
CAUTION_MEGA_DANGER_ZONE_hasExtension(ext) {
|
|
543
|
-
return this._extensions[ext.kind].has(ext.name);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* This is an internal method used to register behaviors for legacy mode.
|
|
548
|
-
* It is not intended for public use.
|
|
549
|
-
*
|
|
550
|
-
* We do think a generalized `kind` registration system would be useful,
|
|
551
|
-
* but we have not yet designed it.
|
|
552
|
-
*
|
|
553
|
-
* See https://github.com/warp-drive-data/warp-drive/issues/9534
|
|
554
|
-
*
|
|
555
|
-
* @internal
|
|
556
|
-
*/
|
|
557
|
-
_registerMode(mode, kinds) {
|
|
558
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
559
|
-
if (!test) {
|
|
560
|
-
throw new Error(`Mode '${mode}' is already registered`);
|
|
561
|
-
}
|
|
562
|
-
})(!this._modes.has(mode)) : {};
|
|
563
|
-
this._modes.set(mode, kinds);
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
/**
|
|
567
|
-
* This is an internal method used to enable legacy behaviors for legacy mode.
|
|
568
|
-
* It is not intended for public use.
|
|
569
|
-
*
|
|
570
|
-
* We do think a generalized `kind` registration system would be useful,
|
|
571
|
-
* but we have not yet designed it.
|
|
572
|
-
*
|
|
573
|
-
* See https://github.com/warp-drive-data/warp-drive/issues/9534
|
|
574
|
-
*
|
|
575
|
-
* @internal
|
|
576
|
-
*/
|
|
577
|
-
_kind(mode, kind) {
|
|
578
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
579
|
-
if (!test) {
|
|
580
|
-
throw new Error(`Mode '${mode}' is not registered`);
|
|
581
|
-
}
|
|
582
|
-
})(this._modes.has(mode)) : {};
|
|
583
|
-
const kinds = this._modes.get(mode);
|
|
584
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
585
|
-
if (!test) {
|
|
586
|
-
throw new Error(`Kind '${kind}' is not registered for mode '${mode}'`);
|
|
587
|
-
}
|
|
588
|
-
})(kinds[kind]) : {};
|
|
589
|
-
return kinds[kind];
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/**
|
|
593
|
-
* Registers a {@link HashFn} for use with a {@link HashField} for
|
|
594
|
-
* either {@link ObjectSchema} identity or polymorphic type calculation.
|
|
595
|
-
*
|
|
596
|
-
* @public
|
|
597
|
-
*/
|
|
598
|
-
registerHashFn(hashFn) {
|
|
599
|
-
this._hashFns.set(hashFn[Type], hashFn);
|
|
600
|
-
}
|
|
601
|
-
fields({
|
|
602
|
-
type
|
|
603
|
-
}) {
|
|
604
|
-
const schema = this._schemas.get(type);
|
|
605
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
606
|
-
if (!test) {
|
|
607
|
-
throw new Error(`No schema defined for ${type}`);
|
|
608
|
-
}
|
|
609
|
-
})(schema) : {};
|
|
610
|
-
if (!schema.finalized) {
|
|
611
|
-
finalizeResource(this, schema);
|
|
612
|
-
}
|
|
613
|
-
return schema.fields;
|
|
614
|
-
}
|
|
615
|
-
cacheFields({
|
|
616
|
-
type
|
|
617
|
-
}) {
|
|
618
|
-
const schema = this._schemas.get(type);
|
|
619
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
620
|
-
if (!test) {
|
|
621
|
-
throw new Error(`No schema defined for ${type}`);
|
|
622
|
-
}
|
|
623
|
-
})(schema) : {};
|
|
624
|
-
if (!schema.finalized) {
|
|
625
|
-
finalizeResource(this, schema);
|
|
626
|
-
}
|
|
627
|
-
return schema.cacheFields;
|
|
628
|
-
}
|
|
629
|
-
hasResource(resource) {
|
|
630
|
-
return this._schemas.has(resource.type);
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
if (macroCondition(getGlobalConfig().WarpDrive.deprecations.ENABLE_LEGACY_SCHEMA_SERVICE)) {
|
|
634
|
-
SchemaService.prototype.attributesDefinitionFor = function ({
|
|
635
|
-
type
|
|
636
|
-
}) {
|
|
637
|
-
deprecate(`Use \`schema.fields({ type })\` instead of \`schema.attributesDefinitionFor({ type })\``, false, {
|
|
638
|
-
id: 'ember-data:schema-service-updates',
|
|
639
|
-
until: '6.0',
|
|
640
|
-
for: 'ember-data',
|
|
641
|
-
since: {
|
|
642
|
-
available: '4.13',
|
|
643
|
-
enabled: '5.4'
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
const schema = this._schemas.get(type);
|
|
647
|
-
if (!schema) {
|
|
648
|
-
throw new Error(`No schema defined for ${type}`);
|
|
649
|
-
}
|
|
650
|
-
return schema.attributes;
|
|
651
|
-
};
|
|
652
|
-
SchemaService.prototype.relationshipsDefinitionFor = function ({
|
|
653
|
-
type
|
|
654
|
-
}) {
|
|
655
|
-
deprecate(`Use \`schema.fields({ type })\` instead of \`schema.relationshipsDefinitionFor({ type })\``, false, {
|
|
656
|
-
id: 'ember-data:schema-service-updates',
|
|
657
|
-
until: '6.0',
|
|
658
|
-
for: 'ember-data',
|
|
659
|
-
since: {
|
|
660
|
-
available: '4.13',
|
|
661
|
-
enabled: '5.4'
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
const schema = this._schemas.get(type);
|
|
665
|
-
if (!schema) {
|
|
666
|
-
throw new Error(`No schema defined for ${type}`);
|
|
667
|
-
}
|
|
668
|
-
return schema.relationships;
|
|
669
|
-
};
|
|
670
|
-
SchemaService.prototype.doesTypeExist = function (type) {
|
|
671
|
-
deprecate(`Use \`schema.hasResource({ type })\` instead of \`schema.doesTypeExist(type)\``, false, {
|
|
672
|
-
id: 'ember-data:schema-service-updates',
|
|
673
|
-
until: '6.0',
|
|
674
|
-
for: 'ember-data',
|
|
675
|
-
since: {
|
|
676
|
-
available: '4.13',
|
|
677
|
-
enabled: '5.4'
|
|
678
|
-
}
|
|
679
|
-
});
|
|
680
|
-
return this._schemas.has(type);
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* When we finalize a resource, we walk its traits and apply their fields
|
|
686
|
-
* to the resource's fields.
|
|
687
|
-
*
|
|
688
|
-
* Traits are applied left-to-right, with traits of traits being applied in the same
|
|
689
|
-
* way. Thus for the most part, application of traits is a post-order graph traversal
|
|
690
|
-
* problem.
|
|
691
|
-
*
|
|
692
|
-
* A trait is only ever processed once. If multiple traits (A, B, C) have the same
|
|
693
|
-
* trait (D) as a dependency, D will be included only once when first encountered by
|
|
694
|
-
* A.
|
|
695
|
-
*
|
|
696
|
-
* If a cycle exists such that trait A has trait B which has Trait A, trait A will
|
|
697
|
-
* be applied *after* trait B in production. In development a cycle error will be thrown.
|
|
698
|
-
*
|
|
699
|
-
* Fields are finalized on a "last wins principle". Thus traits appearing higher in
|
|
700
|
-
* the tree and further to the right of a traits array take precedence, with the
|
|
701
|
-
* resource's fields always being applied last and winning out.
|
|
702
|
-
*/
|
|
703
|
-
function finalizeResource(schema, resource) {
|
|
704
|
-
const fields = new Map();
|
|
705
|
-
const seen = new Set();
|
|
706
|
-
for (const traitName of resource.traits) {
|
|
707
|
-
const trait = schema._traits.get(traitName);
|
|
708
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
709
|
-
if (!test) {
|
|
710
|
-
throw new Error(`The trait ${traitName} MUST be supplied before the resource ${resource.original.type} can be finalized for use.`);
|
|
711
|
-
}
|
|
712
|
-
})(trait) : {};
|
|
713
|
-
walkTrait(schema, trait, fields, seen, resource.original.type, macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? [] : null);
|
|
714
|
-
}
|
|
715
|
-
mergeMap(fields, resource.fields);
|
|
716
|
-
resource.fields = fields;
|
|
717
|
-
resource.cacheFields = getCacheFields(resource);
|
|
718
|
-
resource.finalized = true;
|
|
719
|
-
}
|
|
720
|
-
function getCacheFields(resource) {
|
|
721
|
-
const {
|
|
722
|
-
fields
|
|
723
|
-
} = resource;
|
|
724
|
-
const cacheFields = new Map();
|
|
725
|
-
for (const [key, value] of fields) {
|
|
726
|
-
if (isNonIdentityCacheableField(value)) {
|
|
727
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
728
|
-
if (!test) {
|
|
729
|
-
throw new Error(`The sourceKey '${value.sourceKey}' for the field '${key}' on ${resource.original.type} is invalid because it matches the name of an existing field`);
|
|
730
|
-
}
|
|
731
|
-
})(!value.sourceKey || value.sourceKey === key || !fields.has(value.sourceKey)) : {};
|
|
732
|
-
const cacheKey = getFieldCacheKeyStrict(value);
|
|
733
|
-
cacheFields.set(cacheKey, value);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
return cacheFields;
|
|
737
|
-
}
|
|
738
|
-
function walkTrait(schema, trait, fields, seen, type, debugPath) {
|
|
739
|
-
if (seen.has(trait)) {
|
|
740
|
-
// if the trait is in the current path, we throw a cycle error in dev.
|
|
741
|
-
if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
|
|
742
|
-
if (debugPath.includes(trait.name)) {
|
|
743
|
-
throw new Error(`CycleError: The Trait '${trait.name}' utilized by the Resource '${type}' includes the following circular reference "${debugPath.join(' > ')} > ${trait.name}"`);
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
return;
|
|
747
|
-
}
|
|
748
|
-
const ownPath = macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? [...debugPath, trait.name] : null;
|
|
749
|
-
|
|
750
|
-
// immediately mark as seen to prevent cycles
|
|
751
|
-
// further down the tree from looping back
|
|
752
|
-
seen.add(trait);
|
|
753
|
-
|
|
754
|
-
// first apply any child traits
|
|
755
|
-
if (trait.traits?.length) {
|
|
756
|
-
for (const traitName of trait.traits) {
|
|
757
|
-
const subtrait = schema._traits.get(traitName);
|
|
758
|
-
if (macroCondition(getGlobalConfig().WarpDrive.features.ENFORCE_STRICT_RESOURCE_FINALIZATION)) {
|
|
759
|
-
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
760
|
-
if (!test) {
|
|
761
|
-
throw new Error(`The trait ${traitName} used by the trait ${trait.name} MUST be supplied before the resource ${type} can be finalized for use.`);
|
|
762
|
-
}
|
|
763
|
-
})(subtrait) : {};
|
|
764
|
-
} else {
|
|
765
|
-
warn(`The trait ${traitName} used by the trait ${trait.name} MUST be supplied before the resource ${type} can be finalized for use.`, !!subtrait, {
|
|
766
|
-
id: 'warp-drive:missing-trait-schema-for-resource'
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
if (!subtrait) continue;
|
|
770
|
-
walkTrait(schema, subtrait, fields, seen, type, ownPath);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// then apply our own fields
|
|
775
|
-
mergeMap(fields, trait.fields);
|
|
776
|
-
}
|
|
777
|
-
function mergeMap(base, toApply) {
|
|
778
|
-
for (const [key, value] of toApply) {
|
|
779
|
-
base.set(key, value);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
8
|
const Subscriptions = new WeakMap();
|
|
783
9
|
|
|
784
10
|
/**
|
|
@@ -900,4 +126,4 @@ function getExpensiveRequestSubscription(store, requestKey, callback) {
|
|
|
900
126
|
subscription.removeWatcher(callback);
|
|
901
127
|
};
|
|
902
128
|
}
|
|
903
|
-
export {
|
|
129
|
+
export { getExpensiveRequestSubscription };
|