@ember-data/legacy-compat 5.4.0-alpha.52 → 5.4.0-alpha.54
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/addon/builders.js +274 -0
- package/addon/builders.js.map +1 -0
- package/addon/index.js +1 -0
- package/addon/index.js.map +1 -1
- package/addon/utils.js +246 -0
- package/addon/utils.js.map +1 -0
- package/package.json +28 -23
- package/unstable-preview-types/builders/find-all.d.ts +36 -0
- package/unstable-preview-types/builders/find-all.d.ts.map +1 -0
- package/unstable-preview-types/builders/find-record.d.ts +57 -0
- package/unstable-preview-types/builders/find-record.d.ts.map +1 -0
- package/unstable-preview-types/builders/query.d.ts +66 -0
- package/unstable-preview-types/builders/query.d.ts.map +1 -0
- package/unstable-preview-types/builders/save-record.d.ts +35 -0
- package/unstable-preview-types/builders/save-record.d.ts.map +1 -0
- package/unstable-preview-types/builders/utils.d.ts +6 -0
- package/unstable-preview-types/builders/utils.d.ts.map +1 -0
- package/unstable-preview-types/builders.d.ts +18 -0
- package/unstable-preview-types/builders.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +7 -0
- package/unstable-preview-types/utils.d.ts +159 -0
- package/unstable-preview-types/utils.d.ts.map +1 -0
package/addon/utils.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { dasherize } from '@ember/string';
|
|
2
|
+
import { macroCondition, dependencySatisfies, importSync, getOwnConfig } from '@embroider/macros';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Utilities for helping to migrate to stricter
|
|
6
|
+
and more consistent use of IDs and types.
|
|
7
|
+
|
|
8
|
+
@module @ember-data/legacy-compat/utils
|
|
9
|
+
@main @ember-data/legacy-compat/utils
|
|
10
|
+
@deprecated
|
|
11
|
+
*/
|
|
12
|
+
let singularize;
|
|
13
|
+
if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {
|
|
14
|
+
singularize = importSync('ember-inflector').singularize;
|
|
15
|
+
}
|
|
16
|
+
let MismatchReporter = function () {};
|
|
17
|
+
|
|
18
|
+
// TODO: @runspired This pattern prevents AssertFn from being removed in production builds
|
|
19
|
+
// but we should enable that if we can.
|
|
20
|
+
let _AssertFn = function () {};
|
|
21
|
+
const AssertFn = (message, condition) => {
|
|
22
|
+
if (!condition) {
|
|
23
|
+
_AssertFn(message, condition);
|
|
24
|
+
}
|
|
25
|
+
if (macroCondition(getOwnConfig().env.DEBUG)) {
|
|
26
|
+
if (!condition) {
|
|
27
|
+
throw new Error(`Assertion Failed: ${message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
let NormalizedType = str => {
|
|
32
|
+
return singularize(dasherize(str));
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configure a function to be called when an id or type
|
|
37
|
+
* changes during normalization. This is useful for instrumenting
|
|
38
|
+
* to discover places where usage in the app is not consistent.
|
|
39
|
+
*
|
|
40
|
+
* @method configureMismatchReporter
|
|
41
|
+
* @for @ember-data/legacy-compat/utils
|
|
42
|
+
* @param method a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
|
|
43
|
+
* @public
|
|
44
|
+
* @static
|
|
45
|
+
*/
|
|
46
|
+
function configureMismatchReporter(fn) {
|
|
47
|
+
MismatchReporter = fn;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Configure a function to be called when an id or type
|
|
52
|
+
* fails validation. This is useful for instrumenting
|
|
53
|
+
* to discover places where usage in the app is not consistent.
|
|
54
|
+
*
|
|
55
|
+
* @method configureAssertFn
|
|
56
|
+
* @for @ember-data/legacy-compat/utils
|
|
57
|
+
* @param method a function which takes a message and a condition
|
|
58
|
+
* @public
|
|
59
|
+
* @static
|
|
60
|
+
*/
|
|
61
|
+
function configureAssertFn(fn) {
|
|
62
|
+
_AssertFn = fn;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Configure a function to be called to normalize
|
|
67
|
+
* a resource type string. Used by both formattedType
|
|
68
|
+
* and isEquivType to ensure consistent normalization
|
|
69
|
+
* during comparison.
|
|
70
|
+
*
|
|
71
|
+
* If validation fails or the type turns out be unnormalized
|
|
72
|
+
* the configured mismatch reporter and assert functions will
|
|
73
|
+
* be called.
|
|
74
|
+
*
|
|
75
|
+
* @method configureTypeNormalization
|
|
76
|
+
* @for @ember-data/legacy-compat/utils
|
|
77
|
+
* @param method a function which takes a string and returns a string
|
|
78
|
+
* @public
|
|
79
|
+
* @static
|
|
80
|
+
*/
|
|
81
|
+
function configureTypeNormalization(fn) {
|
|
82
|
+
NormalizedType = fn;
|
|
83
|
+
}
|
|
84
|
+
const NORMALIZED_TYPES = new Map();
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Converts a potentially unnormalized type into the format expected
|
|
88
|
+
* by our EmberData Cache. Currently this is singular-dasherized.
|
|
89
|
+
*
|
|
90
|
+
* you should not rely on this function to give you an exact format
|
|
91
|
+
* for display purposes. Formatting for display should be handled
|
|
92
|
+
* differently if the exact format matters.
|
|
93
|
+
*
|
|
94
|
+
* Asserts invalid types (undefined, null, '') in dev.
|
|
95
|
+
*
|
|
96
|
+
* **Usage**
|
|
97
|
+
*
|
|
98
|
+
* ```js
|
|
99
|
+
* import formattedType from 'soxhub-client/helpers/formatted-type';
|
|
100
|
+
*
|
|
101
|
+
* formattedType('post'); // => 'post'
|
|
102
|
+
* formattedType('posts'); // => 'post'
|
|
103
|
+
* formattedType('Posts'); // => 'post'
|
|
104
|
+
* formattedType('post-comment'); // => 'post-comment'
|
|
105
|
+
* formattedType('post-comments'); // => 'post-comment'
|
|
106
|
+
* formattedType('post_comment'); // => 'post-comment'
|
|
107
|
+
* formattedType('postComment'); // => 'post-comment'
|
|
108
|
+
* formattedType('PostComment'); // => 'post-comment'
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @method formattedType
|
|
112
|
+
* @for @ember-data/legacy-compat/utils
|
|
113
|
+
* @param {string} type the potentially un-normalized type
|
|
114
|
+
* @return {string} the normalized type
|
|
115
|
+
* @public
|
|
116
|
+
* @static
|
|
117
|
+
*/
|
|
118
|
+
function formattedType(type) {
|
|
119
|
+
AssertFn('formattedType: type must not be null', type !== null);
|
|
120
|
+
AssertFn('formattedType: type must not be undefined', type !== undefined);
|
|
121
|
+
AssertFn('formattedType: type must be a string', typeof type === 'string');
|
|
122
|
+
AssertFn('formattedType: type must not be empty', type.length > 0);
|
|
123
|
+
let normalized = NORMALIZED_TYPES.get(type);
|
|
124
|
+
if (normalized === undefined) {
|
|
125
|
+
normalized = NormalizedType(type);
|
|
126
|
+
NORMALIZED_TYPES.set(type, normalized);
|
|
127
|
+
}
|
|
128
|
+
if (normalized !== type) {
|
|
129
|
+
MismatchReporter('formatted-type', type, normalized);
|
|
130
|
+
}
|
|
131
|
+
return normalized;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Format an id to the format expected by the EmberData Cache.
|
|
136
|
+
* Currently this means that id should be `string | null`.
|
|
137
|
+
*
|
|
138
|
+
* Asserts invalid IDs (undefined, '', 0, '0') in dev.
|
|
139
|
+
*
|
|
140
|
+
* **Usage**
|
|
141
|
+
*
|
|
142
|
+
* ```js
|
|
143
|
+
* import formattedId from 'client/utils/formatted-id';
|
|
144
|
+
*
|
|
145
|
+
* formattedId('1'); // => '1'
|
|
146
|
+
* formattedId(1); // => '1'
|
|
147
|
+
* formattedId(null); // => null
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @method formattedId
|
|
151
|
+
* @for @ember-data/legacy-compat/utils
|
|
152
|
+
* @param {string | number | null} id the potentially un-normalized id
|
|
153
|
+
* @return {string | null} the normalized id
|
|
154
|
+
* @public
|
|
155
|
+
* @static
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
function formattedId(id) {
|
|
159
|
+
AssertFn('formattedId: id must not be undefined', id !== undefined);
|
|
160
|
+
AssertFn('formattedId: id must be a number, string or null', typeof id === 'number' || typeof id === 'string' || id === null);
|
|
161
|
+
AssertFn('formattedId: id must not be empty', typeof id === 'number' || id === null || typeof id === 'string' && id.length > 0);
|
|
162
|
+
AssertFn('formattedId: id must not be 0', id !== '0' && id !== 0);
|
|
163
|
+
const formatted = id === null ? null : String(id);
|
|
164
|
+
if (formatted !== id) {
|
|
165
|
+
MismatchReporter('formatted-id', id, formatted);
|
|
166
|
+
}
|
|
167
|
+
return id === null ? null : String(id);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Compares two types for strict equality, converting them to
|
|
172
|
+
* the format expected by the EmberData Cache to ensure
|
|
173
|
+
* differences in format are accounted for in the comparison.
|
|
174
|
+
*
|
|
175
|
+
* Asserts when expected or actual are invalid types in dev.
|
|
176
|
+
* Expected may never be null.
|
|
177
|
+
*
|
|
178
|
+
* ```js
|
|
179
|
+
* isEquivType('posts', 'post'); // true
|
|
180
|
+
* isEquivType('post', 'post'); // true
|
|
181
|
+
* isEquivType('posts', 'posts'); // true
|
|
182
|
+
* isEquivType('post-comment', 'postComment'); // true
|
|
183
|
+
* isEquivType('post-comment', 'PostComment'); // true
|
|
184
|
+
* isEquivType('post-comment', 'post_comment'); // true
|
|
185
|
+
* isEquivType('post-comment', 'post-comment'); // true
|
|
186
|
+
* isEquivType('post-comment', 'post'); // false
|
|
187
|
+
* isEquivType('posts', null); // false
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @method isEquivType
|
|
191
|
+
* @for @ember-data/legacy-compat/utils
|
|
192
|
+
* @param {string} expected a potentially unnormalized type to match against
|
|
193
|
+
* @param {string} actual a potentially unnormalized type to match against
|
|
194
|
+
* @return {boolean} true if the types are equivalent
|
|
195
|
+
* @public
|
|
196
|
+
* @static
|
|
197
|
+
*/
|
|
198
|
+
function isEquivType(expected, actual) {
|
|
199
|
+
AssertFn('isEquivType: Expected type must not be null', expected !== null);
|
|
200
|
+
AssertFn('isEquivType: Expected type must not be undefined', expected !== undefined);
|
|
201
|
+
AssertFn('isEquivType: Expected type must be a string', typeof expected === 'string');
|
|
202
|
+
AssertFn('isEquivType: Expected type must not be empty', expected.length > 0);
|
|
203
|
+
AssertFn('isEquivType: Actual type must not be null', actual !== null);
|
|
204
|
+
AssertFn('isEquivType: Actual type must not be undefined', actual !== undefined);
|
|
205
|
+
AssertFn('isEquivType: Actual type must be a string', typeof actual === 'string');
|
|
206
|
+
AssertFn('isEquivType: Actual type must not be empty', actual.length > 0);
|
|
207
|
+
return expected === actual || formattedType(expected) === formattedType(actual);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Compares two IDs for strict equality, converting them to
|
|
212
|
+
* the format expected by the EmberData Cache to ensure
|
|
213
|
+
* differences in format are accounted for in the comparison.
|
|
214
|
+
*
|
|
215
|
+
* Asserts when expected or actual are invalid IDs in dev.
|
|
216
|
+
* Expected may never be null.
|
|
217
|
+
*
|
|
218
|
+
* ```js
|
|
219
|
+
* isEquivId('1', 1); // true
|
|
220
|
+
* isEquivId('2', '2'); // true
|
|
221
|
+
* isEquivId(3, '3'); // true
|
|
222
|
+
* isEquivId(4, '3'); // false
|
|
223
|
+
* isEquivId(1, null); // false
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @method isEquivId
|
|
227
|
+
* @for @ember-data/legacy-compat/utils
|
|
228
|
+
* @param {string | number} expected a potentially un-normalized id to match against
|
|
229
|
+
* @param {string | number} actual a potentially un-normalized id to match against
|
|
230
|
+
* @return {boolean} true if the ids are equivalent
|
|
231
|
+
* @public
|
|
232
|
+
* @static
|
|
233
|
+
*/
|
|
234
|
+
function isEquivId(expected, actual) {
|
|
235
|
+
AssertFn('isEquivId: Expected id must not be null', expected !== null);
|
|
236
|
+
AssertFn('isEquivId: Expected id must not be undefined', expected !== undefined);
|
|
237
|
+
AssertFn('isEquivId: Expected id must be a number or string', typeof expected === 'number' || typeof expected === 'string');
|
|
238
|
+
AssertFn('isEquivId: Expected id must not be empty', typeof expected === 'number' || typeof expected === 'string' && expected.length > 0);
|
|
239
|
+
AssertFn('isEquivId: Expected id must not be 0', expected !== '0' && expected !== 0);
|
|
240
|
+
AssertFn('isEquivId: Actual id must not be undefined', actual !== undefined);
|
|
241
|
+
AssertFn('isEquivId: Actual id must be a number, string or null', typeof actual === 'number' || typeof actual === 'string' || actual === null);
|
|
242
|
+
AssertFn('isEquivId: Actual id must not be empty', actual === null || typeof actual === 'number' || typeof actual === 'string' && actual.length > 0);
|
|
243
|
+
AssertFn('isEquivId: Actual id must not be 0', actual !== '0' && actual !== 0);
|
|
244
|
+
return expected === actual || formattedId(expected) === formattedId(actual);
|
|
245
|
+
}
|
|
246
|
+
export { configureAssertFn, configureMismatchReporter, configureTypeNormalization, formattedId, formattedType, isEquivId, isEquivType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["/**\n Utilities for helping to migrate to stricter\n and more consistent use of IDs and types.\n\n @module @ember-data/legacy-compat/utils\n @main @ember-data/legacy-compat/utils\n @deprecated\n*/\nimport { dasherize } from '@ember/string';\n\nimport { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';\n\nimport { DEBUG } from '@ember-data/env';\n\ninterface AssertFunc {\n (desc: string, condition: unknown): asserts condition;\n (desc: string): never;\n}\n\ntype Reporter = (type: 'formatted-id' | 'formatted-type', actual: unknown, expected: unknown) => void;\ntype Normalizer = (type: string) => string;\nlet singularize: (str: string) => string;\nif (macroCondition(dependencySatisfies('ember-inflector', '*'))) {\n singularize = (importSync('ember-inflector') as typeof import('ember-inflector')).singularize;\n}\n\nlet MismatchReporter: Reporter = function () {};\n\n// TODO: @runspired This pattern prevents AssertFn from being removed in production builds\n// but we should enable that if we can.\nlet _AssertFn: (message: string, condition: unknown) => void = function () {};\nconst AssertFn: AssertFunc = ((message: string, condition: unknown) => {\n if (!condition) {\n _AssertFn(message, condition);\n }\n if (DEBUG) {\n if (!condition) {\n throw new Error(`Assertion Failed: ${message}`);\n }\n }\n}) as unknown as AssertFunc;\nlet NormalizedType: Normalizer = (str: string) => {\n return singularize(dasherize(str));\n};\n\n/**\n * Configure a function to be called when an id or type\n * changes during normalization. This is useful for instrumenting\n * to discover places where usage in the app is not consistent.\n *\n * @method configureMismatchReporter\n * @for @ember-data/legacy-compat/utils\n * @param method a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value\n * @public\n * @static\n */\nexport function configureMismatchReporter(fn: Reporter): void {\n MismatchReporter = fn;\n}\n\n/**\n * Configure a function to be called when an id or type\n * fails validation. This is useful for instrumenting\n * to discover places where usage in the app is not consistent.\n *\n * @method configureAssertFn\n * @for @ember-data/legacy-compat/utils\n * @param method a function which takes a message and a condition\n * @public\n * @static\n */\nexport function configureAssertFn(fn: (message: string, condition: unknown) => void): void {\n _AssertFn = fn;\n}\n\n/**\n * Configure a function to be called to normalize\n * a resource type string. Used by both formattedType\n * and isEquivType to ensure consistent normalization\n * during comparison.\n *\n * If validation fails or the type turns out be unnormalized\n * the configured mismatch reporter and assert functions will\n * be called.\n *\n * @method configureTypeNormalization\n * @for @ember-data/legacy-compat/utils\n * @param method a function which takes a string and returns a string\n * @public\n * @static\n */\nexport function configureTypeNormalization(fn: (type: string) => string): void {\n NormalizedType = fn;\n}\n\nconst NORMALIZED_TYPES = new Map<string, string>();\n\n/**\n * Converts a potentially unnormalized type into the format expected\n * by our EmberData Cache. Currently this is singular-dasherized.\n *\n * you should not rely on this function to give you an exact format\n * for display purposes. Formatting for display should be handled\n * differently if the exact format matters.\n *\n * Asserts invalid types (undefined, null, '') in dev.\n *\n * **Usage**\n *\n * ```js\n * import formattedType from 'soxhub-client/helpers/formatted-type';\n *\n * formattedType('post'); // => 'post'\n * formattedType('posts'); // => 'post'\n * formattedType('Posts'); // => 'post'\n * formattedType('post-comment'); // => 'post-comment'\n * formattedType('post-comments'); // => 'post-comment'\n * formattedType('post_comment'); // => 'post-comment'\n * formattedType('postComment'); // => 'post-comment'\n * formattedType('PostComment'); // => 'post-comment'\n * ```\n *\n * @method formattedType\n * @for @ember-data/legacy-compat/utils\n * @param {string} type the potentially un-normalized type\n * @return {string} the normalized type\n * @public\n * @static\n */\nexport function formattedType<T extends string>(type: T | string): T {\n AssertFn('formattedType: type must not be null', type !== null);\n AssertFn('formattedType: type must not be undefined', type !== undefined);\n AssertFn('formattedType: type must be a string', typeof type === 'string');\n AssertFn('formattedType: type must not be empty', type.length > 0);\n let normalized = NORMALIZED_TYPES.get(type);\n\n if (normalized === undefined) {\n normalized = NormalizedType(type);\n NORMALIZED_TYPES.set(type, normalized);\n }\n\n if (normalized !== type) {\n MismatchReporter('formatted-type', type, normalized);\n }\n\n return normalized as T;\n}\n\n/**\n * Format an id to the format expected by the EmberData Cache.\n * Currently this means that id should be `string | null`.\n *\n * Asserts invalid IDs (undefined, '', 0, '0') in dev.\n *\n * **Usage**\n *\n * ```js\n * import formattedId from 'client/utils/formatted-id';\n *\n * formattedId('1'); // => '1'\n * formattedId(1); // => '1'\n * formattedId(null); // => null\n *\t```\n *\n * @method formattedId\n * @for @ember-data/legacy-compat/utils\n * @param {string | number | null} id the potentially un-normalized id\n * @return {string | null} the normalized id\n * @public\n * @static\n */\nexport function formattedId(id: string | number): string;\nexport function formattedId(id: null): null;\nexport function formattedId(id: string | number | null): string | null;\nexport function formattedId(id: string | number | null): string | null {\n AssertFn('formattedId: id must not be undefined', id !== undefined);\n AssertFn(\n 'formattedId: id must be a number, string or null',\n typeof id === 'number' || typeof id === 'string' || id === null\n );\n AssertFn(\n 'formattedId: id must not be empty',\n typeof id === 'number' || id === null || (typeof id === 'string' && id.length > 0)\n );\n AssertFn('formattedId: id must not be 0', id !== '0' && id !== 0);\n\n const formatted = id === null ? null : String(id);\n if (formatted !== id) {\n MismatchReporter('formatted-id', id, formatted);\n }\n return id === null ? null : String(id);\n}\n\n/**\n * Compares two types for strict equality, converting them to\n * the format expected by the EmberData Cache to ensure\n * differences in format are accounted for in the comparison.\n *\n * Asserts when expected or actual are invalid types in dev.\n * Expected may never be null.\n *\n * ```js\n * isEquivType('posts', 'post'); // true\n * isEquivType('post', 'post'); // true\n * isEquivType('posts', 'posts'); // true\n * isEquivType('post-comment', 'postComment'); // true\n * isEquivType('post-comment', 'PostComment'); // true\n * isEquivType('post-comment', 'post_comment'); // true\n * isEquivType('post-comment', 'post-comment'); // true\n * isEquivType('post-comment', 'post'); // false\n * isEquivType('posts', null); // false\n * ```\n *\n * @method isEquivType\n * @for @ember-data/legacy-compat/utils\n * @param {string} expected a potentially unnormalized type to match against\n * @param {string} actual a potentially unnormalized type to match against\n * @return {boolean} true if the types are equivalent\n * @public\n * @static\n */\nexport function isEquivType(expected: string, actual: string): boolean {\n AssertFn('isEquivType: Expected type must not be null', expected !== null);\n AssertFn('isEquivType: Expected type must not be undefined', expected !== undefined);\n AssertFn('isEquivType: Expected type must be a string', typeof expected === 'string');\n AssertFn('isEquivType: Expected type must not be empty', expected.length > 0);\n\n AssertFn('isEquivType: Actual type must not be null', actual !== null);\n AssertFn('isEquivType: Actual type must not be undefined', actual !== undefined);\n AssertFn('isEquivType: Actual type must be a string', typeof actual === 'string');\n AssertFn('isEquivType: Actual type must not be empty', actual.length > 0);\n\n return expected === actual || formattedType(expected) === formattedType(actual);\n}\n\n/**\n * Compares two IDs for strict equality, converting them to\n * the format expected by the EmberData Cache to ensure\n * differences in format are accounted for in the comparison.\n *\n * Asserts when expected or actual are invalid IDs in dev.\n * Expected may never be null.\n *\n * ```js\n * isEquivId('1', 1); // true\n * isEquivId('2', '2'); // true\n * isEquivId(3, '3'); // true\n * isEquivId(4, '3'); // false\n * isEquivId(1, null); // false\n * ```\n *\n * @method isEquivId\n * @for @ember-data/legacy-compat/utils\n * @param {string | number} expected a potentially un-normalized id to match against\n * @param {string | number} actual a potentially un-normalized id to match against\n * @return {boolean} true if the ids are equivalent\n * @public\n * @static\n */\nexport function isEquivId(expected: string | number, actual: string | number | null): boolean {\n AssertFn('isEquivId: Expected id must not be null', expected !== null);\n AssertFn('isEquivId: Expected id must not be undefined', expected !== undefined);\n AssertFn(\n 'isEquivId: Expected id must be a number or string',\n typeof expected === 'number' || typeof expected === 'string'\n );\n AssertFn(\n 'isEquivId: Expected id must not be empty',\n typeof expected === 'number' || (typeof expected === 'string' && expected.length > 0)\n );\n AssertFn('isEquivId: Expected id must not be 0', expected !== '0' && expected !== 0);\n\n AssertFn('isEquivId: Actual id must not be undefined', actual !== undefined);\n AssertFn(\n 'isEquivId: Actual id must be a number, string or null',\n typeof actual === 'number' || typeof actual === 'string' || actual === null\n );\n AssertFn(\n 'isEquivId: Actual id must not be empty',\n actual === null || typeof actual === 'number' || (typeof actual === 'string' && actual.length > 0)\n );\n AssertFn('isEquivId: Actual id must not be 0', actual !== '0' && actual !== 0);\n\n return expected === actual || formattedId(expected) === formattedId(actual);\n}\n"],"names":["singularize","macroCondition","dependencySatisfies","importSync","MismatchReporter","_AssertFn","AssertFn","message","condition","getOwnConfig","env","DEBUG","Error","NormalizedType","str","dasherize","configureMismatchReporter","fn","configureAssertFn","configureTypeNormalization","NORMALIZED_TYPES","Map","formattedType","type","undefined","length","normalized","get","set","formattedId","id","formatted","String","isEquivType","expected","actual","isEquivId"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcA,IAAIA,WAAoC,CAAA;AACxC,IAAIC,cAAc,CAACC,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,EAAE;AAC/DF,EAAAA,WAAW,GAAIG,UAAU,CAAC,iBAAiB,CAAC,CAAsCH,WAAW,CAAA;AAC/F,CAAA;AAEA,IAAII,gBAA0B,GAAG,YAAY,EAAE,CAAA;;AAE/C;AACA;AACA,IAAIC,SAAwD,GAAG,YAAY,EAAE,CAAA;AAC7E,MAAMC,QAAoB,GAAIA,CAACC,OAAe,EAAEC,SAAkB,KAAK;EACrE,IAAI,CAACA,SAAS,EAAE;AACdH,IAAAA,SAAS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AK,CAAC,CAAC,CAAA;AAE9E,EAAA,OAAOD,QAAQ,KAAKC,MAAM,IAAIN,WAAW,CAACK,QAAQ,CAAC,KAAKL,WAAW,CAACM,MAAM,CAAC,CAAA;AAC7E;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/legacy-compat",
|
|
3
3
|
"description": "Compatibility Shims for Older EmberData",
|
|
4
|
-
"version": "5.4.0-alpha.
|
|
4
|
+
"version": "5.4.0-alpha.54",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Chris Thoburn <runspired@users.noreply.github.com>",
|
|
7
7
|
"repository": {
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"version": 1
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@ember-data/private-build-infra": "5.4.0-alpha.
|
|
46
|
-
"@embroider/macros": "^1.15.
|
|
45
|
+
"@ember-data/private-build-infra": "5.4.0-alpha.54",
|
|
46
|
+
"@embroider/macros": "^1.15.1",
|
|
47
47
|
"ember-cli-babel": "^8.2.0"
|
|
48
48
|
},
|
|
49
49
|
"dependenciesMeta": {
|
|
@@ -79,11 +79,13 @@
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@ember-data/graph": "5.4.0-alpha.
|
|
83
|
-
"@ember-data/json-api": "5.4.0-alpha.
|
|
84
|
-
"@ember-data/request": "5.4.0-alpha.
|
|
85
|
-
"@ember-data/store": "5.4.0-alpha.
|
|
86
|
-
"@
|
|
82
|
+
"@ember-data/graph": "5.4.0-alpha.54",
|
|
83
|
+
"@ember-data/json-api": "5.4.0-alpha.54",
|
|
84
|
+
"@ember-data/request": "5.4.0-alpha.54",
|
|
85
|
+
"@ember-data/store": "5.4.0-alpha.54",
|
|
86
|
+
"@ember/string": "^3.1.1",
|
|
87
|
+
"ember-inflector": "^4.0.2",
|
|
88
|
+
"@warp-drive/core-types": "0.0.0-alpha.40"
|
|
87
89
|
},
|
|
88
90
|
"peerDependenciesMeta": {
|
|
89
91
|
"@ember-data/graph": {
|
|
@@ -91,37 +93,40 @@
|
|
|
91
93
|
},
|
|
92
94
|
"@ember-data/json-api": {
|
|
93
95
|
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"ember-inflector": {
|
|
98
|
+
"optional": true
|
|
94
99
|
}
|
|
95
100
|
},
|
|
96
101
|
"devDependencies": {
|
|
97
102
|
"@babel/cli": "^7.24.1",
|
|
98
|
-
"@babel/core": "^7.24.
|
|
103
|
+
"@babel/core": "^7.24.4",
|
|
99
104
|
"@babel/plugin-proposal-decorators": "^7.24.1",
|
|
100
105
|
"@babel/plugin-transform-class-properties": "^7.24.1",
|
|
101
106
|
"@babel/plugin-transform-private-methods": "^7.24.1",
|
|
102
107
|
"@babel/plugin-transform-runtime": "^7.24.3",
|
|
103
|
-
"@babel/plugin-transform-typescript": "^7.24.
|
|
104
|
-
"@babel/preset-env": "^7.24.
|
|
108
|
+
"@babel/plugin-transform-typescript": "^7.24.4",
|
|
109
|
+
"@babel/preset-env": "^7.24.4",
|
|
105
110
|
"@babel/preset-typescript": "^7.24.1",
|
|
106
|
-
"@babel/runtime": "^7.24.
|
|
107
|
-
"@ember-data/graph": "5.4.0-alpha.
|
|
108
|
-
"@ember-data/json-api": "5.4.0-alpha.
|
|
109
|
-
"@ember-data/request": "5.4.0-alpha.
|
|
110
|
-
"@ember-data/request-utils": "5.4.0-alpha.
|
|
111
|
-
"@ember-data/store": "5.4.0-alpha.
|
|
112
|
-
"@ember-data/tracking": "5.4.0-alpha.
|
|
111
|
+
"@babel/runtime": "^7.24.4",
|
|
112
|
+
"@ember-data/graph": "5.4.0-alpha.54",
|
|
113
|
+
"@ember-data/json-api": "5.4.0-alpha.54",
|
|
114
|
+
"@ember-data/request": "5.4.0-alpha.54",
|
|
115
|
+
"@ember-data/request-utils": "5.4.0-alpha.54",
|
|
116
|
+
"@ember-data/store": "5.4.0-alpha.54",
|
|
117
|
+
"@ember-data/tracking": "5.4.0-alpha.54",
|
|
113
118
|
"@ember/string": "^3.1.1",
|
|
114
|
-
"@embroider/addon-dev": "^4.
|
|
119
|
+
"@embroider/addon-dev": "^4.3.1",
|
|
115
120
|
"@glimmer/component": "^1.1.2",
|
|
116
121
|
"@rollup/plugin-babel": "^6.0.4",
|
|
117
122
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
118
|
-
"@warp-drive/core-types": "0.0.0-alpha.
|
|
119
|
-
"@warp-drive/internal-config": "5.4.0-alpha.
|
|
123
|
+
"@warp-drive/core-types": "0.0.0-alpha.40",
|
|
124
|
+
"@warp-drive/internal-config": "5.4.0-alpha.54",
|
|
120
125
|
"ember-inflector": "^4.0.2",
|
|
121
126
|
"ember-source": "~5.7.0",
|
|
122
127
|
"pnpm-sync-dependencies-meta-injected": "0.0.10",
|
|
123
|
-
"rollup": "^4.
|
|
124
|
-
"typescript": "^5.4.
|
|
128
|
+
"rollup": "^4.14.1",
|
|
129
|
+
"typescript": "^5.4.5",
|
|
125
130
|
"walk-sync": "^3.0.0"
|
|
126
131
|
},
|
|
127
132
|
"ember": {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders/find-all' {
|
|
2
|
+
import type { StoreRequestInput } from '@ember-data/store';
|
|
3
|
+
import type { FindAllOptions } from '@ember-data/store/-types/q/store';
|
|
4
|
+
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
|
|
5
|
+
type FindAllRequestInput<T extends string> = StoreRequestInput & {
|
|
6
|
+
op: 'findAll';
|
|
7
|
+
data: {
|
|
8
|
+
type: T;
|
|
9
|
+
options: FindAllBuilderOptions;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type FindAllBuilderOptions = FindAllOptions;
|
|
13
|
+
/**
|
|
14
|
+
This function builds a request config to perform a `findAll` request for the given type.
|
|
15
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.findAll` request.
|
|
16
|
+
Additionally, it takes the same options as `store.findAll`.
|
|
17
|
+
|
|
18
|
+
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.
|
|
19
|
+
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.
|
|
20
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
21
|
+
|
|
22
|
+
@method findAll
|
|
23
|
+
@deprecated
|
|
24
|
+
@public
|
|
25
|
+
@static
|
|
26
|
+
@for @ember-data/legacy-compat/builders
|
|
27
|
+
@param {string} type the name of the resource
|
|
28
|
+
@param {object} query a query to be used by the adapter
|
|
29
|
+
@param {FindAllBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.findAll
|
|
30
|
+
@return {FindAllRequestInput} request config
|
|
31
|
+
*/
|
|
32
|
+
export function findAllBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, options?: FindAllBuilderOptions): FindAllRequestInput<TypeFromInstance<T>>;
|
|
33
|
+
export function findAllBuilder(type: string, options?: FindAllBuilderOptions): FindAllRequestInput<string>;
|
|
34
|
+
export {};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=find-all.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-all.d.ts","sourceRoot":"","sources":["../../src/builders/find-all.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAK3F,KAAK,mBAAmB,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG;IAC/D,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,OAAO,EAAE,qBAAqB,CAAC;KAChC,CAAC;CACH,CAAC;AAEF,KAAK,qBAAqB,GAAG,cAAc,CAAC;AAE5C;;;;;;;;;;;;;;;;;;EAkBE;AACF,wBAAgB,cAAc,CAAC,CAAC,SAAS,mBAAmB,EAC1D,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders/find-record' {
|
|
2
|
+
import type { StoreRequestInput } from '@ember-data/store';
|
|
3
|
+
import type { FindRecordOptions } from '@ember-data/store/-types/q/store';
|
|
4
|
+
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
|
|
5
|
+
import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
|
|
6
|
+
type FindRecordRequestInput<T extends string> = StoreRequestInput & {
|
|
7
|
+
op: 'findRecord';
|
|
8
|
+
data: {
|
|
9
|
+
record: ResourceIdentifierObject<T>;
|
|
10
|
+
options: FindRecordBuilderOptions;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type FindRecordBuilderOptions = Omit<FindRecordOptions, 'preload'>;
|
|
14
|
+
/**
|
|
15
|
+
This function builds a request config to find the record for a given identifier or type and id combination.
|
|
16
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.findRecord` request.
|
|
17
|
+
Additionally, it takes the same options as `store.findRecord`, with the exception of `preload` (which is unsupported).
|
|
18
|
+
|
|
19
|
+
**Example 1**
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { findRecord } from '@ember-data/legacy-compat/builders';
|
|
23
|
+
const { content: post } = await store.request<Post>(findRecord<Post>('post', '1'));
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Example 2**
|
|
27
|
+
|
|
28
|
+
`findRecord` can be called with a single identifier argument instead of the combination
|
|
29
|
+
of `type` (modelName) and `id` as separate arguments. You may recognize this combo as
|
|
30
|
+
the typical pairing from [JSON:API](https://jsonapi.org/format/#document-resource-object-identification)
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { findRecord } from '@ember-data/legacy-compat/builders';
|
|
34
|
+
const { content: post } = await store.request<Post>(findRecord<Post>({ type: 'post', id }));
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
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.
|
|
38
|
+
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.
|
|
39
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
40
|
+
|
|
41
|
+
@method findRecord
|
|
42
|
+
@deprecated
|
|
43
|
+
@public
|
|
44
|
+
@static
|
|
45
|
+
@for @ember-data/legacy-compat/builders
|
|
46
|
+
@param {string|object} type - 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
|
|
47
|
+
@param {string|number|object} 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
|
|
48
|
+
@param {FindRecordBuilderOptions} [options] - if the first param is a string this will be the optional options for the request. See examples for available options.
|
|
49
|
+
@return {FindRecordRequestInput} request config
|
|
50
|
+
*/
|
|
51
|
+
export function findRecordBuilder<T extends TypedRecordInstance>(resource: TypeFromInstance<T>, id: string, options?: FindRecordBuilderOptions): FindRecordRequestInput<TypeFromInstance<T>>;
|
|
52
|
+
export function findRecordBuilder(resource: string, id: string, options?: FindRecordBuilderOptions): FindRecordRequestInput<string>;
|
|
53
|
+
export function findRecordBuilder<T extends TypedRecordInstance>(resource: ResourceIdentifierObject<TypeFromInstance<T>>, options?: FindRecordBuilderOptions): FindRecordRequestInput<TypeFromInstance<T>>;
|
|
54
|
+
export function findRecordBuilder(resource: ResourceIdentifierObject, options?: FindRecordBuilderOptions): FindRecordRequestInput<string>;
|
|
55
|
+
export {};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=find-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-record.d.ts","sourceRoot":"","sources":["../../src/builders/find-record.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EAAqB,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC7F,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAE3F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAIhF,KAAK,sBAAsB,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG;IAClE,EAAE,EAAE,YAAY,CAAC;IACjB,IAAI,EAAE;QACJ,MAAM,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,EAAE,wBAAwB,CAAC;KACnC,CAAC;CACH,CAAC;AAEF,KAAK,wBAAwB,GAAG,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoCE;AACF,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,mBAAmB,EAC7D,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAC7B,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,wBAAwB,GACjC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,wBAAwB,GACjC,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAClC,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,mBAAmB,EAC7D,QAAQ,EAAE,wBAAwB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,EACvD,OAAO,CAAC,EAAE,wBAAwB,GACjC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,wBAAwB,EAClC,OAAO,CAAC,EAAE,wBAAwB,GACjC,sBAAsB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders/query' {
|
|
2
|
+
import type { StoreRequestInput } from '@ember-data/store';
|
|
3
|
+
import type { QueryOptions } from '@ember-data/store/-types/q/store';
|
|
4
|
+
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
|
|
5
|
+
type QueryRequestInput<T extends string> = StoreRequestInput & {
|
|
6
|
+
op: 'query';
|
|
7
|
+
data: {
|
|
8
|
+
type: T;
|
|
9
|
+
query: Record<string, unknown>;
|
|
10
|
+
options: QueryBuilderOptions;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type QueryBuilderOptions = QueryOptions;
|
|
14
|
+
/**
|
|
15
|
+
This function builds a request config for a given type and query object.
|
|
16
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.query` request.
|
|
17
|
+
Additionally, it takes the same options as `store.query`.
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
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.
|
|
21
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
22
|
+
|
|
23
|
+
@method query
|
|
24
|
+
@deprecated
|
|
25
|
+
@public
|
|
26
|
+
@static
|
|
27
|
+
@for @ember-data/legacy-compat/builders
|
|
28
|
+
@param {string} type the name of the resource
|
|
29
|
+
@param {object} query a query to be used by the adapter
|
|
30
|
+
@param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
31
|
+
@return {QueryRequestInput} request config
|
|
32
|
+
*/
|
|
33
|
+
export function queryBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: Record<string, unknown>, options?: QueryBuilderOptions): QueryRequestInput<TypeFromInstance<T>>;
|
|
34
|
+
export function queryBuilder(type: string, query: Record<string, unknown>, options?: QueryBuilderOptions): QueryRequestInput<string>;
|
|
35
|
+
type QueryRecordRequestInput<T extends string> = StoreRequestInput & {
|
|
36
|
+
op: 'queryRecord';
|
|
37
|
+
data: {
|
|
38
|
+
type: T;
|
|
39
|
+
query: Record<string, unknown>;
|
|
40
|
+
options: QueryBuilderOptions;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
This function builds a request config for a given type and query object.
|
|
45
|
+
When passed to `store.request`, this config will result in the same behavior as a `store.queryRecord` request.
|
|
46
|
+
Additionally, it takes the same options as `store.queryRecord`.
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
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.
|
|
50
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
51
|
+
|
|
52
|
+
@method queryRecord
|
|
53
|
+
@deprecated
|
|
54
|
+
@public
|
|
55
|
+
@static
|
|
56
|
+
@for @ember-data/legacy-compat/builders
|
|
57
|
+
@param {string} type the name of the resource
|
|
58
|
+
@param {object} query a query to be used by the adapter
|
|
59
|
+
@param {QueryBuilderOptions} [options] optional, may include `adapterOptions` hash which will be passed to adapter.query
|
|
60
|
+
@return {QueryRecordRequestInput} request config
|
|
61
|
+
*/
|
|
62
|
+
export function queryRecordBuilder<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query: Record<string, unknown>, options?: QueryBuilderOptions): QueryRecordRequestInput<TypeFromInstance<T>>;
|
|
63
|
+
export function queryRecordBuilder(type: string, query: Record<string, unknown>, options?: QueryBuilderOptions): QueryRecordRequestInput<string>;
|
|
64
|
+
export {};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/builders/query.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAK3F,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG;IAC7D,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,EAAE,mBAAmB,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF,KAAK,mBAAmB,GAAG,YAAY,CAAC;AAExC;;;;;;;;;;;;;;;;;;EAkBE;AACF,wBAAgB,YAAY,CAAC,CAAC,SAAS,mBAAmB,EACxD,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,iBAAiB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAwB7B,KAAK,uBAAuB,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG;IACnE,EAAE,EAAE,aAAa,CAAC;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,CAAC,CAAC;QACR,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC/B,OAAO,EAAE,mBAAmB,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;;EAkBE;AACF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,mBAAmB,EAC9D,IAAI,EAAE,gBAAgB,CAAC,CAAC,CAAC,EACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,uBAAuB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,GAC5B,uBAAuB,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders/save-record' {
|
|
2
|
+
import { type StoreRequestInput } from '@ember-data/store';
|
|
3
|
+
import type { StableRecordIdentifier } from '@warp-drive/core-types';
|
|
4
|
+
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
|
|
5
|
+
type SaveRecordRequestInput<T extends string> = StoreRequestInput & {
|
|
6
|
+
op: 'createRecord' | 'deleteRecord' | 'updateRecord';
|
|
7
|
+
data: {
|
|
8
|
+
record: StableRecordIdentifier<T>;
|
|
9
|
+
options: SaveRecordBuilderOptions;
|
|
10
|
+
};
|
|
11
|
+
records: [StableRecordIdentifier<T>];
|
|
12
|
+
};
|
|
13
|
+
type SaveRecordBuilderOptions = Record<string, unknown>;
|
|
14
|
+
/**
|
|
15
|
+
This function builds a request config for saving the given record (e.g. creating, updating, or deleting the record).
|
|
16
|
+
When passed to `store.request`, this config will result in the same behavior as a legacy `store.saveRecord` request.
|
|
17
|
+
Additionally, it takes the same options as `store.saveRecord`.
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
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.
|
|
21
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
22
|
+
|
|
23
|
+
@method saveRecord
|
|
24
|
+
@deprecated
|
|
25
|
+
@public
|
|
26
|
+
@static
|
|
27
|
+
@for @ember-data/legacy-compat/builders
|
|
28
|
+
@param {object} record a record to save
|
|
29
|
+
@param {SaveRecordBuilderOptions} options optional, may include `adapterOptions` hash which will be passed to adapter.saveRecord
|
|
30
|
+
@return {SaveRecordRequestInput} request config
|
|
31
|
+
*/
|
|
32
|
+
export function saveRecordBuilder<T extends TypedRecordInstance>(record: T, options?: Record<string, unknown>): SaveRecordRequestInput<TypeFromInstance<T>>;
|
|
33
|
+
export {};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=save-record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-record.d.ts","sourceRoot":"","sources":["../../src/builders/save-record.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiC,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAG3F,KAAK,sBAAsB,CAAC,CAAC,SAAS,MAAM,IAAI,iBAAiB,GAAG;IAClE,EAAE,EAAE,cAAc,GAAG,cAAc,GAAG,cAAc,CAAC;IACrD,IAAI,EAAE;QACJ,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;QAClC,OAAO,EAAE,wBAAwB,CAAC;KACnC,CAAC;IACF,OAAO,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC;CACtC,CAAC;AAEF,KAAK,wBAAwB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAWxD;;;;;;;;;;;;;;;;;EAiBE;AACF,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,mBAAmB,EAC7D,MAAM,EAAE,CAAC,EACT,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACpC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAuC7C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders/utils' {
|
|
2
|
+
import type { ResourceIdentifierObject } from '@warp-drive/core-types/spec/raw';
|
|
3
|
+
export function isMaybeIdentifier(maybeIdentifier: string | ResourceIdentifierObject): maybeIdentifier is ResourceIdentifierObject;
|
|
4
|
+
export function normalizeModelName(type: string): string;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/builders/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,wBAAgB,iBAAiB,CAC/B,eAAe,EAAE,MAAM,GAAG,wBAAwB,GACjD,eAAe,IAAI,wBAAwB,CAO7C;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsBvD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare module '@ember-data/legacy-compat/builders' {
|
|
2
|
+
/**
|
|
3
|
+
Builders for migrating from `store` methods to `store.request`.
|
|
4
|
+
|
|
5
|
+
These builders enable you to migrate your codebase to using the correct syntax for `store.request` while temporarily preserving legacy behaviors.
|
|
6
|
+
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.
|
|
7
|
+
To that end, these builders are deprecated and will be removed in a future version of Ember Data.
|
|
8
|
+
|
|
9
|
+
@module @ember-data/legacy-compat/builders
|
|
10
|
+
@main @ember-data/legacy-compat/builders
|
|
11
|
+
@deprecated
|
|
12
|
+
*/
|
|
13
|
+
export { findAllBuilder as findAll } from '@ember-data/legacy-compat/builders/find-all';
|
|
14
|
+
export { findRecordBuilder as findRecord } from '@ember-data/legacy-compat/builders/find-record';
|
|
15
|
+
export { queryBuilder as query, queryRecordBuilder as queryRecord } from '@ember-data/legacy-compat/builders/query';
|
|
16
|
+
export { saveRecordBuilder as saveRecord } from '@ember-data/legacy-compat/builders/save-record';
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EAAE,iBAAiB,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,EAAE,YAAY,IAAI,KAAK,EAAE,kBAAkB,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE5F,OAAO,EAAE,iBAAiB,IAAI,UAAU,EAAE,MAAM,wBAAwB,CAAC"}
|