@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,223 @@
|
|
|
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
|
+
(test => {
|
|
20
|
+
if (!test) {
|
|
21
|
+
throw new Error(message);
|
|
22
|
+
}
|
|
23
|
+
})(condition);
|
|
24
|
+
};
|
|
25
|
+
let NormalizedType = str => {
|
|
26
|
+
return singularize(dasherize(str));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Configure a function to be called when an id or type
|
|
31
|
+
* changes during normalization. This is useful for instrumenting
|
|
32
|
+
* to discover places where usage in the app is not consistent.
|
|
33
|
+
*
|
|
34
|
+
* @param fn - a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
function configureMismatchReporter(fn) {
|
|
38
|
+
MismatchReporter = fn;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Configure a function to be called when an id or type
|
|
43
|
+
* fails validation. This is useful for instrumenting
|
|
44
|
+
* to discover places where usage in the app is not consistent.
|
|
45
|
+
*
|
|
46
|
+
* @param fn - a function which takes a message and a condition
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
function configureAssertFn(fn) {
|
|
50
|
+
_AssertFn = fn;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Configure a function to be called to normalize
|
|
55
|
+
* a resource type string. Used by both formattedType
|
|
56
|
+
* and isEquivType to ensure consistent normalization
|
|
57
|
+
* during comparison.
|
|
58
|
+
*
|
|
59
|
+
* If validation fails or the type turns out be unnormalized
|
|
60
|
+
* the configured mismatch reporter and assert functions will
|
|
61
|
+
* be called.
|
|
62
|
+
*
|
|
63
|
+
* @param fn - a function which takes a string and returns a string
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
function configureTypeNormalization(fn) {
|
|
67
|
+
NormalizedType = fn;
|
|
68
|
+
}
|
|
69
|
+
const NORMALIZED_TYPES = new Map();
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts a potentially unnormalized type into the format expected
|
|
73
|
+
* by our WarpDrive Cache. Currently this is singular-dasherized.
|
|
74
|
+
*
|
|
75
|
+
* you should not rely on this function to give you an exact format
|
|
76
|
+
* for display purposes. Formatting for display should be handled
|
|
77
|
+
* differently if the exact format matters.
|
|
78
|
+
*
|
|
79
|
+
* Asserts invalid types (undefined, null, '') in dev.
|
|
80
|
+
*
|
|
81
|
+
* **Usage**
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* import formattedType from 'soxhub-client/helpers/formatted-type';
|
|
85
|
+
*
|
|
86
|
+
* formattedType('post'); // => 'post'
|
|
87
|
+
* formattedType('posts'); // => 'post'
|
|
88
|
+
* formattedType('Posts'); // => 'post'
|
|
89
|
+
* formattedType('post-comment'); // => 'post-comment'
|
|
90
|
+
* formattedType('post-comments'); // => 'post-comment'
|
|
91
|
+
* formattedType('post_comment'); // => 'post-comment'
|
|
92
|
+
* formattedType('postComment'); // => 'post-comment'
|
|
93
|
+
* formattedType('PostComment'); // => 'post-comment'
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @param type the potentially un-normalized type
|
|
97
|
+
* @return the normalized type
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
function formattedType(type) {
|
|
101
|
+
AssertFn('formattedType: type must not be null', type !== null);
|
|
102
|
+
AssertFn('formattedType: type must not be undefined', type !== undefined);
|
|
103
|
+
AssertFn('formattedType: type must be a string', typeof type === 'string');
|
|
104
|
+
AssertFn('formattedType: type must not be empty', type.length > 0);
|
|
105
|
+
let normalized = NORMALIZED_TYPES.get(type);
|
|
106
|
+
if (normalized === undefined) {
|
|
107
|
+
normalized = NormalizedType(type);
|
|
108
|
+
NORMALIZED_TYPES.set(type, normalized);
|
|
109
|
+
}
|
|
110
|
+
if (normalized !== type) {
|
|
111
|
+
MismatchReporter('formatted-type', type, normalized);
|
|
112
|
+
}
|
|
113
|
+
return normalized;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Format an id to the format expected by the WarpDrive Cache.
|
|
118
|
+
* Currently this means that id should be `string | null`.
|
|
119
|
+
*
|
|
120
|
+
* Asserts invalid IDs (undefined, '', 0, '0') in dev.
|
|
121
|
+
*
|
|
122
|
+
* **Usage**
|
|
123
|
+
*
|
|
124
|
+
* ```js
|
|
125
|
+
* import formattedId from 'client/utils/formatted-id';
|
|
126
|
+
*
|
|
127
|
+
* formattedId('1'); // => '1'
|
|
128
|
+
* formattedId(1); // => '1'
|
|
129
|
+
* formattedId(null); // => null
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param id the potentially un-normalized id
|
|
133
|
+
* @return the normalized id
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
function formattedId(id) {
|
|
138
|
+
AssertFn('formattedId: id must not be undefined', id !== undefined);
|
|
139
|
+
AssertFn('formattedId: id must be a number, string or null', typeof id === 'number' || typeof id === 'string' || id === null);
|
|
140
|
+
AssertFn('formattedId: id must not be empty', typeof id === 'number' || id === null || typeof id === 'string' && id.length > 0);
|
|
141
|
+
AssertFn('formattedId: id must not be 0', id !== '0' && id !== 0);
|
|
142
|
+
const formatted = id === null ? null : String(id);
|
|
143
|
+
if (formatted !== id) {
|
|
144
|
+
MismatchReporter('formatted-id', id, formatted);
|
|
145
|
+
}
|
|
146
|
+
return id === null ? null : String(id);
|
|
147
|
+
}
|
|
148
|
+
function expectId(id) {
|
|
149
|
+
AssertFn('expectId: id must not be null', id !== null);
|
|
150
|
+
return formattedId(id);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Compares two types for strict equality, converting them to
|
|
155
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
156
|
+
* differences in format are accounted for in the comparison.
|
|
157
|
+
*
|
|
158
|
+
* Asserts when expected or actual are invalid types in dev.
|
|
159
|
+
* Expected may never be null.
|
|
160
|
+
*
|
|
161
|
+
* ```js
|
|
162
|
+
* isEquivType('posts', 'post'); // true
|
|
163
|
+
* isEquivType('post', 'post'); // true
|
|
164
|
+
* isEquivType('posts', 'posts'); // true
|
|
165
|
+
* isEquivType('post-comment', 'postComment'); // true
|
|
166
|
+
* isEquivType('post-comment', 'PostComment'); // true
|
|
167
|
+
* isEquivType('post-comment', 'post_comment'); // true
|
|
168
|
+
* isEquivType('post-comment', 'post-comment'); // true
|
|
169
|
+
* isEquivType('post-comment', 'post'); // false
|
|
170
|
+
* isEquivType('posts', null); // false
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @param expected a potentially unnormalized type to match against
|
|
174
|
+
* @param actual a potentially unnormalized type to match against
|
|
175
|
+
* @return true if the types are equivalent
|
|
176
|
+
* @public
|
|
177
|
+
*/
|
|
178
|
+
function isEquivType(expected, actual) {
|
|
179
|
+
AssertFn('isEquivType: Expected type must not be null', expected !== null);
|
|
180
|
+
AssertFn('isEquivType: Expected type must not be undefined', expected !== undefined);
|
|
181
|
+
AssertFn('isEquivType: Expected type must be a string', typeof expected === 'string');
|
|
182
|
+
AssertFn('isEquivType: Expected type must not be empty', expected.length > 0);
|
|
183
|
+
AssertFn('isEquivType: Actual type must not be null', actual !== null);
|
|
184
|
+
AssertFn('isEquivType: Actual type must not be undefined', actual !== undefined);
|
|
185
|
+
AssertFn('isEquivType: Actual type must be a string', typeof actual === 'string');
|
|
186
|
+
AssertFn('isEquivType: Actual type must not be empty', actual.length > 0);
|
|
187
|
+
return expected === actual || formattedType(expected) === formattedType(actual);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Compares two IDs for strict equality, converting them to
|
|
192
|
+
* the format expected by the WarpDrive Cache to ensure
|
|
193
|
+
* differences in format are accounted for in the comparison.
|
|
194
|
+
*
|
|
195
|
+
* Asserts when expected or actual are invalid IDs in dev.
|
|
196
|
+
* Expected may never be null.
|
|
197
|
+
*
|
|
198
|
+
* ```js
|
|
199
|
+
* isEquivId('1', 1); // true
|
|
200
|
+
* isEquivId('2', '2'); // true
|
|
201
|
+
* isEquivId(3, '3'); // true
|
|
202
|
+
* isEquivId(4, '3'); // false
|
|
203
|
+
* isEquivId(1, null); // false
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @param expected a potentially un-normalized id to match against
|
|
207
|
+
* @param actual a potentially un-normalized id to match against
|
|
208
|
+
* @return true if the ids are equivalent
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
function isEquivId(expected, actual) {
|
|
212
|
+
AssertFn('isEquivId: Expected id must not be null', expected !== null);
|
|
213
|
+
AssertFn('isEquivId: Expected id must not be undefined', expected !== undefined);
|
|
214
|
+
AssertFn('isEquivId: Expected id must be a number or string', typeof expected === 'number' || typeof expected === 'string');
|
|
215
|
+
AssertFn('isEquivId: Expected id must not be empty', typeof expected === 'number' || typeof expected === 'string' && expected.length > 0);
|
|
216
|
+
AssertFn('isEquivId: Expected id must not be 0', expected !== '0' && expected !== 0);
|
|
217
|
+
AssertFn('isEquivId: Actual id must not be undefined', actual !== undefined);
|
|
218
|
+
AssertFn('isEquivId: Actual id must be a number, string or null', typeof actual === 'number' || typeof actual === 'string' || actual === null);
|
|
219
|
+
AssertFn('isEquivId: Actual id must not be empty', actual === null || typeof actual === 'number' || typeof actual === 'string' && actual.length > 0);
|
|
220
|
+
AssertFn('isEquivId: Actual id must not be 0', actual !== '0' && actual !== 0);
|
|
221
|
+
return expected === actual || formattedId(expected) === formattedId(actual);
|
|
222
|
+
}
|
|
223
|
+
export { configureAssertFn, configureMismatchReporter, configureTypeNormalization, expectId, formattedId, formattedType, isEquivId, isEquivType };
|