@warp-drive-mirror/utilities 5.8.0-alpha.30 → 5.8.0-alpha.32
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.
- package/dist/string.js +428 -1
- package/dist/unpkg/dev/-private.js +7 -0
- package/dist/unpkg/dev/active-record.js +395 -0
- package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/dev/declarations/-private.d.ts +1 -0
- package/dist/unpkg/dev/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/dev/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/dev/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/dev/declarations/index.d.ts +208 -0
- package/dist/unpkg/dev/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/dev/declarations/rest.d.ts +3 -0
- package/dist/unpkg/dev/declarations/string.d.ts +14 -0
- package/dist/unpkg/dev/derivations.js +30 -0
- package/dist/unpkg/dev/handlers.js +317 -0
- package/dist/unpkg/dev/index.js +361 -0
- package/dist/unpkg/dev/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/dev/json-api.js +740 -0
- package/dist/unpkg/dev/rest.js +393 -0
- package/dist/unpkg/dev/string.js +1 -0
- package/dist/unpkg/dev-deprecated/-private.js +7 -0
- package/dist/unpkg/dev-deprecated/active-record.js +395 -0
- package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +1 -0
- package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/dev-deprecated/declarations/index.d.ts +208 -0
- package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +3 -0
- package/dist/unpkg/dev-deprecated/declarations/string.d.ts +14 -0
- package/dist/unpkg/dev-deprecated/derivations.js +30 -0
- package/dist/unpkg/dev-deprecated/handlers.js +317 -0
- package/dist/unpkg/dev-deprecated/index.js +361 -0
- package/dist/unpkg/dev-deprecated/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/dev-deprecated/json-api.js +740 -0
- package/dist/unpkg/dev-deprecated/rest.js +393 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -0
- package/dist/unpkg/prod/-private.js +7 -0
- package/dist/unpkg/prod/active-record.js +395 -0
- package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/prod/declarations/-private.d.ts +1 -0
- package/dist/unpkg/prod/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/prod/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/prod/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/prod/declarations/index.d.ts +208 -0
- package/dist/unpkg/prod/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/prod/declarations/rest.d.ts +3 -0
- package/dist/unpkg/prod/declarations/string.d.ts +14 -0
- package/dist/unpkg/prod/derivations.js +30 -0
- package/dist/unpkg/prod/handlers.js +317 -0
- package/dist/unpkg/prod/index.js +361 -0
- package/dist/unpkg/prod/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/prod/json-api.js +740 -0
- package/dist/unpkg/prod/rest.js +393 -0
- package/dist/unpkg/prod/string.js +1 -0
- package/dist/unpkg/prod-deprecated/-private.js +7 -0
- package/dist/unpkg/prod-deprecated/active-record.js +395 -0
- package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +22 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +64 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +53 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +146 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +4 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +158 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +19 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +47 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +41 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +109 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +84 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +100 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +228 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +70 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +62 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +53 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +146 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +82 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +9 -0
- package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +77 -0
- package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +1 -0
- package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +3 -0
- package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +27 -0
- package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +10 -0
- package/dist/unpkg/prod-deprecated/declarations/index.d.ts +208 -0
- package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +5 -0
- package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +3 -0
- package/dist/unpkg/prod-deprecated/declarations/string.d.ts +14 -0
- package/dist/unpkg/prod-deprecated/derivations.js +30 -0
- package/dist/unpkg/prod-deprecated/handlers.js +317 -0
- package/dist/unpkg/prod-deprecated/index.js +361 -0
- package/dist/unpkg/prod-deprecated/inflect-BSG696t-.js +344 -0
- package/dist/unpkg/prod-deprecated/json-api.js +740 -0
- package/dist/unpkg/prod-deprecated/rest.js +393 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive.js";
|
|
2
|
+
import type { TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
|
+
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
+
/**
|
|
5
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
|
|
6
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
7
|
+
* desired and correctly formatted data is sent with the request.
|
|
8
|
+
* :::
|
|
9
|
+
*
|
|
10
|
+
* Builds request options to delete record for resources,
|
|
11
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
12
|
+
*
|
|
13
|
+
* **Basic Usage**
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
17
|
+
*
|
|
18
|
+
* const person = store.peekRecord('person', '1');
|
|
19
|
+
*
|
|
20
|
+
* // mark record as deleted
|
|
21
|
+
* store.deleteRecord(person);
|
|
22
|
+
*
|
|
23
|
+
* // persist deletion
|
|
24
|
+
* const data = await store.request(deleteRecord(person));
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
28
|
+
*
|
|
29
|
+
* The following options are supported:
|
|
30
|
+
*
|
|
31
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
32
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
33
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
34
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
35
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
36
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
37
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
38
|
+
* defaulting to `false` if none is configured.
|
|
39
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
43
|
+
*
|
|
44
|
+
* const person = store.peekRecord('person', '1');
|
|
45
|
+
*
|
|
46
|
+
* // mark record as deleted
|
|
47
|
+
* store.deleteRecord(person);
|
|
48
|
+
*
|
|
49
|
+
* // persist deletion
|
|
50
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
51
|
+
* const data = await store.request(options);
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
* @param record
|
|
56
|
+
* @param options
|
|
57
|
+
*/
|
|
58
|
+
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
59
|
+
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
60
|
+
/**
|
|
61
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
62
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
63
|
+
* desired and correctly formatted data is sent with the request.
|
|
64
|
+
* :::
|
|
65
|
+
*
|
|
66
|
+
* Builds request options to create new record for resources,
|
|
67
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
68
|
+
*
|
|
69
|
+
* **Basic Usage**
|
|
70
|
+
*
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
73
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
74
|
+
* import type { Person } from '#/data/types';
|
|
75
|
+
*
|
|
76
|
+
* const person = store.createRecord<Person>('person', { name: 'Ted' });
|
|
77
|
+
* const init = createRecord(person);
|
|
78
|
+
* init.body = JSON.stringify(
|
|
79
|
+
* {
|
|
80
|
+
* // it's likely you will want to transform this data
|
|
81
|
+
* // somewhat
|
|
82
|
+
* data: store.cache.peek(cacheKeyFor(person))
|
|
83
|
+
* }
|
|
84
|
+
* );
|
|
85
|
+
* const data = await store.request(init);
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
89
|
+
*
|
|
90
|
+
* The following options are supported:
|
|
91
|
+
*
|
|
92
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
93
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
94
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
95
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
96
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
97
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
98
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
99
|
+
* defaulting to `false` if none is configured.
|
|
100
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
104
|
+
*
|
|
105
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
106
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
107
|
+
* const data = await store.request(options);
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @public
|
|
111
|
+
* @param record
|
|
112
|
+
* @param options
|
|
113
|
+
*/
|
|
114
|
+
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
115
|
+
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
116
|
+
/**
|
|
117
|
+
* :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
|
|
118
|
+
* While this may come as a surprise, the app providing the body ensures that only
|
|
119
|
+
* desired and correctly formatted data is sent with the request.
|
|
120
|
+
* :::
|
|
121
|
+
*
|
|
122
|
+
* Builds request options to update existing record for resources,
|
|
123
|
+
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
124
|
+
*
|
|
125
|
+
* **Example Usage**
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { cacheKeyFor } from '@warp-drive-mirror/core';
|
|
129
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
130
|
+
* import type { EditablePerson } from '#/data/types';
|
|
131
|
+
*
|
|
132
|
+
* const mutable = await checkout<EditablePerson>(person);
|
|
133
|
+
* mutable.name = 'Chris';
|
|
134
|
+
* const init = updateRecord(mutable);
|
|
135
|
+
*
|
|
136
|
+
* init.body = JSON.stringify(
|
|
137
|
+
* // it's likely you will want to transform this data
|
|
138
|
+
* // somewhat, or serialize only specific properties instead
|
|
139
|
+
* serializePatch(store.cache, cacheKeyFor(mutable))
|
|
140
|
+
* );
|
|
141
|
+
* const data = await store.request(init);
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
*
|
|
145
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
146
|
+
*
|
|
147
|
+
* The following options are supported:
|
|
148
|
+
*
|
|
149
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
150
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
151
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
152
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
153
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
154
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
155
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
156
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
157
|
+
* defaulting to `false` if none is configured.
|
|
158
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
162
|
+
*
|
|
163
|
+
* const person = store.peekRecord('person', '1');
|
|
164
|
+
* person.name = 'Chris';
|
|
165
|
+
* const options = updateRecord(person, { patch: true });
|
|
166
|
+
* const data = await store.request(options);
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @public
|
|
170
|
+
* @param record
|
|
171
|
+
* @param options
|
|
172
|
+
*/
|
|
173
|
+
export declare function updateRecord<
|
|
174
|
+
T extends TypedRecordInstance,
|
|
175
|
+
RT extends TypedRecordInstance = T
|
|
176
|
+
>(record: T, options?: ConstrainedRequestOptions & {
|
|
177
|
+
patch?: boolean;
|
|
178
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
179
|
+
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
180
|
+
patch?: boolean;
|
|
181
|
+
}): UpdateRequestOptions;
|
|
182
|
+
/**
|
|
183
|
+
* Builds request options to update existing record for resources,
|
|
184
|
+
* configured for the url and header expectations of most JSON:API APIs
|
|
185
|
+
* for a PATCH request.
|
|
186
|
+
*
|
|
187
|
+
* Note: This is a convenience method that calls `updateRecord` with the
|
|
188
|
+
* supplied request with the `patch` option set to `true`.
|
|
189
|
+
*
|
|
190
|
+
* **Basic Usage**
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { patchRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
194
|
+
*
|
|
195
|
+
* const person = store.peekRecord('person', '1');
|
|
196
|
+
* person.name = 'Chris';
|
|
197
|
+
* const data = await store.request(patchRecord(person));
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
201
|
+
*
|
|
202
|
+
* The following options are supported:
|
|
203
|
+
*
|
|
204
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
205
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
206
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
207
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
208
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
209
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
210
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
211
|
+
* defaulting to `false` if none is configured.
|
|
212
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* import { patchRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
216
|
+
*
|
|
217
|
+
* const person = store.peekRecord('person', '1');
|
|
218
|
+
* person.name = 'Chris';
|
|
219
|
+
* const options = patchRecord(person);
|
|
220
|
+
* const data = await store.request(options);
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @public
|
|
224
|
+
* @param record
|
|
225
|
+
* @param options
|
|
226
|
+
*/
|
|
227
|
+
export declare function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;
|
|
228
|
+
export declare function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Cache } from "@warp-drive-mirror/core/types/cache";
|
|
2
|
+
import type { ResourceKey } from "@warp-drive-mirror/core/types/identifier";
|
|
3
|
+
import type { Value } from "@warp-drive-mirror/core/types/json/raw";
|
|
4
|
+
import type { InnerRelationshipDocument, ResourceObject } from "@warp-drive-mirror/core/types/spec/json-api-raw";
|
|
5
|
+
type ChangedRelationshipData = InnerRelationshipDocument;
|
|
6
|
+
export type JsonApiResourcePatch = {
|
|
7
|
+
type: string;
|
|
8
|
+
id: string;
|
|
9
|
+
attributes?: Record<string, Value>;
|
|
10
|
+
relationships?: Record<string, ChangedRelationshipData>;
|
|
11
|
+
} | {
|
|
12
|
+
type: string;
|
|
13
|
+
id: null;
|
|
14
|
+
lid: string;
|
|
15
|
+
attributes?: Record<string, Value>;
|
|
16
|
+
relationships?: Record<string, ChangedRelationshipData>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
20
|
+
*
|
|
21
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
22
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
23
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
24
|
+
* :::
|
|
25
|
+
*
|
|
26
|
+
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param {Cache} cache}
|
|
30
|
+
* @param {ResourceKey} identifier
|
|
31
|
+
* @return {Object} An object with a `data` property containing the serialized resource patch
|
|
32
|
+
*/
|
|
33
|
+
export declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
|
|
34
|
+
data: ResourceObject;
|
|
35
|
+
};
|
|
36
|
+
export declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
|
|
37
|
+
data: ResourceObject[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
|
|
41
|
+
*
|
|
42
|
+
* While this may come as a surprise, they are intended to serialize cache state for more
|
|
43
|
+
* generalized usage. {json:api} has a large variance in acceptable shapes, and only your
|
|
44
|
+
* app can ensure that the body is correctly formatted and contains all necessary data.
|
|
45
|
+
* :::
|
|
46
|
+
*
|
|
47
|
+
* Serializes changes to a resource. Useful for use with building bodies for PATCH requests.
|
|
48
|
+
*
|
|
49
|
+
* Only attributes which are changed are serialized.
|
|
50
|
+
* Only relationships which are changed are serialized.
|
|
51
|
+
*
|
|
52
|
+
* Collection relationships serialize the collection as a whole.
|
|
53
|
+
*
|
|
54
|
+
* If you would like to serialize updates to a collection more granularly
|
|
55
|
+
* (for instance, as operations) request the diff from the store and
|
|
56
|
+
* serialize as desired:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
* @param {Cache} cache}
|
|
64
|
+
* @param {ResourceKey} identifier
|
|
65
|
+
* @return {Object} An object with a `data` property containing the serialized resource patch
|
|
66
|
+
*/
|
|
67
|
+
export declare function serializePatch(cache: Cache, identifier: ResourceKey): {
|
|
68
|
+
data: JsonApiResourcePatch;
|
|
69
|
+
};
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
2
|
+
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
|
+
import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from "@warp-drive-mirror/core/types/request";
|
|
4
|
+
/**
|
|
5
|
+
* Builds request options to fetch a single resource by a known id or identifier
|
|
6
|
+
* configured for the url and header expectations of most REST APIs.
|
|
7
|
+
*
|
|
8
|
+
* **Basic Usage**
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
12
|
+
*
|
|
13
|
+
* const data = await store.request(findRecord('person', '1'));
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* **With Options**
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
20
|
+
*
|
|
21
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] });
|
|
22
|
+
* const data = await store.request(options);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* **With an Identifier**
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
29
|
+
*
|
|
30
|
+
* const options = findRecord({ type: 'person', id: '1' }, { include: ['pets', 'friends'] });
|
|
31
|
+
* const data = await store.request(options);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
35
|
+
*
|
|
36
|
+
* The following options are supported:
|
|
37
|
+
*
|
|
38
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
39
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
40
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
|
|
41
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
42
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
43
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
44
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
45
|
+
* defaulting to `false` if none is configured.
|
|
46
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { findRecord } from '@warp-drive-mirror/utilities/rest';
|
|
50
|
+
*
|
|
51
|
+
* const options = findRecord('person', '1', { include: ['pets', 'friends'] }, { namespace: 'api/v2' });
|
|
52
|
+
* const data = await store.request(options);
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
58
|
+
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
59
|
+
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
60
|
+
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
61
|
+
/** @deprecated use {@link ReactiveDataDocument} instead */
|
|
62
|
+
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
2
|
+
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
3
|
+
import type { TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
4
|
+
import type { ConstrainedRequestOptions, QueryRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
5
|
+
/**
|
|
6
|
+
* Builds request options to query for resources, usually by a primary
|
|
7
|
+
* type, configured for the url and header expectations of most REST APIs.
|
|
8
|
+
*
|
|
9
|
+
* **Basic Usage**
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
13
|
+
*
|
|
14
|
+
* const data = await store.request(query('person'));
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* **With Query Params**
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
21
|
+
*
|
|
22
|
+
* const options = query('person', { include: ['pets', 'friends'] });
|
|
23
|
+
* const data = await store.request(options);
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
27
|
+
*
|
|
28
|
+
* The following options are supported:
|
|
29
|
+
*
|
|
30
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
31
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
32
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing and camelCasing the supplied type
|
|
33
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
34
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
35
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
36
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
37
|
+
* defaulting to `false` if none is configured.
|
|
38
|
+
* - `urlParamsSettings` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { query } from '@warp-drive-mirror/utilities/rest';
|
|
42
|
+
*
|
|
43
|
+
* const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
44
|
+
* const data = await store.request(options);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
* @param identifier
|
|
49
|
+
* @param query
|
|
50
|
+
* @param options
|
|
51
|
+
*/
|
|
52
|
+
export declare function query<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
53
|
+
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
2
|
+
import type { TypedRecordInstance } from "@warp-drive-mirror/core/types/record";
|
|
3
|
+
import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from "@warp-drive-mirror/core/types/request";
|
|
4
|
+
/**
|
|
5
|
+
* Builds request options to delete record for resources,
|
|
6
|
+
* configured for the url, method and header expectations of REST APIs.
|
|
7
|
+
*
|
|
8
|
+
* **Basic Usage**
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
|
|
12
|
+
*
|
|
13
|
+
* const person = store.peekRecord('person', '1');
|
|
14
|
+
*
|
|
15
|
+
* // mark record as deleted
|
|
16
|
+
* store.deleteRecord(person);
|
|
17
|
+
*
|
|
18
|
+
* // persist deletion
|
|
19
|
+
* const data = await store.request(deleteRecord(person));
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
23
|
+
*
|
|
24
|
+
* The following options are supported:
|
|
25
|
+
*
|
|
26
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
27
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
28
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
29
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
30
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
31
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
32
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
33
|
+
* defaulting to `false` if none is configured.
|
|
34
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { deleteRecord } from '@warp-drive-mirror/utilities/rest';
|
|
38
|
+
*
|
|
39
|
+
* const person = store.peekRecord('person', '1');
|
|
40
|
+
*
|
|
41
|
+
* // mark record as deleted
|
|
42
|
+
* store.deleteRecord(person);
|
|
43
|
+
*
|
|
44
|
+
* // persist deletion
|
|
45
|
+
* const options = deleteRecord(person, { namespace: 'api/v1' });
|
|
46
|
+
* const data = await store.request(options);
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
* @param record
|
|
51
|
+
* @param options
|
|
52
|
+
*/
|
|
53
|
+
export declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
|
|
54
|
+
export declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
|
|
55
|
+
/**
|
|
56
|
+
* Builds request options to create new record for resources,
|
|
57
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
58
|
+
*
|
|
59
|
+
* **Basic Usage**
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/rest';
|
|
63
|
+
*
|
|
64
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
65
|
+
* const data = await store.request(createRecord(person));
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
69
|
+
*
|
|
70
|
+
* The following options are supported:
|
|
71
|
+
*
|
|
72
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
73
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
74
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
75
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
76
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
77
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
78
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
79
|
+
* defaulting to `false` if none is configured.
|
|
80
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { createRecord } from '@warp-drive-mirror/utilities/rest';
|
|
84
|
+
*
|
|
85
|
+
* const person = store.createRecord('person', { name: 'Ted' });
|
|
86
|
+
* const options = createRecord(person, { namespace: 'api/v1' });
|
|
87
|
+
* const data = await store.request(options);
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @public
|
|
91
|
+
* @param record
|
|
92
|
+
* @param options
|
|
93
|
+
*/
|
|
94
|
+
export declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
|
|
95
|
+
export declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
|
|
96
|
+
/**
|
|
97
|
+
* Builds request options to update existing record for resources,
|
|
98
|
+
* configured for the url, method and header expectations of most REST APIs.
|
|
99
|
+
*
|
|
100
|
+
* **Basic Usage**
|
|
101
|
+
*
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/rest';
|
|
104
|
+
*
|
|
105
|
+
* const person = store.peekRecord('person', '1');
|
|
106
|
+
* person.name = 'Chris';
|
|
107
|
+
* const data = await store.request(updateRecord(person));
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* **Supplying Options to Modify the Request Behavior**
|
|
111
|
+
*
|
|
112
|
+
* The following options are supported:
|
|
113
|
+
*
|
|
114
|
+
* - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
|
|
115
|
+
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
116
|
+
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
117
|
+
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
118
|
+
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
119
|
+
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
120
|
+
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
121
|
+
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
122
|
+
* defaulting to `false` if none is configured.
|
|
123
|
+
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
124
|
+
*
|
|
125
|
+
* ```ts
|
|
126
|
+
* import { updateRecord } from '@warp-drive-mirror/utilities/rest';
|
|
127
|
+
*
|
|
128
|
+
* const person = store.peekRecord('person', '1');
|
|
129
|
+
* person.name = 'Chris';
|
|
130
|
+
* const options = updateRecord(person, { patch: true });
|
|
131
|
+
* const data = await store.request(options);
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @param record
|
|
136
|
+
* @param options
|
|
137
|
+
*/
|
|
138
|
+
export declare function updateRecord<
|
|
139
|
+
T extends TypedRecordInstance,
|
|
140
|
+
RT extends TypedRecordInstance = T
|
|
141
|
+
>(record: T, options?: ConstrainedRequestOptions & {
|
|
142
|
+
patch?: boolean;
|
|
143
|
+
}): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
|
|
144
|
+
export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
|
|
145
|
+
patch?: boolean;
|
|
146
|
+
}): UpdateRequestOptions;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a word as uncountable. Uncountable words are not pluralized
|
|
3
|
+
* or singularized.
|
|
4
|
+
*
|
|
5
|
+
* @public
|
|
6
|
+
* @since 4.13.0
|
|
7
|
+
*/
|
|
8
|
+
export declare function uncountable(word: string): void;
|
|
9
|
+
/**
|
|
10
|
+
* Marks a list of words as uncountable. Uncountable words are not pluralized
|
|
11
|
+
* or singularized.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
* @since 4.13.0
|
|
15
|
+
*/
|
|
16
|
+
export declare function loadUncountable(uncountables: string[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* Marks a word as irregular. Irregular words have unique
|
|
19
|
+
* pluralization and singularization rules.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @since 4.13.0
|
|
23
|
+
*/
|
|
24
|
+
export declare function irregular(single: string, plur: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Marks a list of word pairs as irregular. Irregular words have unique
|
|
27
|
+
* pluralization and singularization rules.
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
* @since 4.13.0
|
|
31
|
+
*/
|
|
32
|
+
export declare function loadIrregular(irregularPairs: Array<[string, string]>): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clears the caches for singularize and pluralize.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
* @since 4.13.0
|
|
38
|
+
*/
|
|
39
|
+
export declare function clear(): void;
|
|
40
|
+
/**
|
|
41
|
+
* Resets the inflection rules to the defaults.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @since 4.13.0
|
|
45
|
+
*/
|
|
46
|
+
export declare function resetToDefaults(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Clears all inflection rules
|
|
49
|
+
* and resets the caches for singularize and pluralize.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
* @since 4.13.0
|
|
53
|
+
*/
|
|
54
|
+
export declare function clearRules(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Singularizes a word.
|
|
57
|
+
*
|
|
58
|
+
* @public
|
|
59
|
+
* @since 4.13.0
|
|
60
|
+
*/
|
|
61
|
+
export declare function singularize(word: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Pluralizes a word.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @since 4.13.0
|
|
67
|
+
*/
|
|
68
|
+
export declare function pluralize(word: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Adds a pluralization rule.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
* @since 4.13.0
|
|
74
|
+
*/
|
|
75
|
+
export declare function plural(regex: RegExp, string: string): void;
|
|
76
|
+
/**
|
|
77
|
+
* Adds a singularization rule.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
* @since 4.13.0
|
|
81
|
+
*/
|
|
82
|
+
export declare function singular(regex: RegExp, string: string): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type RulesArray = Array<[RegExp, string]>;
|
|
2
|
+
type DefaultRulesType = {
|
|
3
|
+
plurals: RulesArray;
|
|
4
|
+
singular: RulesArray;
|
|
5
|
+
irregularPairs: Array<[string, string]>;
|
|
6
|
+
uncountable: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare const defaultRules: DefaultRulesType;
|
|
9
|
+
export {};
|