@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.
Files changed (214) hide show
  1. package/README.md +14 -27
  2. package/declarations/adapter/error.d.ts +7 -7
  3. package/declarations/adapter/json-api.d.ts +6 -8
  4. package/declarations/adapter/rest.d.ts +26 -112
  5. package/declarations/adapter.d.ts +6 -8
  6. package/declarations/compat/-private.d.ts +1 -1
  7. package/declarations/compat/builders/find-all.d.ts +6 -6
  8. package/declarations/compat/builders/find-record.d.ts +8 -8
  9. package/declarations/compat/builders/query.d.ts +12 -12
  10. package/declarations/compat/extensions.d.ts +1 -1
  11. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +7 -9
  12. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +20 -30
  13. package/declarations/compat/utils.d.ts +17 -17
  14. package/declarations/compat.d.ts +35 -11
  15. package/declarations/index.d.ts +70 -0
  16. package/declarations/model/-private/attr.d.ts +5 -6
  17. package/declarations/model/-private/belongs-to.d.ts +4 -5
  18. package/declarations/model/-private/has-many.d.ts +4 -5
  19. package/declarations/model/-private/hooks.d.ts +1 -1
  20. package/declarations/model/-private/legacy-relationships-support.d.ts +2 -2
  21. package/declarations/model/-private/model.d.ts +18 -59
  22. package/declarations/model/-private/promise-many-array.d.ts +0 -18
  23. package/declarations/model/-private/record-state.d.ts +1 -1
  24. package/declarations/model/-private/references/belongs-to.d.ts +19 -29
  25. package/declarations/model/-private/references/has-many.d.ts +14 -16
  26. package/declarations/model/migration-support.d.ts +46 -21
  27. package/declarations/model-fragments/extensions/fragment-array.d.ts +16 -0
  28. package/declarations/model-fragments/extensions/fragment.d.ts +15 -0
  29. package/declarations/model-fragments/hooks/model-for.d.ts +20 -0
  30. package/declarations/model-fragments/index.d.ts +5 -0
  31. package/declarations/model-fragments/instance-initializers/fragment-extensions.d.ts +9 -0
  32. package/declarations/model-fragments/utilities/with-array-defaults.d.ts +15 -0
  33. package/declarations/model-fragments/utilities/with-fragment-array-defaults.d.ts +20 -0
  34. package/declarations/model-fragments/utilities/with-fragment-defaults.d.ts +19 -0
  35. package/declarations/model-fragments/utilities/with-legacy.d.ts +3 -0
  36. package/declarations/model-fragments.d.ts +9 -0
  37. package/declarations/model.d.ts +2 -2
  38. package/declarations/serializer/-private/embedded-records-mixin.d.ts +1 -6
  39. package/declarations/serializer/-private/transforms/boolean.d.ts +2 -2
  40. package/declarations/serializer/-private/transforms/date.d.ts +2 -2
  41. package/declarations/serializer/-private/transforms/number.d.ts +1 -1
  42. package/declarations/serializer/-private/transforms/string.d.ts +1 -1
  43. package/declarations/serializer/json-api.d.ts +11 -12
  44. package/declarations/serializer/json.d.ts +9 -11
  45. package/declarations/serializer/rest.d.ts +4 -6
  46. package/declarations/serializer.d.ts +9 -12
  47. package/dist/{-private-8UmnAf9J.js → -private-BG3bMiKp.js} +3 -2
  48. package/dist/adapter/-private.js +1 -1
  49. package/dist/adapter/error.js +14 -15
  50. package/dist/adapter/json-api.js +4 -1
  51. package/dist/adapter/rest.js +38 -125
  52. package/dist/adapter.js +6 -8
  53. package/dist/compat/-private.js +1 -1
  54. package/dist/compat/builders.js +26 -26
  55. package/dist/compat/utils.js +17 -18
  56. package/dist/compat.js +61 -43
  57. package/dist/{errors-8kD2mSe_.js → errors-Cz5KrzBk.js} +115 -122
  58. package/dist/hooks-D6diaM34.js +74 -0
  59. package/dist/index.js +195 -0
  60. package/dist/{json-DziiodPf.js → json-ChdEfB0X.js} +18 -35
  61. package/dist/model/-private.js +1 -1
  62. package/dist/model/migration-support.js +57 -25
  63. package/dist/model-for-CqXsIKws.js +221 -0
  64. package/dist/model-fragments.js +76 -0
  65. package/dist/model.js +18 -90
  66. package/dist/{schema-provider-DQu4Rjco.js → schema-provider-DJCV_6AF.js} +50 -95
  67. package/dist/{serialize-into-hash-CS0MIv4F.js → serialize-into-hash-DPZYoF-i.js} +1 -1
  68. package/dist/serializer/json-api.js +18 -45
  69. package/dist/serializer/json.js +1 -1
  70. package/dist/serializer/rest.js +14 -21
  71. package/dist/serializer/transform.js +15 -6
  72. package/dist/serializer.js +9 -13
  73. package/dist/store.js +5 -1
  74. package/dist/unpkg/dev/-private-DtjBbEgy.js +1206 -0
  75. package/dist/unpkg/dev/adapter/-private.js +1 -0
  76. package/dist/unpkg/dev/adapter/error.js +335 -0
  77. package/dist/unpkg/dev/adapter/json-api.js +271 -0
  78. package/dist/unpkg/dev/adapter/rest.js +1171 -0
  79. package/dist/unpkg/dev/adapter.js +1252 -0
  80. package/dist/unpkg/dev/compat/-private.js +1 -0
  81. package/dist/unpkg/dev/compat/builders.js +275 -0
  82. package/dist/unpkg/dev/compat/extensions.js +242 -0
  83. package/dist/unpkg/dev/compat/utils.js +223 -0
  84. package/dist/unpkg/dev/compat.js +1147 -0
  85. package/dist/unpkg/dev/errors-DmGGJr3T.js +2562 -0
  86. package/dist/unpkg/dev/hooks-CkYiE6Ud.js +73 -0
  87. package/dist/unpkg/dev/index.js +197 -0
  88. package/dist/unpkg/dev/json-Cu1LNgmQ.js +1256 -0
  89. package/dist/unpkg/dev/model/-private.js +1 -0
  90. package/dist/unpkg/dev/model/migration-support.js +553 -0
  91. package/dist/unpkg/dev/model-for-CqXsIKws.js +221 -0
  92. package/dist/unpkg/dev/model-fragments.js +76 -0
  93. package/dist/unpkg/dev/model.js +678 -0
  94. package/dist/unpkg/dev/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  95. package/dist/unpkg/dev/schema-provider-DDVYxmUV.js +2186 -0
  96. package/dist/unpkg/dev/serialize-into-hash-B2xDbuo5.js +259 -0
  97. package/dist/unpkg/dev/serializer/json-api.js +649 -0
  98. package/dist/unpkg/dev/serializer/json.js +4 -0
  99. package/dist/unpkg/dev/serializer/rest.js +1242 -0
  100. package/dist/unpkg/dev/serializer/transform.js +278 -0
  101. package/dist/unpkg/dev/serializer.js +248 -0
  102. package/dist/unpkg/dev/store.js +637 -0
  103. package/dist/unpkg/dev/util-DvanW33H.js +20 -0
  104. package/dist/unpkg/dev/utils-BhvS1iTS.js +8 -0
  105. package/dist/unpkg/dev-deprecated/-private-DtjBbEgy.js +1206 -0
  106. package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -0
  107. package/dist/unpkg/dev-deprecated/adapter/error.js +335 -0
  108. package/dist/unpkg/dev-deprecated/adapter/json-api.js +271 -0
  109. package/dist/unpkg/dev-deprecated/adapter/rest.js +1171 -0
  110. package/dist/unpkg/dev-deprecated/adapter.js +1252 -0
  111. package/dist/unpkg/dev-deprecated/compat/-private.js +1 -0
  112. package/dist/unpkg/dev-deprecated/compat/builders.js +275 -0
  113. package/dist/unpkg/dev-deprecated/compat/extensions.js +242 -0
  114. package/dist/unpkg/dev-deprecated/compat/utils.js +223 -0
  115. package/dist/unpkg/dev-deprecated/compat.js +1147 -0
  116. package/dist/unpkg/dev-deprecated/errors-Spt6ubMd.js +2565 -0
  117. package/dist/unpkg/dev-deprecated/hooks-DOXegvhL.js +73 -0
  118. package/dist/unpkg/dev-deprecated/index.js +196 -0
  119. package/dist/unpkg/dev-deprecated/json-Cu1LNgmQ.js +1256 -0
  120. package/dist/unpkg/dev-deprecated/model/-private.js +1 -0
  121. package/dist/unpkg/dev-deprecated/model/migration-support.js +570 -0
  122. package/dist/unpkg/dev-deprecated/model-for-CqXsIKws.js +221 -0
  123. package/dist/unpkg/dev-deprecated/model-fragments.js +76 -0
  124. package/dist/unpkg/dev-deprecated/model.js +682 -0
  125. package/dist/unpkg/dev-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  126. package/dist/unpkg/dev-deprecated/schema-provider-BP6_8N-V.js +2211 -0
  127. package/dist/unpkg/dev-deprecated/serialize-into-hash-B2xDbuo5.js +259 -0
  128. package/dist/unpkg/dev-deprecated/serializer/json-api.js +649 -0
  129. package/dist/unpkg/dev-deprecated/serializer/json.js +4 -0
  130. package/dist/unpkg/dev-deprecated/serializer/rest.js +1242 -0
  131. package/dist/unpkg/dev-deprecated/serializer/transform.js +278 -0
  132. package/dist/unpkg/dev-deprecated/serializer.js +248 -0
  133. package/dist/unpkg/dev-deprecated/store.js +637 -0
  134. package/dist/unpkg/dev-deprecated/util-CWr5WQOT.js +24 -0
  135. package/dist/unpkg/dev-deprecated/utils-C9PJehtL.js +12 -0
  136. package/dist/unpkg/prod/-private-BdyZaGEh.js +971 -0
  137. package/dist/unpkg/prod/adapter/-private.js +1 -0
  138. package/dist/unpkg/prod/adapter/error.js +330 -0
  139. package/dist/unpkg/prod/adapter/json-api.js +266 -0
  140. package/dist/unpkg/prod/adapter/rest.js +1134 -0
  141. package/dist/unpkg/prod/adapter.js +1219 -0
  142. package/dist/unpkg/prod/compat/-private.js +1 -0
  143. package/dist/unpkg/prod/compat/builders.js +210 -0
  144. package/dist/unpkg/prod/compat/extensions.js +232 -0
  145. package/dist/unpkg/prod/compat/utils.js +218 -0
  146. package/dist/unpkg/prod/compat.js +727 -0
  147. package/dist/unpkg/prod/errors-BGVFCBmi.js +2314 -0
  148. package/dist/unpkg/prod/hooks-BztVA_x0.js +41 -0
  149. package/dist/unpkg/prod/index.js +151 -0
  150. package/dist/unpkg/prod/json-BWrZ5546.js +1243 -0
  151. package/dist/unpkg/prod/model/-private.js +1 -0
  152. package/dist/unpkg/prod/model/migration-support.js +546 -0
  153. package/dist/unpkg/prod/model-for-CqXsIKws.js +221 -0
  154. package/dist/unpkg/prod/model-fragments.js +76 -0
  155. package/dist/unpkg/prod/model.js +593 -0
  156. package/dist/unpkg/prod/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  157. package/dist/unpkg/prod/schema-provider-DJtD_8jZ.js +1861 -0
  158. package/dist/unpkg/prod/serialize-into-hash-DGlzQteF.js +215 -0
  159. package/dist/unpkg/prod/serializer/json-api.js +592 -0
  160. package/dist/unpkg/prod/serializer/json.js +4 -0
  161. package/dist/unpkg/prod/serializer/rest.js +1210 -0
  162. package/dist/unpkg/prod/serializer/transform.js +278 -0
  163. package/dist/unpkg/prod/serializer.js +248 -0
  164. package/dist/unpkg/prod/store.js +505 -0
  165. package/dist/unpkg/prod/util-DvanW33H.js +20 -0
  166. package/dist/unpkg/prod/utils-BhvS1iTS.js +8 -0
  167. package/dist/unpkg/prod-deprecated/-private-BdyZaGEh.js +971 -0
  168. package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -0
  169. package/dist/unpkg/prod-deprecated/adapter/error.js +330 -0
  170. package/dist/unpkg/prod-deprecated/adapter/json-api.js +266 -0
  171. package/dist/unpkg/prod-deprecated/adapter/rest.js +1134 -0
  172. package/dist/unpkg/prod-deprecated/adapter.js +1219 -0
  173. package/dist/unpkg/prod-deprecated/compat/-private.js +1 -0
  174. package/dist/unpkg/prod-deprecated/compat/builders.js +210 -0
  175. package/dist/unpkg/prod-deprecated/compat/extensions.js +232 -0
  176. package/dist/unpkg/prod-deprecated/compat/utils.js +218 -0
  177. package/dist/unpkg/prod-deprecated/compat.js +727 -0
  178. package/dist/unpkg/prod-deprecated/errors-CdDaK81x.js +2317 -0
  179. package/dist/unpkg/prod-deprecated/hooks-yId87yyG.js +41 -0
  180. package/dist/unpkg/prod-deprecated/index.js +150 -0
  181. package/dist/unpkg/prod-deprecated/json-BWrZ5546.js +1243 -0
  182. package/dist/unpkg/prod-deprecated/model/-private.js +1 -0
  183. package/dist/unpkg/prod-deprecated/model/migration-support.js +563 -0
  184. package/dist/unpkg/prod-deprecated/model-for-CqXsIKws.js +221 -0
  185. package/dist/unpkg/prod-deprecated/model-fragments.js +76 -0
  186. package/dist/unpkg/prod-deprecated/model.js +596 -0
  187. package/dist/unpkg/prod-deprecated/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  188. package/dist/unpkg/prod-deprecated/schema-provider-CjX55uSY.js +1904 -0
  189. package/dist/unpkg/prod-deprecated/serialize-into-hash-DGlzQteF.js +215 -0
  190. package/dist/unpkg/prod-deprecated/serializer/json-api.js +592 -0
  191. package/dist/unpkg/prod-deprecated/serializer/json.js +4 -0
  192. package/dist/unpkg/prod-deprecated/serializer/rest.js +1210 -0
  193. package/dist/unpkg/prod-deprecated/serializer/transform.js +278 -0
  194. package/dist/unpkg/prod-deprecated/serializer.js +248 -0
  195. package/dist/unpkg/prod-deprecated/store.js +505 -0
  196. package/dist/unpkg/prod-deprecated/util-B6cn-i93.js +23 -0
  197. package/dist/unpkg/prod-deprecated/utils-BUWwQwCh.js +11 -0
  198. package/logos/README.md +2 -2
  199. package/logos/logo-yellow-slab.svg +1 -0
  200. package/logos/word-mark-black.svg +1 -0
  201. package/logos/word-mark-white.svg +1 -0
  202. package/package.json +14 -6
  203. package/logos/NCC-1701-a-blue.svg +0 -4
  204. package/logos/NCC-1701-a-gold.svg +0 -4
  205. package/logos/NCC-1701-a-gold_100.svg +0 -1
  206. package/logos/NCC-1701-a-gold_base-64.txt +0 -1
  207. package/logos/NCC-1701-a.svg +0 -4
  208. package/logos/docs-badge.svg +0 -2
  209. package/logos/ember-data-logo-dark.svg +0 -12
  210. package/logos/ember-data-logo-light.svg +0 -12
  211. package/logos/social1.png +0 -0
  212. package/logos/social2.png +0 -0
  213. package/logos/warp-drive-logo-dark.svg +0 -4
  214. package/logos/warp-drive-logo-gold.svg +0 -4
@@ -0,0 +1,278 @@
1
+ import EmberObject from '@ember/object';
2
+
3
+ /**
4
+ The `Transform` class is used to serialize and deserialize model
5
+ attributes when they are saved or loaded from an
6
+ adapter. Subclassing `Transform` is useful for creating custom
7
+ attributes. All subclasses of `Transform` must implement a
8
+ `serialize` and a `deserialize` method.
9
+
10
+ Example
11
+
12
+ ```js [app/transforms/temperature.js]
13
+
14
+ // Converts centigrade in the JSON to fahrenheit in the app
15
+ export default class TemperatureTransform {
16
+ deserialize(serialized, options) {
17
+ return (serialized * 1.8) + 32;
18
+ }
19
+
20
+ serialize(deserialized, options) {
21
+ return (deserialized - 32) / 1.8;
22
+ }
23
+
24
+ static create() {
25
+ return new this();
26
+ }
27
+ }
28
+ ```
29
+
30
+ Usage
31
+
32
+ ```js [app/models/requirement.js]
33
+ import { Model, attr } from '@warp-drive/legacy/model';
34
+
35
+ export default class RequirementModel extends Model {
36
+ @attr('string') name;
37
+ @attr('temperature') temperature;
38
+ }
39
+ ```
40
+
41
+ The options passed into the `attr` function when the attribute is
42
+ declared on the model is also available in the transform.
43
+
44
+ ```js [app/models/post.js]
45
+ import { Model, attr } from '@warp-drive/legacy/model';
46
+
47
+ export default class PostModel extends Model {
48
+ @attr('string') title;
49
+ @attr('markdown', {
50
+ markdown: {
51
+ gfm: false,
52
+ sanitize: true
53
+ }
54
+ })
55
+ markdown;
56
+ }
57
+ ```
58
+
59
+ ```js [app/transforms/markdown.js]
60
+ export default class MarkdownTransform {
61
+ serialize(deserialized, options) {
62
+ return deserialized.raw;
63
+ }
64
+
65
+ deserialize(serialized, options) {
66
+ let markdownOptions = options.markdown || {};
67
+
68
+ return marked(serialized, markdownOptions);
69
+ }
70
+
71
+ static create() {
72
+ return new this();
73
+ }
74
+ }
75
+ ```
76
+
77
+ @class Transform
78
+ @public
79
+ */
80
+ const Transform = EmberObject;
81
+
82
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
83
+
84
+ /**
85
+ The `BooleanTransform` class is used to serialize and deserialize
86
+ boolean attributes on Ember Data record objects. This transform is
87
+ used when `'boolean'` is passed as the type parameter to the
88
+ {@link attr}function.
89
+
90
+ Usage
91
+
92
+ ```js [app/models/user.js]
93
+ import { Model, attr } from '@warp-drive/legacy/model';
94
+
95
+ export default class UserModel extends Model {
96
+ @attr('boolean') isAdmin;
97
+ @attr('string') name;
98
+ @attr('string') email;
99
+ }
100
+ ```
101
+
102
+ By default, the boolean transform only allows for values of `true` or
103
+ `false`. You can opt into allowing `null` values for
104
+ boolean attributes via `attr('boolean', { allowNull: true })`
105
+
106
+ ```js [app/models/user.js]
107
+ import { Model, attr } from '@warp-drive/legacy/model';
108
+
109
+ export default class UserModel extends Model {
110
+ @attr('string') email;
111
+ @attr('string') username;
112
+ @attr('boolean', { allowNull: true }) wantsWeeklyEmail;
113
+ }
114
+ ```
115
+
116
+ @public
117
+ */
118
+ class BooleanTransform {
119
+ deserialize(serialized, options) {
120
+ if ((serialized === null || serialized === undefined) && options?.allowNull === true) {
121
+ return null;
122
+ }
123
+ if (typeof serialized === 'boolean') {
124
+ return serialized;
125
+ } else if (typeof serialized === 'string') {
126
+ return /^(true|t|1)$/i.test(serialized);
127
+ } else if (typeof serialized === 'number') {
128
+ return serialized === 1;
129
+ } else {
130
+ return false;
131
+ }
132
+ }
133
+ serialize(deserialized, options) {
134
+ if ((deserialized === null || deserialized === undefined) && options?.allowNull === true) {
135
+ return null;
136
+ }
137
+ return Boolean(deserialized);
138
+ }
139
+ static create() {
140
+ return new this();
141
+ }
142
+ }
143
+
144
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
145
+
146
+ /**
147
+ The `DateTransform` class is used to serialize and deserialize
148
+ date attributes on Ember Data record objects. This transform is used
149
+ when `'date'` is passed as the type parameter to the
150
+ {@link attr} function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)
151
+ standard.
152
+
153
+ ```js [app/models/score.js]
154
+ import Model, { attr, belongsTo } from '@ember-data/model';
155
+
156
+ export default class ScoreModel extends Model {
157
+ @attr('number') value;
158
+ @belongsTo('player') player;
159
+ @attr('date') date;
160
+ }
161
+ ```
162
+
163
+ @public
164
+ */
165
+
166
+ class DateTransform {
167
+ deserialize(serialized, _options) {
168
+ if (typeof serialized === 'string') {
169
+ let offset = serialized.indexOf('+');
170
+ if (offset !== -1 && serialized.length - 5 === offset) {
171
+ offset += 3;
172
+ return new Date(serialized.slice(0, offset) + ':' + serialized.slice(offset));
173
+ }
174
+ return new Date(serialized);
175
+ } else if (typeof serialized === 'number') {
176
+ return new Date(serialized);
177
+ } else if (serialized === null || serialized === undefined) {
178
+ // if the value is null return null
179
+ // if the value is not present in the data return undefined
180
+ return serialized;
181
+ } else {
182
+ return null;
183
+ }
184
+ }
185
+ serialize(date, _options) {
186
+ // @ts-expect-error isNaN accepts date as it is coercible
187
+ if (date instanceof Date && !isNaN(date)) {
188
+ return date.toISOString();
189
+ } else {
190
+ return null;
191
+ }
192
+ }
193
+ static create() {
194
+ return new this();
195
+ }
196
+ }
197
+
198
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
199
+
200
+ function isNumber(value) {
201
+ return value === value && value !== Infinity && value !== -Infinity;
202
+ }
203
+ /**
204
+ The `NumberTransform` class is used to serialize and deserialize
205
+ numeric attributes on Ember Data record objects. This transform is
206
+ used when `number` is passed as the type parameter to the
207
+ {@link attr} function.
208
+
209
+ Usage
210
+
211
+ ```js [app/models/score.js]
212
+ import Model, { attr, belongsTo } from '@ember-data/model';
213
+
214
+ export default class ScoreModel extends Model {
215
+ @attr('number') value;
216
+ @belongsTo('player') player;
217
+ @attr('date') date;
218
+ }
219
+ ```
220
+
221
+ @public
222
+ */
223
+ class NumberTransform {
224
+ deserialize(serialized, _options) {
225
+ if (serialized === '' || serialized === null || serialized === undefined) {
226
+ return null;
227
+ } else {
228
+ const transformed = Number(serialized);
229
+ return isNumber(transformed) ? transformed : null;
230
+ }
231
+ }
232
+ serialize(deserialized, _options) {
233
+ if (deserialized === '' || deserialized === null || deserialized === undefined) {
234
+ return null;
235
+ } else {
236
+ const transformed = Number(deserialized);
237
+ return isNumber(transformed) ? transformed : null;
238
+ }
239
+ }
240
+ static create() {
241
+ return new this();
242
+ }
243
+ }
244
+
245
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
246
+
247
+ /**
248
+ The `StringTransform` class is used to serialize and deserialize
249
+ string attributes on Ember Data record objects. This transform is
250
+ used when `string` is passed as the type parameter to the
251
+ {@link attr} function.
252
+
253
+ Usage
254
+
255
+ ```js [app/models/user.js]
256
+ import Model, { attr, belongsTo } from '@ember-data/model';
257
+
258
+ export default class UserModel extends Model {
259
+ @attr('boolean') isAdmin;
260
+ @attr('string') name;
261
+ @attr('string') email;
262
+ }
263
+ ```
264
+
265
+ @public
266
+ */
267
+ class StringTransform {
268
+ deserialize(serialized, _options) {
269
+ return !serialized && serialized !== '' ? null : String(serialized);
270
+ }
271
+ serialize(deserialized, _options) {
272
+ return !deserialized && deserialized !== '' ? null : String(deserialized);
273
+ }
274
+ static create() {
275
+ return new this();
276
+ }
277
+ }
278
+ export { BooleanTransform, DateTransform, NumberTransform, StringTransform, Transform };
@@ -0,0 +1,248 @@
1
+ import EmberObject from '@ember/object';
2
+ import * as s from '@ember/service';
3
+ import { a as decorateFieldV2, i as initializeDeferredDecorator } from "./runtime-BPCpkOf1-BKOwiRJp.js";
4
+
5
+ /**
6
+ ## Overview
7
+
8
+ :::danger
9
+ ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.
10
+ If starting a new app or thinking of implementing a new serializer, consider writing a
11
+ {@link Handler} instead to be used with the {@link RequestManager}
12
+ :::
13
+
14
+ In order to properly manage and present your data, WarpDrive
15
+ needs to understand the structure of data it receives.
16
+
17
+ `Serializers` convert data between the server's API format and
18
+ the format WarpDrive understands.
19
+
20
+ Data received from an API response is **normalized** into
21
+ [{json:api}](https://jsonapi.org/) (the format used internally
22
+ by WarpDrive), while data sent to an API is **serialized**
23
+ into the format the API expects.
24
+
25
+ ### Implementing a Serializer
26
+
27
+ There are only two required serializer methods, one for
28
+ normalizing data from the server API format into {json:api}, and
29
+ another for serializing records via `Snapshots` into the expected
30
+ server API format.
31
+
32
+ To implement a serializer, export a class that conforms to the structure
33
+ described by {@link MinimumSerializerInterface}
34
+ from the `app/serializers/` directory. An example is below.
35
+
36
+ ```ts
37
+ import EmberObject from '@ember/object';
38
+
39
+ export default class ApplicationSerializer extends EmberObject {
40
+ normalizeResponse(store, schema, rawPayload) {
41
+ return rawPayload;
42
+ }
43
+
44
+ serialize(snapshot, options) {
45
+ const serializedResource = {
46
+ id: snapshot.id,
47
+ type: snapshot.modelName,
48
+ attributes: snapshot.attributes()
49
+ };
50
+
51
+ return serializedResource;
52
+ }
53
+ }
54
+ ```
55
+
56
+
57
+ ### Serializer Resolution
58
+
59
+ `store.serializerFor(name)` will lookup serializers defined in
60
+ `app/serializers/` and return an instance. If no serializer is found, an
61
+ error will be thrown.
62
+
63
+ `serializerFor` first attempts to find a serializer with an exact match on `name`,
64
+ then falls back to checking for the presence of a serializer named `application`.
65
+
66
+ ```ts
67
+ store.serializerFor('author');
68
+
69
+ // lookup paths (in order) =>
70
+ // app/serializers/author.js
71
+ // app/serializers/application.js
72
+ ```
73
+
74
+ Most requests in `@warp-drive/legacy` are made with respect to a particular `type` (or `modelName`)
75
+ (e.g., "get me the full collection of **books**" or "get me the **employee** whose id is 37"). We
76
+ refer to this as the **primary** resource `type`.
77
+
78
+ Typically `serializerFor` will be used to find a serializer with a name matching that of the primary
79
+ resource `type` for the request, falling back to the `application` serializer for those types that
80
+ do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy
81
+ for defining serializers. However, because APIs rarely format payloads per-type but rather
82
+ per-API-version, this may not be a desired strategy.
83
+
84
+ It is recommended that applications define only a single `application` adapter and serializer
85
+ where possible.
86
+
87
+ If you have multiple API formats and the per-type strategy is not viable, one strategy is to
88
+ write an `application` adapter and serializer that make use of `options` to specify the desired
89
+ format when making a request.
90
+
91
+ ### Using a Serializer
92
+
93
+ Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.
94
+
95
+ ### Default Serializers
96
+
97
+ For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**
98
+ format the `@warp-drive/legacy/serializer` package contains implementations these applications can
99
+ extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.
100
+
101
+ Many applications will find writing their own serializer to be more performant and less
102
+ complex than extending these classes even when their API format is very close to that expected
103
+ by these serializers.
104
+
105
+ It is recommended that apps write their own serializer to best suit the needs of their API and
106
+ application.
107
+
108
+ @module
109
+ */
110
+ const service = s.service ?? s.inject;
111
+
112
+ /**
113
+ > ⚠️ CAUTION you likely want the docs for {@link MinimumSerializerInterface}
114
+ > as extending this abstract class is unnecessary.
115
+
116
+ `Serializer` is an abstract base class that you may override in your
117
+ application to customize it for your backend. The minimum set of methods
118
+ that you should implement is:
119
+
120
+ * `normalizeResponse()`
121
+ * `serialize()`
122
+
123
+ And you can optionally override the following methods:
124
+
125
+ * `normalize()`
126
+
127
+ For an example implementation, see the included {@link JSONSerializer}.
128
+
129
+ @class Serializer
130
+ @public
131
+ */
132
+
133
+ class Serializer extends EmberObject {
134
+ static {
135
+ decorateFieldV2(this.prototype, "store", [service]);
136
+ }
137
+ #store = (initializeDeferredDecorator(this, "store"), void 0);
138
+ /**
139
+ The `store` property is the application's `store` that contains
140
+ all records. It can be used to look up serializers for other model
141
+ types that may be nested inside the payload response.
142
+ Example:
143
+ ```js
144
+ Serializer.extend({
145
+ extractRelationship(relationshipModelName, relationshipHash) {
146
+ let modelClass = this.store.modelFor(relationshipModelName);
147
+ let relationshipSerializer = this.store.serializerFor(relationshipModelName);
148
+ return relationshipSerializer.normalize(modelClass, relationshipHash);
149
+ }
150
+ });
151
+ ```
152
+ @property store
153
+ @type {Store}
154
+ @public
155
+ */
156
+
157
+ /**
158
+ The `normalizeResponse` method is used to normalize a payload from the
159
+ server to a JSON-API Document.
160
+ http://jsonapi.org/format/#document-structure
161
+ Example:
162
+ ```js
163
+ Serializer.extend({
164
+ normalizeResponse(store, primaryModelClass, payload, id, requestType) {
165
+ if (requestType === 'findRecord') {
166
+ return this.normalize(primaryModelClass, payload);
167
+ } else {
168
+ return payload.reduce(function(documentHash, item) {
169
+ let { data, included } = this.normalize(primaryModelClass, item);
170
+ documentHash.included.push(...included);
171
+ documentHash.data.push(data);
172
+ return documentHash;
173
+ }, { data: [], included: [] })
174
+ }
175
+ }
176
+ });
177
+ ```
178
+ @since 1.13.0
179
+ @public
180
+ @param {Store} store
181
+ @param {Model} primaryModelClass
182
+ @param {Object} payload
183
+ @param {String|Number} id
184
+ @param {String} requestType
185
+ @return {Object} JSON-API Document
186
+ */
187
+
188
+ /**
189
+ The `serialize` method is used when a record is saved in order to convert
190
+ the record into the form that your external data source expects.
191
+ `serialize` takes an optional `options` hash with a single option:
192
+ - `includeId`: If this is `true`, `serialize` should include the ID
193
+ in the serialized object it builds.
194
+ Example:
195
+ ```js
196
+ Serializer.extend({
197
+ serialize(snapshot, options) {
198
+ let json = {
199
+ id: snapshot.id
200
+ };
201
+ snapshot.eachAttribute((key, attribute) => {
202
+ json[key] = snapshot.attr(key);
203
+ });
204
+ snapshot.eachRelationship((key, relationship) => {
205
+ if (relationship.kind === 'belongsTo') {
206
+ json[key] = snapshot.belongsTo(key, { id: true });
207
+ } else if (relationship.kind === 'hasMany') {
208
+ json[key] = snapshot.hasMany(key, { ids: true });
209
+ }
210
+ });
211
+ return json;
212
+ },
213
+ });
214
+ ```
215
+ @public
216
+ @param {Snapshot} snapshot
217
+ @param {Object} [options]
218
+ @return {Object}
219
+ */
220
+
221
+ /**
222
+ The `normalize` method is used to convert a payload received from your
223
+ external data source into the normalized form `store.push()` expects. You
224
+ should override this method, munge the hash and return the normalized
225
+ payload.
226
+ Example:
227
+ ```js
228
+ Serializer.extend({
229
+ normalize(modelClass, resourceHash) {
230
+ let data = {
231
+ id: resourceHash.id,
232
+ type: modelClass.modelName,
233
+ attributes: resourceHash
234
+ };
235
+ return { data: data };
236
+ }
237
+ })
238
+ ```
239
+ @public
240
+ @param {Model} typeClass
241
+ @param {Object} hash
242
+ @return {Object}
243
+ */
244
+ normalize(_typeClass, hash) {
245
+ return hash;
246
+ }
247
+ }
248
+ export { Serializer };