@warp-drive/core 5.6.0-alpha.18 → 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,3 +0,0 @@
1
- export { C as CollectionRecordArray, D as DISPOSE, I as LiveArray, M as MUTATE, R as RecordArrayManager, l as RelatedCollection, d as SOURCE, A as Signals, S as Store, j as StoreMap, _ as _clearCaches, n as _deprecatingNormalize, b as coerceId, c as constructResource, G as consumeInternalSignal, t as createRequestSubscription, z as defineNonEnumerableSignal, y as defineSignal, e as ensureStringId, x as entangleSignal, f as fastPush, w as gate, H as getOrCreateInternalSignal, q as getPromiseState, u as getRequestState, a as isDocumentIdentifier, i as isStableIdentifier, m as log, o as logGroup, v as memoized, F as notifyInternalSignal, p as peekCache, B as peekInternalSignal, r as recordIdentifierFor, g as removeRecordDataFor, k as setCacheFor, h as setRecordIdentifier, s as storeFor, E as withSignalStore } from "../request-state-CjLph1LP.js";
2
- export { C as CacheHandler } from "../handler-C2T-IyJK.js";
3
- export { A as ARRAY_SIGNAL, O as OBJECT_SIGNAL, c as createMemo, w as waitFor } from "../configure-B48bFHOl.js";
package/dist/store.js DELETED
@@ -1,545 +0,0 @@
1
- import { deprecate } from '@ember/debug';
2
- import { LRUCache } from './utils/string.js';
3
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
4
- const NUMERIC_KEYS = new Set(['max-age', 's-maxage', 'stale-if-error', 'stale-while-revalidate']);
5
-
6
- /**
7
- * Parses a string Cache-Control header value into an object with the following structure:
8
- *
9
- * ```ts
10
- * interface CacheControlValue {
11
- * immutable?: boolean;
12
- * 'max-age'?: number;
13
- * 'must-revalidate'?: boolean;
14
- * 'must-understand'?: boolean;
15
- * 'no-cache'?: boolean;
16
- * 'no-store'?: boolean;
17
- * 'no-transform'?: boolean;
18
- * 'only-if-cached'?: boolean;
19
- * private?: boolean;
20
- * 'proxy-revalidate'?: boolean;
21
- * public?: boolean;
22
- * 's-maxage'?: number;
23
- * 'stale-if-error'?: number;
24
- * 'stale-while-revalidate'?: number;
25
- * }
26
- * ```
27
- *
28
- * @public
29
- * @param {String} header
30
- * @return {CacheControlValue}
31
- */
32
- function parseCacheControl(header) {
33
- return CACHE_CONTROL_CACHE.get(header);
34
- }
35
- const CACHE_CONTROL_CACHE = new LRUCache(header => {
36
- let key = '';
37
- let value = '';
38
- let isParsingKey = true;
39
- const cacheControlValue = {};
40
- for (let i = 0; i < header.length; i++) {
41
- const char = header.charAt(i);
42
- if (char === ',') {
43
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
44
- if (!test) {
45
- throw new Error(`Invalid Cache-Control value, expected a value`);
46
- }
47
- })(!isParsingKey || !NUMERIC_KEYS.has(key)) : {};
48
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
49
- if (!test) {
50
- throw new Error(`Invalid Cache-Control value, expected a value after "=" but got ","`);
51
- }
52
- })(i === 0 || header.charAt(i - 1) !== '=') : {};
53
- isParsingKey = true;
54
- // @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined
55
- cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;
56
- key = '';
57
- value = '';
58
- continue;
59
- } else if (char === '=') {
60
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
61
- if (!test) {
62
- throw new Error(`Invalid Cache-Control value, expected a value after "="`);
63
- }
64
- })(i + 1 !== header.length) : {};
65
- isParsingKey = false;
66
- } else if (char === ' ' || char === `\t` || char === `\n`) {
67
- continue;
68
- } else if (isParsingKey) {
69
- key += char;
70
- } else {
71
- value += char;
72
- }
73
- if (i === header.length - 1) {
74
- // @ts-expect-error TS incorrectly thinks that optional keys must have a type that includes undefined
75
- cacheControlValue[key] = NUMERIC_KEYS.has(key) ? parseCacheControlValue(value) : true;
76
- }
77
- }
78
- return cacheControlValue;
79
- }, 200);
80
- function parseCacheControlValue(stringToParse) {
81
- const parsedValue = Number.parseInt(stringToParse);
82
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
83
- if (!test) {
84
- throw new Error(`Invalid Cache-Control value, expected a number but got - ${stringToParse}`);
85
- }
86
- })(!Number.isNaN(parsedValue)) : {};
87
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
88
- if (!test) {
89
- throw new Error(`Invalid Cache-Control value, expected a number greater than 0 but got - ${stringToParse}`);
90
- }
91
- })(parsedValue >= 0) : {};
92
- if (Number.isNaN(parsedValue) || parsedValue < 0) {
93
- return 0;
94
- }
95
- return parsedValue;
96
- }
97
- function isExpired(identifier, request, config) {
98
- const {
99
- constraints
100
- } = config;
101
- if (constraints?.isExpired) {
102
- const result = constraints.isExpired(request);
103
- if (result !== null) {
104
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
105
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
106
- // eslint-disable-next-line no-console
107
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because constraints.isExpired returned ${result}`);
108
- }
109
- }
110
- return result;
111
- }
112
- }
113
- const {
114
- headers
115
- } = request.response;
116
- if (!headers) {
117
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
118
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
119
- // eslint-disable-next-line no-console
120
- console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no headers were provided`);
121
- }
122
- }
123
-
124
- // if we have no headers then both the headers based expiration
125
- // and the time based expiration will be considered expired
126
- return true;
127
- }
128
-
129
- // check for X-WarpDrive-Expires
130
- const now = Date.now();
131
- const date = headers.get('Date');
132
- if (constraints?.headers) {
133
- if (constraints.headers['X-WarpDrive-Expires']) {
134
- const xWarpDriveExpires = headers.get('X-WarpDrive-Expires');
135
- if (xWarpDriveExpires) {
136
- const expirationTime = new Date(xWarpDriveExpires).getTime();
137
- const result = now >= expirationTime;
138
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
139
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
140
- // eslint-disable-next-line no-console
141
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by X-WarpDrive-Expires header is ${result ? 'in the past' : 'in the future'}`);
142
- }
143
- }
144
- return result;
145
- }
146
- }
147
-
148
- // check for Cache-Control
149
- if (constraints.headers['Cache-Control']) {
150
- const cacheControl = headers.get('Cache-Control');
151
- const age = headers.get('Age');
152
- if (cacheControl && age && date) {
153
- const cacheControlValue = parseCacheControl(cacheControl);
154
-
155
- // max-age and s-maxage are stored in
156
- const maxAge = cacheControlValue['max-age'] || cacheControlValue['s-maxage'];
157
- if (maxAge) {
158
- // age is stored in seconds
159
- const ageValue = parseInt(age, 10);
160
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
161
- if (!test) {
162
- throw new Error(`Invalid Cache-Control value, expected a number but got - ${age}`);
163
- }
164
- })(!Number.isNaN(ageValue)) : {};
165
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
166
- if (!test) {
167
- throw new Error(`Invalid Cache-Control value, expected a number greater than 0 but got - ${age}`);
168
- }
169
- })(ageValue >= 0) : {};
170
- if (!Number.isNaN(ageValue) && ageValue >= 0) {
171
- const dateValue = new Date(date).getTime();
172
- const expirationTime = dateValue + (maxAge - ageValue) * 1000;
173
- const result = now >= expirationTime;
174
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
175
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
176
- // eslint-disable-next-line no-console
177
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Cache-Control header is ${result ? 'in the past' : 'in the future'}`);
178
- }
179
- }
180
- return result;
181
- }
182
- }
183
- }
184
- }
185
-
186
- // check for Expires
187
- if (constraints.headers.Expires) {
188
- const expires = headers.get('Expires');
189
- if (expires) {
190
- const expirationTime = new Date(expires).getTime();
191
- const result = now >= expirationTime;
192
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
193
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
194
- // eslint-disable-next-line no-console
195
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the time set by Expires header is ${result ? 'in the past' : 'in the future'}`);
196
- }
197
- }
198
- return result;
199
- }
200
- }
201
- }
202
-
203
- // check for Date
204
- if (!date) {
205
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
206
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
207
- // eslint-disable-next-line no-console
208
- console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no Date header was provided`);
209
- }
210
- }
211
- return true;
212
- }
213
- let expirationTime = config.apiCacheHardExpires;
214
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
215
- if (!config.disableTestOptimization) {
216
- expirationTime = config.apiCacheSoftExpires;
217
- }
218
- }
219
- const time = new Date(date).getTime();
220
- const deadline = time + expirationTime;
221
- const result = now >= deadline;
222
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
223
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
224
- // eslint-disable-next-line no-console
225
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'EXPIRED' : 'NOT expired'} because the apiCacheHardExpires time since the response's Date header is ${result ? 'in the past' : 'in the future'}`);
226
- }
227
- }
228
- return result;
229
- }
230
-
231
- /**
232
- * The configuration options for the {@link DefaultCachePolicy}
233
- *
234
- * ```ts
235
- * import { DefaultCachePolicy } from '@warp-drive/core/store';
236
- *
237
- * new DefaultCachePolicy({
238
- * // ... PolicyConfig Settings ... //
239
- * });
240
- * ```
241
- *
242
- */
243
-
244
- /**
245
- * A basic CachePolicy that can be added to the Store service.
246
- *
247
- * Determines staleness based on time since the request was last received from the API
248
- * using the `date` header.
249
- *
250
- * Determines expiration based on configured constraints as well as a time based
251
- * expiration strategy based on the `date` header.
252
- *
253
- * In order expiration is determined by:
254
- *
255
- * - Is explicitly invalidated
256
- * - ↳ (if null) isExpired function \<IF Constraint Active>
257
- * - ↳ (if null) X-WarpDrive-Expires header \<IF Constraint Active>
258
- * - ↳ (if null) Cache-Control header \<IF Constraint Active>
259
- * - ↳ (if null) Expires header \<IF Constraint Active>
260
- * - ↳ (if null) Date header + apiCacheHardExpires \< current time
261
- *
262
- * Invalidates any request for which `cacheOptions.types` was provided when a createRecord
263
- * request for that type is successful.
264
- *
265
- * For this to work, the `createRecord` request must include the `cacheOptions.types` array
266
- * with the types that should be invalidated, or its request should specify the identifiers
267
- * of the records that are being created via `records`. Providing both is valid.
268
- *
269
- * > [!NOTE]
270
- * > only requests that had specified `cacheOptions.types` and occurred prior to the
271
- * > createRecord request will be invalidated. This means that a given request should always
272
- * > specify the types that would invalidate it to opt into this behavior. Abstracting this
273
- * > behavior via builders is recommended to ensure consistency.
274
- *
275
- * This allows the Store's CacheHandler to determine if a request is expired and
276
- * should be refetched upon next request.
277
- *
278
- * The `Fetch` handler provided by `@warp-drive/core` will automatically
279
- * add the `date` header to responses if it is not present.
280
- *
281
- * > [!NOTE]
282
- * > Date headers do not have millisecond precision, so expiration times should
283
- * > generally be larger than 1000ms.
284
- *
285
- * Usage:
286
- *
287
- * ```ts
288
- * import { Store } from '@warp-drive/core';
289
- * import { DefaultCachePolicy } from '@warp-drive/core/store';
290
- *
291
- * export class AppStore extends Store {
292
- * lifetimes = new DefaultCachePolicy({
293
- * apiCacheSoftExpires: 30_000,
294
- * apiCacheHardExpires: 60_000
295
- * });
296
- * }
297
- * ```
298
- *
299
- * In Testing environments, the `apiCacheSoftExpires` will always be `false`
300
- * and `apiCacheHardExpires` will use the `apiCacheSoftExpires` value.
301
- *
302
- * This helps reduce flakiness and produce predictably rendered results in test suites.
303
- *
304
- * Requests that specifically set `cacheOptions.backgroundReload = true` will
305
- * still be background reloaded in tests.
306
- *
307
- * This behavior can be opted out of by setting `disableTestOptimization = true`
308
- * in the policy config.
309
- *
310
- * @public
311
- */
312
- class DefaultCachePolicy {
313
- _getStore(store) {
314
- let set = this._stores.get(store);
315
- if (!set) {
316
- set = {
317
- invalidated: new Set(),
318
- types: new Map()
319
- };
320
- this._stores.set(store, set);
321
- }
322
- return set;
323
- }
324
- constructor(config) {
325
- this._stores = new WeakMap();
326
- const _config = arguments.length === 1 ? config : arguments[1];
327
- deprecate(`Passing a Store to the CachePolicy is deprecated, please pass only a config instead.`, arguments.length === 1, {
328
- id: 'ember-data:request-utils:lifetimes-service-store-arg',
329
- since: {
330
- enabled: '5.4',
331
- available: '4.13'
332
- },
333
- for: '@ember-data/request-utils',
334
- until: '6.0'
335
- });
336
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
337
- if (!test) {
338
- throw new Error(`You must pass a config to the CachePolicy`);
339
- }
340
- })(_config) : {};
341
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
342
- if (!test) {
343
- throw new Error(`You must pass a apiCacheSoftExpires to the CachePolicy`);
344
- }
345
- })(typeof _config.apiCacheSoftExpires === 'number') : {};
346
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
347
- if (!test) {
348
- throw new Error(`You must pass a apiCacheHardExpires to the CachePolicy`);
349
- }
350
- })(typeof _config.apiCacheHardExpires === 'number') : {};
351
- this.config = _config;
352
- }
353
-
354
- /**
355
- * Invalidate a request by its identifier for a given store instance.
356
- *
357
- * While the store argument may seem redundant, the CachePolicy
358
- * is designed to be shared across multiple stores / forks
359
- * of the store.
360
- *
361
- * ```ts
362
- * store.lifetimes.invalidateRequest(store, identifier);
363
- * ```
364
- *
365
- * @public
366
- * @param {StableDocumentIdentifier} identifier
367
- * @param {Store} store
368
- */
369
- invalidateRequest(identifier, store) {
370
- this._getStore(store).invalidated.add(identifier);
371
- }
372
-
373
- /**
374
- * Invalidate all requests associated to a specific type
375
- * for a given store instance.
376
- *
377
- * While the store argument may seem redundant, the CachePolicy
378
- * is designed to be shared across multiple stores / forks
379
- * of the store.
380
- *
381
- * This invalidation is done automatically when using this service
382
- * for both the CacheHandler and the LegacyNetworkHandler.
383
- *
384
- * ```ts
385
- * store.lifetimes.invalidateRequestsForType(store, 'person');
386
- * ```
387
- *
388
- * @public
389
- * @param {String} type
390
- * @param {Store} store
391
- */
392
- invalidateRequestsForType(type, store) {
393
- const storeCache = this._getStore(store);
394
- const set = storeCache.types.get(type);
395
- const notifications = store.notifications;
396
- if (set) {
397
- // TODO batch notifications
398
- set.forEach(id => {
399
- storeCache.invalidated.add(id);
400
- notifications.notify(id, 'invalidated');
401
- });
402
- }
403
- }
404
-
405
- /**
406
- * Invoked when a request has been fulfilled from the configured request handlers.
407
- * This is invoked by the CacheHandler for both foreground and background requests
408
- * once the cache has been updated.
409
- *
410
- * Note, this is invoked by the CacheHandler regardless of whether
411
- * the request has a cache-key.
412
- *
413
- * This method should not be invoked directly by consumers.
414
- *
415
- * @public
416
- * @param {ImmutableRequestInfo} request
417
- * @param {ImmutableResponse} response
418
- * @param {Store} store
419
- * @param {StableDocumentIdentifier | null} identifier
420
- * @return {void}
421
- */
422
- didRequest(request, response, identifier, store) {
423
- // if this is a successful createRecord request, invalidate the cacheKey for the type
424
- if (request.op === 'createRecord') {
425
- const statusNumber = response?.status ?? 0;
426
- if (statusNumber >= 200 && statusNumber < 400) {
427
- const types = new Set(request.records?.map(r => r.type));
428
- const additionalTypes = request.cacheOptions?.types;
429
- additionalTypes?.forEach(type => {
430
- types.add(type);
431
- });
432
- types.forEach(type => {
433
- this.invalidateRequestsForType(type, store);
434
- });
435
- }
436
-
437
- // add this document's cacheKey to a map for all associated types
438
- // it is recommended to only use this for queries
439
- } else if (identifier && request.cacheOptions?.types?.length) {
440
- const storeCache = this._getStore(store);
441
- request.cacheOptions?.types.forEach(type => {
442
- const set = storeCache.types.get(type);
443
- if (set) {
444
- set.add(identifier);
445
- storeCache.invalidated.delete(identifier);
446
- } else {
447
- storeCache.types.set(type, new Set([identifier]));
448
- }
449
- });
450
- }
451
- }
452
-
453
- /**
454
- * Invoked to determine if the request may be fulfilled from cache
455
- * if possible.
456
- *
457
- * Note, this is only invoked by the CacheHandler if the request has
458
- * a cache-key.
459
- *
460
- * If no cache entry is found or the entry is hard expired,
461
- * the request will be fulfilled from the configured request handlers
462
- * and the cache will be updated before returning the response.
463
- *
464
- * @public
465
- * @param {StableDocumentIdentifier} identifier
466
- * @param {Store} store
467
- * @return {Boolean} true if the request is considered hard expired
468
- */
469
- isHardExpired(identifier, store) {
470
- // if we are explicitly invalidated, we are hard expired
471
- const storeCache = this._getStore(store);
472
- if (storeCache.invalidated.has(identifier)) {
473
- return true;
474
- }
475
- const cache = store.cache;
476
- const cached = cache.peekRequest(identifier);
477
- if (!cached?.response) {
478
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
479
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
480
- // eslint-disable-next-line no-console
481
- console.log(`CachePolicy: ${identifier.lid} is EXPIRED because no cache entry was found`);
482
- }
483
- }
484
- return true;
485
- }
486
- return isExpired(identifier, cached, this.config);
487
- }
488
-
489
- /**
490
- * Invoked if `isHardExpired` is false to determine if the request
491
- * should be update behind the scenes if cache data is already available.
492
- *
493
- * Note, this is only invoked by the CacheHandler if the request has
494
- * a cache-key.
495
- *
496
- * If true, the request will be fulfilled from cache while a backgrounded
497
- * request is made to update the cache via the configured request handlers.
498
- *
499
- * @public
500
- * @param {StableDocumentIdentifier} identifier
501
- * @param {Store} store
502
- * @return {Boolean} true if the request is considered soft expired
503
- */
504
- isSoftExpired(identifier, store) {
505
- if (macroCondition(getGlobalConfig().WarpDrive.env.TESTING)) {
506
- if (!this.config.disableTestOptimization) {
507
- return false;
508
- }
509
- }
510
- const cache = store.cache;
511
- const cached = cache.peekRequest(identifier);
512
- if (cached?.response) {
513
- const date = cached.response.headers.get('date');
514
- if (!date) {
515
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
516
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
517
- // eslint-disable-next-line no-console
518
- console.log(`CachePolicy: ${identifier.lid} is STALE because no date header was found`);
519
- }
520
- }
521
- return true;
522
- } else {
523
- const time = new Date(date).getTime();
524
- const now = Date.now();
525
- const deadline = time + this.config.apiCacheSoftExpires;
526
- const result = now >= deadline;
527
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
528
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
529
- // eslint-disable-next-line no-console
530
- console.log(`CachePolicy: ${identifier.lid} is ${result ? 'STALE' : 'NOT stale'}. Expiration time: ${deadline}, now: ${now}`);
531
- }
532
- }
533
- return result;
534
- }
535
- }
536
- if (macroCondition(getGlobalConfig().WarpDrive.activeLogging.LOG_CACHE_POLICY)) {
537
- if (getGlobalConfig().WarpDrive.debug.LOG_CACHE_POLICY || globalThis.getWarpDriveRuntimeConfig().debug.LOG_CACHE_POLICY) {
538
- // eslint-disable-next-line no-console
539
- console.log(`CachePolicy: ${identifier.lid} is STALE because no cache entry was found`);
540
- }
541
- }
542
- return true;
543
- }
544
- }
545
- export { DefaultCachePolicy, parseCacheControl };
@@ -1,44 +0,0 @@
1
- import { getOrSetGlobal } from './types/-private.js';
2
-
3
- ///////////////////
4
- ///// WARNING /////
5
- ///////////////////
6
-
7
- // Great, got your attention with that warning didn't we?
8
- // Good. Here's the deal: typescript treats symbols as unique types.
9
- // If by accident a module creating a symbol is processed more than
10
- // once, the symbol will be different in each processing. This will
11
- // cause a type error.
12
- // It could also cause a runtime error if the symbol is used innapropriately.
13
- // However, this case is extremely hard to hit and would require other things
14
- // to go wrong first.
15
- //
16
- // So, why do the warning? And why do we lie about the types of the symbols?
17
- //
18
- // Because we intentionally create multiple copies of them within the types
19
- // at build time. This is because we rollup our d.ts files in order to give
20
- // our consumers a better experience.
21
- //
22
- // However, no tool today supports rolling up d.ts files with multiple entry
23
- // points correctly. The tool we use currently (vite-plugin-dts) uses @microsoft/api-extractor
24
- // which creates a fully unique stand-alone types file per-entry-point. Thus
25
- // every entry point that uses one of these symbols somewhere will have accidentally
26
- // created a new symbol type.
27
- //
28
- // This cast allows us to rollup these types using this tool while not encountering
29
- // the unique symbol type issue.
30
- //
31
- // Note that none of these symbols are part of the public API, these are used for
32
- // debugging DX and as a safe way to provide an intimate contract on public objects.
33
-
34
- const SOURCE = getOrSetGlobal('SOURCE', Symbol('#source'));
35
- getOrSetGlobal('MUTATE', Symbol('#update'));
36
- const Destroy = getOrSetGlobal('Destroy', Symbol.dispose || Symbol.for('Dispose'));
37
- const Identifier = getOrSetGlobal('Identifier', Symbol('Identifier'));
38
- const Editable = getOrSetGlobal('Editable', Symbol('Editable'));
39
- const Parent = getOrSetGlobal('Parent', Symbol('Parent'));
40
- const Checkout = getOrSetGlobal('Checkout', Symbol('Checkout'));
41
- const Legacy = getOrSetGlobal('Legacy', Symbol('Legacy'));
42
- const EmbeddedPath = getOrSetGlobal('EmbeddedPath', Symbol('EmbeddedPath'));
43
- const EmbeddedField = getOrSetGlobal('EmbeddedField', Symbol('EmbeddedField'));
44
- export { Checkout as C, Destroy as D, Editable as E, Identifier as I, Legacy as L, Parent as P, SOURCE as S, EmbeddedPath as a, EmbeddedField as b };
@@ -1,92 +0,0 @@
1
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
2
- const DEFAULT_MAX_CACHE_SIZE = 10_000;
3
-
4
- /**
5
- * An LRUCache implementation with upsert semantics.
6
- *
7
- * This implementation is *not* generic, but focuses on
8
- * performance tuning for the string transformation cases
9
- * where the key maps to the value very simply.
10
- *
11
- * It takes a work function that should generate a new value
12
- * for a given key when called. It will be called when the key
13
- * is not found in the cache.
14
- *
15
- * It keeps track of the number of hits, misses, and ejections
16
- * in DEBUG envs, which is useful for tuning the cache size.
17
- *
18
- * This is an internal utility class for use by this module
19
- * and by `@warp-drive/utilities/string`. It is not intended
20
- * for use outside of these modules at this time.
21
- *
22
- * @internal
23
- */
24
- class LRUCache {
25
- // debug stats
26
-
27
- constructor(doWork, size) {
28
- this.size = size || DEFAULT_MAX_CACHE_SIZE;
29
- this.state = new Map();
30
- this.doWork = doWork;
31
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
32
- this._hits = 0;
33
- this._misses = 0;
34
- this._ejected = 0;
35
- }
36
- }
37
- get(key) {
38
- const value = this.state.get(key);
39
- if (value) {
40
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
41
- this._hits++;
42
- }
43
- this.state.delete(key);
44
- this.state.set(key, value);
45
- return value;
46
- }
47
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
48
- this._misses++;
49
- }
50
- const newValue = this.doWork(key);
51
- this.set(key, newValue);
52
- return newValue;
53
- }
54
- set(key, value) {
55
- if (this.state.size === this.size) {
56
- for (const [k] of this.state) {
57
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
58
- this._ejected++;
59
- }
60
- this.state.delete(k);
61
- break;
62
- }
63
- }
64
- this.state.set(key, value);
65
- }
66
- clear() {
67
- this.state.clear();
68
- if (macroCondition(getGlobalConfig().WarpDrive.env.DEBUG)) {
69
- this._hits = 0;
70
- this._misses = 0;
71
- this._ejected = 0;
72
- }
73
- }
74
- }
75
- const STRING_DASHERIZE_REGEXP = /[ _]/g;
76
- const STRING_DECAMELIZE_REGEXP = /([a-z\d])([A-Z])/g;
77
- const STRING_DASHERIZE_CACHE = new LRUCache(key => key.replace(STRING_DECAMELIZE_REGEXP, '$1_$2').toLowerCase().replace(STRING_DASHERIZE_REGEXP, '-'));
78
-
79
- /**
80
- * This is an internal utility function that converts a string
81
- * to a dasherized format. Library consumers should use the
82
- * re-exported version from `@warp-drive/utilities/string` instead.
83
- *
84
- * This version is only in this location to support a deprecated
85
- * behavior in the core package and will be removed in a future.
86
- *
87
- * @internal
88
- */
89
- function dasherize(str) {
90
- return STRING_DASHERIZE_CACHE.get(str);
91
- }
92
- export { LRUCache, STRING_DASHERIZE_CACHE, dasherize };