@warp-drive-mirror/utilities 5.8.0-alpha.37 → 5.8.0-alpha.40
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/unpkg/dev/active-record.js +11 -12
- package/dist/unpkg/dev/handlers.js +4 -5
- package/dist/unpkg/dev/index.js +50 -49
- package/dist/unpkg/{prod-deprecated/inflect-BSG696t-.js → dev/inflect-BEv8WqY1.js} +4 -5
- package/dist/unpkg/dev/json-api.js +16 -16
- package/dist/unpkg/dev/rest.js +11 -12
- package/dist/unpkg/dev/string.js +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js +11 -12
- package/dist/unpkg/dev-deprecated/handlers.js +4 -5
- package/dist/unpkg/dev-deprecated/index.js +50 -49
- package/dist/unpkg/dev-deprecated/{inflect-BSG696t-.js → inflect-BEv8WqY1.js} +4 -5
- package/dist/unpkg/dev-deprecated/json-api.js +16 -16
- package/dist/unpkg/dev-deprecated/rest.js +11 -12
- package/dist/unpkg/dev-deprecated/string.js +1 -1
- package/dist/unpkg/prod/active-record.js +1 -30
- package/dist/unpkg/prod/handlers.js +1 -13
- package/dist/unpkg/prod/index.js +2 -124
- package/dist/unpkg/{dev/inflect-BSG696t-.js → prod/inflect-Dh9dyEYx.js} +0 -11
- package/dist/unpkg/prod/json-api.js +2 -40
- package/dist/unpkg/prod/rest.js +1 -30
- package/dist/unpkg/prod/string.js +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js +1 -30
- package/dist/unpkg/prod-deprecated/handlers.js +1 -13
- package/dist/unpkg/prod-deprecated/index.js +2 -124
- package/dist/unpkg/{prod/inflect-BSG696t-.js → prod-deprecated/inflect-Dh9dyEYx.js} +0 -11
- package/dist/unpkg/prod-deprecated/json-api.js +2 -40
- package/dist/unpkg/prod-deprecated/rest.js +1 -30
- package/dist/unpkg/prod-deprecated/string.js +1 -1
- package/package.json +12 -20
- package/dist/unpkg/dev/declarations/-private/active-record/find-record.d.ts +0 -64
- package/dist/unpkg/dev/declarations/-private/active-record/query.d.ts +0 -53
- package/dist/unpkg/dev/declarations/-private/active-record/save-record.d.ts +0 -146
- package/dist/unpkg/dev/declarations/-private/builder-utils.d.ts +0 -4
- package/dist/unpkg/dev/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/dist/unpkg/dev/declarations/-private/handlers/gated.d.ts +0 -19
- package/dist/unpkg/dev/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/dist/unpkg/dev/declarations/-private/handlers/utils.d.ts +0 -41
- package/dist/unpkg/dev/declarations/-private/json-api/-utils.d.ts +0 -109
- package/dist/unpkg/dev/declarations/-private/json-api/find-record.d.ts +0 -84
- package/dist/unpkg/dev/declarations/-private/json-api/query.d.ts +0 -100
- package/dist/unpkg/dev/declarations/-private/json-api/save-record.d.ts +0 -228
- package/dist/unpkg/dev/declarations/-private/json-api/serialize.d.ts +0 -70
- package/dist/unpkg/dev/declarations/-private/rest/find-record.d.ts +0 -62
- package/dist/unpkg/dev/declarations/-private/rest/query.d.ts +0 -53
- package/dist/unpkg/dev/declarations/-private/rest/save-record.d.ts +0 -146
- package/dist/unpkg/dev/declarations/-private/string/inflect.d.ts +0 -82
- package/dist/unpkg/dev/declarations/-private/string/inflections.d.ts +0 -9
- package/dist/unpkg/dev/declarations/-private/string/transform.d.ts +0 -77
- package/dist/unpkg/dev/declarations/-private.d.ts +0 -1
- package/dist/unpkg/dev/declarations/active-record.d.ts +0 -3
- package/dist/unpkg/dev/declarations/derivations.d.ts +0 -27
- package/dist/unpkg/dev/declarations/handlers.d.ts +0 -10
- package/dist/unpkg/dev/declarations/index.d.ts +0 -208
- package/dist/unpkg/dev/declarations/json-api.d.ts +0 -5
- package/dist/unpkg/dev/declarations/rest.d.ts +0 -3
- package/dist/unpkg/dev/declarations/string.d.ts +0 -14
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/find-record.d.ts +0 -64
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/query.d.ts +0 -53
- package/dist/unpkg/dev-deprecated/declarations/-private/active-record/save-record.d.ts +0 -146
- package/dist/unpkg/dev-deprecated/declarations/-private/builder-utils.d.ts +0 -4
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/gated.d.ts +0 -19
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/dist/unpkg/dev-deprecated/declarations/-private/handlers/utils.d.ts +0 -41
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/-utils.d.ts +0 -109
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/find-record.d.ts +0 -84
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/query.d.ts +0 -100
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/save-record.d.ts +0 -228
- package/dist/unpkg/dev-deprecated/declarations/-private/json-api/serialize.d.ts +0 -70
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/find-record.d.ts +0 -62
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/query.d.ts +0 -53
- package/dist/unpkg/dev-deprecated/declarations/-private/rest/save-record.d.ts +0 -146
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflect.d.ts +0 -82
- package/dist/unpkg/dev-deprecated/declarations/-private/string/inflections.d.ts +0 -9
- package/dist/unpkg/dev-deprecated/declarations/-private/string/transform.d.ts +0 -77
- package/dist/unpkg/dev-deprecated/declarations/-private.d.ts +0 -1
- package/dist/unpkg/dev-deprecated/declarations/active-record.d.ts +0 -3
- package/dist/unpkg/dev-deprecated/declarations/derivations.d.ts +0 -27
- package/dist/unpkg/dev-deprecated/declarations/handlers.d.ts +0 -10
- package/dist/unpkg/dev-deprecated/declarations/index.d.ts +0 -208
- package/dist/unpkg/dev-deprecated/declarations/json-api.d.ts +0 -5
- package/dist/unpkg/dev-deprecated/declarations/rest.d.ts +0 -3
- package/dist/unpkg/dev-deprecated/declarations/string.d.ts +0 -14
- package/dist/unpkg/prod/declarations/-private/active-record/find-record.d.ts +0 -64
- package/dist/unpkg/prod/declarations/-private/active-record/query.d.ts +0 -53
- package/dist/unpkg/prod/declarations/-private/active-record/save-record.d.ts +0 -146
- package/dist/unpkg/prod/declarations/-private/builder-utils.d.ts +0 -4
- package/dist/unpkg/prod/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/dist/unpkg/prod/declarations/-private/handlers/gated.d.ts +0 -19
- package/dist/unpkg/prod/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/dist/unpkg/prod/declarations/-private/handlers/utils.d.ts +0 -41
- package/dist/unpkg/prod/declarations/-private/json-api/-utils.d.ts +0 -109
- package/dist/unpkg/prod/declarations/-private/json-api/find-record.d.ts +0 -84
- package/dist/unpkg/prod/declarations/-private/json-api/query.d.ts +0 -100
- package/dist/unpkg/prod/declarations/-private/json-api/save-record.d.ts +0 -228
- package/dist/unpkg/prod/declarations/-private/json-api/serialize.d.ts +0 -70
- package/dist/unpkg/prod/declarations/-private/rest/find-record.d.ts +0 -62
- package/dist/unpkg/prod/declarations/-private/rest/query.d.ts +0 -53
- package/dist/unpkg/prod/declarations/-private/rest/save-record.d.ts +0 -146
- package/dist/unpkg/prod/declarations/-private/string/inflect.d.ts +0 -82
- package/dist/unpkg/prod/declarations/-private/string/inflections.d.ts +0 -9
- package/dist/unpkg/prod/declarations/-private/string/transform.d.ts +0 -77
- package/dist/unpkg/prod/declarations/-private.d.ts +0 -1
- package/dist/unpkg/prod/declarations/active-record.d.ts +0 -3
- package/dist/unpkg/prod/declarations/derivations.d.ts +0 -27
- package/dist/unpkg/prod/declarations/handlers.d.ts +0 -10
- package/dist/unpkg/prod/declarations/index.d.ts +0 -208
- package/dist/unpkg/prod/declarations/json-api.d.ts +0 -5
- package/dist/unpkg/prod/declarations/rest.d.ts +0 -3
- package/dist/unpkg/prod/declarations/string.d.ts +0 -14
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/find-record.d.ts +0 -64
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/query.d.ts +0 -53
- package/dist/unpkg/prod-deprecated/declarations/-private/active-record/save-record.d.ts +0 -146
- package/dist/unpkg/prod-deprecated/declarations/-private/builder-utils.d.ts +0 -4
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/auto-compress.d.ts +0 -158
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/gated.d.ts +0 -19
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/meta-doc.d.ts +0 -47
- package/dist/unpkg/prod-deprecated/declarations/-private/handlers/utils.d.ts +0 -41
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/-utils.d.ts +0 -109
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/find-record.d.ts +0 -84
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/query.d.ts +0 -100
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/save-record.d.ts +0 -228
- package/dist/unpkg/prod-deprecated/declarations/-private/json-api/serialize.d.ts +0 -70
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/find-record.d.ts +0 -62
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/query.d.ts +0 -53
- package/dist/unpkg/prod-deprecated/declarations/-private/rest/save-record.d.ts +0 -146
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflect.d.ts +0 -82
- package/dist/unpkg/prod-deprecated/declarations/-private/string/inflections.d.ts +0 -9
- package/dist/unpkg/prod-deprecated/declarations/-private/string/transform.d.ts +0 -77
- package/dist/unpkg/prod-deprecated/declarations/-private.d.ts +0 -1
- package/dist/unpkg/prod-deprecated/declarations/active-record.d.ts +0 -3
- package/dist/unpkg/prod-deprecated/declarations/derivations.d.ts +0 -27
- package/dist/unpkg/prod-deprecated/declarations/handlers.d.ts +0 -10
- package/dist/unpkg/prod-deprecated/declarations/index.d.ts +0 -208
- package/dist/unpkg/prod-deprecated/declarations/json-api.d.ts +0 -5
- package/dist/unpkg/prod-deprecated/declarations/rest.d.ts +0 -3
- package/dist/unpkg/prod-deprecated/declarations/string.d.ts +0 -14
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { Handler } from "@warp-drive-mirror/core/request";
|
|
2
|
-
/**
|
|
3
|
-
* MetaDocHandler processes requests that are marked as meta requests.
|
|
4
|
-
*
|
|
5
|
-
* It treats the response body as "entirely meta" transforming
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* {
|
|
9
|
-
* some: "key",
|
|
10
|
-
* another: "thing"
|
|
11
|
-
* }
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* into
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* {
|
|
18
|
-
* meta: {
|
|
19
|
-
* some: "key",
|
|
20
|
-
* another: "thing"
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* To activate this handler, a request should specify
|
|
26
|
-
*
|
|
27
|
-
* ```ts
|
|
28
|
-
* options.isMetaRequest = true
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* For instance
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* store.request({
|
|
35
|
-
* url: '/example',
|
|
36
|
-
* options: {
|
|
37
|
-
* isMetaRequest: true
|
|
38
|
-
* }
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* Errors are not processed by this handler, so if the request fails and the error response
|
|
43
|
-
* is not in {json:api} format additional processing may be needed.
|
|
44
|
-
*
|
|
45
|
-
* @group Handlers
|
|
46
|
-
*/
|
|
47
|
-
export declare const MetaDocHandler: Handler;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A unique identifier for the current browser tab
|
|
3
|
-
* useful for observability/tracing and deduping
|
|
4
|
-
* across multiple tabs.
|
|
5
|
-
*
|
|
6
|
-
* @group Constants
|
|
7
|
-
*/
|
|
8
|
-
export declare const TAB_ID: string;
|
|
9
|
-
/**
|
|
10
|
-
* The epoch seconds at which the tab id was generated
|
|
11
|
-
*
|
|
12
|
-
* @group Constants
|
|
13
|
-
*/
|
|
14
|
-
export declare const TAB_ASSIGNED: number;
|
|
15
|
-
/**
|
|
16
|
-
* Adds the `X-Amzn-Trace-Id` header to support observability
|
|
17
|
-
* tooling around request routing.
|
|
18
|
-
*
|
|
19
|
-
* This makes use of the {@link TAB_ID} and {@link TAB_ASSIGNED}
|
|
20
|
-
* to enable tracking the browser tab of origin across multiple requests.
|
|
21
|
-
*
|
|
22
|
-
* Follows the template: `Root=1-${now}-${uuidv4};TabId=1-${epochSeconds}-${tab-uuid}`
|
|
23
|
-
*
|
|
24
|
-
* @group Utility Functions
|
|
25
|
-
*/
|
|
26
|
-
export declare function addTraceHeader(headers: Headers): Headers;
|
|
27
|
-
/**
|
|
28
|
-
* Source: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/cloudfront-limits.html
|
|
29
|
-
* As of 2024-12-05 the maximum URL length is 8192 bytes.
|
|
30
|
-
*
|
|
31
|
-
* @group Constants
|
|
32
|
-
*/
|
|
33
|
-
export declare const MAX_URL_LENGTH = 8192;
|
|
34
|
-
/**
|
|
35
|
-
* This assertion takes a URL and throws an error if the URL is longer than the maximum URL length.
|
|
36
|
-
*
|
|
37
|
-
* See also {@link MAX_URL_LENGTH}
|
|
38
|
-
*
|
|
39
|
-
* @group Utility Functions
|
|
40
|
-
*/
|
|
41
|
-
export declare function assertInvalidUrlLength(url: string | undefined): void;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
2
|
-
import type { BuildURLConfig } from "../../index.js";
|
|
3
|
-
export interface JSONAPIConfig extends BuildURLConfig {
|
|
4
|
-
profiles?: {
|
|
5
|
-
pagination?: string;
|
|
6
|
-
[key: string]: string | undefined;
|
|
7
|
-
};
|
|
8
|
-
extensions?: {
|
|
9
|
-
atomic?: string;
|
|
10
|
-
[key: string]: string | undefined;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export declare let CONFIG: JSONAPIConfig;
|
|
14
|
-
export declare let ACCEPT_HEADER_VALUE: string;
|
|
15
|
-
/**
|
|
16
|
-
* Allows setting extensions and profiles to be used in the `Accept` header.
|
|
17
|
-
*
|
|
18
|
-
* Extensions and profiles are keyed by their namespace with the value being
|
|
19
|
-
* their URI.
|
|
20
|
-
*
|
|
21
|
-
* Example:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* setBuildURLConfig({
|
|
25
|
-
* extensions: {
|
|
26
|
-
* atomic: 'https://jsonapi.org/ext/atomic'
|
|
27
|
-
* },
|
|
28
|
-
* profiles: {
|
|
29
|
-
* pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'
|
|
30
|
-
* }
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* This also sets the global configuration for `buildBaseURL`
|
|
35
|
-
* for host and namespace values for the global coniguration
|
|
36
|
-
* done via `import { setBuildURLConfig } from '@warp-drive-mirror/utilities';`
|
|
37
|
-
*
|
|
38
|
-
* These values may still be overridden by passing
|
|
39
|
-
* them to buildBaseURL directly.
|
|
40
|
-
*
|
|
41
|
-
* This method may be called as many times as needed
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* type BuildURLConfig = {
|
|
45
|
-
* host: string;
|
|
46
|
-
* namespace: string'
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @public
|
|
51
|
-
* @param {BuildURLConfig} config
|
|
52
|
-
* @return {void}
|
|
53
|
-
*/
|
|
54
|
-
export declare function setBuildURLConfig(config: JSONAPIConfig): void;
|
|
55
|
-
interface RelatedObject {
|
|
56
|
-
[key: string]: string | string[] | RelatedObject;
|
|
57
|
-
}
|
|
58
|
-
export type JsonApiQuery = {
|
|
59
|
-
include?: string | string[] | RelatedObject;
|
|
60
|
-
fields?: Record<string, string | string[]>;
|
|
61
|
-
page?: {
|
|
62
|
-
size?: number;
|
|
63
|
-
after?: string;
|
|
64
|
-
before?: string;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Sorts query params by both key and value, returning a query params string
|
|
69
|
-
*
|
|
70
|
-
* Treats `included` specially, splicing it into an array if it is a string and sorting the array.
|
|
71
|
-
* - If `included` is an object we build paths dynamically for you
|
|
72
|
-
* Treats `fields` specially, building JSON:API partial fields params from an object
|
|
73
|
-
* Treats `page` specially, building cursor-pagination profile page params from an object
|
|
74
|
-
*
|
|
75
|
-
* ```ts
|
|
76
|
-
* const params = buildQueryParams({
|
|
77
|
-
* include: {
|
|
78
|
-
* company: {
|
|
79
|
-
* locations: 'address'
|
|
80
|
-
* }
|
|
81
|
-
* },
|
|
82
|
-
* fields: {
|
|
83
|
-
* company: ['name', 'ticker'],
|
|
84
|
-
* person: 'name'
|
|
85
|
-
* },
|
|
86
|
-
* page: {
|
|
87
|
-
* size: 10,
|
|
88
|
-
* after: 'abc',
|
|
89
|
-
* }
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // => 'fields[company]=name,ticker&fields[person]=name&include=company.locations,company.locations.address&page[after]=abc&page[size]=10'
|
|
93
|
-
* ```
|
|
94
|
-
*
|
|
95
|
-
* Options:
|
|
96
|
-
* - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'
|
|
97
|
-
*
|
|
98
|
-
* 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`
|
|
99
|
-
* 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`
|
|
100
|
-
* 'repeat': appends the key for every value e.g. `ids=1&ids=2`
|
|
101
|
-
* 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`
|
|
102
|
-
*
|
|
103
|
-
* @public
|
|
104
|
-
* @param {URLSearchParams | Object} params
|
|
105
|
-
* @param {Object} [options]
|
|
106
|
-
* @return {String} A sorted query params string without the leading `?`
|
|
107
|
-
*/
|
|
108
|
-
export declare function buildQueryParams(query: JsonApiQuery | QueryParamsSource): string;
|
|
109
|
-
export {};
|
|
@@ -1,84 +0,0 @@
|
|
|
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 JSON:API APIs.
|
|
7
|
-
*
|
|
8
|
-
* :::tabs
|
|
9
|
-
*
|
|
10
|
-
* == Basic Usage
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
14
|
-
* import type { Person } from '#/data/types';
|
|
15
|
-
*
|
|
16
|
-
* const result = await store.request(
|
|
17
|
-
* findRecord<Person>('person', '1')
|
|
18
|
-
* );
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* == With Options
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
25
|
-
* import type { Person } from '#/data/types';
|
|
26
|
-
*
|
|
27
|
-
* const data = await store.request(
|
|
28
|
-
* findRecord<Person>(
|
|
29
|
-
* 'person', '1',
|
|
30
|
-
* { include: ['pets', 'friends'] }
|
|
31
|
-
* )
|
|
32
|
-
* );
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* == With an Identifier
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
39
|
-
* import type { Person } from '#/data/types';
|
|
40
|
-
*
|
|
41
|
-
* const data = await store.request(
|
|
42
|
-
* findRecord<Person>(
|
|
43
|
-
* { type: 'person', id: '1' },
|
|
44
|
-
* { include: ['pets', 'friends'] }
|
|
45
|
-
* )
|
|
46
|
-
* );
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* :::
|
|
50
|
-
*
|
|
51
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
52
|
-
*
|
|
53
|
-
* The following options are supported:
|
|
54
|
-
*
|
|
55
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
56
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
57
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
58
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
59
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
60
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
61
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
62
|
-
* defaulting to `false` if none is configured.
|
|
63
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* import { findRecord } from '@warp-drive-mirror/utilities/json-api';
|
|
67
|
-
*
|
|
68
|
-
* const data = await store.request(
|
|
69
|
-
* findRecord(
|
|
70
|
-
* 'person', '1',
|
|
71
|
-
* { include: ['pets', 'friends'] },
|
|
72
|
-
* { namespace: 'api/v2' }
|
|
73
|
-
* )
|
|
74
|
-
* );
|
|
75
|
-
* ```
|
|
76
|
-
*
|
|
77
|
-
* @public
|
|
78
|
-
*/
|
|
79
|
-
export declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
80
|
-
export declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
81
|
-
export declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
|
|
82
|
-
export declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
|
|
83
|
-
/** @deprecated use {@link ReactiveDataDocument} */
|
|
84
|
-
export type FindRecordResultDocument<T> = ReactiveDataDocument<T>;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { ReactiveDataDocument } from "@warp-drive-mirror/core/reactive";
|
|
2
|
-
import type { QueryParamsSource } from "@warp-drive-mirror/core/types/params";
|
|
3
|
-
import type { TypedRecordInstance, TypeFromInstance } from "@warp-drive-mirror/core/types/record";
|
|
4
|
-
import type { ConstrainedRequestOptions, PostQueryRequestOptions, 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 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-mirror/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-mirror/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-mirror/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
|
-
*/
|
|
53
|
-
export declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
54
|
-
export declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
|
|
55
|
-
/**
|
|
56
|
-
* Builds request options to query for resources, usually by a primary
|
|
57
|
-
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
58
|
-
*
|
|
59
|
-
* The key difference between this and `query` is that this method will send the query
|
|
60
|
-
* as the JSON body of a "POST" request instead of as query params in the url of a "GET"
|
|
61
|
-
* request.
|
|
62
|
-
*
|
|
63
|
-
* A CacheKey is generated from the url and query params, and used to cache the response
|
|
64
|
-
* in the store.
|
|
65
|
-
*
|
|
66
|
-
* ```ts
|
|
67
|
-
* import { postQuery } from '@warp-drive-mirror/utilities/json-api';
|
|
68
|
-
*
|
|
69
|
-
* const options = postQuery('person', { include: ['pets', 'friends'] });
|
|
70
|
-
* const data = await store.request(options);
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* **Supplying Options to Modify the Request Behavior**
|
|
74
|
-
*
|
|
75
|
-
* The following options are supported:
|
|
76
|
-
*
|
|
77
|
-
* - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
|
|
78
|
-
* - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
|
|
79
|
-
* - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
|
|
80
|
-
* - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
|
|
81
|
-
* option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
|
|
82
|
-
* - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
|
|
83
|
-
* promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
|
|
84
|
-
* defaulting to `false` if none is configured.
|
|
85
|
-
* - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
|
|
86
|
-
*
|
|
87
|
-
* ```ts
|
|
88
|
-
* import { postQuery } from '@warp-drive-mirror/utilities/json-api';
|
|
89
|
-
*
|
|
90
|
-
* const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });
|
|
91
|
-
* const data = await store.request(options);
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @public
|
|
95
|
-
* @param identifier
|
|
96
|
-
* @param query
|
|
97
|
-
* @param options
|
|
98
|
-
*/
|
|
99
|
-
export declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
|
|
100
|
-
export declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
|
|
@@ -1,228 +0,0 @@
|
|
|
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;
|
|
@@ -1,70 +0,0 @@
|
|
|
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 {};
|