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