@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.
@@ -1,4 +1,11 @@
1
+ /// <reference path="./builders.d.ts" />
1
2
  /// <reference path="./-private.d.ts" />
3
+ /// <reference path="./utils.d.ts" />
4
+ /// <reference path="./builders/find-record.d.ts" />
5
+ /// <reference path="./builders/find-all.d.ts" />
6
+ /// <reference path="./builders/query.d.ts" />
7
+ /// <reference path="./builders/save-record.d.ts" />
8
+ /// <reference path="./builders/utils.d.ts" />
2
9
  /// <reference path="./legacy-network-handler/fetch-manager.d.ts" />
3
10
  /// <reference path="./legacy-network-handler/identifier-has-id.d.ts" />
4
11
  /// <reference path="./legacy-network-handler/minimum-adapter-interface.d.ts" />
@@ -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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