@ember-data/legacy-compat 5.4.0-alpha.53 → 5.4.0-alpha.55

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/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;AAC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IAAIA,MAAM,KAAK,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.53",
4
+ "version": "5.4.0-alpha.55",
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.53",
46
- "@embroider/macros": "^1.15.0",
45
+ "@ember-data/private-build-infra": "5.4.0-alpha.55",
46
+ "@embroider/macros": "^1.15.1",
47
47
  "ember-cli-babel": "^8.2.0"
48
48
  },
49
49
  "dependenciesMeta": {
@@ -79,12 +79,13 @@
79
79
  }
80
80
  },
81
81
  "peerDependencies": {
82
- "@ember-data/graph": "5.4.0-alpha.53",
83
- "@ember-data/json-api": "5.4.0-alpha.53",
84
- "@ember-data/request": "5.4.0-alpha.53",
85
- "@ember-data/store": "5.4.0-alpha.53",
82
+ "@ember-data/graph": "5.4.0-alpha.55",
83
+ "@ember-data/json-api": "5.4.0-alpha.55",
84
+ "@ember-data/request": "5.4.0-alpha.55",
85
+ "@ember-data/store": "5.4.0-alpha.55",
86
86
  "@ember/string": "^3.1.1",
87
- "@warp-drive/core-types": "0.0.0-alpha.39"
87
+ "ember-inflector": "^4.0.2",
88
+ "@warp-drive/core-types": "0.0.0-alpha.41"
88
89
  },
89
90
  "peerDependenciesMeta": {
90
91
  "@ember-data/graph": {
@@ -92,6 +93,9 @@
92
93
  },
93
94
  "@ember-data/json-api": {
94
95
  "optional": true
96
+ },
97
+ "ember-inflector": {
98
+ "optional": true
95
99
  }
96
100
  },
97
101
  "devDependencies": {
@@ -105,24 +109,24 @@
105
109
  "@babel/preset-env": "^7.24.4",
106
110
  "@babel/preset-typescript": "^7.24.1",
107
111
  "@babel/runtime": "^7.24.4",
108
- "@ember-data/graph": "5.4.0-alpha.53",
109
- "@ember-data/json-api": "5.4.0-alpha.53",
110
- "@ember-data/request": "5.4.0-alpha.53",
111
- "@ember-data/request-utils": "5.4.0-alpha.53",
112
- "@ember-data/store": "5.4.0-alpha.53",
113
- "@ember-data/tracking": "5.4.0-alpha.53",
112
+ "@ember-data/graph": "5.4.0-alpha.55",
113
+ "@ember-data/json-api": "5.4.0-alpha.55",
114
+ "@ember-data/request": "5.4.0-alpha.55",
115
+ "@ember-data/request-utils": "5.4.0-alpha.55",
116
+ "@ember-data/store": "5.4.0-alpha.55",
117
+ "@ember-data/tracking": "5.4.0-alpha.55",
114
118
  "@ember/string": "^3.1.1",
115
- "@embroider/addon-dev": "^4.2.1",
119
+ "@embroider/addon-dev": "^4.3.1",
116
120
  "@glimmer/component": "^1.1.2",
117
121
  "@rollup/plugin-babel": "^6.0.4",
118
122
  "@rollup/plugin-node-resolve": "^15.2.3",
119
- "@warp-drive/core-types": "0.0.0-alpha.39",
120
- "@warp-drive/internal-config": "5.4.0-alpha.53",
123
+ "@warp-drive/core-types": "0.0.0-alpha.41",
124
+ "@warp-drive/internal-config": "5.4.0-alpha.55",
121
125
  "ember-inflector": "^4.0.2",
122
126
  "ember-source": "~5.7.0",
123
127
  "pnpm-sync-dependencies-meta-injected": "0.0.10",
124
- "rollup": "^4.14.0",
125
- "typescript": "^5.4.4",
128
+ "rollup": "^4.14.1",
129
+ "typescript": "^5.4.5",
126
130
  "walk-sync": "^3.0.0"
127
131
  },
128
132
  "ember": {
@@ -1,20 +1,21 @@
1
+ /// <reference path="./utils.d.ts" />
1
2
  /// <reference path="./builders.d.ts" />
2
3
  /// <reference path="./-private.d.ts" />
3
- /// <reference path="./builders/find-record.d.ts" />
4
- /// <reference path="./builders/find-all.d.ts" />
5
- /// <reference path="./builders/query.d.ts" />
6
- /// <reference path="./builders/save-record.d.ts" />
7
- /// <reference path="./builders/utils.d.ts" />
8
- /// <reference path="./legacy-network-handler/fetch-manager.d.ts" />
9
4
  /// <reference path="./legacy-network-handler/identifier-has-id.d.ts" />
5
+ /// <reference path="./legacy-network-handler/minimum-serializer-interface.d.ts" />
6
+ /// <reference path="./legacy-network-handler/legacy-data-fetch.d.ts" />
7
+ /// <reference path="./legacy-network-handler/snapshot.d.ts" />
8
+ /// <reference path="./legacy-network-handler/snapshot-record-array.d.ts" />
10
9
  /// <reference path="./legacy-network-handler/minimum-adapter-interface.d.ts" />
11
10
  /// <reference path="./legacy-network-handler/legacy-data-utils.d.ts" />
12
- /// <reference path="./legacy-network-handler/legacy-data-fetch.d.ts" />
13
11
  /// <reference path="./legacy-network-handler/legacy-network-handler.d.ts" />
14
- /// <reference path="./legacy-network-handler/snapshot-record-array.d.ts" />
15
12
  /// <reference path="./legacy-network-handler/serializer-response.d.ts" />
16
- /// <reference path="./legacy-network-handler/minimum-serializer-interface.d.ts" />
17
- /// <reference path="./legacy-network-handler/snapshot.d.ts" />
13
+ /// <reference path="./legacy-network-handler/fetch-manager.d.ts" />
14
+ /// <reference path="./builders/save-record.d.ts" />
15
+ /// <reference path="./builders/find-all.d.ts" />
16
+ /// <reference path="./builders/query.d.ts" />
17
+ /// <reference path="./builders/utils.d.ts" />
18
+ /// <reference path="./builders/find-record.d.ts" />
18
19
  declare module '@ember-data/legacy-compat' {
19
20
  import type Store from '@ember-data/store';
20
21
  import type { ObjectValue } from '@warp-drive/core-types/json/raw';
@@ -0,0 +1,159 @@
1
+ declare module '@ember-data/legacy-compat/utils' {
2
+ type Reporter = (type: 'formatted-id' | 'formatted-type', actual: unknown, expected: unknown) => void;
3
+ /**
4
+ * Configure a function to be called when an id or type
5
+ * changes during normalization. This is useful for instrumenting
6
+ * to discover places where usage in the app is not consistent.
7
+ *
8
+ * @method configureMismatchReporter
9
+ * @for @ember-data/legacy-compat/utils
10
+ * @param method a function which takes a mismatch-type ('formatted-id' | 'formatted-type'), actual, and expected value
11
+ * @public
12
+ * @static
13
+ */
14
+ export function configureMismatchReporter(fn: Reporter): void;
15
+ /**
16
+ * Configure a function to be called when an id or type
17
+ * fails validation. This is useful for instrumenting
18
+ * to discover places where usage in the app is not consistent.
19
+ *
20
+ * @method configureAssertFn
21
+ * @for @ember-data/legacy-compat/utils
22
+ * @param method a function which takes a message and a condition
23
+ * @public
24
+ * @static
25
+ */
26
+ export function configureAssertFn(fn: (message: string, condition: unknown) => void): void;
27
+ /**
28
+ * Configure a function to be called to normalize
29
+ * a resource type string. Used by both formattedType
30
+ * and isEquivType to ensure consistent normalization
31
+ * during comparison.
32
+ *
33
+ * If validation fails or the type turns out be unnormalized
34
+ * the configured mismatch reporter and assert functions will
35
+ * be called.
36
+ *
37
+ * @method configureTypeNormalization
38
+ * @for @ember-data/legacy-compat/utils
39
+ * @param method a function which takes a string and returns a string
40
+ * @public
41
+ * @static
42
+ */
43
+ export function configureTypeNormalization(fn: (type: string) => string): void;
44
+ /**
45
+ * Converts a potentially unnormalized type into the format expected
46
+ * by our EmberData Cache. Currently this is singular-dasherized.
47
+ *
48
+ * you should not rely on this function to give you an exact format
49
+ * for display purposes. Formatting for display should be handled
50
+ * differently if the exact format matters.
51
+ *
52
+ * Asserts invalid types (undefined, null, '') in dev.
53
+ *
54
+ * **Usage**
55
+ *
56
+ * ```js
57
+ * import formattedType from 'soxhub-client/helpers/formatted-type';
58
+ *
59
+ * formattedType('post'); // => 'post'
60
+ * formattedType('posts'); // => 'post'
61
+ * formattedType('Posts'); // => 'post'
62
+ * formattedType('post-comment'); // => 'post-comment'
63
+ * formattedType('post-comments'); // => 'post-comment'
64
+ * formattedType('post_comment'); // => 'post-comment'
65
+ * formattedType('postComment'); // => 'post-comment'
66
+ * formattedType('PostComment'); // => 'post-comment'
67
+ * ```
68
+ *
69
+ * @method formattedType
70
+ * @for @ember-data/legacy-compat/utils
71
+ * @param {string} type the potentially un-normalized type
72
+ * @return {string} the normalized type
73
+ * @public
74
+ * @static
75
+ */
76
+ export function formattedType<T extends string>(type: T | string): T;
77
+ /**
78
+ * Format an id to the format expected by the EmberData Cache.
79
+ * Currently this means that id should be `string | null`.
80
+ *
81
+ * Asserts invalid IDs (undefined, '', 0, '0') in dev.
82
+ *
83
+ * **Usage**
84
+ *
85
+ * ```js
86
+ * import formattedId from 'client/utils/formatted-id';
87
+ *
88
+ * formattedId('1'); // => '1'
89
+ * formattedId(1); // => '1'
90
+ * formattedId(null); // => null
91
+ * ```
92
+ *
93
+ * @method formattedId
94
+ * @for @ember-data/legacy-compat/utils
95
+ * @param {string | number | null} id the potentially un-normalized id
96
+ * @return {string | null} the normalized id
97
+ * @public
98
+ * @static
99
+ */
100
+ export function formattedId(id: string | number): string;
101
+ export function formattedId(id: null): null;
102
+ export function formattedId(id: string | number | null): string | null;
103
+ /**
104
+ * Compares two types for strict equality, converting them to
105
+ * the format expected by the EmberData Cache to ensure
106
+ * differences in format are accounted for in the comparison.
107
+ *
108
+ * Asserts when expected or actual are invalid types in dev.
109
+ * Expected may never be null.
110
+ *
111
+ * ```js
112
+ * isEquivType('posts', 'post'); // true
113
+ * isEquivType('post', 'post'); // true
114
+ * isEquivType('posts', 'posts'); // true
115
+ * isEquivType('post-comment', 'postComment'); // true
116
+ * isEquivType('post-comment', 'PostComment'); // true
117
+ * isEquivType('post-comment', 'post_comment'); // true
118
+ * isEquivType('post-comment', 'post-comment'); // true
119
+ * isEquivType('post-comment', 'post'); // false
120
+ * isEquivType('posts', null); // false
121
+ * ```
122
+ *
123
+ * @method isEquivType
124
+ * @for @ember-data/legacy-compat/utils
125
+ * @param {string} expected a potentially unnormalized type to match against
126
+ * @param {string} actual a potentially unnormalized type to match against
127
+ * @return {boolean} true if the types are equivalent
128
+ * @public
129
+ * @static
130
+ */
131
+ export function isEquivType(expected: string, actual: string): boolean;
132
+ /**
133
+ * Compares two IDs for strict equality, converting them to
134
+ * the format expected by the EmberData Cache to ensure
135
+ * differences in format are accounted for in the comparison.
136
+ *
137
+ * Asserts when expected or actual are invalid IDs in dev.
138
+ * Expected may never be null.
139
+ *
140
+ * ```js
141
+ * isEquivId('1', 1); // true
142
+ * isEquivId('2', '2'); // true
143
+ * isEquivId(3, '3'); // true
144
+ * isEquivId(4, '3'); // false
145
+ * isEquivId(1, null); // false
146
+ * ```
147
+ *
148
+ * @method isEquivId
149
+ * @for @ember-data/legacy-compat/utils
150
+ * @param {string | number} expected a potentially un-normalized id to match against
151
+ * @param {string | number} actual a potentially un-normalized id to match against
152
+ * @return {boolean} true if the ids are equivalent
153
+ * @public
154
+ * @static
155
+ */
156
+ export function isEquivId(expected: string | number, actual: string | number | null): boolean;
157
+ export {};
158
+ }
159
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAmBA,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,cAAc,GAAG,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;AA0BtG;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE5D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAEzF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAE7E;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,GAAG,CAAC,CAiBnE;AAED;;;;;;;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