@warp-drive/utilities 5.6.0-alpha.11

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 (87) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/-private/active-record/find-record.d.ts +66 -0
  6. package/declarations/-private/active-record/find-record.d.ts.map +1 -0
  7. package/declarations/-private/active-record/query.d.ts +54 -0
  8. package/declarations/-private/active-record/query.d.ts.map +1 -0
  9. package/declarations/-private/active-record/save-record.d.ts +144 -0
  10. package/declarations/-private/active-record/save-record.d.ts.map +1 -0
  11. package/declarations/-private/builder-utils.d.ts +5 -0
  12. package/declarations/-private/builder-utils.d.ts.map +1 -0
  13. package/declarations/-private/handlers/auto-compress.d.ts +153 -0
  14. package/declarations/-private/handlers/auto-compress.d.ts.map +1 -0
  15. package/declarations/-private/json-api/-utils.d.ts +110 -0
  16. package/declarations/-private/json-api/-utils.d.ts.map +1 -0
  17. package/declarations/-private/json-api/find-record.d.ts +66 -0
  18. package/declarations/-private/json-api/find-record.d.ts.map +1 -0
  19. package/declarations/-private/json-api/find-record.type-test.d.ts +2 -0
  20. package/declarations/-private/json-api/find-record.type-test.d.ts.map +1 -0
  21. package/declarations/-private/json-api/query.d.ts +104 -0
  22. package/declarations/-private/json-api/query.d.ts.map +1 -0
  23. package/declarations/-private/json-api/query.type-test.d.ts +2 -0
  24. package/declarations/-private/json-api/query.type-test.d.ts.map +1 -0
  25. package/declarations/-private/json-api/save-record.d.ts +191 -0
  26. package/declarations/-private/json-api/save-record.d.ts.map +1 -0
  27. package/declarations/-private/json-api/serialize.d.ts +57 -0
  28. package/declarations/-private/json-api/serialize.d.ts.map +1 -0
  29. package/declarations/-private/rest/find-record.d.ts +66 -0
  30. package/declarations/-private/rest/find-record.d.ts.map +1 -0
  31. package/declarations/-private/rest/query.d.ts +54 -0
  32. package/declarations/-private/rest/query.d.ts.map +1 -0
  33. package/declarations/-private/rest/save-record.d.ts +144 -0
  34. package/declarations/-private/rest/save-record.d.ts.map +1 -0
  35. package/declarations/-private/string/inflect.d.ts +105 -0
  36. package/declarations/-private/string/inflect.d.ts.map +1 -0
  37. package/declarations/-private/string/inflections.d.ts +10 -0
  38. package/declarations/-private/string/inflections.d.ts.map +1 -0
  39. package/declarations/-private/string/transform.d.ts +89 -0
  40. package/declarations/-private/string/transform.d.ts.map +1 -0
  41. package/declarations/-private.d.ts +2 -0
  42. package/declarations/-private.d.ts.map +1 -0
  43. package/declarations/active-record.d.ts +71 -0
  44. package/declarations/active-record.d.ts.map +1 -0
  45. package/declarations/handlers.d.ts +8 -0
  46. package/declarations/handlers.d.ts.map +1 -0
  47. package/declarations/index.d.ts +255 -0
  48. package/declarations/index.d.ts.map +1 -0
  49. package/declarations/json-api.d.ts +51 -0
  50. package/declarations/json-api.d.ts.map +1 -0
  51. package/declarations/rest.d.ts +51 -0
  52. package/declarations/rest.d.ts.map +1 -0
  53. package/declarations/string.d.ts +14 -0
  54. package/declarations/string.d.ts.map +1 -0
  55. package/dist/-private.js +7 -0
  56. package/dist/-private.js.map +1 -0
  57. package/dist/active-record.js +393 -0
  58. package/dist/active-record.js.map +1 -0
  59. package/dist/builder-utils-Donkk-BZ.js +22 -0
  60. package/dist/builder-utils-Donkk-BZ.js.map +1 -0
  61. package/dist/handlers.js +141 -0
  62. package/dist/handlers.js.map +1 -0
  63. package/dist/index.js +403 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/inflect-C1laviCe.js +376 -0
  66. package/dist/inflect-C1laviCe.js.map +1 -0
  67. package/dist/json-api.js +671 -0
  68. package/dist/json-api.js.map +1 -0
  69. package/dist/rest.js +393 -0
  70. package/dist/rest.js.map +1 -0
  71. package/dist/string.js +1 -0
  72. package/dist/string.js.map +1 -0
  73. package/logos/NCC-1701-a-blue.svg +4 -0
  74. package/logos/NCC-1701-a-gold.svg +4 -0
  75. package/logos/NCC-1701-a-gold_100.svg +1 -0
  76. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  77. package/logos/NCC-1701-a.svg +4 -0
  78. package/logos/README.md +4 -0
  79. package/logos/docs-badge.svg +2 -0
  80. package/logos/ember-data-logo-dark.svg +12 -0
  81. package/logos/ember-data-logo-light.svg +12 -0
  82. package/logos/github-header.svg +444 -0
  83. package/logos/social1.png +0 -0
  84. package/logos/social2.png +0 -0
  85. package/logos/warp-drive-logo-dark.svg +4 -0
  86. package/logos/warp-drive-logo-gold.svg +4 -0
  87. package/package.json +68 -0
package/dist/index.js ADDED
@@ -0,0 +1,403 @@
1
+ import { getOrSetGlobal } from '@warp-drive/core/types/-private';
2
+ import { macroCondition, getGlobalConfig } from '@embroider/macros';
3
+
4
+ /**
5
+ * Simple utility function to assist in url building,
6
+ * query params, and other common request operations.
7
+ *
8
+ * These primitives may be used directly or composed
9
+ * by request builders to provide a consistent interface
10
+ * for building requests.
11
+ *
12
+ * For instance:
13
+ *
14
+ * ```ts
15
+ * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';
16
+ *
17
+ * const baseURL = buildBaseURL({
18
+ * host: 'https://api.example.com',
19
+ * namespace: 'api/v1',
20
+ * resourcePath: 'emberDevelopers',
21
+ * op: 'query',
22
+ * identifier: { type: 'ember-developer' }
23
+ * });
24
+ * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;
25
+ * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'
26
+ * ```
27
+ *
28
+ * This is useful, but not as useful as the REST request builder for query which is sugar
29
+ * over this (and more!):
30
+ *
31
+ * ```ts
32
+ * import { query } from '@ember-data/rest/request';
33
+ *
34
+ * const options = query('ember-developer', { name: 'Chris', include:['pets'] });
35
+ * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }
36
+ * // Note: options will also include other request options like headers, method, etc.
37
+ * ```
38
+ *
39
+ * @module
40
+ * @public
41
+ */
42
+ // prevents the final constructed object from needing to add
43
+ // host and namespace which are provided by the final consuming
44
+ // class to the prototype which can result in overwrite errors
45
+ const CONFIG = getOrSetGlobal('CONFIG', {
46
+ host: '',
47
+ namespace: ''
48
+ });
49
+
50
+ /**
51
+ * Sets the global configuration for `buildBaseURL`
52
+ * for host and namespace values for the application.
53
+ *
54
+ * These values may still be overridden by passing
55
+ * them to buildBaseURL directly.
56
+ *
57
+ * This method may be called as many times as needed.
58
+ * host values of `''` or `'/'` are equivalent.
59
+ *
60
+ * Except for the value of `/` as host, host should not
61
+ * end with `/`.
62
+ *
63
+ * namespace should not start or end with a `/`.
64
+ *
65
+ * ```ts
66
+ * type BuildURLConfig = {
67
+ * host: string;
68
+ * namespace: string'
69
+ * }
70
+ * ```
71
+ *
72
+ * Example:
73
+ *
74
+ * ```ts
75
+ * import { setBuildURLConfig } from '@ember-data/request-utils';
76
+ *
77
+ * setBuildURLConfig({
78
+ * host: 'https://api.example.com',
79
+ * namespace: 'api/v1'
80
+ * });
81
+ * ```
82
+ *
83
+ * @public
84
+ * @param {BuildURLConfig} config
85
+ * @return {void}
86
+ */
87
+ function setBuildURLConfig(config) {
88
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
89
+ if (!test) {
90
+ throw new Error(`setBuildURLConfig: You must pass a config object`);
91
+ }
92
+ })(config) : {};
93
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
94
+ if (!test) {
95
+ throw new Error(`setBuildURLConfig: You must pass a config object with a 'host' or 'namespace' property`);
96
+ }
97
+ })('host' in config || 'namespace' in config) : {};
98
+ CONFIG.host = config.host || '';
99
+ CONFIG.namespace = config.namespace || '';
100
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
101
+ if (!test) {
102
+ throw new Error(`buildBaseURL: host must NOT end with '/', received '${CONFIG.host}'`);
103
+ }
104
+ })(CONFIG.host === '/' || !CONFIG.host.endsWith('/')) : {};
105
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
106
+ if (!test) {
107
+ throw new Error(`buildBaseURL: namespace must NOT start with '/', received '${CONFIG.namespace}'`);
108
+ }
109
+ })(!CONFIG.namespace.startsWith('/')) : {};
110
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
111
+ if (!test) {
112
+ throw new Error(`buildBaseURL: namespace must NOT end with '/', received '${CONFIG.namespace}'`);
113
+ }
114
+ })(!CONFIG.namespace.endsWith('/')) : {};
115
+ }
116
+ const OPERATIONS_WITH_PRIMARY_RECORDS = new Set(['findRecord', 'findRelatedRecord', 'findRelatedCollection', 'updateRecord', 'deleteRecord']);
117
+ function isOperationWithPrimaryRecord(options) {
118
+ return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);
119
+ }
120
+ function hasResourcePath(options) {
121
+ return 'resourcePath' in options && typeof options.resourcePath === 'string' && options.resourcePath.length > 0;
122
+ }
123
+ function resourcePathForType(options) {
124
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
125
+ if (!test) {
126
+ throw new Error(`resourcePathForType: You must pass a valid op as part of options`);
127
+ }
128
+ })('op' in options && typeof options.op === 'string') : {};
129
+ return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;
130
+ }
131
+
132
+ /**
133
+ * Builds a URL for a request based on the provided options.
134
+ * Does not include support for building query params (see `buildQueryParams`)
135
+ * so that it may be composed cleanly with other query-params strategies.
136
+ *
137
+ * Usage:
138
+ *
139
+ * ```ts
140
+ * import { buildBaseURL } from '@ember-data/request-utils';
141
+ *
142
+ * const url = buildBaseURL({
143
+ * host: 'https://api.example.com',
144
+ * namespace: 'api/v1',
145
+ * resourcePath: 'emberDevelopers',
146
+ * op: 'query',
147
+ * identifier: { type: 'ember-developer' }
148
+ * });
149
+ *
150
+ * // => 'https://api.example.com/api/v1/emberDevelopers'
151
+ * ```
152
+ *
153
+ * On the surface this may seem like a lot of work to do something simple, but
154
+ * it is designed to be composable with other utilities and interfaces that the
155
+ * average product engineer will never need to see or use.
156
+ *
157
+ * A few notes:
158
+ *
159
+ * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
160
+ * - `host` and `namespace` are optional, but if they are not provided, the values globally
161
+ * configured via `setBuildURLConfig` will be used.
162
+ * - `op` is required and must be one of the following:
163
+ * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
164
+ * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
165
+ *
166
+ * @public
167
+ * @param urlOptions
168
+ * @return {String}
169
+ */
170
+ function buildBaseURL(urlOptions) {
171
+ const options = Object.assign({
172
+ host: CONFIG.host,
173
+ namespace: CONFIG.namespace
174
+ }, urlOptions);
175
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
176
+ if (!test) {
177
+ throw new Error(`buildBaseURL: You must pass \`op\` as part of options`);
178
+ }
179
+ })(hasResourcePath(options) || typeof options.op === 'string' && options.op.length > 0) : {};
180
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
181
+ if (!test) {
182
+ throw new Error(`buildBaseURL: You must pass \`identifier\` as part of options`);
183
+ }
184
+ })(hasResourcePath(options) || options.op === 'findMany' || options.identifier && typeof options.identifier === 'object') : {};
185
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
186
+ if (!test) {
187
+ throw new Error(`buildBaseURL: You must pass \`identifiers\` as part of options`);
188
+ }
189
+ })(hasResourcePath(options) || options.op !== 'findMany' || options.identifiers && Array.isArray(options.identifiers) && options.identifiers.length > 0 && options.identifiers.every(i => i && typeof i === 'object')) : {};
190
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
191
+ if (!test) {
192
+ throw new Error(`buildBaseURL: You must pass valid \`identifier\` as part of options, expected 'id'`);
193
+ }
194
+ })(hasResourcePath(options) || !isOperationWithPrimaryRecord(options) || typeof options.identifier.id === 'string' && options.identifier.id.length > 0) : {};
195
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
196
+ if (!test) {
197
+ throw new Error(`buildBaseURL: You must pass \`identifiers\` as part of options`);
198
+ }
199
+ })(hasResourcePath(options) || options.op !== 'findMany' || options.identifiers.every(i => typeof i.id === 'string' && i.id.length > 0)) : {};
200
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
201
+ if (!test) {
202
+ throw new Error(`buildBaseURL: You must pass valid \`identifier\` as part of options, expected 'type'`);
203
+ }
204
+ })(hasResourcePath(options) || options.op === 'findMany' || typeof options.identifier.type === 'string' && options.identifier.type.length > 0) : {};
205
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
206
+ if (!test) {
207
+ throw new Error(`buildBaseURL: You must pass valid \`identifiers\` as part of options, expected 'type'`);
208
+ }
209
+ })(hasResourcePath(options) || options.op !== 'findMany' || typeof options.identifiers[0].type === 'string' && options.identifiers[0].type.length > 0) : {};
210
+
211
+ // prettier-ignore
212
+ const idPath = isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id) : '';
213
+ const resourcePath = options.resourcePath || resourcePathForType(options);
214
+ const {
215
+ host,
216
+ namespace
217
+ } = options;
218
+ const fieldPath = 'fieldPath' in options ? options.fieldPath : '';
219
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
220
+ if (!test) {
221
+ throw new Error(`buildBaseURL: You tried to build a url for a ${String('op' in options ? options.op + ' ' : '')}request to ${resourcePath} but resourcePath must be set or op must be one of "${['findRecord', 'findRelatedRecord', 'findRelatedCollection', 'updateRecord', 'deleteRecord', 'createRecord', 'query', 'findMany'].join('","')}".`);
222
+ }
223
+ })(hasResourcePath(options) || ['findRecord', 'query', 'findMany', 'findRelatedCollection', 'findRelatedRecord', 'createRecord', 'updateRecord', 'deleteRecord'].includes(options.op)) : {};
224
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
225
+ if (!test) {
226
+ throw new Error(`buildBaseURL: host must NOT end with '/', received '${host}'`);
227
+ }
228
+ })(host === '/' || !host.endsWith('/')) : {};
229
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
230
+ if (!test) {
231
+ throw new Error(`buildBaseURL: namespace must NOT start with '/', received '${namespace}'`);
232
+ }
233
+ })(!namespace.startsWith('/')) : {};
234
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
235
+ if (!test) {
236
+ throw new Error(`buildBaseURL: namespace must NOT end with '/', received '${namespace}'`);
237
+ }
238
+ })(!namespace.endsWith('/')) : {};
239
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
240
+ if (!test) {
241
+ throw new Error(`buildBaseURL: resourcePath must NOT start with '/', received '${resourcePath}'`);
242
+ }
243
+ })(!resourcePath.startsWith('/')) : {};
244
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
245
+ if (!test) {
246
+ throw new Error(`buildBaseURL: resourcePath must NOT end with '/', received '${resourcePath}'`);
247
+ }
248
+ })(!resourcePath.endsWith('/')) : {};
249
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
250
+ if (!test) {
251
+ throw new Error(`buildBaseURL: fieldPath must NOT start with '/', received '${fieldPath}'`);
252
+ }
253
+ })(!fieldPath.startsWith('/')) : {};
254
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
255
+ if (!test) {
256
+ throw new Error(`buildBaseURL: fieldPath must NOT end with '/', received '${fieldPath}'`);
257
+ }
258
+ })(!fieldPath.endsWith('/')) : {};
259
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
260
+ if (!test) {
261
+ throw new Error(`buildBaseURL: idPath must NOT start with '/', received '${idPath}'`);
262
+ }
263
+ })(!idPath.startsWith('/')) : {};
264
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
265
+ if (!test) {
266
+ throw new Error(`buildBaseURL: idPath must NOT end with '/', received '${idPath}'`);
267
+ }
268
+ })(!idPath.endsWith('/')) : {};
269
+ const hasHost = host !== '' && host !== '/';
270
+ const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');
271
+ return hasHost ? url : `/${url}`;
272
+ }
273
+ const DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS = {
274
+ arrayFormat: 'comma'
275
+ };
276
+ function handleInclude(include) {
277
+ macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
278
+ if (!test) {
279
+ throw new Error(`Expected include to be a string or array, got ${typeof include}`);
280
+ }
281
+ })(typeof include === 'string' || Array.isArray(include)) : {};
282
+ return typeof include === 'string' ? include.split(',') : include;
283
+ }
284
+
285
+ /**
286
+ * filter out keys of an object that have falsy values or point to empty arrays
287
+ * returning a new object with only those keys that have truthy values / non-empty arrays
288
+ *
289
+ * @public
290
+ * @param {Record<string, Serializable>} source object to filter keys with empty values from
291
+ * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed
292
+ */
293
+ function filterEmpty(source) {
294
+ const result = {};
295
+ for (const key in source) {
296
+ const value = source[key];
297
+ // Allow `0` and `false` but filter falsy values that indicate "empty"
298
+ if (value !== undefined && value !== null && value !== '') {
299
+ if (!Array.isArray(value) || value.length > 0) {
300
+ result[key] = source[key];
301
+ }
302
+ }
303
+ }
304
+ return result;
305
+ }
306
+
307
+ /**
308
+ * Sorts query params by both key and value returning a new URLSearchParams
309
+ * object with the keys inserted in sorted order.
310
+ *
311
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
312
+ *
313
+ * Options:
314
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
315
+ *
316
+ * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
317
+ * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
318
+ * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
319
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
320
+ *
321
+ * @public
322
+ * @param {URLSearchParams | object} params
323
+ * @param {Object} options
324
+ * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order
325
+ */
326
+ function sortQueryParams(params, options) {
327
+ const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);
328
+ const paramsIsObject = !(params instanceof URLSearchParams);
329
+ const urlParams = new URLSearchParams();
330
+ const dictionaryParams = paramsIsObject ? params : {};
331
+ if (!paramsIsObject) {
332
+ params.forEach((value, key) => {
333
+ const hasExisting = key in dictionaryParams;
334
+ if (!hasExisting) {
335
+ dictionaryParams[key] = value;
336
+ } else {
337
+ const existingValue = dictionaryParams[key];
338
+ if (Array.isArray(existingValue)) {
339
+ existingValue.push(value);
340
+ } else {
341
+ dictionaryParams[key] = [existingValue, value];
342
+ }
343
+ }
344
+ });
345
+ }
346
+ if ('include' in dictionaryParams) {
347
+ dictionaryParams.include = handleInclude(dictionaryParams.include);
348
+ }
349
+ const sortedKeys = Object.keys(dictionaryParams).sort();
350
+ sortedKeys.forEach(key => {
351
+ const value = dictionaryParams[key];
352
+ if (Array.isArray(value)) {
353
+ value.sort();
354
+ switch (opts.arrayFormat) {
355
+ case 'indices':
356
+ value.forEach((v, i) => {
357
+ urlParams.append(`${key}[${i}]`, String(v));
358
+ });
359
+ return;
360
+ case 'bracket':
361
+ value.forEach(v => {
362
+ urlParams.append(`${key}[]`, String(v));
363
+ });
364
+ return;
365
+ case 'repeat':
366
+ value.forEach(v => {
367
+ urlParams.append(key, String(v));
368
+ });
369
+ return;
370
+ case 'comma':
371
+ default:
372
+ urlParams.append(key, value.join(','));
373
+ return;
374
+ }
375
+ } else {
376
+ urlParams.append(key, String(value));
377
+ }
378
+ });
379
+ return urlParams;
380
+ }
381
+
382
+ /**
383
+ * Sorts query params by both key and value, returning a query params string
384
+ *
385
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
386
+ *
387
+ * Options:
388
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
389
+ *
390
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
391
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
392
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
393
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
394
+ *
395
+ * @public
396
+ * @param {URLSearchParams | Object} params
397
+ * @param {Object} [options]
398
+ * @return {String} A sorted query params string without the leading `?`
399
+ */
400
+ function buildQueryParams(params, options) {
401
+ return sortQueryParams(params, options).toString();
402
+ }
403
+ export { buildBaseURL, buildQueryParams, filterEmpty, setBuildURLConfig, sortQueryParams };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { assert } from '@warp-drive/core/build-config/macros';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';\n\n/**\n * Simple utility function to assist in url building,\n * query params, and other common request operations.\n *\n * These primitives may be used directly or composed\n * by request builders to provide a consistent interface\n * for building requests.\n *\n * For instance:\n *\n * ```ts\n * import { buildBaseURL, buildQueryParams } from '@ember-data/request-utils';\n *\n * const baseURL = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n * const url = `${baseURL}?${buildQueryParams({ name: 'Chris', include:['pets'] })}`;\n * // => 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris'\n * ```\n *\n * This is useful, but not as useful as the REST request builder for query which is sugar\n * over this (and more!):\n *\n * ```ts\n * import { query } from '@ember-data/rest/request';\n *\n * const options = query('ember-developer', { name: 'Chris', include:['pets'] });\n * // => { url: 'https://api.example.com/api/v1/emberDevelopers?include=pets&name=Chris' }\n * // Note: options will also include other request options like headers, method, etc.\n * ```\n *\n * @module\n * @public\n */\n\n// prevents the final constructed object from needing to add\n// host and namespace which are provided by the final consuming\n// class to the prototype which can result in overwrite errors\n\nexport interface BuildURLConfig {\n host: string | null;\n namespace: string | null;\n}\n\nconst CONFIG: BuildURLConfig = getOrSetGlobal('CONFIG', {\n host: '',\n namespace: '',\n});\n\n/**\n * Sets the global configuration for `buildBaseURL`\n * for host and namespace values for the application.\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed.\n * host values of `''` or `'/'` are equivalent.\n *\n * Except for the value of `/` as host, host should not\n * end with `/`.\n *\n * namespace should not start or end with a `/`.\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * Example:\n *\n * ```ts\n * import { setBuildURLConfig } from '@ember-data/request-utils';\n *\n * setBuildURLConfig({\n * host: 'https://api.example.com',\n * namespace: 'api/v1'\n * });\n * ```\n *\n * @public\n * @param {BuildURLConfig} config\n * @return {void}\n */\nexport function setBuildURLConfig(config: BuildURLConfig) {\n assert(`setBuildURLConfig: You must pass a config object`, config);\n assert(\n `setBuildURLConfig: You must pass a config object with a 'host' or 'namespace' property`,\n 'host' in config || 'namespace' in config\n );\n\n CONFIG.host = config.host || '';\n CONFIG.namespace = config.namespace || '';\n\n assert(\n `buildBaseURL: host must NOT end with '/', received '${CONFIG.host}'`,\n CONFIG.host === '/' || !CONFIG.host.endsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT start with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.startsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT end with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.endsWith('/')\n );\n}\n\nexport interface FindRecordUrlOptions {\n op: 'findRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface QueryUrlOptions {\n op: 'query';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindManyUrlOptions {\n op: 'findMany';\n identifiers: { type: string; id: string }[];\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\nexport interface FindRelatedCollectionUrlOptions {\n op: 'findRelatedCollection';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface FindRelatedResourceUrlOptions {\n op: 'findRelatedRecord';\n identifier: { type: string; id: string };\n fieldPath: string;\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface CreateRecordUrlOptions {\n op: 'createRecord';\n identifier: { type: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface UpdateRecordUrlOptions {\n op: 'updateRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface DeleteRecordUrlOptions {\n op: 'deleteRecord';\n identifier: { type: string; id: string };\n resourcePath?: string;\n host?: string;\n namespace?: string;\n}\n\nexport interface GenericUrlOptions {\n resourcePath: string;\n host?: string;\n namespace?: string;\n}\n\nexport type UrlOptions =\n | FindRecordUrlOptions\n | QueryUrlOptions\n | FindManyUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | CreateRecordUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions\n | GenericUrlOptions;\n\nconst OPERATIONS_WITH_PRIMARY_RECORDS = new Set([\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n]);\n\nfunction isOperationWithPrimaryRecord(\n options: UrlOptions\n): options is\n | FindRecordUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions {\n return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);\n}\n\nfunction hasResourcePath(options: UrlOptions): options is GenericUrlOptions {\n return 'resourcePath' in options && typeof options.resourcePath === 'string' && options.resourcePath.length > 0;\n}\n\nfunction resourcePathForType(options: UrlOptions): string {\n assert(\n `resourcePathForType: You must pass a valid op as part of options`,\n 'op' in options && typeof options.op === 'string'\n );\n return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;\n}\n\n/**\n * Builds a URL for a request based on the provided options.\n * Does not include support for building query params (see `buildQueryParams`)\n * so that it may be composed cleanly with other query-params strategies.\n *\n * Usage:\n *\n * ```ts\n * import { buildBaseURL } from '@ember-data/request-utils';\n *\n * const url = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n *\n * // => 'https://api.example.com/api/v1/emberDevelopers'\n * ```\n *\n * On the surface this may seem like a lot of work to do something simple, but\n * it is designed to be composable with other utilities and interfaces that the\n * average product engineer will never need to see or use.\n *\n * A few notes:\n *\n * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.\n * - `host` and `namespace` are optional, but if they are not provided, the values globally\n * configured via `setBuildURLConfig` will be used.\n * - `op` is required and must be one of the following:\n * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'\n * - Depending on the value of `op`, `identifier` or `identifiers` will be required.\n *\n * @public\n * @param urlOptions\n * @return {String}\n */\nexport function buildBaseURL(urlOptions: UrlOptions): string {\n const options = Object.assign(\n {\n host: CONFIG.host,\n namespace: CONFIG.namespace,\n },\n urlOptions\n );\n assert(\n `buildBaseURL: You must pass \\`op\\` as part of options`,\n hasResourcePath(options) || (typeof options.op === 'string' && options.op.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifier\\` as part of options`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (options.identifier && typeof options.identifier === 'object')\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (options.identifiers &&\n Array.isArray(options.identifiers) &&\n options.identifiers.length > 0 &&\n options.identifiers.every((i) => i && typeof i === 'object'))\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'id'`,\n hasResourcePath(options) ||\n !isOperationWithPrimaryRecord(options) ||\n (typeof options.identifier.id === 'string' && options.identifier.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n options.identifiers.every((i) => typeof i.id === 'string' && i.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (typeof options.identifier.type === 'string' && options.identifier.type.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifiers\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (typeof options.identifiers[0].type === 'string' && options.identifiers[0].type.length > 0)\n );\n\n // prettier-ignore\n const idPath: string =\n isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id)\n : '';\n const resourcePath = options.resourcePath || resourcePathForType(options);\n const { host, namespace } = options;\n const fieldPath = 'fieldPath' in options ? options.fieldPath : '';\n\n assert(\n `buildBaseURL: You tried to build a url for a ${String(\n 'op' in options ? options.op + ' ' : ''\n )}request to ${resourcePath} but resourcePath must be set or op must be one of \"${[\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n 'createRecord',\n 'query',\n 'findMany',\n ].join('\",\"')}\".`,\n hasResourcePath(options) ||\n [\n 'findRecord',\n 'query',\n 'findMany',\n 'findRelatedCollection',\n 'findRelatedRecord',\n 'createRecord',\n 'updateRecord',\n 'deleteRecord',\n ].includes(options.op)\n );\n\n assert(`buildBaseURL: host must NOT end with '/', received '${host}'`, host === '/' || !host.endsWith('/'));\n assert(`buildBaseURL: namespace must NOT start with '/', received '${namespace}'`, !namespace.startsWith('/'));\n assert(`buildBaseURL: namespace must NOT end with '/', received '${namespace}'`, !namespace.endsWith('/'));\n assert(\n `buildBaseURL: resourcePath must NOT start with '/', received '${resourcePath}'`,\n !resourcePath.startsWith('/')\n );\n assert(`buildBaseURL: resourcePath must NOT end with '/', received '${resourcePath}'`, !resourcePath.endsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT start with '/', received '${fieldPath}'`, !fieldPath.startsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT end with '/', received '${fieldPath}'`, !fieldPath.endsWith('/'));\n assert(`buildBaseURL: idPath must NOT start with '/', received '${idPath}'`, !idPath.startsWith('/'));\n assert(`buildBaseURL: idPath must NOT end with '/', received '${idPath}'`, !idPath.endsWith('/'));\n\n const hasHost = host !== '' && host !== '/';\n const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');\n return hasHost ? url : `/${url}`;\n}\n\nconst DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS: QueryParamsSerializationOptions = {\n arrayFormat: 'comma',\n};\n\nfunction handleInclude(include: string | string[]): string[] {\n assert(\n `Expected include to be a string or array, got ${typeof include}`,\n typeof include === 'string' || Array.isArray(include)\n );\n return typeof include === 'string' ? include.split(',') : include;\n}\n\n/**\n * filter out keys of an object that have falsy values or point to empty arrays\n * returning a new object with only those keys that have truthy values / non-empty arrays\n *\n * @public\n * @param {Record<string, Serializable>} source object to filter keys with empty values from\n * @return {Record<string, Serializable>} A new object with the keys that contained empty values removed\n */\nexport function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable> {\n const result: Record<string, Serializable> = {};\n for (const key in source) {\n const value = source[key];\n // Allow `0` and `false` but filter falsy values that indicate \"empty\"\n if (value !== undefined && value !== null && value !== '') {\n if (!Array.isArray(value) || value.length > 0) {\n result[key] = source[key];\n }\n }\n }\n return result;\n}\n\n/**\n * Sorts query params by both key and value returning a new URLSearchParams\n * object with the keys inserted in sorted order.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`\n *\n * @public\n * @param {URLSearchParams | object} params\n * @param {Object} options\n * @return {URLSearchParams} A URLSearchParams with keys inserted in sorted order\n */\nexport function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams {\n const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);\n const paramsIsObject = !(params instanceof URLSearchParams);\n const urlParams = new URLSearchParams();\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? params : {};\n\n if (!paramsIsObject) {\n params.forEach((value, key) => {\n const hasExisting = key in dictionaryParams;\n if (!hasExisting) {\n dictionaryParams[key] = value;\n } else {\n const existingValue = dictionaryParams[key];\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n dictionaryParams[key] = [existingValue, value];\n }\n }\n });\n }\n\n if ('include' in dictionaryParams) {\n dictionaryParams.include = handleInclude(dictionaryParams.include as string | string[]);\n }\n\n const sortedKeys = Object.keys(dictionaryParams).sort();\n sortedKeys.forEach((key) => {\n const value = dictionaryParams[key];\n if (Array.isArray(value)) {\n value.sort();\n switch (opts.arrayFormat) {\n case 'indices':\n value.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n value.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n value.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, value.join(','));\n return;\n }\n } else {\n urlParams.append(key, String(value));\n }\n });\n\n return urlParams;\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @param {URLSearchParams | Object} params\n * @param {Object} [options]\n * @return {String} A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string {\n return sortQueryParams(params, options).toString();\n}\n"],"names":["CONFIG","getOrSetGlobal","host","namespace","setBuildURLConfig","config","macroCondition","getGlobalConfig","WarpDrive","env","DEBUG","test","Error","endsWith","startsWith","OPERATIONS_WITH_PRIMARY_RECORDS","Set","isOperationWithPrimaryRecord","options","has","op","hasResourcePath","resourcePath","length","resourcePathForType","identifiers","type","identifier","buildBaseURL","urlOptions","Object","assign","Array","isArray","every","i","id","idPath","encodeURIComponent","fieldPath","String","join","includes","hasHost","url","filter","Boolean","DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS","arrayFormat","handleInclude","include","split","filterEmpty","source","result","key","value","undefined","sortQueryParams","params","opts","paramsIsObject","URLSearchParams","urlParams","dictionaryParams","forEach","hasExisting","existingValue","push","sortedKeys","keys","sort","v","append","buildQueryParams","toString"],"mappings":";;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAOA,MAAMA,MAAsB,GAAGC,cAAc,CAAC,QAAQ,EAAE;AACtDC,EAAAA,IAAI,EAAE,EAAE;AACRC,EAAAA,SAAS,EAAE;AACb,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;A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