@warp-drive/legacy 5.7.0-alpha.0 → 5.7.0-alpha.1

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/dist/store.js ADDED
@@ -0,0 +1,631 @@
1
+ import { defineSignal, ensureStringId, recordIdentifierFor, constructResource, storeFor } from '@warp-drive/core/store/-private';
2
+ import { SkipCache } from '@warp-drive/core/types/request';
3
+ import { i as isMaybeIdentifier } from "./utils-Cqw9eRj5.js";
4
+ import { n as normalizeModelName } from "./util-Dul6TZts.js";
5
+ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
6
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
7
+
8
+ /*
9
+ When a find request is triggered on the store, the user can optionally pass in
10
+ attributes and relationships to be preloaded. These are meant to behave as if they
11
+ came back from the server, except the user obtained them out of band and is informing
12
+ the store of their existence. The most common use case is for supporting client side
13
+ nested URLs, such as `/posts/1/comments/2` so the user can do
14
+ `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.
15
+
16
+ Preloaded data can be attributes and relationships passed in either as IDs or as actual
17
+ models.
18
+ */
19
+ function preloadData(store, identifier, preload) {
20
+ const jsonPayload = {};
21
+ //TODO(Igor) consider the polymorphic case
22
+ const schemas = store.schema;
23
+ const fields = schemas.fields(identifier);
24
+ Object.keys(preload).forEach(key => {
25
+ const preloadValue = preload[key];
26
+ const field = fields.get(key);
27
+ if (field && (field.kind === 'hasMany' || field.kind === 'belongsTo')) {
28
+ if (!jsonPayload.relationships) {
29
+ jsonPayload.relationships = {};
30
+ }
31
+ jsonPayload.relationships[key] = preloadRelationship(field, preloadValue);
32
+ } else {
33
+ if (!jsonPayload.attributes) {
34
+ jsonPayload.attributes = {};
35
+ }
36
+ jsonPayload.attributes[key] = preloadValue;
37
+ }
38
+ });
39
+ const cache = store.cache;
40
+ const hasRecord = Boolean(store._instanceCache.peek(identifier));
41
+ cache.upsert(identifier, jsonPayload, hasRecord);
42
+ }
43
+ function preloadRelationship(schema, preloadValue) {
44
+ const relatedType = schema.type;
45
+ if (schema.kind === 'hasMany') {
46
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
47
+ if (!test) {
48
+ throw new Error('You need to pass in an array to set a hasMany property on a record');
49
+ }
50
+ })(Array.isArray(preloadValue)) : {};
51
+ return {
52
+ data: preloadValue.map(value => _convertPreloadRelationshipToJSON(value, relatedType))
53
+ };
54
+ }
55
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
56
+ if (!test) {
57
+ throw new Error('You should not pass in an array to set a belongsTo property on a record');
58
+ }
59
+ })(!Array.isArray(preloadValue)) : {};
60
+ return {
61
+ data: preloadValue ? _convertPreloadRelationshipToJSON(preloadValue, relatedType) : null
62
+ };
63
+ }
64
+
65
+ /*
66
+ findRecord('user', '1', { preload: { friends: ['1'] }});
67
+ findRecord('user', '1', { preload: { friends: [record] }});
68
+ */
69
+ function _convertPreloadRelationshipToJSON(value, type) {
70
+ if (typeof value === 'string' || typeof value === 'number') {
71
+ return {
72
+ type,
73
+ id: ensureStringId(value)
74
+ };
75
+ }
76
+ // TODO if not a record instance assert it's an identifier
77
+ // and allow identifiers to be used
78
+ return recordIdentifierFor(value);
79
+ }
80
+
81
+ /**
82
+ * Minimum subset of static schema methods and properties on the
83
+ * "model" class.
84
+ *
85
+ * Only used when using the legacy schema-service implementation
86
+ * for @ember-data/model or when wrapping schema for legacy
87
+ * Adapters/Serializers.
88
+ *
89
+ */
90
+
91
+ function _resourceIsFullDeleted(identifier, cache) {
92
+ return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
93
+ }
94
+ function resourceIsFullyDeleted(instanceCache, identifier) {
95
+ const cache = instanceCache.cache;
96
+ return !cache || _resourceIsFullDeleted(identifier, cache);
97
+ }
98
+
99
+ /**
100
+ A `RecordReference` is a low-level API that allows users and
101
+ addon authors to perform meta-operations on a record.
102
+
103
+ @hideconstructor
104
+ @public
105
+ */
106
+ class RecordReference {
107
+ /** @internal */
108
+
109
+ /** @internal */
110
+ // unsubscribe token given to us by the notification manager
111
+ ___token;
112
+ /** @internal */
113
+ ___identifier;
114
+
115
+ /** @internal */
116
+
117
+ constructor(store, identifier) {
118
+ this.store = store;
119
+ this.___identifier = identifier;
120
+ this.___token = store.notifications.subscribe(identifier, (_, bucket, notifiedKey) => {
121
+ if (bucket === 'identity' || bucket === 'attributes' && notifiedKey === 'id') {
122
+ this._ref++;
123
+ }
124
+ });
125
+ }
126
+
127
+ /** @internal */
128
+ destroy() {
129
+ this.store.notifications.unsubscribe(this.___token);
130
+ }
131
+ get type() {
132
+ return this.identifier().type;
133
+ }
134
+
135
+ /**
136
+ The `id` of the record that this reference refers to.
137
+ Together, the `type` and `id` properties form a composite key for
138
+ the identity map.
139
+ Example
140
+ ```javascript
141
+ let userRef = store.getReference('user', 1);
142
+ userRef.id(); // '1'
143
+ ```
144
+ @public
145
+ @return The id of the record.
146
+ */
147
+ id() {
148
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
149
+ this._ref; // consume the tracked prop
150
+ return this.___identifier.id;
151
+ }
152
+
153
+ /**
154
+ The `identifier` of the record that this reference refers to.
155
+ Together, the `type` and `id` properties form a composite key for
156
+ the identity map.
157
+ Example
158
+ ```javascript
159
+ let userRef = store.getReference('user', 1);
160
+ userRef.identifier(); // '1'
161
+ ```
162
+ @public
163
+ @return The identifier of the record.
164
+ */
165
+ identifier() {
166
+ return this.___identifier;
167
+ }
168
+
169
+ /**
170
+ How the reference will be looked up when it is loaded. Currently
171
+ this always returns `identity` to signify that a record will be
172
+ loaded by its `type` and `id`.
173
+ Example
174
+ ```javascript
175
+ const userRef = store.getReference('user', 1);
176
+ userRef.remoteType(); // 'identity'
177
+ ```
178
+ @public
179
+ */
180
+ remoteType() {
181
+ return 'identity';
182
+ }
183
+
184
+ /**
185
+ This API allows you to provide a reference with new data. The
186
+ simplest usage of this API is similar to `store.push`: you provide a
187
+ normalized hash of data and the object represented by the reference
188
+ will update.
189
+ If you pass a promise to `push`, Ember Data will not ask the adapter
190
+ for the data if another attempt to fetch it is made in the
191
+ interim. When the promise resolves, the underlying object is updated
192
+ with the new data, and the promise returned by *this function* is resolved
193
+ with that object.
194
+ For example, `recordReference.push(promise)` will be resolved with a
195
+ record.
196
+ Example
197
+ ```javascript
198
+ let userRef = store.getReference('user', 1);
199
+ // provide data for reference
200
+ userRef.push({
201
+ data: {
202
+ id: "1",
203
+ type: "user",
204
+ attributes: {
205
+ username: "@user"
206
+ }
207
+ }
208
+ }).then(function(user) {
209
+ userRef.value() === user;
210
+ });
211
+ ```
212
+ @public
213
+ @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one
214
+ @return a promise for the value (record or relationship)
215
+ */
216
+ push(objectOrPromise) {
217
+ // TODO @deprecate pushing unresolved payloads
218
+ return Promise.resolve(objectOrPromise).then(data => {
219
+ return this.store.push(data);
220
+ });
221
+ }
222
+
223
+ /**
224
+ If the entity referred to by the reference is already loaded, it is
225
+ present as `reference.value`. Otherwise the value returned by this function
226
+ is `null`.
227
+ Example
228
+ ```javascript
229
+ let userRef = store.getReference('user', 1);
230
+ userRef.value(); // user
231
+ ```
232
+ @public
233
+ @return {Model} the record for this RecordReference
234
+ */
235
+ value() {
236
+ return this.store.peekRecord(this.___identifier);
237
+ }
238
+
239
+ /**
240
+ Triggers a fetch for the backing entity based on its `remoteType`
241
+ (see `remoteType` definitions per reference type).
242
+ Example
243
+ ```javascript
244
+ let userRef = store.getReference('user', 1);
245
+ // load user (via store.find)
246
+ userRef.load().then(...)
247
+ ```
248
+ @public
249
+ @return the record for this RecordReference
250
+ */
251
+ load() {
252
+ const id = this.id();
253
+ if (id !== null) {
254
+ return this.store.findRecord(this.type, id);
255
+ }
256
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
257
+ {
258
+ throw new Error(`Unable to fetch record of type ${this.type} without an id`);
259
+ }
260
+ })() : {};
261
+ }
262
+
263
+ /**
264
+ Reloads the record if it is already loaded. If the record is not
265
+ loaded it will load the record via `store.findRecord`
266
+ Example
267
+ ```javascript
268
+ let userRef = store.getReference('user', 1);
269
+ // or trigger a reload
270
+ userRef.reload().then(...)
271
+ ```
272
+ @public
273
+ @return the record for this RecordReference
274
+ */
275
+ reload() {
276
+ const id = this.id();
277
+ if (id !== null) {
278
+ return this.store.findRecord(this.type, id, {
279
+ reload: true
280
+ });
281
+ }
282
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
283
+ {
284
+ throw new Error(`Unable to fetch record of type ${this.type} without an id`);
285
+ }
286
+ })() : {};
287
+ }
288
+ }
289
+ defineSignal(RecordReference.prototype, '_ref');
290
+
291
+ // if modelFor turns out to be a bottleneck we should replace with a Map
292
+ // and clear it during store teardown.
293
+ const AvailableShims = getOrSetGlobal('AvailableShims', new WeakMap());
294
+ function getShimClass(store, modelName) {
295
+ let shims = AvailableShims.get(store);
296
+ if (!shims) {
297
+ shims = Object.create(null);
298
+ AvailableShims.set(store, shims);
299
+ }
300
+ let shim = shims[modelName];
301
+ if (shim === undefined) {
302
+ shim = shims[modelName] = new ShimModelClass(store, modelName);
303
+ }
304
+ return shim;
305
+ }
306
+
307
+ // Mimics the static apis of @ember-data/model
308
+ class ShimModelClass {
309
+ constructor(store, modelName) {
310
+ this.__store = store;
311
+ this.modelName = modelName;
312
+ }
313
+ get fields() {
314
+ const fields = new Map();
315
+ const fieldSchemas = this.__store.schema.fields({
316
+ type: this.modelName
317
+ });
318
+ fieldSchemas.forEach((schema, key) => {
319
+ if (schema.kind === 'attribute' || schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
320
+ fields.set(key, schema.kind);
321
+ }
322
+ });
323
+ return fields;
324
+ }
325
+ get attributes() {
326
+ const attrs = new Map();
327
+ const fields = this.__store.schema.fields({
328
+ type: this.modelName
329
+ });
330
+ fields.forEach((schema, key) => {
331
+ if (schema.kind === 'attribute') {
332
+ attrs.set(key, schema);
333
+ }
334
+ });
335
+ return attrs;
336
+ }
337
+ get relationshipsByName() {
338
+ const rels = new Map();
339
+ const fields = this.__store.schema.fields({
340
+ type: this.modelName
341
+ });
342
+ fields.forEach((schema, key) => {
343
+ if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
344
+ rels.set(key, schema);
345
+ }
346
+ });
347
+ return rels;
348
+ }
349
+ eachAttribute(callback, binding) {
350
+ this.__store.schema.fields({
351
+ type: this.modelName
352
+ }).forEach((schema, key) => {
353
+ if (schema.kind === 'attribute') {
354
+ callback.call(binding, key, schema);
355
+ }
356
+ });
357
+ }
358
+ eachRelationship(callback, binding) {
359
+ this.__store.schema.fields({
360
+ type: this.modelName
361
+ }).forEach((schema, key) => {
362
+ if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
363
+ callback.call(binding, key, schema);
364
+ }
365
+ });
366
+ }
367
+ eachTransformedAttribute(callback, binding) {
368
+ this.__store.schema.fields({
369
+ type: this.modelName
370
+ }).forEach((schema, key) => {
371
+ if (schema.kind === 'attribute') {
372
+ const type = schema.type;
373
+ if (type) callback.call(binding, key, type);
374
+ }
375
+ });
376
+ }
377
+ }
378
+ function restoreDeprecatedStoreBehaviors(StoreKlass) {
379
+ StoreKlass.prototype.findRecord = function (resource, id, options) {
380
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
381
+ if (!test) {
382
+ throw new Error(`Attempted to call store.findRecord(), but the store instance has already been destroyed.`);
383
+ }
384
+ })(!(this.isDestroying || this.isDestroyed)) : {};
385
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
386
+ if (!test) {
387
+ throw new Error(`You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`);
388
+ }
389
+ })(resource) : {};
390
+ if (isMaybeIdentifier(resource)) {
391
+ options = id;
392
+ } else {
393
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
394
+ if (!test) {
395
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`);
396
+ }
397
+ })(typeof resource === 'string') : {};
398
+ const type = normalizeModelName(resource);
399
+ const normalizedId = ensureStringId(id);
400
+ resource = constructResource(type, normalizedId);
401
+ }
402
+ const identifier = this.identifierCache.getOrCreateRecordIdentifier(resource);
403
+ options = options || {};
404
+ if (options.preload) {
405
+ // force reload if we preload to ensure we don't resolve the promise
406
+ // until we are complete, else we will end up background-reloading
407
+ // even for initial load.
408
+ if (!this._instanceCache.recordIsLoaded(identifier)) {
409
+ options.reload = true;
410
+ }
411
+ this._join(() => {
412
+ preloadData(this, identifier, options.preload);
413
+ });
414
+ }
415
+ const promise = this.request({
416
+ op: 'findRecord',
417
+ data: {
418
+ record: identifier,
419
+ options
420
+ },
421
+ cacheOptions: {
422
+ [SkipCache]: true
423
+ }
424
+ });
425
+ return promise.then(document => {
426
+ return document.content;
427
+ });
428
+ };
429
+ StoreKlass.prototype.findAll = function (type, options = {}) {
430
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
431
+ if (!test) {
432
+ throw new Error(`Attempted to call store.findAll(), but the store instance has already been destroyed.`);
433
+ }
434
+ })(!(this.isDestroying || this.isDestroyed)) : {};
435
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
436
+ if (!test) {
437
+ throw new Error(`You need to pass a model name to the store's findAll method`);
438
+ }
439
+ })(type) : {};
440
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
441
+ if (!test) {
442
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
443
+ }
444
+ })(typeof type === 'string') : {};
445
+ const promise = this.request({
446
+ op: 'findAll',
447
+ data: {
448
+ type: normalizeModelName(type),
449
+ options: options || {}
450
+ },
451
+ cacheOptions: {
452
+ [SkipCache]: true
453
+ }
454
+ });
455
+ return promise.then(document => document.content);
456
+ };
457
+ StoreKlass.prototype.query = function (type, query, options = {}) {
458
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
459
+ if (!test) {
460
+ throw new Error(`Attempted to call store.query(), but the store instance has already been destroyed.`);
461
+ }
462
+ })(!(this.isDestroying || this.isDestroyed)) : {};
463
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
464
+ if (!test) {
465
+ throw new Error(`You need to pass a model name to the store's query method`);
466
+ }
467
+ })(type) : {};
468
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
469
+ if (!test) {
470
+ throw new Error(`You need to pass a query hash to the store's query method`);
471
+ }
472
+ })(query) : {};
473
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
474
+ if (!test) {
475
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
476
+ }
477
+ })(typeof type === 'string') : {};
478
+ const promise = this.request({
479
+ op: 'query',
480
+ data: {
481
+ type: normalizeModelName(type),
482
+ query,
483
+ options: options
484
+ },
485
+ cacheOptions: {
486
+ [SkipCache]: true
487
+ }
488
+ });
489
+ return promise.then(document => document.content);
490
+ };
491
+ StoreKlass.prototype.queryRecord = function (type, query, options) {
492
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
493
+ if (!test) {
494
+ throw new Error(`Attempted to call store.queryRecord(), but the store instance has already been destroyed.`);
495
+ }
496
+ })(!(this.isDestroying || this.isDestroyed)) : {};
497
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
498
+ if (!test) {
499
+ throw new Error(`You need to pass a model name to the store's queryRecord method`);
500
+ }
501
+ })(type) : {};
502
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
503
+ if (!test) {
504
+ throw new Error(`You need to pass a query hash to the store's queryRecord method`);
505
+ }
506
+ })(query) : {};
507
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
508
+ if (!test) {
509
+ throw new Error(`Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`);
510
+ }
511
+ })(typeof type === 'string') : {};
512
+ const promise = this.request({
513
+ op: 'queryRecord',
514
+ data: {
515
+ type: normalizeModelName(type),
516
+ query,
517
+ options: options || {}
518
+ },
519
+ cacheOptions: {
520
+ [SkipCache]: true
521
+ }
522
+ });
523
+ return promise.then(document => document.content);
524
+ };
525
+
526
+ // @ts-expect-error RecordReference private store shouldn't matter
527
+ StoreKlass.prototype.getReference = function (resource, id) {
528
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
529
+ if (!test) {
530
+ throw new Error(`Attempted to call store.getReference(), but the store instance has already been destroyed.`);
531
+ }
532
+ })(!(this.isDestroying || this.isDestroyed)) : {};
533
+ let resourceIdentifier;
534
+ if (arguments.length === 1 && isMaybeIdentifier(resource)) {
535
+ resourceIdentifier = resource;
536
+ } else {
537
+ const type = normalizeModelName(resource);
538
+ const normalizedId = ensureStringId(id);
539
+ resourceIdentifier = constructResource(type, normalizedId);
540
+ }
541
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
542
+ if (!test) {
543
+ throw new Error('getReference expected to receive either a resource identifier or type and id as arguments');
544
+ }
545
+ })(isMaybeIdentifier(resourceIdentifier)) : {};
546
+ const identifier = this.identifierCache.getOrCreateRecordIdentifier(resourceIdentifier);
547
+ const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;
548
+ let reference = cache.get(identifier);
549
+ if (!reference) {
550
+ reference = new RecordReference(this, identifier);
551
+ cache.set(identifier, reference);
552
+ }
553
+ return reference;
554
+ };
555
+ StoreKlass.prototype.modelFor = function (type) {
556
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
557
+ if (!test) {
558
+ throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
559
+ }
560
+ })(!this.isDestroyed) : {};
561
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
562
+ if (!test) {
563
+ throw new Error(`You need to pass <type> to the store's modelFor method`);
564
+ }
565
+ })(typeof type === 'string' && type.length) : {};
566
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
567
+ if (!test) {
568
+ throw new Error(`No model was found for '${type}' and no schema handles the type`);
569
+ }
570
+ })(this.schema.hasResource({
571
+ type
572
+ })) : {};
573
+ return getShimClass(this, type);
574
+ };
575
+ StoreKlass.prototype.saveRecord = function (record, options = {}) {
576
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
577
+ if (!test) {
578
+ throw new Error(`Attempted to call store.saveRecord(), but the store instance has already been destroyed.`);
579
+ }
580
+ })(!(this.isDestroying || this.isDestroyed)) : {};
581
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
582
+ if (!test) {
583
+ throw new Error(`Unable to initiate save for a record in a disconnected state`);
584
+ }
585
+ })(storeFor(record)) : {};
586
+ const identifier = recordIdentifierFor(record);
587
+ const cache = this.cache;
588
+ if (!identifier) {
589
+ // this commonly means we're disconnected
590
+ // but just in case we reject here to prevent bad things.
591
+ return Promise.reject(new Error(`Record Is Disconnected`));
592
+ }
593
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
594
+ if (!test) {
595
+ throw new Error(`Cannot initiate a save request for an unloaded record: ${identifier.lid}`);
596
+ }
597
+ })(this._instanceCache.recordIsLoaded(identifier)) : {};
598
+ if (resourceIsFullyDeleted(this._instanceCache, identifier)) {
599
+ return Promise.resolve(record);
600
+ }
601
+ if (!options) {
602
+ options = {};
603
+ }
604
+ let operation = 'updateRecord';
605
+ if (cache.isNew(identifier)) {
606
+ operation = 'createRecord';
607
+ } else if (cache.isDeleted(identifier)) {
608
+ operation = 'deleteRecord';
609
+ }
610
+ const request = {
611
+ op: operation,
612
+ data: {
613
+ options,
614
+ record: identifier
615
+ },
616
+ records: [identifier],
617
+ cacheOptions: {
618
+ [SkipCache]: true
619
+ }
620
+ };
621
+ return this.request(request).then(document => document.content);
622
+ };
623
+ }
624
+ function upgradeInstanceCaches(cache) {
625
+ const withReferences = cache;
626
+ if (!withReferences.reference) {
627
+ withReferences.reference = new WeakMap();
628
+ }
629
+ return withReferences;
630
+ }
631
+ export { restoreDeprecatedStoreBehaviors };
@@ -0,0 +1,35 @@
1
+ import { deprecate } from '@ember/debug';
2
+ import { dasherize } from '@warp-drive/utilities/string';
3
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
+ function isElementDescriptor(args) {
5
+ const [maybeTarget, maybeKey, maybeDesc] = args;
6
+ return (
7
+ // Ensure we have the right number of args
8
+ args.length === 3 && (
9
+ // Make sure the target is a class or object (prototype)
10
+ typeof maybeTarget === 'function' || typeof maybeTarget === 'object' && maybeTarget !== null) &&
11
+ // Make sure the key is a string
12
+ typeof maybeKey === 'string' && (
13
+ // Make sure the descriptor is the right shape
14
+ typeof maybeDesc === 'object' && maybeDesc !== null && 'enumerable' in maybeDesc && 'configurable' in maybeDesc ||
15
+ // TS compatibility
16
+ maybeDesc === undefined)
17
+ );
18
+ }
19
+ function normalizeModelName(type) {
20
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
21
+ const result = dasherize(type);
22
+ deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
23
+ id: 'ember-data:deprecate-non-strict-types',
24
+ until: '6.0',
25
+ for: 'ember-data',
26
+ since: {
27
+ available: '4.13',
28
+ enabled: '5.3'
29
+ }
30
+ });
31
+ return result;
32
+ }
33
+ return type;
34
+ }
35
+ export { isElementDescriptor as i, normalizeModelName as n };
@@ -0,0 +1,23 @@
1
+ import { deprecate } from '@ember/debug';
2
+ import { dasherize } from '@warp-drive/utilities/string';
3
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
+ function isMaybeIdentifier(maybeIdentifier) {
5
+ return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === 'object' && ('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
6
+ }
7
+ function normalizeModelName(type) {
8
+ if (macroCondition(getGlobalConfig().WarpDrive.deprecations.DEPRECATE_NON_STRICT_TYPES)) {
9
+ const result = dasherize(type);
10
+ deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
11
+ id: 'ember-data:deprecate-non-strict-types',
12
+ until: '6.0',
13
+ for: 'ember-data',
14
+ since: {
15
+ available: '4.13',
16
+ enabled: '5.3'
17
+ }
18
+ });
19
+ return result;
20
+ }
21
+ return type;
22
+ }
23
+ export { isMaybeIdentifier as i, normalizeModelName as n };