@warp-drive/core 5.8.0-alpha.4 → 5.8.0-alpha.40

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 (248) hide show
  1. package/README.md +22 -38
  2. package/declarations/build-config.d.ts +18 -1
  3. package/declarations/graph/-private/-edge-definition.d.ts +12 -2
  4. package/declarations/index.d.ts +90 -8
  5. package/declarations/reactive/-private/document.d.ts +58 -46
  6. package/declarations/reactive/-private/record.d.ts +10 -1
  7. package/declarations/reactive/-private/schema.d.ts +77 -4
  8. package/declarations/reactive/-private.d.ts +1 -0
  9. package/declarations/reactive.d.ts +13 -7
  10. package/declarations/request/-private/types.d.ts +1 -1
  11. package/declarations/request.d.ts +47 -0
  12. package/declarations/store/-private/caches/instance-cache.d.ts +5 -6
  13. package/declarations/store/-private/default-cache-policy.d.ts +147 -129
  14. package/declarations/store/-private/managers/cache-capabilities-manager.d.ts +1 -1
  15. package/declarations/store/-private/managers/cache-key-manager.d.ts +26 -8
  16. package/declarations/store/-private/managers/cache-manager.d.ts +6 -4
  17. package/declarations/store/-private/managers/notification-manager.d.ts +1 -1
  18. package/declarations/store/-private/new-core-tmp/promise-state.d.ts +1 -0
  19. package/declarations/store/-private/new-core-tmp/request-state.d.ts +1 -1
  20. package/declarations/store/-private/store-service.d.ts +43 -64
  21. package/declarations/store/-private.d.ts +0 -1
  22. package/declarations/store/-types/q/cache-capabilities-manager.d.ts +1 -1
  23. package/declarations/store/deprecated/-private.d.ts +1 -1
  24. package/declarations/store/deprecated/store.d.ts +33 -32
  25. package/declarations/store.d.ts +1 -0
  26. package/declarations/types/cache.d.ts +8 -6
  27. package/declarations/types/record.d.ts +132 -0
  28. package/declarations/types/request.d.ts +26 -14
  29. package/declarations/types/schema/fields.d.ts +33 -9
  30. package/declarations/{store/-types/q → types/schema}/schema-service.d.ts +15 -13
  31. package/declarations/types/spec/document.d.ts +34 -0
  32. package/declarations/types/symbols.d.ts +2 -2
  33. package/declarations/types.d.ts +1 -1
  34. package/dist/build-config.js +1 -1
  35. package/dist/default-cache-policy-D7_u4YRH.js +572 -0
  36. package/dist/graph/-private.js +13 -4
  37. package/dist/{request-state-CUuZzgvE.js → index-BKcD4JZK.js} +10018 -8847
  38. package/dist/index.js +6 -382
  39. package/dist/reactive.js +4 -778
  40. package/dist/{context-C_7OLieY.js → request-oqoLC9rz.js} +219 -172
  41. package/dist/request.js +1 -1
  42. package/dist/store/-private.js +1 -1
  43. package/dist/store.js +1 -533
  44. package/dist/types/-private.js +1 -1
  45. package/dist/types/record.js +127 -0
  46. package/dist/types/request.js +14 -12
  47. package/dist/types/schema/fields.js +14 -0
  48. package/dist/types/schema/schema-service.js +0 -0
  49. package/dist/types/symbols.js +2 -2
  50. package/dist/unpkg/dev/-private-3C1OkYtZ.js +39 -0
  51. package/dist/unpkg/dev/build-config/babel-macros.js +1 -0
  52. package/dist/unpkg/dev/build-config/canary-features.js +1 -0
  53. package/dist/unpkg/dev/build-config/debugging.js +1 -0
  54. package/dist/unpkg/dev/build-config/deprecations.js +1 -0
  55. package/dist/unpkg/dev/build-config/env.js +1 -0
  56. package/dist/unpkg/dev/build-config/macros.js +1 -0
  57. package/dist/unpkg/dev/build-config.js +1 -0
  58. package/dist/unpkg/dev/configure-BC66sfNO.js +183 -0
  59. package/dist/unpkg/dev/configure.js +1 -0
  60. package/dist/unpkg/dev/graph/-private.js +3131 -0
  61. package/dist/unpkg/dev/index-DqhXrNZ_.js +11160 -0
  62. package/dist/unpkg/dev/index.js +6 -0
  63. package/dist/unpkg/dev/reactive/-private.js +1 -0
  64. package/dist/unpkg/dev/reactive.js +127 -0
  65. package/dist/unpkg/dev/request-CA9K0gXq.js +719 -0
  66. package/dist/unpkg/dev/request.js +1 -0
  67. package/dist/unpkg/dev/runtime-DGG4CvlW.js +135 -0
  68. package/dist/unpkg/dev/store/-private.js +56 -0
  69. package/dist/unpkg/dev/store.js +558 -0
  70. package/dist/unpkg/dev/types/-private.js +69 -0
  71. package/dist/unpkg/dev/types/cache/aliases.js +0 -0
  72. package/dist/unpkg/dev/types/cache/change.js +0 -0
  73. package/dist/unpkg/dev/types/cache/mutations.js +0 -0
  74. package/dist/unpkg/dev/types/cache/operations.js +0 -0
  75. package/dist/unpkg/dev/types/cache/relationship.js +0 -0
  76. package/dist/unpkg/dev/types/cache.js +0 -0
  77. package/dist/unpkg/dev/types/graph.js +0 -0
  78. package/dist/unpkg/dev/types/identifier.js +61 -0
  79. package/dist/unpkg/dev/types/json/raw.js +0 -0
  80. package/dist/unpkg/dev/types/params.js +0 -0
  81. package/dist/unpkg/dev/types/record.js +191 -0
  82. package/dist/unpkg/dev/types/request.js +77 -0
  83. package/dist/unpkg/dev/types/runtime.js +34 -0
  84. package/dist/unpkg/dev/types/schema/concepts.js +0 -0
  85. package/dist/unpkg/dev/types/schema/fields.js +505 -0
  86. package/dist/unpkg/dev/types/schema/fields.type-test.js +0 -0
  87. package/dist/unpkg/dev/types/schema/schema-service.js +0 -0
  88. package/dist/unpkg/dev/types/spec/document.js +0 -0
  89. package/dist/unpkg/dev/types/spec/error.js +0 -0
  90. package/dist/unpkg/dev/types/spec/json-api-raw.js +0 -0
  91. package/dist/unpkg/dev/types/symbols.js +84 -0
  92. package/dist/unpkg/dev/types/utils.js +0 -0
  93. package/dist/unpkg/dev/types.js +0 -0
  94. package/dist/unpkg/dev/utils/string.js +91 -0
  95. package/dist/unpkg/dev-deprecated/-private-3C1OkYtZ.js +39 -0
  96. package/dist/unpkg/dev-deprecated/build-config/babel-macros.js +1 -0
  97. package/dist/unpkg/dev-deprecated/build-config/canary-features.js +1 -0
  98. package/dist/unpkg/dev-deprecated/build-config/debugging.js +1 -0
  99. package/dist/unpkg/dev-deprecated/build-config/deprecations.js +1 -0
  100. package/dist/unpkg/dev-deprecated/build-config/env.js +1 -0
  101. package/dist/unpkg/dev-deprecated/build-config/macros.js +1 -0
  102. package/dist/unpkg/dev-deprecated/build-config.js +1 -0
  103. package/dist/unpkg/dev-deprecated/configure-BC66sfNO.js +183 -0
  104. package/dist/unpkg/dev-deprecated/configure.js +1 -0
  105. package/dist/unpkg/dev-deprecated/graph/-private.js +3326 -0
  106. package/dist/unpkg/dev-deprecated/index-BBlq5is_.js +11775 -0
  107. package/dist/unpkg/dev-deprecated/index.js +5 -0
  108. package/dist/unpkg/dev-deprecated/reactive/-private.js +1 -0
  109. package/dist/unpkg/dev-deprecated/reactive.js +127 -0
  110. package/dist/unpkg/dev-deprecated/request-CA9K0gXq.js +719 -0
  111. package/dist/unpkg/dev-deprecated/request.js +1 -0
  112. package/dist/unpkg/dev-deprecated/runtime-DfhJzpZH.js +135 -0
  113. package/dist/unpkg/dev-deprecated/store/-private.js +2 -0
  114. package/dist/unpkg/dev-deprecated/store.js +558 -0
  115. package/dist/unpkg/dev-deprecated/types/-private.js +69 -0
  116. package/dist/unpkg/dev-deprecated/types/cache/aliases.js +0 -0
  117. package/dist/unpkg/dev-deprecated/types/cache/change.js +0 -0
  118. package/dist/unpkg/dev-deprecated/types/cache/mutations.js +0 -0
  119. package/dist/unpkg/dev-deprecated/types/cache/operations.js +0 -0
  120. package/dist/unpkg/dev-deprecated/types/cache/relationship.js +0 -0
  121. package/dist/unpkg/dev-deprecated/types/cache.js +0 -0
  122. package/dist/unpkg/dev-deprecated/types/graph.js +0 -0
  123. package/dist/unpkg/dev-deprecated/types/identifier.js +61 -0
  124. package/dist/unpkg/dev-deprecated/types/json/raw.js +0 -0
  125. package/dist/unpkg/dev-deprecated/types/params.js +0 -0
  126. package/dist/unpkg/dev-deprecated/types/record.js +191 -0
  127. package/dist/unpkg/dev-deprecated/types/request.js +77 -0
  128. package/dist/unpkg/dev-deprecated/types/runtime.js +34 -0
  129. package/dist/unpkg/dev-deprecated/types/schema/concepts.js +0 -0
  130. package/dist/unpkg/dev-deprecated/types/schema/fields.js +505 -0
  131. package/dist/unpkg/dev-deprecated/types/schema/fields.type-test.js +0 -0
  132. package/dist/unpkg/dev-deprecated/types/schema/schema-service.js +0 -0
  133. package/dist/unpkg/dev-deprecated/types/spec/document.js +0 -0
  134. package/dist/unpkg/dev-deprecated/types/spec/error.js +0 -0
  135. package/dist/unpkg/dev-deprecated/types/spec/json-api-raw.js +0 -0
  136. package/dist/unpkg/dev-deprecated/types/symbols.js +84 -0
  137. package/dist/unpkg/dev-deprecated/types/utils.js +0 -0
  138. package/dist/unpkg/dev-deprecated/types.js +0 -0
  139. package/dist/unpkg/dev-deprecated/utils/string.js +91 -0
  140. package/dist/unpkg/prod/-private-3C1OkYtZ.js +39 -0
  141. package/dist/unpkg/prod/build-config/babel-macros.js +1 -0
  142. package/dist/unpkg/prod/build-config/canary-features.js +1 -0
  143. package/dist/unpkg/prod/build-config/debugging.js +1 -0
  144. package/dist/unpkg/prod/build-config/deprecations.js +1 -0
  145. package/dist/unpkg/prod/build-config/env.js +1 -0
  146. package/dist/unpkg/prod/build-config/macros.js +1 -0
  147. package/dist/unpkg/prod/build-config.js +1 -0
  148. package/dist/unpkg/prod/configure-C0C1LpG6.js +158 -0
  149. package/dist/unpkg/prod/configure.js +1 -0
  150. package/dist/unpkg/prod/graph/-private.js +2234 -0
  151. package/dist/unpkg/prod/handler-LAyD1Y5l.js +1619 -0
  152. package/dist/unpkg/prod/hooks-BfiqDg3O.js +26 -0
  153. package/dist/unpkg/prod/index.js +481 -0
  154. package/dist/unpkg/prod/promise-state-ipG60SdD.js +6738 -0
  155. package/dist/unpkg/prod/reactive/-private.js +1 -0
  156. package/dist/unpkg/prod/reactive.js +127 -0
  157. package/dist/unpkg/prod/request-CN2LxbYX.js +437 -0
  158. package/dist/unpkg/prod/request.js +1 -0
  159. package/dist/unpkg/prod/store/-private.js +127 -0
  160. package/dist/unpkg/prod/store.js +437 -0
  161. package/dist/unpkg/prod/types/-private.js +49 -0
  162. package/dist/unpkg/prod/types/cache/aliases.js +0 -0
  163. package/dist/unpkg/prod/types/cache/change.js +0 -0
  164. package/dist/unpkg/prod/types/cache/mutations.js +0 -0
  165. package/dist/unpkg/prod/types/cache/operations.js +0 -0
  166. package/dist/unpkg/prod/types/cache/relationship.js +0 -0
  167. package/dist/unpkg/prod/types/cache.js +0 -0
  168. package/dist/unpkg/prod/types/graph.js +0 -0
  169. package/dist/unpkg/prod/types/identifier.js +61 -0
  170. package/dist/unpkg/prod/types/json/raw.js +0 -0
  171. package/dist/unpkg/prod/types/params.js +0 -0
  172. package/dist/unpkg/prod/types/record.js +191 -0
  173. package/dist/unpkg/prod/types/request.js +77 -0
  174. package/dist/unpkg/prod/types/runtime.js +34 -0
  175. package/dist/unpkg/prod/types/schema/concepts.js +0 -0
  176. package/dist/unpkg/prod/types/schema/fields.js +505 -0
  177. package/dist/unpkg/prod/types/schema/fields.type-test.js +0 -0
  178. package/dist/unpkg/prod/types/schema/schema-service.js +0 -0
  179. package/dist/unpkg/prod/types/spec/document.js +0 -0
  180. package/dist/unpkg/prod/types/spec/error.js +0 -0
  181. package/dist/unpkg/prod/types/spec/json-api-raw.js +0 -0
  182. package/dist/unpkg/prod/types/symbols.js +84 -0
  183. package/dist/unpkg/prod/types/utils.js +0 -0
  184. package/dist/unpkg/prod/types.js +0 -0
  185. package/dist/unpkg/prod/utils/string.js +72 -0
  186. package/dist/unpkg/prod-deprecated/-private-3C1OkYtZ.js +39 -0
  187. package/dist/unpkg/prod-deprecated/build-config/babel-macros.js +1 -0
  188. package/dist/unpkg/prod-deprecated/build-config/canary-features.js +1 -0
  189. package/dist/unpkg/prod-deprecated/build-config/debugging.js +1 -0
  190. package/dist/unpkg/prod-deprecated/build-config/deprecations.js +1 -0
  191. package/dist/unpkg/prod-deprecated/build-config/env.js +1 -0
  192. package/dist/unpkg/prod-deprecated/build-config/macros.js +1 -0
  193. package/dist/unpkg/prod-deprecated/build-config.js +1 -0
  194. package/dist/unpkg/prod-deprecated/configure-BQ8CpIcW.js +158 -0
  195. package/dist/unpkg/prod-deprecated/configure.js +1 -0
  196. package/dist/unpkg/prod-deprecated/graph/-private.js +2407 -0
  197. package/dist/unpkg/prod-deprecated/handler-D639oFvl.js +334 -0
  198. package/dist/unpkg/prod-deprecated/hooks-DGvi9teJ.js +26 -0
  199. package/dist/unpkg/prod-deprecated/index.js +481 -0
  200. package/dist/unpkg/prod-deprecated/promise-state-CYvoIPna.js +8458 -0
  201. package/dist/unpkg/prod-deprecated/reactive/-private.js +1 -0
  202. package/dist/unpkg/prod-deprecated/reactive.js +126 -0
  203. package/dist/unpkg/prod-deprecated/request-CN2LxbYX.js +437 -0
  204. package/dist/unpkg/prod-deprecated/request.js +1 -0
  205. package/dist/unpkg/prod-deprecated/store/-private.js +89 -0
  206. package/dist/unpkg/prod-deprecated/store.js +437 -0
  207. package/dist/unpkg/prod-deprecated/types/-private.js +49 -0
  208. package/dist/unpkg/prod-deprecated/types/cache/aliases.js +0 -0
  209. package/dist/unpkg/prod-deprecated/types/cache/change.js +0 -0
  210. package/dist/unpkg/prod-deprecated/types/cache/mutations.js +0 -0
  211. package/dist/unpkg/prod-deprecated/types/cache/operations.js +0 -0
  212. package/dist/unpkg/prod-deprecated/types/cache/relationship.js +0 -0
  213. package/dist/unpkg/prod-deprecated/types/cache.js +0 -0
  214. package/dist/unpkg/prod-deprecated/types/graph.js +0 -0
  215. package/dist/unpkg/prod-deprecated/types/identifier.js +61 -0
  216. package/dist/unpkg/prod-deprecated/types/json/raw.js +0 -0
  217. package/dist/unpkg/prod-deprecated/types/params.js +0 -0
  218. package/dist/unpkg/prod-deprecated/types/record.js +191 -0
  219. package/dist/unpkg/prod-deprecated/types/request.js +77 -0
  220. package/dist/unpkg/prod-deprecated/types/runtime.js +34 -0
  221. package/dist/unpkg/prod-deprecated/types/schema/concepts.js +0 -0
  222. package/dist/unpkg/prod-deprecated/types/schema/fields.js +505 -0
  223. package/dist/unpkg/prod-deprecated/types/schema/fields.type-test.js +0 -0
  224. package/dist/unpkg/prod-deprecated/types/schema/schema-service.js +0 -0
  225. package/dist/unpkg/prod-deprecated/types/spec/document.js +0 -0
  226. package/dist/unpkg/prod-deprecated/types/spec/error.js +0 -0
  227. package/dist/unpkg/prod-deprecated/types/spec/json-api-raw.js +0 -0
  228. package/dist/unpkg/prod-deprecated/types/symbols.js +84 -0
  229. package/dist/unpkg/prod-deprecated/types/utils.js +0 -0
  230. package/dist/unpkg/prod-deprecated/types.js +0 -0
  231. package/dist/unpkg/prod-deprecated/utils/string.js +72 -0
  232. package/logos/README.md +2 -2
  233. package/logos/logo-yellow-slab.svg +1 -0
  234. package/logos/word-mark-black.svg +1 -0
  235. package/logos/word-mark-white.svg +1 -0
  236. package/package.json +11 -3
  237. package/logos/NCC-1701-a-blue.svg +0 -4
  238. package/logos/NCC-1701-a-gold.svg +0 -4
  239. package/logos/NCC-1701-a-gold_100.svg +0 -1
  240. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  241. package/logos/NCC-1701-a.svg +0 -4
  242. package/logos/docs-badge.svg +0 -2
  243. package/logos/ember-data-logo-dark.svg +0 -12
  244. package/logos/ember-data-logo-light.svg +0 -12
  245. package/logos/social1.png +0 -0
  246. package/logos/social2.png +0 -0
  247. package/logos/warp-drive-logo-dark.svg +0 -4
  248. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -0,0 +1 @@
1
+ export { a as Context } from "../-private-3C1OkYtZ.js";
@@ -0,0 +1,126 @@
1
+ export { I as SchemaService, H as checkout, M as commit, m as createRequestSubscription, K as fromIdentity, N as getPromiseState, o as getRequestState, L as registerDerivations, J as withDefaults } from "./promise-state-CYvoIPna.js";
2
+ export { i as instantiateRecord, t as teardownRecord } from "./hooks-DGvi9teJ.js";
3
+ export { C as Checkout } from "./-private-3C1OkYtZ.js";
4
+ import './types/-private.js';
5
+ const Subscriptions = new WeakMap();
6
+
7
+ /**
8
+ * `ExpensiveSubscription` is a mechanism for non-reactive
9
+ * frameworks such as `react` to integrate with WarpDrive.
10
+ *
11
+ * This mechanism should never be used by frameworks or libraries
12
+ * that support fine-grained reactivity.
13
+ *
14
+ * ExpensiveSubscription is expensive *because* it doubles the number
15
+ * of notification callbacks required for each resource contained in
16
+ * the request being subscribed to. The more requests in-use, the more
17
+ * this cost adds up.
18
+ */
19
+ class ExpensiveSubscription {
20
+ constructor(store, request) {
21
+ this._store = store;
22
+ this._request = request;
23
+ this._callbacks = new Set();
24
+ this._resources = new Map();
25
+ this._subscription = store.notifications.subscribe(request, this._notifyRequestChange);
26
+ this._updateResourceCallbacks();
27
+ }
28
+ _updateResourceCallbacks() {
29
+ const request = this._request;
30
+ const store = this._store;
31
+ const {
32
+ notifications
33
+ } = store;
34
+ const req = store.cache.peek(request);
35
+ const resources = this._resources;
36
+ const isInitialSubscription = resources.size === 0;
37
+ if (req && 'data' in req) {
38
+ if (Array.isArray(req.data)) {
39
+ for (const resourceKey of req.data) {
40
+ if (isInitialSubscription || !resources.has(resourceKey)) {
41
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
42
+ }
43
+ }
44
+ } else if (req.data) {
45
+ if (isInitialSubscription || !resources.has(req.data)) {
46
+ resources.set(req.data, notifications.subscribe(req.data, this._scheduleNotify));
47
+ }
48
+ }
49
+ }
50
+ if (req && 'included' in req && Array.isArray(req.included)) {
51
+ for (const resourceKey of req.included) {
52
+ if (isInitialSubscription || !resources.has(resourceKey)) {
53
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
54
+ }
55
+ }
56
+ }
57
+ }
58
+ _notifyRequestChange = () => {
59
+ this._updateResourceCallbacks();
60
+ this._scheduleNotify();
61
+ };
62
+ _scheduleNotify = () => {
63
+ this._notify = this._notify || Promise.resolve().then(() => {
64
+ for (const callback of this._callbacks) {
65
+ callback();
66
+ }
67
+ this._notify = null;
68
+ });
69
+ };
70
+ addWatcher(callback) {
71
+ this._callbacks.add(callback);
72
+ }
73
+ removeWatcher(callback) {
74
+ this._callbacks.delete(callback);
75
+ if (this._callbacks.size === 0) {
76
+ this.destroy();
77
+ }
78
+ }
79
+ destroy() {
80
+ Subscriptions.delete(this._request);
81
+ const {
82
+ notifications
83
+ } = this._store;
84
+ if (this._subscription) {
85
+ notifications.unsubscribe(this._subscription);
86
+ }
87
+ for (const token of this._resources.values()) {
88
+ notifications.unsubscribe(token);
89
+ }
90
+ this._callbacks.clear();
91
+ this._resources.clear();
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Creates an {@link ExpensiveSubscription} for the {@link RequestKey}
97
+ * if one does not already exist and adds a watcher to it.
98
+ *
99
+ * Returns a cleanup function. This should be called on-mount by a component
100
+ * that wants to subscribe to a request and cleanup should be called on dismount.
101
+ *
102
+ * ::: warning ⚠️ Avoid Using If Your App Supports Fine-grained Reactivity
103
+ * This mechanism should never be used by frameworks or libraries
104
+ * that support fine-grained reactivity.
105
+ * :::
106
+ *
107
+ * `ExpensiveSubscription` is a mechanism for non-reactive
108
+ * frameworks such as `react` to integrate with WarpDrive, for instance
109
+ * by treating a request as an [external store](https://react.dev/reference/react/useSyncExternalStore)
110
+ *
111
+ * `ExpensiveSubscription` is expensive *because* it doubles the number
112
+ * of notification callbacks required for each resource contained in
113
+ * the request being subscribed to. The more requests in-use, the more
114
+ * this cost adds up.
115
+ */
116
+ function getExpensiveRequestSubscription(store, requestKey, callback) {
117
+ let subscription = Subscriptions.get(requestKey);
118
+ if (!subscription) {
119
+ subscription = new ExpensiveSubscription(store, requestKey);
120
+ }
121
+ subscription.addWatcher(callback);
122
+ return () => {
123
+ subscription.removeWatcher(callback);
124
+ };
125
+ }
126
+ export { getExpensiveRequestSubscription };
@@ -0,0 +1,437 @@
1
+ import { STRUCTURED, IS_FUTURE } from './types/request.js';
2
+ import { getOrSetUniversal, getOrSetGlobal } from './types/-private.js';
3
+ function upgradeHeaders(headers) {
4
+ headers.clone = () => {
5
+ return new Headers(headers);
6
+ };
7
+ headers.toJSON = () => {
8
+ return Array.from(headers);
9
+ };
10
+ return headers;
11
+ }
12
+ function cloneResponseProperties(response) {
13
+ const {
14
+ headers,
15
+ ok,
16
+ redirected,
17
+ status,
18
+ statusText,
19
+ type,
20
+ url
21
+ } = response;
22
+ upgradeHeaders(headers);
23
+ return {
24
+ headers: headers,
25
+ ok,
26
+ redirected,
27
+ status,
28
+ statusText,
29
+ type,
30
+ url
31
+ };
32
+ }
33
+ class ContextOwner {
34
+ hasSetStream = false;
35
+ hasSetResponse = false;
36
+ hasSubscribers = false;
37
+ stream = createDeferred();
38
+ response = null;
39
+ nextCalled = 0;
40
+ constructor(request, god, isRoot = false) {
41
+ this.isRoot = isRoot;
42
+ this.requestId = god.id;
43
+ this.controller = request.controller || god.controller;
44
+ this.stream.promise.sizeHint = 0;
45
+ if (request.controller) {
46
+ if (request.controller !== god.controller) {
47
+ god.controller.signal.addEventListener('abort', () => {
48
+ this.controller.abort(god.controller.signal.reason);
49
+ });
50
+ }
51
+ delete request.controller;
52
+ }
53
+ let enhancedRequest = Object.assign({
54
+ signal: this.controller.signal
55
+ }, request);
56
+ {
57
+ if (request.headers) {
58
+ upgradeHeaders(request.headers);
59
+ }
60
+ }
61
+ this.enhancedRequest = enhancedRequest;
62
+ this.request = request;
63
+ this.god = god;
64
+ this.stream.promise = this.stream.promise.then(stream => {
65
+ if (this.god.stream === stream && this.hasSubscribers) {
66
+ this.god.stream = null;
67
+ }
68
+ return stream;
69
+ });
70
+ }
71
+ get hasRequestedStream() {
72
+ return this.god.hasRequestedStream;
73
+ }
74
+ getResponse() {
75
+ if (this.hasSetResponse) {
76
+ return this.response;
77
+ }
78
+ if (this.nextCalled === 1) {
79
+ return this.god.response;
80
+ }
81
+ return null;
82
+ }
83
+ getStream() {
84
+ if (this.isRoot) {
85
+ this.god.hasRequestedStream = true;
86
+ }
87
+ if (!this.hasSetResponse) {
88
+ const hint = this.god.response?.headers?.get('content-length');
89
+ this.stream.promise.sizeHint = hint ? parseInt(hint, 10) : 0;
90
+ }
91
+ this.hasSubscribers = true;
92
+ return this.stream.promise;
93
+ }
94
+ abort(reason) {
95
+ this.controller.abort(reason);
96
+ }
97
+ setStream(stream) {
98
+ if (!this.hasSetStream) {
99
+ this.hasSetStream = true;
100
+ if (!(stream instanceof Promise)) {
101
+ this.god.stream = stream;
102
+ }
103
+ // @ts-expect-error
104
+ this.stream.resolve(stream);
105
+ }
106
+ }
107
+ resolveStream() {
108
+ this.setStream(this.nextCalled === 1 ? this.god.stream : null);
109
+ }
110
+ setResponse(response) {
111
+ if (this.hasSetResponse) {
112
+ return;
113
+ }
114
+ this.hasSetResponse = true;
115
+ if (response instanceof Response) {
116
+ // TODO potentially avoid cloning in prod
117
+ let responseData = cloneResponseProperties(response);
118
+ this.response = responseData;
119
+ this.god.response = responseData;
120
+ const sizeHint = response.headers?.get('content-length');
121
+ this.stream.promise.sizeHint = sizeHint ? parseInt(sizeHint, 10) : 0;
122
+ } else {
123
+ this.response = response;
124
+ this.god.response = response;
125
+ }
126
+ }
127
+ }
128
+ class Context {
129
+ /** @internal */
130
+
131
+ /** @internal */
132
+
133
+ /** @internal */
134
+
135
+ constructor(owner, isCacheHandler) {
136
+ this.id = owner.requestId;
137
+ this.___owner = owner;
138
+ this.request = owner.enhancedRequest;
139
+ this._isCacheHandler = isCacheHandler;
140
+ this._finalized = false;
141
+ }
142
+ setStream(stream) {
143
+ this.___owner.setStream(stream);
144
+ }
145
+ setResponse(response) {
146
+ this.___owner.setResponse(response);
147
+ }
148
+ setIdentifier(identifier) {
149
+ this.___owner.god.identifier = identifier;
150
+ }
151
+ get hasRequestedStream() {
152
+ return this.___owner.hasRequestedStream;
153
+ }
154
+
155
+ /** @private */
156
+ _finalize() {
157
+ this._finalized = true;
158
+ }
159
+ }
160
+ const PromiseCache = getOrSetUniversal('PromiseCache', new WeakMap());
161
+ const RequestMap = getOrSetUniversal('RequestMap', new Map());
162
+ function setRequestResult(requestId, result) {
163
+ RequestMap.set(requestId, result);
164
+ }
165
+ function clearRequestResult(requestId) {
166
+ RequestMap.delete(requestId);
167
+ }
168
+ function getRequestResult(requestId) {
169
+ return RequestMap.get(requestId);
170
+ }
171
+ function setPromiseResult(promise, result) {
172
+ PromiseCache.set(promise, result);
173
+ }
174
+ function getPromiseResult(promise) {
175
+ return PromiseCache.get(promise);
176
+ }
177
+ const IS_CACHE_HANDLER = getOrSetGlobal('IS_CACHE_HANDLER', Symbol('IS_CACHE_HANDLER'));
178
+ function curryFuture(owner, inbound, outbound) {
179
+ owner.setStream(inbound.getStream());
180
+ inbound.then(doc => {
181
+ const document = {
182
+ [STRUCTURED]: true,
183
+ request: owner.request,
184
+ response: doc.response,
185
+ content: doc.content
186
+ };
187
+ outbound.resolve(document);
188
+ }, error => {
189
+ if (isDoc(error)) {
190
+ owner.setStream(owner.god.stream);
191
+ }
192
+ if (!error || !(error instanceof Error)) {
193
+ try {
194
+ throw new Error(error ? error : `Request Rejected with an Unknown Error`);
195
+ } catch (e) {
196
+ if (error && typeof error === 'object') {
197
+ Object.assign(e, error);
198
+ e.message = error.message || `Request Rejected with an Unknown Error`;
199
+ }
200
+ error = e;
201
+ }
202
+ }
203
+ error[STRUCTURED] = true;
204
+ error.request = owner.request;
205
+ error.response = owner.getResponse();
206
+ error.error = error.error || error.message;
207
+ outbound.reject(error);
208
+ });
209
+ return outbound.promise;
210
+ }
211
+ function isDoc(doc) {
212
+ return doc && doc[STRUCTURED] === true;
213
+ }
214
+ function ensureDoc(owner, content, isError) {
215
+ if (isDoc(content)) {
216
+ return content;
217
+ }
218
+ if (isError) {
219
+ return {
220
+ [STRUCTURED]: true,
221
+ request: owner.request,
222
+ response: owner.getResponse(),
223
+ error: content
224
+ };
225
+ }
226
+ return {
227
+ [STRUCTURED]: true,
228
+ request: owner.request,
229
+ response: owner.getResponse(),
230
+ content: content
231
+ };
232
+ }
233
+
234
+ /**
235
+ * Additional properties exposed on errors thrown by the
236
+ * {@link Fetch | Fetch Handler}.
237
+ *
238
+ * In the case of an Abort or system/browser level issue,
239
+ * this extends {@link DOMException}.
240
+ *
241
+ * Else it extends from {@link AggregateError} if the
242
+ * response includes an array of errors, falling back
243
+ * to {@link Error} as its base.
244
+ */
245
+
246
+ function enhanceReason(reason) {
247
+ return new DOMException(reason || 'The user aborted a request.', 'AbortError');
248
+ }
249
+ function handleOutcome(owner, inbound, outbound) {
250
+ inbound.then(content => {
251
+ if (owner.controller.signal.aborted) {
252
+ // the next function did not respect the signal, we handle it here
253
+ outbound.reject(enhanceReason(owner.controller.signal.reason));
254
+ return;
255
+ }
256
+ if (isDoc(content)) {
257
+ owner.setStream(owner.god.stream);
258
+ content = content.content;
259
+ }
260
+ const document = {
261
+ [STRUCTURED]: true,
262
+ request: owner.request,
263
+ response: owner.getResponse(),
264
+ content
265
+ };
266
+ outbound.resolve(document);
267
+ }, error => {
268
+ if (isDoc(error)) {
269
+ owner.setStream(owner.god.stream);
270
+ }
271
+ if (!error || !(error instanceof Error)) {
272
+ try {
273
+ throw new Error(error ? error : `Request Rejected with an Unknown Error`);
274
+ } catch (e) {
275
+ if (error && typeof error === 'object') {
276
+ Object.assign(e, error);
277
+ e.message = error.message || `Request Rejected with an Unknown Error`;
278
+ }
279
+ error = e;
280
+ }
281
+ }
282
+ error[STRUCTURED] = true;
283
+ error.request = owner.request;
284
+ error.response = owner.getResponse();
285
+ error.error = error.error || error.message;
286
+ outbound.reject(error);
287
+ });
288
+ return outbound.promise;
289
+ }
290
+ function isCacheHandler(handler, index) {
291
+ return index === 0 && Boolean(handler[IS_CACHE_HANDLER]);
292
+ }
293
+ function executeNextHandler(wares, request, i, god) {
294
+ const owner = new ContextOwner(request, god, i === 0);
295
+ function next(r) {
296
+ owner.nextCalled++;
297
+ return executeNextHandler(wares, r, i + 1, god);
298
+ }
299
+ const _isCacheHandler = isCacheHandler(wares[i], i);
300
+ const context = new Context(owner, _isCacheHandler);
301
+ let outcome;
302
+ try {
303
+ outcome = wares[i].request(context, next);
304
+ if (_isCacheHandler) {
305
+ context._finalize();
306
+ }
307
+ if (!!outcome && _isCacheHandler) {
308
+ if (!(outcome instanceof Promise)) {
309
+ setRequestResult(owner.requestId, {
310
+ isError: false,
311
+ result: ensureDoc(owner, outcome, false)
312
+ });
313
+ outcome = Promise.resolve(outcome);
314
+ }
315
+ }
316
+ } catch (e) {
317
+ if (_isCacheHandler) {
318
+ setRequestResult(owner.requestId, {
319
+ isError: true,
320
+ result: ensureDoc(owner, e, true)
321
+ });
322
+ }
323
+ // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
324
+ outcome = Promise.reject(e);
325
+ }
326
+ const future = createFuture(owner);
327
+ if (isFuture(outcome)) {
328
+ return curryFuture(owner, outcome, future);
329
+ }
330
+ return handleOutcome(owner, outcome, future);
331
+ }
332
+ function isFuture(maybe) {
333
+ return Boolean(maybe && maybe instanceof Promise && maybe[IS_FUTURE] === true);
334
+ }
335
+ function createDeferred() {
336
+ let resolve;
337
+ let reject;
338
+ const promise = new Promise((res, rej) => {
339
+ resolve = res;
340
+ reject = rej;
341
+ });
342
+ return {
343
+ resolve,
344
+ reject,
345
+ promise
346
+ };
347
+ }
348
+ function upgradePromise(promise, future) {
349
+ promise[IS_FUTURE] = true;
350
+ // eslint-disable-next-line @typescript-eslint/unbound-method
351
+ promise.getStream = future.getStream;
352
+ // eslint-disable-next-line @typescript-eslint/unbound-method
353
+ promise.abort = future.abort;
354
+ // eslint-disable-next-line @typescript-eslint/unbound-method
355
+ promise.onFinalize = future.onFinalize;
356
+ promise.id = future.id;
357
+ promise.lid = future.lid;
358
+ promise.requester = future.requester;
359
+ return promise;
360
+ }
361
+ function createFuture(owner) {
362
+ const deferred = createDeferred();
363
+ let {
364
+ promise
365
+ } = deferred;
366
+ let cbs;
367
+ promise = promise.finally(() => {
368
+ owner.resolveStream();
369
+ if (cbs) {
370
+ cbs.forEach(cb => cb());
371
+ }
372
+ });
373
+ promise.onFinalize = fn => {
374
+ cbs = cbs || [];
375
+ cbs.push(fn);
376
+ };
377
+ promise[IS_FUTURE] = true;
378
+ promise.getStream = () => {
379
+ return owner.getStream();
380
+ };
381
+ promise.abort = reason => {
382
+ owner.abort(enhanceReason(reason));
383
+ };
384
+ promise.id = owner.requestId;
385
+ promise.lid = owner.god.identifier;
386
+ promise.requester = owner.god.requester;
387
+ deferred.promise = promise;
388
+ return deferred;
389
+ }
390
+
391
+ /**
392
+ * Brands the supplied object with the supplied response type.
393
+ *
394
+ * ```ts
395
+ * import type { ReactiveDataDocument } from '@warp-drive/core/reactive';
396
+ * import { withResponseType } from '@warp-drive/core/request';
397
+ * import type { User } from '#/data/user.ts'
398
+ *
399
+ * const result = await store.request(
400
+ * withResponseType<ReactiveDataDocument<User>>({ url: '/users/1' })
401
+ * );
402
+ *
403
+ * result.content.data; // will have type User
404
+ * ```
405
+ *
406
+ */
407
+ function withResponseType(obj) {
408
+ return obj;
409
+ }
410
+
411
+ /**
412
+ * Brands the supplied object with the supplied response type
413
+ * wrapped in {@link ReactiveDataDocument}. This is a convenience for
414
+ * the common case of using {@link withResponseType} with `ReactiveDataDocument`.
415
+ *
416
+ * ```ts
417
+ * import { withReactiveResponse } from '@warp-drive/core/request';
418
+ * import type { User } from '#/data/user.ts'
419
+ *
420
+ * const result = await store.request(
421
+ * withReactiveResponse<User>({ url: '/users/1' })
422
+ * );
423
+ *
424
+ * result.content.data; // will have type User
425
+ * ```
426
+ *
427
+ * @public
428
+ */
429
+ function withReactiveResponse(obj) {
430
+ return obj;
431
+ }
432
+
433
+ /**
434
+ * @deprecated use {@link withResponseType} instead
435
+ */
436
+ const withBrand = withResponseType;
437
+ export { IS_CACHE_HANDLER as I, clearRequestResult as a, getPromiseResult as b, cloneResponseProperties as c, withResponseType as d, executeNextHandler as e, withReactiveResponse as f, getRequestResult as g, createDeferred as h, setPromiseResult as s, upgradePromise as u, withBrand as w };
@@ -0,0 +1 @@
1
+ export { h as createDeferred, b as getPromiseResult, s as setPromiseResult, w as withBrand, f as withReactiveResponse, d as withResponseType } from "./request-CN2LxbYX.js";
@@ -0,0 +1,89 @@
1
+ export { D as DISPOSE, R as RecordArrayManager, z as Signals, S as Store, k as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, h as assertPrivateCapabilities, d as assertPrivateStore, b as coerceId, c as constructResource, F as consumeInternalSignal, B as createInternalMemo, l as createLegacyManyArray, m as createRequestSubscription, x as defineGate, y as defineNonEnumerableSignal, w as defineSignal, e as ensureStringId, v as entangleInitiallyStaleSignal, u as entangleSignal, f as fastPush, t as gate, G as getOrCreateInternalSignal, o as getRequestState, g as isPrivateStore, a as isRequestKey, i as isResourceKey, q as memoized, E as notifyInternalSignal, A as peekInternalSignal, r as recordIdentifierFor, j as setRecordIdentifier, p as signal, s as storeFor, C as withSignalStore } from "../promise-state-CYvoIPna.js";
2
+ export { C as CacheHandler } from "../handler-D639oFvl.js";
3
+ export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-BQ8CpIcW.js";
4
+ const TEXT_COLORS = {
5
+ TEXT: 'inherit',
6
+ notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
7
+ 'reactive-ui': ['white', 'white', 'inherit', 'magenta', 'inherit'],
8
+ graph: ['white', 'white', 'inherit', 'magenta', 'inherit'],
9
+ request: ['white', 'white', 'inherit', 'magenta', 'inherit'],
10
+ cache: ['white', 'white', 'inherit', 'magenta', 'inherit']
11
+ };
12
+ const BG_COLORS = {
13
+ TEXT: 'transparent',
14
+ notify: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
15
+ 'reactive-ui': ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
16
+ graph: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
17
+ request: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
18
+ cache: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent']
19
+ };
20
+ const NOTIFY_BORDER = {
21
+ TEXT: 0,
22
+ notify: [3, 2, 0, 0, 0],
23
+ 'reactive-ui': [3, 2, 0, 0, 0],
24
+ graph: [3, 2, 0, 0, 0],
25
+ request: [3, 2, 0, 0, 0],
26
+ cache: [3, 2, 0, 0, 0]
27
+ };
28
+ const LIGHT_DARK_ALT = {
29
+ lightgreen: 'green',
30
+ green: 'lightgreen'
31
+ };
32
+ function badge(isLight, color, bgColor, border) {
33
+ return [`color: ${correctColor(isLight, color)}; background-color: ${correctColor(isLight, bgColor)}; padding: ${border}px ${2 * border}px; border-radius: ${border}px;`, `color: ${TEXT_COLORS.TEXT}; background-color: ${BG_COLORS.TEXT};`];
34
+ }
35
+ function colorForBucket(isLight, scope, bucket) {
36
+ if (scope === 'request') {
37
+ return bucket === 'blocking' ? badge(isLight, 'red', 'transparent', 0) : bucket === 'cached' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'non-blocking' ? badge(isLight, 'orange', 'transparent', 0) : badge(isLight, 'gray', 'transparent', 0);
38
+ }
39
+ if (scope === 'notify') {
40
+ return bucket === 'added' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
41
+ }
42
+ if (scope === 'reactive-ui') {
43
+ return bucket === 'created' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'disconnected' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
44
+ }
45
+ if (scope === 'cache') {
46
+ return bucket === 'inserted' ? badge(isLight, 'lightgreen', 'transparent', 0) : bucket === 'removed' ? badge(isLight, 'red', 'transparent', 0) : badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]);
47
+ }
48
+ return badge(isLight, TEXT_COLORS[scope][3], BG_COLORS[scope][3], NOTIFY_BORDER[scope][3]);
49
+ }
50
+ function logGroup(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
51
+ // eslint-disable-next-line no-console
52
+ console.groupCollapsed(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
53
+ }
54
+ function log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
55
+ // eslint-disable-next-line no-console
56
+ console.log(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
57
+ }
58
+ function correctColor(isLight, color) {
59
+ if (!isLight) {
60
+ return color;
61
+ }
62
+ return color in LIGHT_DARK_ALT ? LIGHT_DARK_ALT[color] : color;
63
+ }
64
+ function isLightMode() {
65
+ if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+ function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
71
+ const isLight = isLightMode();
72
+ switch (scope) {
73
+ case 'request':
74
+ case 'reactive-ui':
75
+ case 'notify':
76
+ {
77
+ const scopePath = prefix ? `[${prefix}] ${scope}` : scope;
78
+ const path = subScop4 ? `${subScop3}.${subScop4}` : subScop3;
79
+ return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${path}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, path)];
80
+ }
81
+ case 'cache':
82
+ {
83
+ const scopePath = prefix ? `${scope} (${prefix})` : scope;
84
+ return [`%c@warp%c-%cdrive%c %c${scopePath}%c %c${subScop1}%c %c${subScop2}%c %c${subScop3}%c %c${subScop4}%c`, ...badge(isLight, 'lightgreen', 'transparent', 0), ...badge(isLight, 'magenta', 'transparent', 0), ...badge(isLight, TEXT_COLORS[scope][0], BG_COLORS[scope][0], NOTIFY_BORDER[scope][0]), ...badge(isLight, TEXT_COLORS[scope][1], BG_COLORS[scope][1], NOTIFY_BORDER[scope][1]), ...badge(isLight, TEXT_COLORS[scope][2], BG_COLORS[scope][2], NOTIFY_BORDER[scope][2]), ...colorForBucket(isLight, scope, subScop3), ...badge(isLight, TEXT_COLORS[scope][4], BG_COLORS[scope][4], NOTIFY_BORDER[scope][4])];
85
+ }
86
+ }
87
+ return [];
88
+ }
89
+ export { log, logGroup };