@warp-drive/core 5.6.0-beta.1 → 5.6.0-beta.3

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 (123) hide show
  1. package/declarations/graph/-private/-diff.d.ts +7 -20
  2. package/declarations/graph/-private/-edge-definition.d.ts +3 -12
  3. package/declarations/graph/-private/-state.d.ts +0 -87
  4. package/declarations/graph/-private/-utils.d.ts +5 -11
  5. package/declarations/graph/-private/coerce-id.d.ts +0 -6
  6. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +2 -14
  7. package/declarations/graph/-private/edges/collection.d.ts +10 -10
  8. package/declarations/graph/-private/edges/implicit.d.ts +5 -5
  9. package/declarations/graph/-private/edges/resource.d.ts +6 -7
  10. package/declarations/graph/-private/graph.d.ts +17 -51
  11. package/declarations/graph/-private/normalize-link.d.ts +0 -6
  12. package/declarations/graph/-private/operations/replace-related-records.d.ts +4 -59
  13. package/declarations/graph/-private/operations/update-relationship.d.ts +3 -7
  14. package/declarations/index.d.ts +1 -1
  15. package/declarations/reactive/-private/default-mode.d.ts +73 -0
  16. package/declarations/reactive/-private/document.d.ts +11 -27
  17. package/declarations/reactive/-private/fields/get-field-key.d.ts +8 -0
  18. package/declarations/reactive/-private/fields/managed-array.d.ts +7 -11
  19. package/declarations/reactive/-private/fields/managed-object.d.ts +7 -11
  20. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  21. package/declarations/reactive/-private/hooks.d.ts +2 -2
  22. package/declarations/reactive/-private/kind/alias-field.d.ts +4 -0
  23. package/declarations/reactive/-private/kind/array-field.d.ts +4 -0
  24. package/declarations/reactive/-private/kind/attribute-field.d.ts +4 -0
  25. package/declarations/reactive/-private/kind/belongs-to-field.d.ts +4 -0
  26. package/declarations/reactive/-private/kind/collection-field.d.ts +4 -0
  27. package/declarations/reactive/-private/kind/derived-field.d.ts +4 -0
  28. package/declarations/reactive/-private/kind/generic-field.d.ts +4 -0
  29. package/declarations/reactive/-private/kind/has-many-field.d.ts +4 -0
  30. package/declarations/reactive/-private/kind/hash-field.d.ts +4 -0
  31. package/declarations/reactive/-private/kind/identity-field.d.ts +4 -0
  32. package/declarations/reactive/-private/kind/local-field.d.ts +4 -0
  33. package/declarations/reactive/-private/kind/object-field.d.ts +4 -0
  34. package/declarations/reactive/-private/kind/resource-field.d.ts +4 -0
  35. package/declarations/reactive/-private/kind/schema-array-field.d.ts +4 -0
  36. package/declarations/reactive/-private/kind/schema-object-field.d.ts +4 -0
  37. package/declarations/reactive/-private/record.d.ts +44 -34
  38. package/declarations/reactive/-private/schema.d.ts +50 -68
  39. package/declarations/reactive/-private/symbols.d.ts +2 -33
  40. package/declarations/reactive/-private.d.ts +1 -1
  41. package/declarations/reactive.d.ts +278 -1
  42. package/declarations/request/-private/context.d.ts +3 -5
  43. package/declarations/request/-private/fetch.d.ts +2 -0
  44. package/declarations/request/-private/manager.d.ts +24 -28
  45. package/declarations/request/-private/types.d.ts +22 -24
  46. package/declarations/request/-private/utils.d.ts +44 -2
  47. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  48. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  49. package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
  50. package/declarations/store/-private/caches/instance-cache.d.ts +22 -28
  51. package/declarations/store/-private/debug/utils.d.ts +1 -0
  52. package/declarations/store/-private/default-cache-policy.d.ts +25 -40
  53. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  54. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
  55. package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
  56. package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
  57. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  58. package/declarations/store/-private/network/request-cache.d.ts +21 -25
  59. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  60. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  61. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  62. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  63. package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
  64. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
  65. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  66. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  67. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  68. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  69. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  70. package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
  71. package/declarations/store/-private/store-service.d.ts +167 -877
  72. package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
  73. package/declarations/store/-private.d.ts +13 -14
  74. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  75. package/declarations/store/-types/q/identifier.d.ts +9 -6
  76. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  77. package/declarations/store/-types/q/schema-service.d.ts +64 -40
  78. package/declarations/store/-types/q/store.d.ts +6 -7
  79. package/declarations/store/deprecated/-private.d.ts +223 -0
  80. package/declarations/store/deprecated/store.d.ts +783 -0
  81. package/declarations/types/-private.d.ts +1 -1
  82. package/declarations/types/cache/aliases.d.ts +0 -11
  83. package/declarations/types/cache/change.d.ts +2 -2
  84. package/declarations/types/cache/mutations.d.ts +13 -37
  85. package/declarations/types/cache/operations.d.ts +115 -32
  86. package/declarations/types/cache/relationship.d.ts +4 -7
  87. package/declarations/types/cache.d.ts +51 -127
  88. package/declarations/types/graph.d.ts +12 -12
  89. package/declarations/types/identifier.d.ts +52 -78
  90. package/declarations/types/params.d.ts +2 -3
  91. package/declarations/types/request.d.ts +66 -42
  92. package/declarations/types/schema/concepts.d.ts +2 -2
  93. package/declarations/types/schema/fields.d.ts +391 -14
  94. package/declarations/types/spec/document.d.ts +6 -10
  95. package/declarations/types/spec/json-api-raw.d.ts +6 -9
  96. package/declarations/types.d.ts +1 -1
  97. package/declarations/utils/string.d.ts +2 -3
  98. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  99. package/dist/configure.js +1 -1
  100. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  101. package/dist/graph/-private.js +137 -144
  102. package/dist/index.js +25 -14
  103. package/dist/reactive/-private.js +1 -1
  104. package/dist/reactive.js +337 -1422
  105. package/dist/{request-state-CjLph1LP.js → request-state-C955e0AL.js} +8352 -5912
  106. package/dist/request.js +1 -1
  107. package/dist/store/-private.js +2 -3
  108. package/dist/store.js +32 -44
  109. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  110. package/dist/types/-private.js +1 -1
  111. package/dist/types/identifier.js +19 -45
  112. package/dist/types/request.js +45 -3
  113. package/dist/types/schema/fields.js +23 -2
  114. package/dist/utils/string.js +2 -2
  115. package/package.json +11 -11
  116. package/declarations/reactive/-private/fields/compute.d.ts +0 -43
  117. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  118. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
  119. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
  120. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  121. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  122. package/declarations/store/-types/q/ds-model.d.ts +0 -21
  123. package/dist/handler-C2T-IyJK.js +0 -339
@@ -1,12 +1,12 @@
1
1
  import type { Store } from "../../store/-private/store-service.js";
2
- import type { StableDocumentIdentifier } from "../../types/identifier.js";
2
+ import type { RequestKey } from "../../types/identifier.js";
3
3
  import type { ImmutableRequestInfo, RequestInfo } from "../../types/request.js";
4
4
  import type { ResourceDocument } from "../../types/spec/document.js";
5
5
  import type { Meta, PaginationLinks } from "../../types/spec/json-api-raw.js";
6
6
  /**
7
7
  * A Document is a class that wraps the response content from a request to the API
8
- * returned by `Cache.put` or `Cache.peek`, converting resource-identifiers into
9
- * record instances.
8
+ * returned by `Cache.put` or `Cache.peek`, converting ResourceKeys into
9
+ * ReactiveResource instances.
10
10
  *
11
11
  * It is not directly instantiated by the user, and its properties should not
12
12
  * be directly modified. Whether individual properties are mutable or not is
@@ -16,7 +16,6 @@ import type { Meta, PaginationLinks } from "../../types/spec/json-api-raw.js";
16
16
  * @hideconstructor
17
17
  */
18
18
  export declare class ReactiveDocument<T> {
19
- #private;
20
19
  /**
21
20
  * The links object for this document, if any
22
21
  *
@@ -28,8 +27,6 @@ export declare class ReactiveDocument<T> {
28
27
  * }
29
28
  * ```
30
29
  *
31
- * @property links
32
- * @type {Object|undefined} - a links object
33
30
  * @public
34
31
  */
35
32
  readonly links?: PaginationLinks;
@@ -42,41 +39,28 @@ export declare class ReactiveDocument<T> {
42
39
  * For collections this will be an array of record instances,
43
40
  * for single resource requests it will be a single record instance or null.
44
41
  *
45
- * @property data
46
42
  * @public
47
- * @type {Object|Array<object>|null|undefined} - a data object
48
43
  */
49
44
  readonly data?: T;
50
45
  /**
51
46
  * The errors returned by the API for this request, if any
52
47
  *
53
- * @property errors
54
48
  * @public
55
- * @type {Object|undefined} - an errors object
56
49
  */
57
50
  readonly errors?: object[];
58
51
  /**
59
52
  * The meta object for this document, if any
60
53
  *
61
- * @property meta
62
54
  * @public
63
- * @type {Object|undefined} - a meta object
64
55
  */
65
56
  readonly meta?: Meta;
66
57
  /**
67
- * The identifier associated with this document, if any
58
+ * The RequestKey associated with this document, if any
68
59
  *
69
- * @property identifier
70
60
  * @public
71
- * @type {StableDocumentIdentifier|null}
72
61
  */
73
- readonly identifier: StableDocumentIdentifier | null;
74
- protected readonly _store: Store;
75
- protected readonly _localCache: {
76
- document: ResourceDocument;
77
- request: ImmutableRequestInfo;
78
- } | null;
79
- constructor(store: Store, identifier: StableDocumentIdentifier | null, localCache: {
62
+ readonly identifier: RequestKey | null;
63
+ constructor(store: Store, cacheKey: RequestKey | null, localCache: {
80
64
  document: ResourceDocument;
81
65
  request: ImmutableRequestInfo;
82
66
  } | null);
@@ -89,7 +73,7 @@ export declare class ReactiveDocument<T> {
89
73
  * @param {Object} options
90
74
  * @return {Promise<Document>}
91
75
  */
92
- fetch(options?: RequestInfo<ReactiveDocument<T>, T>): Promise<ReactiveDocument<T>>;
76
+ fetch(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T>>;
93
77
  /**
94
78
  * Fetches the next link for this document, returning a promise that resolves
95
79
  * with the new document when the request completes, or null if there is no
@@ -99,7 +83,7 @@ export declare class ReactiveDocument<T> {
99
83
  * @param {Object} options
100
84
  * @return {Promise<Document | null>}
101
85
  */
102
- next(options?: RequestInfo<ReactiveDocument<T>, T>): Promise<ReactiveDocument<T> | null>;
86
+ next(options?: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
103
87
  /**
104
88
  * Fetches the prev link for this document, returning a promise that resolves
105
89
  * with the new document when the request completes, or null if there is no
@@ -109,7 +93,7 @@ export declare class ReactiveDocument<T> {
109
93
  * @param {Object} options
110
94
  * @return {Promise<Document | null>}
111
95
  */
112
- prev(options: RequestInfo<ReactiveDocument<T>, T>): Promise<ReactiveDocument<T> | null>;
96
+ prev(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
113
97
  /**
114
98
  * Fetches the first link for this document, returning a promise that resolves
115
99
  * with the new document when the request completes, or null if there is no
@@ -119,7 +103,7 @@ export declare class ReactiveDocument<T> {
119
103
  * @param {Object} options
120
104
  * @return {Promise<Document | null>}
121
105
  */
122
- first(options: RequestInfo<ReactiveDocument<T>, T>): Promise<ReactiveDocument<T> | null>;
106
+ first(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
123
107
  /**
124
108
  * Fetches the last link for this document, returning a promise that resolves
125
109
  * with the new document when the request completes, or null if there is no
@@ -129,7 +113,7 @@ export declare class ReactiveDocument<T> {
129
113
  * @param {Object} options
130
114
  * @return {Promise<Document | null>}
131
115
  */
132
- last(options: RequestInfo<ReactiveDocument<T>, T>): Promise<ReactiveDocument<T> | null>;
116
+ last(options: RequestInfo<ReactiveDocument<T>>): Promise<ReactiveDocument<T> | null>;
133
117
  /**
134
118
  * Implemented for `JSON.stringify` support.
135
119
  *
@@ -0,0 +1,8 @@
1
+ import type { CacheableFieldSchema, FieldSchema, HashField, IdentityField } from "../../../types/schema/fields.js";
2
+ type InvalidKind = "alias" | "derived" | "@local";
3
+ export declare function isInvalidKind(kind: string): kind is InvalidKind;
4
+ export declare function isNonIdentityCacheableField(field: FieldSchema | IdentityField | HashField): field is Exclude<CacheableFieldSchema, IdentityField>;
5
+ export declare function getFieldCacheKeyStrict(field: CacheableFieldSchema): string;
6
+ export declare function getFieldCacheKey(field: FieldSchema | IdentityField | HashField): string | null;
7
+ export declare function assertIsCacheField(field: FieldSchema | IdentityField): asserts field is CacheableFieldSchema;
8
+ export {};
@@ -1,22 +1,18 @@
1
- import type { Store } from "../../../index.js";
2
1
  import type { WarpDriveSignal } from "../../../store/-private.js";
3
2
  import { ARRAY_SIGNAL } from "../../../store/-private.js";
4
- import type { Cache } from "../../../types/cache.js";
5
- import type { StableRecordIdentifier } from "../../../types/identifier.js";
3
+ import type { ResourceKey } from "../../../types/identifier.js";
6
4
  import type { ArrayField, SchemaArrayField } from "../../../types/schema/fields.js";
5
+ import type { KindContext } from "../default-mode.js";
7
6
  import { ReactiveResource } from "../record.js";
8
- import type { SchemaService } from "../schema.js";
9
- import { Editable, Legacy, SOURCE } from "../symbols.js";
7
+ import { Context, SOURCE } from "../symbols.js";
10
8
  export interface ManagedArray extends Omit<Array<unknown>, "[]"> {
11
9
  [SOURCE]: unknown[];
12
- identifier: StableRecordIdentifier;
13
- path: string[];
10
+ identifier: ResourceKey;
11
+ path: string | string[];
14
12
  owner: ReactiveResource;
15
13
  [ARRAY_SIGNAL]: WarpDriveSignal;
16
- [Editable]: boolean;
17
- [Legacy]: boolean;
14
+ [Context]: KindContext<SchemaArrayField | ArrayField>;
18
15
  }
19
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
20
16
  export declare class ManagedArray {
21
- constructor(store: Store, schema: SchemaService, cache: Cache, field: ArrayField | SchemaArrayField, data: unknown[], identifier: StableRecordIdentifier, path: string[], owner: ReactiveResource, isSchemaArray: boolean, editable: boolean, legacy: boolean);
17
+ constructor(context: KindContext<SchemaArrayField | ArrayField>, owner: ReactiveResource, data: unknown[]);
22
18
  }
@@ -1,21 +1,17 @@
1
1
  import { OBJECT_SIGNAL, type WarpDriveSignal } from "../../../store/-private.js";
2
- import type { Cache } from "../../../types/cache.js";
3
- import type { StableRecordIdentifier } from "../../../types/identifier.js";
4
2
  import type { ObjectField, SchemaObjectField } from "../../../types/schema/fields.js";
3
+ import type { KindContext } from "../default-mode.js";
5
4
  import type { ReactiveResource } from "../record.js";
6
- import type { SchemaService } from "../schema.js";
7
- import { Editable, EmbeddedPath, Legacy, Parent, SOURCE } from "../symbols.js";
5
+ import { Context, SOURCE } from "../symbols.js";
8
6
  export declare function notifyObject(obj: ManagedObject): void;
9
- // const ignoredGlobalFields = new Set<string>(['setInterval', 'nodeType', 'nodeName', 'length', 'document', STRUCTURED]);
10
7
  export interface ManagedObject {
11
8
  [SOURCE]: object;
12
- [Parent]: StableRecordIdentifier;
13
- [EmbeddedPath]: string[];
9
+ [Context]: KindContext<ObjectField>;
14
10
  [OBJECT_SIGNAL]: WarpDriveSignal;
15
- [Editable]: boolean;
16
- [Legacy]: boolean;
17
11
  }
18
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
19
12
  export declare class ManagedObject {
20
- constructor(schema: SchemaService, cache: Cache, field: ObjectField | SchemaObjectField, data: object, identifier: StableRecordIdentifier, path: string[], owner: ReactiveResource, editable: boolean, legacy: boolean);
13
+ constructor(context: KindContext<ObjectField>);
21
14
  }
15
+ export declare const ManagedObjectMap: Map<ReactiveResource, Map<string, ManagedObject | ReactiveResource>>;
16
+ export declare function peekManagedObject(record: ReactiveResource, field: ObjectField): ManagedObject | undefined;
17
+ export declare function peekManagedObject(record: ReactiveResource, field: SchemaObjectField): ReactiveResource | undefined;
@@ -1,7 +1,7 @@
1
1
  import type { Store } from "../../../index.js";
2
2
  import type { RelatedCollection as ManyArray } from "../../../store/-private.js";
3
3
  import type { LocalRelationshipOperation } from "../../../types/graph.js";
4
- import type { StableRecordIdentifier } from "../../../types/identifier.js";
4
+ import type { ResourceKey } from "../../../types/identifier.js";
5
5
  import type { ReactiveResource } from "../record.js";
6
6
  export interface FindHasManyOptions {
7
7
  reload?: boolean;
@@ -10,7 +10,7 @@ export interface FindHasManyOptions {
10
10
  export declare class ManyArrayManager {
11
11
  record: ReactiveResource;
12
12
  store: Store;
13
- identifier: StableRecordIdentifier;
13
+ identifier: ResourceKey;
14
14
  editable: boolean;
15
15
  constructor(record: ReactiveResource, editable: boolean);
16
16
  _syncArray(array: ManyArray): void;
@@ -1,5 +1,5 @@
1
1
  import type { Store } from "../../index.js";
2
- import type { StableRecordIdentifier } from "../../types.js";
2
+ import type { ResourceKey } from "../../types.js";
3
3
  import { ReactiveResource } from "./record.js";
4
- export declare function instantiateRecord(store: Store, identifier: StableRecordIdentifier, createArgs?: Record<string, unknown>): ReactiveResource;
4
+ export declare function instantiateRecord(store: Store, identifier: ResourceKey, createArgs?: Record<string, unknown>): ReactiveResource;
5
5
  export declare function teardownRecord(record: unknown): void;
@@ -0,0 +1,4 @@
1
+ import type { LegacyAliasField, ObjectAliasField, PolarisAliasField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getAliasField(context: KindContext<LegacyAliasField | ObjectAliasField | PolarisAliasField>): unknown;
4
+ export declare function setAliasField(context: KindContext<LegacyAliasField | ObjectAliasField | PolarisAliasField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { ArrayField, SchemaArrayField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getArrayField(context: KindContext<ArrayField | SchemaArrayField>): unknown;
4
+ export declare function setArrayField(context: KindContext<ArrayField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { LegacyAttributeField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getAttributeField(context: KindContext<LegacyAttributeField>): unknown;
4
+ export declare function setAttributeField(context: KindContext<LegacyAttributeField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { LegacyBelongsToField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getBelongsToField(context: KindContext<LegacyBelongsToField>): unknown;
4
+ export declare function setBelongsToField(context: KindContext<LegacyBelongsToField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { CollectionField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getCollectionField(context: KindContext<CollectionField>): unknown;
4
+ export declare function setCollectionField(context: KindContext<CollectionField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { DerivedField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getDerivedField(context: KindContext<DerivedField>): unknown;
4
+ export declare function setDerivedField(context: KindContext<DerivedField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { GenericField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getGenericField(context: KindContext<GenericField>): unknown;
4
+ export declare function setGenericField(context: KindContext<GenericField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { LegacyHasManyField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getHasManyField(context: KindContext<LegacyHasManyField>): unknown;
4
+ export declare function setHasManyField(context: KindContext<LegacyHasManyField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { HashField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getHashField(context: KindContext<HashField>): unknown;
4
+ export declare function setHashField(context: KindContext<HashField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { IdentityField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getIdentityField(context: KindContext<IdentityField>): unknown;
4
+ export declare function setIdentityField(context: KindContext<IdentityField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { LocalField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getLocalField(context: KindContext<LocalField>): unknown;
4
+ export declare function setLocalField(context: KindContext<LocalField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { ObjectField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getObjectField(context: KindContext<ObjectField>): unknown;
4
+ export declare function setObjectField(context: KindContext<ObjectField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { ResourceField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getResourceField(context: KindContext<ResourceField>): unknown;
4
+ export declare function setResourceField(context: KindContext<ResourceField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { SchemaArrayField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export { getArrayField as getSchemaArrayField } from "./array-field.js";
4
+ export declare function setSchemaArrayField(context: KindContext<SchemaArrayField>): boolean;
@@ -0,0 +1,4 @@
1
+ import type { SchemaObjectField } from "../../../types/schema/fields.js";
2
+ import type { KindContext } from "../default-mode.js";
3
+ export declare function getSchemaObjectField(context: KindContext<SchemaObjectField>): unknown;
4
+ export declare function setSchemaObjectField(context: KindContext<SchemaObjectField>): boolean;
@@ -1,37 +1,14 @@
1
- import type { Store } from "../../index.js";
2
- import type { StableRecordIdentifier } from "../../types/identifier.js";
3
- import type { SchemaArrayField, SchemaObjectField } from "../../types/schema/fields.js";
4
- import { RecordStore } from "../../types/symbols.js";
5
- import { Checkout, Destroy, Editable, EmbeddedField, EmbeddedPath, Identifier, Legacy, Parent } from "./symbols.js";
6
- export { Editable, Legacy, Checkout } from "./symbols.js";
1
+ import type { ObjectContext, ResourceContext } from "./default-mode.js";
2
+ import { Checkout } from "./symbols.js";
7
3
  export interface ReactiveResource {
8
- [Symbol.toStringTag]: `ReactiveResource<${string}>`;
9
- /** @internal */
10
- [RecordStore]: Store;
11
- /** @internal */
12
- [Identifier]: StableRecordIdentifier;
13
- /** @internal */
14
- [Parent]: StableRecordIdentifier;
15
- /** @internal */
16
- [EmbeddedField]: SchemaArrayField | SchemaObjectField | null;
17
- /** @internal */
18
- [EmbeddedPath]: string[] | null;
19
- /** @internal */
20
- [Editable]: boolean;
21
- /** @internal */
22
- [Legacy]: boolean;
23
- /** @internal */
24
- ___notifications: object;
25
- /** @internal */
26
- [Destroy](): void;
27
4
  /**
28
5
  * Create an editable copy of the record
29
6
  *
30
7
  * ReactiveResource instances are not editable by default. This method creates an editable copy of the record. To use,
31
- * import the `Checkout` symbol from `@warp-drive/schema-record` and call it on the record.
8
+ * import the `Checkout` symbol from `@warp-drive/core/reactive` and call it on the record.
32
9
  *
33
10
  * ```ts
34
- * import { Checkout } from '@warp-drive/schema-record';
11
+ * import { Checkout } from '@warp-drive/core/reactive';
35
12
  *
36
13
  * const record = store.peekRecord('user', '1');
37
14
  * const editableRecord = await record[Checkout]();
@@ -39,13 +16,13 @@ export interface ReactiveResource {
39
16
  *
40
17
  * @returns a promise that resolves to the editable record
41
18
  * @throws if the record is already editable or if the record is embedded
42
- *
19
+ * @private
43
20
  */
44
21
  [Checkout]<T>(): Promise<T>;
45
22
  }
46
23
  /**
47
24
  * A class that uses a the ResourceSchema for a ResourceType
48
- * and a ResouceKey to transform data from the cache into a rich, reactive
25
+ * and a ResourceKey to transform data from the cache into a rich, reactive
49
26
  * object.
50
27
  *
51
28
  * This class is not directly instantiable. To use it, you should
@@ -55,10 +32,43 @@ export interface ReactiveResource {
55
32
  * @hideconstructor
56
33
  * @public
57
34
  */
58
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
59
35
  export declare class ReactiveResource {
60
- constructor(store: Store, identifier: StableRecordIdentifier, Mode: {
61
- [Editable]: boolean;
62
- [Legacy]: boolean;
63
- }, isEmbedded?: boolean, embeddedField?: SchemaArrayField | SchemaObjectField | null, embeddedPath?: string[] | null);
36
+ constructor(context: ResourceContext | ObjectContext);
64
37
  }
38
+ export declare function _CHECKOUT(record: ReactiveResource): ReactiveResource;
39
+ /**
40
+ * Checkout an immutable resource for editing.
41
+ *
42
+ * {@link ReactiveResource | ReactiveResources} are not editable by default. This method
43
+ * creates an editable copy of the resource.
44
+ *
45
+ * This returns a promise which resolves with the editable
46
+ * version of the resource.
47
+ *
48
+ * ```ts
49
+ * import { checkout } from '@warp-drive/core/reactive';
50
+ *
51
+ * const immutable = store.peekRecord('user', '1');
52
+ * const editable = await checkout(immutable);
53
+ * ```
54
+ *
55
+ * Edits to editable resources will be automatically committed if a new
56
+ * payload from the cache matches their existing value.
57
+ *
58
+ * @public
59
+ *
60
+ * @returns a promise that resolves to the editable resource
61
+ * @throws if the resource is already editable or if resource is an embedded object
62
+ */
63
+ export declare function checkout<T>(resource: unknown): Promise<T & ReactiveResource>;
64
+ /**
65
+ * Forcibly commit all local changes on an editable resource to
66
+ * the remote (immutable) version.
67
+ *
68
+ * This API should only be used cautiously. Typically a better
69
+ * approach is for either the API or a Handler to reflect saved
70
+ * changes back to update the cache.
71
+ *
72
+ * @public
73
+ */
74
+ export declare function commit(record: ReactiveResource): Promise<void>;
@@ -1,9 +1,8 @@
1
- import type { Store } from "../../store/-private.js";
2
1
  import type { SchemaService as SchemaServiceInterface } from "../../types.js";
3
- import type { StableRecordIdentifier } from "../../types/identifier.js";
2
+ import type { ResourceKey } from "../../types/identifier.js";
4
3
  import type { ObjectValue, Value } from "../../types/json/raw.js";
5
4
  import type { Derivation, HashFn } from "../../types/schema/concepts.js";
6
- import { type ArrayField, type DerivedField, type FieldSchema, type GenericField, type HashField, type LegacyAttributeField, type LegacyBelongsToField, type LegacyHasManyField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema } from "../../types/schema/fields.js";
5
+ import { type ArrayField, type CacheableFieldSchema, type DerivedField, type FieldSchema, type GenericField, type HashField, type IdentityField, type LegacyAttributeField, type LegacyRelationshipField, type ObjectField, type ObjectSchema, type PolarisResourceSchema, type ResourceSchema, type Trait } from "../../types/schema/fields.js";
7
6
  import { Type } from "../../types/symbols.js";
8
7
  import type { WithPartial } from "../../types/utils.js";
9
8
  import type { ReactiveResource } from "./record.js";
@@ -31,12 +30,10 @@ export interface CAUTION_MEGA_DANGER_ZONE_Extension {
31
30
  * A constructable such as a Function or Class whose prototype
32
31
  * will be iterated with getOwnPropertyNames.
33
32
  */
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
35
33
  features: Record<string | symbol, unknown> | Function;
36
34
  }
37
35
  export type ExtensionDef = {
38
36
  kind: "method";
39
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
40
37
  fn: Function;
41
38
  } | {
42
39
  kind: "readonly-value";
@@ -95,11 +92,11 @@ interface FromIdentityDerivation {
95
92
  }, key: string): string | null;
96
93
  (record: ReactiveResource, options: {
97
94
  key: "^";
98
- }, key: string): StableRecordIdentifier;
95
+ }, key: string): ResourceKey;
99
96
  (record: ReactiveResource, options: null, key: string): asserts options;
100
97
  (record: ReactiveResource, options: {
101
98
  key: "id" | "lid" | "type" | "^";
102
- } | null, key: string): StableRecordIdentifier | string | null;
99
+ } | null, key: string): ResourceKey | string | null;
103
100
  [Type]: "@identity";
104
101
  }
105
102
  /**
@@ -133,13 +130,14 @@ export declare const fromIdentity: FromIdentityDerivation;
133
130
  * ```
134
131
  *
135
132
  * @public
136
- * @param {SchemaService} schema
137
133
  */
138
134
  export declare function registerDerivations(schema: SchemaServiceInterface): void;
139
135
  interface InternalSchema {
140
136
  original: ResourceSchema | ObjectSchema;
137
+ finalized: boolean;
141
138
  traits: Set<string>;
142
139
  fields: Map<string, FieldSchema>;
140
+ cacheFields: Map<string, Exclude<CacheableFieldSchema, IdentityField>>;
143
141
  attributes: Record<string, LegacyAttributeField>;
144
142
  relationships: Record<string, LegacyRelationshipField>;
145
143
  }
@@ -149,20 +147,9 @@ export type Transformation<
149
147
  > = {
150
148
  serialize(value: PT, options: Record<string, unknown> | null, record: ReactiveResource): T;
151
149
  hydrate(value: T | undefined, options: Record<string, unknown> | null, record: ReactiveResource): PT;
152
- defaultValue?(options: Record<string, unknown> | null, identifier: StableRecordIdentifier): T;
150
+ defaultValue?(options: Record<string, unknown> | null, identifier: ResourceKey): T;
153
151
  [Type]: string;
154
152
  };
155
- interface KindFns {
156
- belongsTo: {
157
- get: (store: Store, record: object, resourceKey: StableRecordIdentifier, field: LegacyBelongsToField) => unknown;
158
- set: (store: Store, record: object, cacheKey: StableRecordIdentifier, field: LegacyBelongsToField, value: unknown) => void;
159
- };
160
- hasMany: {
161
- get: (store: Store, record: object, resourceKey: StableRecordIdentifier, field: LegacyHasManyField) => unknown;
162
- set: (store: Store, record: object, cacheKey: StableRecordIdentifier, field: LegacyHasManyField, value: unknown) => void;
163
- notify: (store: Store, record: object, cacheKey: StableRecordIdentifier, field: LegacyHasManyField) => boolean;
164
- };
165
- }
166
153
  export interface SchemaService {
167
154
  doesTypeExist(type: string): boolean;
168
155
  attributesDefinitionFor(identifier: {
@@ -175,36 +162,13 @@ export interface SchemaService {
175
162
  /**
176
163
  * A SchemaService designed to work with dynamically registered schemas.
177
164
  *
178
- * @class SchemaService
179
165
  * @public
180
166
  */
181
167
  export declare class SchemaService implements SchemaServiceInterface {
182
- /** @internal */
183
- _schemas: Map<string, InternalSchema>;
184
- /** @internal */
185
- _transforms: Map<string, Transformation>;
186
- /** @internal */
187
- _hashFns: Map<string, HashFn>;
188
- /** @internal */
189
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
190
- _derivations: Map<string, Derivation<any, any, any>>;
191
- /** @internal */
192
- _traits: Set<string>;
193
- /** @internal */
194
- _modes: Map<string, KindFns>;
195
- /** @internal */
196
- _extensions: {
197
- object: Map<string, ProcessedExtension>;
198
- array: Map<string, ProcessedExtension>;
199
- };
200
- _cachedFieldExtensionsByField: {
201
- object: Map<object, ProcessedExtension["features"] | null>;
202
- array: Map<object, ProcessedExtension["features"] | null>;
203
- };
204
168
  constructor();
205
169
  resourceTypes(): Readonly<string[]>;
206
170
  hasTrait(type: string): boolean;
207
- resourceHasTrait(resource: StableRecordIdentifier | {
171
+ resourceHasTrait(resource: ResourceKey | {
208
172
  type: string;
209
173
  }, trait: string): boolean;
210
174
  transformation(field: GenericField | ObjectField | ArrayField | {
@@ -216,11 +180,40 @@ export declare class SchemaService implements SchemaServiceInterface {
216
180
  hashFn(field: HashField | {
217
181
  type: string;
218
182
  }): HashFn;
219
- resource(resource: StableRecordIdentifier | {
183
+ resource(resource: ResourceKey | {
220
184
  type: string;
221
185
  }): ResourceSchema | ObjectSchema;
222
186
  registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
223
187
  registerResource(schema: ResourceSchema | ObjectSchema): void;
188
+ /**
189
+ * Registers a {@link Trait} for use by resource schemas.
190
+ *
191
+ * Traits are re-usable collections of fields that can be composed to
192
+ * build up a resource schema. Often they represent polymorphic behaviors
193
+ * a resource should exhibit.
194
+ *
195
+ * When we finalize a resource, we walk its traits and apply their fields
196
+ * to the resource's fields. All specified traits must be registered by
197
+ * this time or an error will be thrown.
198
+ *
199
+ * Traits are applied left-to-right, with traits of traits being applied in the same
200
+ * way. Thus for the most part, application of traits is a post-order graph traversal
201
+ * problem.
202
+ *
203
+ * A trait is only ever processed once. If multiple traits (A, B, C) have the same
204
+ * trait (D) as a dependency, D will be included only once when first encountered by
205
+ * A.
206
+ *
207
+ * If a cycle exists such that trait A has trait B which has Trait A, trait A will
208
+ * be applied *after* trait B in production. In development a cycle error will be thrown.
209
+ *
210
+ * Fields are finalized on a "last wins principle". Thus traits appearing higher in
211
+ * the tree and further to the right of a traits array take precedence, with the
212
+ * resource's fields always being applied last and winning out.
213
+ *
214
+ * @public
215
+ */
216
+ registerTrait(trait: Trait): void;
224
217
  registerTransformation<
225
218
  T extends Value = string,
226
219
  PT = unknown
@@ -231,39 +224,28 @@ export declare class SchemaService implements SchemaServiceInterface {
231
224
  FM extends ObjectValue | null
232
225
  >(derivation: Derivation<R, T, FM>): void;
233
226
  CAUTION_MEGA_DANGER_ZONE_registerExtension(extension: CAUTION_MEGA_DANGER_ZONE_Extension): void;
234
- CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: StableRecordIdentifier | {
227
+ CAUTION_MEGA_DANGER_ZONE_resourceExtensions(resource: ResourceKey | {
235
228
  type: string;
236
229
  }): null | ProcessedExtension["features"];
237
- CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
230
+ CAUTION_MEGA_DANGER_ZONE_objectExtensions(field: ExtensibleField, resolvedType: string | null): null | ProcessedExtension["features"];
238
231
  CAUTION_MEGA_DANGER_ZONE_arrayExtensions(field: ExtensibleField): null | ProcessedExtension["features"];
232
+ CAUTION_MEGA_DANGER_ZONE_hasExtension(ext: {
233
+ kind: "object" | "array";
234
+ name: string;
235
+ }): boolean;
239
236
  /**
240
- * This is an internal method used to register behaviors for legacy mode.
241
- * It is not intended for public use.
242
- *
243
- * We do think a generalized `kind` registration system would be useful,
244
- * but we have not yet designed it.
245
- *
246
- * See https://github.com/emberjs/data/issues/9534
247
- *
248
- * @internal
249
- */
250
- _registerMode(mode: string, kinds: KindFns): void;
251
- /**
252
- * This is an internal method used to enable legacy behaviors for legacy mode.
253
- * It is not intended for public use.
254
- *
255
- * We do think a generalized `kind` registration system would be useful,
256
- * but we have not yet designed it.
237
+ * Registers a {@link HashFn} for use with a {@link HashField} for
238
+ * either {@link ObjectSchema} identity or polymorphic type calculation.
257
239
  *
258
- * See https://github.com/emberjs/data/issues/9534
259
- *
260
- * @internal
240
+ * @public
261
241
  */
262
- _kind<T extends keyof KindFns>(mode: string, kind: T): KindFns[T];
263
242
  registerHashFn<T extends object>(hashFn: HashFn<T>): void;
264
243
  fields({ type }: {
265
244
  type: string;
266
245
  }): InternalSchema["fields"];
246
+ cacheFields({ type }: {
247
+ type: string;
248
+ }): InternalSchema["cacheFields"];
267
249
  hasResource(resource: {
268
250
  type: string;
269
251
  }): boolean;