@warp-drive/core 5.6.0-alpha.17 → 5.6.0-alpha.5

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 (219) hide show
  1. package/README.md +7 -8
  2. package/declarations/index.d.ts +3 -14
  3. package/declarations/index.d.ts.map +1 -0
  4. package/declarations/request/-private/context.d.ts +35 -34
  5. package/declarations/request/-private/context.d.ts.map +1 -0
  6. package/declarations/request/-private/debug.d.ts +3 -2
  7. package/declarations/request/-private/debug.d.ts.map +1 -0
  8. package/declarations/request/-private/fetch.d.ts +36 -24
  9. package/declarations/request/-private/fetch.d.ts.map +1 -0
  10. package/declarations/request/-private/future.d.ts +4 -3
  11. package/declarations/request/-private/future.d.ts.map +1 -0
  12. package/declarations/request/-private/manager.d.ts +132 -159
  13. package/declarations/request/-private/manager.d.ts.map +1 -0
  14. package/declarations/request/-private/promise-cache.d.ts +13 -21
  15. package/declarations/request/-private/promise-cache.d.ts.map +1 -0
  16. package/declarations/request/-private/types.d.ts +123 -124
  17. package/declarations/request/-private/types.d.ts.map +1 -0
  18. package/declarations/request/-private/utils.d.ts +9 -8
  19. package/declarations/request/-private/utils.d.ts.map +1 -0
  20. package/declarations/request.d.ts +433 -5
  21. package/declarations/request.d.ts.map +1 -0
  22. package/declarations/types/-private.d.ts +8 -16
  23. package/declarations/types/-private.d.ts.map +1 -0
  24. package/declarations/types/cache/aliases.d.ts +1 -11
  25. package/declarations/types/cache/aliases.d.ts.map +1 -0
  26. package/declarations/types/cache/change.d.ts +5 -4
  27. package/declarations/types/cache/change.d.ts.map +1 -0
  28. package/declarations/types/cache/mutations.d.ts +28 -51
  29. package/declarations/types/cache/mutations.d.ts.map +1 -0
  30. package/declarations/types/cache/operations.d.ts +47 -60
  31. package/declarations/types/cache/operations.d.ts.map +1 -0
  32. package/declarations/types/cache/relationship.d.ts +9 -11
  33. package/declarations/types/cache/relationship.d.ts.map +1 -0
  34. package/declarations/types/cache.d.ts +484 -495
  35. package/declarations/types/cache.d.ts.map +1 -0
  36. package/declarations/types/graph.d.ts +40 -31
  37. package/declarations/types/graph.d.ts.map +1 -0
  38. package/declarations/types/identifier.d.ts +82 -83
  39. package/declarations/types/identifier.d.ts.map +1 -0
  40. package/declarations/types/json/raw.d.ts +2 -1
  41. package/declarations/types/json/raw.d.ts.map +1 -0
  42. package/declarations/types/params.d.ts +5 -4
  43. package/declarations/types/params.d.ts.map +1 -0
  44. package/declarations/types/record.d.ts +76 -117
  45. package/declarations/types/record.d.ts.map +1 -0
  46. package/declarations/types/record.type-test.d.ts +2 -0
  47. package/declarations/types/record.type-test.d.ts.map +1 -0
  48. package/declarations/types/request.d.ts +266 -289
  49. package/declarations/types/request.d.ts.map +1 -0
  50. package/declarations/types/request.type-test.d.ts +2 -0
  51. package/declarations/types/request.type-test.d.ts.map +1 -0
  52. package/declarations/types/runtime.d.ts +9 -8
  53. package/declarations/types/runtime.d.ts.map +1 -0
  54. package/declarations/types/schema/concepts.d.ts +13 -19
  55. package/declarations/types/schema/concepts.d.ts.map +1 -0
  56. package/declarations/types/schema/fields.d.ts +1741 -1712
  57. package/declarations/types/schema/fields.d.ts.map +1 -0
  58. package/declarations/types/schema/fields.type-test.d.ts +1 -0
  59. package/declarations/types/schema/fields.type-test.d.ts.map +1 -0
  60. package/declarations/types/spec/document.d.ts +22 -28
  61. package/declarations/types/spec/document.d.ts.map +1 -0
  62. package/declarations/types/spec/error.d.ts +17 -16
  63. package/declarations/types/spec/error.d.ts.map +1 -0
  64. package/declarations/types/spec/json-api-raw.d.ts +102 -102
  65. package/declarations/types/spec/json-api-raw.d.ts.map +1 -0
  66. package/declarations/types/symbols.d.ts +75 -74
  67. package/declarations/types/symbols.d.ts.map +1 -0
  68. package/declarations/types/utils.d.ts +5 -5
  69. package/declarations/types/utils.d.ts.map +1 -0
  70. package/declarations/types.d.ts +7 -10
  71. package/declarations/types.d.ts.map +1 -0
  72. package/dist/{context-COmAnXUQ.js → context-DE5sFezZ.js} +2 -2
  73. package/dist/context-DE5sFezZ.js.map +1 -0
  74. package/dist/index.js +104 -37
  75. package/dist/index.js.map +1 -0
  76. package/dist/request.js +1 -1
  77. package/dist/request.js.map +1 -0
  78. package/dist/types/-private.js +3 -3
  79. package/dist/types/-private.js.map +1 -0
  80. package/dist/types/cache/aliases.js.map +1 -0
  81. package/dist/types/cache/change.js.map +1 -0
  82. package/dist/types/cache/mutations.js.map +1 -0
  83. package/dist/types/cache/operations.js.map +1 -0
  84. package/dist/types/cache/relationship.js.map +1 -0
  85. package/dist/types/cache.js.map +1 -0
  86. package/dist/types/graph.js.map +1 -0
  87. package/dist/types/identifier.js.map +1 -0
  88. package/dist/types/json/raw.js.map +1 -0
  89. package/dist/types/params.js.map +1 -0
  90. package/dist/types/record.js +1 -1
  91. package/dist/types/record.js.map +1 -0
  92. package/dist/types/request.js +2 -2
  93. package/dist/types/request.js.map +1 -0
  94. package/dist/types/runtime.js +1 -1
  95. package/dist/types/runtime.js.map +1 -0
  96. package/dist/types/schema/concepts.js.map +1 -0
  97. package/dist/types/schema/fields.js +41 -8
  98. package/dist/types/schema/fields.js.map +1 -0
  99. package/dist/types/schema/fields.type-test.js.map +1 -0
  100. package/dist/types/spec/document.js.map +1 -0
  101. package/dist/types/spec/error.js.map +1 -0
  102. package/dist/types/spec/json-api-raw.js.map +1 -0
  103. package/dist/types/symbols.js +3 -3
  104. package/dist/types/symbols.js.map +1 -0
  105. package/dist/types/utils.js.map +1 -0
  106. package/dist/types.js.map +1 -0
  107. package/package.json +8 -11
  108. package/cjs-dist/addon-shim.cjs +0 -1
  109. package/cjs-dist/cjs-set-config.cjs +0 -1
  110. package/declarations/build-config/babel-macros.d.ts +0 -1
  111. package/declarations/build-config/canary-features.d.ts +0 -1
  112. package/declarations/build-config/debugging.d.ts +0 -1
  113. package/declarations/build-config/deprecations.d.ts +0 -1
  114. package/declarations/build-config/env.d.ts +0 -1
  115. package/declarations/build-config/macros.d.ts +0 -1
  116. package/declarations/build-config.d.ts +0 -1
  117. package/declarations/configure.d.ts +0 -7
  118. package/declarations/graph/-private/-diff.d.ts +0 -32
  119. package/declarations/graph/-private/-edge-definition.d.ts +0 -148
  120. package/declarations/graph/-private/-state.d.ts +0 -96
  121. package/declarations/graph/-private/-utils.d.ts +0 -31
  122. package/declarations/graph/-private/coerce-id.d.ts +0 -10
  123. package/declarations/graph/-private/debug/assert-polymorphic-type.d.ts +0 -18
  124. package/declarations/graph/-private/edges/collection.d.ts +0 -39
  125. package/declarations/graph/-private/edges/implicit.d.ts +0 -43
  126. package/declarations/graph/-private/edges/resource.d.ts +0 -24
  127. package/declarations/graph/-private/graph.d.ts +0 -90
  128. package/declarations/graph/-private/normalize-link.d.ts +0 -8
  129. package/declarations/graph/-private/operations/add-to-related-records.d.ts +0 -4
  130. package/declarations/graph/-private/operations/merge-identifier.d.ts +0 -3
  131. package/declarations/graph/-private/operations/remove-from-related-records.d.ts +0 -4
  132. package/declarations/graph/-private/operations/replace-related-record.d.ts +0 -3
  133. package/declarations/graph/-private/operations/replace-related-records.d.ts +0 -62
  134. package/declarations/graph/-private/operations/update-relationship.d.ts +0 -13
  135. package/declarations/graph/-private.d.ts +0 -13
  136. package/declarations/reactive/-private/document.d.ts +0 -146
  137. package/declarations/reactive/-private/fields/compute.d.ts +0 -43
  138. package/declarations/reactive/-private/fields/extension.d.ts +0 -8
  139. package/declarations/reactive/-private/fields/managed-array.d.ts +0 -22
  140. package/declarations/reactive/-private/fields/managed-object.d.ts +0 -21
  141. package/declarations/reactive/-private/fields/many-array-manager.d.ts +0 -19
  142. package/declarations/reactive/-private/hooks.d.ts +0 -5
  143. package/declarations/reactive/-private/record.d.ts +0 -64
  144. package/declarations/reactive/-private/schema.d.ts +0 -271
  145. package/declarations/reactive/-private/symbols.d.ts +0 -36
  146. package/declarations/reactive/-private.d.ts +0 -1
  147. package/declarations/reactive.d.ts +0 -4
  148. package/declarations/store/-private/cache-handler/handler.d.ts +0 -62
  149. package/declarations/store/-private/cache-handler/types.d.ts +0 -98
  150. package/declarations/store/-private/cache-handler/utils.d.ts +0 -32
  151. package/declarations/store/-private/caches/cache-utils.d.ts +0 -12
  152. package/declarations/store/-private/caches/identifier-cache.d.ts +0 -304
  153. package/declarations/store/-private/caches/instance-cache.d.ts +0 -65
  154. package/declarations/store/-private/caches/resource-utils.d.ts +0 -9
  155. package/declarations/store/-private/debug/utils.d.ts +0 -6
  156. package/declarations/store/-private/default-cache-policy.d.ts +0 -384
  157. package/declarations/store/-private/legacy-model-support/record-reference.d.ts +0 -159
  158. package/declarations/store/-private/legacy-model-support/shim-model-class.d.ts +0 -17
  159. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +0 -25
  160. package/declarations/store/-private/managers/cache-manager.d.ts +0 -443
  161. package/declarations/store/-private/managers/notification-manager.d.ts +0 -98
  162. package/declarations/store/-private/managers/record-array-manager.d.ts +0 -97
  163. package/declarations/store/-private/network/request-cache.d.ts +0 -107
  164. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +0 -263
  165. package/declarations/store/-private/new-core-tmp/reactivity/configure.d.ts +0 -176
  166. package/declarations/store/-private/new-core-tmp/reactivity/internal.d.ts +0 -169
  167. package/declarations/store/-private/new-core-tmp/reactivity/signal.d.ts +0 -35
  168. package/declarations/store/-private/new-core-tmp/request-state.d.ts +0 -277
  169. package/declarations/store/-private/new-core-tmp/request-subscription.d.ts +0 -261
  170. package/declarations/store/-private/record-arrays/identifier-array.d.ts +0 -147
  171. package/declarations/store/-private/record-arrays/many-array.d.ts +0 -197
  172. package/declarations/store/-private/record-arrays/native-proxy-type-fix.d.ts +0 -126
  173. package/declarations/store/-private/store-service.d.ts +0 -1605
  174. package/declarations/store/-private/utils/coerce-id.d.ts +0 -10
  175. package/declarations/store/-private/utils/construct-resource.d.ts +0 -6
  176. package/declarations/store/-private/utils/is-non-empty-string.d.ts +0 -1
  177. package/declarations/store/-private/utils/normalize-model-name.d.ts +0 -1
  178. package/declarations/store/-private/utils/uuid-polyfill.d.ts +0 -1
  179. package/declarations/store/-private.d.ts +0 -31
  180. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +0 -99
  181. package/declarations/store/-types/q/ds-model.d.ts +0 -21
  182. package/declarations/store/-types/q/identifier.d.ts +0 -20
  183. package/declarations/store/-types/q/record-instance.d.ts +0 -23
  184. package/declarations/store/-types/q/schema-service.d.ts +0 -354
  185. package/declarations/store/-types/q/store.d.ts +0 -32
  186. package/declarations/store.d.ts +0 -1
  187. package/declarations/utils/string.d.ts +0 -48
  188. package/dist/build-config/babel-macros.js +0 -1
  189. package/dist/build-config/canary-features.js +0 -1
  190. package/dist/build-config/debugging.js +0 -1
  191. package/dist/build-config/deprecations.js +0 -1
  192. package/dist/build-config/env.js +0 -1
  193. package/dist/build-config/macros.js +0 -1
  194. package/dist/build-config.js +0 -1
  195. package/dist/configure-B48bFHOl.js +0 -181
  196. package/dist/configure.js +0 -1
  197. package/dist/graph/-private.js +0 -3372
  198. package/dist/handler-C2T-IyJK.js +0 -339
  199. package/dist/reactive/-private.js +0 -1
  200. package/dist/reactive.js +0 -1988
  201. package/dist/request-state-CjLph1LP.js +0 -8139
  202. package/dist/store/-private.js +0 -3
  203. package/dist/store.js +0 -545
  204. package/dist/symbols-SIstXMLI.js +0 -44
  205. package/dist/utils/string.js +0 -92
  206. package/logos/NCC-1701-a-blue.svg +0 -4
  207. package/logos/NCC-1701-a-gold.svg +0 -4
  208. package/logos/NCC-1701-a-gold_100.svg +0 -1
  209. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  210. package/logos/NCC-1701-a.svg +0 -4
  211. package/logos/README.md +0 -4
  212. package/logos/docs-badge.svg +0 -2
  213. package/logos/ember-data-logo-dark.svg +0 -12
  214. package/logos/ember-data-logo-light.svg +0 -12
  215. package/logos/github-header.svg +0 -444
  216. package/logos/social1.png +0 -0
  217. package/logos/social2.png +0 -0
  218. package/logos/warp-drive-logo-dark.svg +0 -4
  219. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -1,62 +0,0 @@
1
- import type { CacheHandler as CacheHandlerType } from "../../../request.js";
2
- import type { ImmutableRequestInfo, RequestContext } from "../../../types/request.js";
3
- import type { ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
4
- import type { RequestSignature } from "../../../types/symbols.js";
5
- import type { Store } from "../store-service.js";
6
- export type LooseStoreRequestInfo<
7
- RT = unknown,
8
- T = unknown
9
- > = Omit<ImmutableRequestInfo<RT, T>, "records" | "headers" | typeof RequestSignature> & {
10
- records?: ResourceIdentifierObject[];
11
- headers?: Headers;
12
- };
13
- export type StoreRequestInput<
14
- RT = unknown,
15
- T = unknown
16
- > = ImmutableRequestInfo<RT, T> | LooseStoreRequestInfo<RT, T>;
17
- export interface StoreRequestContext extends RequestContext {
18
- request: ImmutableRequestInfo & {
19
- store: Store;
20
- };
21
- }
22
- /**
23
- * A CacheHandler that adds support for using an WarpDrive Cache with a RequestManager.
24
- *
25
- * This handler will only run when a request has supplied a `store` instance. Requests
26
- * issued by the store via `store.request()` will automatically have the `store` instance
27
- * attached to the request.
28
- *
29
- * ```ts
30
- * requestManager.request({
31
- * store: store,
32
- * url: '/api/posts',
33
- * method: 'GET'
34
- * });
35
- * ```
36
- *
37
- * When this handler elects to handle a request, it will return the raw `StructuredDocument`
38
- * unless the request has `[EnableHydration]` set to `true`. In this case, the handler will
39
- * return a `Document` instance that will automatically update the UI when the cache is updated
40
- * in the future and will hydrate any identifiers in the StructuredDocument into Record instances.
41
- *
42
- * When issuing a request via the store, [EnableHydration] is automatically set to `true`. This
43
- * means that if desired you can issue requests that utilize the cache without needing to also
44
- * utilize Record instances if desired.
45
- *
46
- * Said differently, you could elect to issue all requests via a RequestManager, without ever using
47
- * the store directly, by setting [EnableHydration] to `true` and providing a store instance. Not
48
- * necessarily the most useful thing, but the decoupled nature of the RequestManager and incremental-feature
49
- * approach of WarpDrive allows for this flexibility.
50
- *
51
- * ```ts
52
- * import { EnableHydration } from '@warp-drive/core/types/request';
53
- *
54
- * requestManager.request({
55
- * store: store,
56
- * url: '/api/posts',
57
- * method: 'GET',
58
- * [EnableHydration]: true
59
- * });
60
- *
61
- */
62
- export declare const CacheHandler: CacheHandlerType;
@@ -1,98 +0,0 @@
1
- import type { StableDocumentIdentifier } from "../../../types/identifier.js";
2
- import type { ImmutableRequestInfo, ResponseInfo } from "../../../types/request.js";
3
- import type { Store } from "../store-service.js";
4
- /**
5
- * A service which an application may provide to the store via
6
- * the store's `lifetimes` property to configure the behavior
7
- * of the CacheHandler.
8
- *
9
- * The default behavior for request lifetimes is to never expire
10
- * unless manually refreshed via `cacheOptions.reload` or `cacheOptions.backgroundReload`.
11
- *
12
- * Implementing this service allows you to programatically define
13
- * when a request should be considered expired.
14
- *
15
- * @class (Interface) CachePolicy
16
- * @public
17
- */
18
- export interface CachePolicy {
19
- /**
20
- * Invoked to determine if the request may be fulfilled from cache
21
- * if possible.
22
- *
23
- * Note, this is only invoked if the request has a cache-key.
24
- *
25
- * If no cache entry is found or the entry is hard expired,
26
- * the request will be fulfilled from the configured request handlers
27
- * and the cache will be updated before returning the response.
28
- *
29
- * @public
30
- * @param {StableDocumentIdentifier} identifier
31
- * @param {Store} store
32
- * @return {Boolean} true if the request is considered hard expired
33
- */
34
- isHardExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
35
- /**
36
- * Invoked if `isHardExpired` is false to determine if the request
37
- * should be update behind the scenes if cache data is already available.
38
- *
39
- * Note, this is only invoked if the request has a cache-key.
40
- *
41
- * If true, the request will be fulfilled from cache while a backgrounded
42
- * request is made to update the cache via the configured request handlers.
43
- *
44
- * @public
45
- * @param {StableDocumentIdentifier} identifier
46
- * @param {Store} store
47
- * @return {Boolean} true if the request is considered soft expired
48
- */
49
- isSoftExpired(identifier: StableDocumentIdentifier, store: Store): boolean;
50
- /**
51
- * Invoked when a request will be sent to the configured request handlers.
52
- * This is invoked for both foreground and background requests.
53
- *
54
- * Note, this is invoked regardless of whether the request has a cache-key.
55
- *
56
- * @public
57
- * @param {ImmutableRequestInfo} request
58
- * @param {StableDocumentIdentifier | null} identifier
59
- * @param {Store} store
60
- * @return {void}
61
- */
62
- willRequest?(request: ImmutableRequestInfo, identifier: StableDocumentIdentifier | null, store: Store): void;
63
- /**
64
- * Invoked when a request has been fulfilled from the configured request handlers.
65
- * This is invoked for both foreground and background requests once the cache has
66
- * been updated.
67
- *
68
- * Note, this is invoked regardless of whether the request has a cache-key.
69
- *
70
- * It is best practice to notify the store of any requests marked as invalidated
71
- * so that request subscriptions can reload when needed.
72
- *
73
- * ```ts
74
- * store.notifications.notify(identifier, 'invalidated');
75
- * ```
76
- *
77
- * This allows anything subscribed to the request to be notified of the change
78
- *
79
- * e.g.
80
- *
81
- * ```ts
82
- * store.notifications.subscribe(identifier, (_, type) => {
83
- * if (type === 'invalidated') {
84
- * // do update
85
- * }
86
- * });
87
- * ```
88
- *
89
- *
90
- * @public
91
- * @param {ImmutableRequestInfo} request
92
- * @param {ImmutableResponse} response
93
- * @param {StableDocumentIdentifier | null} identifier
94
- * @param {Store} store
95
- * @return {void}
96
- */
97
- didRequest?(request: ImmutableRequestInfo, response: Response | ResponseInfo | null, identifier: StableDocumentIdentifier | null, store: Store): void;
98
- }
@@ -1,32 +0,0 @@
1
- import type { StableDocumentIdentifier } from "../../../types/identifier.js";
2
- import type { ImmutableCreateRequestOptions, ImmutableDeleteRequestOptions, ImmutableRequestInfo, ImmutableUpdateRequestOptions, StructuredDataDocument } from "../../../types/request.js";
3
- import type { ResourceDataDocument, ResourceErrorDocument } from "../../../types/spec/document.js";
4
- import type { ApiError } from "../../../types/spec/error.js";
5
- import type { Store } from "../store-service.js";
6
- export declare const MUTATION_OPS: Set<string>;
7
- export declare function calcShouldFetch(store: Store, request: ImmutableRequestInfo, hasCachedValue: boolean, identifier: StableDocumentIdentifier | null): boolean;
8
- export declare function calcShouldBackgroundFetch(store: Store, request: ImmutableRequestInfo, willFetch: boolean, identifier: StableDocumentIdentifier | null): boolean;
9
- export declare function isMutation(request: Partial<ImmutableRequestInfo>): request is ImmutableUpdateRequestOptions | ImmutableCreateRequestOptions | ImmutableDeleteRequestOptions;
10
- export declare function isCacheAffecting<T>(document: StructuredDataDocument<T>): boolean;
11
- export declare function isAggregateError(error: Error & {
12
- errors?: ApiError[];
13
- }): error is AggregateError & {
14
- errors: ApiError[];
15
- };
16
- export type RobustError = Error & {
17
- error: string | object;
18
- errors?: ApiError[];
19
- content?: unknown;
20
- };
21
- // TODO @runspired, consider if we should deep freeze errors (potentially only in debug) vs cloning them
22
- export declare function cloneError(error: RobustError): RobustError;
23
- export declare function isErrorDocument(document: ResourceDataDocument | ResourceErrorDocument): document is ResourceErrorDocument;
24
- export declare function getPriority(identifier: StableDocumentIdentifier | null, deduped: Map<StableDocumentIdentifier, {
25
- priority: {
26
- blocking: boolean;
27
- };
28
- }>, priority: {
29
- blocking: boolean;
30
- }): {
31
- blocking: boolean;
32
- };
@@ -1,12 +0,0 @@
1
- import type { Cache } from "../../../types/cache.js";
2
- import type { StableRecordIdentifier } from "../../../types/identifier.js";
3
- import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
4
- /*
5
- * Returns the Cache instance associated with a given
6
- * Model or Identifier
7
- */
8
- export declare const CacheForIdentifierCache: Map<unknown, Cache>;
9
- export declare function setCacheFor(identifier: StableRecordIdentifier | OpaqueRecordInstance, cache: Cache): void;
10
- export declare function removeRecordDataFor(identifier: StableRecordIdentifier | OpaqueRecordInstance): void;
11
- export declare function peekCache(instance: StableRecordIdentifier): Cache | null;
12
- export declare function peekCache(instance: OpaqueRecordInstance): Cache;
@@ -1,304 +0,0 @@
1
- import { type Identifier, type RecordIdentifier, type StableDocumentIdentifier, type StableExistingRecordIdentifier, type StableRecordIdentifier } from "../../../types/identifier.js";
2
- import type { ImmutableRequestInfo } from "../../../types/request.js";
3
- import type { ExistingResourceIdentifierObject, ResourceIdentifierObject } from "../../../types/spec/json-api-raw.js";
4
- import type { ForgetMethod, GenerationMethod, KeyInfo, KeyInfoMethod, ResetMethod, UpdateMethod } from "../../-types/q/identifier.js";
5
- type TypeFromIdentifier<T> = T extends {
6
- type: infer U;
7
- } ? U : string;
8
- type NarrowIdentifierIfPossible<T> = T extends ExistingResourceIdentifierObject ? StableExistingRecordIdentifier<TypeFromIdentifier<T>> : StableRecordIdentifier;
9
- export declare function isStableIdentifier(identifier: unknown): identifier is StableRecordIdentifier;
10
- export declare function isDocumentIdentifier(identifier: unknown): identifier is StableDocumentIdentifier;
11
- interface KeyOptions {
12
- lid: IdentifierMap;
13
- id: IdentifierMap;
14
- }
15
- type TypeMap = {
16
- [key: string]: KeyOptions;
17
- };
18
- // type IdentifierTypeLookup = { all: Set<StableRecordIdentifier>; id: Map<string, StableRecordIdentifier> };
19
- // type IdentifiersByType = Map<string, IdentifierTypeLookup>;
20
- type IdentifierMap = Map<string, StableRecordIdentifier>;
21
- type StableCache = {
22
- resources: IdentifierMap;
23
- documents: Map<string, StableDocumentIdentifier>;
24
- resourcesByType: TypeMap;
25
- polymorphicLidBackMap: Map<string, string[]>;
26
- };
27
- export type MergeMethod = (targetIdentifier: StableRecordIdentifier, matchedIdentifier: StableRecordIdentifier, resourceData: unknown) => StableRecordIdentifier;
28
- /**
29
- Configures how unique identifier lid strings are generated by @ember-data/store.
30
-
31
- This configuration MUST occur prior to the store instance being created.
32
-
33
- Takes a method which can expect to receive various data as its first argument
34
- and the name of a bucket as its second argument.
35
-
36
- Currently there are two buckets, 'record' and 'document'.
37
-
38
- ### Resource (`Record`) Identity
39
-
40
- If the bucket is `record` the method must return a unique (to at-least
41
- the given bucket) string identifier for the given data as a string to be
42
- used as the `lid` of an `Identifier` token.
43
-
44
- This method will only be called by either `getOrCreateRecordIdentifier` or
45
- `createIdentifierForNewRecord` when an identifier for the supplied data
46
- is not already known via `lid` or `type + id` combo and one needs to be
47
- generated or retrieved from a proprietary cache.
48
-
49
- `data` will be the same data argument provided to `getOrCreateRecordIdentifier`
50
- and in the `createIdentifierForNewRecord` case will be an object with
51
- only `type` as a key.
52
-
53
- ```ts
54
- import { setIdentifierGenerationMethod } from '@warp-drive/core';
55
-
56
- export function initialize(applicationInstance) {
57
- // note how `count` here is now scoped to the application instance
58
- // for our generation method by being inside the closure provided
59
- // by the initialize function
60
- let count = 0;
61
-
62
- setIdentifierGenerationMethod((resource, bucket) => {
63
- return resource.lid || `my-key-${count++}`;
64
- });
65
- }
66
-
67
- export default {
68
- name: 'configure-ember-data-identifiers',
69
- initialize
70
- };
71
- ```
72
-
73
- ### Document Identity
74
-
75
- If the bucket is `document` the method will receive the associated
76
- immutable `request` passed to `store.request` as its first argument
77
- and should return a unique string for the given request if the document
78
- should be cached, and `null` if it should not be cached.
79
-
80
- Note, the request result will still be passed to the cache via `Cache.put`,
81
- but caches should take this as a signal that the document should not itself
82
- be cached, while its contents may still be used to update other cache state.
83
-
84
- The presence of `cacheOptions.key` on the request will take precedence
85
- for the document cache key, and this method will not be called if it is
86
- present.
87
-
88
- The default method implementation for this bucket is to return `null`
89
- for all requests whose method is not `GET`, and to return the `url` for
90
- those where it is.
91
-
92
- This means that queries via `POST` MUST provide `cacheOptions.key` or
93
- implement this hook.
94
-
95
- ⚠️ Caution: Requests that do not have a `method` assigned are assumed to be `GET`
96
-
97
- @public
98
- */
99
- export declare function setIdentifierGenerationMethod(method: GenerationMethod | null): void;
100
- /**
101
- Configure a callback for when the identifier cache encounters new resource
102
- data for an existing resource.
103
-
104
- This configuration MUST occur prior to the store instance being created.
105
-
106
- ```js
107
- import { setIdentifierUpdateMethod } from '@warp-drive/core';
108
- ```
109
-
110
- Takes a method which can expect to receive an existing `Identifier` alongside
111
- some new data to consider as a second argument. This is an opportunity
112
- for secondary lookup tables and caches associated with the identifier
113
- to be amended.
114
-
115
- This method is called everytime `updateRecordIdentifier` is called and
116
- with the same arguments. It provides the opportunity to update secondary
117
- lookup tables for existing identifiers.
118
-
119
- It will always be called after an identifier created with `createIdentifierForNewRecord`
120
- has been committed, or after an update to the `record` a `RecordIdentifier`
121
- is assigned to has been committed. Committed here meaning that the server
122
- has acknowledged the update (for instance after a call to `.save()`)
123
-
124
- If `id` has not previously existed, it will be assigned to the `Identifier`
125
- prior to this `UpdateMethod` being called; however, calls to the parent method
126
- `updateRecordIdentifier` that attempt to change the `id` or calling update
127
- without providing an `id` when one is missing will throw an error.
128
-
129
- @public
130
- */
131
- export declare function setIdentifierUpdateMethod(method: UpdateMethod | null): void;
132
- /**
133
- Configure a callback for when the identifier cache is going to release an identifier.
134
-
135
- This configuration MUST occur prior to the store instance being created.
136
-
137
- ```js
138
- import { setIdentifierForgetMethod } from '@warp-drive/core';
139
- ```
140
-
141
- Takes method which can expect to receive an existing `Identifier` that should be eliminated
142
- from any secondary lookup tables or caches that the user has populated for it.
143
-
144
- @public
145
- */
146
- export declare function setIdentifierForgetMethod(method: ForgetMethod | null): void;
147
- /**
148
- Configure a callback for when the identifier cache is being torn down.
149
-
150
- This configuration MUST occur prior to the store instance being created.
151
-
152
- ```js
153
- import { setIdentifierResetMethod } from '@warp-drive/core';
154
- ```
155
-
156
- Takes a method which can expect to be called when the parent application is destroyed.
157
-
158
- If you have properly used a WeakMap to encapsulate the state of your customization
159
- to the application instance, you may not need to implement the `resetMethod`.
160
-
161
- @public
162
- */
163
- export declare function setIdentifierResetMethod(method: ResetMethod | null): void;
164
- /**
165
- Configure a callback for when the identifier cache is generating a new
166
- StableRecordIdentifier for a resource.
167
-
168
- This method controls the `type` and `id` that will be assigned to the
169
- `StableRecordIdentifier` that is created.
170
-
171
- This configuration MUST occur prior to the store instance being created.
172
-
173
- ```js
174
- import { setKeyInfoForResource } from '@warp-drive/core';
175
- ```
176
-
177
- @public
178
- */
179
- export declare function setKeyInfoForResource(method: KeyInfoMethod | null): void;
180
- /**
181
- * Each instance of {@link Store} receives a unique instance of a IdentifierCache.
182
- *
183
- * This cache is responsible for assigning or retrieving the unique identify
184
- * for arbitrary resource data encountered by the store. Data representing
185
- * a unique resource or record should always be represented by the same
186
- * identifier.
187
- *
188
- * It can be configured by consuming applications.
189
- *
190
- * @hideconstructor
191
- * @public
192
- */
193
- export declare class IdentifierCache {
194
- /** @internal */
195
- _cache: StableCache;
196
- private _generate;
197
- private _update;
198
- private _forget;
199
- private _reset;
200
- private _merge;
201
- private _keyInfoForResource;
202
- private _id;
203
- constructor();
204
- /**
205
- * Internal hook to allow management of merge conflicts with identifiers.
206
- *
207
- * we allow late binding of this private internal merge so that
208
- * the cache can insert itself here to handle elimination of duplicates
209
- *
210
- * @private
211
- */
212
- __configureMerge(method: MergeMethod | null): void;
213
- /** @internal */
214
- upgradeIdentifier(resource: {
215
- type: string;
216
- id: string | null;
217
- lid?: string;
218
- }): StableRecordIdentifier;
219
- /**
220
- * @private
221
- */
222
- private _getRecordIdentifier;
223
- private _getRecordIdentifier;
224
- private _getRecordIdentifier;
225
- /**
226
- * allows us to peek without generating when needed
227
- * useful for the "create" case when we need to see if
228
- * we are accidentally overwritting something
229
- *
230
- * @private
231
- */
232
- peekRecordIdentifier(resource: ResourceIdentifierObject | Identifier): StableRecordIdentifier | undefined;
233
- /**
234
- Returns the DocumentIdentifier for the given Request, creates one if it does not yet exist.
235
- Returns `null` if the request does not have a `cacheKey` or `url`.
236
-
237
- @public
238
- */
239
- getOrCreateDocumentIdentifier(request: ImmutableRequestInfo): StableDocumentIdentifier | null;
240
- /**
241
- Returns the Identifier for the given Resource, creates one if it does not yet exist.
242
-
243
- Specifically this means that we:
244
-
245
- - validate the `id` `type` and `lid` combo against known identifiers
246
- - return an object with an `lid` that is stable (repeated calls with the same
247
- `id` + `type` or `lid` will return the same `lid` value)
248
- - this referential stability of the object itself is guaranteed
249
-
250
- @public
251
- */
252
- getOrCreateRecordIdentifier<T>(resource: T): NarrowIdentifierIfPossible<T>;
253
- /**
254
- Returns a new Identifier for the supplied data. Call this method to generate
255
- an identifier when a new resource is being created local to the client and
256
- potentially does not have an `id`.
257
-
258
- Delegates generation to the user supplied `GenerateMethod` if one has been provided
259
- with the signature `generateMethod({ type }, 'record')`.
260
-
261
- @public
262
- */
263
- createIdentifierForNewRecord(data: {
264
- type: string;
265
- id?: string | null;
266
- }): StableRecordIdentifier;
267
- /**
268
- Provides the opportunity to update secondary lookup tables for existing identifiers
269
- Called after an identifier created with `createIdentifierForNewRecord` has been
270
- committed.
271
-
272
- Assigned `id` to an `Identifier` if `id` has not previously existed; however,
273
- attempting to change the `id` or calling update without providing an `id` when
274
- one is missing will throw an error.
275
-
276
- - sets `id` (if `id` was previously `null`)
277
- - `lid` and `type` MUST NOT be altered post creation
278
-
279
- If a merge occurs, it is possible the returned identifier does not match the originally
280
- provided identifier. In this case the abandoned identifier will go through the usual
281
- `forgetRecordIdentifier` codepaths.
282
-
283
- @public
284
- */
285
- updateRecordIdentifier(identifierObject: RecordIdentifier, data: unknown): StableRecordIdentifier;
286
- /**
287
- * @private
288
- */
289
- _mergeRecordIdentifiers(keyInfo: KeyInfo, identifier: StableRecordIdentifier, existingIdentifier: StableRecordIdentifier, data: unknown): StableRecordIdentifier;
290
- /**
291
- Provides the opportunity to eliminate an identifier from secondary lookup tables
292
- as well as eliminates it from ember-data's own lookup tables and book keeping.
293
-
294
- Useful when a record has been deleted and the deletion has been persisted and
295
- we do not care about the record anymore. Especially useful when an `id` of a
296
- deleted record might be reused later for a new record.
297
-
298
- @public
299
- */
300
- forgetRecordIdentifier(identifierObject: RecordIdentifier): void;
301
- /** @internal */
302
- destroy(): void;
303
- }
304
- export {};
@@ -1,65 +0,0 @@
1
- import { ReactiveDocument } from "../../../reactive/-private/document.js";
2
- import type { Cache } from "../../../types/cache.js";
3
- import type { StableDocumentIdentifier, StableRecordIdentifier } from "../../../types/identifier.js";
4
- import type { Value } from "../../../types/json/raw.js";
5
- import type { TypedRecordInstance, TypeFromInstance } from "../../../types/record.js";
6
- import type { OpaqueRecordInstance } from "../../-types/q/record-instance.js";
7
- import RecordReference from "../legacy-model-support/record-reference.js";
8
- import { CacheCapabilitiesManager } from "../managers/cache-capabilities-manager.js";
9
- import type { CacheManager } from "../managers/cache-manager.js";
10
- import type { CreateRecordProperties, Store } from "../store-service.js";
11
- export declare function peekRecordIdentifier(record: OpaqueRecordInstance): StableRecordIdentifier | undefined;
12
- /**
13
- Retrieves the unique referentially-stable [RecordIdentifier](/ember-data/release/classes/StableRecordIdentifier)
14
- assigned to the given record instance.
15
-
16
- ```js
17
- import { recordIdentifierFor } from "@ember-data/store";
18
- // ... gain access to a record, for instance with peekRecord or findRecord
19
- const record = store.peekRecord("user", "1");
20
- // get the identifier for the record (see docs for StableRecordIdentifier)
21
- const identifier = recordIdentifierFor(record);
22
- // access the identifier's properties.
23
- const { id, type, lid } = identifier;
24
- ```
25
-
26
- @public
27
- @param {Object} record a record instance previously obstained from the store.
28
- @return {StableRecordIdentifier}
29
- */
30
- export declare function recordIdentifierFor<T extends TypedRecordInstance>(record: T): StableRecordIdentifier<TypeFromInstance<T>>;
31
- export declare function recordIdentifierFor(record: OpaqueRecordInstance): StableRecordIdentifier;
32
- export declare function setRecordIdentifier(record: OpaqueRecordInstance, identifier: StableRecordIdentifier): void;
33
- export declare const StoreMap: Map<unknown, Store>;
34
- /**
35
- * We may eventually make this public, but its likely better for this to be killed off
36
- * @internal
37
- */
38
- export declare function storeFor(record: OpaqueRecordInstance): Store | undefined;
39
- type Caches = {
40
- record: Map<StableRecordIdentifier, OpaqueRecordInstance>;
41
- reference: WeakMap<StableRecordIdentifier, RecordReference>;
42
- document: Map<StableDocumentIdentifier, ReactiveDocument<OpaqueRecordInstance | OpaqueRecordInstance[] | null | undefined>>;
43
- };
44
- export declare class InstanceCache {
45
- store: Store;
46
- cache: Cache;
47
- _storeWrapper: CacheCapabilitiesManager;
48
- __cacheManager: CacheManager;
49
- __instances: Caches;
50
- constructor(store: Store);
51
- peek(identifier: StableRecordIdentifier): Cache | OpaqueRecordInstance | undefined;
52
- getDocument<T>(identifier: StableDocumentIdentifier): ReactiveDocument<T>;
53
- getRecord(identifier: StableRecordIdentifier, properties?: CreateRecordProperties): OpaqueRecordInstance;
54
- getReference(identifier: StableRecordIdentifier): RecordReference;
55
- recordIsLoaded(identifier: StableRecordIdentifier, filterDeleted?: boolean): boolean;
56
- disconnect(identifier: StableRecordIdentifier): void;
57
- unloadRecord(identifier: StableRecordIdentifier): void;
58
- clear(type?: string): void;
59
- // TODO this should move into something coordinating operations
60
- setRecordId(identifier: StableRecordIdentifier, id: string): void;
61
- }
62
- export declare function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: StableRecordIdentifier): boolean;
63
- export declare function preloadData(store: Store, identifier: StableRecordIdentifier, preload: Record<string, Value>): void;
64
- export declare function _clearCaches(): void;
65
- export {};
@@ -1,9 +0,0 @@
1
- export declare function hasLid(resource: unknown): resource is {
2
- lid: string;
3
- };
4
- export declare function hasId(resource: unknown): resource is {
5
- id: string;
6
- };
7
- export declare function hasType(resource: unknown): resource is {
8
- type: string;
9
- };
@@ -1,6 +0,0 @@
1
- export declare function logGroup(scope: "cache", prefix: string, type: string, lid: string, bucket: string, key: string): void;
2
- export declare function logGroup(scope: "reactive-ui", prefix: string, type: string, lid: string, bucket: string, key: ""): void;
3
- export declare function logGroup(scope: "notify", prefix: string, type: string, lid: string, bucket: string, key: string): void;
4
- export declare function log(scope: "cache", prefix: string, type: string, lid: string, bucket: string, key: string): void;
5
- export declare function log(scope: "reactive-ui", prefix: string, type: string, lid: string, bucket: string, key: ""): void;
6
- export declare function log(scope: "notify", prefix: string, type: string, lid: string, bucket: string, key: string): void;