@warp-drive-mirror/schema-record 0.0.0-alpha.50 → 0.0.0-alpha.57

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/addon-main.cjs ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const { addonShim } = require('@warp-drive-mirror/build-config/addon-shim.cjs');
4
+
5
+ module.exports = addonShim(__dirname);
@@ -1,7 +1,8 @@
1
- import { SchemaRecord, Editable, Legacy, Destroy } from "./record";
1
+ import { SchemaRecord } from "./record";
2
+ import { E as Editable, L as Legacy, D as Destroy } from "./symbols-CAUfvZjq";
2
3
  function instantiateRecord(store, identifier, createArgs) {
3
4
  const schema = store.schema;
4
- const isLegacy = schema.schemas.get(identifier.type)?.legacy ?? false;
5
+ const isLegacy = schema.resource(identifier)?.legacy ?? false;
5
6
  const isEditable = isLegacy || Boolean(createArgs);
6
7
  const record = new SchemaRecord(store, identifier, {
7
8
  [Editable]: isEditable,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sources":["../src/hooks.ts"],"sourcesContent":["import type Store from '@ember-data-mirror/store';\nimport type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\n\nimport { SchemaRecord } from './record';\nimport type { SchemaService } from './schema';\nimport { Destroy, Editable, Legacy } from './symbols';\n\nexport function instantiateRecord(\n store: Store,\n identifier: StableRecordIdentifier,\n createArgs?: Record<string, unknown>\n): SchemaRecord {\n const schema = store.schema as unknown as SchemaService;\n const isLegacy = schema.resource(identifier)?.legacy ?? false;\n const isEditable = isLegacy || Boolean(createArgs);\n const record = new SchemaRecord(store, identifier, {\n [Editable]: isEditable,\n [Legacy]: isLegacy,\n });\n\n if (createArgs) {\n Object.assign(record, createArgs);\n }\n\n return record;\n}\n\nexport function teardownRecord(record: SchemaRecord): void {\n record[Destroy]();\n}\n"],"names":["instantiateRecord","store","identifier","createArgs","schema","isLegacy","resource","legacy","isEditable","Boolean","record","SchemaRecord","Editable","Legacy","Object","assign","teardownRecord","Destroy"],"mappings":";;;AAOO,SAASA,iBAAiBA,CAC/BC,KAAY,EACZC,UAAkC,EAClCC,UAAoC,EACtB;AACd,EAAA,MAAMC,MAAM,GAAGH,KAAK,CAACG,MAAkC,CAAA;EACvD,MAAMC,QAAQ,GAAGD,MAAM,CAACE,QAAQ,CAACJ,UAAU,CAAC,EAAEK,MAAM,IAAI,KAAK,CAAA;AAC7D,EAAA,MAAMC,UAAU,GAAGH,QAAQ,IAAII,OAAO,CAACN,UAAU,CAAC,CAAA;EAClD,MAAMO,MAAM,GAAG,IAAIC,YAAY,CAACV,KAAK,EAAEC,UAAU,EAAE;IACjD,CAACU,QAAQ,GAAGJ,UAAU;AACtB,IAAA,CAACK,MAAM,GAAGR,QAAAA;AACZ,GAAC,CAAC,CAAA;AAEF,EAAA,IAAIF,UAAU,EAAE;AACdW,IAAAA,MAAM,CAACC,MAAM,CAACL,MAAM,EAAEP,UAAU,CAAC,CAAA;AACnC,GAAA;AAEA,EAAA,OAAOO,MAAM,CAAA;AACf,CAAA;AAEO,SAASM,cAAcA,CAACN,MAAoB,EAAQ;AACzDA,EAAAA,MAAM,CAACO,OAAO,CAAC,EAAE,CAAA;AACnB;;;;"}
@@ -1,14 +1,164 @@
1
- import { assert } from '@ember/debug';
2
1
  import { createSignal, subscribe, defineSignal, Signals, addToTransaction, entangleSignal, getSignal, peekSignal } from '@ember-data-mirror/tracking/-private';
2
+ import { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';
3
3
  import { STRUCTURED } from '@warp-drive-mirror/core-types/request';
4
4
  import { RecordStore } from '@warp-drive-mirror/core-types/symbols';
5
- import { ARRAY_SIGNAL, ManagedArray } from "./managed-array";
6
- import { macroCondition, getOwnConfig } from '@embroider/macros';
7
- const SOURCE = Symbol('#source');
8
- const OBJECT_SIGNAL = Symbol('#signal');
5
+ import { S as SOURCE, A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, D as Destroy, I as Identifier, E as Editable, P as Parent, C as Checkout, L as Legacy } from "./symbols-CAUfvZjq";
6
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
7
+ const ARRAY_GETTER_METHODS = new Set([Symbol.iterator, 'concat', 'entries', 'every', 'fill', 'filter', 'find', 'findIndex', 'flat', 'flatMap', 'forEach', 'includes', 'indexOf', 'join', 'keys', 'lastIndexOf', 'map', 'reduce', 'reduceRight', 'slice', 'some', 'values']);
8
+ // const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);
9
+ const SYNC_PROPS = new Set(['[]', 'length']);
10
+ function isArrayGetter(prop) {
11
+ return ARRAY_GETTER_METHODS.has(prop);
12
+ }
13
+ // function isArraySetter<T>(prop: KeyType): prop is keyof Array<T> {
14
+ // return ARRAY_SETTER_METHODS.has(prop);
15
+ // }
16
+ // function isSelfProp<T extends object>(self: T, prop: KeyType): prop is keyof T {
17
+ // return prop in self;
18
+ // }
19
+
20
+ function convertToInt(prop) {
21
+ if (typeof prop === 'symbol') return null;
22
+ const num = Number(prop);
23
+ if (isNaN(num)) return null;
24
+ return num % 1 === 0 ? num : null;
25
+ }
26
+ function safeForEach(instance, arr, store, callback, target) {
27
+ if (target === undefined) {
28
+ target = null;
29
+ }
30
+ // clone to prevent mutation
31
+ arr = arr.slice();
32
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
33
+ if (!test) {
34
+ throw new Error('`forEach` expects a function as first argument.');
35
+ }
36
+ })(typeof callback === 'function') : {};
37
+
38
+ // because we retrieveLatest above we need not worry if array is mutated during iteration
39
+ // by unloadRecord/rollbackAttributes
40
+ // push/add/removeObject may still be problematic
41
+ // but this is a more traditionally expected forEach bug.
42
+ const length = arr.length; // we need to access length to ensure we are consumed
43
+
44
+ for (let index = 0; index < length; index++) {
45
+ callback.call(target, arr[index], index, instance);
46
+ }
47
+ return instance;
48
+ }
49
+ class ManagedArray {
50
+ [SOURCE];
51
+ constructor(store, schema, cache, field, data, address, key, owner) {
52
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
53
+ const self = this;
54
+ this[SOURCE] = data?.slice();
55
+ this[ARRAY_SIGNAL] = createSignal(this, 'length');
56
+ const _SIGNAL = this[ARRAY_SIGNAL];
57
+ const boundFns = new Map();
58
+ this.address = address;
59
+ this.key = key;
60
+ this.owner = owner;
61
+ let transaction = false;
62
+ const proxy = new Proxy(this[SOURCE], {
63
+ get(target, prop, receiver) {
64
+ if (prop === ARRAY_SIGNAL) {
65
+ return _SIGNAL;
66
+ }
67
+ if (prop === 'address') {
68
+ return self.address;
69
+ }
70
+ if (prop === 'key') {
71
+ return self.key;
72
+ }
73
+ if (prop === 'owner') {
74
+ return self.owner;
75
+ }
76
+ const index = convertToInt(prop);
77
+ if (_SIGNAL.shouldReset && (index !== null || SYNC_PROPS.has(prop) || isArrayGetter(prop))) {
78
+ _SIGNAL.t = false;
79
+ _SIGNAL.shouldReset = false;
80
+ const newData = cache.getAttr(self.address, self.key);
81
+ if (newData && newData !== self[SOURCE]) {
82
+ self[SOURCE].length = 0;
83
+ self[SOURCE].push(...newData);
84
+ }
85
+ }
86
+ if (index !== null) {
87
+ const val = target[index];
88
+ if (!transaction) {
89
+ subscribe(_SIGNAL);
90
+ }
91
+ if (field.type) {
92
+ const transform = schema.transformation(field);
93
+ return transform.hydrate(val, field.options ?? null, self.owner);
94
+ }
95
+ return val;
96
+ }
97
+ if (isArrayGetter(prop)) {
98
+ let fn = boundFns.get(prop);
99
+ if (fn === undefined) {
100
+ if (prop === 'forEach') {
101
+ fn = function () {
102
+ subscribe(_SIGNAL);
103
+ transaction = true;
104
+ const result = safeForEach(receiver, target, store, arguments[0], arguments[1]);
105
+ transaction = false;
106
+ return result;
107
+ };
108
+ } else {
109
+ fn = function () {
110
+ subscribe(_SIGNAL);
111
+ // array functions must run through Reflect to work properly
112
+ // binding via other means will not work.
113
+ transaction = true;
114
+ const result = Reflect.apply(target[prop], receiver, arguments);
115
+ transaction = false;
116
+ return result;
117
+ };
118
+ }
119
+ boundFns.set(prop, fn);
120
+ }
121
+ return fn;
122
+ }
123
+ return Reflect.get(target, prop, receiver);
124
+ },
125
+ set(target, prop, value, receiver) {
126
+ if (prop === 'address') {
127
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
128
+ self.address = value;
129
+ return true;
130
+ }
131
+ if (prop === 'key') {
132
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
133
+ self.key = value;
134
+ return true;
135
+ }
136
+ if (prop === 'owner') {
137
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
138
+ self.owner = value;
139
+ return true;
140
+ }
141
+ const reflect = Reflect.set(target, prop, value, receiver);
142
+ if (reflect) {
143
+ if (!field.type) {
144
+ cache.setAttr(self.address, self.key, self[SOURCE]);
145
+ _SIGNAL.shouldReset = true;
146
+ return true;
147
+ }
148
+ const transform = schema.transformation(field);
149
+ const rawValue = self[SOURCE].map(item => transform.serialize(item, field.options ?? null, self.owner));
150
+ cache.setAttr(self.address, self.key, rawValue);
151
+ _SIGNAL.shouldReset = true;
152
+ }
153
+ return reflect;
154
+ }
155
+ });
156
+ return proxy;
157
+ }
158
+ }
9
159
  class ManagedObject {
160
+ [SOURCE];
10
161
  constructor(store, schema, cache, field, data, address, key, owner) {
11
- this[SOURCE] = void 0;
12
162
  // eslint-disable-next-line @typescript-eslint/no-this-alias
13
163
  const self = this;
14
164
  this[SOURCE] = {
@@ -39,11 +189,8 @@ class ManagedObject {
39
189
  _SIGNAL.shouldReset = false;
40
190
  let newData = cache.getAttr(self.address, self.key);
41
191
  if (newData && newData !== self[SOURCE]) {
42
- if (field.type !== null) {
43
- const transform = schema.transforms.get(field.type);
44
- if (!transform) {
45
- throw new Error(`No '${field.type}' transform defined for use by ${address.type}.${String(prop)}`);
46
- }
192
+ if (field.type) {
193
+ const transform = schema.transformation(field);
47
194
  newData = transform.hydrate(newData, field.options ?? null, self.owner);
48
195
  }
49
196
  self[SOURCE] = {
@@ -77,15 +224,12 @@ class ManagedObject {
77
224
  }
78
225
  const reflect = Reflect.set(target, prop, value, receiver);
79
226
  if (reflect) {
80
- if (field.type === null) {
227
+ if (!field.type) {
81
228
  cache.setAttr(self.address, self.key, self[SOURCE]);
82
229
  _SIGNAL.shouldReset = true;
83
230
  return true;
84
231
  }
85
- const transform = schema.transforms.get(field.type);
86
- if (!transform) {
87
- throw new Error(`No '${field.type}' transform defined for use by ${address.type}.${String(prop)}`);
88
- }
232
+ const transform = schema.transformation(field);
89
233
  const val = transform.serialize(self[SOURCE], field.options ?? null, self.owner);
90
234
  cache.setAttr(self.address, self.key, val);
91
235
  _SIGNAL.shouldReset = true;
@@ -96,16 +240,11 @@ class ManagedObject {
96
240
  return proxy;
97
241
  }
98
242
  }
99
- const Destroy = Symbol('Destroy');
100
- const Identifier = Symbol('Identifier');
101
- const Editable = Symbol('Editable');
102
- const Parent = Symbol('Parent');
103
- const Checkout = Symbol('Checkout');
104
- const Legacy = Symbol('Legacy');
105
243
  const IgnoredGlobalFields = new Set(['then', STRUCTURED]);
106
- const RecordSymbols = new Set([Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals]);
107
- const ManagedArrayMap = new Map();
108
- const ManagedObjectMap = new Map();
244
+ const symbolList = [Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals];
245
+ const RecordSymbols = new Set(symbolList);
246
+ const ManagedArrayMap = getOrSetGlobal('ManagedArrayMap', new Map());
247
+ const ManagedObjectMap = getOrSetGlobal('ManagedObjectMap', new Map());
109
248
  function computeLocal(record, field, prop) {
110
249
  let signal = peekSignal(record, prop);
111
250
  if (!signal) {
@@ -128,13 +267,10 @@ function peekManagedObject(record, field) {
128
267
  }
129
268
  function computeField(schema, cache, record, identifier, field, prop) {
130
269
  const rawValue = cache.getAttr(identifier, prop);
131
- if (field.type === null) {
270
+ if (!field.type) {
132
271
  return rawValue;
133
272
  }
134
- const transform = schema.transforms.get(field.type);
135
- if (!transform) {
136
- throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
137
- }
273
+ const transform = schema.transformation(field);
138
274
  return transform.hydrate(rawValue, field.options ?? null, record);
139
275
  }
140
276
  function computeArray(store, schema, cache, record, identifier, field, prop) {
@@ -179,11 +315,8 @@ function computeObject(store, schema, cache, record, identifier, field, prop) {
179
315
  return null;
180
316
  }
181
317
  if (field.kind === 'object') {
182
- if (field.type !== null) {
183
- const transform = schema.transforms.get(field.type);
184
- if (!transform) {
185
- throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
186
- }
318
+ if (field.type) {
319
+ const transform = schema.transformation(field);
187
320
  rawValue = transform.hydrate(rawValue, field.options ?? null, record);
188
321
  }
189
322
  }
@@ -200,14 +333,7 @@ function computeAttribute(cache, identifier, prop) {
200
333
  return cache.getAttr(identifier, prop);
201
334
  }
202
335
  function computeDerivation(schema, record, identifier, field, prop) {
203
- if (field.type === null) {
204
- throw new Error(`The schema for ${identifier.type}.${String(prop)} is missing the type of the derivation`);
205
- }
206
- const derivation = schema.derivations.get(field.type);
207
- if (!derivation) {
208
- throw new Error(`No '${field.type}' derivation defined for use by ${identifier.type}.${String(prop)}`);
209
- }
210
- return derivation(record, field.options ?? null, prop);
336
+ return schema.derivation(field)(record, field.options ?? null, prop);
211
337
  }
212
338
 
213
339
  // TODO probably this should just be a Document
@@ -222,7 +348,7 @@ class ResourceRelationship {
222
348
  this.lid = rawValue.lid ?? rawValue.links?.self ?? `relationship:${identifier.lid}.${name}`;
223
349
  this.data = rawValue.data ? store.peekRecord(rawValue.data) : null;
224
350
  this.name = name;
225
- if (macroCondition(getOwnConfig().env.DEBUG)) {
351
+ if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
226
352
  this.links = Object.freeze(Object.assign({}, rawValue.links));
227
353
  this.meta = Object.freeze(Object.assign({}, rawValue.meta));
228
354
  } else {
@@ -272,6 +398,7 @@ class SchemaRecord {
272
398
  this[Legacy] = Mode[Legacy] ?? false;
273
399
  const schema = store.schema;
274
400
  const cache = store.cache;
401
+ const identityField = schema.resource(identifier).identity;
275
402
  const fields = schema.fields(identifier);
276
403
  const signals = new Map();
277
404
  this[Signals] = signals;
@@ -309,7 +436,7 @@ class SchemaRecord {
309
436
  // for its own usage.
310
437
  // _, @, $, *
311
438
 
312
- const field = fields.get(prop);
439
+ const field = prop === identityField?.name ? identityField : fields.get(prop);
313
440
  if (!field) {
314
441
  if (IgnoredGlobalFields.has(prop)) {
315
442
  return undefined;
@@ -320,6 +447,9 @@ class SchemaRecord {
320
447
  case '@id':
321
448
  entangleSignal(signals, receiver, '@identity');
322
449
  return identifier.id;
450
+ case '@hash':
451
+ // TODO pass actual cache value not {}
452
+ return schema.hashFn(field)({}, field.options ?? null, field.name ?? null);
323
453
  case '@local':
324
454
  {
325
455
  const lastValue = computeLocal(receiver, field, prop);
@@ -327,14 +457,22 @@ class SchemaRecord {
327
457
  return lastValue;
328
458
  }
329
459
  case 'field':
330
- assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
460
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
461
+ if (!test) {
462
+ throw new Error(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`);
463
+ }
464
+ })(!target[Legacy]) : {};
331
465
  entangleSignal(signals, receiver, field.name);
332
466
  return computeField(schema, cache, target, identifier, field, prop);
333
467
  case 'attribute':
334
468
  entangleSignal(signals, receiver, field.name);
335
469
  return computeAttribute(cache, identifier, prop);
336
470
  case 'resource':
337
- assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
471
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
472
+ if (!test) {
473
+ throw new Error(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`);
474
+ }
475
+ })(!target[Legacy]) : {};
338
476
  entangleSignal(signals, receiver, field.name);
339
477
  return computeResource(store, cache, target, identifier, field, prop);
340
478
  case 'derived':
@@ -342,7 +480,11 @@ class SchemaRecord {
342
480
  case 'schema-array':
343
481
  throw new Error(`Not Implemented`);
344
482
  case 'array':
345
- assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
483
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
484
+ if (!test) {
485
+ throw new Error(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`);
486
+ }
487
+ })(!target[Legacy]) : {};
346
488
  entangleSignal(signals, receiver, field.name);
347
489
  return computeArray(store, schema, cache, target, identifier, field, prop);
348
490
  case 'schema-object':
@@ -350,7 +492,11 @@ class SchemaRecord {
350
492
  // use raw cache value as the object to manage
351
493
  throw new Error(`Not Implemented`);
352
494
  case 'object':
353
- assert(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`, !target[Legacy]);
495
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
496
+ if (!test) {
497
+ throw new Error(`SchemaRecord.${field.name} is not available in legacy mode because it has type '${field.kind}'`);
498
+ }
499
+ })(!target[Legacy]) : {};
354
500
  entangleSignal(signals, receiver, field.name);
355
501
  // run transform, then use that value as the object to manage
356
502
  return computeObject(store, schema, cache, target, identifier, field, prop);
@@ -378,14 +524,11 @@ class SchemaRecord {
378
524
  }
379
525
  case 'field':
380
526
  {
381
- if (field.type === null) {
527
+ if (!field.type) {
382
528
  cache.setAttr(identifier, prop, value);
383
529
  return true;
384
530
  }
385
- const transform = schema.transforms.get(field.type);
386
- if (!transform) {
387
- throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
388
- }
531
+ const transform = schema.transformation(field);
389
532
  const rawValue = transform.serialize(value, field.options ?? null, target);
390
533
  cache.setAttr(identifier, prop, rawValue);
391
534
  return true;
@@ -397,7 +540,7 @@ class SchemaRecord {
397
540
  }
398
541
  case 'array':
399
542
  {
400
- if (field.type === null) {
543
+ if (!field.type) {
401
544
  cache.setAttr(identifier, prop, value?.slice());
402
545
  const peeked = peekManagedArray(self, field);
403
546
  if (peeked) {
@@ -409,10 +552,7 @@ class SchemaRecord {
409
552
  }
410
553
  return true;
411
554
  }
412
- const transform = schema.transforms.get(field.type);
413
- if (!transform) {
414
- throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
415
- }
555
+ const transform = schema.transformation(field);
416
556
  const rawValue = value.map(item => transform.serialize(item, field.options ?? null, target));
417
557
  cache.setAttr(identifier, prop, rawValue);
418
558
  const peeked = peekManagedArray(self, field);
@@ -424,7 +564,7 @@ class SchemaRecord {
424
564
  }
425
565
  case 'object':
426
566
  {
427
- if (field.type === null) {
567
+ if (!field.type) {
428
568
  let newValue = value;
429
569
  if (value !== null) {
430
570
  newValue = {
@@ -441,10 +581,7 @@ class SchemaRecord {
441
581
  }
442
582
  return true;
443
583
  }
444
- const transform = schema.transforms.get(field.type);
445
- if (!transform) {
446
- throw new Error(`No '${field.type}' transform defined for use by ${identifier.type}.${String(prop)}`);
447
- }
584
+ const transform = schema.transformation(field);
448
585
  const rawValue = transform.serialize({
449
586
  ...value
450
587
  }, field.options ?? null, target);
@@ -479,4 +616,4 @@ class SchemaRecord {
479
616
  return Promise.resolve(this);
480
617
  }
481
618
  }
482
- export { Checkout, Destroy, Editable, Identifier, Legacy, Parent, SchemaRecord };
619
+ export { Editable, Legacy, SchemaRecord };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sources":["../src/managed-array.ts","../src/managed-object.ts","../src/record.ts"],"sourcesContent":["import type Store from '@ember-data-mirror/store';\nimport type { Signal } from '@ember-data-mirror/tracking/-private';\nimport { addToTransaction, createSignal, subscribe } from '@ember-data-mirror/tracking/-private';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\nimport type { Cache } from '@warp-drive-mirror/core-types/cache';\nimport type { ArrayValue, Value } from '@warp-drive-mirror/core-types/json/raw';\nimport type { OpaqueRecordInstance } from '@warp-drive-mirror/core-types/record';\nimport type { ArrayField } from '@warp-drive-mirror/core-types/schema/fields';\n\nimport type { SchemaRecord } from './record';\nimport type { SchemaService } from './schema';\nimport { ARRAY_SIGNAL, MUTATE, SOURCE } from './symbols';\n\nexport function notifyArray(arr: ManagedArray) {\n addToTransaction(arr[ARRAY_SIGNAL]);\n}\n\ntype KeyType = string | symbol | number;\nconst ARRAY_GETTER_METHODS = new Set<KeyType>([\n Symbol.iterator,\n 'concat',\n 'entries',\n 'every',\n 'fill',\n 'filter',\n 'find',\n 'findIndex',\n 'flat',\n 'flatMap',\n 'forEach',\n 'includes',\n 'indexOf',\n 'join',\n 'keys',\n 'lastIndexOf',\n 'map',\n 'reduce',\n 'reduceRight',\n 'slice',\n 'some',\n 'values',\n]);\n// const ARRAY_SETTER_METHODS = new Set<KeyType>(['push', 'pop', 'unshift', 'shift', 'splice', 'sort']);\nconst SYNC_PROPS = new Set<KeyType>(['[]', 'length']);\nfunction isArrayGetter<T>(prop: KeyType): prop is keyof Array<T> {\n return ARRAY_GETTER_METHODS.has(prop);\n}\n// function isArraySetter<T>(prop: KeyType): prop is keyof Array<T> {\n// return ARRAY_SETTER_METHODS.has(prop);\n// }\n// function isSelfProp<T extends object>(self: T, prop: KeyType): prop is keyof T {\n// return prop in self;\n// }\n\nfunction convertToInt(prop: KeyType): number | null {\n if (typeof prop === 'symbol') return null;\n\n const num = Number(prop);\n\n if (isNaN(num)) return null;\n\n return num % 1 === 0 ? num : null;\n}\n\ntype ProxiedMethod = (...args: unknown[]) => unknown;\n\ntype ForEachCB = (record: OpaqueRecordInstance, index: number, context: typeof Proxy<unknown[]>) => void;\nfunction safeForEach(\n instance: typeof Proxy<unknown[]>,\n arr: unknown[],\n store: Store,\n callback: ForEachCB,\n target: unknown\n) {\n if (target === undefined) {\n target = null;\n }\n // clone to prevent mutation\n arr = arr.slice();\n assert('`forEach` expects a function as first argument.', typeof callback === 'function');\n\n // because we retrieveLatest above we need not worry if array is mutated during iteration\n // by unloadRecord/rollbackAttributes\n // push/add/removeObject may still be problematic\n // but this is a more traditionally expected forEach bug.\n const length = arr.length; // we need to access length to ensure we are consumed\n\n for (let index = 0; index < length; index++) {\n callback.call(target, arr[index], index, instance);\n }\n\n return instance;\n}\n\nexport interface ManagedArray extends Omit<Array<unknown>, '[]'> {\n [MUTATE]?(\n target: unknown[],\n receiver: typeof Proxy<unknown[]>,\n prop: string,\n args: unknown[],\n _SIGNAL: Signal\n ): unknown;\n}\n\nexport class ManagedArray {\n [SOURCE]: unknown[];\n declare address: StableRecordIdentifier;\n declare key: string;\n declare owner: SchemaRecord;\n declare [ARRAY_SIGNAL]: Signal;\n\n constructor(\n store: Store,\n schema: SchemaService,\n cache: Cache,\n field: ArrayField,\n data: unknown[],\n address: StableRecordIdentifier,\n key: string,\n owner: SchemaRecord\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n this[SOURCE] = data?.slice();\n this[ARRAY_SIGNAL] = createSignal(this, 'length');\n const _SIGNAL = this[ARRAY_SIGNAL];\n const boundFns = new Map<KeyType, ProxiedMethod>();\n this.address = address;\n this.key = key;\n this.owner = owner;\n let transaction = false;\n\n const proxy = new Proxy(this[SOURCE], {\n get<R extends typeof Proxy<unknown[]>>(target: unknown[], prop: keyof R, receiver: R) {\n if (prop === ARRAY_SIGNAL) {\n return _SIGNAL;\n }\n if (prop === 'address') {\n return self.address;\n }\n if (prop === 'key') {\n return self.key;\n }\n if (prop === 'owner') {\n return self.owner;\n }\n\n const index = convertToInt(prop);\n if (_SIGNAL.shouldReset && (index !== null || SYNC_PROPS.has(prop) || isArrayGetter(prop))) {\n _SIGNAL.t = false;\n _SIGNAL.shouldReset = false;\n const newData = cache.getAttr(self.address, self.key);\n if (newData && newData !== self[SOURCE]) {\n self[SOURCE].length = 0;\n self[SOURCE].push(...(newData as ArrayValue));\n }\n }\n\n if (index !== null) {\n const val = target[index];\n if (!transaction) {\n subscribe(_SIGNAL);\n }\n if (field.type) {\n const transform = schema.transformation(field);\n return transform.hydrate(val as Value, field.options ?? null, self.owner);\n }\n return val;\n }\n\n if (isArrayGetter(prop)) {\n let fn = boundFns.get(prop);\n\n if (fn === undefined) {\n if (prop === 'forEach') {\n fn = function () {\n subscribe(_SIGNAL);\n transaction = true;\n const result = safeForEach(receiver, target, store, arguments[0] as ForEachCB, arguments[1]);\n transaction = false;\n return result;\n };\n } else {\n fn = function () {\n subscribe(_SIGNAL);\n // array functions must run through Reflect to work properly\n // binding via other means will not work.\n transaction = true;\n const result = Reflect.apply(target[prop] as ProxiedMethod, receiver, arguments) as unknown;\n transaction = false;\n return result;\n };\n }\n boundFns.set(prop, fn);\n }\n return fn;\n }\n\n return Reflect.get(target, prop, receiver);\n },\n set(target, prop: KeyType, value, receiver) {\n if (prop === 'address') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.address = value;\n return true;\n }\n if (prop === 'key') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.key = value;\n return true;\n }\n if (prop === 'owner') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.owner = value;\n return true;\n }\n const reflect = Reflect.set(target, prop, value, receiver);\n\n if (reflect) {\n if (!field.type) {\n cache.setAttr(self.address, self.key, self[SOURCE] as Value);\n _SIGNAL.shouldReset = true;\n return true;\n }\n\n const transform = schema.transformation(field);\n const rawValue = (self[SOURCE] as ArrayValue).map((item) =>\n transform.serialize(item, field.options ?? null, self.owner)\n );\n cache.setAttr(self.address, self.key, rawValue as Value);\n _SIGNAL.shouldReset = true;\n }\n return reflect;\n },\n }) as ManagedArray;\n\n return proxy;\n }\n}\n","import type Store from '@ember-data-mirror/store';\nimport type { Signal } from '@ember-data-mirror/tracking/-private';\nimport { addToTransaction, createSignal, subscribe } from '@ember-data-mirror/tracking/-private';\nimport type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\nimport type { Cache } from '@warp-drive-mirror/core-types/cache';\nimport type { ObjectValue, Value } from '@warp-drive-mirror/core-types/json/raw';\nimport type { ObjectField } from '@warp-drive-mirror/core-types/schema/fields';\n\nimport type { SchemaRecord } from './record';\nimport type { SchemaService } from './schema';\nimport { MUTATE, OBJECT_SIGNAL, SOURCE } from './symbols';\n\nexport function notifyObject(obj: ManagedObject) {\n addToTransaction(obj[OBJECT_SIGNAL]);\n}\n\ntype KeyType = string | symbol | number;\n\nexport interface ManagedObject {\n [MUTATE]?(\n target: unknown[],\n receiver: typeof Proxy<unknown[]>,\n prop: string,\n args: unknown[],\n _SIGNAL: Signal\n ): unknown;\n}\n\nexport class ManagedObject {\n [SOURCE]: object;\n declare address: StableRecordIdentifier;\n declare key: string;\n declare owner: SchemaRecord;\n declare [OBJECT_SIGNAL]: Signal;\n\n constructor(\n store: Store,\n schema: SchemaService,\n cache: Cache,\n field: ObjectField,\n data: object,\n address: StableRecordIdentifier,\n key: string,\n owner: SchemaRecord\n ) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const self = this;\n this[SOURCE] = { ...data };\n this[OBJECT_SIGNAL] = createSignal(this, 'length');\n const _SIGNAL = this[OBJECT_SIGNAL];\n // const boundFns = new Map<KeyType, ProxiedMethod>();\n this.address = address;\n this.key = key;\n this.owner = owner;\n const transaction = false;\n\n const proxy = new Proxy(this[SOURCE], {\n get<R extends typeof Proxy<object>>(target: object, prop: keyof R, receiver: R) {\n if (prop === OBJECT_SIGNAL) {\n return _SIGNAL;\n }\n if (prop === 'address') {\n return self.address;\n }\n if (prop === 'key') {\n return self.key;\n }\n if (prop === 'owner') {\n return self.owner;\n }\n\n if (_SIGNAL.shouldReset) {\n _SIGNAL.t = false;\n _SIGNAL.shouldReset = false;\n let newData = cache.getAttr(self.address, self.key);\n if (newData && newData !== self[SOURCE]) {\n if (field.type) {\n const transform = schema.transformation(field);\n newData = transform.hydrate(newData as ObjectValue, field.options ?? null, self.owner) as ObjectValue;\n }\n self[SOURCE] = { ...(newData as ObjectValue) }; // Add type assertion for newData\n }\n }\n\n if (prop in self[SOURCE]) {\n if (!transaction) {\n subscribe(_SIGNAL);\n }\n\n return (self[SOURCE] as R)[prop];\n }\n return Reflect.get(target, prop, receiver) as R;\n },\n\n set(target, prop: KeyType, value, receiver) {\n if (prop === 'address') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.address = value;\n return true;\n }\n if (prop === 'key') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.key = value;\n return true;\n }\n if (prop === 'owner') {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n self.owner = value;\n return true;\n }\n const reflect = Reflect.set(target, prop, value, receiver);\n\n if (reflect) {\n if (!field.type) {\n cache.setAttr(self.address, self.key, self[SOURCE] as Value);\n _SIGNAL.shouldReset = true;\n return true;\n }\n\n const transform = schema.transformation(field);\n const val = transform.serialize(self[SOURCE], field.options ?? null, self.owner);\n cache.setAttr(self.address, self.key, val);\n _SIGNAL.shouldReset = true;\n }\n return reflect;\n },\n }) as ManagedObject;\n\n return proxy;\n }\n}\n","import type { Future } from '@ember-data-mirror/request';\nimport type Store from '@ember-data-mirror/store';\nimport type { NotificationType, StoreRequestInput } from '@ember-data-mirror/store';\nimport {\n addToTransaction,\n defineSignal,\n entangleSignal,\n getSignal,\n peekSignal,\n type Signal,\n Signals,\n} from '@ember-data-mirror/tracking/-private';\nimport { DEBUG } from '@warp-drive-mirror/build-config/env';\nimport { assert } from '@warp-drive-mirror/build-config/macros';\nimport type { StableRecordIdentifier } from '@warp-drive-mirror/core-types';\nimport { getOrSetGlobal } from '@warp-drive-mirror/core-types/-private';\nimport type { Cache } from '@warp-drive-mirror/core-types/cache';\nimport type { ResourceRelationship as SingleResourceRelationship } from '@warp-drive-mirror/core-types/cache/relationship';\nimport type { ArrayValue, ObjectValue, Value } from '@warp-drive-mirror/core-types/json/raw';\nimport { STRUCTURED } from '@warp-drive-mirror/core-types/request';\nimport type {\n ArrayField,\n DerivedField,\n FieldSchema,\n GenericField,\n LocalField,\n ObjectField,\n} from '@warp-drive-mirror/core-types/schema/fields';\nimport type { Link, Links } from '@warp-drive-mirror/core-types/spec/json-api-raw';\nimport { RecordStore } from '@warp-drive-mirror/core-types/symbols';\n\nimport { ManagedArray } from './managed-array';\nimport { ManagedObject } from './managed-object';\nimport type { SchemaService } from './schema';\nimport { ARRAY_SIGNAL, Checkout, Destroy, Editable, Identifier, Legacy, OBJECT_SIGNAL, Parent } from './symbols';\n\nexport { Editable, Legacy } from './symbols';\nconst IgnoredGlobalFields = new Set<string>(['then', STRUCTURED]);\nconst symbolList = [Destroy, RecordStore, Identifier, Editable, Parent, Checkout, Legacy, Signals];\nconst RecordSymbols = new Set(symbolList);\n\ntype RecordSymbol = (typeof symbolList)[number];\n\nconst ManagedArrayMap = getOrSetGlobal('ManagedArrayMap', new Map<SchemaRecord, Map<FieldSchema, ManagedArray>>());\nconst ManagedObjectMap = getOrSetGlobal('ManagedObjectMap', new Map<SchemaRecord, Map<FieldSchema, ManagedObject>>());\n\nfunction computeLocal(record: typeof Proxy<SchemaRecord>, field: LocalField, 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 peekManagedObject(record: SchemaRecord, field: FieldSchema): ManagedObject | undefined {\n const managedObjectMapForRecord = ManagedObjectMap.get(record);\n if (managedObjectMapForRecord) {\n return managedObjectMapForRecord.get(field);\n }\n}\n\nfunction computeField(\n schema: SchemaService,\n cache: Cache,\n record: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: GenericField,\n prop: string\n): unknown {\n const rawValue = cache.getAttr(identifier, prop);\n if (!field.type) {\n return rawValue;\n }\n const transform = schema.transformation(field);\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: ArrayField,\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 computeObject(\n store: Store,\n schema: SchemaService,\n cache: Cache,\n record: SchemaRecord,\n identifier: StableRecordIdentifier,\n field: ObjectField,\n prop: string\n) {\n const managedObjectMapForRecord = ManagedObjectMap.get(record);\n let managedObject;\n if (managedObjectMapForRecord) {\n managedObject = managedObjectMapForRecord.get(field);\n }\n if (managedObject) {\n return managedObject;\n } else {\n let rawValue = cache.getAttr(identifier, prop) as object;\n if (!rawValue) {\n return null;\n }\n if (field.kind === 'object') {\n if (field.type) {\n const transform = schema.transformation(field);\n rawValue = transform.hydrate(rawValue as ObjectValue, field.options ?? null, record) as object;\n }\n }\n managedObject = new ManagedObject(store, schema, cache, field, rawValue, identifier, prop, record);\n if (!managedObjectMapForRecord) {\n ManagedObjectMap.set(record, new Map([[field, managedObject]]));\n } else {\n managedObjectMapForRecord.set(field, managedObject);\n }\n }\n return managedObject;\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: DerivedField,\n prop: string\n): unknown {\n return schema.derivation(field)(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<T, T>): 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 identityField = schema.resource(identifier).identity;\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 RecordSymbol)) {\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 = prop === identityField?.name ? identityField : fields.get(prop as string);\n if (!field) {\n if (IgnoredGlobalFields.has(prop as string)) {\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 '@hash':\n // TODO pass actual cache value not {}\n return schema.hashFn(field)({}, field.options ?? null, field.name ?? null);\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 'schema-array':\n throw new Error(`Not Implemented`);\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 case 'schema-object':\n // validate any access off of schema, no transform to run\n // use raw cache value as the object to manage\n throw new Error(`Not Implemented`);\n case 'object':\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 // run transform, then use that value as the object to manage\n return computeObject(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) {\n cache.setAttr(identifier, prop as string, value as Value);\n return true;\n }\n const transform = schema.transformation(field);\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) {\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.transformation(field);\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 'object': {\n if (!field.type) {\n let newValue = value;\n if (value !== null) {\n newValue = { ...(value as ObjectValue) };\n } else {\n ManagedObjectMap.delete(target);\n }\n\n cache.setAttr(identifier, prop as string, newValue as Value);\n\n const peeked = peekManagedObject(self, field);\n if (peeked) {\n const objSignal = peeked[OBJECT_SIGNAL];\n objSignal.shouldReset = true;\n }\n return true;\n }\n const transform = schema.transformation(field);\n const rawValue = transform.serialize({ ...(value as ObjectValue) }, field.options ?? null, target);\n\n cache.setAttr(identifier, prop as string, rawValue);\n const peeked = peekManagedObject(self, field);\n if (peeked) {\n const objSignal = peeked[OBJECT_SIGNAL];\n objSignal.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":["ARRAY_GETTER_METHODS","Set","Symbol","iterator","SYNC_PROPS","isArrayGetter","prop","has","convertToInt","num","Number","isNaN","safeForEach","instance","arr","store","callback","target","undefined","slice","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","length","index","call","ManagedArray","SOURCE","constructor","schema","cache","field","data","address","key","owner","self","ARRAY_SIGNAL","createSignal","_SIGNAL","boundFns","Map","transaction","proxy","Proxy","get","receiver","shouldReset","t","newData","getAttr","push","val","subscribe","type","transform","transformation","hydrate","options","fn","result","arguments","Reflect","apply","set","value","reflect","setAttr","rawValue","map","item","serialize","ManagedObject","OBJECT_SIGNAL","IgnoredGlobalFields","STRUCTURED","symbolList","Destroy","RecordStore","Identifier","Editable","Parent","Checkout","Legacy","Signals","RecordSymbols","ManagedArrayMap","getOrSetGlobal","ManagedObjectMap","computeLocal","record","signal","peekSignal","getSignal","lastValue","defaultValue","peekManagedArray","managedArrayMapForRecord","peekManagedObject","managedObjectMapForRecord","computeField","identifier","computeArray","managedArray","computeObject","managedObject","kind","computeAttribute","computeDerivation","derivation","ResourceRelationship","parent","name","getRelationship","lid","links","peekRecord","Object","freeze","assign","meta","fetch","url","getHref","related","method","String","request","defineSignal","prototype","link","href","computeResource","SchemaRecord","Mode","IS_EDITABLE","identityField","resource","identity","fields","signals","___notifications","notifications","_","addToTransaction","peeked","arrSignal","entangleSignal","id","hashFn","Array","isArray","delete","newValue","objSignal","isDestroying","isDestroyed","unsubscribe","Promise","resolve"],"mappings":";;;;;;;AAmBA,MAAMA,oBAAoB,GAAG,IAAIC,GAAG,CAAU,CAC5CC,MAAM,CAACC,QAAQ,EACf,QAAQ,EACR,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,WAAW,EACX,MAAM,EACN,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,MAAM,EACN,MAAM,EACN,aAAa,EACb,KAAK,EACL,QAAQ,EACR,aAAa,EACb,OAAO,EACP,MAAM,EACN,QAAQ,CACT,CAAC,CAAA;AACF;AACA,MAAMC,UAAU,GAAG,IAAIH,GAAG,CAAU,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAA;AACrD,SAASI,aAAaA,CAAIC,IAAa,EAA0B;AAC/D,EAAA,OAAON,oBAAoB,CAACO,GAAG,CAACD,IAAI,CAAC,CAAA;AACvC,CAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASE,YAAYA,CAACF,IAAa,EAAiB;AAClD,EAAA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE,OAAO,IAAI,CAAA;AAEzC,EAAA,MAAMG,GAAG,GAAGC,MAAM,CAACJ,IAAI,CAAC,CAAA;AAExB,EAAA,IAAIK,KAAK,CAACF,GAAG,CAAC,EAAE,OAAO,IAAI,CAAA;EAE3B,OAAOA,GAAG,GAAG,CAAC,KAAK,CAAC,GAAGA,GAAG,GAAG,IAAI,CAAA;AACnC,CAAA;AAKA,SAASG,WAAWA,CAClBC,QAAiC,EACjCC,GAAc,EACdC,KAAY,EACZC,QAAmB,EACnBC,MAAe,EACf;EACA,IAAIA,MAAM,KAAKC,SAAS,EAAE;AACxBD,IAAAA,MAAM,GAAG,IAAI,CAAA;AACf,GAAA;AACA;AACAH,EAAAA,GAAG,GAAGA,GAAG,CAACK,KAAK,EAAE,CAAA;EACjBC,cAA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