@warp-drive/legacy 5.8.0-alpha.4 → 5.8.0-alpha.41
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/README.md +14 -27
- package/declarations/adapter/error.d.ts +7 -7
- package/declarations/adapter/json-api.d.ts +6 -8
- package/declarations/adapter/rest.d.ts +26 -112
- package/declarations/adapter.d.ts +6 -8
- package/declarations/compat/-private.d.ts +1 -1
- package/declarations/compat/builders/find-all.d.ts +6 -6
- package/declarations/compat/builders/find-record.d.ts +8 -8
- package/declarations/compat/builders/query.d.ts +12 -12
- package/declarations/compat/extensions.d.ts +1 -1
- package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
- package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
- package/declarations/compat/utils.d.ts +17 -17
- package/declarations/compat.d.ts +35 -11
- package/declarations/index.d.ts +70 -0
- package/declarations/model/-private/attr.d.ts +5 -6
- package/declarations/model/-private/belongs-to.d.ts +4 -5
- package/declarations/model/-private/has-many.d.ts +4 -5
- package/declarations/model/-private/hooks.d.ts +1 -1
- package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
- package/declarations/model/-private/model.d.ts +18 -59
- package/declarations/model/-private/promise-many-array.d.ts +0 -18
- package/declarations/model/-private/record-state.d.ts +1 -1
- package/declarations/model/-private/references/belongs-to.d.ts +19 -29
- package/declarations/model/-private/references/has-many.d.ts +14 -16
- package/declarations/model/migration-support.d.ts +46 -21
- package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
- package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
- package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
- package/declarations/model-fragments/index.d.ts +5 -0
- package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
- package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
- package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
- package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
- package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
- package/declarations/model-fragments.d.ts +9 -0
- package/declarations/model.d.ts +2 -2
- package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
- package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
- package/declarations/serializer/-private/transforms/date.d.ts +2 -2
- package/declarations/serializer/-private/transforms/number.d.ts +1 -1
- package/declarations/serializer/-private/transforms/string.d.ts +1 -1
- package/declarations/serializer/json-api.d.ts +11 -12
- package/declarations/serializer/json.d.ts +9 -11
- package/declarations/serializer/rest.d.ts +4 -6
- package/declarations/serializer.d.ts +9 -12
- package/dist/{-private-8UmnAf9J.js → -private-BG3bMiKp.js} +3 -2
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.js +14 -15
- package/dist/adapter/json-api.js +4 -1
- package/dist/adapter/rest.js +38 -125
- package/dist/adapter.js +6 -8
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.js +26 -26
- package/dist/compat/utils.js +17 -18
- package/dist/compat.js +61 -43
- package/dist/{errors-8kD2mSe_.js → errors-Cz5KrzBk.js} +115 -122
- package/dist/hooks-D6diaM34.js +74 -0
- package/dist/index.js +195 -0
- package/dist/{json-DziiodPf.js → json-ChdEfB0X.js} +18 -35
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.js +57 -25
- package/dist/model-for-CqXsIKws.js +221 -0
- package/dist/model-fragments.js +76 -0
- package/dist/model.js +18 -90
- package/dist/{schema-provider-DQu4Rjco.js → schema-provider-DJCV_6AF.js} +50 -95
- package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-DPZYoF-i.js} +1 -1
- package/dist/serializer/json-api.js +18 -45
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.js +14 -21
- package/dist/serializer/transform.js +15 -6
- package/dist/serializer.js +9 -13
- package/dist/store.js +5 -1
- package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev/adapter/-private.js +1 -0
- package/dist/unpkg/dev/adapter/error.js +335 -0
- package/dist/unpkg/dev/adapter/json-api.js +271 -0
- package/dist/unpkg/dev/adapter/rest.js +1171 -0
- package/dist/unpkg/dev/adapter.js +1252 -0
- package/dist/unpkg/dev/compat/-private.js +1 -0
- package/dist/unpkg/dev/compat/builders.js +275 -0
- package/dist/unpkg/dev/compat/extensions.js +242 -0
- package/dist/unpkg/dev/compat/utils.js +223 -0
- package/dist/unpkg/dev/compat.js +1147 -0
- package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
- package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
- package/dist/unpkg/dev/index.js +197 -0
- package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev/model/-private.js +1 -0
- package/dist/unpkg/dev/model/migration-support.js +553 -0
- package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev/model-fragments.js +76 -0
- package/dist/unpkg/dev/model.js +678 -0
- package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +2186 -0
- package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev/serializer/json-api.js +649 -0
- package/dist/unpkg/dev/serializer/json.js +4 -0
- package/dist/unpkg/dev/serializer/rest.js +1242 -0
- package/dist/unpkg/dev/serializer/transform.js +278 -0
- package/dist/unpkg/dev/serializer.js +248 -0
- package/dist/unpkg/dev/store.js +637 -0
- package/dist/unpkg/dev/util-DvanW33H.js +20 -0
- package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +1206 -0
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
- package/dist/unpkg/dev-deprecated/adapter/rest.js +1171 -0
- package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
- package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
- package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
- package/dist/unpkg/dev-deprecated/compat.js +1147 -0
- package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
- package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
- package/dist/unpkg/dev-deprecated/index.js +196 -0
- package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
- package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -0
- package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/dev-deprecated/model.js +682 -0
- package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +2211 -0
- package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -0
- package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
- package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/dev-deprecated/serializer.js +248 -0
- package/dist/unpkg/dev-deprecated/store.js +637 -0
- package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
- package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
- package/dist/unpkg/prod/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -0
- package/dist/unpkg/prod/adapter/error.js +330 -0
- package/dist/unpkg/prod/adapter/json-api.js +266 -0
- package/dist/unpkg/prod/adapter/rest.js +1134 -0
- package/dist/unpkg/prod/adapter.js +1219 -0
- package/dist/unpkg/prod/compat/-private.js +1 -0
- package/dist/unpkg/prod/compat/builders.js +210 -0
- package/dist/unpkg/prod/compat/extensions.js +232 -0
- package/dist/unpkg/prod/compat/utils.js +218 -0
- package/dist/unpkg/prod/compat.js +727 -0
- package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
- package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
- package/dist/unpkg/prod/index.js +151 -0
- package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod/model/-private.js +1 -0
- package/dist/unpkg/prod/model/migration-support.js +546 -0
- package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod/model-fragments.js +76 -0
- package/dist/unpkg/prod/model.js +593 -0
- package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +1861 -0
- package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod/serializer/json-api.js +592 -0
- package/dist/unpkg/prod/serializer/json.js +4 -0
- package/dist/unpkg/prod/serializer/rest.js +1210 -0
- package/dist/unpkg/prod/serializer/transform.js +278 -0
- package/dist/unpkg/prod/serializer.js +248 -0
- package/dist/unpkg/prod/store.js +505 -0
- package/dist/unpkg/prod/util-DvanW33H.js +20 -0
- package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
- package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +971 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
- package/dist/unpkg/prod-deprecated/adapter/rest.js +1134 -0
- package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
- package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
- package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
- package/dist/unpkg/prod-deprecated/compat.js +727 -0
- package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
- package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
- package/dist/unpkg/prod-deprecated/index.js +150 -0
- package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
- package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -0
- package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
- package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
- package/dist/unpkg/prod-deprecated/model.js +596 -0
- package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
- package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +1904 -0
- package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -0
- package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
- package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
- package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
- package/dist/unpkg/prod-deprecated/serializer.js +248 -0
- package/dist/unpkg/prod-deprecated/store.js +505 -0
- package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
- package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
- package/logos/README.md +2 -2
- package/logos/logo-yellow-slab.svg +1 -0
- package/logos/word-mark-black.svg +1 -0
- package/logos/word-mark-white.svg +1 -0
- package/package.json +14 -6
- package/logos/NCC-1701-a-blue.svg +0 -4
- package/logos/NCC-1701-a-gold.svg +0 -4
- package/logos/NCC-1701-a-gold_100.svg +0 -1
- package/logos/NCC-1701-a-gold_base-64.txt +0 -1
- package/logos/NCC-1701-a.svg +0 -4
- package/logos/docs-badge.svg +0 -2
- package/logos/ember-data-logo-dark.svg +0 -12
- package/logos/ember-data-logo-light.svg +0 -12
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +0 -4
- package/logos/warp-drive-logo-gold.svg +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { F as FetchManager, S as SaveOp, b as Snapshot, a as SnapshotRecordArray, u as upgradeStore } from "../-private-BdyZaGEh.js";
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { SkipCache } from '@warp-drive/core/types/request';
|
|
2
|
+
import { n as normalizeModelName, i as isMaybeIdentifier } from "../utils-BhvS1iTS.js";
|
|
3
|
+
import { ensureStringId, constructResource, assertPrivateStore } from '@warp-drive/core/store/-private';
|
|
4
|
+
import { storeFor, recordIdentifierFor } from '@warp-drive/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
This function builds a request config to perform a `findAll` request for the given type.
|
|
8
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
|
|
9
|
+
Additionally, it takes the same options as `store.findAll`.
|
|
10
|
+
|
|
11
|
+
All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
12
|
+
This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
|
|
13
|
+
To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
|
|
14
|
+
|
|
15
|
+
@deprecated
|
|
16
|
+
@public
|
|
17
|
+
@param type the name of the resource
|
|
18
|
+
@param query a query to be used by the adapter
|
|
19
|
+
@param options optional, may include `adapterOptions` hash which will be passed to adapter.findAll
|
|
20
|
+
@return request config
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function findAllBuilder(type, options = {}) {
|
|
24
|
+
return {
|
|
25
|
+
op: 'findAll',
|
|
26
|
+
data: {
|
|
27
|
+
type: normalizeModelName(type),
|
|
28
|
+
options: options || {}
|
|
29
|
+
},
|
|
30
|
+
cacheOptions: {
|
|
31
|
+
[SkipCache]: true
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
This function builds a request config to find the record for a given identifier or type and id combination.
|
|
38
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.
|
|
39
|
+
Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).
|
|
40
|
+
|
|
41
|
+
**Example 1**
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { findRecord } from '@warp-drive/legacy/compat/builders';
|
|
45
|
+
const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Example 2**
|
|
49
|
+
|
|
50
|
+
`findRecord` can be called with a single identifier argument instead of the combination
|
|
51
|
+
of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
|
|
52
|
+
the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { findRecord } from '@warp-drive/legacy/compat/builders';
|
|
56
|
+
const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
60
|
+
This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
|
|
61
|
+
To that end, these builders are deprecated and will be removed in a future version of Warp Drive.
|
|
62
|
+
|
|
63
|
+
@deprecated
|
|
64
|
+
@public
|
|
65
|
+
@param resource - either a string representing the name of the resource or a ResourceIdentifier object containing both the type (a string) and the id (a string) for the record or an lid (a string) of an existing record
|
|
66
|
+
@param id - optional object with options for the request only if the first param is a ResourceIdentifier, else the string id of the record to be retrieved
|
|
67
|
+
@param options - if the first param is a string this will be the optional options for the request. See examples for available options.
|
|
68
|
+
@return request config
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
function findRecordBuilder(resource, idOrOptions, options) {
|
|
72
|
+
if (isMaybeIdentifier(resource)) {
|
|
73
|
+
options = idOrOptions;
|
|
74
|
+
} else {
|
|
75
|
+
const type = normalizeModelName(resource);
|
|
76
|
+
const normalizedId = ensureStringId(idOrOptions);
|
|
77
|
+
resource = constructResource(type, normalizedId);
|
|
78
|
+
}
|
|
79
|
+
options = options || {};
|
|
80
|
+
return {
|
|
81
|
+
op: 'findRecord',
|
|
82
|
+
data: {
|
|
83
|
+
record: resource,
|
|
84
|
+
options
|
|
85
|
+
},
|
|
86
|
+
cacheOptions: {
|
|
87
|
+
[SkipCache]: true
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
This function builds a request config for a given type and query object.
|
|
94
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.query` request.
|
|
95
|
+
Additionally, it takes the same options as `store.query`.
|
|
96
|
+
|
|
97
|
+
All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
98
|
+
This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
|
|
99
|
+
To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
|
|
100
|
+
|
|
101
|
+
@deprecated
|
|
102
|
+
@public
|
|
103
|
+
@param type the name of the resource
|
|
104
|
+
@param query a query to be used by the adapter
|
|
105
|
+
@param options optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
106
|
+
@return request config
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
function queryBuilder(type, query, options = {}) {
|
|
110
|
+
return {
|
|
111
|
+
op: 'query',
|
|
112
|
+
data: {
|
|
113
|
+
type: normalizeModelName(type),
|
|
114
|
+
query,
|
|
115
|
+
options: options
|
|
116
|
+
},
|
|
117
|
+
cacheOptions: {
|
|
118
|
+
[SkipCache]: true
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
This function builds a request config for a given type and query object.
|
|
125
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.
|
|
126
|
+
Additionally, it takes the same options as `store.queryRecord`.
|
|
127
|
+
|
|
128
|
+
All `@warp-drive/legacy/compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
129
|
+
This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
|
|
130
|
+
To that end, these builders are deprecated and will be removed in a future version of WarpDrive.
|
|
131
|
+
|
|
132
|
+
@deprecated
|
|
133
|
+
@public
|
|
134
|
+
@param type the name of the resource
|
|
135
|
+
@param query a query to be used by the adapter
|
|
136
|
+
@param options optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
137
|
+
@return request config
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
function queryRecordBuilder(type, query, options) {
|
|
141
|
+
return {
|
|
142
|
+
op: 'queryRecord',
|
|
143
|
+
data: {
|
|
144
|
+
type: normalizeModelName(type),
|
|
145
|
+
query,
|
|
146
|
+
options: options || {}
|
|
147
|
+
},
|
|
148
|
+
cacheOptions: {
|
|
149
|
+
[SkipCache]: true
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function _resourceIsFullDeleted(identifier, cache) {
|
|
154
|
+
return cache.isDeletionCommitted(identifier) || cache.isNew(identifier) && cache.isDeleted(identifier);
|
|
155
|
+
}
|
|
156
|
+
function resourceIsFullyDeleted(instanceCache, identifier) {
|
|
157
|
+
const cache = instanceCache.cache;
|
|
158
|
+
return !cache || _resourceIsFullDeleted(identifier, cache);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).
|
|
163
|
+
When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.
|
|
164
|
+
Additionally, it takes the same options as `store.saveRecord`.
|
|
165
|
+
|
|
166
|
+
All `@ember-data/legacy-compat` builders exist to enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
167
|
+
This is useful for quickly upgrading an entire app to a unified syntax while a longer incremental migration is made to shift off of adapters and serializers.
|
|
168
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
169
|
+
|
|
170
|
+
@deprecated
|
|
171
|
+
@public
|
|
172
|
+
@param {Object} record a record to save
|
|
173
|
+
@param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord
|
|
174
|
+
@return {SaveRecordRequestInput} request config
|
|
175
|
+
*/
|
|
176
|
+
function saveRecordBuilder(record, options = {}) {
|
|
177
|
+
const store = storeFor(record, true);
|
|
178
|
+
assertPrivateStore(store);
|
|
179
|
+
const identifier = recordIdentifierFor(record);
|
|
180
|
+
if (!identifier) {
|
|
181
|
+
// this commonly means we're disconnected
|
|
182
|
+
// but just in case we throw here to prevent bad things.
|
|
183
|
+
throw new Error(`Record Is Disconnected`);
|
|
184
|
+
}
|
|
185
|
+
if (resourceIsFullyDeleted(store._instanceCache, identifier)) {
|
|
186
|
+
throw new Error('cannot build saveRecord request for deleted record');
|
|
187
|
+
}
|
|
188
|
+
if (!options) {
|
|
189
|
+
options = {};
|
|
190
|
+
}
|
|
191
|
+
let operation = 'updateRecord';
|
|
192
|
+
const cache = store.cache;
|
|
193
|
+
if (cache.isNew(identifier)) {
|
|
194
|
+
operation = 'createRecord';
|
|
195
|
+
} else if (cache.isDeleted(identifier)) {
|
|
196
|
+
operation = 'deleteRecord';
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
op: operation,
|
|
200
|
+
data: {
|
|
201
|
+
options,
|
|
202
|
+
record: identifier
|
|
203
|
+
},
|
|
204
|
+
records: [identifier],
|
|
205
|
+
cacheOptions: {
|
|
206
|
+
[SkipCache]: true
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export { findAllBuilder as findAll, findRecordBuilder as findRecord, queryBuilder as query, queryRecordBuilder as queryRecord, saveRecordBuilder as saveRecord };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { get, set } from '@ember/object';
|
|
2
|
+
import { compare } from '@ember/utils';
|
|
3
|
+
import Ember from 'ember';
|
|
4
|
+
const EmberObjectFeatures = {};
|
|
5
|
+
const EmberObjectMethods = ['addObserver', 'cacheFor', 'decrementProperty', 'get', 'getProperties', 'incrementProperty', 'notifyPropertyChange', 'removeObserver', 'set', 'setProperties', 'toggleProperty'];
|
|
6
|
+
EmberObjectMethods.forEach(method => {
|
|
7
|
+
EmberObjectFeatures[method] = function delegatedMethod(...args) {
|
|
8
|
+
return Ember[method](this, ...args);
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
const EmberObjectArrayExtension = {
|
|
12
|
+
kind: 'array',
|
|
13
|
+
name: 'ember-object',
|
|
14
|
+
features: EmberObjectFeatures
|
|
15
|
+
};
|
|
16
|
+
const EmberObjectExtension = {
|
|
17
|
+
kind: 'object',
|
|
18
|
+
name: 'ember-object',
|
|
19
|
+
features: EmberObjectFeatures
|
|
20
|
+
};
|
|
21
|
+
const EmberArrayLikeFeatures = {
|
|
22
|
+
addObject(obj) {
|
|
23
|
+
const index = this.indexOf(obj);
|
|
24
|
+
if (index === -1) {
|
|
25
|
+
this.push(obj);
|
|
26
|
+
}
|
|
27
|
+
return this;
|
|
28
|
+
},
|
|
29
|
+
addObjects(objs) {
|
|
30
|
+
objs.forEach(obj => {
|
|
31
|
+
const index = this.indexOf(obj);
|
|
32
|
+
if (index === -1) {
|
|
33
|
+
this.push(obj);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return this;
|
|
37
|
+
},
|
|
38
|
+
popObject() {
|
|
39
|
+
return this.pop();
|
|
40
|
+
},
|
|
41
|
+
pushObject(obj) {
|
|
42
|
+
this.push(obj);
|
|
43
|
+
return obj;
|
|
44
|
+
},
|
|
45
|
+
pushObjects(objs) {
|
|
46
|
+
this.push(...objs);
|
|
47
|
+
return this;
|
|
48
|
+
},
|
|
49
|
+
shiftObject() {
|
|
50
|
+
return this.shift();
|
|
51
|
+
},
|
|
52
|
+
unshiftObject(obj) {
|
|
53
|
+
this.unshift(obj);
|
|
54
|
+
return obj;
|
|
55
|
+
},
|
|
56
|
+
unshiftObjects(objs) {
|
|
57
|
+
this.unshift(...objs);
|
|
58
|
+
return this;
|
|
59
|
+
},
|
|
60
|
+
objectAt(index) {
|
|
61
|
+
//For negative index values go back from the end of the array
|
|
62
|
+
const arrIndex = Math.sign(index) === -1 ? this.length + index : index;
|
|
63
|
+
return this[arrIndex];
|
|
64
|
+
},
|
|
65
|
+
objectsAt(indices) {
|
|
66
|
+
// @ts-expect-error adding MutableArray method
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
68
|
+
return indices.map(index => this.objectAt(index));
|
|
69
|
+
},
|
|
70
|
+
removeAt(index) {
|
|
71
|
+
this.splice(index, 1);
|
|
72
|
+
return this;
|
|
73
|
+
},
|
|
74
|
+
insertAt(index, obj) {
|
|
75
|
+
this.splice(index, 0, obj);
|
|
76
|
+
return this;
|
|
77
|
+
},
|
|
78
|
+
removeObject(obj) {
|
|
79
|
+
const index = this.indexOf(obj);
|
|
80
|
+
if (index !== -1) {
|
|
81
|
+
this.splice(index, 1);
|
|
82
|
+
}
|
|
83
|
+
return this;
|
|
84
|
+
},
|
|
85
|
+
removeObjects(objs) {
|
|
86
|
+
objs.forEach(obj => {
|
|
87
|
+
const index = this.indexOf(obj);
|
|
88
|
+
if (index !== -1) {
|
|
89
|
+
this.splice(index, 1);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return this;
|
|
93
|
+
},
|
|
94
|
+
toArray() {
|
|
95
|
+
return this.slice();
|
|
96
|
+
},
|
|
97
|
+
replace(idx, amt, objects) {
|
|
98
|
+
if (objects) {
|
|
99
|
+
this.splice(idx, amt, ...objects);
|
|
100
|
+
} else {
|
|
101
|
+
this.splice(idx, amt);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
clear() {
|
|
105
|
+
this.splice(0, this.length);
|
|
106
|
+
return this;
|
|
107
|
+
},
|
|
108
|
+
setObjects(objects) {
|
|
109
|
+
this.splice(0, this.length);
|
|
110
|
+
this.push(...objects);
|
|
111
|
+
return this;
|
|
112
|
+
},
|
|
113
|
+
reverseObjects() {
|
|
114
|
+
this.reverse();
|
|
115
|
+
return this;
|
|
116
|
+
},
|
|
117
|
+
compact() {
|
|
118
|
+
return this.filter(v => v !== null && v !== undefined);
|
|
119
|
+
},
|
|
120
|
+
any(callback, target) {
|
|
121
|
+
return this.some(callback, target);
|
|
122
|
+
},
|
|
123
|
+
isAny(prop, value) {
|
|
124
|
+
const hasValue = arguments.length === 2;
|
|
125
|
+
return this.some(v => hasValue ? v[prop] === value : v[prop] === true);
|
|
126
|
+
},
|
|
127
|
+
isEvery(prop, value) {
|
|
128
|
+
const hasValue = arguments.length === 2;
|
|
129
|
+
return this.every(v => hasValue ? v[prop] === value : v[prop] === true);
|
|
130
|
+
},
|
|
131
|
+
getEach(key) {
|
|
132
|
+
return this.map(value => get(value, key));
|
|
133
|
+
},
|
|
134
|
+
mapBy(key) {
|
|
135
|
+
return this.map(value => get(value, key));
|
|
136
|
+
},
|
|
137
|
+
findBy(key, value) {
|
|
138
|
+
if (arguments.length === 2) {
|
|
139
|
+
return this.find(val => {
|
|
140
|
+
return get(val, key) === value;
|
|
141
|
+
});
|
|
142
|
+
} else {
|
|
143
|
+
return this.find(val => Boolean(get(val, key)));
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
filterBy(key, value) {
|
|
147
|
+
if (arguments.length === 2) {
|
|
148
|
+
return this.filter(record => {
|
|
149
|
+
return get(record, key) === value;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return this.filter(record => {
|
|
153
|
+
return Boolean(get(record, key));
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
sortBy(...sortKeys) {
|
|
157
|
+
return this.slice().sort((a, b) => {
|
|
158
|
+
for (let i = 0; i < sortKeys.length; i++) {
|
|
159
|
+
const key = sortKeys[i];
|
|
160
|
+
const propA = get(a, key);
|
|
161
|
+
const propB = get(b, key);
|
|
162
|
+
// return 1 or -1 else continue to the next sortKey
|
|
163
|
+
const compareValue = compare(propA, propB);
|
|
164
|
+
if (compareValue) {
|
|
165
|
+
return compareValue;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return 0;
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
invoke(key, ...args) {
|
|
172
|
+
return this.map(value => value[key](...args));
|
|
173
|
+
},
|
|
174
|
+
addArrayObserver() {},
|
|
175
|
+
removeArrayObserver() {},
|
|
176
|
+
arrayContentWillChange() {},
|
|
177
|
+
arrayContentDidChange() {},
|
|
178
|
+
reject(callback, target) {
|
|
179
|
+
return this.filter((...args) => {
|
|
180
|
+
return !callback.apply(target, args);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
rejectBy(key, value) {
|
|
184
|
+
if (arguments.length === 2) {
|
|
185
|
+
return this.filter(record => {
|
|
186
|
+
return get(record, key) !== value;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return this.filter(record => {
|
|
190
|
+
return !get(record, key);
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
setEach(key, value) {
|
|
194
|
+
this.forEach(item => set(item, key, value));
|
|
195
|
+
},
|
|
196
|
+
uniq() {
|
|
197
|
+
return Array.from(new Set(this));
|
|
198
|
+
},
|
|
199
|
+
uniqBy(key) {
|
|
200
|
+
const seen = new Set();
|
|
201
|
+
const result = [];
|
|
202
|
+
this.forEach(item => {
|
|
203
|
+
const value = get(item, key);
|
|
204
|
+
if (seen.has(value)) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
seen.add(value);
|
|
208
|
+
result.push(item);
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
},
|
|
212
|
+
without(value) {
|
|
213
|
+
const newArr = this.slice();
|
|
214
|
+
const index = this.indexOf(value);
|
|
215
|
+
if (index !== -1) {
|
|
216
|
+
newArr.splice(index, 1);
|
|
217
|
+
}
|
|
218
|
+
return newArr;
|
|
219
|
+
},
|
|
220
|
+
get firstObject() {
|
|
221
|
+
return this.at(0);
|
|
222
|
+
},
|
|
223
|
+
get lastObject() {
|
|
224
|
+
return this.at(-1);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const EmberArrayLikeExtension = {
|
|
228
|
+
kind: 'array',
|
|
229
|
+
name: 'ember-array-like',
|
|
230
|
+
features: EmberArrayLikeFeatures
|
|
231
|
+
};
|
|
232
|
+
export { EmberArrayLikeExtension, EmberObjectArrayExtension, EmberObjectExtension };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { singularize, dasherize } from '@warp-drive/utilities/string';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Utilities for helping to migrate to stricter
|
|
5
|
+
and more consistent use of IDs and types.
|
|
6
|
+
|
|
7
|
+
@module
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
let MismatchReporter = function () {};
|
|
11
|
+
|
|
12
|
+
// TODO: @runspired This pattern prevents AssertFn from being removed in production builds
|
|
13
|
+
// but we should enable that if we can.
|
|
14
|
+
let _AssertFn = function () {};
|
|
15
|
+
const AssertFn = (message, condition) => {
|
|
16
|
+
if (!condition) {
|
|
17
|
+
_AssertFn(message, condition);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
let NormalizedType = str => {
|
|
21
|
+
return singularize(dasherize(str));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Configure a function to be called when an id or type
|
|
26
|
+
* changes during normalization. This is useful for instrumenting
|
|
27
|
+
* to discover places where usage in the app is not consistent.
|
|
28
|
+
*
|
|
29
|
+
* @param fn - a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
function configureMismatchReporter(fn) {
|
|
33
|
+
MismatchReporter = fn;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Configure a function to be called when an id or type
|
|
38
|
+
* fails validation. This is useful for instrumenting
|
|
39
|
+
* to discover places where usage in the app is not consistent.
|
|
40
|
+
*
|
|
41
|
+
* @param fn - a function which takes a message and a condition
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
function configureAssertFn(fn) {
|
|
45
|
+
_AssertFn = fn;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Configure a function to be called to normalize
|
|
50
|
+
* a resource type string. Used by both formattedType
|
|
51
|
+
* and isEquivType to ensure consistent normalization
|
|
52
|
+
* during comparison.
|
|
53
|
+
*
|
|
54
|
+
* If validation fails or the type turns out be unnormalized
|
|
55
|
+
* the configured mismatch reporter and assert functions will
|
|
56
|
+
* be called.
|
|
57
|
+
*
|
|
58
|
+
* @param fn - a function which takes a string and returns a string
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
function configureTypeNormalization(fn) {
|
|
62
|
+
NormalizedType = fn;
|
|
63
|
+
}
|
|
64
|
+
const NORMALIZED_TYPES = new Map();
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Converts a potentially unnormalized type into the format expected
|
|
68
|
+
* by our WarpDrive Cache. Currently this is singular-dasherized.
|
|
69
|
+
*
|
|
70
|
+
* you should not rely on this function to give you an exact format
|
|
71
|
+
* for display purposes. Formatting for display should be handled
|
|
72
|
+
* differently if the exact format matters.
|
|
73
|
+
*
|
|
74
|
+
* Asserts invalid types (undefined, null, '') in dev.
|
|
75
|
+
*
|
|
76
|
+
* **Usage**
|
|
77
|
+
*
|
|
78
|
+
* ```js
|
|
79
|
+
* import formattedType from 'soxhub-client/helpers/formatted-type';
|
|
80
|
+
*
|
|
81
|
+
* formattedType('post'); // => 'post'
|
|
82
|
+
* formattedType('posts'); // => 'post'
|
|
83
|
+
* formattedType('Posts'); // => 'post'
|
|
84
|
+
* formattedType('post-comment'); // => 'post-comment'
|
|
85
|
+
* formattedType('post-comments'); // => 'post-comment'
|
|
86
|
+
* formattedType('post_comment'); // => 'post-comment'
|
|
87
|
+
* formattedType('postComment'); // => 'post-comment'
|
|
88
|
+
* formattedType('PostComment'); // => 'post-comment'
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @param type the potentially un-normalized type
|
|
92
|
+
* @return the normalized type
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
function formattedType(type) {
|
|
96
|
+
AssertFn('formattedType: type must not be null', type !== null);
|
|
97
|
+
AssertFn('formattedType: type must not be undefined', type !== undefined);
|
|
98
|
+
AssertFn('formattedType: type must be a string', typeof type === 'string');
|
|
99
|
+
AssertFn('formattedType: type must not be empty', type.length > 0);
|
|
100
|
+
let normalized = NORMALIZED_TYPES.get(type);
|
|
101
|
+
if (normalized === undefined) {
|
|
102
|
+
normalized = NormalizedType(type);
|
|
103
|
+
NORMALIZED_TYPES.set(type, normalized);
|
|
104
|
+
}
|
|
105
|
+
if (normalized !== type) {
|
|
106
|
+
MismatchReporter('formatted-type', type, normalized);
|
|
107
|
+
}
|
|
108
|
+
return normalized;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Format an id to the format expected by the WarpDrive Cache.
|
|
113
|
+
* Currently this means that id should be `string | null`.
|
|
114
|
+
*
|
|
115
|
+
* Asserts invalid IDs (undefined, '', 0, '0') in dev.
|
|
116
|
+
*
|
|
117
|
+
* **Usage**
|
|
118
|
+
*
|
|
119
|
+
* ```js
|
|
120
|
+
* import formattedId from 'client/utils/formatted-id';
|
|
121
|
+
*
|
|
122
|
+
* formattedId('1'); // => '1'
|
|
123
|
+
* formattedId(1); // => '1'
|
|
124
|
+
* formattedId(null); // => null
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* @param id the potentially un-normalized id
|
|
128
|
+
* @return the normalized id
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
function formattedId(id) {
|
|
133
|
+
AssertFn('formattedId: id must not be undefined', id !== undefined);
|
|
134
|
+
AssertFn('formattedId: id must be a number, string or null', typeof id === 'number' || typeof id === 'string' || id === null);
|
|
135
|
+
AssertFn('formattedId: id must not be empty', typeof id === 'number' || id === null || typeof id === 'string' && id.length > 0);
|
|
136
|
+
AssertFn('formattedId: id must not be 0', id !== '0' && id !== 0);
|
|
137
|
+
const formatted = id === null ? null : String(id);
|
|
138
|
+
if (formatted !== id) {
|
|
139
|
+
MismatchReporter('formatted-id', id, formatted);
|
|
140
|
+
}
|
|
141
|
+
return id === null ? null : String(id);
|
|
142
|
+
}
|
|
143
|
+
function expectId(id) {
|
|
144
|
+
AssertFn('expectId: id must not be null', id !== null);
|
|
145
|
+
return formattedId(id);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Compares two types for strict equality, converting them to
|
|
150
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
151
|
+
* differences in format are accounted for in the comparison.
|
|
152
|
+
*
|
|
153
|
+
* Asserts when expected or actual are invalid types in dev.
|
|
154
|
+
* Expected may never be null.
|
|
155
|
+
*
|
|
156
|
+
* ```js
|
|
157
|
+
* isEquivType('posts', 'post'); // true
|
|
158
|
+
* isEquivType('post', 'post'); // true
|
|
159
|
+
* isEquivType('posts', 'posts'); // true
|
|
160
|
+
* isEquivType('post-comment', 'postComment'); // true
|
|
161
|
+
* isEquivType('post-comment', 'PostComment'); // true
|
|
162
|
+
* isEquivType('post-comment', 'post_comment'); // true
|
|
163
|
+
* isEquivType('post-comment', 'post-comment'); // true
|
|
164
|
+
* isEquivType('post-comment', 'post'); // false
|
|
165
|
+
* isEquivType('posts', null); // false
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @param expected a potentially unnormalized type to match against
|
|
169
|
+
* @param actual a potentially unnormalized type to match against
|
|
170
|
+
* @return true if the types are equivalent
|
|
171
|
+
* @public
|
|
172
|
+
*/
|
|
173
|
+
function isEquivType(expected, actual) {
|
|
174
|
+
AssertFn('isEquivType: Expected type must not be null', expected !== null);
|
|
175
|
+
AssertFn('isEquivType: Expected type must not be undefined', expected !== undefined);
|
|
176
|
+
AssertFn('isEquivType: Expected type must be a string', typeof expected === 'string');
|
|
177
|
+
AssertFn('isEquivType: Expected type must not be empty', expected.length > 0);
|
|
178
|
+
AssertFn('isEquivType: Actual type must not be null', actual !== null);
|
|
179
|
+
AssertFn('isEquivType: Actual type must not be undefined', actual !== undefined);
|
|
180
|
+
AssertFn('isEquivType: Actual type must be a string', typeof actual === 'string');
|
|
181
|
+
AssertFn('isEquivType: Actual type must not be empty', actual.length > 0);
|
|
182
|
+
return expected === actual || formattedType(expected) === formattedType(actual);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Compares two IDs for strict equality, converting them to
|
|
187
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
188
|
+
* differences in format are accounted for in the comparison.
|
|
189
|
+
*
|
|
190
|
+
* Asserts when expected or actual are invalid IDs in dev.
|
|
191
|
+
* Expected may never be null.
|
|
192
|
+
*
|
|
193
|
+
* ```js
|
|
194
|
+
* isEquivId('1', 1); // true
|
|
195
|
+
* isEquivId('2', '2'); // true
|
|
196
|
+
* isEquivId(3, '3'); // true
|
|
197
|
+
* isEquivId(4, '3'); // false
|
|
198
|
+
* isEquivId(1, null); // false
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @param expected a potentially un-normalized id to match against
|
|
202
|
+
* @param actual a potentially un-normalized id to match against
|
|
203
|
+
* @return true if the ids are equivalent
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
function isEquivId(expected, actual) {
|
|
207
|
+
AssertFn('isEquivId: Expected id must not be null', expected !== null);
|
|
208
|
+
AssertFn('isEquivId: Expected id must not be undefined', expected !== undefined);
|
|
209
|
+
AssertFn('isEquivId: Expected id must be a number or string', typeof expected === 'number' || typeof expected === 'string');
|
|
210
|
+
AssertFn('isEquivId: Expected id must not be empty', typeof expected === 'number' || typeof expected === 'string' && expected.length > 0);
|
|
211
|
+
AssertFn('isEquivId: Expected id must not be 0', expected !== '0' && expected !== 0);
|
|
212
|
+
AssertFn('isEquivId: Actual id must not be undefined', actual !== undefined);
|
|
213
|
+
AssertFn('isEquivId: Actual id must be a number, string or null', typeof actual === 'number' || typeof actual === 'string' || actual === null);
|
|
214
|
+
AssertFn('isEquivId: Actual id must not be empty', actual === null || typeof actual === 'number' || typeof actual === 'string' && actual.length > 0);
|
|
215
|
+
AssertFn('isEquivId: Actual id must not be 0', actual !== '0' && actual !== 0);
|
|
216
|
+
return expected === actual || formattedId(expected) === formattedId(actual);
|
|
217
|
+
}
|
|
218
|
+
export { configureAssertFn, configureMismatchReporter, configureTypeNormalization, expectId, formattedId, formattedType, isEquivId, isEquivType };
|