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