@warp-drive-mirror/utilities 5.10.0-alpha.2 → 5.10.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 (131) hide show
  1. package/README.md +92 -7
  2. package/cjs-dist/string.cjs +23 -8
  3. package/cjs-dist/string.cjs.map +1 -1
  4. package/dist/-private.d.ts +0 -2
  5. package/dist/-private.d.ts.map +1 -1
  6. package/dist/-private.js +1 -1
  7. package/dist/active-record.d.ts +21 -6
  8. package/dist/active-record.d.ts.map +1 -1
  9. package/dist/active-record.js +17 -8
  10. package/dist/active-record.js.map +1 -1
  11. package/dist/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
  12. package/dist/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
  13. package/dist/derivations.d.ts +3 -2
  14. package/dist/derivations.d.ts.map +1 -1
  15. package/dist/derivations.js +7 -2
  16. package/dist/derivations.js.map +1 -1
  17. package/dist/handlers.d.ts +26 -9
  18. package/dist/handlers.d.ts.map +1 -1
  19. package/dist/handlers.js +29 -9
  20. package/dist/handlers.js.map +1 -1
  21. package/dist/{index-BeMAuqgZ.d.ts → index-Dv5kZpGe.d.ts} +47 -3
  22. package/dist/index-Dv5kZpGe.d.ts.map +1 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +54 -8
  25. package/dist/index.js.map +1 -1
  26. package/dist/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
  27. package/dist/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
  28. package/dist/json-api.d.ts +51 -11
  29. package/dist/json-api.d.ts.map +1 -1
  30. package/dist/json-api.js +43 -12
  31. package/dist/json-api.js.map +1 -1
  32. package/dist/rest.d.ts +20 -6
  33. package/dist/rest.d.ts.map +1 -1
  34. package/dist/rest.js +17 -8
  35. package/dist/rest.js.map +1 -1
  36. package/dist/{string-CWmAluxh.js → string-DFhbMVCj.js} +23 -6
  37. package/dist/string-DFhbMVCj.js.map +1 -0
  38. package/dist/string.d.ts +19 -4
  39. package/dist/string.d.ts.map +1 -1
  40. package/dist/string.js +1 -1
  41. package/dist/unpkg/dev/-private.js +1 -1
  42. package/dist/unpkg/dev/active-record.js +17 -8
  43. package/dist/unpkg/dev/active-record.js.map +1 -1
  44. package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
  45. package/dist/unpkg/dev/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
  46. package/dist/unpkg/dev/derivations.js +7 -2
  47. package/dist/unpkg/dev/derivations.js.map +1 -1
  48. package/dist/unpkg/dev/handlers.js +29 -9
  49. package/dist/unpkg/dev/handlers.js.map +1 -1
  50. package/dist/unpkg/dev/index.js +54 -8
  51. package/dist/unpkg/dev/index.js.map +1 -1
  52. package/dist/unpkg/dev/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
  53. package/dist/unpkg/dev/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
  54. package/dist/unpkg/dev/json-api.js +43 -12
  55. package/dist/unpkg/dev/json-api.js.map +1 -1
  56. package/dist/unpkg/dev/rest.js +17 -8
  57. package/dist/unpkg/dev/rest.js.map +1 -1
  58. package/dist/unpkg/dev/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
  59. package/dist/unpkg/dev/string-D9jrClhQ.js.map +1 -0
  60. package/dist/unpkg/dev/string.js +1 -1
  61. package/dist/unpkg/dev-deprecated/-private.js +1 -1
  62. package/dist/unpkg/dev-deprecated/active-record.js +17 -8
  63. package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
  64. package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
  65. package/dist/unpkg/dev-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
  66. package/dist/unpkg/dev-deprecated/derivations.js +7 -2
  67. package/dist/unpkg/dev-deprecated/derivations.js.map +1 -1
  68. package/dist/unpkg/dev-deprecated/handlers.js +29 -9
  69. package/dist/unpkg/dev-deprecated/handlers.js.map +1 -1
  70. package/dist/unpkg/dev-deprecated/index.js +54 -8
  71. package/dist/unpkg/dev-deprecated/index.js.map +1 -1
  72. package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
  73. package/dist/unpkg/dev-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
  74. package/dist/unpkg/dev-deprecated/json-api.js +43 -12
  75. package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
  76. package/dist/unpkg/dev-deprecated/rest.js +17 -8
  77. package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
  78. package/dist/unpkg/dev-deprecated/{string-j4ur-TDs.js → string-D9jrClhQ.js} +23 -6
  79. package/dist/unpkg/dev-deprecated/string-D9jrClhQ.js.map +1 -0
  80. package/dist/unpkg/dev-deprecated/string.js +1 -1
  81. package/dist/unpkg/prod/-private.js +1 -1
  82. package/dist/unpkg/prod/active-record.js +17 -8
  83. package/dist/unpkg/prod/active-record.js.map +1 -1
  84. package/dist/unpkg/prod/builder-utils-bjXbHa-m.js +15 -0
  85. package/dist/unpkg/prod/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
  86. package/dist/unpkg/prod/derivations.js +7 -2
  87. package/dist/unpkg/prod/derivations.js.map +1 -1
  88. package/dist/unpkg/prod/handlers.js +29 -9
  89. package/dist/unpkg/prod/handlers.js.map +1 -1
  90. package/dist/unpkg/prod/index.js +54 -8
  91. package/dist/unpkg/prod/index.js.map +1 -1
  92. package/dist/unpkg/prod/inflections-CWdUh2K_.js +79 -0
  93. package/dist/unpkg/prod/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
  94. package/dist/unpkg/prod/json-api.js +43 -12
  95. package/dist/unpkg/prod/json-api.js.map +1 -1
  96. package/dist/unpkg/prod/rest.js +17 -8
  97. package/dist/unpkg/prod/rest.js.map +1 -1
  98. package/dist/unpkg/prod/string-Du9nRZEd.js +300 -0
  99. package/dist/unpkg/prod/string-Du9nRZEd.js.map +1 -0
  100. package/dist/unpkg/prod/string.js +1 -1
  101. package/dist/unpkg/prod-deprecated/-private.js +1 -1
  102. package/dist/unpkg/prod-deprecated/active-record.js +17 -8
  103. package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
  104. package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js → builder-utils-bjXbHa-m.js} +2 -3
  105. package/dist/unpkg/prod-deprecated/{builder-utils-BkXwUT0x.js.map → builder-utils-bjXbHa-m.js.map} +1 -1
  106. package/dist/unpkg/prod-deprecated/derivations.js +7 -2
  107. package/dist/unpkg/prod-deprecated/derivations.js.map +1 -1
  108. package/dist/unpkg/prod-deprecated/handlers.js +29 -9
  109. package/dist/unpkg/prod-deprecated/handlers.js.map +1 -1
  110. package/dist/unpkg/prod-deprecated/index.js +54 -8
  111. package/dist/unpkg/prod-deprecated/index.js.map +1 -1
  112. package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js → inflections-CWdUh2K_.js} +2 -3
  113. package/dist/unpkg/prod-deprecated/{inflections-DzBsjJqj.js.map → inflections-CWdUh2K_.js.map} +1 -1
  114. package/dist/unpkg/prod-deprecated/json-api.js +43 -12
  115. package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
  116. package/dist/unpkg/prod-deprecated/rest.js +17 -8
  117. package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
  118. package/dist/unpkg/prod-deprecated/{string-T1ahjLdj.js → string-Du9nRZEd.js} +23 -6
  119. package/dist/unpkg/prod-deprecated/string-Du9nRZEd.js.map +1 -0
  120. package/dist/unpkg/prod-deprecated/string.js +1 -1
  121. package/logos/README.md +1 -1
  122. package/package.json +9 -9
  123. package/dist/index-BeMAuqgZ.d.ts.map +0 -1
  124. package/dist/string-CWmAluxh.js.map +0 -1
  125. package/dist/unpkg/dev/string-j4ur-TDs.js.map +0 -1
  126. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +0 -1
  127. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +0 -16
  128. package/dist/unpkg/prod/inflections-DzBsjJqj.js +0 -80
  129. package/dist/unpkg/prod/string-T1ahjLdj.js +0 -283
  130. package/dist/unpkg/prod/string-T1ahjLdj.js.map +0 -1
  131. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +0 -1
package/dist/rest.d.ts CHANGED
@@ -3,11 +3,13 @@ import { TypeFromInstance, TypedRecordInstance } from "@warp-drive-mirror/core/t
3
3
  import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
4
4
  import { Meta } from "@warp-drive-mirror/core/types/spec/json-api-raw";
5
5
  import { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
6
- //#region src/-private/rest/find-record.d.ts
7
6
  /**
8
7
  * Builds request options to fetch a single resource by a known id or identifier
9
8
  * configured for the url and header expectations of most REST APIs.
10
9
  *
10
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
11
+ * when to use one.
12
+ *
11
13
  * **Basic Usage**
12
14
  *
13
15
  * ```ts
@@ -55,18 +57,20 @@ import { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
55
57
  * const data = await store.request(options);
56
58
  * ```
57
59
  *
60
+ * @summary Builds a `GET` request for one resource by type and id, using REST-style pluralized, camelCased URLs.
58
61
  * @public
59
62
  */
60
63
  export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
61
64
  export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
62
65
  export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
63
66
  export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
64
- //#endregion
65
- //#region src/-private/rest/query.d.ts
66
67
  /**
67
68
  * Builds request options to query for resources, usually by a primary
68
69
  * type, configured for the url and header expectations of most REST APIs.
69
70
  *
71
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
72
+ * when to use one.
73
+ *
70
74
  * **Basic Usage**
71
75
  *
72
76
  * ```ts
@@ -105,6 +109,7 @@ export declare function findRecord(type: string, id: string, options?: FindRecor
105
109
  * const data = await store.request(options);
106
110
  * ```
107
111
  *
112
+ * @summary Builds a `GET` request that queries a resource type with query params, using REST-style URLs.
108
113
  * @public
109
114
  * @param identifier
110
115
  * @param query
@@ -112,12 +117,13 @@ export declare function findRecord(type: string, id: string, options?: FindRecor
112
117
  */
113
118
  export declare function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;
114
119
  export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
115
- //#endregion
116
- //#region src/-private/rest/save-record.d.ts
117
120
  /**
118
121
  * Builds request options to delete record for resources,
119
122
  * configured for the url, method and header expectations of REST APIs.
120
123
  *
124
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
125
+ * when to use one.
126
+ *
121
127
  * **Basic Usage**
122
128
  *
123
129
  * ```ts
@@ -159,6 +165,7 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
159
165
  * const data = await store.request(options);
160
166
  * ```
161
167
  *
168
+ * @summary Builds a `DELETE` request that persists deletion of an existing record, using REST-style URLs.
162
169
  * @public
163
170
  * @param record
164
171
  * @param options
@@ -169,6 +176,9 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
169
176
  * Builds request options to create new record for resources,
170
177
  * configured for the url, method and header expectations of most REST APIs.
171
178
  *
179
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
180
+ * when to use one.
181
+ *
172
182
  * **Basic Usage**
173
183
  *
174
184
  * ```ts
@@ -200,6 +210,7 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
200
210
  * const data = await store.request(options);
201
211
  * ```
202
212
  *
213
+ * @summary Builds a `POST` request that saves a newly created record, using REST-style URLs.
203
214
  * @public
204
215
  * @param record
205
216
  * @param options
@@ -210,6 +221,9 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
210
221
  * Builds request options to update existing record for resources,
211
222
  * configured for the url, method and header expectations of most REST APIs.
212
223
  *
224
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
225
+ * when to use one.
226
+ *
213
227
  * **Basic Usage**
214
228
  *
215
229
  * ```ts
@@ -244,6 +258,7 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
244
258
  * const data = await store.request(options);
245
259
  * ```
246
260
  *
261
+ * @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using REST-style URLs.
247
262
  * @public
248
263
  * @param record
249
264
  * @param options
@@ -254,5 +269,4 @@ export declare function updateRecord<T extends TypedRecordInstance, RT extends T
254
269
  export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
255
270
  patch?: boolean;
256
271
  }): UpdateRequestOptions;
257
- //#endregion
258
272
  //# sourceMappingURL=rest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rest.d.ts","names":[],"sources":["../src/-private/rest/find-record.ts","../src/-private/rest/query.ts","../src/-private/rest/save-record.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkEgB,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WACd,YAAY,8BACZ,UAAU,oBACT;wBACa,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCtBnE,MAAM,GAAG,UAAU,mBAAmB,kBAAkB,2BACtE,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB,KAAK,GAAG;wBACpC,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCSa,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAqEpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuEpE,aACd,UAAU,qBACV,WAAW,sBAAsB,GACjC,UAAU,mBAAmB,kBAC7B,2BAEA,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,qBAAqB,IAAI,GAAG,IAAI;wBACxC,aACd,iBACA,UAAU;EAA8B;IACvC"}
1
+ {"version":3,"file":"rest.d.ts","names":[],"sources":["../src/-private/rest/find-record.ts","../src/-private/rest/query.ts","../src/-private/rest/save-record.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsEgB,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WACd,YAAY,8BACZ,UAAU,oBACT;wBACa,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,2BAC3E,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCtBnE,MAAM,GAAG,UAAU,mBAAmB,kBAAkB,2BACtE,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB,KAAK,GAAG;wBACpC,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCSa,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyEpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2EpE,aACd,UAAU,qBACV,WAAW,sBAAsB,GACjC,UAAU,mBAAmB,kBAC7B,2BAEA,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,qBAAqB,IAAI,GAAG,IAAI;wBACxC,aACd,iBACA,UAAU;EAA8B;IACvC"}
package/dist/rest.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { buildBaseURL, buildQueryParams } from "./index.js";
2
- import { f as camelize, s as pluralize } from "./string-CWmAluxh.js";
3
- import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-BkXwUT0x.js";
2
+ import { f as camelize, s as pluralize } from "./string-DFhbMVCj.js";
3
+ import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-bjXbHa-m.js";
4
4
  import { getGlobalConfig, macroCondition } from "@embroider/macros";
5
5
  import { recordIdentifierFor } from "@warp-drive-mirror/core";
6
6
 
7
- //#region src/-private/rest/find-record.ts
7
+ // src/-private/rest/find-record.ts
8
8
  function findRecord(arg1, arg2, arg3) {
9
9
  const identifier = typeof arg1 === "string" ? {
10
10
  type: arg1,
@@ -31,8 +31,7 @@ function findRecord(arg1, arg2, arg3) {
31
31
  };
32
32
  }
33
33
 
34
- //#endregion
35
- //#region src/-private/rest/query.ts
34
+ // src/-private/rest/query.ts
36
35
  function query(type, query = {}, options = {}) {
37
36
  const cacheOptions = extractCacheOptions(options);
38
37
  const urlOptions = {
@@ -54,8 +53,7 @@ function query(type, query = {}, options = {}) {
54
53
  };
55
54
  }
56
55
 
57
- //#endregion
58
- //#region src/-private/rest/save-record.ts
56
+ // src/-private/rest/save-record.ts
59
57
  function isExisting(identifier) {
60
58
  return "id" in identifier && identifier.id !== null && "type" in identifier && identifier.type !== null;
61
59
  }
@@ -63,6 +61,9 @@ function isExisting(identifier) {
63
61
  * Builds request options to delete record for resources,
64
62
  * configured for the url, method and header expectations of REST APIs.
65
63
  *
64
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
65
+ * when to use one.
66
+ *
66
67
  * **Basic Usage**
67
68
  *
68
69
  * ```ts
@@ -104,6 +105,7 @@ function isExisting(identifier) {
104
105
  * const data = await store.request(options);
105
106
  * ```
106
107
  *
108
+ * @summary Builds a `DELETE` request that persists deletion of an existing record, using REST-style URLs.
107
109
  * @public
108
110
  * @param record
109
111
  * @param options
@@ -138,6 +140,9 @@ function deleteRecord(record, options = {}) {
138
140
  * Builds request options to create new record for resources,
139
141
  * configured for the url, method and header expectations of most REST APIs.
140
142
  *
143
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
144
+ * when to use one.
145
+ *
141
146
  * **Basic Usage**
142
147
  *
143
148
  * ```ts
@@ -169,6 +174,7 @@ function deleteRecord(record, options = {}) {
169
174
  * const data = await store.request(options);
170
175
  * ```
171
176
  *
177
+ * @summary Builds a `POST` request that saves a newly created record, using REST-style URLs.
172
178
  * @public
173
179
  * @param record
174
180
  * @param options
@@ -200,6 +206,9 @@ function createRecord(record, options = {}) {
200
206
  * Builds request options to update existing record for resources,
201
207
  * configured for the url, method and header expectations of most REST APIs.
202
208
  *
209
+ * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
210
+ * when to use one.
211
+ *
203
212
  * **Basic Usage**
204
213
  *
205
214
  * ```ts
@@ -234,6 +243,7 @@ function createRecord(record, options = {}) {
234
243
  * const data = await store.request(options);
235
244
  * ```
236
245
  *
246
+ * @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using REST-style URLs.
237
247
  * @public
238
248
  * @param record
239
249
  * @param options
@@ -265,6 +275,5 @@ function updateRecord(record, options = {}) {
265
275
  };
266
276
  }
267
277
 
268
- //#endregion
269
278
  export { createRecord, deleteRecord, findRecord, query, updateRecord };
270
279
  //# sourceMappingURL=rest.js.map
package/dist/rest.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"rest.js","names":["recordIdentifierFor","buildBaseURL","camelize","pluralize","copyForwardUrlOptions","macroCondition","getGlobalConfig","isExisting","identifier","id","type","deleteRecord","record","options","WarpDrive","env","DEBUG","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../src/-private/rest/find-record.ts","../src/-private/rest/query.ts","../src/-private/rest/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n arg1: TypeFromInstance<T> | RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T> {\n const identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>> =\n typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options: FindRecordOptions = (typeof arg1 === 'string' ? arg3 : (arg2 as FindRecordOptions)) || {};\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n> = ReactiveDataDocument<T, M, E>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(camelize(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":";;;;;;;AAgFA,SAAgB,WACd,MACA,MACA,MAC4D;CAC5D,MAAM,aACJ,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CAClE,MAAM,WAA8B,OAAO,SAAS,WAAW,OAAQ,SAA+B,CAAC;CACvG,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,SAAS,WAAW,IAAI,CAAC;CACnD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EACA,IAAI;EACJ,SAAS,CAAC,UAAU;CACtB;AACF;;;;AC5CA,SAAgB,MACd,MAEA,QAA2B,CAAC,GAC5B,UAAqC,CAAC,GACjB;CACrB,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAA8B;EAClC,YAAY,EAAE,KAAK;EACnB,IAAI;EACJ,cAAc,UAAU,SAAS,IAAI,CAAC;CACxC;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,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LH;EACAI,QAAQb,QAAQkB,QAAQ,UAAU;EAClCR;EACAH,IAAI;EACJO,MAAM,EACJf,QAAQJ,WACV;EACAoB,SAAS,CAACpB,UAAU;CACtB;AACF"}
1
+ {"version":3,"file":"rest.js","names":["recordIdentifierFor","buildBaseURL","camelize","pluralize","copyForwardUrlOptions","macroCondition","getGlobalConfig","isExisting","identifier","id","type","deleteRecord","record","options","WarpDrive","env","DEBUG","test","Error","urlOptions","op","resourcePath","url","headers","Headers","append","method","data","records","createRecord","updateRecord","patch"],"sources":["../src/-private/rest/find-record.ts","../src/-private/rest/query.ts","../src/-private/rest/save-record.ts"],"sourcesContent":["import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n FindRecordOptions,\n FindRecordRequestOptions,\n RemotelyAccessibleIdentifier,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type FindRecordUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to fetch a single resource by a known id or identifier\n * configured for the url and header expectations of most REST APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const data = await store.request(findRecord('person', '1'));\n * ```\n *\n * **With Options**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **With an Identifier**\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { findRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `GET` request for one resource by type and id, using REST-style pluralized, camelCased URLs.\n * @public\n */\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(\n identifier: RemotelyAccessibleIdentifier,\n options?: FindRecordOptions\n): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n id: string,\n options?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;\nexport function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;\nexport function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n arg1: TypeFromInstance<T> | RemotelyAccessibleIdentifier<TypeFromInstance<T>>,\n arg2: string | FindRecordOptions | undefined,\n arg3?: FindRecordOptions\n): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T> {\n const identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>> =\n typeof arg1 === 'string' ? { type: arg1, id: arg2 as string } : arg1;\n const options: FindRecordOptions = (typeof arg1 === 'string' ? arg3 : (arg2 as FindRecordOptions)) || {};\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: FindRecordUrlOptions = {\n identifier,\n op: 'findRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url: options.include?.length\n ? `${url}?${buildQueryParams({ include: options.include }, options.urlParamsSettings)}`\n : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'findRecord',\n records: [identifier],\n };\n}\n\n/** @deprecated use {@link ReactiveDataDocument} instead */\nexport type FindRecordResultDocument<\n T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n> = ReactiveDataDocument<T, M, E>;\n","import type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { QueryParamsSource } from '@warp-drive-mirror/core/types/params';\nimport type { TypeFromInstance } from '@warp-drive-mirror/core/types/record';\nimport type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport { buildBaseURL, buildQueryParams, type QueryUrlOptions } from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions, extractCacheOptions } from '../builder-utils.ts';\n\n/**\n * Builds request options to query for resources, usually by a primary\n * type, configured for the url and header expectations of most REST APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const data = await store.request(query('person'));\n * ```\n *\n * **With Query Params**\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] });\n * const data = await store.request(options);\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { query } from '@warp-drive-mirror/utilities/rest';\n *\n * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `GET` request that queries a resource type with query params, using REST-style URLs.\n * @public\n * @param identifier\n * @param query\n * @param options\n */\nexport function query<T, M extends Meta | undefined = Meta | undefined, E extends object = object>(\n type: TypeFromInstance<T>,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions<ReactiveDataDocument<T[], M, E>>;\nexport function query(\n type: string,\n query?: QueryParamsSource,\n options?: ConstrainedRequestOptions\n): QueryRequestOptions;\nexport function query(\n type: string,\n // oxlint-disable-next-line no-shadow\n query: QueryParamsSource = {},\n options: ConstrainedRequestOptions = {}\n): QueryRequestOptions {\n const cacheOptions = extractCacheOptions(options);\n const urlOptions: QueryUrlOptions = {\n identifier: { type },\n op: 'query',\n resourcePath: pluralize(camelize(type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n const queryString = buildQueryParams(query, options.urlParamsSettings);\n\n return {\n url: queryString ? `${url}?${queryString}` : url,\n method: 'GET',\n headers,\n cacheOptions,\n op: 'query',\n };\n}\n","import { recordIdentifierFor } from '@warp-drive-mirror/core';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { ReactiveDataDocument } from '@warp-drive-mirror/core/reactive';\nimport type { PersistedResourceKey, ResourceKey } from '@warp-drive-mirror/core/types/identifier';\nimport type { TypedRecordInstance } from '@warp-drive-mirror/core/types/record';\nimport type {\n ConstrainedRequestOptions,\n CreateRequestOptions,\n DeleteRequestOptions,\n UpdateRequestOptions,\n} from '@warp-drive-mirror/core/types/request';\nimport type { Meta } from '@warp-drive-mirror/core/types/spec/json-api-raw';\n\nimport {\n buildBaseURL,\n type CreateRecordUrlOptions,\n type DeleteRecordUrlOptions,\n type UpdateRecordUrlOptions,\n} from '../../index.ts';\nimport { camelize, pluralize } from '../../string';\nimport { copyForwardUrlOptions } from '../builder-utils.ts';\n\nfunction isExisting(identifier: ResourceKey): identifier is PersistedResourceKey {\n return 'id' in identifier && identifier.id !== null && 'type' in identifier && identifier.type !== null;\n}\n\n/**\n * Builds request options to delete record for resources,\n * configured for the url, method and header expectations of REST APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const data = await store.request(deleteRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { deleteRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n *\n * // mark record as deleted\n * store.deleteRecord(person);\n *\n * // persist deletion\n * const options = deleteRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `DELETE` request that persists deletion of an existing record, using REST-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;\nexport function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;\nexport function deleteRecord(record: unknown, options: ConstrainedRequestOptions = {}): DeleteRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot delete a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: DeleteRecordUrlOptions = {\n identifier: identifier,\n op: 'deleteRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'DELETE',\n headers,\n op: 'deleteRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to create new record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const data = await store.request(createRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { createRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.createRecord('person', { name: 'Ted' });\n * const options = createRecord(person, { namespace: 'api/v1' });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `POST` request that saves a newly created record, using REST-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;\nexport function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;\nexport function createRecord(record: unknown, options: ConstrainedRequestOptions = {}): CreateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n\n const urlOptions: CreateRecordUrlOptions = {\n identifier: identifier,\n op: 'createRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: 'POST',\n headers,\n op: 'createRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n\n/**\n * Builds request options to update existing record for resources,\n * configured for the url, method and header expectations of most REST APIs.\n *\n * See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and\n * when to use one.\n *\n * **Basic Usage**\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const data = await store.request(updateRecord(person));\n * ```\n *\n * **Supplying Options to Modify the Request Behavior**\n *\n * The following options are supported:\n *\n * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.\n * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.\n * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.\n * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type\n * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this\n * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.\n * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the\n * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,\n * defaulting to `false` if none is configured.\n * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)\n *\n * ```ts\n * import { updateRecord } from '@warp-drive-mirror/utilities/rest';\n *\n * const person = store.peekRecord('person', '1');\n * person.name = 'Chris';\n * const options = updateRecord(person, { patch: true });\n * const data = await store.request(options);\n * ```\n *\n * @summary Builds a `PUT` (or `PATCH`) request that saves changes to an existing record, using REST-style URLs.\n * @public\n * @param record\n * @param options\n */\nexport function updateRecord<\n T extends TypedRecordInstance,\n RT extends TypedRecordInstance = T,\n M extends Meta | undefined = Meta | undefined,\n E extends object = object,\n>(\n record: T,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions<ReactiveDataDocument<RT, M, E>, T>;\nexport function updateRecord(\n record: unknown,\n options?: ConstrainedRequestOptions & { patch?: boolean }\n): UpdateRequestOptions;\nexport function updateRecord(\n record: unknown,\n options: ConstrainedRequestOptions & { patch?: boolean } = {}\n): UpdateRequestOptions {\n const identifier = recordIdentifierFor(record);\n assert(`Expected to be given a record instance`, identifier);\n assert(`Cannot update a record that does not have an associated type and id.`, isExisting(identifier));\n\n const urlOptions: UpdateRecordUrlOptions = {\n identifier: identifier,\n op: 'updateRecord',\n resourcePath: pluralize(camelize(identifier.type)),\n };\n\n copyForwardUrlOptions(urlOptions, options);\n\n const url = buildBaseURL(urlOptions);\n const headers = new Headers();\n headers.append('Accept', 'application/json;charset=utf-8');\n\n return {\n url,\n method: options.patch ? 'PATCH' : 'PUT',\n headers,\n op: 'updateRecord',\n data: {\n record: identifier,\n },\n records: [identifier],\n };\n}\n"],"mappings":";;;;;;;AAoFA,SAAgB,WACd,MACA,MACA,MAC4D;CAC5D,MAAM,aACJ,OAAO,SAAS,WAAW;EAAE,MAAM;EAAM,IAAI;CAAe,IAAI;CAClE,MAAM,WAA8B,OAAO,SAAS,WAAW,OAAQ,SAA+B,CAAC;CACvG,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAAmC;EACvC;EACA,IAAI;EACJ,cAAc,UAAU,SAAS,WAAW,IAAI,CAAC;CACnD;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CAEzD,OAAO;EACL,KAAK,QAAQ,SAAS,SAClB,GAAG,IAAI,GAAG,iBAAiB,EAAE,SAAS,QAAQ,QAAQ,GAAG,QAAQ,iBAAiB,MAClF;EACJ,QAAQ;EACR;EACA;EACA,IAAI;EACJ,SAAS,CAAC,UAAU;CACtB;AACF;;;AC5CA,SAAgB,MACd,MAEA,QAA2B,CAAC,GAC5B,UAAqC,CAAC,GACjB;CACrB,MAAM,eAAe,oBAAoB,OAAO;CAChD,MAAM,aAA8B;EAClC,YAAY,EAAE,KAAK;EACnB,IAAI;EACJ,cAAc,UAAU,SAAS,IAAI,CAAC;CACxC;CAEA,sBAAsB,YAAY,OAAO;CAEzC,MAAM,MAAM,aAAa,UAAU;CACnC,MAAM,UAAU,IAAI,QAAQ;CAC5B,QAAQ,OAAO,UAAU,gCAAgC;CACzD,MAAM,cAAc,iBAAiB,OAAO,QAAQ,iBAAiB;CAErE,OAAO;EACL,KAAK,cAAc,GAAG,IAAI,GAAG,gBAAgB;EAC7C,QAAQ;EACR;EACA;EACA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 import { t as defaultRules } from "./inflections-CWdUh2K_.js";
2
2
  import { getGlobalConfig, macroCondition } from "@embroider/macros";
3
3
  import { LRUCache, STRING_DASHERIZE_CACHE, dasherize } from "@warp-drive-mirror/core/utils/string";
4
4
 
5
- //#region src/-private/string/transform.ts
5
+ // src/-private/string/transform.ts
6
6
  const STRING_CAMELIZE_REGEXP_1 = /(\-|\_|\.|\s)+(.)?/g;
7
7
  const STRING_CAMELIZE_REGEXP_2 = /(^|\/)([A-Z])/g;
8
8
  const CAMELIZE_CACHE = new LRUCache((key) => key.replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr) => chr ? chr.toUpperCase() : "").replace(STRING_CAMELIZE_REGEXP_2, (match) => match.toLowerCase()));
@@ -24,6 +24,7 @@ const CAPITALIZE_CACHE = new LRUCache((str) => str.replace(STRING_CAPITALIZE_REG
24
24
  * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'
25
25
  * ```
26
26
  *
27
+ * @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.
27
28
  * @public
28
29
  * @since 4.13.0
29
30
  */
@@ -42,6 +43,8 @@ const dasherize$1 = dasherize;
42
43
  * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'
43
44
  * ```
44
45
  *
46
+ * @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to
47
+ * `actionName`.
45
48
  * @public
46
49
  * @since 4.13.0
47
50
  */
@@ -61,6 +64,7 @@ function camelize(str) {
61
64
  * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'
62
65
  * ```
63
66
  *
67
+ * @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.
64
68
  * @public
65
69
  * @since 4.13.0
66
70
  */
@@ -80,6 +84,7 @@ function underscore(str) {
80
84
  * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'
81
85
  * ```
82
86
  *
87
+ * @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.
83
88
  * @public
84
89
  * @since 4.13.0
85
90
  */
@@ -90,6 +95,8 @@ function capitalize(str) {
90
95
  * Sets the maximum size of the LRUCache for all string transformation functions.
91
96
  * The default size is 10,000.
92
97
  *
98
+ * @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default
99
+ * 10,000).
93
100
  * @public
94
101
  * @since 4.13.0
95
102
  */
@@ -100,8 +107,7 @@ function setMaxLRUCacheSize(size) {
100
107
  STRING_DASHERIZE_CACHE.size = size;
101
108
  }
102
109
 
103
- //#endregion
104
- //#region src/-private/string/inflect.ts
110
+ // src/-private/string/inflect.ts
105
111
  const BLANK_REGEX = /^\s*$/;
106
112
  const LAST_WORD_DASHED_REGEX = /([\w/-]+[_/\s-])([a-z\d]+$)/;
107
113
  const LAST_WORD_CAMELIZED_REGEX = /([\w/\s-]+)([A-Z][a-z\d]*$)/;
@@ -121,6 +127,7 @@ const PLURAL_RULES = new Map(defaultRules.plurals.reverse());
121
127
  * Marks a word as uncountable. Uncountable words are not pluralized
122
128
  * or singularized.
123
129
  *
130
+ * @summary Registers a word that `pluralize` and `singularize` should always return unchanged.
124
131
  * @public
125
132
  * @since 4.13.0
126
133
  */
@@ -131,6 +138,7 @@ function uncountable(word) {
131
138
  * Marks a list of words as uncountable. Uncountable words are not pluralized
132
139
  * or singularized.
133
140
  *
141
+ * @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.
134
142
  * @public
135
143
  * @since 4.13.0
136
144
  */
@@ -143,6 +151,8 @@ function loadUncountable(uncountables) {
143
151
  * Marks a word as irregular. Irregular words have unique
144
152
  * pluralization and singularization rules.
145
153
  *
154
+ * @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of
155
+ * applying rules.
146
156
  * @public
147
157
  * @since 4.13.0
148
158
  */
@@ -156,6 +166,7 @@ function irregular(single, plur) {
156
166
  * Marks a list of word pairs as irregular. Irregular words have unique
157
167
  * pluralization and singularization rules.
158
168
  *
169
+ * @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.
159
170
  * @public
160
171
  * @since 4.13.0
161
172
  */
@@ -171,6 +182,7 @@ loadIrregular(defaultRules.irregularPairs);
171
182
  /**
172
183
  * Clears the caches for singularize and pluralize.
173
184
  *
185
+ * @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.
174
186
  * @public
175
187
  * @since 4.13.0
176
188
  */
@@ -181,6 +193,7 @@ function clear() {
181
193
  /**
182
194
  * Resets the inflection rules to the defaults.
183
195
  *
196
+ * @summary Discards all custom inflection rules and caches, then restores the built-in default rules.
184
197
  * @public
185
198
  * @since 4.13.0
186
199
  */
@@ -195,6 +208,7 @@ function resetToDefaults() {
195
208
  * Clears all inflection rules
196
209
  * and resets the caches for singularize and pluralize.
197
210
  *
211
+ * @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.
198
212
  * @public
199
213
  * @since 4.13.0
200
214
  */
@@ -210,6 +224,7 @@ function clearRules() {
210
224
  /**
211
225
  * Singularizes a word.
212
226
  *
227
+ * @summary Returns the singular form of an English word using the registered inflection rules, with cached results.
213
228
  * @public
214
229
  * @since 4.13.0
215
230
  */
@@ -223,6 +238,7 @@ function singularize(word) {
223
238
  /**
224
239
  * Pluralizes a word.
225
240
  *
241
+ * @summary Returns the plural form of an English word using the registered inflection rules, with cached results.
226
242
  * @public
227
243
  * @since 4.13.0
228
244
  */
@@ -243,6 +259,7 @@ function unshiftMap(v, map) {
243
259
  /**
244
260
  * Adds a pluralization rule.
245
261
  *
262
+ * @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.
246
263
  * @public
247
264
  * @since 4.13.0
248
265
  */
@@ -253,6 +270,7 @@ function plural(regex, string) {
253
270
  /**
254
271
  * Adds a singularization rule.
255
272
  *
273
+ * @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.
256
274
  * @public
257
275
  * @since 4.13.0
258
276
  */
@@ -285,6 +303,5 @@ function inflect(word, typeRules, irregulars) {
285
303
  return word;
286
304
  }
287
305
 
288
- //#endregion
289
306
  export { loadUncountable as a, resetToDefaults as c, uncountable as d, camelize as f, underscore as g, setMaxLRUCacheSize as h, loadIrregular as i, singular as l, dasherize$1 as m, clearRules as n, plural as o, capitalize as p, irregular as r, pluralize as s, clear as t, singularize as u };
290
- //# sourceMappingURL=string-CWmAluxh.js.map
307
+ //# sourceMappingURL=string-DFhbMVCj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string-DFhbMVCj.js","names":["dasherize","internalDasherize","LRUCache","defaultRules","capitalize","macroCondition","getGlobalConfig","BLANK_REGEX","LAST_WORD_DASHED_REGEX","LAST_WORD_CAMELIZED_REGEX","CAMELIZED_REGEX","SINGULARS","word","_singularize","PLURALS","_pluralize","UNCOUNTABLE","Set","uncountable","IRREGULAR","Map","INVERSE_IRREGULAR","SINGULAR_RULES","singular","reverse","PLURAL_RULES","plurals","add","toLowerCase","loadUncountable","uncountables","forEach","irregular","single","plur","set","loadIrregular","irregularPairs","pair","clear","resetToDefaults","clearRules","v","singularize","WarpDrive","env","DEBUG","test","Error","length","get","pluralize","unshiftMap","map","rules","entries","rule","plural","regex","string","has","delete","inflect","typeRules","irregulars","isBlank","lowercase","wordSplit","exec","lastWord","isCamelized","substitution","match","replace","RegExp"],"sources":["../src/-private/string/transform.ts","../src/-private/string/inflect.ts"],"sourcesContent":["import { dasherize as internalDasherize, LRUCache, STRING_DASHERIZE_CACHE } from '@warp-drive-mirror/core/utils/string';\n\n// oxlint-disable-next-line no-useless-escape\nconst STRING_CAMELIZE_REGEXP_1 = /(\\-|\\_|\\.|\\s)+(.)?/g;\nconst STRING_CAMELIZE_REGEXP_2 = /(^|\\/)([A-Z])/g;\nconst CAMELIZE_CACHE = new LRUCache<string, string>((key: string) =>\n key\n .replace(STRING_CAMELIZE_REGEXP_1, (_match, _separator, chr: string | null) => (chr ? chr.toUpperCase() : ''))\n .replace(STRING_CAMELIZE_REGEXP_2, (match /*, separator, chr */) => match.toLowerCase())\n);\n\nconst STRING_UNDERSCORE_REGEXP_1 = /([a-z\\d])([A-Z]+)/g;\n// oxlint-disable-next-line no-useless-escape\nconst STRING_UNDERSCORE_REGEXP_2 = /\\-|\\s+/g;\nconst UNDERSCORE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_UNDERSCORE_REGEXP_1, '$1_$2').replace(STRING_UNDERSCORE_REGEXP_2, '_').toLowerCase()\n);\n\nconst STRING_CAPITALIZE_REGEXP = /(^|\\/)([a-z\\u00C0-\\u024F])/g;\nconst CAPITALIZE_CACHE = new LRUCache<string, string>((str: string) =>\n str.replace(STRING_CAPITALIZE_REGEXP, (match /*, separator, chr */) => match.toUpperCase())\n);\n\n/**\n * Replaces underscores, spaces, or camelCase with dashes.\n *\n * ```js\n * import { dasherize } from '@warp-drive-mirror/utilities/string';\n *\n * dasherize('innerHTML'); // 'inner-html'\n * dasherize('action_name'); // 'action-name'\n * dasherize('css-class-name'); // 'css-class-name'\n * dasherize('my favorite items'); // 'my-favorite-items'\n * dasherize('privateDocs/ownerInvoice'; // 'private-docs/owner-invoice'\n * ```\n *\n * @summary Converts camelCase, underscored, or spaced strings to dasherized form, such as `innerHTML` to `inner-html`.\n * @public\n * @since 4.13.0\n */\nexport const dasherize: (str: string) => string = internalDasherize;\n\n/**\n * Returns the lowerCamelCase form of a string.\n *\n * ```js\n * import { camelize } from '@warp-drive-mirror/utilities/string';\n *\n * camelize('innerHTML'); // 'innerHTML'\n * camelize('action_name'); // 'actionName'\n * camelize('css-class-name'); // 'cssClassName'\n * camelize('my favorite items'); // 'myFavoriteItems'\n * camelize('My Favorite Items'); // 'myFavoriteItems'\n * camelize('private-docs/owner-invoice'); // 'privateDocs/ownerInvoice'\n * ```\n *\n * @summary Converts dashed, underscored, dotted, or spaced strings to lowerCamelCase, such as `action_name` to\n * `actionName`.\n * @public\n * @since 4.13.0\n */\nexport function camelize(str: string): string {\n return CAMELIZE_CACHE.get(str);\n}\n\n/**\n * Returns the lower\\_case\\_and\\_underscored form of a string.\n *\n * ```js\n * import { underscore } from '@warp-drive-mirror/utilities/string';\n *\n * underscore('innerHTML'); // 'inner_html'\n * underscore('action_name'); // 'action_name'\n * underscore('css-class-name'); // 'css_class_name'\n * underscore('my favorite items'); // 'my_favorite_items'\n * underscore('privateDocs/ownerInvoice'); // 'private_docs/owner_invoice'\n * ```\n *\n * @summary Converts camelCase, dashed, or spaced strings to lowercase snake_case, such as `innerHTML` to `inner_html`.\n * @public\n * @since 4.13.0\n */\nexport function underscore(str: string): string {\n return UNDERSCORE_CACHE.get(str);\n}\n\n/**\n * Returns the Capitalized form of a string\n *\n * ```js\n * import { capitalize } from '@warp-drive-mirror/utilities/string';\n *\n * capitalize('innerHTML') // 'InnerHTML'\n * capitalize('action_name') // 'Action_name'\n * capitalize('css-class-name') // 'Css-class-name'\n * capitalize('my favorite items') // 'My favorite items'\n * capitalize('privateDocs/ownerInvoice'); // 'PrivateDocs/ownerInvoice'\n * ```\n *\n * @summary Uppercases the first letter of a string, and of each `/`-separated path segment, leaving the rest unchanged.\n * @public\n * @since 4.13.0\n */\nexport function capitalize(str: string): string {\n return CAPITALIZE_CACHE.get(str);\n}\n\n/**\n * Sets the maximum size of the LRUCache for all string transformation functions.\n * The default size is 10,000.\n *\n * @summary Sets how many results the `camelize`, `underscore`, `capitalize`, and `dasherize` caches each keep (default\n * 10,000).\n * @public\n * @since 4.13.0\n */\nexport function setMaxLRUCacheSize(size: number): void {\n CAMELIZE_CACHE.size = size;\n UNDERSCORE_CACHE.size = size;\n CAPITALIZE_CACHE.size = size;\n STRING_DASHERIZE_CACHE.size = size;\n}\n","import { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport { LRUCache } from '@warp-drive-mirror/core/utils/string';\n\nimport { defaultRules } from './inflections.ts';\nimport { capitalize } from './transform.ts';\n\nconst BLANK_REGEX = /^\\s*$/;\nconst LAST_WORD_DASHED_REGEX = /([\\w/-]+[_/\\s-])([a-z\\d]+$)/;\nconst LAST_WORD_CAMELIZED_REGEX = /([\\w/\\s-]+)([A-Z][a-z\\d]*$)/;\nconst CAMELIZED_REGEX = /[A-Z][a-z\\d]*$/;\n\nconst SINGULARS = new LRUCache<string, string>((word: string) => {\n return _singularize(word);\n});\nconst PLURALS = new LRUCache<string, string>((word: string) => {\n return _pluralize(word);\n});\nconst UNCOUNTABLE = new Set(defaultRules.uncountable);\nconst IRREGULAR: Map<string, string> = new Map();\nconst INVERSE_IRREGULAR: Map<string, string> = new Map();\nconst SINGULAR_RULES = new Map(defaultRules.singular.reverse());\nconst PLURAL_RULES = new Map(defaultRules.plurals.reverse());\n\n/**\n * Marks a word as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @summary Registers a word that `pluralize` and `singularize` should always return unchanged.\n * @public\n * @since 4.13.0\n */\nexport function uncountable(word: string): void {\n UNCOUNTABLE.add(word.toLowerCase());\n}\n\n/**\n * Marks a list of words as uncountable. Uncountable words are not pluralized\n * or singularized.\n *\n * @summary Registers a list of words that `pluralize` and `singularize` should always return unchanged.\n * @public\n * @since 4.13.0\n */\nexport function loadUncountable(uncountables: string[]): void {\n uncountables.forEach((word) => {\n uncountable(word);\n });\n}\n\n/**\n * Marks a word as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @summary Registers a singular and plural word pair that `pluralize` and `singularize` map directly instead of\n * applying rules.\n * @public\n * @since 4.13.0\n */\nexport function irregular(single: string, plur: string): void {\n //pluralizing\n IRREGULAR.set(single.toLowerCase(), plur);\n IRREGULAR.set(plur.toLowerCase(), plur);\n\n //singularizing\n INVERSE_IRREGULAR.set(plur.toLowerCase(), single);\n INVERSE_IRREGULAR.set(single.toLowerCase(), single);\n}\n\n/**\n * Marks a list of word pairs as irregular. Irregular words have unique\n * pluralization and singularization rules.\n *\n * @summary Registers a list of singular and plural word pairs that `pluralize` and `singularize` map directly.\n * @public\n * @since 4.13.0\n */\nexport function loadIrregular(irregularPairs: Array<[string, string]>): void {\n irregularPairs.forEach((pair) => {\n //pluralizing\n IRREGULAR.set(pair[0].toLowerCase(), pair[1]);\n IRREGULAR.set(pair[1].toLowerCase(), pair[1]);\n\n //singularizing\n INVERSE_IRREGULAR.set(pair[1].toLowerCase(), pair[0]);\n INVERSE_IRREGULAR.set(pair[0].toLowerCase(), pair[0]);\n });\n}\nloadIrregular(defaultRules.irregularPairs);\n\n/**\n * Clears the caches for singularize and pluralize.\n *\n * @summary Empties the cached results of `singularize` and `pluralize` while keeping all inflection rules.\n * @public\n * @since 4.13.0\n */\nexport function clear(): void {\n SINGULARS.clear();\n PLURALS.clear();\n}\n\n/**\n * Resets the inflection rules to the defaults.\n *\n * @summary Discards all custom inflection rules and caches, then restores the built-in default rules.\n * @public\n * @since 4.13.0\n */\nexport function resetToDefaults(): void {\n clearRules();\n defaultRules.uncountable.forEach((v) => UNCOUNTABLE.add(v));\n defaultRules.singular.forEach((v) => SINGULAR_RULES.set(v[0], v[1]));\n defaultRules.plurals.forEach((v) => PLURAL_RULES.set(v[0], v[1]));\n loadIrregular(defaultRules.irregularPairs);\n}\n\n/**\n * Clears all inflection rules\n * and resets the caches for singularize and pluralize.\n *\n * @summary Removes every inflection rule, including the defaults, and empties the `singularize` and `pluralize` caches.\n * @public\n * @since 4.13.0\n */\nexport function clearRules(): void {\n SINGULARS.clear();\n PLURALS.clear();\n UNCOUNTABLE.clear();\n IRREGULAR.clear();\n INVERSE_IRREGULAR.clear();\n SINGULAR_RULES.clear();\n PLURAL_RULES.clear();\n}\n\n/**\n * Singularizes a word.\n *\n * @summary Returns the singular form of an English word using the registered inflection rules, with cached results.\n * @public\n * @since 4.13.0\n */\nexport function singularize(word: string): string {\n assert(`singularize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return SINGULARS.get(word);\n}\n\n/**\n * Pluralizes a word.\n *\n * @summary Returns the plural form of an English word using the registered inflection rules, with cached results.\n * @public\n * @since 4.13.0\n */\nexport function pluralize(word: string): string {\n assert(`pluralize expects to receive a non-empty string`, typeof word === 'string' && word.length > 0);\n if (!word) return '';\n return PLURALS.get(word);\n}\n\nfunction unshiftMap<K, V>(v: [K, V], map: Map<K, V>) {\n // reorder\n const rules = [v, ...map.entries()];\n map.clear();\n rules.forEach((rule) => {\n map.set(rule[0], rule[1]);\n });\n}\n\n/**\n * Adds a pluralization rule.\n *\n * @summary Adds a regex and replacement rule that `pluralize` checks before all existing plural rules.\n * @public\n * @since 4.13.0\n */\nexport function plural(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (PLURAL_RULES.has(regex)) {\n PLURAL_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], PLURAL_RULES);\n}\n\n/**\n * Adds a singularization rule.\n *\n * @summary Adds a regex and replacement rule that `singularize` checks before all existing singular rules.\n * @public\n * @since 4.13.0\n */\nexport function singular(regex: RegExp, string: string): void {\n // rule requires reordering if exists, so remove it first\n if (SINGULAR_RULES.has(regex)) {\n SINGULAR_RULES.delete(regex);\n }\n\n // reorder\n unshiftMap([regex, string], SINGULAR_RULES);\n}\n\nfunction _pluralize(word: string) {\n return inflect(word, PLURAL_RULES, IRREGULAR);\n}\n\nfunction _singularize(word: string) {\n return inflect(word, SINGULAR_RULES, INVERSE_IRREGULAR);\n}\n\nfunction inflect(word: string, typeRules: Map<RegExp, string>, irregulars: Map<string, string>) {\n // empty strings\n const isBlank = !word || BLANK_REGEX.test(word);\n if (isBlank) {\n return word;\n }\n\n // basic uncountables\n const lowercase = word.toLowerCase();\n if (UNCOUNTABLE.has(lowercase)) {\n return word;\n }\n\n // adv uncountables\n const wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word);\n const lastWord = wordSplit ? wordSplit[2].toLowerCase() : null;\n if (lastWord && UNCOUNTABLE.has(lastWord)) {\n return word;\n }\n\n // handle irregulars\n const isCamelized = CAMELIZED_REGEX.test(word);\n for (let [rule, substitution] of irregulars) {\n if (lowercase.match(rule + '$')) {\n if (isCamelized && lastWord && irregulars.has(lastWord)) {\n substitution = capitalize(substitution);\n rule = capitalize(rule);\n }\n\n return word.replace(new RegExp(rule, 'i'), substitution);\n }\n }\n\n // do the actual inflection\n for (const [rule, substitution] of typeRules) {\n if (rule.test(word)) {\n return word.replace(rule, substitution);\n }\n }\n\n return word;\n}\n"],"mappings":";;;;;AAGA,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,iBAAiB,IAAI,UAA0B,QACnD,IACG,QAAQ,2BAA2B,QAAQ,YAAY,QAAwB,MAAM,IAAI,YAAY,IAAI,EAAG,CAAC,CAC7G,QAAQ,2BAA2B,UAAgC,MAAM,YAAY,CAAC,CAC3F;AAEA,MAAM,6BAA6B;AAEnC,MAAM,6BAA6B;AACnC,MAAM,mBAAmB,IAAI,UAA0B,QACrD,IAAI,QAAQ,4BAA4B,OAAO,CAAC,CAAC,QAAQ,4BAA4B,GAAG,CAAC,CAAC,YAAY,CACxG;AAEA,MAAM,2BAA2B;AACjC,MAAM,mBAAmB,IAAI,UAA0B,QACrD,IAAI,QAAQ,2BAA2B,UAAgC,MAAM,YAAY,CAAC,CAC5F;;;;;;;;;;;;;;;;;;AAmBA,MAAaA,cAAqCC;;;;;;;;;;;;;;;;;;;;AAqBlD,SAAgB,SAAS,KAAqB;CAC5C,OAAO,eAAe,IAAI,GAAG;AAC/B;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,WAAW,KAAqB;CAC9C,OAAO,iBAAiB,IAAI,GAAG;AACjC;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,WAAW,KAAqB;CAC9C,OAAO,iBAAiB,IAAI,GAAG;AACjC;;;;;;;;;;AAWA,SAAgB,mBAAmB,MAAoB;CACrD,eAAe,OAAO;CACtB,iBAAiB,OAAO;CACxB,iBAAiB,OAAO;CACxB,uBAAuB,OAAO;AAChC;;;ACnHA,MAAMM,cAAc;AACpB,MAAMC,yBAAyB;AAC/B,MAAMC,4BAA4B;AAClC,MA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