@warp-drive/utilities 5.6.0-alpha.11

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 (87) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/-private/active-record/find-record.d.ts +66 -0
  6. package/declarations/-private/active-record/find-record.d.ts.map +1 -0
  7. package/declarations/-private/active-record/query.d.ts +54 -0
  8. package/declarations/-private/active-record/query.d.ts.map +1 -0
  9. package/declarations/-private/active-record/save-record.d.ts +144 -0
  10. package/declarations/-private/active-record/save-record.d.ts.map +1 -0
  11. package/declarations/-private/builder-utils.d.ts +5 -0
  12. package/declarations/-private/builder-utils.d.ts.map +1 -0
  13. package/declarations/-private/handlers/auto-compress.d.ts +153 -0
  14. package/declarations/-private/handlers/auto-compress.d.ts.map +1 -0
  15. package/declarations/-private/json-api/-utils.d.ts +110 -0
  16. package/declarations/-private/json-api/-utils.d.ts.map +1 -0
  17. package/declarations/-private/json-api/find-record.d.ts +66 -0
  18. package/declarations/-private/json-api/find-record.d.ts.map +1 -0
  19. package/declarations/-private/json-api/find-record.type-test.d.ts +2 -0
  20. package/declarations/-private/json-api/find-record.type-test.d.ts.map +1 -0
  21. package/declarations/-private/json-api/query.d.ts +104 -0
  22. package/declarations/-private/json-api/query.d.ts.map +1 -0
  23. package/declarations/-private/json-api/query.type-test.d.ts +2 -0
  24. package/declarations/-private/json-api/query.type-test.d.ts.map +1 -0
  25. package/declarations/-private/json-api/save-record.d.ts +191 -0
  26. package/declarations/-private/json-api/save-record.d.ts.map +1 -0
  27. package/declarations/-private/json-api/serialize.d.ts +57 -0
  28. package/declarations/-private/json-api/serialize.d.ts.map +1 -0
  29. package/declarations/-private/rest/find-record.d.ts +66 -0
  30. package/declarations/-private/rest/find-record.d.ts.map +1 -0
  31. package/declarations/-private/rest/query.d.ts +54 -0
  32. package/declarations/-private/rest/query.d.ts.map +1 -0
  33. package/declarations/-private/rest/save-record.d.ts +144 -0
  34. package/declarations/-private/rest/save-record.d.ts.map +1 -0
  35. package/declarations/-private/string/inflect.d.ts +105 -0
  36. package/declarations/-private/string/inflect.d.ts.map +1 -0
  37. package/declarations/-private/string/inflections.d.ts +10 -0
  38. package/declarations/-private/string/inflections.d.ts.map +1 -0
  39. package/declarations/-private/string/transform.d.ts +89 -0
  40. package/declarations/-private/string/transform.d.ts.map +1 -0
  41. package/declarations/-private.d.ts +2 -0
  42. package/declarations/-private.d.ts.map +1 -0
  43. package/declarations/active-record.d.ts +71 -0
  44. package/declarations/active-record.d.ts.map +1 -0
  45. package/declarations/handlers.d.ts +8 -0
  46. package/declarations/handlers.d.ts.map +1 -0
  47. package/declarations/index.d.ts +255 -0
  48. package/declarations/index.d.ts.map +1 -0
  49. package/declarations/json-api.d.ts +51 -0
  50. package/declarations/json-api.d.ts.map +1 -0
  51. package/declarations/rest.d.ts +51 -0
  52. package/declarations/rest.d.ts.map +1 -0
  53. package/declarations/string.d.ts +14 -0
  54. package/declarations/string.d.ts.map +1 -0
  55. package/dist/-private.js +7 -0
  56. package/dist/-private.js.map +1 -0
  57. package/dist/active-record.js +393 -0
  58. package/dist/active-record.js.map +1 -0
  59. package/dist/builder-utils-Donkk-BZ.js +22 -0
  60. package/dist/builder-utils-Donkk-BZ.js.map +1 -0
  61. package/dist/handlers.js +141 -0
  62. package/dist/handlers.js.map +1 -0
  63. package/dist/index.js +403 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/inflect-C1laviCe.js +376 -0
  66. package/dist/inflect-C1laviCe.js.map +1 -0
  67. package/dist/json-api.js +671 -0
  68. package/dist/json-api.js.map +1 -0
  69. package/dist/rest.js +393 -0
  70. package/dist/rest.js.map +1 -0
  71. package/dist/string.js +1 -0
  72. package/dist/string.js.map +1 -0
  73. package/logos/NCC-1701-a-blue.svg +4 -0
  74. package/logos/NCC-1701-a-gold.svg +4 -0
  75. package/logos/NCC-1701-a-gold_100.svg +1 -0
  76. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  77. package/logos/NCC-1701-a.svg +4 -0
  78. package/logos/README.md +4 -0
  79. package/logos/docs-badge.svg +2 -0
  80. package/logos/ember-data-logo-dark.svg +12 -0
  81. package/logos/ember-data-logo-light.svg +12 -0
  82. package/logos/github-header.svg +444 -0
  83. package/logos/social1.png +0 -0
  84. package/logos/social2.png +0 -0
  85. package/logos/warp-drive-logo-dark.svg +4 -0
  86. package/logos/warp-drive-logo-gold.svg +4 -0
  87. package/package.json +68 -0
@@ -0,0 +1,66 @@
1
+ import type { TypeFromInstance } from '@warp-drive/core/types/record';
2
+ import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from '@warp-drive/core/types/request';
3
+ import type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';
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 JSON:API APIs.
7
+ *
8
+ * **Basic Usage**
9
+ *
10
+ * ```ts
11
+ * import { findRecord } from '@warp-drive/utilities/json-api';
12
+ *
13
+ * const data = await store.request(findRecord('person', '1'));
14
+ * ```
15
+ *
16
+ * **With Options**
17
+ *
18
+ * ```ts
19
+ * import { findRecord } from '@warp-drive/utilities/json-api';
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/utilities/json-api';
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 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/utilities/json-api';
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
+ * @param identifier
57
+ * @param options
58
+ */
59
+ export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & {
60
+ data: T;
61
+ };
62
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
63
+ export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
64
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
65
+ export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
66
+ //# sourceMappingURL=find-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-record.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/find-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAOvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAEpG,wBAAgB,UAAU,CAAC,CAAC,EAC1B,UAAU,EAAE,4BAA4B,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAC7D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CACxB,UAAU,EAAE,4BAA4B,EACxC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,wBAAwB,CAAC;AAC5B,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=find-record.type-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-record.type-test.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/find-record.type-test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,104 @@
1
+ import type { QueryParamsSource } from '@warp-drive/core/types/params';
2
+ import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';
3
+ import type { ConstrainedRequestOptions, PostQueryRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';
4
+ import type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';
5
+ /**
6
+ * Builds request options to query for resources, usually by a primary
7
+ * type, configured for the url and header expectations of most JSON:API APIs.
8
+ *
9
+ * The key difference between this and `postQuery` is that this method will send the query
10
+ * as query params in the url of a "GET" request instead of as the JSON body of a "POST"
11
+ * request.
12
+ *
13
+ * **Basic Usage**
14
+ *
15
+ * ```ts
16
+ * import { query } from '@warp-drive/utilities/json-api';
17
+ *
18
+ * const data = await store.request(query('person'));
19
+ * ```
20
+ *
21
+ * **With Query Params**
22
+ *
23
+ * ```ts
24
+ * import { query } from '@warp-drive/utilities/json-api';
25
+ *
26
+ * const options = query('person', { include: ['pets', 'friends'] });
27
+ * const data = await store.request(options);
28
+ * ```
29
+ *
30
+ * **Supplying Options to Modify the Request Behavior**
31
+ *
32
+ * The following options are supported:
33
+ *
34
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
35
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
36
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
37
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
38
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
39
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
40
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
41
+ * defaulting to `false` if none is configured.
42
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
43
+ *
44
+ * ```ts
45
+ * import { query } from '@warp-drive/utilities/json-api';
46
+ *
47
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
48
+ * const data = await store.request(options);
49
+ * ```
50
+ *
51
+ * @public
52
+ * @param identifier
53
+ * @param query
54
+ * @param options
55
+ */
56
+ export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource<T>, options?: ConstrainedRequestOptions): QueryRequestOptions<CollectionResourceDataDocument<T>, T>;
57
+ export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
58
+ /**
59
+ * Builds request options to query for resources, usually by a primary
60
+ * type, configured for the url and header expectations of most JSON:API APIs.
61
+ *
62
+ * The key difference between this and `query` is that this method will send the query
63
+ * as the JSON body of a "POST" request instead of as query params in the url of a "GET"
64
+ * request.
65
+ *
66
+ * A CacheKey is generated from the url and query params, and used to cache the response
67
+ * in the store.
68
+ *
69
+ * ```ts
70
+ * import { postQuery } from '@warp-drive/utilities/json-api';
71
+ *
72
+ * const options = postQuery('person', { include: ['pets', 'friends'] });
73
+ * const data = await store.request(options);
74
+ * ```
75
+ *
76
+ * **Supplying Options to Modify the Request Behavior**
77
+ *
78
+ * The following options are supported:
79
+ *
80
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
81
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
82
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
83
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
84
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
85
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
86
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
87
+ * defaulting to `false` if none is configured.
88
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
89
+ *
90
+ * ```ts
91
+ * import { postQuery } from '@warp-drive/utilities/json-api';
92
+ *
93
+ * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });
94
+ * const data = await store.request(options);
95
+ * ```
96
+ *
97
+ * @public
98
+ * @param identifier
99
+ * @param query
100
+ * @param options
101
+ */
102
+ export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<CollectionResourceDataDocument<T>, T>;
103
+ export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
104
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAEV,yBAAyB,EACzB,uBAAuB,EACvB,mBAAmB,EACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAM3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,mBAAmB,EACjD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7D,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC;AA8BvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,uBAAuB,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACjE,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=query.type-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.type-test.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/query.type-test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,191 @@
1
+ import type { TypedRecordInstance } from '@warp-drive/core/types/record';
2
+ import type { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, UpdateRequestOptions } from '@warp-drive/core/types/request';
3
+ import type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';
4
+ /**
5
+ * Builds request options to delete record for resources,
6
+ * configured for the url, method and header expectations of most JSON:API APIs.
7
+ *
8
+ * **Basic Usage**
9
+ *
10
+ * ```ts
11
+ * import { deleteRecord } from '@warp-drive/utilities/json-api';
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/utilities/json-api';
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 JSON:API APIs.
58
+ *
59
+ * **Basic Usage**
60
+ *
61
+ * ```ts
62
+ * import { createRecord } from '@warp-drive/utilities/json-api';
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/utilities/json-api';
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 JSON:API APIs.
99
+ *
100
+ * **Basic Usage**
101
+ *
102
+ * ```ts
103
+ * import { updateRecord } from '@warp-drive/utilities/json-api';
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/utilities/json-api';
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<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
139
+ patch?: boolean;
140
+ }): UpdateRequestOptions<SingleResourceDataDocument<RT>, T>;
141
+ export declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
142
+ patch?: boolean;
143
+ }): UpdateRequestOptions;
144
+ /**
145
+ * Builds request options to update existing record for resources,
146
+ * configured for the url and header expectations of most JSON:API APIs
147
+ * for a PATCH request.
148
+ *
149
+ * Note: This is a convenience method that calls `updateRecord` with the
150
+ * supplied request with the `patch` option set to `true`.
151
+ *
152
+ * **Basic Usage**
153
+ *
154
+ * ```ts
155
+ * import { patchRecord } from '@warp-drive/utilities/json-api';
156
+ *
157
+ * const person = store.peekRecord('person', '1');
158
+ * person.name = 'Chris';
159
+ * const data = await store.request(patchRecord(person));
160
+ * ```
161
+ *
162
+ * **Supplying Options to Modify the Request Behavior**
163
+ *
164
+ * The following options are supported:
165
+ *
166
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
167
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
168
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
169
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
170
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
171
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
172
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
173
+ * defaulting to `false` if none is configured.
174
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
175
+ *
176
+ * ```ts
177
+ * import { patchRecord } from '@warp-drive/utilities/json-api';
178
+ *
179
+ * const person = store.peekRecord('person', '1');
180
+ * person.name = 'Chris';
181
+ * const options = patchRecord(person);
182
+ * const data = await store.request(options);
183
+ * ```
184
+ *
185
+ * @public
186
+ * @param record
187
+ * @param options
188
+ */
189
+ export declare function patchRecord<T>(record: T, options?: ConstrainedRequestOptions): UpdateRequestOptions<T>;
190
+ export declare function patchRecord(record: unknown, options?: ConstrainedRequestOptions): UpdateRequestOptions;
191
+ //# sourceMappingURL=save-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"save-record.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/save-record.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EACV,yBAAyB,EACzB,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAgBvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA8BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACzG,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC;AA6BzG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,mBAAmB,EAAE,EAAE,SAAS,mBAAmB,GAAG,CAAC,EAC5F,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC,0BAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3D,wBAAgB,YAAY,CAC1B,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,yBAAyB,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GACxD,oBAAoB,CAAC;AAiCxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;AACxG,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,57 @@
1
+ import type { Cache } from '@warp-drive/core/types/cache';
2
+ import type { StableRecordIdentifier } from '@warp-drive/core/types/identifier';
3
+ import type { Value } from '@warp-drive/core/types/json/raw';
4
+ import type { InnerRelationshipDocument, ResourceObject } from '@warp-drive/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
+ * Serializes the current state of a resource or array of resources for use with POST or PUT requests.
20
+ *
21
+ * @public
22
+ * @param {Cache} cache}
23
+ * @param {StableRecordIdentifier} identifier
24
+ * @return {Object} An object with a `data` property containing the serialized resource patch
25
+ */
26
+ export declare function serializeResources(cache: Cache, identifiers: StableRecordIdentifier): {
27
+ data: ResourceObject;
28
+ };
29
+ export declare function serializeResources(cache: Cache, identifiers: StableRecordIdentifier[]): {
30
+ data: ResourceObject[];
31
+ };
32
+ /**
33
+ * Serializes changes to a resource for use with PATCH requests.
34
+ *
35
+ * Only attributes which are changed are serialized.
36
+ * Only relationships which are changed are serialized.
37
+ *
38
+ * Collection relationships serialize the collection as a whole.
39
+ *
40
+ * If you would like to serialize updates to a collection more granularly
41
+ * (for instance, as operations) request the diff from the store and
42
+ * serialize as desired:
43
+ *
44
+ * ```ts
45
+ * const relationshipDiffMap = cache.changedRelationships(identifier);
46
+ * ```
47
+ *
48
+ * @public
49
+ * @param {Cache} cache}
50
+ * @param {StableRecordIdentifier} identifier
51
+ * @return {Object} An object with a `data` property containing the serialized resource patch
52
+ */
53
+ export declare function serializePatch(cache: Cache, identifier: StableRecordIdentifier): {
54
+ data: JsonApiResourcePatch;
55
+ };
56
+ export {};
57
+ //# sourceMappingURL=serialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/-private/json-api/serialize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAE1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAChF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAE1G,KAAK,uBAAuB,GAAG,yBAAyB,CAAC;AAEzD,MAAM,MAAM,oBAAoB,GAC5B;IACE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACzD,GACD;IACE,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,IAAI,CAAC;IACT,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACnC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACzD,CAAC;AAEN;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,GAAG;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC;AAChH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG;IAAE,IAAI,EAAE,cAAc,EAAE,CAAA;CAAE,CAAC;AAuEpH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,sBAAsB,GAEjC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,CAuChC"}
@@ -0,0 +1,66 @@
1
+ import type { TypeFromInstance } from '@warp-drive/core/types/record';
2
+ import type { FindRecordOptions, FindRecordRequestOptions, RemotelyAccessibleIdentifier } from '@warp-drive/core/types/request';
3
+ import type { SingleResourceDataDocument } from '@warp-drive/core/types/spec/document';
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/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/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/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/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
+ * @param identifier
57
+ * @param options
58
+ */
59
+ export type FindRecordResultDocument<T> = Omit<SingleResourceDataDocument<T>, 'data'> & {
60
+ data: T;
61
+ };
62
+ export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
63
+ export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
64
+ export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions<T>): FindRecordRequestOptions<FindRecordResultDocument<T>, T>;
65
+ export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
66
+ //# sourceMappingURL=find-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-record.d.ts","sourceRoot":"","sources":["../../../src/-private/rest/find-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EACV,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAMvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,MAAM,wBAAwB,CAAC,CAAC,IAAI,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC;AAEpG,wBAAgB,UAAU,CAAC,CAAC,EAC1B,UAAU,EAAE,4BAA4B,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAC7D,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CACxB,UAAU,EAAE,4BAA4B,EACxC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,wBAAwB,CAAC;AAC5B,wBAAgB,UAAU,CAAC,CAAC,EAC1B,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC7B,wBAAwB,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,wBAAwB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { QueryParamsSource } from '@warp-drive/core/types/params';
2
+ import type { TypeFromInstance } from '@warp-drive/core/types/record';
3
+ import type { ConstrainedRequestOptions, QueryRequestOptions } from '@warp-drive/core/types/request';
4
+ import type { CollectionResourceDataDocument } from '@warp-drive/core/types/spec/document';
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/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/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/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<CollectionResourceDataDocument<T>, T>;
53
+ export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
54
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../src/-private/rest/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrG,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAC;AAM3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,KAAK,CAAC,CAAC,EACrB,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC,8BAA8B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7D,wBAAgB,KAAK,CACnB,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,iBAAiB,EACzB,OAAO,CAAC,EAAE,yBAAyB,GAClC,mBAAmB,CAAC"}