@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,127 @@
1
+ export { S as SchemaService, c as checkout, a as commit, b as createRequestSubscription, f as fromIdentity, d as getPromiseState, g as getRequestState, r as registerDerivations, w as withDefaults } from "./promise-state-ipG60SdD.js";
2
+ export { i as instantiateRecord, t as teardownRecord } from "./hooks-BfiqDg3O.js";
3
+ export { C as Checkout } from "./-private-3C1OkYtZ.js";
4
+ import './types/-private.js';
5
+ import './types/runtime.js';
6
+ const Subscriptions = new WeakMap();
7
+
8
+ /**
9
+ * `ExpensiveSubscription` is a mechanism for non-reactive
10
+ * frameworks such as `react` to integrate with WarpDrive.
11
+ *
12
+ * This mechanism should never be used by frameworks or libraries
13
+ * that support fine-grained reactivity.
14
+ *
15
+ * ExpensiveSubscription is expensive *because* it doubles the number
16
+ * of notification callbacks required for each resource contained in
17
+ * the request being subscribed to. The more requests in-use, the more
18
+ * this cost adds up.
19
+ */
20
+ class ExpensiveSubscription {
21
+ constructor(store, request) {
22
+ this._store = store;
23
+ this._request = request;
24
+ this._callbacks = new Set();
25
+ this._resources = new Map();
26
+ this._subscription = store.notifications.subscribe(request, this._notifyRequestChange);
27
+ this._updateResourceCallbacks();
28
+ }
29
+ _updateResourceCallbacks() {
30
+ const request = this._request;
31
+ const store = this._store;
32
+ const {
33
+ notifications
34
+ } = store;
35
+ const req = store.cache.peek(request);
36
+ const resources = this._resources;
37
+ const isInitialSubscription = resources.size === 0;
38
+ if (req && 'data' in req) {
39
+ if (Array.isArray(req.data)) {
40
+ for (const resourceKey of req.data) {
41
+ if (isInitialSubscription || !resources.has(resourceKey)) {
42
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
43
+ }
44
+ }
45
+ } else if (req.data) {
46
+ if (isInitialSubscription || !resources.has(req.data)) {
47
+ resources.set(req.data, notifications.subscribe(req.data, this._scheduleNotify));
48
+ }
49
+ }
50
+ }
51
+ if (req && 'included' in req && Array.isArray(req.included)) {
52
+ for (const resourceKey of req.included) {
53
+ if (isInitialSubscription || !resources.has(resourceKey)) {
54
+ resources.set(resourceKey, notifications.subscribe(resourceKey, this._scheduleNotify));
55
+ }
56
+ }
57
+ }
58
+ }
59
+ _notifyRequestChange = () => {
60
+ this._updateResourceCallbacks();
61
+ this._scheduleNotify();
62
+ };
63
+ _scheduleNotify = () => {
64
+ this._notify = this._notify || Promise.resolve().then(() => {
65
+ for (const callback of this._callbacks) {
66
+ callback();
67
+ }
68
+ this._notify = null;
69
+ });
70
+ };
71
+ addWatcher(callback) {
72
+ this._callbacks.add(callback);
73
+ }
74
+ removeWatcher(callback) {
75
+ this._callbacks.delete(callback);
76
+ if (this._callbacks.size === 0) {
77
+ this.destroy();
78
+ }
79
+ }
80
+ destroy() {
81
+ Subscriptions.delete(this._request);
82
+ const {
83
+ notifications
84
+ } = this._store;
85
+ if (this._subscription) {
86
+ notifications.unsubscribe(this._subscription);
87
+ }
88
+ for (const token of this._resources.values()) {
89
+ notifications.unsubscribe(token);
90
+ }
91
+ this._callbacks.clear();
92
+ this._resources.clear();
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Creates an {@link ExpensiveSubscription} for the {@link RequestKey}
98
+ * if one does not already exist and adds a watcher to it.
99
+ *
100
+ * Returns a cleanup function. This should be called on-mount by a component
101
+ * that wants to subscribe to a request and cleanup should be called on dismount.
102
+ *
103
+ * ::: warning ⚠️ Avoid Using If Your App Supports Fine-grained Reactivity
104
+ * This mechanism should never be used by frameworks or libraries
105
+ * that support fine-grained reactivity.
106
+ * :::
107
+ *
108
+ * `ExpensiveSubscription` is a mechanism for non-reactive
109
+ * frameworks such as `react` to integrate with WarpDrive, for instance
110
+ * by treating a request as an [external store](https://react.dev/reference/react/useSyncExternalStore)
111
+ *
112
+ * `ExpensiveSubscription` is expensive *because* it doubles the number
113
+ * of notification callbacks required for each resource contained in
114
+ * the request being subscribed to. The more requests in-use, the more
115
+ * this cost adds up.
116
+ */
117
+ function getExpensiveRequestSubscription(store, requestKey, callback) {
118
+ let subscription = Subscriptions.get(requestKey);
119
+ if (!subscription) {
120
+ subscription = new ExpensiveSubscription(store, requestKey);
121
+ }
122
+ subscription.addWatcher(callback);
123
+ return () => {
124
+ subscription.removeWatcher(callback);
125
+ };
126
+ }
127
+ 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,127 @@
1
+ import '../types/-private.js';
2
+ export { C as CacheHandler, S as Store, a as assertPrivateStore, i as isPrivateStore } from "../handler-LAyD1Y5l.js";
3
+ import { m as isResourceKey, n as coerceId } from "../promise-state-ipG60SdD.js";
4
+ export { D as DISPOSE, q as RecordArrayManager, J as Signals, x as StoreMap, _ as _clearCaches, y as _deprecatingNormalize, u as assertPrivateCapabilities, O as consumeInternalSignal, L as createInternalMemo, z as createLegacyManyArray, b as createRequestSubscription, H as defineGate, I as defineNonEnumerableSignal, G as defineSignal, p as ensureStringId, F as entangleInitiallyStaleSignal, E as entangleSignal, t as fastPush, C as gate, P as getOrCreateInternalSignal, g as getRequestState, o as isRequestKey, B as memoized, N as notifyInternalSignal, K as peekInternalSignal, e as recordIdentifierFor, v as setRecordIdentifier, A as signal, s as storeFor, M as withSignalStore } from "../promise-state-ipG60SdD.js";
5
+ export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, w as waitFor } from "../configure-C0C1LpG6.js";
6
+ const TEXT_COLORS = {
7
+ TEXT: 'inherit',
8
+ notify: ['white', 'white', 'inherit', 'magenta', 'inherit'],
9
+ 'reactive-ui': ['white', 'white', 'inherit', 'magenta', 'inherit'],
10
+ graph: ['white', 'white', 'inherit', 'magenta', 'inherit'],
11
+ request: ['white', 'white', 'inherit', 'magenta', 'inherit'],
12
+ cache: ['white', 'white', 'inherit', 'magenta', 'inherit']
13
+ };
14
+ const BG_COLORS = {
15
+ TEXT: 'transparent',
16
+ notify: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
17
+ 'reactive-ui': ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
18
+ graph: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
19
+ request: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent'],
20
+ cache: ['dimgray', 'cadetblue', 'transparent', 'transparent', 'transparent']
21
+ };
22
+ const NOTIFY_BORDER = {
23
+ TEXT: 0,
24
+ notify: [3, 2, 0, 0, 0],
25
+ 'reactive-ui': [3, 2, 0, 0, 0],
26
+ graph: [3, 2, 0, 0, 0],
27
+ request: [3, 2, 0, 0, 0],
28
+ cache: [3, 2, 0, 0, 0]
29
+ };
30
+ const LIGHT_DARK_ALT = {
31
+ lightgreen: 'green',
32
+ green: 'lightgreen'
33
+ };
34
+ function badge(isLight, color, bgColor, border) {
35
+ 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};`];
36
+ }
37
+ function colorForBucket(isLight, scope, bucket) {
38
+ if (scope === 'request') {
39
+ 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);
40
+ }
41
+ if (scope === 'notify') {
42
+ 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]);
43
+ }
44
+ if (scope === 'reactive-ui') {
45
+ 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]);
46
+ }
47
+ if (scope === 'cache') {
48
+ 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]);
49
+ }
50
+ return badge(isLight, TEXT_COLORS[scope][3], BG_COLORS[scope][3], NOTIFY_BORDER[scope][3]);
51
+ }
52
+ function logGroup(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
53
+ // eslint-disable-next-line no-console
54
+ console.groupCollapsed(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
55
+ }
56
+ function log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
57
+ // eslint-disable-next-line no-console
58
+ console.log(..._log(scope, prefix, subScop1, subScop2, subScop3, subScop4));
59
+ }
60
+ function correctColor(isLight, color) {
61
+ if (!isLight) {
62
+ return color;
63
+ }
64
+ return color in LIGHT_DARK_ALT ? LIGHT_DARK_ALT[color] : color;
65
+ }
66
+ function isLightMode() {
67
+ if (window?.matchMedia?.('(prefers-color-scheme: light)').matches) {
68
+ return true;
69
+ }
70
+ return false;
71
+ }
72
+ function _log(scope, prefix, subScop1, subScop2, subScop3, subScop4) {
73
+ const isLight = isLightMode();
74
+ switch (scope) {
75
+ case 'request':
76
+ case 'reactive-ui':
77
+ case 'notify':
78
+ {
79
+ const scopePath = prefix ? `[${prefix}] ${scope}` : scope;
80
+ const path = subScop4 ? `${subScop3}.${subScop4}` : subScop3;
81
+ 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)];
82
+ }
83
+ case 'cache':
84
+ {
85
+ const scopePath = prefix ? `${scope} (${prefix})` : scope;
86
+ 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])];
87
+ }
88
+ }
89
+ return [];
90
+ }
91
+ function isNonEmptyString(str) {
92
+ return Boolean(str && typeof str === 'string');
93
+ }
94
+ function constructResource(type, id, lid) {
95
+ if (typeof type === 'object' && type !== null) {
96
+ const resource = type;
97
+ if (isResourceKey(resource)) {
98
+ return resource;
99
+ }
100
+ if ('id' in resource) {
101
+ resource.id = coerceId(resource.id);
102
+ }
103
+ return resource;
104
+ } else {
105
+ const trueId = coerceId(id);
106
+ if (!isNonEmptyString(trueId)) {
107
+ if (isNonEmptyString(lid)) {
108
+ return {
109
+ lid
110
+ };
111
+ }
112
+ throw new Error('Expected either id or lid to be a valid string');
113
+ }
114
+ if (isNonEmptyString(lid)) {
115
+ return {
116
+ type,
117
+ id: trueId,
118
+ lid
119
+ };
120
+ }
121
+ return {
122
+ type,
123
+ id: trueId
124
+ };
125
+ }
126
+ }
127
+ export { coerceId, constructResource, isResourceKey, log, logGroup };