@warp-drive/core 5.7.0-alpha.9 → 5.7.0-beta.0

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 (103) 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 +2 -2
  16. package/declarations/reactive/-private/document.d.ts +11 -27
  17. package/declarations/reactive/-private/fields/managed-array.d.ts +4 -6
  18. package/declarations/reactive/-private/fields/managed-object.d.ts +2 -8
  19. package/declarations/reactive/-private/fields/many-array-manager.d.ts +2 -2
  20. package/declarations/reactive/-private/hooks.d.ts +2 -2
  21. package/declarations/reactive/-private/record.d.ts +42 -30
  22. package/declarations/reactive/-private/schema.d.ts +11 -73
  23. package/declarations/reactive/-private/symbols.d.ts +2 -33
  24. package/declarations/reactive/-private.d.ts +1 -1
  25. package/declarations/reactive.d.ts +277 -1
  26. package/declarations/request/-private/context.d.ts +3 -5
  27. package/declarations/request/-private/fetch.d.ts +2 -2
  28. package/declarations/request/-private/manager.d.ts +24 -28
  29. package/declarations/request/-private/types.d.ts +22 -24
  30. package/declarations/request/-private/utils.d.ts +44 -2
  31. package/declarations/store/-private/cache-handler/handler.d.ts +2 -8
  32. package/declarations/store/-private/cache-handler/types.d.ts +10 -10
  33. package/declarations/store/-private/cache-handler/utils.d.ts +4 -5
  34. package/declarations/store/-private/caches/instance-cache.d.ts +21 -20
  35. package/declarations/store/-private/debug/utils.d.ts +1 -0
  36. package/declarations/store/-private/default-cache-policy.d.ts +25 -40
  37. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +24 -15
  38. package/declarations/store/-private/{caches/identifier-cache.d.ts → managers/cache-key-manager.d.ts} +35 -53
  39. package/declarations/store/-private/managers/cache-manager.d.ts +46 -111
  40. package/declarations/store/-private/managers/notification-manager.d.ts +30 -45
  41. package/declarations/store/-private/managers/record-array-manager.d.ts +44 -41
  42. package/declarations/store/-private/network/request-cache.d.ts +21 -25
  43. package/declarations/store/-private/new-core-tmp/expensive-subscription.d.ts +24 -0
  44. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +3 -41
  45. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +14 -29
  46. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +24 -3
  47. package/declarations/store/-private/new-core-tmp/request-state.d.ts +132 -37
  48. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +51 -135
  49. package/declarations/store/-private/record-arrays/-utils.d.ts +80 -0
  50. package/declarations/store/-private/record-arrays/legacy-live-array.d.ts +81 -0
  51. package/declarations/store/-private/record-arrays/legacy-many-array.d.ts +133 -0
  52. package/declarations/store/-private/record-arrays/legacy-query.d.ts +81 -0
  53. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +1 -124
  54. package/declarations/store/-private/record-arrays/resource-array.d.ts +67 -0
  55. package/declarations/store/-private/store-service.d.ts +156 -106
  56. package/declarations/store/-private/utils/coerce-id.d.ts +0 -6
  57. package/declarations/store/-private.d.ts +11 -13
  58. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +15 -24
  59. package/declarations/store/-types/q/identifier.d.ts +9 -6
  60. package/declarations/store/-types/q/record-instance.d.ts +0 -1
  61. package/declarations/store/-types/q/schema-service.d.ts +9 -9
  62. package/declarations/store/-types/q/store.d.ts +6 -7
  63. package/declarations/store/deprecated/-private.d.ts +12 -24
  64. package/declarations/store/deprecated/store.d.ts +11 -16
  65. package/declarations/types/-private.d.ts +1 -1
  66. package/declarations/types/cache/aliases.d.ts +0 -11
  67. package/declarations/types/cache/change.d.ts +2 -2
  68. package/declarations/types/cache/mutations.d.ts +13 -37
  69. package/declarations/types/cache/operations.d.ts +115 -32
  70. package/declarations/types/cache/relationship.d.ts +4 -7
  71. package/declarations/types/cache.d.ts +51 -125
  72. package/declarations/types/graph.d.ts +12 -12
  73. package/declarations/types/identifier.d.ts +52 -78
  74. package/declarations/types/params.d.ts +2 -3
  75. package/declarations/types/request.d.ts +66 -42
  76. package/declarations/types/schema/concepts.d.ts +2 -2
  77. package/declarations/types/schema/fields.d.ts +30 -3
  78. package/declarations/types/spec/document.d.ts +6 -10
  79. package/declarations/types/spec/json-api-raw.d.ts +6 -9
  80. package/declarations/types.d.ts +0 -1
  81. package/declarations/utils/string.d.ts +2 -3
  82. package/dist/{configure-B48bFHOl.js → configure-C3x8YXzL.js} +5 -5
  83. package/dist/configure.js +1 -1
  84. package/dist/{context-COmAnXUQ.js → context-C_7OLieY.js} +48 -6
  85. package/dist/graph/-private.js +137 -144
  86. package/dist/index.js +25 -14
  87. package/dist/reactive/-private.js +1 -1
  88. package/dist/reactive.js +144 -1926
  89. package/dist/{request-state-CeN66aML.js → request-state-C955e0AL.js} +5968 -3033
  90. package/dist/request.js +1 -1
  91. package/dist/store/-private.js +2 -3
  92. package/dist/store.js +32 -44
  93. package/dist/{symbols-SIstXMLI.js → symbols-sql1_mdx.js} +3 -8
  94. package/dist/types/-private.js +1 -1
  95. package/dist/types/identifier.js +19 -45
  96. package/dist/types/request.js +45 -3
  97. package/dist/types/schema/fields.js +6 -0
  98. package/dist/utils/string.js +2 -2
  99. package/package.json +11 -11
  100. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  101. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  102. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  103. package/dist/handler-SdXlte1w.js +0 -339
@@ -3,14 +3,22 @@ import type { Future } from "../../../request.js";
3
3
  import type { StructuredErrorDocument } from "../../../types/request.js";
4
4
  import type { RequestState } from "../../-private.js";
5
5
  export declare const DISPOSE: "(symbol) dispose";
6
- interface ErrorFeatures {
7
- isHidden: boolean;
6
+ export type AutorefreshBehaviorType = "online" | "interval" | "invalid";
7
+ export type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
8
+ /**
9
+ * Utilities to assist in recovering from the error.
10
+ */
11
+ export interface RecoveryFeatures {
8
12
  isOnline: boolean;
13
+ isHidden: boolean;
9
14
  retry: () => Promise<void>;
10
15
  }
11
- type AutorefreshBehaviorType = "online" | "interval" | "invalid";
12
- type AutorefreshBehaviorCombos = boolean | AutorefreshBehaviorType | `${AutorefreshBehaviorType},${AutorefreshBehaviorType}` | `${AutorefreshBehaviorType},${AutorefreshBehaviorType},${AutorefreshBehaviorType}`;
13
- type ContentFeatures<RT> = {
16
+ /** @deprecated use {@link RecoveryFeatures} */
17
+ export type ErrorFeatures = RecoveryFeatures;
18
+ /**
19
+ * Utilities for keeping the request fresh
20
+ */
21
+ export interface ContentFeatures<RT> {
14
22
  isOnline: boolean;
15
23
  isHidden: boolean;
16
24
  isRefreshing: boolean;
@@ -18,11 +26,24 @@ type ContentFeatures<RT> = {
18
26
  reload: () => Promise<void>;
19
27
  abort?: () => void;
20
28
  latestRequest?: Future<RT>;
21
- };
22
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ }
30
+ export interface RequestArgs<
31
+ RT,
32
+ E
33
+ > extends SubscriptionArgs<RT, E> {
34
+ subscription?: RequestSubscription<RT, E>;
35
+ /**
36
+ * The store instance to use for making requests. If contexts are available,
37
+ * the component will default to using the `store` on the context.
38
+ *
39
+ * This is required if the store is not available via context or should be
40
+ * different from the store provided via context.
41
+ *
42
+ */
43
+ store?: Store | RequestManager;
44
+ }
23
45
  export interface SubscriptionArgs<
24
46
  RT,
25
- T,
26
47
  E
27
48
  > {
28
49
  /**
@@ -30,14 +51,14 @@ export interface SubscriptionArgs<
30
51
  * by either the `store.request` or `store.requestManager.request` methods.
31
52
  *
32
53
  */
33
- request?: Future<RT>;
54
+ request?: Future<RT> | undefined | null;
34
55
  /**
35
56
  * A query to use for the request. This should be an object that can be
36
57
  * passed to `store.request`. Use this in place of `@request` if you would
37
58
  * like the component to also initiate the request.
38
59
  *
39
60
  */
40
- query?: StoreRequestInput<RT, T>;
61
+ query?: StoreRequestInput<RT> | undefined | null;
41
62
  /**
42
63
  * The autorefresh behavior for the request. This can be a boolean, or any
43
64
  * combination of the following values: `'online'`, `'interval'`, `'invalid'`.
@@ -77,10 +98,22 @@ export interface SubscriptionArgs<
77
98
  */
78
99
  autorefreshBehavior?: "refresh" | "reload" | "policy";
79
100
  }
80
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
101
+ export interface RequestComponentArgs<
102
+ RT,
103
+ E
104
+ > extends SubscriptionArgs<RT, E> {
105
+ /**
106
+ * The store instance to use for making requests. If contexts are available,
107
+ * the component will default to using the `store` on the context.
108
+ *
109
+ * This is required if the store is not available via context or should be
110
+ * different from the store provided via context.
111
+ *
112
+ */
113
+ store?: Store | RequestManager;
114
+ }
81
115
  export interface RequestSubscription<
82
116
  RT,
83
- T,
84
117
  E
85
118
  > {
86
119
  /**
@@ -96,7 +129,6 @@ export interface RequestSubscription<
96
129
  */
97
130
  export declare class RequestSubscription<
98
131
  RT,
99
- T,
100
132
  E
101
133
  > {
102
134
  /**
@@ -112,123 +144,13 @@ export declare class RequestSubscription<
112
144
  */
113
145
  isRefreshing: boolean;
114
146
  /**
115
- * The most recent blocking request that was made, typically
116
- * the result of a reload.
117
- *
118
- * This will never be the original request passed as an arg to
119
- * the component.
120
- *
121
- * @internal
122
- */
123
- private _localRequest;
124
- /**
125
- * The most recent request that was made, typically due to either a
126
- * reload or a refresh.
127
- *
128
- * This will never be the original request passed as an arg to
129
- * the component.
130
- *
131
- * @internal
132
- */
133
- private _latestRequest;
134
- /**
135
- * The time at which the network was reported as offline.
136
- *
137
- * @internal
138
- */
139
- private _unavailableStart;
140
- /** @internal */
141
- private _intervalStart;
142
- /** @internal */
143
- private _nextInterval;
144
- /** @internal */
145
- private _invalidated;
146
- /** @internal */
147
- private _isUpdating;
148
- /** @internal */
149
- private isDestroyed;
150
- /**
151
- * The event listener for network status changes,
152
- * cached to use the reference for removal.
153
- *
154
- * @internal
147
+ * The Store this subscription subscribes to or the RequestManager
148
+ * which issues this request.
155
149
  */
156
- private _onlineChanged;
157
- /**
158
- * The event listener for visibility status changes,
159
- * cached to use the reference for removal.
160
- *
161
- * @internal
162
- */
163
- private _backgroundChanged;
164
- /**
165
- * The last request passed as an arg to the component,
166
- * cached for comparison.
167
- *
168
- * @internal
169
- */
170
- private _originalRequest;
171
- /**
172
- * The last query passed as an arg to the component,
173
- * cached for comparison.
174
- *
175
- * @internal
176
- */
177
- private _originalQuery;
178
- /** @internal */
179
- private _subscription;
180
- /** @internal */
181
- private _subscribedTo;
182
- /** @internal */
183
- private _args;
184
- /** @internal */
185
150
  store: Store | RequestManager;
186
- constructor(store: Store | RequestManager, args: SubscriptionArgs<RT, T, E>);
187
- /**
188
- * @internal
189
- */
190
- private _beginPolling;
151
+ constructor(store: Store | RequestManager, args: SubscriptionArgs<RT, E>);
191
152
  get isIdle(): boolean;
192
153
  get autorefreshTypes(): Set<AutorefreshBehaviorType>;
193
- // we only run this function on component creation
194
- // and when an update is triggered, so it does not
195
- // react to changes in the autorefreshThreshold
196
- // or autorefresh args.
197
- //
198
- // if we need to react to those changes, we can
199
- // use a modifier or internal component or some
200
- // such to trigger a re-run of this function.
201
- private _scheduleInterval;
202
- private _clearInterval;
203
- /**
204
- * @internal
205
- */
206
- private _updateSubscriptions;
207
- /**
208
- * @internal
209
- */
210
- private _removeSubscriptions;
211
- /**
212
- * Install the event listeners for network and visibility changes.
213
- * This is only done in browser environments with a global `window`.
214
- *
215
- * @internal
216
- */
217
- private _installListeners;
218
- /**
219
- * If the network is online and the tab is visible, either reload or refresh the request
220
- * based on the component's configuration and the requested update mode.
221
- *
222
- * Valid modes are:
223
- *
224
- * - `'reload'`: Force a reload of the request.
225
- * - `'refresh'`: Refresh the request in the background.
226
- * - `'policy'`: Make the request, letting the store's configured CachePolicy decide whether to reload, refresh, or do nothing.
227
- * - `undefined`: Make the request using the component's autorefreshBehavior setting if the autorefreshThreshold has passed.
228
- *
229
- * @internal
230
- */
231
- private _maybeUpdate;
232
154
  /**
233
155
  * Retry the request, reloading it from the server.
234
156
  */
@@ -240,22 +162,16 @@ export declare class RequestSubscription<
240
162
  /**
241
163
  * features to yield to the error slot of a component
242
164
  */
243
- get errorFeatures(): ErrorFeatures;
165
+ get errorFeatures(): RecoveryFeatures;
244
166
  /**
245
167
  * features to yield to the content slot of a component
246
168
  */
247
169
  get contentFeatures(): ContentFeatures<RT>;
248
- /**
249
- * @internal
250
- */
251
- get _request(): Future<RT>;
252
170
  get request(): Future<RT>;
253
- get reqState(): RequestState<RT, T, StructuredErrorDocument<E>>;
171
+ get reqState(): RequestState<RT, StructuredErrorDocument<E>>;
254
172
  get result(): RT;
255
173
  }
256
174
  export declare function createRequestSubscription<
257
175
  RT,
258
- T,
259
176
  E
260
- >(store: Store | RequestManager, args: SubscriptionArgs<RT, T, E>): RequestSubscription<RT, T, E>;
261
- export {};
177
+ >(store: Store | RequestManager, args: SubscriptionArgs<RT, E>): RequestSubscription<RT, E>;
@@ -0,0 +1,80 @@
1
+ import type { BaseFinderOptions } from "../../../types.js";
2
+ import type { LocalRelationshipOperation } from "../../../types/graph.js";
3
+ import type { ResourceKey } from "../../../types/identifier.js";
4
+ import type { Store } from "../store-service.js";
5
+ import type { NativeProxy } from "./native-proxy-type-fix.js";
6
+ import type { ReactiveResourceArray } from "./resource-array.js";
7
+ /**
8
+ * LegacyArrays have the capability of updating via `array.update()`
9
+ * and saving each contained record individually via `array.save()`
10
+ */
11
+ export interface LegacyArray<T = unknown> extends ReactiveResourceArray<T> {
12
+ /**
13
+ The flag to signal a `RecordArray` is currently loading data.
14
+ Example
15
+ ```javascript
16
+ let people = store.peekAll('person');
17
+ people.isUpdating; // false
18
+ people.update();
19
+ people.isUpdating; // true
20
+ ```
21
+ */
22
+ isUpdating: boolean;
23
+ /**
24
+ Used to get the latest version of all of the records in this array
25
+ from the adapter.
26
+
27
+ Example
28
+
29
+ ```javascript
30
+ let people = store.peekAll('person');
31
+ people.isUpdating; // false
32
+
33
+ people.update().then(function() {
34
+ people.isUpdating; // false
35
+ });
36
+
37
+ people.isUpdating; // true
38
+ ```
39
+
40
+ @public
41
+ */
42
+ update(this: LegacyArray<T>): Promise<LegacyArray<T>>;
43
+ /**
44
+ Saves all of the records in the `RecordArray`.
45
+
46
+ Example
47
+
48
+ ```js
49
+ let messages = store.peekAll('message');
50
+ messages.forEach(function(message) {
51
+ message.hasBeenSeen = true;
52
+ });
53
+ messages.save();
54
+ ```
55
+
56
+ @public
57
+ */
58
+ save(this: LegacyArray<T>): Promise<LegacyArray<T>>;
59
+ }
60
+ export declare function upgradeThis(obj: unknown): asserts obj is LegacyArray;
61
+ export declare function update(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
62
+ export declare function save(this: ReactiveResourceArray): Promise<ReactiveResourceArray>;
63
+ export type KeyType = string | symbol | number;
64
+ export declare function isArrayGetter<T>(prop: KeyType): prop is keyof Array<T>;
65
+ export declare function isArraySetter<T>(prop: KeyType): prop is keyof Array<T>;
66
+ export declare function convertToInt(prop: KeyType): number | null;
67
+ export type ForEachCB<T> = (record: T, index: number, context: typeof NativeProxy<ResourceKey[], T[]>) => void;
68
+ export declare function safeForEach<T>(instance: typeof NativeProxy<ResourceKey[], T[]>, arr: ResourceKey[], store: Store, callback: ForEachCB<T>, target: unknown): typeof NativeProxy<ResourceKey[], T[]>;
69
+ type PromiseTo<T> = Omit<Promise<T>, typeof Symbol.toStringTag>;
70
+ type PromiseManyArray<T> = {
71
+ length: number;
72
+ content: ReactiveResourceArray<T> | null;
73
+ promise: Promise<ReactiveResourceArray<T>> | null;
74
+ } & PromiseTo<ReactiveResourceArray<T>>;
75
+ export interface MinimumManager {
76
+ _syncArray(array: ReactiveResourceArray): void;
77
+ mutate?(mutation: LocalRelationshipOperation): void;
78
+ reloadHasMany?<T>(key: string, options?: BaseFinderOptions): Promise<ReactiveResourceArray> | PromiseManyArray<T>;
79
+ }
80
+ export {};
@@ -0,0 +1,81 @@
1
+ import type { ResourceKey } from "../../../types/identifier.js";
2
+ import type { TypeFromInstanceOrString } from "../../../types/record.js";
3
+ import type { Store } from "../store-service.js";
4
+ import type { LegacyArray, MinimumManager } from "./-utils.js";
5
+ /**
6
+ * LiveArrays contain all the known records for a given `ResourceType`.
7
+ *
8
+ * ### Basic Example
9
+ *
10
+ * For instance, if an application were to have a `'user'` type:
11
+ *
12
+ * ```ts
13
+ * const usersLiveArray = store.peekAll('user');
14
+ * ```
15
+ *
16
+ * ---
17
+ *
18
+ * &nbsp;
19
+ *
20
+ * ### LiveArrays are Arrays
21
+ *
22
+ * LiveArrays have all array APIs, and will report `true`
23
+ * for both `liveArray instanceof Array` and `Array.isArray(liveArray)`
24
+ *
25
+ * ---
26
+ *
27
+ * &nbsp;
28
+ *
29
+ * ### Reactive
30
+ *
31
+ * The array is "live" as it will reactively update any time new
32
+ * users are added to the store's cache.
33
+ *
34
+ * There is only one LiveArray instance per ResourceType, and it
35
+ * can be accessed either via {@link Store.peekAll} or {@link Store.findAll}
36
+ *
37
+ * ```ts
38
+ * const users = await store.findAll('user');
39
+ * const peekedUsers = store.peekAll('user');
40
+ * peekedUsers === users; // true
41
+ * ```
42
+ *
43
+ * ---
44
+ *
45
+ * &nbsp;
46
+ *
47
+ * ### New Records
48
+ *
49
+ * Records in the `"new"` state (created locally on the client
50
+ * but not yet saved) appear in LiveArrays if they are in LegacyMode.
51
+ *
52
+ * PolarisMode records in the `"new"` state do not appear in LiveArrays.
53
+ *
54
+ * ---
55
+ *
56
+ * &nbsp;
57
+ *
58
+ * ### Polymorphism
59
+ *
60
+ * LiveArrays are not polymorphic. If your application has an abstract
61
+ * type "car" with concrete types "ferrari" and "bmw", then "ferrari"
62
+ * and "bmw" will have populated LiveArrays, but the LiveArray for "car"
63
+ * would be empty.
64
+ *
65
+ * @legacy we recommend againt using LiveArrays. Use {@link Store.request} instead
66
+ */
67
+ export interface LegacyLiveArray<T = unknown> extends LegacyArray<T> {
68
+ isLoaded: boolean;
69
+ modelName: TypeFromInstanceOrString<T>;
70
+ }
71
+ /**
72
+ * The options for {@link createLegacyLiveArray}
73
+ *
74
+ * @private
75
+ */
76
+ export interface LegacyLiveArrayCreateOptions {
77
+ store: Store;
78
+ manager: MinimumManager;
79
+ source: ResourceKey[];
80
+ type: string;
81
+ }
@@ -0,0 +1,133 @@
1
+ import type { BaseFinderOptions, ResourceKey } from "../../../types.js";
2
+ import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
3
+ import type { LegacyHasManyField, LinksModeHasManyField } from "../../../types/schema/fields.js";
4
+ import type { Links, Meta, PaginationLinks } from "../../../types/spec/json-api-raw.js";
5
+ import type { CreateRecordProperties } from "../store-service.js";
6
+ import type { LegacyLiveArrayCreateOptions } from "./legacy-live-array.js";
7
+ import { type ReactiveResourceArray } from "./resource-array.js";
8
+ /**
9
+ A `ManyArray` is a `MutableArray` that represents the contents of a has-many
10
+ relationship.
11
+
12
+ The `ManyArray` is instantiated lazily the first time the relationship is
13
+ requested.
14
+
15
+ This class is not intended to be directly instantiated by consuming applications.
16
+
17
+ ### Inverses
18
+
19
+ Often, the relationships in Ember Data applications will have
20
+ an inverse. For example, imagine the following models are
21
+ defined:
22
+
23
+ ```js [app/models/post.js]
24
+ import Model, { hasMany } from '@ember-data/model';
25
+
26
+ export default class PostModel extends Model {
27
+ @hasMany('comment') comments;
28
+ }
29
+ ```
30
+
31
+ ```js [app/models/comment.js]
32
+ import { Model, belongsTo } from '@warp-drive/legacy/model';
33
+
34
+ export default class CommentModel extends Model {
35
+ @belongsTo('post') post;
36
+ }
37
+ ```
38
+
39
+ If you created a new instance of `Post` and added
40
+ a `Comment` record to its `comments` has-many
41
+ relationship, you would expect the comment's `post`
42
+ property to be set to the post that contained
43
+ the has-many.
44
+
45
+ We call the record to which a relationship belongs-to the
46
+ relationship's _owner_.
47
+
48
+ @public
49
+ */
50
+ export interface LegacyManyArray<T = unknown> extends ReactiveResourceArray<T> {
51
+ meta: Meta | null;
52
+ links: Links | PaginationLinks | null;
53
+ /** @private */
54
+ key: string;
55
+ /** @private */
56
+ modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
57
+ /**
58
+ The loading state of this array
59
+ @public
60
+ */
61
+ isLoaded: boolean;
62
+ /**
63
+ Reloads all of the records in the manyArray. If the manyArray
64
+ holds a relationship that was originally fetched using a links url
65
+ WarpDrive will revisit the original links url to repopulate the
66
+ relationship.
67
+
68
+ If the ManyArray holds the result of a `store.query()` reload will
69
+ re-run the original query.
70
+
71
+ Example
72
+
73
+ ```javascript
74
+ let user = store.peekRecord('user', '1')
75
+ await login(user);
76
+
77
+ let permissions = await user.permissions;
78
+ await permissions.reload();
79
+ ```
80
+
81
+ @public
82
+ */
83
+ reload(options?: BaseFinderOptions): Promise<LegacyManyArray<T>>;
84
+ /**
85
+ Create a child record and associated it to the collection
86
+
87
+ @public
88
+ */
89
+ createRecord(hash: CreateRecordProperties<T>): T;
90
+ /**
91
+ Saves all of the records in the `ManyArray`.
92
+
93
+ Note: this API can only be used in legacy mode with a configured Adapter.
94
+
95
+ Example
96
+
97
+ ```js
98
+ const { content: { data: inbox } } = await store.request(findRecord({ type: 'inbox', id: '1' }));
99
+
100
+ let messages = await inbox.messages;
101
+ messages.forEach((message) => {
102
+ message.isRead = true;
103
+ });
104
+ messages.save();
105
+ ```
106
+
107
+ @public
108
+ */
109
+ save: () => Promise<LegacyManyArray<T>>;
110
+ /** @private */
111
+ destroy: () => void;
112
+ }
113
+ /**
114
+ * The options for {@link createLegacyManyArray}
115
+ *
116
+ * @private
117
+ */
118
+ export interface LegacyManyArrayCreateOptions extends LegacyLiveArrayCreateOptions {
119
+ isLoaded: boolean;
120
+ editable: boolean;
121
+ isAsync: boolean;
122
+ isPolymorphic: boolean;
123
+ field: LegacyHasManyField | LinksModeHasManyField;
124
+ identifier: ResourceKey;
125
+ links: Links | PaginationLinks | null;
126
+ meta: Meta | null;
127
+ }
128
+ /**
129
+ * Creates a {@link LegacyManyArray}
130
+ *
131
+ * @private
132
+ */
133
+ export declare function createLegacyManyArray<T>(options: LegacyManyArrayCreateOptions): LegacyManyArray<T>;
@@ -0,0 +1,81 @@
1
+ import type { ImmutableRequestInfo } from "../../../types/request.js";
2
+ import type { Links, Meta, PaginationLinks } from "../../../types/spec/json-api-raw.js";
3
+ import type { LegacyLiveArray } from "./legacy-live-array.js";
4
+ /**
5
+ * QueryArrays contain the primary records returned when querying
6
+ * for records by `ResourceType`.
7
+ *
8
+ * ### Basic Example
9
+ *
10
+ * For instance, if an application were to have a `'user'` type:
11
+ *
12
+ * ```ts
13
+ * const users = await store.query('user', { name: 'Chris' });
14
+ * ```
15
+ *
16
+ * ---
17
+ *
18
+ * &nbsp;
19
+ *
20
+ * ### QueryArrays are Arrays
21
+ *
22
+ * QueryArrays have all array APIs, and will report `true`
23
+ * for both `queryArray instanceof Array` and `Array.isArray(queryArray)`
24
+ *
25
+ * However, any mutation of the array will throw an error.
26
+ *
27
+ * ---
28
+ *
29
+ * &nbsp;
30
+ *
31
+ * ### Reactive
32
+ *
33
+ * If a record in a QueryArray is deleted and unloaded, it will be
34
+ * automatically removed from the array.
35
+ *
36
+ * ---
37
+ *
38
+ * &nbsp;
39
+ *
40
+ * ### Immutable
41
+ *
42
+ * Records cannot be directly added to or removed from a QueryArray.
43
+ *
44
+ * ---
45
+ *
46
+ * &nbsp;
47
+ *
48
+ * ### Polymorphism
49
+ *
50
+ * QueryArrays are not intended to be polymorphic. If your application has
51
+ * an abstract type "car" with concrete types "ferrari" and "bmw", a query
52
+ * which returns primary data containing both ferraris and bmws will *likely*
53
+ * work, but it is not guaranteed.
54
+ *
55
+ * In contrast, the {@link ReactiveResourceArray} returned when using {@link Store.request}
56
+ * is guaranteed to work with polymorphic responses.
57
+ *
58
+ * ---
59
+ *
60
+ * &nbsp;
61
+ *
62
+ * ### Memory Leaks
63
+ *
64
+ * QueryArrays are meant to be long lived. They can be refreshed using
65
+ * `array.update()`, and destroyed via `array.destroy()`.
66
+ *
67
+ * Unlike most Reactive state in WarpDrive, applications must choose to call
68
+ * `destroy` when the `QueryArray` is no longer needed, else the array instance
69
+ * will be retained until either the application or the store which created it
70
+ * are destroyed. Destroying a QueryArray does not remove its records
71
+ * from the cache, but it does remove the array as well as the overhead it requires
72
+ * from the store for book-keeping.
73
+ *
74
+ * @legacy we recommend againt using QueryArrays. Use {@link Store.request} instead
75
+ */
76
+ export interface LegacyQueryArray<T = unknown> extends LegacyLiveArray<T> {
77
+ query: ImmutableRequestInfo | Record<string, unknown> | null;
78
+ destroy(): void;
79
+ links: PaginationLinks | Links | null;
80
+ meta: Meta | null;
81
+ }