@warp-drive-mirror/utilities 5.8.0-alpha.30 → 5.8.0-alpha.34

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 (150) hide show
  1. package/dist/string.js +428 -1
  2. package/dist/unpkg/dev/-private.js +7 -0
  3. package/dist/unpkg/dev/active-record.js +395 -0
  4. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
  5. package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +64 -0
  6. package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +53 -0
  7. package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +146 -0
  8. package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +4 -0
  9. package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +158 -0
  10. package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +19 -0
  11. package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +47 -0
  12. package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +41 -0
  13. package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +109 -0
  14. package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +84 -0
  15. package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +100 -0
  16. package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +228 -0
  17. package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +70 -0
  18. package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +62 -0
  19. package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +53 -0
  20. package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +146 -0
  21. package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +82 -0
  22. package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +9 -0
  23. package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +77 -0
  24. package/dist/unpkg/dev/declarations/-private.d.ts +1 -0
  25. package/dist/unpkg/dev/declarations/active-record.d.ts +3 -0
  26. package/dist/unpkg/dev/declarations/derivations.d.ts +27 -0
  27. package/dist/unpkg/dev/declarations/handlers.d.ts +10 -0
  28. package/dist/unpkg/dev/declarations/index.d.ts +208 -0
  29. package/dist/unpkg/dev/declarations/json-api.d.ts +5 -0
  30. package/dist/unpkg/dev/declarations/rest.d.ts +3 -0
  31. package/dist/unpkg/dev/declarations/string.d.ts +14 -0
  32. package/dist/unpkg/dev/derivations.js +30 -0
  33. package/dist/unpkg/dev/handlers.js +317 -0
  34. package/dist/unpkg/dev/index.js +361 -0
  35. package/dist/unpkg/dev/inflect-BSG696t-.js +344 -0
  36. package/dist/unpkg/dev/json-api.js +740 -0
  37. package/dist/unpkg/dev/rest.js +393 -0
  38. package/dist/unpkg/dev/string.js +1 -0
  39. package/dist/unpkg/dev-deprecated/-private.js +7 -0
  40. package/dist/unpkg/dev-deprecated/active-record.js +395 -0
  41. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
  42. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  43. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  44. package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  45. package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  46. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  47. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  48. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  49. package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  50. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  51. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  52. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  53. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  54. package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  55. package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  56. package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +53 -0
  57. package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  58. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  59. package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  60. package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +77 -0
  61. package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +1 -0
  62. package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +3 -0
  63. package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +27 -0
  64. package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +10 -0
  65. package/dist/unpkg/dev-deprecated/declarations/index.d.ts +208 -0
  66. package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +5 -0
  67. package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +3 -0
  68. package/dist/unpkg/dev-deprecated/declarations/string.d.ts +14 -0
  69. package/dist/unpkg/dev-deprecated/derivations.js +30 -0
  70. package/dist/unpkg/dev-deprecated/handlers.js +317 -0
  71. package/dist/unpkg/dev-deprecated/index.js +361 -0
  72. package/dist/unpkg/dev-deprecated/inflect-BSG696t-.js +344 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +740 -0
  74. package/dist/unpkg/dev-deprecated/rest.js +393 -0
  75. package/dist/unpkg/dev-deprecated/string.js +1 -0
  76. package/dist/unpkg/prod/-private.js +7 -0
  77. package/dist/unpkg/prod/active-record.js +395 -0
  78. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
  79. package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +64 -0
  80. package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +53 -0
  81. package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +146 -0
  82. package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +4 -0
  83. package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +158 -0
  84. package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +19 -0
  85. package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +47 -0
  86. package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +41 -0
  87. package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +109 -0
  88. package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +84 -0
  89. package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +100 -0
  90. package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +228 -0
  91. package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +70 -0
  92. package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +62 -0
  93. package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +53 -0
  94. package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +146 -0
  95. package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +82 -0
  96. package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +9 -0
  97. package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +77 -0
  98. package/dist/unpkg/prod/declarations/-private.d.ts +1 -0
  99. package/dist/unpkg/prod/declarations/active-record.d.ts +3 -0
  100. package/dist/unpkg/prod/declarations/derivations.d.ts +27 -0
  101. package/dist/unpkg/prod/declarations/handlers.d.ts +10 -0
  102. package/dist/unpkg/prod/declarations/index.d.ts +208 -0
  103. package/dist/unpkg/prod/declarations/json-api.d.ts +5 -0
  104. package/dist/unpkg/prod/declarations/rest.d.ts +3 -0
  105. package/dist/unpkg/prod/declarations/string.d.ts +14 -0
  106. package/dist/unpkg/prod/derivations.js +30 -0
  107. package/dist/unpkg/prod/handlers.js +317 -0
  108. package/dist/unpkg/prod/index.js +361 -0
  109. package/dist/unpkg/prod/inflect-BSG696t-.js +344 -0
  110. package/dist/unpkg/prod/json-api.js +740 -0
  111. package/dist/unpkg/prod/rest.js +393 -0
  112. package/dist/unpkg/prod/string.js +1 -0
  113. package/dist/unpkg/prod-deprecated/-private.js +7 -0
  114. package/dist/unpkg/prod-deprecated/active-record.js +395 -0
  115. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
  116. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
  117. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +53 -0
  118. package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
  119. package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +4 -0
  120. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
  121. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
  122. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
  123. package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
  124. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
  125. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
  126. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +100 -0
  127. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
  128. package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
  129. package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
  130. package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +53 -0
  131. package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
  132. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +82 -0
  133. package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +9 -0
  134. package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +77 -0
  135. package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +1 -0
  136. package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +3 -0
  137. package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +27 -0
  138. package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +10 -0
  139. package/dist/unpkg/prod-deprecated/declarations/index.d.ts +208 -0
  140. package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +5 -0
  141. package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +3 -0
  142. package/dist/unpkg/prod-deprecated/declarations/string.d.ts +14 -0
  143. package/dist/unpkg/prod-deprecated/derivations.js +30 -0
  144. package/dist/unpkg/prod-deprecated/handlers.js +317 -0
  145. package/dist/unpkg/prod-deprecated/index.js +361 -0
  146. package/dist/unpkg/prod-deprecated/inflect-BSG696t-.js +344 -0
  147. package/dist/unpkg/prod-deprecated/json-api.js +740 -0
  148. package/dist/unpkg/prod-deprecated/rest.js +393 -0
  149. package/dist/unpkg/prod-deprecated/string.js +1 -0
  150. package/package.json +28 -4
@@ -0,0 +1,158 @@
1
+ import type { Future, Handler, NextFn } from "@warp-drive-mirror/core/request";
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
+ */
9
+ export declare const SupportsRequestStreams: boolean;
10
+ interface Constraints {
11
+ /**
12
+ * The minimum size at which to compress blobs
13
+ *
14
+ * @default 1000
15
+ */
16
+ Blob?: number;
17
+ /**
18
+ * The minimum size at which to compress array buffers
19
+ *
20
+ * @default 1000
21
+ */
22
+ ArrayBuffer?: number;
23
+ /**
24
+ * The minimum size at which to compress typed arrays
25
+ *
26
+ * @default 1000
27
+ */
28
+ TypedArray?: number;
29
+ /**
30
+ * The minimum size at which to compress data views
31
+ *
32
+ * @default 1000
33
+ */
34
+ DataView?: number;
35
+ /**
36
+ * The minimum size at which to compress strings
37
+ *
38
+ * @default 1000
39
+ */
40
+ String?: number;
41
+ }
42
+ /**
43
+ * Options for configuring the AutoCompress handler.
44
+ *
45
+ */
46
+ interface CompressionOptions {
47
+ /**
48
+ * The compression format to use. Must be a valid
49
+ * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
50
+ *
51
+ * The default is `gzip`.
52
+ *
53
+ */
54
+ format?: CompressionFormat;
55
+ /**
56
+ * Some browsers support `ReadableStream` as a request body. This option
57
+ * enables passing the compression stream as the request body instead of
58
+ * the final compressed body when the browser supports doing so.
59
+ *
60
+ * This comes with several caveats:
61
+ *
62
+ * - the request will be put into `duplex: 'half'` mode. This should be
63
+ * transparent to you, but it is worth noting.
64
+ * - the request mode cannot be `no-cors` as requests with a `ReadableStream`
65
+ * have no content length and thus are a new form of request that triggers
66
+ * cors requirements and a preflight request.
67
+ * - http/1.x is not supported.
68
+ *
69
+ * For additional reading about the restrictions of using `ReadableStream`
70
+ * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)
71
+ *
72
+ * Streaming can be enabled per-request in browsers which support it by
73
+ * setting `request.options.allowStreaming` to `true`.
74
+ *
75
+ * Streaming can be forced even when the browser does not support it by setting
76
+ * `request.options.forceStreaming` to `true`. This is useful if later handlers
77
+ * in the chain can handle the request body as a stream.
78
+ *
79
+ * @default false
80
+ */
81
+ allowStreaming?: boolean;
82
+ /**
83
+ * If `true`, the request will be forced into streaming mode even
84
+ * if the browser does not support it. This is useful if later handlers
85
+ * in the chain can handle the request body as a stream.
86
+ *
87
+ * @default false
88
+ */
89
+ forceStreaming?: boolean;
90
+ /**
91
+ * The constraints for the request body. This is used to determine
92
+ * whether to compress the request body or not.
93
+ *
94
+ * The defaults are:
95
+ *
96
+ * ```ts
97
+ * {
98
+ * Blob: 1000, // blob.size
99
+ * ArrayBuffer: 1000, // buffer.byteLength
100
+ * TypedArray: 1000, // array.byteLength
101
+ * DataView: 1000, // view.byteLength
102
+ * String: 1000, // string.length
103
+ * }
104
+ * ```
105
+ *
106
+ * The following body types are never compressed unless explicitly
107
+ * configured by the request:
108
+ * - `FormData`
109
+ * - `URLSearchParams`
110
+ * - `ReadableStream`
111
+ *
112
+ * A request.options.compress value of `false` will disable
113
+ * compression for a request body of any type. While a value of
114
+ * `true` will enable compression for the request.
115
+ *
116
+ * An undefined value will use the default, a value of `0` will
117
+ * enable compression for all values, and a value of `-1` will
118
+ * disable compression.
119
+ *
120
+ */
121
+ constraints?: Constraints;
122
+ }
123
+ /**
124
+ * A request handler that automatically compresses the request body
125
+ * if the request body is a string, array buffer, blob, or form data.
126
+ *
127
+ * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
128
+ *
129
+ * The compression format as well as the kinds of data to compress can be
130
+ * configured using the `format` and `constraints` options.
131
+ *
132
+ * ```diff
133
+ * +import { AutoCompress } from '@ember-data-mirror/request-utils/handlers';
134
+ * import Fetch from '@ember-data-mirror/request/fetch';
135
+ * import RequestManager from '@ember-data-mirror/request';
136
+ * import Store from '@ember-data-mirror/store';
137
+ *
138
+ * class AppStore extends Store {
139
+ * requestManager = new RequestManager()
140
+ * .use([
141
+ * + new AutoCompress(),
142
+ * Fetch
143
+ * ]);
144
+ * }
145
+ * ```
146
+ *
147
+ * @group Handlers
148
+ * @public
149
+ * @since 5.5.0
150
+ */
151
+ export declare class AutoCompress implements Handler {
152
+ options: Required<CompressionOptions> & {
153
+ constraints: Required<Constraints>;
154
+ };
155
+ constructor(options?: CompressionOptions);
156
+ request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T>;
157
+ }
158
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { Future, Handler, NextFn } from "@warp-drive-mirror/core/request";
2
+ import type { RequestContext, StructuredDataDocument } from "@warp-drive-mirror/core/types/request";
3
+ /**
4
+ * If CheckFn returns true, the wrapped handler will be used.
5
+ * If CheckFn returns false, the wrapped handler will be skipped.
6
+ */
7
+ type CheckFn = (context: RequestContext) => boolean;
8
+ /**
9
+ *
10
+ * @group Handlers
11
+ * @public
12
+ */
13
+ export declare class Gate implements Handler {
14
+ handler: Handler;
15
+ checkFn: CheckFn;
16
+ constructor(handler: Handler, checkFn: CheckFn);
17
+ request<T = unknown>(context: RequestContext, next: NextFn<T>): Promise<T | StructuredDataDocument<T>> | Future<T>;
18
+ }
19
+ export {};
@@ -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;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A unique identifier for the current browser tab
3
+ * useful for observability/tracing and deduping
4
+ * across multiple tabs.
5
+ *
6
+ * @group Constants
7
+ */
8
+ export declare const TAB_ID: string;
9
+ /**
10
+ * The epoch seconds at which the tab id was generated
11
+ *
12
+ * @group Constants
13
+ */
14
+ export declare const TAB_ASSIGNED: number;
15
+ /**
16
+ * Adds the `X-Amzn-Trace-Id` header to support observability
17
+ * tooling around request routing.
18
+ *
19
+ * This makes use of the {@link TAB_ID} and {@link TAB_ASSIGNED}
20
+ * to enable tracking the browser tab of origin across multiple requests.
21
+ *
22
+ * Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
23
+ *
24
+ * @group Utility Functions
25
+ */
26
+ export declare function addTraceHeader(headers: Headers): Headers;
27
+ /**
28
+ * Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
29
+ * As of 2024-12-05 the maximum URL length is 8192 bytes.
30
+ *
31
+ * @group Constants
32
+ */
33
+ export declare const MAX_URL_LENGTH = 8192;
34
+ /**
35
+ * This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
36
+ *
37
+ * See also {@link MAX_URL_LENGTH}
38
+ *
39
+ * @group Utility Functions
40
+ */
41
+ export declare function assertInvalidUrlLength(url: string | undefined): void;
@@ -0,0 +1,109 @@
1
+ import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
2
+ import type { BuildURLConfig } from "../../index.js";
3
+ export interface JSONAPIConfig extends BuildURLConfig {
4
+ profiles?: {
5
+ pagination?: string;
6
+ [key: string]: string | undefined;
7
+ };
8
+ extensions?: {
9
+ atomic?: string;
10
+ [key: string]: string | undefined;
11
+ };
12
+ }
13
+ export declare let CONFIG: JSONAPIConfig;
14
+ export declare let ACCEPT_HEADER_VALUE: string;
15
+ /**
16
+ * Allows setting extensions and profiles to be used in the `Accept` header.
17
+ *
18
+ * Extensions and profiles are keyed by their namespace with the value being
19
+ * their URI.
20
+ *
21
+ * Example:
22
+ *
23
+ * ```ts
24
+ * setBuildURLConfig({
25
+ * extensions: {
26
+ * atomic: 'https://jsonapi.org/ext/atomic'
27
+ * },
28
+ * profiles: {
29
+ * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'
30
+ * }
31
+ * });
32
+ * ```
33
+ *
34
+ * This also sets the global configuration for `buildBaseURL`
35
+ * for host and namespace values for the global coniguration
36
+ * done via `import { setBuildURLConfig } from '@warp-drive-mirror/utilities';`
37
+ *
38
+ * These values may still be overridden by passing
39
+ * them to buildBaseURL directly.
40
+ *
41
+ * This method may be called as many times as needed
42
+ *
43
+ * ```ts
44
+ * type BuildURLConfig = {
45
+ * host: string;
46
+ * namespace: string'
47
+ * }
48
+ * ```
49
+ *
50
+ * @public
51
+ * @param {BuildURLConfig} config
52
+ * @return {void}
53
+ */
54
+ export declare function setBuildURLConfig(config: JSONAPIConfig): void;
55
+ interface RelatedObject {
56
+ [key: string]: string | string[] | RelatedObject;
57
+ }
58
+ export type JsonApiQuery = {
59
+ include?: string | string[] | RelatedObject;
60
+ fields?: Record<string, string | string[]>;
61
+ page?: {
62
+ size?: number;
63
+ after?: string;
64
+ before?: string;
65
+ };
66
+ };
67
+ /**
68
+ * Sorts query params by both key and value, returning a query params string
69
+ *
70
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
71
+ * - If `included` is an object we build paths dynamically for you
72
+ * Treats `fields` specially, building JSON:API partial fields params from an object
73
+ * Treats `page` specially, building cursor-pagination profile page params from an object
74
+ *
75
+ * ```ts
76
+ * const params = buildQueryParams({
77
+ * include: {
78
+ * company: {
79
+ * locations: 'address'
80
+ * }
81
+ * },
82
+ * fields: {
83
+ * company: ['name', 'ticker'],
84
+ * person: 'name'
85
+ * },
86
+ * page: {
87
+ * size: 10,
88
+ * after: 'abc',
89
+ * }
90
+ * });
91
+ *
92
+ * // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'
93
+ * ```
94
+ *
95
+ * Options:
96
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
97
+ *
98
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
99
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
100
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
101
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
102
+ *
103
+ * @public
104
+ * @param {URLSearchParams | Object} params
105
+ * @param {Object} [options]
106
+ * @return {String} A sorted query params string without the leading `?`
107
+ */
108
+ export declare function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string;
109
+ export {};
@@ -0,0 +1,84 @@
1
+ import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
2
+ import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
3
+ import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive-mirror/core/types/request";
4
+ /**
5
+ * Builds request options to fetch a single resource by a known id or identifier
6
+ * configured for the url and header expectations of most JSON:API APIs.
7
+ *
8
+ * :::tabs
9
+ *
10
+ * == Basic Usage
11
+ *
12
+ * ```ts
13
+ * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
14
+ * import type { Person } from '#/data/types';
15
+ *
16
+ * const result = await store.request(
17
+ * findRecord<Person>('person', '1')
18
+ * );
19
+ * ```
20
+ *
21
+ * == With Options
22
+ *
23
+ * ```ts
24
+ * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
25
+ * import type { Person } from '#/data/types';
26
+ *
27
+ * const data = await store.request(
28
+ * findRecord<Person>(
29
+ * 'person', '1',
30
+ * { include: ['pets', 'friends'] }
31
+ * )
32
+ * );
33
+ * ```
34
+ *
35
+ * == With an Identifier
36
+ *
37
+ * ```ts
38
+ * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
39
+ * import type { Person } from '#/data/types';
40
+ *
41
+ * const data = await store.request(
42
+ * findRecord<Person>(
43
+ * { type: 'person', id: '1' },
44
+ * { include: ['pets', 'friends'] }
45
+ * )
46
+ * );
47
+ * ```
48
+ *
49
+ * :::
50
+ *
51
+ * **Supplying Options to Modify the Request Behavior**
52
+ *
53
+ * The following options are supported:
54
+ *
55
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
56
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
57
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
58
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
59
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
60
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
61
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
62
+ * defaulting to `false` if none is configured.
63
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
64
+ *
65
+ * ```ts
66
+ * import { findRecord } from '@warp-drive-mirror/utilities/json-api';
67
+ *
68
+ * const data = await store.request(
69
+ * findRecord(
70
+ * 'person', '1',
71
+ * { include: ['pets', 'friends'] },
72
+ * { namespace: 'api/v2' }
73
+ * )
74
+ * );
75
+ * ```
76
+ *
77
+ * @public
78
+ */
79
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
80
+ export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
81
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
82
+ export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
83
+ /** @deprecated use {@link ReactiveDataDocument} */
84
+ export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
@@ -0,0 +1,100 @@
1
+ import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
2
+ import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
3
+ import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive-mirror/core/types/record";
4
+ import type { ConstrainedRequestOptions, PostQueryRequestOptions, QueryRequestOptions } from "@warp-drive-mirror/core/types/request";
5
+ /**
6
+ * Builds request options to query for resources, usually by a primary
7
+ * type, configured for the url and header expectations of most JSON:API APIs.
8
+ *
9
+ * The key difference between this and `postQuery` is that this method will send the query
10
+ * as query params in the url of a "GET" request instead of as the JSON body of a "POST"
11
+ * request.
12
+ *
13
+ * **Basic Usage**
14
+ *
15
+ * ```ts
16
+ * import { query } from '@warp-drive-mirror/utilities/json-api';
17
+ *
18
+ * const data = await store.request(query('person'));
19
+ * ```
20
+ *
21
+ * **With Query Params**
22
+ *
23
+ * ```ts
24
+ * import { query } from '@warp-drive-mirror/utilities/json-api';
25
+ *
26
+ * const options = query('person', { include: ['pets', 'friends'] });
27
+ * const data = await store.request(options);
28
+ * ```
29
+ *
30
+ * **Supplying Options to Modify the Request Behavior**
31
+ *
32
+ * The following options are supported:
33
+ *
34
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
35
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
36
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
37
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
38
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
39
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
40
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
41
+ * defaulting to `false` if none is configured.
42
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
43
+ *
44
+ * ```ts
45
+ * import { query } from '@warp-drive-mirror/utilities/json-api';
46
+ *
47
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
48
+ * const data = await store.request(options);
49
+ * ```
50
+ *
51
+ * @public
52
+ */
53
+ export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
54
+ export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
55
+ /**
56
+ * Builds request options to query for resources, usually by a primary
57
+ * type, configured for the url and header expectations of most JSON:API APIs.
58
+ *
59
+ * The key difference between this and `query` is that this method will send the query
60
+ * as the JSON body of a "POST" request instead of as query params in the url of a "GET"
61
+ * request.
62
+ *
63
+ * A CacheKey is generated from the url and query params, and used to cache the response
64
+ * in the store.
65
+ *
66
+ * ```ts
67
+ * import { postQuery } from '@warp-drive-mirror/utilities/json-api';
68
+ *
69
+ * const options = postQuery('person', { include: ['pets', 'friends'] });
70
+ * const data = await store.request(options);
71
+ * ```
72
+ *
73
+ * **Supplying Options to Modify the Request Behavior**
74
+ *
75
+ * The following options are supported:
76
+ *
77
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
78
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
79
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
80
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
81
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
82
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
83
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
84
+ * defaulting to `false` if none is configured.
85
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
86
+ *
87
+ * ```ts
88
+ * import { postQuery } from '@warp-drive-mirror/utilities/json-api';
89
+ *
90
+ * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });
91
+ * const data = await store.request(options);
92
+ * ```
93
+ *
94
+ * @public
95
+ * @param identifier
96
+ * @param query
97
+ * @param options
98
+ */
99
+ export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
100
+ export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;