@warp-drive/core 5.7.0-alpha.0 → 5.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/reactive/-private/schema.d.ts +42 -2
- package/declarations/store/-private/caches/instance-cache.d.ts +1 -8
- package/declarations/store/-private/store-service.d.ts +17 -777
- package/declarations/store/-private.d.ts +3 -2
- package/declarations/store/-types/q/schema-service.d.ts +37 -1
- package/declarations/store/deprecated/-private.d.ts +235 -0
- package/declarations/store/deprecated/store.d.ts +788 -0
- package/declarations/types/cache.d.ts +0 -2
- package/declarations/types/schema/fields.d.ts +13 -0
- package/declarations/types.d.ts +2 -1
- package/dist/graph/-private.js +1 -1
- package/dist/{handler-C2T-IyJK.js → handler-D2jjnIA-.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/reactive.js +135 -10
- package/dist/{request-state-CjLph1LP.js → request-state-CejVJgdj.js} +839 -1336
- package/dist/store/-private.js +2 -2
- package/dist/types/-private.js +1 -1
- package/package.json +3 -3
- package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
- package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
- package/declarations/store/-types/q/ds-model.d.ts +0 -21
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Store
|
|
1
|
+
export { Store } from "./deprecated/store.js";
|
|
2
|
+
export { storeFor } from "./-private/store-service.js";
|
|
2
3
|
export { recordIdentifierFor } from "./-private/caches/instance-cache.js";
|
|
3
4
|
export { CacheHandler, type StoreRequestContext } from "./-private/cache-handler/handler.js";
|
|
4
5
|
export { type CachePolicy } from "./-private/cache-handler/types.js";
|
|
@@ -27,5 +28,5 @@ export { getPromiseState, type PromiseState } from "./-private/new-core-tmp/prom
|
|
|
27
28
|
export { DISPOSE, createRequestSubscription, type SubscriptionArgs, type RequestSubscription } from "./-private/new-core-tmp/request-subscription.js";
|
|
28
29
|
export { getRequestState, type RequestLoadingState, type RequestCacheRequestState as RequestState } from "./-private/new-core-tmp/request-state.js";
|
|
29
30
|
export { createMemo, type SignalHooks, waitFor } from "./-private/new-core-tmp/reactivity/configure.js";
|
|
30
|
-
export { memoized, gate, entangleSignal, defineSignal, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
|
|
31
|
+
export { memoized, gate, entangleSignal, defineSignal, defineGate, defineNonEnumerableSignal } from "./-private/new-core-tmp/reactivity/signal.js";
|
|
31
32
|
export { ARRAY_SIGNAL, OBJECT_SIGNAL, Signals, type WarpDriveSignal, peekInternalSignal, withSignalStore, notifyInternalSignal, consumeInternalSignal, getOrCreateInternalSignal } from "./-private/new-core-tmp/reactivity/internal.js";
|
|
@@ -3,7 +3,7 @@ import type { ExtensibleField } from "../../../reactive/-private/schema.js";
|
|
|
3
3
|
import type { RecordIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
|
|
4
4
|
import type { ObjectValue } from "../../../types/json/raw.js";
|
|
5
5
|
import type { Derivation, HashFn, Transformation } from "../../../types/schema/concepts.js";
|
|
6
|
-
import type { ArrayField, DerivedField, FieldSchema, GenericField, HashField, LegacyAttributeField, LegacyRelationshipField, ObjectField, Schema } from "../../../types/schema/fields.js";
|
|
6
|
+
import type { ArrayField, DerivedField, FieldSchema, GenericField, HashField, LegacyAttributeField, LegacyRelationshipField, ObjectField, Schema, Trait } from "../../../types/schema/fields.js";
|
|
7
7
|
export type AttributesSchema = Record<string, LegacyAttributeField>;
|
|
8
8
|
export type RelationshipsSchema = Record<string, LegacyRelationshipField>;
|
|
9
9
|
interface ObjectWithStringTypeProperty {
|
|
@@ -201,6 +201,35 @@ export interface SchemaService {
|
|
|
201
201
|
*/
|
|
202
202
|
registerHashFn(hashFn: HashFn): void;
|
|
203
203
|
/**
|
|
204
|
+
* Registers a {@link Trait} for use by resource schemas.
|
|
205
|
+
*
|
|
206
|
+
* Traits are re-usable collections of fields that can be composed to
|
|
207
|
+
* build up a resource schema. Often they represent polymorphic behaviors
|
|
208
|
+
* a resource should exhibit.
|
|
209
|
+
*
|
|
210
|
+
* When we finalize a resource, we walk its traits and apply their fields
|
|
211
|
+
* to the resource's fields. All specified traits must be registered by
|
|
212
|
+
* this time or an error will be thrown.
|
|
213
|
+
*
|
|
214
|
+
* Traits are applied left-to-right, with traits of traits being applied in the same
|
|
215
|
+
* way. Thus for the most part, application of traits is a post-order graph traversal
|
|
216
|
+
* problem.
|
|
217
|
+
*
|
|
218
|
+
* A trait is only ever processed once. If multiple traits (A, B, C) have the same
|
|
219
|
+
* trait (D) as a dependency, D will be included only once when first encountered by
|
|
220
|
+
* A.
|
|
221
|
+
*
|
|
222
|
+
* If a cycle exists such that trait A has trait B which has Trait A, trait A will
|
|
223
|
+
* be applied *after* trait B in production. In development a cycle error will be thrown.
|
|
224
|
+
*
|
|
225
|
+
* Fields are finalized on a "last wins principle". Thus traits appearing higher in
|
|
226
|
+
* the tree and further to the right of a traits array take precedence, with the
|
|
227
|
+
* resource's fields always being applied last and winning out.
|
|
228
|
+
*
|
|
229
|
+
* @public
|
|
230
|
+
*/
|
|
231
|
+
registerTrait?(trait: Trait): void;
|
|
232
|
+
/**
|
|
204
233
|
* DEPRECATED - use `fields` instead
|
|
205
234
|
*
|
|
206
235
|
* Returns definitions for all properties of the specified resource
|
|
@@ -350,5 +379,12 @@ export interface SchemaService {
|
|
|
350
379
|
* Retrieve the extension map for an array field
|
|
351
380
|
*/
|
|
352
381
|
CAUTION_MEGA_DANGER_ZONE_arrayExtensions?(field: ExtensibleField): null | ProcessedExtension["features"];
|
|
382
|
+
/**
|
|
383
|
+
* Check if a specific extension has been registered previously
|
|
384
|
+
*/
|
|
385
|
+
CAUTION_MEGA_DANGER_ZONE_hasExtension?(ext: {
|
|
386
|
+
kind: "object" | "array";
|
|
387
|
+
name: string;
|
|
388
|
+
}): boolean;
|
|
353
389
|
}
|
|
354
390
|
export {};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { StableNewRecordIdentifier, StableRecordIdentifier } from "../../types/identifier.js";
|
|
2
|
+
import type { Value } from "../../types/json/raw.js";
|
|
3
|
+
import type { Includes, OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from "../../types/record.js";
|
|
4
|
+
import type { LegacyAttributeField, LegacyRelationshipField } from "../../types/schema/fields.js";
|
|
5
|
+
import type { SingleResourceDocument } from "../../types/spec/json-api-raw.js";
|
|
6
|
+
import { type InstanceCache } from "../-private.js";
|
|
7
|
+
import type { Store } from "./store.js";
|
|
8
|
+
export declare function preloadData(store: Store, identifier: StableNewRecordIdentifier, preload: Record<string, Value>): void;
|
|
9
|
+
export interface BaseFinderOptions<T = unknown> {
|
|
10
|
+
reload?: boolean;
|
|
11
|
+
backgroundReload?: boolean;
|
|
12
|
+
include?: T extends TypedRecordInstance ? Includes<T>[] : string | string[];
|
|
13
|
+
adapterOptions?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface FindRecordOptions<T = unknown> extends BaseFinderOptions<T> {
|
|
16
|
+
/**
|
|
17
|
+
* Data to preload into the store before the request is made.
|
|
18
|
+
* This feature is *highly* discouraged and has no corresponding
|
|
19
|
+
* feature when using builders and handlers.
|
|
20
|
+
*
|
|
21
|
+
* Excepting relationships: the data should be in the form of a
|
|
22
|
+
* JSON object where the keys are fields on the record and the value
|
|
23
|
+
* is the raw value to be added to the cache.
|
|
24
|
+
*
|
|
25
|
+
* Relationships can either be provided as string IDs from which
|
|
26
|
+
* an identifier will be built base upon the relationship's expected
|
|
27
|
+
* resource type, or be record instances from which the identifier
|
|
28
|
+
* will be extracted.
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
preload?: Record<string, Value>;
|
|
32
|
+
}
|
|
33
|
+
export type QueryOptions = { [K in string | "adapterOptions"]? : K extends "adapterOptions" ? Record<string, unknown> : unknown };
|
|
34
|
+
export type FindAllOptions<T = unknown> = BaseFinderOptions<T>;
|
|
35
|
+
export type LegacyResourceQuery<T = unknown> = {
|
|
36
|
+
include?: T extends TypedRecordInstance ? Includes<T>[] : string | string[];
|
|
37
|
+
[key: string]: Value | undefined;
|
|
38
|
+
};
|
|
39
|
+
export type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;
|
|
40
|
+
/**
|
|
41
|
+
* Minimum subset of static schema methods and properties on the
|
|
42
|
+
* "model" class.
|
|
43
|
+
*
|
|
44
|
+
* Only used when using the legacy schema-service implementation
|
|
45
|
+
* for @ember-data/model or when wrapping schema for legacy
|
|
46
|
+
* Adapters/Serializers.
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
49
|
+
export interface ModelSchema<T = unknown> {
|
|
50
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
51
|
+
fields: Map<KeyOrString<T>, "attribute" | "belongsTo" | "hasMany">;
|
|
52
|
+
attributes: Map<KeyOrString<T>, LegacyAttributeField>;
|
|
53
|
+
relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;
|
|
54
|
+
eachAttribute<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void, binding?: T): void;
|
|
55
|
+
eachRelationship<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
|
|
56
|
+
eachTransformedAttribute<K extends KeyOrString<T>>(callback: (this: ModelSchema<T>, key: K, type: string | null) => void, binding?: T): void;
|
|
57
|
+
}
|
|
58
|
+
export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
|
|
59
|
+
/**
|
|
60
|
+
A `RecordReference` is a low-level API that allows users and
|
|
61
|
+
addon authors to perform meta-operations on a record.
|
|
62
|
+
|
|
63
|
+
@hideconstructor
|
|
64
|
+
@public
|
|
65
|
+
*/
|
|
66
|
+
export declare class RecordReference {
|
|
67
|
+
/** @internal */
|
|
68
|
+
private store;
|
|
69
|
+
// unsubscribe token given to us by the notification manager
|
|
70
|
+
/** @internal */
|
|
71
|
+
private ___token;
|
|
72
|
+
/** @internal */
|
|
73
|
+
private ___identifier;
|
|
74
|
+
/** @internal */
|
|
75
|
+
private _ref;
|
|
76
|
+
constructor(store: Store, identifier: StableRecordIdentifier);
|
|
77
|
+
/** @internal */
|
|
78
|
+
destroy(): void;
|
|
79
|
+
get type(): string;
|
|
80
|
+
/**
|
|
81
|
+
The `id` of the record that this reference refers to.
|
|
82
|
+
|
|
83
|
+
Together, the `type` and `id` properties form a composite key for
|
|
84
|
+
the identity map.
|
|
85
|
+
|
|
86
|
+
Example
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
let userRef = store.getReference('user', 1);
|
|
90
|
+
|
|
91
|
+
userRef.id(); // '1'
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
@public
|
|
95
|
+
@return The id of the record.
|
|
96
|
+
*/
|
|
97
|
+
id(): string | null;
|
|
98
|
+
/**
|
|
99
|
+
The `identifier` of the record that this reference refers to.
|
|
100
|
+
|
|
101
|
+
Together, the `type` and `id` properties form a composite key for
|
|
102
|
+
the identity map.
|
|
103
|
+
|
|
104
|
+
Example
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
let userRef = store.getReference('user', 1);
|
|
108
|
+
|
|
109
|
+
userRef.identifier(); // '1'
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
@public
|
|
113
|
+
@return The identifier of the record.
|
|
114
|
+
*/
|
|
115
|
+
identifier(): StableRecordIdentifier;
|
|
116
|
+
/**
|
|
117
|
+
How the reference will be looked up when it is loaded. Currently
|
|
118
|
+
this always returns `identity` to signify that a record will be
|
|
119
|
+
loaded by its `type` and `id`.
|
|
120
|
+
|
|
121
|
+
Example
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
const userRef = store.getReference('user', 1);
|
|
125
|
+
|
|
126
|
+
userRef.remoteType(); // 'identity'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
@public
|
|
130
|
+
*/
|
|
131
|
+
remoteType(): "identity";
|
|
132
|
+
/**
|
|
133
|
+
This API allows you to provide a reference with new data. The
|
|
134
|
+
simplest usage of this API is similar to `store.push`: you provide a
|
|
135
|
+
normalized hash of data and the object represented by the reference
|
|
136
|
+
will update.
|
|
137
|
+
|
|
138
|
+
If you pass a promise to `push`, Ember Data will not ask the adapter
|
|
139
|
+
for the data if another attempt to fetch it is made in the
|
|
140
|
+
interim. When the promise resolves, the underlying object is updated
|
|
141
|
+
with the new data, and the promise returned by *this function* is resolved
|
|
142
|
+
with that object.
|
|
143
|
+
|
|
144
|
+
For example, `recordReference.push(promise)` will be resolved with a
|
|
145
|
+
record.
|
|
146
|
+
|
|
147
|
+
Example
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
let userRef = store.getReference('user', 1);
|
|
151
|
+
|
|
152
|
+
// provide data for reference
|
|
153
|
+
userRef.push({
|
|
154
|
+
data: {
|
|
155
|
+
id: "1",
|
|
156
|
+
type: "user",
|
|
157
|
+
attributes: {
|
|
158
|
+
username: "@user"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}).then(function(user) {
|
|
162
|
+
userRef.value() === user;
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
@public
|
|
167
|
+
@param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one
|
|
168
|
+
@return a promise for the value (record or relationship)
|
|
169
|
+
*/
|
|
170
|
+
push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance>;
|
|
171
|
+
/**
|
|
172
|
+
If the entity referred to by the reference is already loaded, it is
|
|
173
|
+
present as `reference.value`. Otherwise the value returned by this function
|
|
174
|
+
is `null`.
|
|
175
|
+
|
|
176
|
+
Example
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
let userRef = store.getReference('user', 1);
|
|
180
|
+
|
|
181
|
+
userRef.value(); // user
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
@public
|
|
185
|
+
@return the record for this RecordReference
|
|
186
|
+
*/
|
|
187
|
+
value(): OpaqueRecordInstance | null;
|
|
188
|
+
/**
|
|
189
|
+
Triggers a fetch for the backing entity based on its `remoteType`
|
|
190
|
+
(see `remoteType` definitions per reference type).
|
|
191
|
+
|
|
192
|
+
Example
|
|
193
|
+
|
|
194
|
+
```javascript
|
|
195
|
+
let userRef = store.getReference('user', 1);
|
|
196
|
+
|
|
197
|
+
// load user (via store.find)
|
|
198
|
+
userRef.load().then(...)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
@public
|
|
202
|
+
@return the record for this RecordReference
|
|
203
|
+
*/
|
|
204
|
+
load(): Promise<unknown>;
|
|
205
|
+
/**
|
|
206
|
+
Reloads the record if it is already loaded. If the record is not
|
|
207
|
+
loaded it will load the record via `store.findRecord`
|
|
208
|
+
|
|
209
|
+
Example
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
let userRef = store.getReference('user', 1);
|
|
213
|
+
|
|
214
|
+
// or trigger a reload
|
|
215
|
+
userRef.reload().then(...)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
@public
|
|
219
|
+
@return the record for this RecordReference
|
|
220
|
+
*/
|
|
221
|
+
reload(): Promise<unknown>;
|
|
222
|
+
}
|
|
223
|
+
export declare function getShimClass<T>(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string): ShimModelClass<T>;
|
|
224
|
+
// Mimics the static apis of @ember-data/model
|
|
225
|
+
export declare class ShimModelClass<T = unknown> implements ModelSchema<T> {
|
|
226
|
+
__store: Store;
|
|
227
|
+
modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;
|
|
228
|
+
constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string);
|
|
229
|
+
get fields(): Map<KeyOrString<T>, "attribute" | "belongsTo" | "hasMany">;
|
|
230
|
+
get attributes(): Map<KeyOrString<T>, LegacyAttributeField>;
|
|
231
|
+
get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField>;
|
|
232
|
+
eachAttribute<K extends KeyOrString<T>>(callback: (key: K, attribute: LegacyAttributeField) => void, binding?: T): void;
|
|
233
|
+
eachRelationship<K extends KeyOrString<T>>(callback: (key: K, relationship: LegacyRelationshipField) => void, binding?: T): void;
|
|
234
|
+
eachTransformedAttribute<K extends KeyOrString<T>>(callback: (key: K, type: string | null) => void, binding?: T): void;
|
|
235
|
+
}
|