@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,107 +0,0 @@
1
- import type { StableRecordIdentifier } from "../../../types/identifier.js";
2
- import type { FindRecordOptions } from "../../-types/q/store.js";
3
- import type { Store } from "../store-service.js";
4
- declare const Touching: "___(unique) Symbol(Touching)";
5
- export declare const RequestPromise: "___(unique) Symbol(RequestPromise)";
6
- export interface Operation {
7
- op: string;
8
- options: FindRecordOptions | undefined;
9
- recordIdentifier: StableRecordIdentifier;
10
- }
11
- export interface FindRecordQuery extends Operation {
12
- op: "findRecord";
13
- }
14
- export interface SaveRecordMutation extends Operation {
15
- op: "saveRecord";
16
- }
17
- export interface Request {
18
- data: Operation[];
19
- options?: Record<string, unknown>;
20
- }
21
- export type RequestStates = "pending" | "fulfilled" | "rejected";
22
- export interface RequestCacheRequestState {
23
- state: RequestStates;
24
- type: "query" | "mutation";
25
- request: Request;
26
- response?: Response;
27
- }
28
- export interface Response {
29
- // rawData: unknown;
30
- data: unknown;
31
- }
32
- interface InternalRequest extends RequestCacheRequestState {
33
- [Touching]: StableRecordIdentifier[];
34
- [RequestPromise]?: Promise<unknown>;
35
- }
36
- export type RequestSubscription = (requestState: RequestCacheRequestState) => void;
37
- /**
38
- * The RequestStateService is used to track the state of requests
39
- * for fetching or updating known resource identifies that are inflight.
40
- *
41
- * @hideconstructor
42
- * @public
43
- */
44
- export declare class RequestStateService {
45
- /** @internal */
46
- _pending: Map<StableRecordIdentifier, InternalRequest[]>;
47
- private _done;
48
- private _subscriptions;
49
- private _toFlush;
50
- private _store;
51
- constructor(store: Store);
52
- /** @internal */
53
- _clearEntries(identifier: StableRecordIdentifier): void;
54
- /** @internal */
55
- _enqueue<T>(promise: Promise<T>, queryRequest: Request): Promise<T>;
56
- private _triggerSubscriptions;
57
- private _flush;
58
- private _flushRequest;
59
- private _dequeue;
60
- private _addDone;
61
- /**
62
- * Subscribe to requests for a given resource identity.
63
- *
64
- * The callback will receive the current state of the request.
65
- *
66
- * ```ts
67
- * interface RequestState {
68
- * state: 'pending' | 'fulfilled' | 'rejected';
69
- * type: 'query' | 'mutation';
70
- * request: Request;
71
- * response?: { data: unknown };
72
- * }
73
- * ```
74
- *
75
- * Note: It should be considered dangerous to use this API for more than simple
76
- * state derivation or debugging. The `request` and `response` properties are poorly
77
- * spec'd and may change unexpectedly when shifting what Handlers are in use or how
78
- * requests are issued from the Store.
79
- *
80
- * We expect to revisit this API in the near future as we continue to refine the
81
- * RequestManager ergonomics, as a simpler but more powerful direct integration
82
- * with the RequestManager for these purposes is likely to be a better long-term
83
- * design.
84
- *
85
- * @public
86
- * @param {StableRecordIdentifier} identifier
87
- * @param {(state: RequestCacheRequestState) => void} callback
88
- */
89
- subscribeForRecord(identifier: StableRecordIdentifier, callback: RequestSubscription): void;
90
- /**
91
- * Retrieve all active requests for a given resource identity.
92
- *
93
- * @public
94
- * @param {StableRecordIdentifier} identifier
95
- * @return {RequestCacheRequestState[]} an array of request states for any pending requests for the given identifier
96
- */
97
- getPendingRequestsForRecord(identifier: StableRecordIdentifier): RequestCacheRequestState[];
98
- /**
99
- * Retrieve the last completed request for a given resource identity.
100
- *
101
- * @public
102
- * @param {StableRecordIdentifier} identifier
103
- * @return {RequestCacheRequestState | null} the state of the most recent request for the given identifier
104
- */
105
- getLastRequestForRecord(identifier: StableRecordIdentifier): RequestCacheRequestState | null;
106
- }
107
- export {};
@@ -1,263 +0,0 @@
1
- import type { Awaitable } from "../../../request.js";
2
- /**
3
- * The state of a promise in the "pending"
4
- * state. This is the default initial state.
5
- *
6
- */
7
- export interface PendingPromise {
8
- /**
9
- * The status of the promise.
10
- *
11
- */
12
- status: "pending";
13
- /**
14
- * Whether the promise is pending.
15
- *
16
- */
17
- isPending: true;
18
- /**
19
- * Whether the promise is pending.
20
- *
21
- * @deprecated use `isPending` instead
22
- */
23
- isLoading: true;
24
- /**
25
- * Whether the promise has resolved
26
- * successfully.
27
- *
28
- */
29
- isSuccess: false;
30
- /**
31
- * Whether the promise has rejected
32
- * with an error.
33
- *
34
- */
35
- isError: false;
36
- /**
37
- * Once the promise has resolved, this will
38
- * be the value the promise resolved to.
39
- *
40
- */
41
- value: null;
42
- /**
43
- * Once the promise has resolved, this will
44
- * be the value the promise resolved to.
45
- *
46
- * @deprecated use `value` instead
47
- */
48
- result: null;
49
- /**
50
- * Once the promise has rejected, this will
51
- * be the error the promise rejected with.
52
- *
53
- *
54
- * @deprecated use `reason` instead
55
- */
56
- error: null;
57
- /**
58
- * Once the promise has rejected, this will
59
- * be the error the promise rejected with.
60
- *
61
- */
62
- reason: null;
63
- }
64
- /**
65
- * The state of a promise in the "fulfilled" state.
66
- * This is the state of a promise that has resolved
67
- * successfully.
68
- *
69
- */
70
- export interface ResolvedPromise<T> {
71
- /**
72
- * The status of the promise.
73
- *
74
- */
75
- status: "fulfilled";
76
- /**
77
- * Whether the promise is pending.
78
- *
79
- */
80
- isPending: false;
81
- /**
82
- * Whether the promise is pending.
83
- *
84
- * @deprecated use `isPending` instead
85
- */
86
- isLoading: false;
87
- /**
88
- * Whether the promise has resolved
89
- * successfully.
90
- *
91
- */
92
- isSuccess: true;
93
- /**
94
- * Whether the promise has rejected
95
- * with an error.
96
- *
97
- */
98
- isError: false;
99
- /**
100
- * Once the promise has resolved, this will
101
- * be the value the promise resolved to.
102
- *
103
- */
104
- value: T;
105
- /**
106
- * Once the promise has resolved, this will
107
- * be the value the promise resolved to.
108
- *
109
- * @deprecated use `value` instead
110
- */
111
- result: T;
112
- /**
113
- * Once the promise has rejected, this will
114
- * be the error the promise rejected with.
115
- *
116
- *
117
- * @deprecated use `reason` instead
118
- */
119
- error: null;
120
- /**
121
- * Once the promise has rejected, this will
122
- * be the error the promise rejected with.
123
- *
124
- */
125
- reason: null;
126
- }
127
- /**
128
- * The state of a promise in the "rejected" state.
129
- * This is the state of a promise that has rejected
130
- * with an error.
131
- *
132
- */
133
- export interface RejectedPromise<E> {
134
- /**
135
- * The status of the promise.
136
- *
137
- */
138
- status: "rejected";
139
- /**
140
- * Whether the promise is pending.
141
- *
142
- */
143
- isPending: false;
144
- /**
145
- * Whether the promise is pending.
146
- *
147
- * @deprecated use `isPending` instead
148
- */
149
- isLoading: false;
150
- /**
151
- * Whether the promise has resolved
152
- * successfully.
153
- *
154
- */
155
- isSuccess: false;
156
- /**
157
- * Whether the promise has rejected
158
- * with an error.
159
- *
160
- */
161
- isError: true;
162
- /**
163
- * Once the promise has resolved, this will
164
- * be the value the promise resolved to.
165
- *
166
- */
167
- value: null;
168
- /**
169
- * Once the promise has resolved, this will
170
- * be the value the promise resolved to.
171
- *
172
- * @deprecated use `value` instead
173
- */
174
- result: null;
175
- /**
176
- * Once the promise has rejected, this will
177
- * be the error the promise rejected with.
178
- *
179
- *
180
- * @deprecated use `reason` instead
181
- */
182
- error: E;
183
- /**
184
- * Once the promise has rejected, this will
185
- * be the error the promise rejected with.
186
- *
187
- */
188
- reason: E;
189
- }
190
- /**
191
- * The state of a promise. This is the type that is returned
192
- * from `getPromiseState`.
193
- *
194
- * See also:
195
- * - {@link PendingPromise}
196
- * - {@link ResolvedPromise}
197
- * - {@link RejectedPromise}
198
- *
199
- */
200
- export type PromiseState<
201
- T = unknown,
202
- E = unknown
203
- > = PendingPromise | ResolvedPromise<T> | RejectedPromise<E>;
204
- export declare function createPromiseState<
205
- T,
206
- E
207
- >(promise: Promise<T> | Awaitable<T, E>): Readonly<PromiseState<T, E>>;
208
- /**
209
- * Returns a reactive state-machine for the provided promise or awaitable.
210
- *
211
- * Repeat calls to `getPromiseState` with the same promise will return the same state object
212
- * making is safe and easy to use in templates and JavaScript code to produce reactive
213
- * behaviors around promises.
214
- *
215
- * `getPromiseState` can be used in both JavaScript and Template contexts.
216
- *
217
- * ```ts
218
- * import { getPromiseState } from '@warp-drive/ember';
219
- *
220
- * const state = getPromiseState(promise);
221
- * ```
222
- *
223
- * For instance, we could write a getter on a component that updates whenever
224
- * the promise state advances or the promise changes, by combining the function
225
- * with the use of `@cached`
226
- *
227
- * ```ts
228
- * class Component {
229
- * @cached
230
- * get title() {
231
- * const state = getPromiseState(this.args.request);
232
- * if (state.isPending) {
233
- * return 'loading...';
234
- * }
235
- * if (state.isError) { return null; }
236
- * return state.result.title;
237
- * }
238
- * }
239
- * ```
240
- *
241
- * Or in a template as a helper:
242
- *
243
- * ```gjs
244
- * import { getPromiseState } from '@warp-drive/ember';
245
- *
246
- * <template>
247
- * {{#let (getPromiseState @request) as |state|}}
248
- * {{#if state.isPending}} <Spinner />
249
- * {{else if state.isError}} <ErrorForm @error={{state.error}} />
250
- * {{else}}
251
- * <h1>{{state.result.title}}</h1>
252
- * {{/if}}
253
- * {{/let}}
254
- * </template>
255
- * ```
256
- *
257
- * If looking to use in a template, consider also the `<Await />` component.
258
- *
259
- */
260
- export declare function getPromiseState<
261
- T = unknown,
262
- E = unknown
263
- >(promise: Promise<T> | Awaitable<T, E>): Readonly<PromiseState<T, E>>;
@@ -1,176 +0,0 @@
1
- export declare const ARRAY_SIGNAL: "___(unique) Symbol(#[])";
2
- export declare const OBJECT_SIGNAL: "___(unique) Symbol(#{})";
3
- /**
4
- * Requirements:
5
- *
6
- * Signal:
7
- *
8
- * - signal: a way of creating a reference that we can dirty when we desire to notify
9
- * - @signal: a way of creating an accessor on an object that subscribes to a signal on access
10
- * and notifies the signal on set, or of upgrading a descriptor to be such an accessor
11
- * - defineSignal: a way of creating a signal on an object
12
- * - notifySignal: a way of notifying the underlying signal that it has been dirtied
13
- * - peekSignal: a way of inspecting the signal without notifying it
14
- *
15
- * - gate: a memoized getter function that re-runs when on access if its signal is dirty
16
- * conceptually, a gate is a tightly coupled signal and memo
17
- * - @gate: a way of creating a gate on an object or upgrading a descriptor with a getter
18
- * to be a gate
19
- * - defineGate: a way of creating a gate on an object
20
- * - notifySignal: a way of notifying the signal for a gate that it has been dirtied
21
- *
22
- * - memo:
23
- * - @memo: a way of creating a memoized getter on an object or upgrading a descriptor with a getter
24
- * to be a memo
25
- * - defineMemo: a way of creating a memo on an object
26
- *
27
- * - signalStore: storage bucket for signals associated to an object
28
- * - withSignalStore: a way of pre-creating a signal store on an object
29
- *
30
- *
31
- * @internal
32
- */
33
- /**
34
- * An Opaque type that represents a framework specific or TC39 signal.
35
- *
36
- * It may be an array of signals or a single signal.
37
- *
38
- * @internal
39
- */
40
- export type SignalRef = unknown;
41
- /**
42
- * The hooks which MUST be configured in order to use reactive arrays,
43
- * resources and documents with framework specfic signals or TC39 signals.
44
- *
45
- * Support for multiple frameworks simultaneously can be done via
46
- * this abstraction by returning multiple signals from the `createSignal`
47
- * method, and consuming the correct one via the correct framework via
48
- * the `consumeSignal` and `notifySignal` methods.
49
- *
50
- * Unlike many signals implementations, WarpDrive does not wrap values as
51
- * signals directly, but instead uses signals to alert the reactive layer
52
- * to changes in the underlying cache. E.g. a signal is associated to a value,
53
- * but does not serve as the cache for that value directly. We refer to this as
54
- * a "gate", the pattern has also been called "side-signals".
55
- *
56
- * A no-op implementation is allowed, though it may lead to performance issues
57
- * in locations that use createMemo as no memoization would be done. This is
58
- * typically desirable only when integrating with a framework that does its own
59
- * memoization and does not integrate with any signals-like primitive. For these
60
- * scenarios you may also be interested in integrating with the {@link NotificationManager}
61
- * more directly.
62
- *
63
- * @public
64
- */
65
- export interface SignalHooks<T = SignalRef> {
66
- /**
67
- * Create a signal for the given key associated to the given object.
68
- *
69
- * This method does *not* need to cache the signal, it will only be
70
- * called once for a given object and key. However, if your framework
71
- * will look for a signal cache on the object in a given location or may
72
- * have created its own signal on the object for some reason it may be
73
- * useful to ensure such cache is properly updated.
74
- */
75
- createSignal: (obj: object, key: string | symbol) => T;
76
- /**
77
- * Consume (mark as acccessed) a signal previously created via createSignal.
78
- */
79
- consumeSignal: (signal: T) => void;
80
- /**
81
- * Alert a signal previously created via createSignal that its associated value has changed.
82
- */
83
- notifySignal: (signal: T) => void;
84
- /**
85
- * Take the given function and wrap it in signals-based memoization. Analagous
86
- * to a Computed in the TC39 spec.
87
- *
88
- * Should return a function which when run provides the latest value of the original
89
- * function.
90
- */
91
- createMemo: <F>(obj: object, key: string | symbol, fn: () => F) => () => F;
92
- /**
93
- * If the signals implementation allows synchronous flushing of watchers, and
94
- * has scheduled such a flush (e.g. watchers will run before the current calling
95
- * context yields) this should return "true".
96
- *
97
- * This is generally something that should return false for anything but the few
98
- * frameworks that extensively handle their own reactivity => render scheduling.
99
- *
100
- * For an example, see EmberJS's backburner scheduler which functioned as a microtask
101
- * polyfill.
102
- */
103
- willSyncFlushWatchers: () => boolean;
104
- /**
105
- * An optional method that allows wrapping key promises within WarpDrive
106
- * for things like test-waiters.
107
- */
108
- waitFor?: <K>(promise: Promise<K>) => Promise<K>;
109
- }
110
- /**
111
- * Contains information a {@link SignalHooks} implementation may want
112
- * to use, such as the specialized key used for the signal
113
- * representing an array's contents / length.
114
- *
115
- * ```ts
116
- * interface HooksOptions {
117
- * wellknown: {
118
- * Array: symbol | string;
119
- * }
120
- * }
121
- * ```
122
- *
123
- * @public
124
- */
125
- export interface HooksOptions {
126
- /**
127
- * A list of specialized symbols/strings
128
- * used by WarpDrive to encapsulate key
129
- * reactivity concerns.
130
- */
131
- wellknown: {
132
- /**
133
- * The key used when the signal provides reactivity for the
134
- * `length` or "contents" of an array.
135
- *
136
- * Arrays only use a single signal for all accesses, regardless
137
- * of index, property or method: this one.
138
- */
139
- Array: symbol | string;
140
- };
141
- }
142
- /**
143
- * Configures the signals implementation to use. Supports multiple
144
- * implementations simultaneously.
145
- *
146
- * See {@link HooksOptions} for the options passed to the provided function
147
- * when called.
148
- *
149
- * See {@link SignalHooks} for the implementation the callback function should
150
- * return.
151
- *
152
- * @public
153
- * @param buildConfig - a function that takes options and returns a configuration object
154
- */
155
- export declare function setupSignals<T>(buildConfig: (options: HooksOptions) => SignalHooks<T>): void;
156
- /**
157
- * Internal method for consuming the configured `createSignal` hook
158
- *
159
- * @internal
160
- */
161
- export declare function createSignal(obj: object, key: string | symbol): SignalRef;
162
- /**
163
- * Internal method for consuming the configured `consumeSignal` hook
164
- *
165
- * @internal
166
- */
167
- export declare function consumeSignal(signal: SignalRef): void;
168
- /**
169
- * Internal method for consuming the configured `notifySignal` hook
170
- *
171
- * @internal
172
- */
173
- export declare function notifySignal(signal: SignalRef): void;
174
- export declare function createMemo<T>(object: object, key: string | symbol, fn: () => T): () => T;
175
- export declare function willSyncFlushWatchers(): boolean;
176
- export declare function waitFor<K>(promise: Promise<K>): Promise<K>;
@@ -1,169 +0,0 @@
1
- import { ARRAY_SIGNAL, OBJECT_SIGNAL, type SignalRef } from "./configure.js";
2
- export type { SignalRef };
3
- export { ARRAY_SIGNAL, OBJECT_SIGNAL };
4
- /**
5
- * A WarpDriveSignal is a wrapper around a framework specific or TC39 signal
6
- * that enables us to store and manage the signal in a universal way.
7
- *
8
- * WarpDrive uses signals to manage three separate concepts:
9
- *
10
- * - as a `storage` for a value local to the object that we want to be reactive
11
- * (see `@local` schema field for an example)
12
- * - as a `gate` for a memoized getter that we want to act as a reactive property
13
- * but whose value is computed/pulled from a non-reactive source elsewhere
14
- * and whose latest value is stored in the signal
15
- * (see `field` schema field for an example)
16
- * - as a `gate` with a manually managed value updated on pull when `isStale` is true
17
- *
18
- *
19
- * It offers
20
- *
21
- * - a non-reactive way to access/update the current value
22
- * - a non-reactive way to mark the signal as dirtied
23
- * - a non-reactive way to store content for why the signal was dirtied
24
- * - access to the underlying Signal(s) in-use
25
- *
26
- * For debugging:
27
- * - the "key" or "name" of the signal
28
- * - the "object identity" or "context" to which the signal is attached
29
- *
30
- * @internal
31
- */
32
- export interface WarpDriveSignal {
33
- /**
34
- * The "key" or "name" of the signal.
35
- * This is usually (but not always) the name of a property
36
- * on the object to which the signal is attached.
37
- *
38
- * This is used for debugging purposes.
39
- * It is not used for any other purpose.
40
- *
41
- * @internal
42
- */
43
- key: string | symbol;
44
- /**
45
- * The "object identity" or "context" to which the
46
- * signal is attached.
47
- *
48
- * This is used for debugging purposes.
49
- * It is not used for any other purpose.
50
- *
51
- * @internal
52
- */
53
- context: object;
54
- /**
55
- * The underlying signal(s) in-use.
56
- *
57
- * Generally, this is a single signal.
58
- *
59
- * In some cases multiple signals need to be condensed,
60
- * such as to support legacy Ember Array APIs or to
61
- * support reactive-objects shared between the code of
62
- * multiple frameworks.
63
- *
64
- * In such cases, this value may be an array.
65
- *
66
- * e.g. (pseudo-code for Ember):
67
- *
68
- * setupSignals({
69
- * createSignal: (obj, key, initialValue) => {
70
- * if (isArraySignal(key)) {
71
- * return [
72
- * tagForProperty(obj, key),
73
- * tagForProperty(obj, '[]'),
74
- * tagForProperty(obj, 'length'),
75
- * ];
76
- * }
77
- * return tagForProperty(obj, key);
78
- * },
79
- *
80
- * consumeSignal: (signal) => {
81
- * if (Array.isArray(signal)) {
82
- * signal.forEach((s) => consumeTag(s));
83
- * } else {
84
- * consumeTag(signal);
85
- * }
86
- * },
87
- *
88
- * dirtySignal: (signal) => {
89
- * if (Array.isArray(signal)) {
90
- * signal.forEach((s) => dirtyTag(s));
91
- * } else {
92
- * dirtyTag(signal);
93
- * }
94
- * },
95
- * });
96
- *
97
- * @internal
98
- */
99
- signal: SignalRef;
100
- /**
101
- * The last "value" computed for this signal when
102
- * a signal is also used for storage.
103
- *
104
- * @internal
105
- */
106
- value: unknown;
107
- /**
108
- * Whether ths signal is known to have been dirtied.
109
- * This is useful *both* when manually managing the
110
- * `value` cache and when using the signal as a
111
- * "gate"
112
- *
113
- * @internal
114
- */
115
- isStale: boolean;
116
- }
117
- /**
118
- * We attach signals to their context object via
119
- * a Map attached to the object via this symbol.
120
- *
121
- * This allows us to store multiple signals
122
- * on the same object with smaller memory
123
- * overhead and no WeakMap lookups.
124
- *
125
- * Performance sensitive objects should
126
- * pre-warm their shape by assigning this
127
- * during initialization.
128
- *
129
- * ```ts
130
- * initializeSignalStore(obj);
131
- * ```
132
- *
133
- * @internal
134
- */
135
- export declare const Signals: "___(unique) Symbol(Signals)";
136
- export type SignalStore = Map<string | symbol, WarpDriveSignal>;
137
- /**
138
- * A type util to recast the object as having a signal store.
139
- *
140
- * @internal
141
- */
142
- export declare function upgradeWithSignals<T extends object>(obj: T): asserts obj is T & {
143
- [Signals]: SignalStore;
144
- };
145
- /**
146
- * A util that will create a signal store on the object
147
- * if it does not already exist and returns the associated
148
- * signal store.
149
- *
150
- * @internal
151
- */
152
- export declare function withSignalStore<T extends object>(obj: T): SignalStore;
153
- /**
154
- * A util that will create a signal store on the object
155
- * if it does not already exist.
156
- *
157
- * Useful for pre-warming the shape of an object to ensure
158
- * a key-transition to add it is not required later.
159
- *
160
- * @internal
161
- */
162
- export declare function initializeSignalStore<T extends object>(obj: T): asserts obj is T & {
163
- [Signals]: SignalStore;
164
- };
165
- export declare function createInternalSignal(signals: SignalStore, obj: object, key: string | symbol, initialValue: unknown): WarpDriveSignal;
166
- export declare function getOrCreateInternalSignal(signals: SignalStore, obj: object, key: string | symbol, initialValue: unknown): WarpDriveSignal;
167
- export declare function peekInternalSignal(signals: SignalStore | undefined, key: string | symbol): WarpDriveSignal | undefined;
168
- export declare function consumeInternalSignal(signal: WarpDriveSignal): void;
169
- export declare function notifyInternalSignal(signal: WarpDriveSignal | undefined): void;