@warp-drive-mirror/utilities 5.7.0-alpha.9 → 5.7.0

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.
@@ -59,7 +59,7 @@ export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "d
59
59
  * @param identifier
60
60
  * @param options
61
61
  */
62
- export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
62
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
63
63
  export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
64
- export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
64
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
65
65
  export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
49
49
  * @param query
50
50
  * @param options
51
51
  */
52
- export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;
52
+ export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>>;
53
53
  export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
@@ -1,5 +1,11 @@
1
1
  import type { Future, Handler, NextFn } from "@warp-drive-mirror/core/request";
2
2
  import type { RequestContext } from "@warp-drive-mirror/core/types/request";
3
+ /**
4
+ * Whether the browser supports `ReadableStream` as a request body
5
+ * in a `POST` request.
6
+ *
7
+ * @group Constants
8
+ */
3
9
  export declare const SupportsRequestStreams: boolean;
4
10
  interface Constraints {
5
11
  /**
@@ -138,7 +144,7 @@ interface CompressionOptions {
138
144
  * }
139
145
  * ```
140
146
  *
141
- * @class AutoCompress
147
+ * @group Handlers
142
148
  * @public
143
149
  * @since 5.5.0
144
150
  */
@@ -7,6 +7,7 @@ import type { RequestContext, StructuredDataDocument } from "@warp-drive-mirror/
7
7
  type CheckFn = (context: RequestContext) => boolean;
8
8
  /**
9
9
  *
10
+ * @group Handlers
10
11
  * @public
11
12
  */
12
13
  export declare class Gate implements Handler {
@@ -0,0 +1,47 @@
1
+ import type { Handler } from "@warp-drive-mirror/core/request";
2
+ /**
3
+ * MetaDocHandler processes requests that are marked as meta requests.
4
+ *
5
+ * It treats the response body as "entirely meta" transforming
6
+ *
7
+ * ```ts
8
+ * {
9
+ * some: "key",
10
+ * another: "thing"
11
+ * }
12
+ * ```
13
+ *
14
+ * into
15
+ *
16
+ * ```ts
17
+ * {
18
+ * meta: {
19
+ * some: "key",
20
+ * another: "thing"
21
+ * }
22
+ * }
23
+ * ```
24
+ *
25
+ * To activate this handler, a request should specify
26
+ *
27
+ * ```ts
28
+ * options.isMetaRequest = true
29
+ * ```
30
+ *
31
+ * For instance
32
+ *
33
+ * ```ts
34
+ * store.request({
35
+ * url: '/example',
36
+ * options: {
37
+ * isMetaRequest: true
38
+ * }
39
+ * });
40
+ * ```
41
+ *
42
+ * Errors are not processed by this handler, so if the request fails and the error response
43
+ * is not in {JSON:API} format additional processing may be needed.
44
+ *
45
+ * @group Handlers
46
+ */
47
+ export declare const MetaDocHandler: Handler;
@@ -2,10 +2,14 @@
2
2
  * A unique identifier for the current browser tab
3
3
  * useful for observability/tracing and deduping
4
4
  * across multiple tabs.
5
+ *
6
+ * @group Constants
5
7
  */
6
8
  export declare const TAB_ID: string;
7
9
  /**
8
10
  * The epoch seconds at which the tab id was generated
11
+ *
12
+ * @group Constants
9
13
  */
10
14
  export declare const TAB_ASSIGNED: number;
11
15
  /**
@@ -16,17 +20,22 @@ export declare const TAB_ASSIGNED: number;
16
20
  * to enable tracking the browser tab of origin across multiple requests.
17
21
  *
18
22
  * Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
23
+ *
24
+ * @group Utility Functions
19
25
  */
20
26
  export declare function addTraceHeader(headers: Headers): Headers;
21
27
  /**
22
28
  * Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
23
29
  * As of 2024-12-05 the maximum URL length is 8192 bytes.
24
30
  *
31
+ * @group Constants
25
32
  */
26
33
  export declare const MAX_URL_LENGTH = 8192;
27
34
  /**
28
35
  * This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
29
36
  *
30
37
  * See also {@link MAX_URL_LENGTH}
38
+ *
39
+ * @group Utility Functions
31
40
  */
32
41
  export declare function assertInvalidUrlLength(url: string | undefined): void;
@@ -59,7 +59,7 @@ import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/s
59
59
  export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "data"> & {
60
60
  data: T;
61
61
  };
62
- export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
62
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
63
63
  export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
64
- export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
64
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
65
65
  export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
@@ -53,7 +53,7 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
53
53
  * @param query
54
54
  * @param options
55
55
  */
56
- export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource<T>, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;
56
+ export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>>;
57
57
  export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
58
58
  /**
59
59
  * Builds request options to query for resources, usually by a primary
@@ -99,5 +99,5 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
99
99
  * @param query
100
100
  * @param options
101
101
  */
102
- export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;
102
+ export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<CollectionResourceDataDocument<T>>;
103
103
  export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
@@ -1,5 +1,5 @@
1
1
  import type { Cache } from "@warp-drive-mirror/core/types/cache";
2
- import type { StableRecordIdentifier } from "@warp-drive-mirror/core/types/identifier";
2
+ import type { ResourceKey } from "@warp-drive-mirror/core/types/identifier";
3
3
  import type { Value } from "@warp-drive-mirror/core/types/json/raw";
4
4
  import type { InnerRelationshipDocument, ResourceObject } from "@warp-drive-mirror/core/types/spec/json-api-raw";
5
5
  type ChangedRelationshipData = InnerRelationshipDocument;
@@ -20,13 +20,13 @@ export type JsonApiResourcePatch = {
20
20
  *
21
21
  * @public
22
22
  * @param {Cache} cache}
23
- * @param {StableRecordIdentifier} identifier
23
+ * @param {ResourceKey} identifier
24
24
  * @return {Object} An object with a `data` property containing the serialized resource patch
25
25
  */
26
- export declare function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): {
26
+ export declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
27
27
  data: ResourceObject;
28
28
  };
29
- export declare function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): {
29
+ export declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
30
30
  data: ResourceObject[];
31
31
  };
32
32
  /**
@@ -47,10 +47,10 @@ export declare function serializeResources(cache: Cache, identifiers: StableReco
47
47
  *
48
48
  * @public
49
49
  * @param {Cache} cache}
50
- * @param {StableRecordIdentifier} identifier
50
+ * @param {ResourceKey} identifier
51
51
  * @return {Object} An object with a `data` property containing the serialized resource patch
52
52
  */
53
- export declare function serializePatch(cache: Cache, identifier: StableRecordIdentifier): {
53
+ export declare function serializePatch(cache: Cache, identifier: ResourceKey): {
54
54
  data: JsonApiResourcePatch;
55
55
  };
56
56
  export {};
@@ -59,7 +59,7 @@ import type { SingleResourceDataDocument } from "@warp-drive-mirror/core/types/s
59
59
  export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, "data"> & {
60
60
  data: T;
61
61
  };
62
- export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
62
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
63
63
  export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
64
- export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
64
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
65
65
  export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
@@ -49,5 +49,5 @@ import type { CollectionResourceDataDocument } from "@warp-drive-mirror/core/typ
49
49
  * @param query
50
50
  * @param options
51
51
  */
52
- export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;
52
+ export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>>;
53
53
  export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
@@ -6,4 +6,5 @@
6
6
  */
7
7
  export { AutoCompress, SupportsRequestStreams } from "./-private/handlers/auto-compress.js";
8
8
  export { Gate } from "./-private/handlers/gated.js";
9
+ export { MetaDocHandler } from "./-private/handlers/meta-doc.js";
9
10
  export { addTraceHeader, TAB_ASSIGNED, TAB_ID, assertInvalidUrlLength, MAX_URL_LENGTH } from "./-private/handlers/utils.js";
@@ -1,7 +1,4 @@
1
1
  import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from "@warp-drive-mirror/core/types/params";
2
- // prevents the final constructed object from needing to add
3
- // host and namespace which are provided by the final consuming
4
- // class to the prototype which can result in overwrite errors
5
2
  export interface BuildURLConfig {
6
3
  host: string | null;
7
4
  namespace: string | null;
package/dist/handlers.js CHANGED
@@ -2,6 +2,13 @@ import { macroCondition, getGlobalConfig } from '@embroider/macros';
2
2
  function isCompressibleMethod(method) {
3
3
  return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
4
4
  }
5
+
6
+ /**
7
+ * Whether the browser supports `ReadableStream` as a request body
8
+ * in a `POST` request.
9
+ *
10
+ * @group Constants
11
+ */
5
12
  const SupportsRequestStreams = (() => {
6
13
  let duplexAccessed = false;
7
14
  const hasContentType = new Request('', {
@@ -54,7 +61,7 @@ const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
54
61
  * }
55
62
  * ```
56
63
  *
57
- * @class AutoCompress
64
+ * @group Handlers
58
65
  * @public
59
66
  * @since 5.5.0
60
67
  */
@@ -154,6 +161,7 @@ function encodingForFormat(format) {
154
161
 
155
162
  /**
156
163
  *
164
+ * @group Handlers
157
165
  * @public
158
166
  */
159
167
  class Gate {
@@ -168,6 +176,67 @@ class Gate {
168
176
  return next(context.request);
169
177
  }
170
178
  }
179
+
180
+ /**
181
+ * MetaDocHandler processes requests that are marked as meta requests.
182
+ *
183
+ * It treats the response body as "entirely meta" transforming
184
+ *
185
+ * ```ts
186
+ * {
187
+ * some: "key",
188
+ * another: "thing"
189
+ * }
190
+ * ```
191
+ *
192
+ * into
193
+ *
194
+ * ```ts
195
+ * {
196
+ * meta: {
197
+ * some: "key",
198
+ * another: "thing"
199
+ * }
200
+ * }
201
+ * ```
202
+ *
203
+ * To activate this handler, a request should specify
204
+ *
205
+ * ```ts
206
+ * options.isMetaRequest = true
207
+ * ```
208
+ *
209
+ * For instance
210
+ *
211
+ * ```ts
212
+ * store.request({
213
+ * url: '/example',
214
+ * options: {
215
+ * isMetaRequest: true
216
+ * }
217
+ * });
218
+ * ```
219
+ *
220
+ * Errors are not processed by this handler, so if the request fails and the error response
221
+ * is not in {JSON:API} format additional processing may be needed.
222
+ *
223
+ * @group Handlers
224
+ */
225
+ const MetaDocHandler = {
226
+ request(context, next) {
227
+ if (!context.request.options?.isMetaRequest) {
228
+ return next(context.request);
229
+ }
230
+ return next(context.request).then(response => {
231
+ return processResponse(response);
232
+ });
233
+ }
234
+ };
235
+ function processResponse(response) {
236
+ return {
237
+ meta: response.content
238
+ };
239
+ }
171
240
  if (typeof FastBoot === 'undefined') {
172
241
  globalThis.addEventListener('beforeunload', function () {
173
242
  sessionStorage.setItem('tab-closed', 'true');
@@ -195,10 +264,14 @@ function getTabId() {
195
264
  * A unique identifier for the current browser tab
196
265
  * useful for observability/tracing and deduping
197
266
  * across multiple tabs.
267
+ *
268
+ * @group Constants
198
269
  */
199
270
  const TAB_ID = getTabId();
200
271
  /**
201
272
  * The epoch seconds at which the tab id was generated
273
+ *
274
+ * @group Constants
202
275
  */
203
276
  const TAB_ASSIGNED = Math.floor(Date.now() / 1000);
204
277
 
@@ -210,6 +283,8 @@ const TAB_ASSIGNED = Math.floor(Date.now() / 1000);
210
283
  * to enable tracking the browser tab of origin across multiple requests.
211
284
  *
212
285
  * Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
286
+ *
287
+ * @group Utility Functions
213
288
  */
214
289
  function addTraceHeader(headers) {
215
290
  const now = Math.floor(Date.now() / 1000);
@@ -221,6 +296,7 @@ function addTraceHeader(headers) {
221
296
  * Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
222
297
  * As of 2024-12-05 the maximum URL length is 8192 bytes.
223
298
  *
299
+ * @group Constants
224
300
  */
225
301
  const MAX_URL_LENGTH = 8192;
226
302
 
@@ -228,6 +304,8 @@ const MAX_URL_LENGTH = 8192;
228
304
  * This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
229
305
  *
230
306
  * See also {@link MAX_URL_LENGTH}
307
+ *
308
+ * @group Utility Functions
231
309
  */
232
310
  function assertInvalidUrlLength(url) {
233
311
  macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
@@ -236,4 +314,4 @@ function assertInvalidUrlLength(url) {
236
314
  }
237
315
  })(!url || url.length <= MAX_URL_LENGTH) : {};
238
316
  }
239
- export { AutoCompress, Gate, MAX_URL_LENGTH, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
317
+ export { AutoCompress, Gate, MAX_URL_LENGTH, MetaDocHandler, SupportsRequestStreams, TAB_ASSIGNED, TAB_ID, addTraceHeader, assertInvalidUrlLength };
package/dist/json-api.js CHANGED
@@ -538,7 +538,7 @@ function updateRecord(record, options = {}) {
538
538
  *
539
539
  * @public
540
540
  * @param {Cache} cache}
541
- * @param {StableRecordIdentifier} identifier
541
+ * @param {ResourceKey} identifier
542
542
  * @return {Object} An object with a `data` property containing the serialized resource patch
543
543
  */
544
544
  function serializeResources(cache, identifiers) {
@@ -623,7 +623,7 @@ function _serializeResource(cache, identifier) {
623
623
  *
624
624
  * @public
625
625
  * @param {Cache} cache}
626
- * @param {StableRecordIdentifier} identifier
626
+ * @param {ResourceKey} identifier
627
627
  * @return {Object} An object with a `data` property containing the serialized resource patch
628
628
  */
629
629
  function serializePatch(cache, identifier) {
package/dist/string.cjs CHANGED
@@ -22,7 +22,7 @@ const DEFAULT_MAX_CACHE_SIZE = 10_000;
22
22
  * and by `@warp-drive-mirror/utilities/string`. It is not intended
23
23
  * for use outside of these modules at this time.
24
24
  *
25
- * @internal
25
+ * @private
26
26
  */
27
27
  class LRUCache {
28
28
  // debug stats
@@ -68,7 +68,7 @@ const STRING_DASHERIZE_CACHE = new LRUCache(key => key.replace(STRING_DECAMELIZE
68
68
  * This version is only in this location to support a deprecated
69
69
  * behavior in the core package and will be removed in a future.
70
70
  *
71
- * @internal
71
+ * @private
72
72
  */
73
73
  function dasherize$1(str) {
74
74
  return STRING_DASHERIZE_CACHE.get(str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warp-drive-mirror/utilities",
3
- "version": "5.7.0-alpha.9",
3
+ "version": "5.7.0",
4
4
  "description": "Utilities package for WarpDrive | Things your app might find useful",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -36,21 +36,21 @@
36
36
  }
37
37
  },
38
38
  "peerDependencies": {
39
- "@warp-drive-mirror/core": "5.7.0-alpha.9"
39
+ "@warp-drive-mirror/core": "5.7.0"
40
40
  },
41
41
  "dependencies": {
42
- "@embroider/macros": "^1.16.12"
42
+ "@embroider/macros": "^1.18.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@babel/core": "^7.26.10",
46
- "@babel/plugin-transform-typescript": "^7.27.0",
47
- "@babel/preset-typescript": "^7.27.0",
48
- "@warp-drive/internal-config": "5.7.0-alpha.9",
49
- "@warp-drive-mirror/core": "5.7.0-alpha.9",
45
+ "@babel/core": "^7.28.3",
46
+ "@babel/plugin-transform-typescript": "^7.28.0",
47
+ "@babel/preset-typescript": "^7.27.1",
48
+ "@warp-drive/internal-config": "5.7.0",
49
+ "@warp-drive-mirror/core": "5.7.0",
50
50
  "decorator-transforms": "^2.3.0",
51
- "expect-type": "^1.2.1",
52
- "typescript": "^5.8.3",
53
- "vite": "^7.0.0"
51
+ "expect-type": "^1.2.2",
52
+ "typescript": "^5.9.2",
53
+ "vite": "^7.1.3"
54
54
  },
55
55
  "volta": {
56
56
  "extends": "../../../../../../package.json"