@warp-drive/schema-record 0.0.0-alpha.38

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.
@@ -0,0 +1,307 @@
1
+ import { assert } from '@ember/debug';
2
+ import { defineSignal, Signals, addToTransaction, entangleSignal, getSignal, peekSignal } from '@ember-data/tracking/-private';
3
+ import { STRUCTURED } from '@warp-drive/core-types/request';
4
+ import { RecordStore } from '@warp-drive/core-types/symbols';
5
+ import { ARRAY_SIGNAL, ManagedArray } from "./managed-array";
6
+ import { macroCondition, getOwnConfig } from '@embroider/macros';
7
+ const Destroy = Symbol('Destroy');
8
+ const Identifier = Symbol('Identifier');
9
+ const Editable = Symbol('Editable');
10
+ const Parent = Symbol('Parent');
11
+ const Checkout = Symbol('Checkout');
12
+ const Legacy = Symbol('Legacy');
13
+ const IgnoredGlobalFields = new Set(['then', STRUCTURED]);
14
+ const RecordSymbols = new Set([Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals]);
15
+ const ManagedArrayMap = new Map();
16
+ function computeLocal(record, field, prop) {
17
+ let signal = peekSignal(record, prop);
18
+ if (!signal) {
19
+ signal = getSignal(record, prop, false);
20
+ signal.lastValue = field.options?.defaultValue ?? null;
21
+ }
22
+ return signal.lastValue;
23
+ }
24
+ function peekManagedArray(record, field) {
25
+ const managedArrayMapForRecord = ManagedArrayMap.get(record);
26
+ if (managedArrayMapForRecord) {
27
+ return managedArrayMapForRecord.get(field);
28
+ }
29
+ }
30
+ function computeField(schema, cache, record, identifier, field, prop) {
31
+ const rawValue = cache.getAttr(identifier, prop);
32
+ if (field.type === null) {
33
+ return rawValue;
34
+ }
35
+ const transform = schema.transforms.get(field.type);
36
+ if (!transform) {
37
+ throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
38
+ }
39
+ return transform.hydrate(rawValue, field.options ?? null, record);
40
+ }
41
+ function computeArray(store, schema, cache, record, identifier, field, prop) {
42
+ // the thing we hand out needs to know its owner and path in a private manner
43
+ // its "address" is the parent identifier (identifier) + field name (field.name)
44
+ // in the nested object case field name here is the full dot path from root resource to this value
45
+ // its "key" is the field on the parent record
46
+ // its "owner" is the parent record
47
+
48
+ const managedArrayMapForRecord = ManagedArrayMap.get(record);
49
+ let managedArray;
50
+ if (managedArrayMapForRecord) {
51
+ managedArray = managedArrayMapForRecord.get(field);
52
+ }
53
+ if (managedArray) {
54
+ return managedArray;
55
+ } else {
56
+ const rawValue = cache.getAttr(identifier, prop);
57
+ if (!rawValue) {
58
+ return null;
59
+ }
60
+ managedArray = new ManagedArray(store, schema, cache, field, rawValue, identifier, prop, record);
61
+ if (!managedArrayMapForRecord) {
62
+ ManagedArrayMap.set(record, new Map([[field, managedArray]]));
63
+ } else {
64
+ managedArrayMapForRecord.set(field, managedArray);
65
+ }
66
+ }
67
+ return managedArray;
68
+ }
69
+ function computeAttribute(cache, identifier, prop) {
70
+ return cache.getAttr(identifier, prop);
71
+ }
72
+ function computeDerivation(schema, record, identifier, field, prop) {
73
+ if (field.type === null) {
74
+ throw new Error(`The schema for ${identifier.type}.${String(prop)} is missing the type of the derivation`);
75
+ }
76
+ const derivation = schema.derivations.get(field.type);
77
+ if (!derivation) {
78
+ throw new Error(`No '${field.type}' derivation defined for use by ${identifier.type}.${String(prop)}`);
79
+ }
80
+ return derivation(record, field.options ?? null, prop);
81
+ }
82
+
83
+ // TODO probably this should just be a Document
84
+ // but its separate until we work out the lid situation
85
+ class ResourceRelationship {
86
+ constructor(store, cache, parent, identifier, field, name) {
87
+ const rawValue = cache.getRelationship(identifier, name);
88
+
89
+ // TODO setup true lids for relationship documents
90
+ // @ts-expect-error we need to give relationship documents a lid
91
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
92
+ this.lid = rawValue.lid ?? rawValue.links?.self ?? `relationship:${identifier.lid}.${name}`;
93
+ this.data = rawValue.data ? store.peekRecord(rawValue.data) : null;
94
+ this.name = name;
95
+ if (macroCondition(getOwnConfig().env.DEBUG)) {
96
+ this.links = Object.freeze(Object.assign({}, rawValue.links));
97
+ this.meta = Object.freeze(Object.assign({}, rawValue.meta));
98
+ } else {
99
+ this.links = rawValue.links ?? {};
100
+ this.meta = rawValue.meta ?? {};
101
+ }
102
+ this[RecordStore] = store;
103
+ this[Parent] = parent;
104
+ }
105
+ fetch(options) {
106
+ const url = options?.url ?? getHref(this.links.related) ?? getHref(this.links.self) ?? null;
107
+ if (!url) {
108
+ throw new Error(`Cannot ${options?.method ?? 'fetch'} ${this[Parent][Identifier].type}.${String(this.name)} because it has no related link`);
109
+ }
110
+ const request = Object.assign({
111
+ url,
112
+ method: 'GET'
113
+ }, options);
114
+ return this[RecordStore].request(request);
115
+ }
116
+ }
117
+ defineSignal(ResourceRelationship.prototype, 'data');
118
+ defineSignal(ResourceRelationship.prototype, 'links');
119
+ defineSignal(ResourceRelationship.prototype, 'meta');
120
+ function getHref(link) {
121
+ if (!link) {
122
+ return null;
123
+ }
124
+ if (typeof link === 'string') {
125
+ return link;
126
+ }
127
+ return link.href;
128
+ }
129
+ function computeResource(store, cache, parent, identifier, field, prop) {
130
+ if (field.kind !== 'resource') {
131
+ throw new Error(`The schema for ${identifier.type}.${String(prop)} is not a resource relationship`);
132
+ }
133
+ return new ResourceRelationship(store, cache, parent, identifier, field, prop);
134
+ }
135
+ class SchemaRecord {
136
+ constructor(store, identifier, Mode) {
137
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
138
+ const self = this;
139
+ this[RecordStore] = store;
140
+ this[Identifier] = identifier;
141
+ const IS_EDITABLE = this[Editable] = Mode[Editable] ?? false;
142
+ this[Legacy] = Mode[Legacy] ?? false;
143
+ const schema = store.schema;
144
+ const cache = store.cache;
145
+ const fields = schema.fields(identifier);
146
+ const signals = new Map();
147
+ this[Signals] = signals;
148
+ this.___notifications = store.notifications.subscribe(identifier, (_, type, key) => {
149
+ switch (type) {
150
+ case 'attributes':
151
+ if (key) {
152
+ const signal = signals.get(key);
153
+ if (signal) {
154
+ addToTransaction(signal);
155
+ }
156
+ const field = fields.get(key);
157
+ if (field?.kind === 'array') {
158
+ const peeked = peekManagedArray(self, field);
159
+ if (peeked) {
160
+ const arrSignal = peeked[ARRAY_SIGNAL];
161
+ arrSignal.shouldReset = true;
162
+ addToTransaction(arrSignal);
163
+ }
164
+ }
165
+ }
166
+ break;
167
+ }
168
+ });
169
+ return new Proxy(this, {
170
+ get(target, prop, receiver) {
171
+ if (RecordSymbols.has(prop)) {
172
+ return target[prop];
173
+ }
174
+ if (prop === '___notifications') {
175
+ return target.___notifications;
176
+ }
177
+
178
+ // SchemaRecord reserves use of keys that begin with these characters
179
+ // for its own usage.
180
+ // _, @, $, *
181
+
182
+ const field = fields.get(prop);
183
+ if (!field) {
184
+ if (IgnoredGlobalFields.has(prop)) {
185
+ return undefined;
186
+ }
187
+ throw new Error(`No field named ${String(prop)} on ${identifier.type}`);
188
+ }
189
+ switch (field.kind) {
190
+ case '@id':
191
+ entangleSignal(signals, receiver, '@identity');
192
+ return identifier.id;
193
+ case '@local':
194
+ {
195
+ const lastValue = computeLocal(receiver, field, prop);
196
+ entangleSignal(signals, receiver, prop);
197
+ return lastValue;
198
+ }
199
+ case 'field':
200
+ assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
201
+ entangleSignal(signals, receiver, field.name);
202
+ return computeField(schema, cache, target, identifier, field, prop);
203
+ case 'attribute':
204
+ entangleSignal(signals, receiver, field.name);
205
+ return computeAttribute(cache, identifier, prop);
206
+ case 'resource':
207
+ assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
208
+ entangleSignal(signals, receiver, field.name);
209
+ return computeResource(store, cache, target, identifier, field, prop);
210
+ case 'derived':
211
+ return computeDerivation(schema, receiver, identifier, field, prop);
212
+ case 'array':
213
+ assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
214
+ entangleSignal(signals, receiver, field.name);
215
+ return computeArray(store, schema, cache, target, identifier, field, prop);
216
+ default:
217
+ throw new Error(`Field '${String(prop)}' on '${identifier.type}' has the unknown kind '${field.kind}'`);
218
+ }
219
+ },
220
+ set(target, prop, value, receiver) {
221
+ if (!IS_EDITABLE) {
222
+ throw new Error(`Cannot set ${String(prop)} on ${identifier.type} because the record is not editable`);
223
+ }
224
+ const field = fields.get(prop);
225
+ if (!field) {
226
+ throw new Error(`There is no field named ${String(prop)} on ${identifier.type}`);
227
+ }
228
+ switch (field.kind) {
229
+ case '@local':
230
+ {
231
+ const signal = getSignal(receiver, prop, true);
232
+ if (signal.lastValue !== value) {
233
+ signal.lastValue = value;
234
+ addToTransaction(signal);
235
+ }
236
+ return true;
237
+ }
238
+ case 'field':
239
+ {
240
+ if (field.type === null) {
241
+ cache.setAttr(identifier, prop, value);
242
+ return true;
243
+ }
244
+ const transform = schema.transforms.get(field.type);
245
+ if (!transform) {
246
+ throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
247
+ }
248
+ const rawValue = transform.serialize(value, field.options ?? null, target);
249
+ cache.setAttr(identifier, prop, rawValue);
250
+ return true;
251
+ }
252
+ case 'attribute':
253
+ {
254
+ cache.setAttr(identifier, prop, value);
255
+ return true;
256
+ }
257
+ case 'array':
258
+ {
259
+ if (field.type === null) {
260
+ cache.setAttr(identifier, prop, value?.slice());
261
+ const peeked = peekManagedArray(self, field);
262
+ if (peeked) {
263
+ const arrSignal = peeked[ARRAY_SIGNAL];
264
+ arrSignal.shouldReset = true;
265
+ }
266
+ if (!Array.isArray(value)) {
267
+ ManagedArrayMap.delete(target);
268
+ }
269
+ return true;
270
+ }
271
+ const transform = schema.transforms.get(field.type);
272
+ if (!transform) {
273
+ throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
274
+ }
275
+ const rawValue = value.map(item => transform.serialize(item, field.options ?? null, target));
276
+ cache.setAttr(identifier, prop, rawValue);
277
+ const peeked = peekManagedArray(self, field);
278
+ if (peeked) {
279
+ const arrSignal = peeked[ARRAY_SIGNAL];
280
+ arrSignal.shouldReset = true;
281
+ }
282
+ return true;
283
+ }
284
+ case 'derived':
285
+ {
286
+ throw new Error(`Cannot set ${String(prop)} on ${identifier.type} because it is derived`);
287
+ }
288
+ default:
289
+ throw new Error(`Unknown field kind ${field.kind}`);
290
+ }
291
+ }
292
+ });
293
+ }
294
+ [Destroy]() {
295
+ if (this[Legacy]) {
296
+ // @ts-expect-error
297
+ this.isDestroying = true;
298
+ // @ts-expect-error
299
+ this.isDestroyed = true;
300
+ }
301
+ this[RecordStore].notifications.unsubscribe(this.___notifications);
302
+ }
303
+ [Checkout]() {
304
+ return Promise.resolve(this);
305
+ }
306
+ }
307
+ export { Checkout, Destroy, Editable, Identifier, Legacy, Parent, SchemaRecord };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sources":["../src/record.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { DEBUG } from '@ember-data/env';\nimport type { Future } from '@ember-data/request';\nimport type Store from '@ember-data/store';\nimport type { StoreRequestInput } from '@ember-data/store/-private/cache-handler';\nimport type { NotificationType } from '@ember-data/store/-private/managers/notification-manager';\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\nimport {\n addToTransaction,\n defineSignal,\n entangleSignal,\n getSignal,\n peekSignal,\n type Signal,\n Signals,\n} from '@ember-data/tracking/-private';\nimport type { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Cache } from '@warp-drive/core-types/cache';\nimport type { ResourceRelationship as SingleResourceRelationship } from '@warp-drive/core-types/cache/relationship';\nimport type { ArrayValue, Value } from '@warp-drive/core-types/json/raw';\nimport { STRUCTURED } from '@warp-drive/core-types/request';\nimport type { Link, Links } from '@warp-drive/core-types/spec/raw';\nimport { RecordStore } from '@warp-drive/core-types/symbols';\n\nimport { ARRAY_SIGNAL, ManagedArray } from './managed-array';\nimport type { SchemaService } from './schema';\n\nexport const Destroy = Symbol('Destroy');\nexport const Identifier = Symbol('Identifier');\nexport const Editable = Symbol('Editable');\nexport const Parent = Symbol('Parent');\nexport const Checkout = Symbol('Checkout');\nexport const Legacy = Symbol('Legacy');\n\nconst IgnoredGlobalFields = new Set(['then', STRUCTURED]);\nconst RecordSymbols = new Set([Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals]);\n\nconst ManagedArrayMap = new Map<SchemaRecord, Map<FieldSchema, ManagedArray>>();\n\nfunction computeLocal(record: typeof Proxy<SchemaRecord>, field: FieldSchema, prop: string): unknown {\n let signal = peekSignal(record, prop);\n\n if (!signal) {\n signal = getSignal(record, prop, false);\n signal.lastValue = field.options?.defaultValue ?? null;\n }\n\n return signal.lastValue;\n}\n\nfunction peekManagedArray(record: SchemaRecord, field: FieldSchema): ManagedArray | undefined {\n const managedArrayMapForRecord = ManagedArrayMap.get(record);\n if (managedArrayMapForRecord) {\n return managedArrayMapForRecord.get(field);\n }\n}\n\nfunction computeField(\n schema: SchemaService,\n cache: Cache,\n record: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: FieldSchema,\n prop: string\n): unknown {\n const rawValue = cache.getAttr(identifier, prop);\n if (field.type === null) {\n return rawValue;\n }\n const transform = schema.transforms.get(field.type);\n if (!transform) {\n throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);\n }\n return transform.hydrate(rawValue, field.options ?? null, record);\n}\n\nfunction computeArray(\n store: Store,\n schema: SchemaService,\n cache: Cache,\n record: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: FieldSchema,\n prop: string\n) {\n // the thing we hand out needs to know its owner and path in a private manner\n // its \"address\" is the parent identifier (identifier) + field name (field.name)\n // in the nested object case field name here is the full dot path from root resource to this value\n // its \"key\" is the field on the parent record\n // its \"owner\" is the parent record\n\n const managedArrayMapForRecord = ManagedArrayMap.get(record);\n let managedArray;\n if (managedArrayMapForRecord) {\n managedArray = managedArrayMapForRecord.get(field);\n }\n if (managedArray) {\n return managedArray;\n } else {\n const rawValue = cache.getAttr(identifier, prop) as unknown[];\n if (!rawValue) {\n return null;\n }\n managedArray = new ManagedArray(store, schema, cache, field, rawValue, identifier, prop, record);\n if (!managedArrayMapForRecord) {\n ManagedArrayMap.set(record, new Map([[field, managedArray]]));\n } else {\n managedArrayMapForRecord.set(field, managedArray);\n }\n }\n return managedArray;\n}\n\nfunction computeAttribute(cache: Cache, identifier: StableRecordIdentifier, prop: string): unknown {\n return cache.getAttr(identifier, prop);\n}\n\nfunction computeDerivation(\n schema: SchemaService,\n record: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: FieldSchema,\n prop: string\n): unknown {\n if (field.type === null) {\n throw new Error(`The schema for ${identifier.type}.${String(prop)} is missing the type of the derivation`);\n }\n\n const derivation = schema.derivations.get(field.type);\n if (!derivation) {\n throw new Error(`No '${field.type}' derivation defined for use by ${identifier.type}.${String(prop)}`);\n }\n return derivation(record, field.options ?? null, prop);\n}\n\n// TODO probably this should just be a Document\n// but its separate until we work out the lid situation\nclass ResourceRelationship<T extends SchemaRecord = SchemaRecord> {\n declare lid: string;\n declare [Parent]: SchemaRecord;\n declare [RecordStore]: Store;\n declare name: string;\n\n declare data: T | null;\n declare links: Links;\n declare meta: Record<string, unknown>;\n\n constructor(\n store: Store,\n cache: Cache,\n parent: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: FieldSchema,\n name: string\n ) {\n const rawValue = cache.getRelationship(identifier, name) as SingleResourceRelationship;\n\n // TODO setup true lids for relationship documents\n // @ts-expect-error we need to give relationship documents a lid\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.lid = rawValue.lid ?? rawValue.links?.self ?? `relationship:${identifier.lid}.${name}`;\n this.data = rawValue.data ? store.peekRecord<T>(rawValue.data) : null;\n this.name = name;\n\n if (DEBUG) {\n this.links = Object.freeze(Object.assign({}, rawValue.links));\n this.meta = Object.freeze(Object.assign({}, rawValue.meta));\n } else {\n this.links = rawValue.links ?? {};\n this.meta = rawValue.meta ?? {};\n }\n\n this[RecordStore] = store;\n this[Parent] = parent;\n }\n\n fetch(options?: StoreRequestInput): Future<T> {\n const url = options?.url ?? getHref(this.links.related) ?? getHref(this.links.self) ?? null;\n\n if (!url) {\n throw new Error(\n `Cannot ${options?.method ?? 'fetch'} ${this[Parent][Identifier].type}.${String(\n this.name\n )} because it has no related link`\n );\n }\n const request = Object.assign(\n {\n url,\n method: 'GET',\n },\n options\n );\n\n return this[RecordStore].request<T>(request);\n }\n}\n\ndefineSignal(ResourceRelationship.prototype, 'data');\ndefineSignal(ResourceRelationship.prototype, 'links');\ndefineSignal(ResourceRelationship.prototype, 'meta');\n\nfunction getHref(link?: Link | null): string | null {\n if (!link) {\n return null;\n }\n if (typeof link === 'string') {\n return link;\n }\n return link.href;\n}\n\nfunction computeResource<T extends SchemaRecord>(\n store: Store,\n cache: Cache,\n parent: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: FieldSchema,\n prop: string\n): ResourceRelationship<T> {\n if (field.kind !== 'resource') {\n throw new Error(`The schema for ${identifier.type}.${String(prop)} is not a resource relationship`);\n }\n\n return new ResourceRelationship<T>(store, cache, parent, identifier, field, prop);\n}\n\nexport class SchemaRecord {\n declare [RecordStore]: Store;\n declare [Identifier]: StableRecordIdentifier;\n declare [Editable]: boolean;\n declare [Legacy]: boolean;\n declare [Signals]: Map<string, Signal>;\n declare ___notifications: object;\n\n constructor(store: Store, identifier: StableRecordIdentifier, Mode: { [Editable]: boolean; [Legacy]: boolean }) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n this[RecordStore] = store;\n this[Identifier] = identifier;\n const IS_EDITABLE = (this[Editable] = Mode[Editable] ?? false);\n this[Legacy] = Mode[Legacy] ?? false;\n\n const schema = store.schema as unknown as SchemaService;\n const cache = store.cache;\n const fields = schema.fields(identifier);\n\n const signals: Map<string, Signal> = new Map();\n this[Signals] = signals;\n this.___notifications = store.notifications.subscribe(\n identifier,\n (_: StableRecordIdentifier, type: NotificationType, key?: string) => {\n switch (type) {\n case 'attributes':\n if (key) {\n const signal = signals.get(key);\n if (signal) {\n addToTransaction(signal);\n }\n const field = fields.get(key);\n if (field?.kind === 'array') {\n const peeked = peekManagedArray(self, field);\n if (peeked) {\n const arrSignal = peeked[ARRAY_SIGNAL];\n arrSignal.shouldReset = true;\n addToTransaction(arrSignal);\n }\n }\n }\n break;\n }\n }\n );\n\n return new Proxy(this, {\n get(target: SchemaRecord, prop: string | number | symbol, receiver: typeof Proxy<SchemaRecord>) {\n if (RecordSymbols.has(prop as symbol)) {\n return target[prop as keyof SchemaRecord];\n }\n\n if (prop === '___notifications') {\n return target.___notifications;\n }\n\n // SchemaRecord reserves use of keys that begin with these characters\n // for its own usage.\n // _, @, $, *\n\n const field = fields.get(prop as string);\n if (!field) {\n if (IgnoredGlobalFields.has(prop as string | symbol)) {\n return undefined;\n }\n throw new Error(`No field named ${String(prop)} on ${identifier.type}`);\n }\n\n switch (field.kind) {\n case '@id':\n entangleSignal(signals, receiver, '@identity');\n return identifier.id;\n case '@local': {\n const lastValue = computeLocal(receiver, field, prop as string);\n entangleSignal(signals, receiver, prop as string);\n return lastValue;\n }\n case 'field':\n assert(\n `SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`,\n !target[Legacy]\n );\n entangleSignal(signals, receiver, field.name);\n return computeField(schema, cache, target, identifier, field, prop as string);\n case 'attribute':\n entangleSignal(signals, receiver, field.name);\n return computeAttribute(cache, identifier, prop as string);\n case 'resource':\n assert(\n `SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`,\n !target[Legacy]\n );\n entangleSignal(signals, receiver, field.name);\n return computeResource(store, cache, target, identifier, field, prop as string);\n case 'derived':\n return computeDerivation(schema, receiver as unknown as SchemaRecord, identifier, field, prop as string);\n case 'array':\n assert(\n `SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`,\n !target[Legacy]\n );\n entangleSignal(signals, receiver, field.name);\n return computeArray(store, schema, cache, target, identifier, field, prop as string);\n default:\n throw new Error(`Field '${String(prop)}' on '${identifier.type}' has the unknown kind '${field.kind}'`);\n }\n },\n set(target: SchemaRecord, prop: string | number | symbol, value: unknown, receiver: typeof Proxy<SchemaRecord>) {\n if (!IS_EDITABLE) {\n throw new Error(`Cannot set ${String(prop)} on ${identifier.type} because the record is not editable`);\n }\n\n const field = fields.get(prop as string);\n if (!field) {\n throw new Error(`There is no field named ${String(prop)} on ${identifier.type}`);\n }\n\n switch (field.kind) {\n case '@local': {\n const signal = getSignal(receiver, prop as string, true);\n if (signal.lastValue !== value) {\n signal.lastValue = value;\n addToTransaction(signal);\n }\n return true;\n }\n case 'field': {\n if (field.type === null) {\n cache.setAttr(identifier, prop as string, value as Value);\n return true;\n }\n const transform = schema.transforms.get(field.type);\n\n if (!transform) {\n throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);\n }\n\n const rawValue = transform.serialize(value, field.options ?? null, target);\n cache.setAttr(identifier, prop as string, rawValue);\n return true;\n }\n case 'attribute': {\n cache.setAttr(identifier, prop as string, value as Value);\n return true;\n }\n case 'array': {\n if (field.type === null) {\n cache.setAttr(identifier, prop as string, (value as ArrayValue)?.slice());\n const peeked = peekManagedArray(self, field);\n if (peeked) {\n const arrSignal = peeked[ARRAY_SIGNAL];\n arrSignal.shouldReset = true;\n }\n if (!Array.isArray(value)) {\n ManagedArrayMap.delete(target);\n }\n return true;\n }\n\n const transform = schema.transforms.get(field.type);\n if (!transform) {\n throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);\n }\n\n const rawValue = (value as ArrayValue).map((item) =>\n transform.serialize(item, field.options ?? null, target)\n );\n cache.setAttr(identifier, prop as string, rawValue);\n const peeked = peekManagedArray(self, field);\n if (peeked) {\n const arrSignal = peeked[ARRAY_SIGNAL];\n arrSignal.shouldReset = true;\n }\n return true;\n }\n case 'derived': {\n throw new Error(`Cannot set ${String(prop)} on ${identifier.type} because it is derived`);\n }\n default:\n throw new Error(`Unknown field kind ${field.kind}`);\n }\n },\n });\n }\n\n [Destroy](): void {\n if (this[Legacy]) {\n // @ts-expect-error\n this.isDestroying = true;\n // @ts-expect-error\n this.isDestroyed = true;\n }\n this[RecordStore].notifications.unsubscribe(this.___notifications);\n }\n [Checkout](): Promise<SchemaRecord> {\n return Promise.resolve(this);\n }\n}\n"],"names":["Destroy","Symbol","Identifier","Editable","Parent","Checkout","Legacy","IgnoredGlobalFields","Set","STRUCTURED","RecordSymbols","RecordStore","Signals","ManagedArrayMap","Map","computeLocal","record","field","prop","signal","peekSignal","getSignal","lastValue","options","defaultValue","peekManagedArray","managedArrayMapForRecord","get","computeField","schema","cache","identifier","rawValue","getAttr","type","transform","transforms","Error","String","hydrate","computeArray","store","managedArray","ManagedArray","set","computeAttribute","computeDerivation","derivation","derivations","ResourceRelationship","constructor","parent","name","getRelationship","lid","links","self","data","peekRecord","macroCondition","getOwnConfig","env","DEBUG","Object","freeze","assign","meta","fetch","url","getHref","related","method","request","defineSignal","prototype","link","href","computeResource","kind","SchemaRecord","Mode","IS_EDITABLE","fields","signals","___notifications","notifications","subscribe","_","key","addToTransaction","peeked","arrSignal","ARRAY_SIGNAL","shouldReset","Proxy","target","receiver","has","undefined","entangleSignal","id","assert","value","setAttr","serialize","slice","Array","isArray","delete","map","item","isDestroying","isDestroyed","unsubscribe","Promise","resolve"],"mappings":";;;;;;;MA4BaA,OAAO,GAAGC,MAAM,CAAC,SAAS,EAAC;MAC3BC,UAAU,GAAGD,MAAM,CAAC,YAAY,EAAC;MACjCE,QAAQ,GAAGF,MAAM,CAAC,UAAU,EAAC;MAC7BG,MAAM,GAAGH,MAAM,CAAC,QAAQ,EAAC;MACzBI,QAAQ,GAAGJ,MAAM,CAAC,UAAU,EAAC;MAC7BK,MAAM,GAAGL,MAAM,CAAC,QAAQ,EAAC;AAEtC,MAAMM,mBAAmB,GAAG,IAAIC,GAAG,CAAC,CAAC,MAAM,EAAEC,UAAU,CAAC,CAAC,CAAA;AACzD,MAAMC,aAAa,GAAG,IAAIF,GAAG,CAAC,C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,CAACyG,YAAY,GAAG,IAAI,CAAA;AACxB;MACA,IAAI,CAACC,WAAW,GAAG,IAAI,CAAA;AACzB,KAAA;IACA,IAAI,CAACrG,WAAW,CAAC,CAAC0E,aAAa,CAAC4B,WAAW,CAAC,IAAI,CAAC7B,gBAAgB,CAAC,CAAA;AACpE,GAAA;AACA,EAAA,CAAC/E,QAAQ,CAA2B,GAAA;AAClC,IAAA,OAAO6G,OAAO,CAACC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC9B,GAAA;AACF;;;;"}
@@ -0,0 +1,152 @@
1
+ import { assert } from '@ember/debug';
2
+ import { createCache, getValue } from '@ember-data/tracking';
3
+ import { Signals } from '@ember-data/tracking/-private';
4
+ import { recordIdentifierFor } from '@ember-data/store';
5
+ import { Identifier } from "./record";
6
+ const Support = new WeakMap();
7
+ const SchemaRecordFields = [{
8
+ type: '@constructor',
9
+ name: 'constructor',
10
+ kind: 'derived'
11
+ }, {
12
+ name: 'id',
13
+ kind: '@id',
14
+ type: null
15
+ }, {
16
+ type: '@identity',
17
+ name: '$type',
18
+ kind: 'derived',
19
+ options: {
20
+ key: 'type'
21
+ }
22
+ }];
23
+ const _constructor = function (record) {
24
+ let state = Support.get(record);
25
+ if (!state) {
26
+ state = {};
27
+ Support.set(record, state);
28
+ }
29
+ return state._constructor = state._constructor || {
30
+ name: `SchemaRecord<${recordIdentifierFor(record).type}>`,
31
+ get modelName() {
32
+ throw new Error('Cannot access record.constructor.modelName on non-Legacy Schema Records.');
33
+ }
34
+ };
35
+ };
36
+ function withFields(fields) {
37
+ fields.push(...SchemaRecordFields);
38
+ return fields;
39
+ }
40
+ function fromIdentity(record, options, key) {
41
+ const identifier = record[Identifier];
42
+ assert(`Cannot compute @identity for a record without an identifier`, identifier);
43
+ assert(`Expected to receive a key to compute @identity, but got ${String(options)}`, options?.key && ['lid', 'id', 'type', '^'].includes(options.key));
44
+ return options.key === '^' ? identifier : identifier[options.key];
45
+ }
46
+ function registerDerivations(schema) {
47
+ schema.registerDerivation('@identity', fromIdentity);
48
+ schema.registerDerivation('@constructor', _constructor);
49
+ }
50
+
51
+ /**
52
+ * The full schema for a resource
53
+ *
54
+ * @class FieldSpec
55
+ * @internal
56
+ */
57
+
58
+ /**
59
+ * Wraps a derivation in a new function with Derivation signature but that looks
60
+ * up the value in the cache before recomputing.
61
+ *
62
+ * @param record
63
+ * @param options
64
+ * @param prop
65
+ */
66
+ function makeCachedDerivation(derivation) {
67
+ return (record, options, prop) => {
68
+ const signals = record[Signals];
69
+ let signal = signals.get(prop);
70
+ if (!signal) {
71
+ signal = createCache(() => {
72
+ return derivation(record, options, prop);
73
+ }); // a total lie, for convenience of reusing the storage
74
+ signals.set(prop, signal);
75
+ }
76
+ return getValue(signal);
77
+ };
78
+ }
79
+ class SchemaService {
80
+ constructor() {
81
+ this.schemas = new Map();
82
+ this.transforms = new Map();
83
+ this.derivations = new Map();
84
+ }
85
+ registerTransform(type, transform) {
86
+ this.transforms.set(type, transform);
87
+ }
88
+ registerDerivation(type, derivation) {
89
+ this.derivations.set(type, makeCachedDerivation(derivation));
90
+ }
91
+ defineSchema(name, schema) {
92
+ const {
93
+ legacy,
94
+ fields
95
+ } = schema;
96
+ const fieldSpec = {
97
+ '@id': null,
98
+ attributes: {},
99
+ relationships: {},
100
+ fields: new Map(),
101
+ legacy: legacy ?? false
102
+ };
103
+ assert(`Only one field can be defined as @id, ${name} has more than one: ${fields.filter(f => f.kind === '@id').map(f => f.name).join(' ')}`, fields.filter(f => f.kind === '@id').length <= 1);
104
+ fields.forEach(field => {
105
+ fieldSpec.fields.set(field.name, field);
106
+ if (field.kind === '@id') {
107
+ fieldSpec['@id'] = field;
108
+ } else if (field.kind === 'field') ;else if (field.kind === 'attribute') {
109
+ fieldSpec.attributes[field.name] = field;
110
+ } else if (field.kind === 'resource' || field.kind === 'collection') {
111
+ const relSchema = Object.assign({}, field, {
112
+ kind: field.kind === 'resource' ? 'belongsTo' : 'hasMany'
113
+ });
114
+ fieldSpec.relationships[field.name] = relSchema;
115
+ } else if (field.kind !== 'derived' && field.kind !== '@local' && field.kind !== 'array') {
116
+ throw new Error(`Unknown field kind ${field.kind}`);
117
+ }
118
+ });
119
+ this.schemas.set(name, fieldSpec);
120
+ }
121
+ fields({
122
+ type
123
+ }) {
124
+ const schema = this.schemas.get(type);
125
+ if (!schema) {
126
+ throw new Error(`No schema defined for ${type}`);
127
+ }
128
+ return schema.fields;
129
+ }
130
+ attributesDefinitionFor({
131
+ type
132
+ }) {
133
+ const schema = this.schemas.get(type);
134
+ if (!schema) {
135
+ throw new Error(`No schema defined for ${type}`);
136
+ }
137
+ return schema.attributes;
138
+ }
139
+ relationshipsDefinitionFor({
140
+ type
141
+ }) {
142
+ const schema = this.schemas.get(type);
143
+ if (!schema) {
144
+ throw new Error(`No schema defined for ${type}`);
145
+ }
146
+ return schema.relationships;
147
+ }
148
+ doesTypeExist(type) {
149
+ return this.schemas.has(type);
150
+ }
151
+ }
152
+ export { SchemaService, registerDerivations, withFields };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sources":["../src/-base-fields.ts","../src/schema.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { recordIdentifierFor } from '@ember-data/store';\nimport type { OpaqueRecordInstance } from '@ember-data/store/-types/q/record-instance';\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\nimport type { StableRecordIdentifier } from '@warp-drive/core-types';\n\nimport { Identifier, type SchemaRecord } from './record';\nimport type { Derivation, SchemaService } from './schema';\n\nconst Support = new WeakMap<WeakKey, Record<string, unknown>>();\n\nexport const SchemaRecordFields: FieldSchema[] = [\n {\n type: '@constructor',\n name: 'constructor',\n kind: 'derived',\n },\n {\n name: 'id',\n kind: '@id',\n type: null,\n },\n {\n type: '@identity',\n name: '$type',\n kind: 'derived',\n options: { key: 'type' },\n },\n];\n\nconst _constructor: Derivation<OpaqueRecordInstance, unknown> = function (record) {\n let state = Support.get(record as WeakKey);\n if (!state) {\n state = {};\n Support.set(record as WeakKey, state);\n }\n\n return (state._constructor = state._constructor || {\n name: `SchemaRecord<${recordIdentifierFor(record).type}>`,\n get modelName() {\n throw new Error('Cannot access record.constructor.modelName on non-Legacy Schema Records.');\n },\n });\n};\n\nexport function withFields(fields: FieldSchema[]) {\n fields.push(...SchemaRecordFields);\n return fields;\n}\n\nexport function fromIdentity(record: SchemaRecord, options: null, key: string): asserts options;\nexport function fromIdentity(record: SchemaRecord, options: { key: 'lid' }, key: string): string;\nexport function fromIdentity(record: SchemaRecord, options: { key: 'type' }, key: string): string;\nexport function fromIdentity(record: SchemaRecord, options: { key: 'id' }, key: string): string | null;\nexport function fromIdentity(record: SchemaRecord, options: { key: '^' }, key: string): StableRecordIdentifier;\nexport function fromIdentity(\n record: SchemaRecord,\n options: { key: 'id' | 'lid' | 'type' | '^' } | null,\n key: string\n): StableRecordIdentifier | string | null {\n const identifier = record[Identifier];\n assert(`Cannot compute @identity for a record without an identifier`, identifier);\n assert(\n `Expected to receive a key to compute @identity, but got ${String(options)}`,\n options?.key && ['lid', 'id', 'type', '^'].includes(options.key)\n );\n\n return options.key === '^' ? identifier : identifier[options.key];\n}\n\nexport function registerDerivations(schema: SchemaService) {\n schema.registerDerivation(\n '@identity',\n fromIdentity as Derivation<SchemaRecord, StableRecordIdentifier | string | null>\n );\n schema.registerDerivation('@constructor', _constructor);\n}\n","import { assert } from '@ember/debug';\n\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\nimport { createCache, getValue } from '@ember-data/tracking';\nimport { type Signal, Signals } from '@ember-data/tracking/-private';\nimport type { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Value } from '@warp-drive/core-types/json/raw';\nimport type { AttributeSchema, RelationshipSchema } from '@warp-drive/core-types/schema';\n\nimport type { SchemaRecord } from './record';\n\nexport { withFields, registerDerivations } from './-base-fields';\n\n/**\n * The full schema for a resource\n *\n * @class FieldSpec\n * @internal\n */\ntype FieldSpec = {\n '@id': FieldSchema | null;\n /**\n * legacy schema service separated attribute\n * from relationship lookup\n * @internal\n */\n attributes: Record<string, AttributeSchema>;\n /**\n * legacy schema service separated attribute\n * from relationship lookup\n * @internal\n */\n relationships: Record<string, RelationshipSchema>;\n /**\n * new schema service is fields based\n * @internal\n */\n fields: Map<string, FieldSchema>;\n /**\n * legacy model mode support\n * @internal\n */\n legacy?: boolean;\n};\n\nexport type Transform<T extends Value = string, PT = unknown> = {\n serialize(value: PT, options: Record<string, unknown> | null, record: SchemaRecord): T;\n hydrate(value: T | undefined, options: Record<string, unknown> | null, record: SchemaRecord): PT;\n defaultValue?(options: Record<string, unknown> | null, identifier: StableRecordIdentifier): T;\n};\n\nexport type Derivation<R, T> = (record: R, options: Record<string, unknown> | null, prop: string) => T;\n\n/**\n * Wraps a derivation in a new function with Derivation signature but that looks\n * up the value in the cache before recomputing.\n *\n * @param record\n * @param options\n * @param prop\n */\nfunction makeCachedDerivation<R, T>(derivation: Derivation<R, T>): Derivation<R, T> {\n return (record: R, options: Record<string, unknown> | null, prop: string): T => {\n const signals = (record as { [Signals]: Map<string, Signal> })[Signals];\n let signal = signals.get(prop);\n if (!signal) {\n signal = createCache(() => {\n return derivation(record, options, prop);\n }) as unknown as Signal; // a total lie, for convenience of reusing the storage\n signals.set(prop, signal);\n }\n\n return getValue(signal as unknown as ReturnType<typeof createCache>) as T;\n };\n}\n\nexport class SchemaService {\n declare schemas: Map<string, FieldSpec>;\n declare transforms: Map<string, Transform<Value>>;\n declare derivations: Map<string, Derivation<unknown, unknown>>;\n\n constructor() {\n this.schemas = new Map();\n this.transforms = new Map();\n this.derivations = new Map();\n }\n\n registerTransform<T extends Value = string, PT = unknown>(type: string, transform: Transform<T, PT>): void {\n this.transforms.set(type, transform);\n }\n\n registerDerivation<R, T>(type: string, derivation: Derivation<R, T>): void {\n this.derivations.set(type, makeCachedDerivation(derivation) as Derivation<unknown, unknown>);\n }\n\n defineSchema(name: string, schema: { legacy?: boolean; fields: FieldSchema[] }): void {\n const { legacy, fields } = schema;\n const fieldSpec: FieldSpec = {\n '@id': null,\n attributes: {},\n relationships: {},\n fields: new Map(),\n legacy: legacy ?? false,\n };\n\n assert(\n `Only one field can be defined as @id, ${name} has more than one: ${fields\n .filter((f) => f.kind === '@id')\n .map((f) => f.name)\n .join(' ')}`,\n fields.filter((f) => f.kind === '@id').length <= 1\n );\n fields.forEach((field) => {\n fieldSpec.fields.set(field.name, field);\n\n if (field.kind === '@id') {\n fieldSpec['@id'] = field;\n } else if (field.kind === 'field') {\n // We don't add 'field' fields to attributes in order to allow simpler\n // migration between transformation behaviors\n // serializers and things which call attributesDefinitionFor will\n // only run on the things that are legacy attribute mode, while all fields\n // will have their serialize/hydrate logic managed by the cache and record\n //\n // This means that if you want to normalize fields pre-cache insertion\n // Or pre-api call you wil need to use the newer `schema.fields()` API\n // To opt-in to that ability (which note, is now an anti-pattern)\n //\n // const attr = Object.assign({}, field, { kind: 'attribute' }) as AttributeSchema;\n // fieldSpec.attributes[attr.name] = attr;\n } else if (field.kind === 'attribute') {\n fieldSpec.attributes[field.name] = field as AttributeSchema;\n } else if (field.kind === 'resource' || field.kind === 'collection') {\n const relSchema = Object.assign({}, field, {\n kind: field.kind === 'resource' ? 'belongsTo' : 'hasMany',\n }) as unknown as RelationshipSchema;\n fieldSpec.relationships[field.name] = relSchema;\n } else if (field.kind !== 'derived' && field.kind !== '@local' && field.kind !== 'array') {\n throw new Error(`Unknown field kind ${field.kind}`);\n }\n });\n\n this.schemas.set(name, fieldSpec);\n }\n\n fields({ type }: { type: string }): FieldSpec['fields'] {\n const schema = this.schemas.get(type);\n\n if (!schema) {\n throw new Error(`No schema defined for ${type}`);\n }\n\n return schema.fields;\n }\n\n attributesDefinitionFor({ type }: { type: string }): FieldSpec['attributes'] {\n const schema = this.schemas.get(type);\n\n if (!schema) {\n throw new Error(`No schema defined for ${type}`);\n }\n\n return schema.attributes;\n }\n\n relationshipsDefinitionFor({ type }: { type: string }): FieldSpec['relationships'] {\n const schema = this.schemas.get(type);\n\n if (!schema) {\n throw new Error(`No schema defined for ${type}`);\n }\n\n return schema.relationships;\n }\n\n doesTypeExist(type: string): boolean {\n return this.schemas.has(type);\n }\n}\n"],"names":["Support","WeakMap","SchemaRecordFields","type","name","kind","options","key","_constructor","record","state","get","set","recordIdentifierFor","modelName","Error","withFields","fields","push","fromIdentity","identifier","Identifier","assert","String","includes","registerDerivations","schema","registerDerivation","makeCachedDerivation","derivation","prop","signals","Signals","signal","createCache","getValue","SchemaService","constructor","schemas","Map","transforms","derivations","registerTransform","transform","defineSchema","legacy","fieldSpec","attributes","relationships","filter","f","map","join","length","forEach","field","relSchema","Object","assign","attributesDefinitionFor","relationshipsDefinitionFor","doesTypeExist","has"],"mappings":";;;;;;AAUA,MAAMA,OAAO,GAAG,IAAIC,OAAO,EAAoC,CAAA;AAExD,MAAMC,kBAAiC,GAAG,CAC/C;AACEC,EAAAA,IAAI,EAAE,cAAc;AACpBC,EAAAA,IAAI,EAAE,aAAa;AACnBC,EAAAA,IAAI,EAAE,SAAA;AACR,CAAC,EACD;AACED,EAAAA,IAAI,EAAE,IAAI;AACVC,EAAAA,IAAI,EAAE,KAAK;AACXF,EAAAA,IAAI,EAAE,IAAA;AACR,CAAC,EACD;AACEA,EAAAA,IAAI,EAAE,WAAW;AACjBC,EAAAA,IAAI,EAAE,OAAO;AACbC,EAAAA,IAAI,EAAE,SAAS;AACfC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,GAAG,EAAE,MAAA;AAAO,GAAA;AACzB,CAAC,CACF,CAAA;AAED,MAAMC,YAAuD,GAAG,UAAUC,MAAM,EAAE;AAChF,EAAA,IAAIC,KAAK,GAAGV,OAAO,CAACW,GAAG,CAACF,MAAiB,CAAC,CAAA;EAC1C,IAAI,CAACC,KAAK,EAAE;IACVA,KAAK,GAAG,EAAE,CAAA;AACVV,IAAAA,OAAO,CAACY,GAAG,CAACH,MAAM,EAAaC,KAAK,CAAC,CAAA;AACvC,GAAA;AAEA,EAAA,OAAQA,KAAK,CAACF,YAAY,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AEAa,EAAAA,0BAA0BA,CAAC;AAAEzD,IAAAA,IAAAA;AAAuB,GAAC,EAA8B;IACjF,MAAMuB,MAAM,GAAG,IAAI,CAACY,OAAO,CAAC3B,GAAG,CAACR,IAAI,CAAC,CAAA;IAErC,IAAI,CAACuB,MAAM,EAAE;AACX,MAAA,MAAM,IAAIX,KAAK,CAAE,CAAwBZ,sBAAAA,EAAAA,IAAK,EAAC,CAAC,CAAA;AAClD,KAAA;IAEA,OAAOuB,MAAM,CAACsB,aAAa,CAAA;AAC7B,GAAA;EAEAa,aAAaA,CAAC1D,IAAY,EAAW;AACnC,IAAA,OAAO,IAAI,CAACmC,OAAO,CAACwB,GAAG,CAAC3D,IAAI,CAAC,CAAA;AAC/B,GAAA;AACF;;;;"}
package/addon-main.js ADDED
@@ -0,0 +1,94 @@
1
+ const requireModule = require('@ember-data/private-build-infra/src/utilities/require-module');
2
+ const getEnv = require('@ember-data/private-build-infra/src/utilities/get-env');
3
+ const detectModule = require('@ember-data/private-build-infra/src/utilities/detect-module');
4
+
5
+ const pkg = require('./package.json');
6
+
7
+ module.exports = {
8
+ name: pkg.name,
9
+
10
+ options: {
11
+ '@embroider/macros': {
12
+ setOwnConfig: {},
13
+ },
14
+ },
15
+
16
+ _emberDataConfig: null,
17
+ configureEmberData() {
18
+ if (this._emberDataConfig) {
19
+ return this._emberDataConfig;
20
+ }
21
+ const app = this._findHost();
22
+ const isProd = /production/.test(process.env.EMBER_ENV);
23
+ const hostOptions = app.options?.emberData || {};
24
+ const debugOptions = Object.assign(
25
+ {
26
+ LOG_PAYLOADS: false,
27
+ LOG_OPERATIONS: false,
28
+ LOG_MUTATIONS: false,
29
+ LOG_NOTIFICATIONS: false,
30
+ LOG_REQUESTS: false,
31
+ LOG_REQUEST_STATUS: false,
32
+ LOG_IDENTIFIERS: false,
33
+ LOG_GRAPH: false,
34
+ LOG_INSTANCE_CACHE: false,
35
+ },
36
+ hostOptions.debug || {}
37
+ );
38
+
39
+ const HAS_DEBUG_PACKAGE = detectModule(require, '@ember-data/debug', __dirname, pkg);
40
+ const HAS_META_PACKAGE = detectModule(require, 'ember-data', __dirname, pkg);
41
+
42
+ const includeDataAdapterInProduction =
43
+ typeof hostOptions.includeDataAdapterInProduction === 'boolean'
44
+ ? hostOptions.includeDataAdapterInProduction
45
+ : HAS_META_PACKAGE;
46
+
47
+ const includeDataAdapter = HAS_DEBUG_PACKAGE ? (isProd ? includeDataAdapterInProduction : true) : false;
48
+ const DEPRECATIONS = require('@ember-data/private-build-infra/src/deprecations')(hostOptions.compatWith || null);
49
+ const FEATURES = require('@ember-data/private-build-infra/src/features')(isProd);
50
+
51
+ const ALL_PACKAGES = requireModule('@ember-data/private-build-infra/virtual-packages/packages.js');
52
+ const MACRO_PACKAGE_FLAGS = Object.assign({}, ALL_PACKAGES.default);
53
+ delete MACRO_PACKAGE_FLAGS['HAS_DEBUG_PACKAGE'];
54
+
55
+ Object.keys(MACRO_PACKAGE_FLAGS).forEach((key) => {
56
+ MACRO_PACKAGE_FLAGS[key] = detectModule(require, MACRO_PACKAGE_FLAGS[key], __dirname, pkg);
57
+ });
58
+
59
+ // copy configs forward
60
+ const ownConfig = this.options['@embroider/macros'].setOwnConfig;
61
+ ownConfig.polyfillUUID = hostOptions.polyfillUUID ?? false;
62
+ ownConfig.compatWith = hostOptions.compatWith || null;
63
+ ownConfig.debug = debugOptions;
64
+ ownConfig.deprecations = Object.assign(DEPRECATIONS, ownConfig.deprecations || {}, hostOptions.deprecations || {});
65
+ ownConfig.features = Object.assign({}, FEATURES);
66
+ ownConfig.includeDataAdapter = includeDataAdapter;
67
+ ownConfig.packages = MACRO_PACKAGE_FLAGS;
68
+ ownConfig.env = getEnv(ownConfig);
69
+
70
+ this._emberDataConfig = ownConfig;
71
+ return ownConfig;
72
+ },
73
+
74
+ included() {
75
+ this.configureEmberData();
76
+ return this._super.included.call(this, ...arguments);
77
+ },
78
+
79
+ treeForVendor() {
80
+ return;
81
+ },
82
+ treeForPublic() {
83
+ return;
84
+ },
85
+ treeForStyles() {
86
+ return;
87
+ },
88
+ treeForAddonStyles() {
89
+ return;
90
+ },
91
+ treeForApp() {
92
+ return;
93
+ },
94
+ };