@warp-drive/legacy 5.9.0-alpha.17 → 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 (62) hide show
  1. package/declarations/model/-private/attr.d.ts +21 -0
  2. package/declarations/model/-private/belongs-to.d.ts +21 -0
  3. package/declarations/model/-private/schema-provider.d.ts +4 -1
  4. package/declarations/serializer/-private/utils.d.ts +24 -0
  5. package/dist/{hooks-D6diaM34.js → hooks-DuAlm6Rk.js} +1 -1
  6. package/dist/index.js +27 -4
  7. package/dist/json-DR3gUXRl.js +1329 -0
  8. package/dist/model/migration-support.js +1 -1
  9. package/dist/{unpkg/dev-deprecated/model-for-CqXsIKws.js → model-for-DOiIKvY_.js} +7 -1
  10. package/dist/model-fragments.js +2 -2
  11. package/dist/model.js +11 -7
  12. package/dist/{schema-provider-DJCV_6AF.js → schema-provider-y3Wz44Br.js} +24 -2
  13. package/dist/serializer/json-api.js +1 -1
  14. package/dist/serializer/json.js +1 -1
  15. package/dist/serializer/rest.js +2 -3
  16. package/dist/unpkg/dev/{hooks-CkYiE6Ud.js → hooks-BEiCsM8w.js} +1 -1
  17. package/dist/unpkg/dev/index.js +27 -4
  18. package/dist/unpkg/{prod-deprecated/json-BWrZ5546.js → dev/json-0O0HyAmg.js} +87 -4
  19. package/dist/unpkg/dev/model/migration-support.js +1 -1
  20. package/dist/{model-for-CqXsIKws.js → unpkg/dev/model-for-DOiIKvY_.js} +7 -1
  21. package/dist/unpkg/dev/model-fragments.js +2 -2
  22. package/dist/unpkg/dev/model.js +11 -7
  23. package/dist/unpkg/dev/{schema-provider-DDVYxmUV.js → schema-provider-CkZd1K6p.js} +24 -2
  24. package/dist/unpkg/dev/serializer/json-api.js +1 -1
  25. package/dist/unpkg/dev/serializer/json.js +1 -1
  26. package/dist/unpkg/dev/serializer/rest.js +2 -3
  27. package/dist/unpkg/dev-deprecated/{hooks-DOXegvhL.js → hooks-CCFCZJvG.js} +1 -1
  28. package/dist/unpkg/dev-deprecated/index.js +27 -4
  29. package/dist/unpkg/{dev/json-Cu1LNgmQ.js → dev-deprecated/json-0O0HyAmg.js} +74 -4
  30. package/dist/unpkg/dev-deprecated/model/migration-support.js +1 -1
  31. package/dist/unpkg/{dev/model-for-CqXsIKws.js → dev-deprecated/model-for-DOiIKvY_.js} +7 -1
  32. package/dist/unpkg/dev-deprecated/model-fragments.js +2 -2
  33. package/dist/unpkg/dev-deprecated/model.js +11 -7
  34. package/dist/unpkg/dev-deprecated/{schema-provider-BP6_8N-V.js → schema-provider-Bow8-gvt.js} +24 -2
  35. package/dist/unpkg/dev-deprecated/serializer/json-api.js +1 -1
  36. package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
  37. package/dist/unpkg/dev-deprecated/serializer/rest.js +2 -3
  38. package/dist/unpkg/prod/{hooks-BztVA_x0.js → hooks-BLLUOwXG.js} +1 -1
  39. package/dist/unpkg/prod/index.js +27 -4
  40. package/dist/{json-ChdEfB0X.js → unpkg/prod/json-C3hcpFmX.js} +54 -20
  41. package/dist/unpkg/prod/model/migration-support.js +1 -1
  42. package/dist/unpkg/prod/model-for-DOiIKvY_.js +227 -0
  43. package/dist/unpkg/prod/model-fragments.js +2 -2
  44. package/dist/unpkg/prod/model.js +11 -7
  45. package/dist/unpkg/prod/{schema-provider-DJtD_8jZ.js → schema-provider-D-l95_QW.js} +19 -2
  46. package/dist/unpkg/prod/serializer/json-api.js +1 -1
  47. package/dist/unpkg/prod/serializer/json.js +1 -1
  48. package/dist/unpkg/prod/serializer/rest.js +2 -3
  49. package/dist/unpkg/prod-deprecated/{hooks-yId87yyG.js → hooks-p4t9BWeH.js} +1 -1
  50. package/dist/unpkg/prod-deprecated/index.js +27 -4
  51. package/dist/unpkg/{dev-deprecated/json-Cu1LNgmQ.js → prod-deprecated/json-C3hcpFmX.js} +54 -17
  52. package/dist/unpkg/prod-deprecated/model/migration-support.js +1 -1
  53. package/dist/unpkg/prod-deprecated/{model-for-CqXsIKws.js → model-for-DOiIKvY_.js} +7 -1
  54. package/dist/unpkg/prod-deprecated/model-fragments.js +2 -2
  55. package/dist/unpkg/prod-deprecated/model.js +11 -7
  56. package/dist/unpkg/prod-deprecated/{schema-provider-CjX55uSY.js → schema-provider-qisHNwCL.js} +19 -2
  57. package/dist/unpkg/prod-deprecated/serializer/json-api.js +1 -1
  58. package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
  59. package/dist/unpkg/prod-deprecated/serializer/rest.js +2 -3
  60. package/package.json +6 -6
  61. package/dist/unpkg/prod/json-BWrZ5546.js +0 -1243
  62. package/dist/unpkg/prod/model-for-CqXsIKws.js +0 -221
@@ -36,6 +36,27 @@ export type AttrOptions<DV = PrimitiveValue | object | unknown[]> = {
36
36
  *
37
37
  */
38
38
  defaultValue?: DV extends PrimitiveValue ? DV : () => DV;
39
+ /**
40
+ * The name of the field as returned by the API and inserted into the
41
+ * cache if it differs from the name of the decorated property.
42
+ *
43
+ * For instance, if the API returns:
44
+ *
45
+ * ```ts
46
+ * {
47
+ * attributes: {
48
+ * 'first-name': 'Chris'
49
+ * }
50
+ * }
51
+ * ```
52
+ *
53
+ * But the app desires to use `record.firstName; // 'Chris'`, then the
54
+ * property should be named `firstName` and `sourceKey` should be set
55
+ * to `'first-name'`.
56
+ *
57
+ * This option is only needed when the value differs from the property name.
58
+ */
59
+ sourceKey?: string;
39
60
  };
40
61
  type LooseTransformInstance<
41
62
  V,
@@ -10,6 +10,27 @@ export type RelationshipOptions<
10
10
  as?: string;
11
11
  linksMode?: true;
12
12
  resetOnRemoteUpdate?: boolean;
13
+ /**
14
+ * The name of the field as returned by the API and inserted into the
15
+ * cache if it differs from the name of the decorated property.
16
+ *
17
+ * For instance, if the API returns:
18
+ *
19
+ * ```ts
20
+ * {
21
+ * relationships: {
22
+ * 'best-friend': { data: { type: 'user', id: '1' } }
23
+ * }
24
+ * }
25
+ * ```
26
+ *
27
+ * But the app desires to use `record.bestFriend`, then the property
28
+ * should be named `bestFriend` and `sourceKey` should be set to
29
+ * `'best-friend'`.
30
+ *
31
+ * This option is only needed when the value differs from the property name.
32
+ */
33
+ sourceKey?: string;
13
34
  };
14
35
  export type NoNull<T> = Exclude<T, null>;
15
36
  export type RelationshipDecorator<T> = <This>(target: This, key: string, desc?: PropertyDescriptor) => void;
@@ -3,7 +3,7 @@ import type { SchemaService } from "@warp-drive/core/types";
3
3
  import type { ResourceKey } from "@warp-drive/core/types/identifier";
4
4
  import type { ObjectValue } from "@warp-drive/core/types/json/raw";
5
5
  import type { Derivation, HashFn, Transformation } from "@warp-drive/core/types/schema/concepts";
6
- import type { ArrayField, DerivedField, GenericField, HashField, LegacyField, ObjectField, ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
6
+ import type { ArrayField, CacheableFieldSchema, DerivedField, GenericField, HashField, IdentityField, LegacyField, ObjectField, ObjectSchema, ResourceSchema } from "@warp-drive/core/types/schema/fields";
7
7
  import type { ModelFactory, ModelStore } from "./model.js";
8
8
  type AttributesSchema = ReturnType<Exclude<SchemaService["attributesDefinitionFor"], undefined>>;
9
9
  type RelationshipsSchema = ReturnType<Exclude<SchemaService["relationshipsDefinitionFor"], undefined>>;
@@ -47,6 +47,9 @@ export declare class ModelSchemaProvider implements SchemaService {
47
47
  fields(resource: ResourceKey | {
48
48
  type: string;
49
49
  }): Map<string, LegacyField>;
50
+ cacheFields(resource: ResourceKey | {
51
+ type: string;
52
+ }): Map<string, Exclude<CacheableFieldSchema, IdentityField>>;
50
53
  hasResource(resource: {
51
54
  type: string;
52
55
  }): boolean;
@@ -1,3 +1,27 @@
1
+ import type { Store } from "@warp-drive/core";
2
+ import type { LegacyBelongsToField, LegacyHasManyField, LegacyRelationshipField } from "@warp-drive/core/types/schema/fields";
1
3
  type Coercable = string | number | boolean | null | undefined | symbol;
2
4
  export declare function coerceId(id: Coercable): string | null;
5
+ /**
6
+ Given the name of a relationship on a resource `type`, determines the
7
+ inverse relationship field (if any) using only the schema service.
8
+
9
+ Unlike `Model.inverseFor`, this does not require `type` to be backed by
10
+ a `Model` class, so it works for both `Model`-based and schema-only
11
+ (e.g. `withDefaults` migration-support) resources.
12
+
13
+ @private
14
+ */
15
+ export declare function inverseForRelationship(store: Store, type: string, name: string): LegacyRelationshipField | null;
16
+ /**
17
+ Given a relationship field on a resource `type`, determines the
18
+ cardinality of the relationship using only the schema service.
19
+
20
+ Unlike `Model.determineRelationshipType`, this does not require `type`
21
+ to be backed by a `Model` class, so it works for both `Model`-based and
22
+ schema-only (e.g. `withDefaults` migration-support) resources.
23
+
24
+ @private
25
+ */
26
+ export declare function determineRelationshipType(store: Store, type: string, knownSide: LegacyBelongsToField | LegacyHasManyField): "oneToOne" | "oneToMany" | "manyToOne" | "manyToMany" | "oneToNone" | "manyToNone";
3
27
  export {};
@@ -1,6 +1,6 @@
1
1
  import { setOwner, getOwner } from '@ember/application';
2
2
  import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
3
- import { g as getModelFactory } from "./schema-provider-DJCV_6AF.js";
3
+ import { g as getModelFactory } from "./schema-provider-y3Wz44Br.js";
4
4
  import { n as normalizeModelName } from "./util-Dul6TZts.js";
5
5
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
6
  function instantiateRecord(identifier, createRecordArgs) {
package/dist/index.js CHANGED
@@ -10,10 +10,10 @@ import '@warp-drive/utilities/string';
10
10
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
11
11
  import '@warp-drive/core/store/-private';
12
12
  import "./errors-Cz5KrzBk.js";
13
- import "./schema-provider-DJCV_6AF.js";
14
- import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-D6diaM34.js";
13
+ import "./schema-provider-y3Wz44Br.js";
14
+ import { i as instantiateRecord, t as teardownRecord, m as modelFor } from "./hooks-DuAlm6Rk.js";
15
15
  import { registerDerivations as registerDerivations$1, DelegatingSchemaService } from './model/migration-support.js';
16
- import { F as FragmentExtension, a as FragmentArrayExtension, f as fragmentsModelFor } from "./model-for-CqXsIKws.js";
16
+ import { F as FragmentExtension, a as FragmentArrayExtension, f as fragmentsModelFor } from "./model-for-DOiIKvY_.js";
17
17
  import { restoreDeprecatedStoreBehaviors } from './store.js';
18
18
 
19
19
  /**
@@ -43,7 +43,30 @@ function useLegacyStore(options, StoreKlass = Store) {
43
43
  // we extend the store to ensure we don't leak our prototype overrides to other stores below.
44
44
  class BaseKlass extends StoreKlass {}
45
45
  class LegacyConfiguredStore extends BaseKlass {
46
- requestManager = new RequestManager().use([options.linksMode ? null : LegacyNetworkHandler, ...(options.handlers ?? []), Fetch].filter(Boolean)).useCache(CacheHandler);
46
+ constructor(createArgs) {
47
+ super(createArgs);
48
+ // installed via defineProperty (rather than a class field/accessor) so that
49
+ // this lazy override of the inherited `requestManager` field does not
50
+ // conflict with the documented pattern of assigning it directly on
51
+ // consumer-authored Store subclasses. The setter preserves the ability
52
+ // to replace `requestManager` outright after construction.
53
+ let requestManager;
54
+ Object.defineProperty(this, 'requestManager', {
55
+ configurable: true,
56
+ enumerable: true,
57
+ get: () => {
58
+ if (!requestManager) {
59
+ const handlersOption = options.handlers;
60
+ const handlers = typeof handlersOption === 'function' ? handlersOption(this) : handlersOption ?? [];
61
+ requestManager = new RequestManager().use([options.linksMode ? null : LegacyNetworkHandler, ...handlers, Fetch].filter(Boolean)).useCache(CacheHandler);
62
+ }
63
+ return requestManager;
64
+ },
65
+ set: value => {
66
+ requestManager = value;
67
+ }
68
+ });
69
+ }
47
70
  lifetimes = options.policy ?? new DefaultCachePolicy({
48
71
  apiCacheHardExpires: 15 * 60 * 1000,
49
72
  // 15 minutes