@warp-drive-mirror/json-api 5.8.0-alpha.30 → 5.8.0-alpha.32
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/dist/unpkg/dev/declarations/-private/cache.d.ts +445 -0
- package/dist/unpkg/dev/declarations/-private/validate-document-fields.d.ts +3 -0
- package/dist/unpkg/dev/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts +1 -0
- package/dist/unpkg/dev/declarations/-private/validator/1.1/7.2_resource-objects.d.ts +1 -0
- package/dist/unpkg/dev/declarations/-private/validator/1.1/links.d.ts +1 -0
- package/dist/unpkg/dev/declarations/-private/validator/index.d.ts +4 -0
- package/dist/unpkg/dev/declarations/-private/validator/utils.d.ts +75 -0
- package/dist/unpkg/dev/declarations/index.d.ts +5 -0
- package/dist/unpkg/dev/index.js +3225 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/cache.d.ts +445 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validate-document-fields.d.ts +3 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts +1 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validator/1.1/7.2_resource-objects.d.ts +1 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validator/1.1/links.d.ts +1 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validator/index.d.ts +4 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/validator/utils.d.ts +75 -0
- package/dist/unpkg/dev-deprecated/declarations/index.d.ts +5 -0
- package/dist/unpkg/dev-deprecated/index.js +3225 -0
- package/dist/unpkg/prod/declarations/-private/cache.d.ts +445 -0
- package/dist/unpkg/prod/declarations/-private/validate-document-fields.d.ts +3 -0
- package/dist/unpkg/prod/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts +1 -0
- package/dist/unpkg/prod/declarations/-private/validator/1.1/7.2_resource-objects.d.ts +1 -0
- package/dist/unpkg/prod/declarations/-private/validator/1.1/links.d.ts +1 -0
- package/dist/unpkg/prod/declarations/-private/validator/index.d.ts +4 -0
- package/dist/unpkg/prod/declarations/-private/validator/utils.d.ts +75 -0
- package/dist/unpkg/prod/declarations/index.d.ts +5 -0
- package/dist/unpkg/prod/index.js +3225 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/cache.d.ts +445 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validate-document-fields.d.ts +3 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts +1 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validator/1.1/7.2_resource-objects.d.ts +1 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validator/1.1/links.d.ts +1 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validator/index.d.ts +4 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/validator/utils.d.ts +75 -0
- package/dist/unpkg/prod-deprecated/declarations/index.d.ts +5 -0
- package/dist/unpkg/prod-deprecated/index.js +3225 -0
- package/package.json +4 -4
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import type { CacheCapabilitiesManager } from "@warp-drive-mirror/core/types";
|
|
2
|
+
import type { Cache, ChangedAttributesHash, RelationshipDiff } from "@warp-drive-mirror/core/types/cache";
|
|
3
|
+
import type { Change } from "@warp-drive-mirror/core/types/cache/change";
|
|
4
|
+
import type { Operation } from "@warp-drive-mirror/core/types/cache/operations";
|
|
5
|
+
import type { CollectionRelationship, ResourceRelationship } from "@warp-drive-mirror/core/types/cache/relationship";
|
|
6
|
+
import type { LocalRelationshipOperation } from "@warp-drive-mirror/core/types/graph";
|
|
7
|
+
import type { RequestKey, ResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
8
|
+
import type { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
9
|
+
import type { RequestContext, StructuredDataDocument, StructuredDocument, StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
10
|
+
import type { CollectionResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument, SingleResourceDataDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
11
|
+
import type { ApiError } from "@warp-drive-mirror/core/types/spec/error";
|
|
12
|
+
import type { CollectionResourceDocument, ExistingResourceObject, ResourceObject, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
13
|
+
/**
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { JSONAPICache } from '@warp-drive-mirror/json-api';
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* A {@link Cache} implementation tuned for [{json:api}](https://jsonapi.org/)
|
|
19
|
+
*
|
|
20
|
+
* @categoryDescription Cache Management
|
|
21
|
+
* APIs for primary cache management functionality
|
|
22
|
+
* @categoryDescription Cache Forking
|
|
23
|
+
* APIs that support Cache Forking
|
|
24
|
+
* @categoryDescription SSR Support
|
|
25
|
+
* APIs that support SSR functionality
|
|
26
|
+
* @categoryDescription Resource Lifecycle
|
|
27
|
+
* APIs that support management of resource data
|
|
28
|
+
* @categoryDescription Resource Data
|
|
29
|
+
* APIs that support granular field level management of resource data
|
|
30
|
+
* @categoryDescription Resource State
|
|
31
|
+
* APIs that support managing Resource states
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare class JSONAPICache implements Cache {
|
|
36
|
+
/**
|
|
37
|
+
* The Cache Version that this implementation implements.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
version: "2";
|
|
42
|
+
constructor(capabilities: CacheCapabilitiesManager);
|
|
43
|
+
/**
|
|
44
|
+
* Cache the response to a request
|
|
45
|
+
*
|
|
46
|
+
* Implements `Cache.put`.
|
|
47
|
+
*
|
|
48
|
+
* Expects a StructuredDocument whose `content` member is a JsonApiDocument.
|
|
49
|
+
*
|
|
50
|
+
* ```js
|
|
51
|
+
* cache.put({
|
|
52
|
+
* request: { url: 'https://api.example.com/v1/user/1' },
|
|
53
|
+
* content: {
|
|
54
|
+
* data: {
|
|
55
|
+
* type: 'user',
|
|
56
|
+
* id: '1',
|
|
57
|
+
* attributes: {
|
|
58
|
+
* name: 'Chris'
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
* }
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* > **Note**
|
|
66
|
+
* > The nested `content` and `data` members are not a mistake. This is because
|
|
67
|
+
* > there are two separate concepts involved here, the `StructuredDocument` which contains
|
|
68
|
+
* > the context of a given Request that has been issued with the returned contents as its
|
|
69
|
+
* > `content` property, and a `JSON:API Document` which is the json contents returned by
|
|
70
|
+
* > this endpoint and which uses its `data` property to signify which resources are the
|
|
71
|
+
* > primary resources associated with the request.
|
|
72
|
+
*
|
|
73
|
+
* StructuredDocument's with urls will be cached as full documents with
|
|
74
|
+
* associated resource membership order and contents preserved but linked
|
|
75
|
+
* into the cache.
|
|
76
|
+
*
|
|
77
|
+
* @category Cache Management
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
put<T extends SingleResourceDocument>(doc: StructuredDataDocument<T>): SingleResourceDataDocument;
|
|
81
|
+
put<T extends CollectionResourceDocument>(doc: StructuredDataDocument<T>): CollectionResourceDataDocument;
|
|
82
|
+
put<T extends ResourceErrorDocument>(doc: StructuredErrorDocument<T>): ResourceErrorDocument;
|
|
83
|
+
put<T extends ResourceMetaDocument>(doc: StructuredDataDocument<T>): ResourceMetaDocument;
|
|
84
|
+
/**
|
|
85
|
+
* Update the "remote" or "canonical" (persisted) state of the Cache
|
|
86
|
+
* by merging new information into the existing state.
|
|
87
|
+
*
|
|
88
|
+
* @category Cache Management
|
|
89
|
+
* @public
|
|
90
|
+
* @param op the operation or list of operations to perform
|
|
91
|
+
*/
|
|
92
|
+
patch(op: Operation | Operation[]): void;
|
|
93
|
+
/**
|
|
94
|
+
* Update the "local" or "current" (unpersisted) state of the Cache
|
|
95
|
+
*
|
|
96
|
+
* @category Cache Management
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
mutate(mutation: LocalRelationshipOperation): void;
|
|
100
|
+
/**
|
|
101
|
+
* Peek resource data from the Cache.
|
|
102
|
+
*
|
|
103
|
+
* In development, if the return value
|
|
104
|
+
* is JSON the return value
|
|
105
|
+
* will be deep-cloned and deep-frozen
|
|
106
|
+
* to prevent mutation thereby enforcing cache
|
|
107
|
+
* Immutability.
|
|
108
|
+
*
|
|
109
|
+
* This form of peek is useful for implementations
|
|
110
|
+
* that want to feed raw-data from cache to the UI
|
|
111
|
+
* or which want to interact with a blob of data
|
|
112
|
+
* directly from the presentation cache.
|
|
113
|
+
*
|
|
114
|
+
* An implementation might want to do this because
|
|
115
|
+
* de-referencing records which read from their own
|
|
116
|
+
* blob is generally safer because the record does
|
|
117
|
+
* not require retainining connections to the Store
|
|
118
|
+
* and Cache to present data on a per-field basis.
|
|
119
|
+
*
|
|
120
|
+
* This generally takes the place of `getAttr` as
|
|
121
|
+
* an API and may even take the place of `getRelationship`
|
|
122
|
+
* depending on implementation specifics, though this
|
|
123
|
+
* latter usage is less recommended due to the advantages
|
|
124
|
+
* of the Graph handling necessary entanglements and
|
|
125
|
+
* notifications for relational data.
|
|
126
|
+
*
|
|
127
|
+
* @category Cache Management
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
peek(identifier: ResourceKey): ResourceObject | null;
|
|
131
|
+
peek(identifier: RequestKey): ResourceDocument | null;
|
|
132
|
+
/**
|
|
133
|
+
* Peek the remote resource data from the Cache.
|
|
134
|
+
*
|
|
135
|
+
* @category Cache Management
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
peekRemoteState(identifier: ResourceKey): ResourceObject | null;
|
|
139
|
+
peekRemoteState(identifier: RequestKey): ResourceDocument | null;
|
|
140
|
+
/**
|
|
141
|
+
* Peek the Cache for the existing request data associated with
|
|
142
|
+
* a cacheable request.
|
|
143
|
+
*
|
|
144
|
+
* This is effectively the reverse of `put` for a request in
|
|
145
|
+
* that it will return the the request, response, and content
|
|
146
|
+
* whereas `peek` will return just the `content`.
|
|
147
|
+
*
|
|
148
|
+
* @category Cache Management
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
peekRequest(identifier: RequestKey): StructuredDocument<ResourceDocument> | null;
|
|
152
|
+
/**
|
|
153
|
+
* Push resource data from a remote source into the cache for this identifier
|
|
154
|
+
*
|
|
155
|
+
* @category Cache Management
|
|
156
|
+
* @public
|
|
157
|
+
* @return if `calculateChanges` is true then calculated key changes should be returned
|
|
158
|
+
*/
|
|
159
|
+
upsert(identifier: ResourceKey, data: ExistingResourceObject, calculateChanges?: boolean): void | string[];
|
|
160
|
+
/**
|
|
161
|
+
* Create a fork of the cache from the current state.
|
|
162
|
+
*
|
|
163
|
+
* Applications should typically not call this method themselves,
|
|
164
|
+
* preferring instead to fork at the Store level, which will
|
|
165
|
+
* utilize this method to fork the cache.
|
|
166
|
+
*
|
|
167
|
+
* @category Cache Forking
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
fork(): Promise<Cache>;
|
|
171
|
+
/**
|
|
172
|
+
* Merge a fork back into a parent Cache.
|
|
173
|
+
*
|
|
174
|
+
* Applications should typically not call this method themselves,
|
|
175
|
+
* preferring instead to merge at the Store level, which will
|
|
176
|
+
* utilize this method to merge the caches.
|
|
177
|
+
*
|
|
178
|
+
* @category Cache Forking
|
|
179
|
+
* @private
|
|
180
|
+
*/
|
|
181
|
+
merge(_cache: Cache): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Generate the list of changes applied to all
|
|
184
|
+
* record in the store.
|
|
185
|
+
*
|
|
186
|
+
* Each individual resource or document that has
|
|
187
|
+
* been mutated should be described as an individual
|
|
188
|
+
* `Change` entry in the returned array.
|
|
189
|
+
*
|
|
190
|
+
* A `Change` is described by an object containing up to
|
|
191
|
+
* three properties: (1) the `identifier` of the entity that
|
|
192
|
+
* changed; (2) the `op` code of that change being one of
|
|
193
|
+
* `upsert` or `remove`, and if the op is `upsert` a `patch`
|
|
194
|
+
* containing the data to merge into the cache for the given
|
|
195
|
+
* entity.
|
|
196
|
+
*
|
|
197
|
+
* This `patch` is opaque to the Store but should be understood
|
|
198
|
+
* by the Cache and may expect to be utilized by an Adapter
|
|
199
|
+
* when generating data during a `save` operation.
|
|
200
|
+
*
|
|
201
|
+
* It is generally recommended that the `patch` contain only
|
|
202
|
+
* the updated state, ignoring fields that are unchanged
|
|
203
|
+
*
|
|
204
|
+
* ```ts
|
|
205
|
+
* interface Change {
|
|
206
|
+
* identifier: ResourceKey | RequestKey;
|
|
207
|
+
* op: 'upsert' | 'remove';
|
|
208
|
+
* patch?: unknown;
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @category Cache Forking
|
|
213
|
+
* @private
|
|
214
|
+
*/
|
|
215
|
+
diff(): Promise<Change[]>;
|
|
216
|
+
/**
|
|
217
|
+
* Serialize the entire contents of the Cache into a Stream
|
|
218
|
+
* which may be fed back into a new instance of the same Cache
|
|
219
|
+
* via `cache.hydrate`.
|
|
220
|
+
*
|
|
221
|
+
* @category SSR Support
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
dump(): Promise<ReadableStream<unknown>>;
|
|
225
|
+
/**
|
|
226
|
+
* hydrate a Cache from a Stream with content previously serialized
|
|
227
|
+
* from another instance of the same Cache, resolving when hydration
|
|
228
|
+
* is complete.
|
|
229
|
+
*
|
|
230
|
+
* This method should expect to be called both in the context of restoring
|
|
231
|
+
* the Cache during application rehydration after SSR **AND** at unknown
|
|
232
|
+
* times during the lifetime of an already booted application when it is
|
|
233
|
+
* desired to bulk-load additional information into the cache. This latter
|
|
234
|
+
* behavior supports optimizing pre/fetching of data for route transitions
|
|
235
|
+
* via data-only SSR modes.
|
|
236
|
+
*
|
|
237
|
+
* @category SSR Support
|
|
238
|
+
* @private
|
|
239
|
+
*/
|
|
240
|
+
hydrate(stream: ReadableStream<unknown>): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* [LIFECYCLE] Signal to the cache that a new record has been instantiated on the client
|
|
243
|
+
*
|
|
244
|
+
* It returns properties from options that should be set on the record during the create
|
|
245
|
+
* process. This return value behavior is deprecated.
|
|
246
|
+
*
|
|
247
|
+
* @category Resource Lifecycle
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
clientDidCreate(identifier: ResourceKey, options?: Record<string, Value>): Record<string, unknown>;
|
|
251
|
+
/**
|
|
252
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
253
|
+
* will be part of a save transaction.
|
|
254
|
+
*
|
|
255
|
+
* @category Resource Lifecycle
|
|
256
|
+
* @public
|
|
257
|
+
*/
|
|
258
|
+
willCommit(identifier: ResourceKey | ResourceKey[], _context: RequestContext | null): void;
|
|
259
|
+
/**
|
|
260
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
261
|
+
* was successfully updated as part of a save transaction.
|
|
262
|
+
*
|
|
263
|
+
* @category Resource Lifecycle
|
|
264
|
+
* @public
|
|
265
|
+
*/
|
|
266
|
+
didCommit(committedIdentifier: ResourceKey, result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
267
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<SingleResourceDataDocument> | null): SingleResourceDataDocument;
|
|
268
|
+
didCommit(committedIdentifier: ResourceKey[], result: StructuredDataDocument<CollectionResourceDataDocument> | null): CollectionResourceDataDocument;
|
|
269
|
+
/**
|
|
270
|
+
* [LIFECYCLE] Signals to the cache that a resource
|
|
271
|
+
* was update via a save transaction failed.
|
|
272
|
+
*
|
|
273
|
+
* @category Resource Lifecycle
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
commitWasRejected(identifier: ResourceKey | ResourceKey[], errors?: ApiError[]): void;
|
|
277
|
+
/**
|
|
278
|
+
* [LIFECYCLE] Signals to the cache that all data for a resource
|
|
279
|
+
* should be cleared.
|
|
280
|
+
*
|
|
281
|
+
* This method is a candidate to become a mutation
|
|
282
|
+
*
|
|
283
|
+
* @category Resource Lifecycle
|
|
284
|
+
* @public
|
|
285
|
+
*/
|
|
286
|
+
unloadRecord(identifier: ResourceKey): void;
|
|
287
|
+
/**
|
|
288
|
+
* Retrieve the data for an attribute from the cache
|
|
289
|
+
* with local mutations applied.
|
|
290
|
+
*
|
|
291
|
+
* @category Resource Data
|
|
292
|
+
* @public
|
|
293
|
+
*/
|
|
294
|
+
getAttr(identifier: ResourceKey, attr: string | string[]): Value | undefined;
|
|
295
|
+
/**
|
|
296
|
+
* Retrieve the remote data for an attribute from the cache
|
|
297
|
+
*
|
|
298
|
+
* @category Resource Data
|
|
299
|
+
* @public
|
|
300
|
+
*/
|
|
301
|
+
getRemoteAttr(identifier: ResourceKey, attr: string | string[]): Value | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Mutate the data for an attribute in the cache
|
|
304
|
+
*
|
|
305
|
+
* This method is a candidate to become a mutation
|
|
306
|
+
*
|
|
307
|
+
* @category Resource Data
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
setAttr(identifier: ResourceKey, attr: string | string[], value: Value): void;
|
|
311
|
+
/**
|
|
312
|
+
* Query the cache for the changed attributes of a resource.
|
|
313
|
+
*
|
|
314
|
+
* @category Resource Data
|
|
315
|
+
* @public
|
|
316
|
+
* @return `{ '<field>': ['<old>', '<new>'] }`
|
|
317
|
+
*/
|
|
318
|
+
changedAttrs(identifier: ResourceKey): ChangedAttributesHash;
|
|
319
|
+
/**
|
|
320
|
+
* Query the cache for whether any mutated attributes exist
|
|
321
|
+
*
|
|
322
|
+
* @category Resource Data
|
|
323
|
+
* @public
|
|
324
|
+
*/
|
|
325
|
+
hasChangedAttrs(identifier: ResourceKey): boolean;
|
|
326
|
+
/**
|
|
327
|
+
* Tell the cache to discard any uncommitted mutations to attributes
|
|
328
|
+
*
|
|
329
|
+
* This method is a candidate to become a mutation
|
|
330
|
+
*
|
|
331
|
+
* @category Resource Data
|
|
332
|
+
* @public
|
|
333
|
+
* @return the names of fields that were restored
|
|
334
|
+
*/
|
|
335
|
+
rollbackAttrs(identifier: ResourceKey): string[];
|
|
336
|
+
/**
|
|
337
|
+
* Query the cache for the changes to relationships of a resource.
|
|
338
|
+
*
|
|
339
|
+
* Returns a map of relationship names to RelationshipDiff objects.
|
|
340
|
+
*
|
|
341
|
+
* ```ts
|
|
342
|
+
* type RelationshipDiff =
|
|
343
|
+
| {
|
|
344
|
+
kind: 'collection';
|
|
345
|
+
remoteState: ResourceKey[];
|
|
346
|
+
additions: Set<ResourceKey>;
|
|
347
|
+
removals: Set<ResourceKey>;
|
|
348
|
+
localState: ResourceKey[];
|
|
349
|
+
reordered: boolean;
|
|
350
|
+
}
|
|
351
|
+
| {
|
|
352
|
+
kind: 'resource';
|
|
353
|
+
remoteState: ResourceKey | null;
|
|
354
|
+
localState: ResourceKey | null;
|
|
355
|
+
};
|
|
356
|
+
```
|
|
357
|
+
*
|
|
358
|
+
* @category Resource Data
|
|
359
|
+
* @public
|
|
360
|
+
*/
|
|
361
|
+
changedRelationships(identifier: ResourceKey): Map<string, RelationshipDiff>;
|
|
362
|
+
/**
|
|
363
|
+
* Query the cache for whether any mutated relationships exist
|
|
364
|
+
*
|
|
365
|
+
* @category Resource Data
|
|
366
|
+
* @public
|
|
367
|
+
*/
|
|
368
|
+
hasChangedRelationships(identifier: ResourceKey): boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Tell the cache to discard any uncommitted mutations to relationships.
|
|
371
|
+
*
|
|
372
|
+
* This will also discard the change on any appropriate inverses.
|
|
373
|
+
*
|
|
374
|
+
* This method is a candidate to become a mutation
|
|
375
|
+
*
|
|
376
|
+
* @category Resource Data
|
|
377
|
+
* @public
|
|
378
|
+
* @return the names of relationships that were restored
|
|
379
|
+
*/
|
|
380
|
+
rollbackRelationships(identifier: ResourceKey): string[];
|
|
381
|
+
/**
|
|
382
|
+
* Query the cache for the current state of a relationship property
|
|
383
|
+
*
|
|
384
|
+
* @category Resource Data
|
|
385
|
+
* @public
|
|
386
|
+
* @return resource relationship object
|
|
387
|
+
*/
|
|
388
|
+
getRelationship(identifier: ResourceKey, field: string): ResourceRelationship | CollectionRelationship;
|
|
389
|
+
/**
|
|
390
|
+
* Query the cache for the remote state of a relationship property
|
|
391
|
+
*
|
|
392
|
+
* @category Resource Data
|
|
393
|
+
* @public
|
|
394
|
+
* @return resource relationship object
|
|
395
|
+
*/
|
|
396
|
+
getRemoteRelationship(identifier: ResourceKey, field: string): ResourceRelationship | CollectionRelationship;
|
|
397
|
+
/**
|
|
398
|
+
* Update the cache state for the given resource to be marked
|
|
399
|
+
* as locally deleted, or remove such a mark.
|
|
400
|
+
*
|
|
401
|
+
* This method is a candidate to become a mutation
|
|
402
|
+
*
|
|
403
|
+
* @category Resource State
|
|
404
|
+
* @public
|
|
405
|
+
*/
|
|
406
|
+
setIsDeleted(identifier: ResourceKey, isDeleted: boolean): void;
|
|
407
|
+
/**
|
|
408
|
+
* Query the cache for any validation errors applicable to the given resource.
|
|
409
|
+
*
|
|
410
|
+
* @category Resource State
|
|
411
|
+
* @public
|
|
412
|
+
*/
|
|
413
|
+
getErrors(identifier: ResourceKey): ApiError[];
|
|
414
|
+
/**
|
|
415
|
+
* Query the cache for whether a given resource has any available data
|
|
416
|
+
*
|
|
417
|
+
* @category Resource State
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
420
|
+
isEmpty(identifier: ResourceKey): boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Query the cache for whether a given resource was created locally and not
|
|
423
|
+
* yet persisted.
|
|
424
|
+
*
|
|
425
|
+
* @category Resource State
|
|
426
|
+
* @public
|
|
427
|
+
*/
|
|
428
|
+
isNew(identifier: ResourceKey): boolean;
|
|
429
|
+
/**
|
|
430
|
+
* Query the cache for whether a given resource is marked as deleted (but not
|
|
431
|
+
* necessarily persisted yet).
|
|
432
|
+
*
|
|
433
|
+
* @category Resource State
|
|
434
|
+
* @public
|
|
435
|
+
*/
|
|
436
|
+
isDeleted(identifier: ResourceKey): boolean;
|
|
437
|
+
/**
|
|
438
|
+
* Query the cache for whether a given resource has been deleted and that deletion
|
|
439
|
+
* has also been persisted.
|
|
440
|
+
*
|
|
441
|
+
* @category Resource State
|
|
442
|
+
* @public
|
|
443
|
+
*/
|
|
444
|
+
isDeletionCommitted(identifier: ResourceKey): boolean;
|
|
445
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SchemaService } from "@warp-drive-mirror/core/types";
|
|
2
|
+
import type { CollectionResourceDocument, SingleResourceDocument } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
3
|
+
export declare function validateDocumentFields(schema: SchemaService, jsonApiDoc: SingleResourceDocument | CollectionResourceDocument): void;
|
package/dist/unpkg/dev/declarations/-private/validator/1.1/7.1_top-level-document-members.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CacheCapabilitiesManager } from "@warp-drive-mirror/core/types";
|
|
2
|
+
import type { StructuredDocument } from "@warp-drive-mirror/core/types/request";
|
|
3
|
+
import type { ResourceDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
4
|
+
export declare function validateDocument(capabilities: CacheCapabilitiesManager, doc: StructuredDocument<ResourceDocument>): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { FuseResult } from "fuse.js";
|
|
2
|
+
import Fuse from "fuse.js";
|
|
3
|
+
import jsonToAst from "json-to-ast";
|
|
4
|
+
import type { CacheCapabilitiesManager, SchemaService } from "@warp-drive-mirror/core/types";
|
|
5
|
+
import type { StructuredDataDocument, StructuredDocument, StructuredErrorDocument } from "@warp-drive-mirror/core/types/request";
|
|
6
|
+
import type { FieldSchema } from "@warp-drive-mirror/core/types/schema/fields";
|
|
7
|
+
import type { ResourceDataDocument, ResourceDocument, ResourceErrorDocument, ResourceMetaDocument } from "@warp-drive-mirror/core/types/spec/document";
|
|
8
|
+
export declare function inspectType(obj: unknown): string;
|
|
9
|
+
export declare function isSimpleObject(obj: unknown): obj is Record<string, unknown>;
|
|
10
|
+
export declare const RELATIONSHIP_FIELD_KINDS: string[];
|
|
11
|
+
export type PathLike = Array<string | number>;
|
|
12
|
+
interface ErrorReport {
|
|
13
|
+
path: PathLike;
|
|
14
|
+
message: string;
|
|
15
|
+
loc: {
|
|
16
|
+
start: {
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
offset: number;
|
|
20
|
+
};
|
|
21
|
+
end: {
|
|
22
|
+
line: number;
|
|
23
|
+
column: number;
|
|
24
|
+
offset: number;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
type: "error" | "warning" | "info";
|
|
28
|
+
kind: "key" | "value";
|
|
29
|
+
}
|
|
30
|
+
export declare class Reporter {
|
|
31
|
+
capabilities: CacheCapabilitiesManager;
|
|
32
|
+
contextDocument: StructuredDocument<ResourceDocument>;
|
|
33
|
+
errors: ErrorReport[];
|
|
34
|
+
ast: ReturnType<typeof jsonToAst>;
|
|
35
|
+
jsonStr: string;
|
|
36
|
+
strict: {
|
|
37
|
+
linkage: boolean;
|
|
38
|
+
unknownType: boolean;
|
|
39
|
+
unknownAttribute: boolean;
|
|
40
|
+
unknownRelationship: boolean;
|
|
41
|
+
};
|
|
42
|
+
constructor(capabilities: CacheCapabilitiesManager, doc: StructuredDocument<ResourceDocument>);
|
|
43
|
+
_typeFilter: Fuse<string> | undefined;
|
|
44
|
+
searchTypes(type: string): FuseResult<string>[];
|
|
45
|
+
_fieldFilters: Map<string, Fuse<string>>;
|
|
46
|
+
searchFields(type: string, field: string): FuseResult<string>[];
|
|
47
|
+
get schema(): SchemaService;
|
|
48
|
+
getLocation(path: PathLike, kind: "key" | "value"): {
|
|
49
|
+
start: {
|
|
50
|
+
line: number;
|
|
51
|
+
column: number;
|
|
52
|
+
offset: number;
|
|
53
|
+
};
|
|
54
|
+
end: {
|
|
55
|
+
line: number;
|
|
56
|
+
column: number;
|
|
57
|
+
offset: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
error(path: PathLike, message: string, kind?: "key" | "value"): void;
|
|
61
|
+
warn(path: PathLike, message: string, kind?: "key" | "value"): void;
|
|
62
|
+
info(path: PathLike, message: string, kind?: "key" | "value"): void;
|
|
63
|
+
hasExtension(extensionName: string): boolean;
|
|
64
|
+
getExtension(extensionName: string): ReporterFn | undefined;
|
|
65
|
+
report(colorize?: boolean): void;
|
|
66
|
+
}
|
|
67
|
+
type ReporterFn = (reporter: Reporter, path: PathLike) => void;
|
|
68
|
+
export declare function isMetaDocument(doc: StructuredDocument<ResourceDocument>): doc is StructuredDataDocument<ResourceMetaDocument>;
|
|
69
|
+
export declare function isErrorDocument(doc: StructuredDocument<ResourceDocument>): doc is StructuredErrorDocument<ResourceErrorDocument>;
|
|
70
|
+
export declare function isPushedDocument(doc: unknown): doc is {
|
|
71
|
+
content: ResourceDataDocument;
|
|
72
|
+
};
|
|
73
|
+
export declare function logPotentialMatches(matches: FuseResult<string>[], kind: string): string;
|
|
74
|
+
export declare function getRemoteField(fields: Map<string, FieldSchema>, key: string): FieldSchema | undefined;
|
|
75
|
+
export {};
|