@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
@@ -1,239 +1,289 @@
1
- import { getOrSetGlobal } from '@warp-drive/core/types/-private';
1
+ import { getOrSetGlobal } from "@warp-drive/core/types/-private";
2
2
 
3
+ //#region src/index.ts
3
4
  /**
4
- * @module
5
- * @mergeModuleWith <project>
6
- */
7
-
8
- // prevents the final constructed object from needing to add
9
- // host and namespace which are provided by the final consuming
10
- // class to the prototype which can result in overwrite errors
11
-
12
- const CONFIG = getOrSetGlobal('CONFIG', {
13
- host: '',
14
- namespace: ''
5
+ * @module
6
+ * @mergeModuleWith <project>
7
+ */
8
+ /**
9
+ * The global configuration used by {@link buildBaseURL} when a call does
10
+ * not provide its own `host`/`namespace`. Set via {@link setBuildURLConfig}.
11
+ *
12
+ * @public
13
+ */
14
+ const CONFIG = getOrSetGlobal("CONFIG", {
15
+ host: "",
16
+ namespace: ""
15
17
  });
16
-
17
18
  /**
18
- * Sets the global configuration for `buildBaseURL`
19
- * for host and namespace values for the application.
20
- *
21
- * These values may still be overridden by passing
22
- * them to buildBaseURL directly.
23
- *
24
- * This method may be called as many times as needed.
25
- * host values of `''` or `'/'` are equivalent.
26
- *
27
- * Except for the value of `/` as host, host should not
28
- * end with `/`.
29
- *
30
- * namespace should not start or end with a `/`.
31
- *
32
- * ```ts
33
- * type BuildURLConfig = {
34
- * host: string;
35
- * namespace: string'
36
- * }
37
- * ```
38
- *
39
- * Example:
40
- *
41
- * ```ts
42
- * import { setBuildURLConfig } from '@warp-drive/utilities';
43
- *
44
- * setBuildURLConfig({
45
- * host: 'https://api.example.com',
46
- * namespace: 'api/v1'
47
- * });
48
- * ```
49
- *
50
- * @public
51
- */
19
+ * Sets the global configuration for `buildBaseURL`
20
+ * for host and namespace values for the application.
21
+ *
22
+ * These values may still be overridden by passing
23
+ * them to buildBaseURL directly.
24
+ *
25
+ * This method may be called as many times as needed.
26
+ * host values of `''` or `'/'` are equivalent.
27
+ *
28
+ * Except for the value of `/` as host, host should not
29
+ * end with `/`.
30
+ *
31
+ * namespace should not start or end with a `/`.
32
+ *
33
+ * ```ts
34
+ * type BuildURLConfig = {
35
+ * host: string;
36
+ * namespace: string'
37
+ * }
38
+ * ```
39
+ *
40
+ * Example:
41
+ *
42
+ * ```ts
43
+ * import { setBuildURLConfig } from '@warp-drive/utilities';
44
+ *
45
+ * setBuildURLConfig({
46
+ * host: 'https://api.example.com',
47
+ * namespace: 'api/v1'
48
+ * });
49
+ * ```
50
+ *
51
+ * @public
52
+ */
52
53
  function setBuildURLConfig(config) {
53
- CONFIG.host = config.host || '';
54
- CONFIG.namespace = config.namespace || '';
54
+ CONFIG.host = config.host || "";
55
+ CONFIG.namespace = config.namespace || "";
55
56
  }
56
- const OPERATIONS_WITH_PRIMARY_RECORDS = new Set(['findRecord', 'findRelatedRecord', 'findRelatedCollection', 'updateRecord', 'deleteRecord']);
57
+ /**
58
+ * {@link buildBaseURL} options for a `findRecord` request.
59
+ *
60
+ * @public
61
+ */
62
+ /**
63
+ * {@link buildBaseURL} options for a `query` request.
64
+ *
65
+ * @public
66
+ */
67
+ /**
68
+ * {@link buildBaseURL} options for a `findMany` request.
69
+ *
70
+ * @public
71
+ */
72
+ /**
73
+ * {@link buildBaseURL} options for a `findRelatedCollection` request.
74
+ *
75
+ * @public
76
+ */
77
+ /**
78
+ * {@link buildBaseURL} options for a `findRelatedRecord` request.
79
+ *
80
+ * @public
81
+ */
82
+ /**
83
+ * {@link buildBaseURL} options for a `createRecord` request.
84
+ *
85
+ * @public
86
+ */
87
+ /**
88
+ * {@link buildBaseURL} options for an `updateRecord` request.
89
+ *
90
+ * @public
91
+ */
92
+ /**
93
+ * {@link buildBaseURL} options for a `deleteRecord` request.
94
+ *
95
+ * @public
96
+ */
97
+ /**
98
+ * {@link buildBaseURL} options for building a URL directly from a `resourcePath`
99
+ * without an associated request operation.
100
+ *
101
+ * @public
102
+ */
103
+ /**
104
+ * The union of all `op`-specific option shapes accepted by {@link buildBaseURL}, one of:
105
+ *
106
+ * - {@link FindRecordUrlOptions}
107
+ * - {@link QueryUrlOptions}
108
+ * - {@link FindManyUrlOptions}
109
+ * - {@link FindRelatedCollectionUrlOptions}
110
+ * - {@link FindRelatedResourceUrlOptions}
111
+ * - {@link CreateRecordUrlOptions}
112
+ * - {@link UpdateRecordUrlOptions}
113
+ * - {@link DeleteRecordUrlOptions}
114
+ * - {@link GenericUrlOptions}
115
+ *
116
+ * @public
117
+ */
118
+ const OPERATIONS_WITH_PRIMARY_RECORDS = /* @__PURE__ */ new Set([
119
+ "findRecord",
120
+ "findRelatedRecord",
121
+ "findRelatedCollection",
122
+ "updateRecord",
123
+ "deleteRecord"
124
+ ]);
57
125
  function isOperationWithPrimaryRecord(options) {
58
- return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);
126
+ return "op" in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);
59
127
  }
60
128
  function resourcePathForType(options) {
61
- return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;
129
+ return options.op === "findMany" ? options.identifiers[0].type : options.identifier.type;
62
130
  }
63
-
64
131
  /**
65
- * Builds a URL for a request based on the provided options.
66
- * Does not include support for building query params (see `buildQueryParams`)
67
- * so that it may be composed cleanly with other query-params strategies.
68
- *
69
- * Usage:
70
- *
71
- * ```ts
72
- * import { buildBaseURL } from '@warp-drive/utilities';
73
- *
74
- * const url = buildBaseURL({
75
- * host: 'https://api.example.com',
76
- * namespace: 'api/v1',
77
- * resourcePath: 'emberDevelopers',
78
- * op: 'query',
79
- * identifier: { type: 'ember-developer' }
80
- * });
81
- *
82
- * // => 'https://api.example.com/api/v1/emberDevelopers'
83
- * ```
84
- *
85
- * On the surface this may seem like a lot of work to do something simple, but
86
- * it is designed to be composable with other utilities and interfaces that the
87
- * average product engineer will never need to see or use.
88
- *
89
- * A few notes:
90
- *
91
- * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
92
- * - `host` and `namespace` are optional, but if they are not provided, the values globally
93
- * configured via `setBuildURLConfig` will be used.
94
- * - `op` is required and must be one of the following:
95
- * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
96
- * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
97
- *
98
- * @public
99
- */
132
+ * Builds a URL for a request based on the provided options.
133
+ * Does not include support for building query params (see `buildQueryParams`)
134
+ * so that it may be composed cleanly with other query-params strategies.
135
+ *
136
+ * Usage:
137
+ *
138
+ * ```ts
139
+ * import { buildBaseURL } from '@warp-drive/utilities';
140
+ *
141
+ * const url = buildBaseURL({
142
+ * host: 'https://api.example.com',
143
+ * namespace: 'api/v1',
144
+ * resourcePath: 'emberDevelopers',
145
+ * op: 'query',
146
+ * identifier: { type: 'ember-developer' }
147
+ * });
148
+ *
149
+ * // => 'https://api.example.com/api/v1/emberDevelopers'
150
+ * ```
151
+ *
152
+ * On the surface this may seem like a lot of work to do something simple, but
153
+ * it is designed to be composable with other utilities and interfaces that the
154
+ * average product engineer will never need to see or use.
155
+ *
156
+ * A few notes:
157
+ *
158
+ * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.
159
+ * - `host` and `namespace` are optional, but if they are not provided, the values globally
160
+ * configured via `setBuildURLConfig` will be used.
161
+ * - `op` is required and must be one of the following:
162
+ * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'
163
+ * - Depending on the value of `op`, `identifier` or `identifiers` will be required.
164
+ *
165
+ * @public
166
+ */
100
167
  function buildBaseURL(urlOptions) {
101
- const options = Object.assign({
102
- host: CONFIG.host,
103
- namespace: CONFIG.namespace
104
- }, urlOptions);
105
-
106
- // prettier-ignore
107
- const idPath = isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id) : '';
108
- const resourcePath = options.resourcePath || resourcePathForType(options);
109
- const {
110
- host,
111
- namespace
112
- } = options;
113
- const fieldPath = 'fieldPath' in options ? options.fieldPath : '';
114
- const hasHost = host !== '' && host !== '/';
115
- const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');
116
- return hasHost ? url : `/${url}`;
168
+ const options = Object.assign({
169
+ host: CONFIG.host,
170
+ namespace: CONFIG.namespace
171
+ }, urlOptions);
172
+ const idPath = isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id) : "";
173
+ const resourcePath = options.resourcePath || resourcePathForType(options);
174
+ const { host, namespace } = options;
175
+ const fieldPath = "fieldPath" in options ? options.fieldPath : "";
176
+ const hasHost = host !== "" && host !== "/";
177
+ const url = [
178
+ hasHost ? host : "",
179
+ namespace,
180
+ resourcePath,
181
+ idPath,
182
+ fieldPath
183
+ ].filter(Boolean).join("/");
184
+ return hasHost ? url : `/${url}`;
117
185
  }
118
- const DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS = {
119
- arrayFormat: 'comma'
120
- };
186
+ const DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS = { arrayFormat: "comma" };
121
187
  function handleInclude(include) {
122
- return typeof include === 'string' ? include.split(',') : include;
188
+ return typeof include === "string" ? include.split(",") : include;
123
189
  }
124
-
125
190
  /**
126
- * filter out keys of an object that have falsy values or point to empty arrays
127
- * returning a new object with only those keys that have truthy values / non-empty arrays
128
- *
129
- * @public
130
- * @param source object to filter keys with empty values from
131
- * @return A new object with the keys that contained empty values removed
132
- */
191
+ * filter out keys of an object that have falsy values or point to empty arrays
192
+ * returning a new object with only those keys that have truthy values / non-empty arrays
193
+ *
194
+ * @public
195
+ * @param source object to filter keys with empty values from
196
+ * @return A new object with the keys that contained empty values removed
197
+ */
133
198
  function filterEmpty(source) {
134
- const result = {};
135
- for (const key in source) {
136
- const value = source[key];
137
- // Allow `0` and `false` but filter falsy values that indicate "empty"
138
- if (value !== undefined && value !== null && value !== '') {
139
- if (!Array.isArray(value) || value.length > 0) {
140
- result[key] = source[key];
141
- }
142
- }
143
- }
144
- return result;
199
+ const result = {};
200
+ for (const key in source) {
201
+ const value = source[key];
202
+ if (value !== void 0 && value !== null && value !== "") {
203
+ if (!Array.isArray(value) || value.length > 0) result[key] = source[key];
204
+ }
205
+ }
206
+ return result;
145
207
  }
146
-
147
208
  /**
148
- * Sorts query params by both key and value returning a new URLSearchParams
149
- * object with the keys inserted in sorted order.
150
- *
151
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
152
- *
153
- * Options:
154
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
155
- *
156
- * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
157
- * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
158
- * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
159
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
160
- *
161
- * @public
162
- * @return A {@link URLSearchParams} with keys inserted in sorted order
163
- */
209
+ * Sorts query params by both key and value returning a new URLSearchParams
210
+ * object with the keys inserted in sorted order.
211
+ *
212
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
213
+ *
214
+ * Options:
215
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
216
+ *
217
+ * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`
218
+ * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`
219
+ * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`
220
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`
221
+ *
222
+ * @public
223
+ * @return A {@link URLSearchParams} with keys inserted in sorted order
224
+ */
164
225
  function sortQueryParams(params, options) {
165
- const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);
166
- const paramsIsObject = !(params instanceof URLSearchParams);
167
- const urlParams = new URLSearchParams();
168
- const dictionaryParams = paramsIsObject ? params : {};
169
- if (!paramsIsObject) {
170
- params.forEach((value, key) => {
171
- const hasExisting = key in dictionaryParams;
172
- if (!hasExisting) {
173
- dictionaryParams[key] = value;
174
- } else {
175
- const existingValue = dictionaryParams[key];
176
- if (Array.isArray(existingValue)) {
177
- existingValue.push(value);
178
- } else {
179
- dictionaryParams[key] = [existingValue, value];
180
- }
181
- }
182
- });
183
- }
184
- if ('include' in dictionaryParams) {
185
- dictionaryParams.include = handleInclude(dictionaryParams.include);
186
- }
187
- const sortedKeys = Object.keys(dictionaryParams).sort();
188
- sortedKeys.forEach(key => {
189
- const value = dictionaryParams[key];
190
- if (Array.isArray(value)) {
191
- value.sort();
192
- switch (opts.arrayFormat) {
193
- case 'indices':
194
- value.forEach((v, i) => {
195
- urlParams.append(`${key}[${i}]`, String(v));
196
- });
197
- return;
198
- case 'bracket':
199
- value.forEach(v => {
200
- urlParams.append(`${key}[]`, String(v));
201
- });
202
- return;
203
- case 'repeat':
204
- value.forEach(v => {
205
- urlParams.append(key, String(v));
206
- });
207
- return;
208
- case 'comma':
209
- default:
210
- urlParams.append(key, value.join(','));
211
- return;
212
- }
213
- } else {
214
- urlParams.append(key, String(value));
215
- }
216
- });
217
- return urlParams;
226
+ const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);
227
+ const paramsIsObject = !(params instanceof URLSearchParams);
228
+ const urlParams = new URLSearchParams();
229
+ const dictionaryParams = paramsIsObject ? params : {};
230
+ if (!paramsIsObject) params.forEach((value, key) => {
231
+ if (!(key in dictionaryParams)) dictionaryParams[key] = value;
232
+ else {
233
+ const existingValue = dictionaryParams[key];
234
+ if (Array.isArray(existingValue)) existingValue.push(value);
235
+ else dictionaryParams[key] = [existingValue, value];
236
+ }
237
+ });
238
+ if ("include" in dictionaryParams) dictionaryParams.include = handleInclude(dictionaryParams.include);
239
+ Object.keys(dictionaryParams).sort().forEach((key) => {
240
+ const value = dictionaryParams[key];
241
+ if (Array.isArray(value)) {
242
+ value.sort();
243
+ switch (opts.arrayFormat) {
244
+ case "indices":
245
+ value.forEach((v, i) => {
246
+ urlParams.append(`${key}[${i}]`, String(v));
247
+ });
248
+ return;
249
+ case "bracket":
250
+ value.forEach((v) => {
251
+ urlParams.append(`${key}[]`, String(v));
252
+ });
253
+ return;
254
+ case "repeat":
255
+ value.forEach((v) => {
256
+ urlParams.append(key, String(v));
257
+ });
258
+ return;
259
+ default:
260
+ urlParams.append(key, value.join(","));
261
+ return;
262
+ }
263
+ } else urlParams.append(key, String(value));
264
+ });
265
+ return urlParams;
218
266
  }
219
-
220
267
  /**
221
- * Sorts query params by both key and value, returning a query params string
222
- *
223
- * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
224
- *
225
- * Options:
226
- * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
227
- *
228
- * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
229
- * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
230
- * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
231
- * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
232
- *
233
- * @public
234
- * @return A sorted query params string without the leading `?`
235
- */
268
+ * Sorts query params by both key and value, returning a query params string
269
+ *
270
+ * Treats `included` specially, splicing it into an array if it is a string and sorting the array.
271
+ *
272
+ * Options:
273
+ * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
274
+ *
275
+ * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
276
+ * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
277
+ * 'repeat': appends the key for every value e.g. `ids=1&ids=2`
278
+ * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
279
+ *
280
+ * @public
281
+ * @return A sorted query params string without the leading `?`
282
+ */
236
283
  function buildQueryParams(params, options) {
237
- return sortQueryParams(params, options).toString();
284
+ return sortQueryParams(params, options).toString();
238
285
  }
239
- export { buildBaseURL, buildQueryParams, filterEmpty, setBuildURLConfig, sortQueryParams };
286
+
287
+ //#endregion
288
+ export { buildBaseURL, buildQueryParams, filterEmpty, setBuildURLConfig, sortQueryParams };
289
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["getOrSetGlobal","CONFIG","host","namespace","setBuildURLConfig","config","OPERATIONS_WITH_PRIMARY_RECORDS","Set","isOperationWithPrimaryRecord","options","has","op","hasResourcePath","resourcePath","length","resourcePathForType","identifiers","type","identifier","buildBaseURL","urlOptions","Object","assign","idPath","encodeURIComponent","id","fieldPath","hasHost","url","filter","Boolean","join","DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS","arrayFormat","handleInclude","include","split","filterEmpty","source","result","key","value","undefined","Array","isArray","sortQueryParams","params","opts","paramsIsObject","URLSearchParams","urlParams","dictionaryParams","forEach","hasExisting","existingValue","push","sortedKeys","keys","sort","v","i","append","String","buildQueryParams","toString"],"sources":["../../../src/index.ts"],"sourcesContent":["/**\n * @module\n * @mergeModuleWith <project>\n */\n\nimport { 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// 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\n/**\n * The global configuration used by {@link buildBaseURL} when a call does\n * not provide its own `host`/`namespace`. Set via {@link setBuildURLConfig}.\n *\n * @public\n */\nexport interface BuildURLConfig {\n /**\n * The scheme, domain and port (if any) to prefix built URLs with, e.g. `'https://api.example.com'`.\n */\n host: string | null;\n /**\n * The path segment to insert between `host` and the resource path, e.g. `'api/v1'`.\n */\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 '@warp-drive/utilities';\n *\n * setBuildURLConfig({\n * host: 'https://api.example.com',\n * namespace: 'api/v1'\n * });\n * ```\n *\n * @public\n */\nexport function setBuildURLConfig(config: BuildURLConfig): void {\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\n/**\n * {@link buildBaseURL} options for a `findRecord` request.\n *\n * @public\n */\nexport interface FindRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRecord';\n /**\n * The type and id of the record to find.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `query` request.\n *\n * @public\n */\nexport interface QueryUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'query';\n /**\n * The type of the records to query.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `findMany` request.\n *\n * @public\n */\nexport interface FindManyUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findMany';\n /**\n * The type and id of each record to find.\n */\n identifiers: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n }[];\n /**\n * The path segment for the resource, defaults to the first identifier's `type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n/**\n * {@link buildBaseURL} options for a `findRelatedCollection` request.\n *\n * @public\n */\nexport interface FindRelatedCollectionUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRelatedCollection';\n /**\n * The type and id of the record whose relationship is being fetched.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The relationship field name, appended to the resource path.\n */\n fieldPath: string;\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `findRelatedRecord` request.\n *\n * @public\n */\nexport interface FindRelatedResourceUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRelatedRecord';\n /**\n * The type and id of the record whose relationship is being fetched.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The relationship field name, appended to the resource path.\n */\n fieldPath: string;\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `createRecord` request.\n *\n * @public\n */\nexport interface CreateRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'createRecord';\n /**\n * The type of the record being created.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for an `updateRecord` request.\n *\n * @public\n */\nexport interface UpdateRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'updateRecord';\n /**\n * The type and id of the record being updated.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `deleteRecord` request.\n *\n * @public\n */\nexport interface DeleteRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'deleteRecord';\n /**\n * The type and id of the record being deleted.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for building a URL directly from a `resourcePath`\n * without an associated request operation.\n *\n * @public\n */\nexport interface GenericUrlOptions {\n /**\n * The path segment for the resource.\n */\n resourcePath: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * The union of all `op`-specific option shapes accepted by {@link buildBaseURL}, one of:\n *\n * - {@link FindRecordUrlOptions}\n * - {@link QueryUrlOptions}\n * - {@link FindManyUrlOptions}\n * - {@link FindRelatedCollectionUrlOptions}\n * - {@link FindRelatedResourceUrlOptions}\n * - {@link CreateRecordUrlOptions}\n * - {@link UpdateRecordUrlOptions}\n * - {@link DeleteRecordUrlOptions}\n * - {@link GenericUrlOptions}\n *\n * @public\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 '@warp-drive/utilities';\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 */\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 source object to filter keys with empty values from\n * @return 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 * @return A {@link 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 * @return 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"],"mappings":"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"}
@@ -0,0 +1,80 @@
1
+ //#region src/-private/string/inflections.ts
2
+ const defaultRules = {
3
+ plurals: [
4
+ [/$/, "s"],
5
+ [/s$/i, "s"],
6
+ [/^(ax|test)is$/i, "$1es"],
7
+ [/(octop|vir)us$/i, "$1i"],
8
+ [/(octop|vir)i$/i, "$1i"],
9
+ [/(alias|status|bonus)$/i, "$1es"],
10
+ [/(tu|bu)s$/i, "$1ses"],
11
+ [/(buffal|tomat)o$/i, "$1oes"],
12
+ [/([ti])um$/i, "$1a"],
13
+ [/([ti])a$/i, "$1a"],
14
+ [/sis$/i, "ses"],
15
+ [/(?:([^f])fe|([lr])f)$/i, "$1$2ves"],
16
+ [/(hive)$/i, "$1s"],
17
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
18
+ [/(x|ch|ss|sh)$/i, "$1es"],
19
+ [/(matr|vert|ind)(?:ix|ex)$/i, "$1ices"],
20
+ [/^(m|l)ouse$/i, "$1ice"],
21
+ [/^(m|l)ice$/i, "$1ice"],
22
+ [/^(ox)$/i, "$1en"],
23
+ [/^(oxen)$/i, "$1"],
24
+ [/(quiz)$/i, "$1zes"]
25
+ ],
26
+ singular: [
27
+ [/s$/i, ""],
28
+ [/(ss)$/i, "$1"],
29
+ [/(n)ews$/i, "$1ews"],
30
+ [/([ti])a$/i, "$1um"],
31
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "$1sis"],
32
+ [/(^analy)(sis|ses)$/i, "$1sis"],
33
+ [/([^f])ves$/i, "$1fe"],
34
+ [/(hive)s$/i, "$1"],
35
+ [/(tive)s$/i, "$1"],
36
+ [/([lr])ves$/i, "$1f"],
37
+ [/([^aeiouy]|qu)ies$/i, "$1y"],
38
+ [/(s)eries$/i, "$1eries"],
39
+ [/(m)ovies$/i, "$1ovie"],
40
+ [/(x|ch|ss|sh)es$/i, "$1"],
41
+ [/^(m|l)ice$/i, "$1ouse"],
42
+ [/(tus|bus)(es)?$/i, "$1"],
43
+ [/(o)es$/i, "$1"],
44
+ [/(shoe)s$/i, "$1"],
45
+ [/(cris|test)(is|es)$/i, "$1is"],
46
+ [/^(a)x[ie]s$/i, "$1xis"],
47
+ [/(octop|vir)(us|i)$/i, "$1us"],
48
+ [/(alias|status|bonus)(es)?$/i, "$1"],
49
+ [/^(ox)en/i, "$1"],
50
+ [/(vert|ind)ices$/i, "$1ex"],
51
+ [/(matr)ices$/i, "$1ix"],
52
+ [/(quiz)zes$/i, "$1"],
53
+ [/(database)s$/i, "$1"]
54
+ ],
55
+ irregularPairs: [
56
+ ["person", "people"],
57
+ ["man", "men"],
58
+ ["child", "children"],
59
+ ["sex", "sexes"],
60
+ ["move", "moves"],
61
+ ["cow", "kine"],
62
+ ["zombie", "zombies"]
63
+ ],
64
+ uncountable: [
65
+ "equipment",
66
+ "information",
67
+ "rice",
68
+ "money",
69
+ "species",
70
+ "series",
71
+ "fish",
72
+ "sheep",
73
+ "jeans",
74
+ "police"
75
+ ]
76
+ };
77
+
78
+ //#endregion
79
+ export { defaultRules as t };
80
+ //# sourceMappingURL=inflections-DzBsjJqj.js.map