@warp-drive/utilities 5.9.0-alpha.2 → 5.9.0-alpha.21

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/cjs-dist/string.cjs +448 -0
  2. package/cjs-dist/string.cjs.map +1 -0
  3. package/declarations/-private.d.ts +12 -1
  4. package/declarations/-private.d.ts.map +1 -0
  5. package/declarations/active-record.d.ts +260 -3
  6. package/declarations/active-record.d.ts.map +1 -0
  7. package/declarations/derivations.d.ts +26 -23
  8. package/declarations/derivations.d.ts.map +1 -0
  9. package/declarations/handlers.d.ts +282 -9
  10. package/declarations/handlers.d.ts.map +1 -0
  11. package/declarations/index-BeMAuqgZ.d.ts +462 -0
  12. package/declarations/index-BeMAuqgZ.d.ts.map +1 -0
  13. package/declarations/index.d.ts +2 -208
  14. package/declarations/json-api.d.ts +496 -5
  15. package/declarations/json-api.d.ts.map +1 -0
  16. package/declarations/rest.d.ts +258 -3
  17. package/declarations/rest.d.ts.map +1 -0
  18. package/declarations/string.d.ts +164 -13
  19. package/declarations/string.d.ts.map +1 -0
  20. package/dist/-private.js +2 -6
  21. package/dist/active-record.js +254 -379
  22. package/dist/active-record.js.map +1 -0
  23. package/dist/builder-utils-BkXwUT0x.js +16 -0
  24. package/dist/builder-utils-BkXwUT0x.js.map +1 -0
  25. package/dist/derivations.js +26 -26
  26. package/dist/derivations.js.map +1 -0
  27. package/dist/handlers.js +240 -283
  28. package/dist/handlers.js.map +1 -0
  29. package/dist/index.js +357 -335
  30. package/dist/index.js.map +1 -0
  31. package/dist/inflections-DzBsjJqj.js +80 -0
  32. package/dist/inflections-DzBsjJqj.js.map +1 -0
  33. package/dist/json-api.js +470 -706
  34. package/dist/json-api.js.map +1 -0
  35. package/dist/rest.js +254 -377
  36. package/dist/rest.js.map +1 -0
  37. package/dist/string-CWmAluxh.js +290 -0
  38. package/dist/string-CWmAluxh.js.map +1 -0
  39. package/dist/string.js +2 -427
  40. package/dist/unpkg/dev/-private.js +2 -6
  41. package/dist/unpkg/dev/active-record.js +253 -378
  42. package/dist/unpkg/dev/active-record.js.map +1 -0
  43. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
  44. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
  45. package/dist/unpkg/dev/derivations.js +26 -26
  46. package/dist/unpkg/dev/derivations.js.map +1 -0
  47. package/dist/unpkg/dev/handlers.js +238 -282
  48. package/dist/unpkg/dev/handlers.js.map +1 -0
  49. package/dist/unpkg/dev/index.js +356 -336
  50. package/dist/unpkg/dev/index.js.map +1 -0
  51. package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
  52. package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
  53. package/dist/unpkg/dev/json-api.js +469 -706
  54. package/dist/unpkg/dev/json-api.js.map +1 -0
  55. package/dist/unpkg/dev/rest.js +253 -376
  56. package/dist/unpkg/dev/rest.js.map +1 -0
  57. package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
  58. package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
  59. package/dist/unpkg/dev/string.js +3 -1
  60. package/dist/unpkg/dev-deprecated/-private.js +2 -6
  61. package/dist/unpkg/dev-deprecated/active-record.js +253 -378
  62. package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
  63. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
  64. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  65. package/dist/unpkg/dev-deprecated/derivations.js +26 -26
  66. package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
  67. package/dist/unpkg/dev-deprecated/handlers.js +238 -282
  68. package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
  69. package/dist/unpkg/dev-deprecated/index.js +356 -336
  70. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  71. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
  72. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +469 -706
  74. package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
  75. package/dist/unpkg/dev-deprecated/rest.js +253 -376
  76. package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
  77. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
  78. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
  79. package/dist/unpkg/dev-deprecated/string.js +3 -1
  80. package/dist/unpkg/prod/-private.js +2 -6
  81. package/dist/unpkg/prod/active-record.js +236 -351
  82. package/dist/unpkg/prod/active-record.js.map +1 -0
  83. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
  84. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
  85. package/dist/unpkg/prod/derivations.js +26 -26
  86. package/dist/unpkg/prod/derivations.js.map +1 -0
  87. package/dist/unpkg/prod/handlers.js +231 -272
  88. package/dist/unpkg/prod/handlers.js.map +1 -0
  89. package/dist/unpkg/prod/index.js +265 -215
  90. package/dist/unpkg/prod/index.js.map +1 -0
  91. package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
  92. package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
  93. package/dist/unpkg/prod/json-api.js +446 -669
  94. package/dist/unpkg/prod/json-api.js.map +1 -0
  95. package/dist/unpkg/prod/rest.js +236 -349
  96. package/dist/unpkg/prod/rest.js.map +1 -0
  97. package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
  98. package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
  99. package/dist/unpkg/prod/string.js +3 -1
  100. package/dist/unpkg/prod-deprecated/-private.js +2 -6
  101. package/dist/unpkg/prod-deprecated/active-record.js +236 -351
  102. package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
  103. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
  104. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  105. package/dist/unpkg/prod-deprecated/derivations.js +26 -26
  106. package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
  107. package/dist/unpkg/prod-deprecated/handlers.js +231 -272
  108. package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
  109. package/dist/unpkg/prod-deprecated/index.js +265 -215
  110. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  111. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
  112. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
  113. package/dist/unpkg/prod-deprecated/json-api.js +446 -669
  114. package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
  115. package/dist/unpkg/prod-deprecated/rest.js +236 -349
  116. package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
  117. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
  118. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
  119. package/dist/unpkg/prod-deprecated/string.js +3 -1
  120. package/package.json +11 -10
  121. package/declarations/-private/active-record/find-record.d.ts +0 -64
  122. package/declarations/-private/active-record/query.d.ts +0 -53
  123. package/declarations/-private/active-record/save-record.d.ts +0 -146
  124. package/declarations/-private/builder-utils.d.ts +0 -4
  125. package/declarations/-private/handlers/auto-compress.d.ts +0 -158
  126. package/declarations/-private/handlers/gated.d.ts +0 -19
  127. package/declarations/-private/handlers/meta-doc.d.ts +0 -47
  128. package/declarations/-private/handlers/utils.d.ts +0 -41
  129. package/declarations/-private/json-api/-utils.d.ts +0 -109
  130. package/declarations/-private/json-api/find-record.d.ts +0 -84
  131. package/declarations/-private/json-api/query.d.ts +0 -100
  132. package/declarations/-private/json-api/save-record.d.ts +0 -228
  133. package/declarations/-private/json-api/serialize.d.ts +0 -70
  134. package/declarations/-private/rest/find-record.d.ts +0 -62
  135. package/declarations/-private/rest/query.d.ts +0 -53
  136. package/declarations/-private/rest/save-record.d.ts +0 -146
  137. package/declarations/-private/string/inflect.d.ts +0 -82
  138. package/declarations/-private/string/inflections.d.ts +0 -9
  139. package/declarations/-private/string/transform.d.ts +0 -77
  140. package/dist/builder-utils-Donkk-BZ.js +0 -22
  141. package/dist/inflect-BSG696t-.js +0 -344
  142. package/dist/string.cjs +0 -430
  143. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
  144. package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
  145. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
  146. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
  147. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
  148. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
  149. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
  150. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
@@ -0,0 +1,462 @@
1
+ import { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from "@warp-drive/core/types/params";
2
+ //#region src/index.d.ts
3
+ /**
4
+ * The global configuration used by {@link buildBaseURL} when a call does
5
+ * not provide its own `host`/`namespace`. Set via {@link setBuildURLConfig}.
6
+ *
7
+ * @public
8
+ */
9
+ interface BuildURLConfig {
10
+ /**
11
+ * The scheme, domain and port (if any) to prefix built URLs with, e.g. `'https://api.example.com'`.
12
+ */
13
+ host: string | null;
14
+ /**
15
+ * The path segment to insert between `host` and the resource path, e.g. `'api/v1'`.
16
+ */
17
+ namespace: string | null;
18
+ }
19
+ /**
20
+ * Sets the global configuration for `buildBaseURL`
21
+ * for host and namespace values for the application.
22
+ *
23
+ * These values may still be overridden by passing
24
+ * them to buildBaseURL directly.
25
+ *
26
+ * This method may be called as many times as needed.
27
+ * host values of `''` or `'/'` are equivalent.
28
+ *
29
+ * Except for the value of `/` as host, host should not
30
+ * end with `/`.
31
+ *
32
+ * namespace should not start or end with a `/`.
33
+ *
34
+ * ```ts
35
+ * type BuildURLConfig = {
36
+ * host: string;
37
+ * namespace: string'
38
+ * }
39
+ * ```
40
+ *
41
+ * Example:
42
+ *
43
+ * ```ts
44
+ * import { setBuildURLConfig } from '@warp-drive/utilities';
45
+ *
46
+ * setBuildURLConfig({
47
+ * host: 'https://api.example.com',
48
+ * namespace: 'api/v1'
49
+ * });
50
+ * ```
51
+ *
52
+ * @public
53
+ */
54
+ declare function setBuildURLConfig(config: BuildURLConfig): void;
55
+ /**
56
+ * {@link buildBaseURL} options for a `findRecord` request.
57
+ *
58
+ * @public
59
+ */
60
+ interface FindRecordUrlOptions {
61
+ /**
62
+ * The request operation this URL is for.
63
+ */
64
+ op: "findRecord";
65
+ /**
66
+ * The type and id of the record to find.
67
+ */
68
+ identifier: {
69
+ /**
70
+ * The resource type.
71
+ */
72
+ type: string;
73
+ /**
74
+ * The resource id.
75
+ */
76
+ id: string;
77
+ };
78
+ /**
79
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
80
+ */
81
+ resourcePath?: string;
82
+ /**
83
+ * Overrides the globally configured host for this call only.
84
+ */
85
+ host?: string;
86
+ /**
87
+ * Overrides the globally configured namespace for this call only.
88
+ */
89
+ namespace?: string;
90
+ }
91
+ /**
92
+ * {@link buildBaseURL} options for a `query` request.
93
+ *
94
+ * @public
95
+ */
96
+ interface QueryUrlOptions {
97
+ /**
98
+ * The request operation this URL is for.
99
+ */
100
+ op: "query";
101
+ /**
102
+ * The type of the records to query.
103
+ */
104
+ identifier: {
105
+ /**
106
+ * The resource type.
107
+ */
108
+ type: string;
109
+ };
110
+ /**
111
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
112
+ */
113
+ resourcePath?: string;
114
+ /**
115
+ * Overrides the globally configured host for this call only.
116
+ */
117
+ host?: string;
118
+ /**
119
+ * Overrides the globally configured namespace for this call only.
120
+ */
121
+ namespace?: string;
122
+ }
123
+ /**
124
+ * {@link buildBaseURL} options for a `findMany` request.
125
+ *
126
+ * @public
127
+ */
128
+ interface FindManyUrlOptions {
129
+ /**
130
+ * The request operation this URL is for.
131
+ */
132
+ op: "findMany";
133
+ /**
134
+ * The type and id of each record to find.
135
+ */
136
+ identifiers: {
137
+ /**
138
+ * The resource type.
139
+ */
140
+ type: string;
141
+ /**
142
+ * The resource id.
143
+ */
144
+ id: string;
145
+ }[];
146
+ /**
147
+ * The path segment for the resource, defaults to the first identifier's `type` if not provided.
148
+ */
149
+ resourcePath?: string;
150
+ /**
151
+ * Overrides the globally configured host for this call only.
152
+ */
153
+ host?: string;
154
+ /**
155
+ * Overrides the globally configured namespace for this call only.
156
+ */
157
+ namespace?: string;
158
+ }
159
+ /**
160
+ * {@link buildBaseURL} options for a `findRelatedCollection` request.
161
+ *
162
+ * @public
163
+ */
164
+ interface FindRelatedCollectionUrlOptions {
165
+ /**
166
+ * The request operation this URL is for.
167
+ */
168
+ op: "findRelatedCollection";
169
+ /**
170
+ * The type and id of the record whose relationship is being fetched.
171
+ */
172
+ identifier: {
173
+ /**
174
+ * The resource type.
175
+ */
176
+ type: string;
177
+ /**
178
+ * The resource id.
179
+ */
180
+ id: string;
181
+ };
182
+ /**
183
+ * The relationship field name, appended to the resource path.
184
+ */
185
+ fieldPath: string;
186
+ /**
187
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
188
+ */
189
+ resourcePath?: string;
190
+ /**
191
+ * Overrides the globally configured host for this call only.
192
+ */
193
+ host?: string;
194
+ /**
195
+ * Overrides the globally configured namespace for this call only.
196
+ */
197
+ namespace?: string;
198
+ }
199
+ /**
200
+ * {@link buildBaseURL} options for a `findRelatedRecord` request.
201
+ *
202
+ * @public
203
+ */
204
+ interface FindRelatedResourceUrlOptions {
205
+ /**
206
+ * The request operation this URL is for.
207
+ */
208
+ op: "findRelatedRecord";
209
+ /**
210
+ * The type and id of the record whose relationship is being fetched.
211
+ */
212
+ identifier: {
213
+ /**
214
+ * The resource type.
215
+ */
216
+ type: string;
217
+ /**
218
+ * The resource id.
219
+ */
220
+ id: string;
221
+ };
222
+ /**
223
+ * The relationship field name, appended to the resource path.
224
+ */
225
+ fieldPath: string;
226
+ /**
227
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
228
+ */
229
+ resourcePath?: string;
230
+ /**
231
+ * Overrides the globally configured host for this call only.
232
+ */
233
+ host?: string;
234
+ /**
235
+ * Overrides the globally configured namespace for this call only.
236
+ */
237
+ namespace?: string;
238
+ }
239
+ /**
240
+ * {@link buildBaseURL} options for a `createRecord` request.
241
+ *
242
+ * @public
243
+ */
244
+ interface CreateRecordUrlOptions {
245
+ /**
246
+ * The request operation this URL is for.
247
+ */
248
+ op: "createRecord";
249
+ /**
250
+ * The type of the record being created.
251
+ */
252
+ identifier: {
253
+ /**
254
+ * The resource type.
255
+ */
256
+ type: string;
257
+ };
258
+ /**
259
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
260
+ */
261
+ resourcePath?: string;
262
+ /**
263
+ * Overrides the globally configured host for this call only.
264
+ */
265
+ host?: string;
266
+ /**
267
+ * Overrides the globally configured namespace for this call only.
268
+ */
269
+ namespace?: string;
270
+ }
271
+ /**
272
+ * {@link buildBaseURL} options for an `updateRecord` request.
273
+ *
274
+ * @public
275
+ */
276
+ interface UpdateRecordUrlOptions {
277
+ /**
278
+ * The request operation this URL is for.
279
+ */
280
+ op: "updateRecord";
281
+ /**
282
+ * The type and id of the record being updated.
283
+ */
284
+ identifier: {
285
+ /**
286
+ * The resource type.
287
+ */
288
+ type: string;
289
+ /**
290
+ * The resource id.
291
+ */
292
+ id: string;
293
+ };
294
+ /**
295
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
296
+ */
297
+ resourcePath?: string;
298
+ /**
299
+ * Overrides the globally configured host for this call only.
300
+ */
301
+ host?: string;
302
+ /**
303
+ * Overrides the globally configured namespace for this call only.
304
+ */
305
+ namespace?: string;
306
+ }
307
+ /**
308
+ * {@link buildBaseURL} options for a `deleteRecord` request.
309
+ *
310
+ * @public
311
+ */
312
+ interface DeleteRecordUrlOptions {
313
+ /**
314
+ * The request operation this URL is for.
315
+ */
316
+ op: "deleteRecord";
317
+ /**
318
+ * The type and id of the record being deleted.
319
+ */
320
+ identifier: {
321
+ /**
322
+ * The resource type.
323
+ */
324
+ type: string;
325
+ /**
326
+ * The resource id.
327
+ */
328
+ id: string;
329
+ };
330
+ /**
331
+ * The path segment for the resource, defaults to `identifier.type` if not provided.
332
+ */
333
+ resourcePath?: string;
334
+ /**
335
+ * Overrides the globally configured host for this call only.
336
+ */
337
+ host?: string;
338
+ /**
339
+ * Overrides the globally configured namespace for this call only.
340
+ */
341
+ namespace?: string;
342
+ }
343
+ /**
344
+ * {@link buildBaseURL} options for building a URL directly from a `resourcePath`
345
+ * without an associated request operation.
346
+ *
347
+ * @public
348
+ */
349
+ interface GenericUrlOptions {
350
+ /**
351
+ * The path segment for the resource.
352
+ */
353
+ resourcePath: string;
354
+ /**
355
+ * Overrides the globally configured host for this call only.
356
+ */
357
+ host?: string;
358
+ /**
359
+ * Overrides the globally configured namespace for this call only.
360
+ */
361
+ namespace?: string;
362
+ }
363
+ /**
364
+ * The union of all `op`-specific option shapes accepted by {@link buildBaseURL}, one of:
365
+ *
366
+ * - {@link FindRecordUrlOptions}
367
+ * - {@link QueryUrlOptions}
368
+ * - {@link FindManyUrlOptions}
369
+ * - {@link FindRelatedCollectionUrlOptions}
370
+ * - {@link FindRelatedResourceUrlOptions}
371
+ * - {@link CreateRecordUrlOptions}
372
+ * - {@link UpdateRecordUrlOptions}
373
+ * - {@link DeleteRecordUrlOptions}
374
+ * - {@link GenericUrlOptions}
375
+ *
376
+ * @public
377
+ */
378
+ type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions;
379
+ /**
380
+ * Builds a URL for a request based on the provided options.
381
+ * Does not include support for building query params (see `buildQueryParams`)
382
+ * so that it may be composed cleanly with other query-params strategies.
383
+ *
384
+ * Usage:
385
+ *
386
+ * ```ts
387
+ * import { buildBaseURL } from '@warp-drive/utilities';
388
+ *
389
+ * const url = buildBaseURL({
390
+ * host: 'https://api.example.com',
391
+ * namespace: 'api/v1',
392
+ * resourcePath: 'emberDevelopers',
393
+ * op: 'query',
394
+ * identifier: { type: 'ember-developer' }
395
+ * });
396
+ *
397
+ * // => 'https://api.example.com/api/v1/emberDevelopers'
398
+ * ```
399
+ *
400
+ * On the surface this may seem like a lot of work to do something simple, but
401
+ * it is designed to be composable with other utilities and interfaces that the
402
+ * average product engineer will never need to see or use.
403
+ *
404
+ * A few notes:
405
+ *
406
+ * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
407
+ * - `host` and `namespace` are optional, but if they are not provided, the values globally
408
+ * configured via `setBuildURLConfig` will be used.
409
+ * - `op` is required and must be one of the following:
410
+ * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
411
+ * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
412
+ *
413
+ * @public
414
+ */
415
+ declare function buildBaseURL(urlOptions: UrlOptions): string;
416
+ /**
417
+ * filter out keys of an object that have falsy values or point to empty arrays
418
+ * returning a new object with only those keys that have truthy values / non-empty arrays
419
+ *
420
+ * @public
421
+ * @param source object to filter keys with empty values from
422
+ * @return A new object with the keys that contained empty values removed
423
+ */
424
+ declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
425
+ /**
426
+ * Sorts query params by both key and value returning a new URLSearchParams
427
+ * object with the keys inserted in sorted order.
428
+ *
429
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
430
+ *
431
+ * Options:
432
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
433
+ *
434
+ * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
435
+ * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
436
+ * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
437
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
438
+ *
439
+ * @public
440
+ * @return A {@link URLSearchParams} with keys inserted in sorted order
441
+ */
442
+ declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
443
+ /**
444
+ * Sorts query params by both key and value, returning a query params string
445
+ *
446
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
447
+ *
448
+ * Options:
449
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
450
+ *
451
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
452
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
453
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
454
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
455
+ *
456
+ * @public
457
+ * @return A sorted query params string without the leading `?`
458
+ */
459
+ declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
460
+ //#endregion
461
+ export { FindRecordUrlOptions as a, GenericUrlOptions as c, UrlOptions as d, buildBaseURL as f, sortQueryParams as g, setBuildURLConfig as h, FindManyUrlOptions as i, QueryUrlOptions as l, filterEmpty as m, CreateRecordUrlOptions as n, FindRelatedCollectionUrlOptions as o, buildQueryParams as p, DeleteRecordUrlOptions as r, FindRelatedResourceUrlOptions as s, BuildURLConfig as t, UpdateRecordUrlOptions as u };
462
+ //# sourceMappingURL=index-BeMAuqgZ.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BeMAuqgZ.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;;;;UAmBiB;;;;EAIf;;;;EAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2Cc,kBAAkB,QAAQ;;;;;;UA6BzB;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;UAOe;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;UAQe;;;;EAIf;;;;EAIA;;;;IAIE;;;;IAIA;;;;;EAKF;;;;EAIA;;;;EAIA;;;;;;;;UASe;;;;EAIf;;;;EAIA;;;;EAIA;;;;;;;;;;;;;;;;;KAkBU,aACR,uBACA,kBACA,qBACA,kCACA,gCACA,yBACA,yBACA,yBACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqEY,aAAa,YAAY;;;;;;;;;iBA4HzB,YAAY,QAAQ,eAAe,gBAAgB,eAAe;;;;;;;;;;;;;;;;;;iBA+BlE,gBAAgB,QAAQ,mBAAmB,UAAU,kCAAkC;;;;;;;;;;;;;;;;;iBA4EvF,iBAAiB,QAAQ,mBAAmB,UAAU"}
@@ -1,208 +1,2 @@
1
- import type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from "@warp-drive/core/types/params";
2
- export interface BuildURLConfig {
3
- host: string | null;
4
- namespace: string | null;
5
- }
6
- /**
7
- * Sets the global configuration for `buildBaseURL`
8
- * for host and namespace values for the application.
9
- *
10
- * These values may still be overridden by passing
11
- * them to buildBaseURL directly.
12
- *
13
- * This method may be called as many times as needed.
14
- * host values of `''` or `'/'` are equivalent.
15
- *
16
- * Except for the value of `/` as host, host should not
17
- * end with `/`.
18
- *
19
- * namespace should not start or end with a `/`.
20
- *
21
- * ```ts
22
- * type BuildURLConfig = {
23
- * host: string;
24
- * namespace: string'
25
- * }
26
- * ```
27
- *
28
- * Example:
29
- *
30
- * ```ts
31
- * import { setBuildURLConfig } from '@warp-drive/utilities';
32
- *
33
- * setBuildURLConfig({
34
- * host: 'https://api.example.com',
35
- * namespace: 'api/v1'
36
- * });
37
- * ```
38
- *
39
- * @public
40
- */
41
- export declare function setBuildURLConfig(config: BuildURLConfig): void;
42
- export interface FindRecordUrlOptions {
43
- op: "findRecord";
44
- identifier: {
45
- type: string;
46
- id: string;
47
- };
48
- resourcePath?: string;
49
- host?: string;
50
- namespace?: string;
51
- }
52
- export interface QueryUrlOptions {
53
- op: "query";
54
- identifier: {
55
- type: string;
56
- };
57
- resourcePath?: string;
58
- host?: string;
59
- namespace?: string;
60
- }
61
- export interface FindManyUrlOptions {
62
- op: "findMany";
63
- identifiers: {
64
- type: string;
65
- id: string;
66
- }[];
67
- resourcePath?: string;
68
- host?: string;
69
- namespace?: string;
70
- }
71
- export interface FindRelatedCollectionUrlOptions {
72
- op: "findRelatedCollection";
73
- identifier: {
74
- type: string;
75
- id: string;
76
- };
77
- fieldPath: string;
78
- resourcePath?: string;
79
- host?: string;
80
- namespace?: string;
81
- }
82
- export interface FindRelatedResourceUrlOptions {
83
- op: "findRelatedRecord";
84
- identifier: {
85
- type: string;
86
- id: string;
87
- };
88
- fieldPath: string;
89
- resourcePath?: string;
90
- host?: string;
91
- namespace?: string;
92
- }
93
- export interface CreateRecordUrlOptions {
94
- op: "createRecord";
95
- identifier: {
96
- type: string;
97
- };
98
- resourcePath?: string;
99
- host?: string;
100
- namespace?: string;
101
- }
102
- export interface UpdateRecordUrlOptions {
103
- op: "updateRecord";
104
- identifier: {
105
- type: string;
106
- id: string;
107
- };
108
- resourcePath?: string;
109
- host?: string;
110
- namespace?: string;
111
- }
112
- export interface DeleteRecordUrlOptions {
113
- op: "deleteRecord";
114
- identifier: {
115
- type: string;
116
- id: string;
117
- };
118
- resourcePath?: string;
119
- host?: string;
120
- namespace?: string;
121
- }
122
- export interface GenericUrlOptions {
123
- resourcePath: string;
124
- host?: string;
125
- namespace?: string;
126
- }
127
- export type UrlOptions = FindRecordUrlOptions | QueryUrlOptions | FindManyUrlOptions | FindRelatedCollectionUrlOptions | FindRelatedResourceUrlOptions | CreateRecordUrlOptions | UpdateRecordUrlOptions | DeleteRecordUrlOptions | GenericUrlOptions;
128
- /**
129
- * Builds a URL for a request based on the provided options.
130
- * Does not include support for building query params (see `buildQueryParams`)
131
- * so that it may be composed cleanly with other query-params strategies.
132
- *
133
- * Usage:
134
- *
135
- * ```ts
136
- * import { buildBaseURL } from '@warp-drive/utilities';
137
- *
138
- * const url = buildBaseURL({
139
- * host: 'https://api.example.com',
140
- * namespace: 'api/v1',
141
- * resourcePath: 'emberDevelopers',
142
- * op: 'query',
143
- * identifier: { type: 'ember-developer' }
144
- * });
145
- *
146
- * // => 'https://api.example.com/api/v1/emberDevelopers'
147
- * ```
148
- *
149
- * On the surface this may seem like a lot of work to do something simple, but
150
- * it is designed to be composable with other utilities and interfaces that the
151
- * average product engineer will never need to see or use.
152
- *
153
- * A few notes:
154
- *
155
- * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
156
- * - `host` and `namespace` are optional, but if they are not provided, the values globally
157
- * configured via `setBuildURLConfig` will be used.
158
- * - `op` is required and must be one of the following:
159
- * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
160
- * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
161
- *
162
- * @public
163
- */
164
- export declare function buildBaseURL(urlOptions: UrlOptions): string;
165
- /**
166
- * filter out keys of an object that have falsy values or point to empty arrays
167
- * returning a new object with only those keys that have truthy values / non-empty arrays
168
- *
169
- * @public
170
- * @param source object to filter keys with empty values from
171
- * @return A new object with the keys that contained empty values removed
172
- */
173
- export declare function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable>;
174
- /**
175
- * Sorts query params by both key and value returning a new URLSearchParams
176
- * object with the keys inserted in sorted order.
177
- *
178
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
179
- *
180
- * Options:
181
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
182
- *
183
- * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
184
- * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
185
- * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
186
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
187
- *
188
- * @public
189
- * @return A {@link URLSearchParams} with keys inserted in sorted order
190
- */
191
- export declare function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams;
192
- /**
193
- * Sorts query params by both key and value, returning a query params string
194
- *
195
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
196
- *
197
- * Options:
198
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
199
- *
200
- * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
201
- * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
202
- * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
203
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
204
- *
205
- * @public
206
- * @return A sorted query params string without the leading `?`
207
- */
208
- export declare function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string;
1
+ import { a as FindRecordUrlOptions, c as GenericUrlOptions, d as UrlOptions, f as buildBaseURL, g as sortQueryParams, h as setBuildURLConfig, i as FindManyUrlOptions, l as QueryUrlOptions, m as filterEmpty, n as CreateRecordUrlOptions, o as FindRelatedCollectionUrlOptions, p as buildQueryParams, r as DeleteRecordUrlOptions, s as FindRelatedResourceUrlOptions, t as BuildURLConfig, u as UpdateRecordUrlOptions } from "./index-BeMAuqgZ.js";
2
+ export { BuildURLConfig, CreateRecordUrlOptions, DeleteRecordUrlOptions, FindManyUrlOptions, FindRecordUrlOptions, FindRelatedCollectionUrlOptions, FindRelatedResourceUrlOptions, GenericUrlOptions, QueryUrlOptions, UpdateRecordUrlOptions, UrlOptions, buildBaseURL, buildQueryParams, filterEmpty, setBuildURLConfig, sortQueryParams };