@warp-drive-mirror/core 5.9.0-alpha.18 → 5.9.0-alpha.19

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.
Files changed (30) hide show
  1. package/declarations/index.d.ts +10 -1
  2. package/dist/graph/-private.js +17 -21
  3. package/dist/{index-BoY6aNE5.js → index-LI2ckwf9.js} +244 -1
  4. package/dist/index.js +1 -1
  5. package/dist/reactive.js +1 -1
  6. package/dist/store/-private.js +1 -1
  7. package/dist/types/-private.js +1 -1
  8. package/dist/unpkg/dev/graph/-private.js +17 -21
  9. package/dist/unpkg/dev/{index-BZ6PKU-a.js → index-DU_HLpg-.js} +244 -1
  10. package/dist/unpkg/dev/index.js +1 -1
  11. package/dist/unpkg/dev/reactive.js +1 -1
  12. package/dist/unpkg/dev/store/-private.js +2 -2
  13. package/dist/unpkg/dev/types/-private.js +1 -1
  14. package/dist/unpkg/dev-deprecated/graph/-private.js +17 -21
  15. package/dist/unpkg/dev-deprecated/{index-CDjd631s.js → index-BYFUHVPd.js} +244 -1
  16. package/dist/unpkg/dev-deprecated/index.js +1 -1
  17. package/dist/unpkg/dev-deprecated/reactive.js +1 -1
  18. package/dist/unpkg/dev-deprecated/store/-private.js +1 -1
  19. package/dist/unpkg/dev-deprecated/types/-private.js +1 -1
  20. package/dist/unpkg/prod/{index-BMBm3kYx.js → index-C-AhVafS.js} +146 -1
  21. package/dist/unpkg/prod/index.js +1 -1
  22. package/dist/unpkg/prod/reactive.js +1 -1
  23. package/dist/unpkg/prod/store/-private.js +2 -2
  24. package/dist/unpkg/prod/types/-private.js +1 -1
  25. package/dist/unpkg/prod-deprecated/{index-CZkDXZog.js → index-CplZl2hv.js} +146 -1
  26. package/dist/unpkg/prod-deprecated/index.js +1 -1
  27. package/dist/unpkg/prod-deprecated/reactive.js +1 -1
  28. package/dist/unpkg/prod-deprecated/store/-private.js +1 -1
  29. package/dist/unpkg/prod-deprecated/types/-private.js +1 -1
  30. package/package.json +3 -3
@@ -39,8 +39,17 @@ export interface StoreSetupOptions<T extends Cache = Cache> {
39
39
  * The request handlers to use. {@link Fetch} will automatically
40
40
  * be added to the end of the handler chain and {@link CacheHandler}
41
41
  * will automatically be added as the cache handler.
42
+ *
43
+ * May also be given as a function that receives the {@link Store} instance
44
+ * and returns the handlers to use. This is useful when a handler needs
45
+ * access to the store (e.g. to look up its owner for injections) or when
46
+ * the set of handlers should be decided lazily (e.g. based on a feature
47
+ * flag service that may not be ready until after the store is constructed).
48
+ *
49
+ * The function is invoked lazily, the first time the store's `requestManager`
50
+ * is accessed, and only once per store instance.
42
51
  */
43
- handlers?: Handler[];
52
+ handlers?: Handler[] | ((store: Store) => Handler[]);
44
53
  /**
45
54
  * Schemas describing the structure of your resource data.
46
55
  *
@@ -753,7 +753,7 @@ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
753
753
  errors.set('type', ` <---- should be '${definition.inverseType}'`);
754
754
  }
755
755
  if (definition.inverseKind !== meta.kind) {
756
- errors.set('type', ` <---- should be '${definition.inverseKind}'`);
756
+ errors.set('kind', ` <---- should be '${definition.inverseKind}'`);
757
757
  }
758
758
  if (definition.inverseIsAsync !== meta.options.async) {
759
759
  errors.set('async', ` <---- should be ${definition.inverseIsAsync}`);
@@ -764,7 +764,12 @@ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
764
764
  if (definition.key !== meta.options.inverse) {
765
765
  errors.set('inverse', ` <---- should be '${definition.key}'`);
766
766
  }
767
- if (definition.type !== meta.options.as) {
767
+ // `as` is only meaningful when `definition` itself is polymorphic (i.e. it
768
+ // points at an abstract type that `meta` is expected to implement). When
769
+ // `definition` isn't polymorphic, there's no abstract type for `meta` to
770
+ // declare `as` against, so `meta.options.as` is correctly absent - that's
771
+ // not an error to report.
772
+ if (definition.isPolymorphic && definition.type !== meta.options.as) {
768
773
  errors.set('as', ` <---- should be '${definition.type}'`);
769
774
  }
770
775
  return errors;
@@ -803,18 +808,6 @@ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
803
808
 
804
809
  `;
805
810
  }
806
- function metaFrom(definition) {
807
- return {
808
- name: definition.key,
809
- type: definition.type,
810
- kind: definition.kind,
811
- options: {
812
- async: definition.isAsync,
813
- polymorphic: definition.isPolymorphic,
814
- inverse: definition.inverseKey
815
- }
816
- };
817
- }
818
811
  function inverseMetaFrom(definition) {
819
812
  return {
820
813
  name: definition.inverseKey,
@@ -857,15 +850,18 @@ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
857
850
  });
858
851
  }
859
852
  assertInheritedSchema = function assertInheritedSchema(definition, type) {
860
- const meta1 = metaFrom(definition);
853
+ // `definition` is the only source of truth we have here - there is no
854
+ // second, independently-declared schema available to diff it against.
855
+ // That means the only thing we can actually verify is internal: does
856
+ // `definition`'s own resolved inverse agree that this relationship is
857
+ // polymorphic? Every other field of `meta2` below (name/type/kind/async/
858
+ // inverse) is derived directly from `definition` itself, so comparing
859
+ // them back to `definition` can never disagree - only the polymorphic
860
+ // flag is independently meaningful, because `definitionWithPolymorphic`
861
+ // asserts what it *should* be rather than mirroring what it already is.
861
862
  const meta2 = inverseMetaFrom(definition);
862
- const errors1 = validateSchema(inverseDefinition(definition), meta1);
863
863
  const errors2 = validateSchema(definitionWithPolymorphic(definition), meta2);
864
- if (errors2.size === 0 && errors1.size > 0) {
865
- throw new Error(`The schema for the relationship '${type}.${definition.key}' is not configured to satisfy '${definition.inverseType}' and thus cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}'\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${type}' should include:${printSchema(meta1, errors1)}`);
866
- } else if (errors1.size > 0) {
867
- throw new Error(`The schema for the relationship '${type}.${definition.key}' is not configured to satisfy '${definition.inverseType}' and thus cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}'\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${type}' should include:${printSchema(meta1, errors1)} and the relationships schema definition for '${definition.type}' should include:${printSchema(meta2, errors2)}`);
868
- } else if (errors2.size > 0) {
864
+ if (errors2.size > 0) {
869
865
  throw new Error(`The schema for the relationship '${type}.${definition.key}' satisfies '${definition.inverseType}' but cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}' because that relationship is not polymorphic.\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${definition.type}' should include:${printSchema(meta2, errors2)}`);
870
866
  }
871
867
  };
@@ -8362,6 +8362,9 @@ class ReactiveResource {
8362
8362
  if (prop === Destroy || prop === Checkout) {
8363
8363
  return true;
8364
8364
  }
8365
+ if (prop === identityField?.name) {
8366
+ return true;
8367
+ }
8365
8368
  return fields.has(prop);
8366
8369
  },
8367
8370
  getOwnPropertyDescriptor(target, prop) {
@@ -9112,6 +9115,90 @@ function registerDerivations(schema) {
9112
9115
  schema.registerDerivation(fromIdentity);
9113
9116
  schema.registerDerivation(_constructor);
9114
9117
  }
9118
+
9119
+ /**
9120
+ * A relationship field capable of declaring `options.as`, marking it as a
9121
+ * concrete implementation of an abstract polymorphic type.
9122
+ */
9123
+
9124
+ /**
9125
+ * A relationship field contributed to an abstract type's schema, along with
9126
+ * the name of the type that contributed it (either a concrete implementer,
9127
+ * via `options.as`, or the abstract type's own schema), for use in assertion
9128
+ * messages when two contributions disagree on shape.
9129
+ */
9130
+
9131
+ /**
9132
+ * Reduces a field to a plain object with a fixed key order, covering every
9133
+ * option any relationship-implementer field can declare, so two fields can
9134
+ * be compared for exact equality via `JSON.stringify` regardless of the key
9135
+ * order the schema author happened to write them in.
9136
+ *
9137
+ * `options.as` is included and is *not* special-cased: every contributor to
9138
+ * a given field name on an abstract type - including the abstract type's
9139
+ * own schema, if it has one - is expected to declare `as` equal to that
9140
+ * abstract type's own name. This is redundant/self-referential for the
9141
+ * abstract type's own schema, but required for consistency: relationship
9142
+ * resolution elsewhere (e.g. `inverse` name-matching) does not itself
9143
+ * validate `as`, so a field with a missing or incorrect `as` can otherwise
9144
+ * be silently pulled into a relationship it never declared it implements.
9145
+ */
9146
+ function comparableAbstractFieldShape(field) {
9147
+ const {
9148
+ kind,
9149
+ name,
9150
+ type,
9151
+ sourceKey,
9152
+ options
9153
+ } = field;
9154
+ return {
9155
+ kind,
9156
+ name,
9157
+ type,
9158
+ sourceKey,
9159
+ options: {
9160
+ as: options?.as,
9161
+ async: options?.async,
9162
+ inverse: options?.inverse,
9163
+ polymorphic: options?.polymorphic,
9164
+ linksMode: options?.linksMode,
9165
+ resetOnRemoteUpdate: options?.resetOnRemoteUpdate,
9166
+ arrayExtensions: options?.arrayExtensions
9167
+ }
9168
+ };
9169
+ }
9170
+
9171
+ /**
9172
+ * Asserts that two contributions to the same field name on an abstract
9173
+ * polymorphic type - whether from two different concrete implementers, or
9174
+ * from an implementer and the abstract type's own schema - declare an
9175
+ * identical shape: `kind`, `type`, and every option, including `as` (which
9176
+ * every contributor, the abstract type's own schema included, must declare
9177
+ * equal to `abstractType`). A mismatch here (e.g. one implementer's field
9178
+ * being a `hasMany` while another's is a `belongsTo`, the two disagreeing on
9179
+ * `inverse`/`async`/`polymorphic`, or one omitting or misdeclaring `as`)
9180
+ * cannot be resolved by picking one side arbitrarily, since that would
9181
+ * silently leave whichever side lost the mismatch pointing at a relationship
9182
+ * whose true shape differs from what its own schema declared.
9183
+ */
9184
+ function assertConsistentAbstractFieldShape(abstractType, fieldName, existing, incoming) {
9185
+ // This function exists solely to support the `assert()` call below - there
9186
+ // is no other work here with an effect in production. Since `assert()`'s
9187
+ // own babel-macro stripping only removes the call expression itself, not
9188
+ // the (comparatively expensive, involving `JSON.stringify`) computation of
9189
+ // its arguments, guard the whole body so none of it survives in production
9190
+ // builds, matching how `assertPolymorphicType`/`assertInheritedSchema` and
9191
+ // their call sites are gated in `assert-polymorphic-type.ts`.
9192
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
9193
+ const existingShape = comparableAbstractFieldShape(existing.field);
9194
+ const incomingShape = comparableAbstractFieldShape(incoming.field);
9195
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
9196
+ if (!test) {
9197
+ throw new Error(`Expected the relationship '${fieldName}' on the abstract polymorphic type '${abstractType}' to be declared identically everywhere it is implemented (including 'options.as', which every contributor - the abstract type's own schema included - must declare equal to '${abstractType}'), but '${existing.source}' declares it as:\n\n${JSON.stringify(existingShape, null, 2)}\n\nwhile '${incoming.source}' declares it as:\n\n${JSON.stringify(incomingShape, null, 2)}\n\nAll concrete implementers of an abstract type - and the abstract type's own schema, if it has one - must declare an identical shape for any relationship field they share.`);
9198
+ }
9199
+ })(JSON.stringify(existingShape) === JSON.stringify(incomingShape)) : {};
9200
+ }
9201
+ }
9115
9202
  /**
9116
9203
  * Wraps a derivation in a new function with Derivation signature but that looks
9117
9204
  * up the value in the cache before recomputing.
@@ -9151,6 +9238,18 @@ class SchemaService {
9151
9238
 
9152
9239
  /** @internal */
9153
9240
 
9241
+ /**
9242
+ * Tracks, per abstract type, the relationship fields that concrete
9243
+ * implementers have contributed via `options.as`, along with the type
9244
+ * that contributed each one (for assertion messages). This is
9245
+ * independent of whatever schema (synthesized or user-registered)
9246
+ * currently occupies `_schemas` for that type, so that these fields
9247
+ * survive regardless of the order in which the abstract type's
9248
+ * implementers and its own (optional) concrete schema are registered.
9249
+ *
9250
+ * @internal
9251
+ */
9252
+
9154
9253
  /** @internal */
9155
9254
 
9156
9255
  /** @internal */
@@ -9162,6 +9261,7 @@ class SchemaService {
9162
9261
  this._derivations = new Map();
9163
9262
  this._traits = new Map();
9164
9263
  this._modes = new Map();
9264
+ this._abstractImplementerFields = new Map();
9165
9265
  this._extensions = {
9166
9266
  object: new Map(),
9167
9267
  array: new Map()
@@ -9257,6 +9357,7 @@ class SchemaService {
9257
9357
  const fields = new Map();
9258
9358
  const relationships = {};
9259
9359
  const attributes = {};
9360
+ const abstractImplementations = [];
9260
9361
  for (const field of schema.fields) {
9261
9362
  macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
9262
9363
  if (!test) {
@@ -9270,6 +9371,31 @@ class SchemaService {
9270
9371
  attributes[field.name] = field;
9271
9372
  } else if (field.kind === 'belongsTo' || field.kind === 'hasMany') {
9272
9373
  relationships[field.name] = field;
9374
+ if (field.options?.as) {
9375
+ abstractImplementations.push(field);
9376
+ }
9377
+ }
9378
+ }
9379
+
9380
+ // This type may already be known as an abstract polymorphic type,
9381
+ // implemented by other concrete types via `options.as`, from before it
9382
+ // ever had a schema of its own (see `_registerAbstractTypeImplementation`).
9383
+ // Carry those previously-contributed fields forward so that registering
9384
+ // a "real" schema for the type - whenever that happens to occur - never
9385
+ // erases the relationships its implementers depend on.
9386
+ const implementerFields = this._abstractImplementerFields.get(schema.type);
9387
+ if (implementerFields) {
9388
+ for (const [name, contribution] of implementerFields) {
9389
+ const ownField = fields.get(name);
9390
+ if (!ownField) {
9391
+ fields.set(name, contribution.field);
9392
+ relationships[name] = contribution.field;
9393
+ } else if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
9394
+ assertConsistentAbstractFieldShape(schema.type, name, contribution, {
9395
+ field: ownField,
9396
+ source: schema.type
9397
+ });
9398
+ }
9273
9399
  }
9274
9400
  }
9275
9401
  const cacheFields = null;
@@ -9288,6 +9414,101 @@ class SchemaService {
9288
9414
  internalSchema.cacheFields = getCacheFields(internalSchema);
9289
9415
  }
9290
9416
  this._schemas.set(schema.type, internalSchema);
9417
+
9418
+ // A relationship field's `as` option marks it as a valid concrete
9419
+ // implementer of an abstract polymorphic type (e.g. `as: 'commentable'`).
9420
+ // That abstract type may never be given its own schema by the user - it
9421
+ // may exist only to be implemented by concrete types like this one - or
9422
+ // it may already have (or later receive) a schema of its own, e.g. if it
9423
+ // turns out to also be a real, directly-resolvable resource. Either way,
9424
+ // ensure it has a schema with this field present, so that it behaves
9425
+ // like any other registered resource (`hasResource`, `fields`, etc.)
9426
+ // instead of requiring special-casing wherever abstract relationship
9427
+ // types are resolved.
9428
+ for (const field of abstractImplementations) {
9429
+ this._registerAbstractTypeImplementation(field, schema.type);
9430
+ }
9431
+ }
9432
+
9433
+ /** @internal */
9434
+ _registerAbstractTypeImplementation(field, implementer) {
9435
+ const abstractType = field.options.as;
9436
+ let implementerFields = this._abstractImplementerFields.get(abstractType);
9437
+ if (!implementerFields) {
9438
+ implementerFields = new Map();
9439
+ this._abstractImplementerFields.set(abstractType, implementerFields);
9440
+ }
9441
+
9442
+ // Unlike the original approach this replaced, `as` is *not* stripped here:
9443
+ // the field as synthesized onto the abstract type's own schema keeps
9444
+ // `options.as === abstractType`, redundant/self-referential as that is.
9445
+ // This keeps every contributor - implementers and the abstract type's
9446
+ // own schema alike - declaring the same thing, which is what
9447
+ // `assertConsistentAbstractFieldShape` checks, and it is also what lets
9448
+ // `assertPolymorphicType` (which reads a field's declared `as` off
9449
+ // whatever `schema.fields()` serves for its type) correctly permit the
9450
+ // abstract type itself to be pushed directly into this relationship.
9451
+ const abstractField = {
9452
+ ...field
9453
+ };
9454
+ const contribution = {
9455
+ field: abstractField,
9456
+ source: implementer
9457
+ };
9458
+
9459
+ // all concrete implementations of an abstract type are required to
9460
+ // share the same shape for the field that implements it, so the first
9461
+ // one registered is as good a canonical source as any - but a later,
9462
+ // differently-shaped one is almost certainly a mistake rather than an
9463
+ // intentional override, so we catch it rather than silently ignoring it.
9464
+ const existingImplementer = implementerFields.get(field.name);
9465
+ if (existingImplementer) {
9466
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
9467
+ assertConsistentAbstractFieldShape(abstractType, field.name, existingImplementer, contribution);
9468
+ }
9469
+ return;
9470
+ }
9471
+ implementerFields.set(field.name, contribution);
9472
+ let abstractSchema = this._schemas.get(abstractType);
9473
+ if (!abstractSchema) {
9474
+ abstractSchema = {
9475
+ original: {
9476
+ legacy: true,
9477
+ identity: {
9478
+ kind: '@id',
9479
+ name: 'id'
9480
+ },
9481
+ type: abstractType,
9482
+ fields: []
9483
+ },
9484
+ finalized: true,
9485
+ fields: new Map(),
9486
+ cacheFields: new Map(),
9487
+ relationships: {},
9488
+ attributes: {},
9489
+ traits: new Set()
9490
+ };
9491
+ this._schemas.set(abstractType, abstractSchema);
9492
+ }
9493
+ const existingAbstractField = abstractSchema.fields.get(field.name);
9494
+ if (existingAbstractField) {
9495
+ if (macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG)) {
9496
+ assertConsistentAbstractFieldShape(abstractType, field.name, {
9497
+ field: existingAbstractField,
9498
+ source: abstractType
9499
+ }, contribution);
9500
+ }
9501
+ return;
9502
+ }
9503
+ abstractSchema.fields.set(field.name, abstractField);
9504
+ abstractSchema.relationships[field.name] = abstractField;
9505
+
9506
+ // If the schema is mid-finalization (traits pending), finalizeResource
9507
+ // will recompute cacheFields from the current `fields` map anyway; avoid
9508
+ // doing so prematurely from a partially-resolved set of fields.
9509
+ if (abstractSchema.finalized) {
9510
+ abstractSchema.cacheFields = getCacheFields(abstractSchema);
9511
+ }
9291
9512
  }
9292
9513
 
9293
9514
  /**
@@ -10019,7 +10240,29 @@ globalThis.setWarpDriveIsMaybeMirage = setIsMaybeMirage;
10019
10240
  */
10020
10241
  function useRecommendedStore(options, StoreKlass = Store) {
10021
10242
  return class AppStore extends StoreKlass {
10022
- requestManager = new RequestManager().use([...(options.handlers ?? []), Fetch]).useCache(CacheHandler);
10243
+ constructor(createArgs) {
10244
+ super(createArgs);
10245
+ // installed via defineProperty (rather than a class field/accessor) so that
10246
+ // this lazy override of the inherited `requestManager` field does not
10247
+ // conflict with the documented pattern of assigning it directly on
10248
+ // consumer-authored Store subclasses. The setter preserves the ability
10249
+ // to replace `requestManager` outright after construction.
10250
+ let requestManager;
10251
+ Object.defineProperty(this, 'requestManager', {
10252
+ configurable: true,
10253
+ enumerable: true,
10254
+ get: () => {
10255
+ if (!requestManager) {
10256
+ const handlers = typeof options.handlers === 'function' ? options.handlers(this) : options.handlers ?? [];
10257
+ requestManager = new RequestManager().use([...handlers, Fetch]).useCache(CacheHandler);
10258
+ }
10259
+ return requestManager;
10260
+ },
10261
+ set: value => {
10262
+ requestManager = value;
10263
+ }
10264
+ });
10265
+ }
10023
10266
  lifetimes = options.policy ?? new DefaultCachePolicy({
10024
10267
  apiCacheHardExpires: 15 * 60 * 1000,
10025
10268
  // 15 minutes
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { C as CacheHandler, F as Fetch, z as RequestManager, S as Store, r as cacheKeyFor, r as recordIdentifierFor, E as setIdentifierForgetMethod, B as setIdentifierGenerationMethod, G as setIdentifierResetMethod, D as setIdentifierUpdateMethod, H as setKeyInfoForResource, s as storeFor, A as useRecommendedStore } from "./index-BoY6aNE5.js";
1
+ export { C as CacheHandler, F as Fetch, z as RequestManager, S as Store, r as cacheKeyFor, r as recordIdentifierFor, E as setIdentifierForgetMethod, B as setIdentifierGenerationMethod, G as setIdentifierResetMethod, D as setIdentifierUpdateMethod, H as setKeyInfoForResource, s as storeFor, A as useRecommendedStore } from "./index-LI2ckwf9.js";
2
2
  import "./symbols-3C1OkYtZ.js";
3
3
  import "./configure-BMxnD2RJ.js";
4
4
  import '@embroider/macros';
package/dist/reactive.js CHANGED
@@ -1,4 +1,4 @@
1
- export { u as SchemaService, p as checkout, y as commit, v as fromIdentity, q as instantiateRecord, x as registerDerivations, t as teardownRecord, w as withDefaults } from "./index-BoY6aNE5.js";
1
+ export { u as SchemaService, p as checkout, y as commit, v as fromIdentity, q as instantiateRecord, x as registerDerivations, t as teardownRecord, w as withDefaults } from "./index-LI2ckwf9.js";
2
2
  export { C as Checkout } from "./symbols-3C1OkYtZ.js";
3
3
  export { h as createRequestSubscription, j as getPromiseState, i as getRequestState } from "./configure-BMxnD2RJ.js";
4
4
  import '@embroider/macros';
@@ -1 +1 @@
1
- export { C as CacheHandler, R as RecordArrayManager, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, l as createLegacyManyArray, e as ensureStringId, f as fastPush, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, r as recordIdentifierFor, j as setRecordIdentifier, s as storeFor } from "../index-BoY6aNE5.js";
1
+ export { C as CacheHandler, R as RecordArrayManager, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, l as createLegacyManyArray, e as ensureStringId, f as fastPush, g as isPrivateStore, a as isRequestKey, i as isResourceKey, m as log, o as logGroup, r as recordIdentifierFor, j as setRecordIdentifier, s as storeFor } from "../index-LI2ckwf9.js";
@@ -1,6 +1,6 @@
1
1
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
2
2
  const name = "@warp-drive-mirror/core";
3
- const version = "5.9.0-alpha.18";
3
+ const version = "5.9.0-alpha.19";
4
4
 
5
5
  // in testing mode, we utilize globals to ensure only one copy exists of
6
6
  // these maps, due to bugs in ember-auto-import
@@ -753,7 +753,7 @@ let assertInheritedSchema;
753
753
  errors.set('type', ` <---- should be '${definition.inverseType}'`);
754
754
  }
755
755
  if (definition.inverseKind !== meta.kind) {
756
- errors.set('type', ` <---- should be '${definition.inverseKind}'`);
756
+ errors.set('kind', ` <---- should be '${definition.inverseKind}'`);
757
757
  }
758
758
  if (definition.inverseIsAsync !== meta.options.async) {
759
759
  errors.set('async', ` <---- should be ${definition.inverseIsAsync}`);
@@ -764,7 +764,12 @@ let assertInheritedSchema;
764
764
  if (definition.key !== meta.options.inverse) {
765
765
  errors.set('inverse', ` <---- should be '${definition.key}'`);
766
766
  }
767
- if (definition.type !== meta.options.as) {
767
+ // `as` is only meaningful when `definition` itself is polymorphic (i.e. it
768
+ // points at an abstract type that `meta` is expected to implement). When
769
+ // `definition` isn't polymorphic, there's no abstract type for `meta` to
770
+ // declare `as` against, so `meta.options.as` is correctly absent - that's
771
+ // not an error to report.
772
+ if (definition.isPolymorphic && definition.type !== meta.options.as) {
768
773
  errors.set('as', ` <---- should be '${definition.type}'`);
769
774
  }
770
775
  return errors;
@@ -803,18 +808,6 @@ let assertInheritedSchema;
803
808
 
804
809
  `;
805
810
  }
806
- function metaFrom(definition) {
807
- return {
808
- name: definition.key,
809
- type: definition.type,
810
- kind: definition.kind,
811
- options: {
812
- async: definition.isAsync,
813
- polymorphic: definition.isPolymorphic,
814
- inverse: definition.inverseKey
815
- }
816
- };
817
- }
818
811
  function inverseMetaFrom(definition) {
819
812
  return {
820
813
  name: definition.inverseKey,
@@ -857,15 +850,18 @@ let assertInheritedSchema;
857
850
  });
858
851
  }
859
852
  assertInheritedSchema = function assertInheritedSchema(definition, type) {
860
- const meta1 = metaFrom(definition);
853
+ // `definition` is the only source of truth we have here - there is no
854
+ // second, independently-declared schema available to diff it against.
855
+ // That means the only thing we can actually verify is internal: does
856
+ // `definition`'s own resolved inverse agree that this relationship is
857
+ // polymorphic? Every other field of `meta2` below (name/type/kind/async/
858
+ // inverse) is derived directly from `definition` itself, so comparing
859
+ // them back to `definition` can never disagree - only the polymorphic
860
+ // flag is independently meaningful, because `definitionWithPolymorphic`
861
+ // asserts what it *should* be rather than mirroring what it already is.
861
862
  const meta2 = inverseMetaFrom(definition);
862
- const errors1 = validateSchema(inverseDefinition(definition), meta1);
863
863
  const errors2 = validateSchema(definitionWithPolymorphic(definition), meta2);
864
- if (errors2.size === 0 && errors1.size > 0) {
865
- throw new Error(`The schema for the relationship '${type}.${definition.key}' is not configured to satisfy '${definition.inverseType}' and thus cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}'\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${type}' should include:${printSchema(meta1, errors1)}`);
866
- } else if (errors1.size > 0) {
867
- throw new Error(`The schema for the relationship '${type}.${definition.key}' is not configured to satisfy '${definition.inverseType}' and thus cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}'\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${type}' should include:${printSchema(meta1, errors1)} and the relationships schema definition for '${definition.type}' should include:${printSchema(meta2, errors2)}`);
868
- } else if (errors2.size > 0) {
864
+ if (errors2.size > 0) {
869
865
  throw new Error(`The schema for the relationship '${type}.${definition.key}' satisfies '${definition.inverseType}' but cannot utilize the '${definition.inverseType}.${definition.key}' relationship to connect with '${definition.type}.${definition.inverseKey}' because that relationship is not polymorphic.\n\nIf using this relationship in a polymorphic manner is desired, the relationships schema definition for '${definition.type}' should include:${printSchema(meta2, errors2)}`);
870
866
  }
871
867
  };