@warp-drive/legacy 5.6.0-alpha.11

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 (211) hide show
  1. package/CHANGELOG.md +1 -0
  2. package/LICENSE.md +23 -0
  3. package/README.md +54 -0
  4. package/addon-main.cjs +5 -0
  5. package/declarations/adapter/-private/build-url-mixin.d.ts +34 -0
  6. package/declarations/adapter/-private/build-url-mixin.d.ts.map +1 -0
  7. package/declarations/adapter/-private/fastboot-interface.d.ts +9 -0
  8. package/declarations/adapter/-private/fastboot-interface.d.ts.map +1 -0
  9. package/declarations/adapter/-private/utils/continue-on-reject.d.ts +8 -0
  10. package/declarations/adapter/-private/utils/continue-on-reject.d.ts.map +1 -0
  11. package/declarations/adapter/-private/utils/determine-body-promise.d.ts +5 -0
  12. package/declarations/adapter/-private/utils/determine-body-promise.d.ts.map +1 -0
  13. package/declarations/adapter/-private/utils/fetch.d.ts +9 -0
  14. package/declarations/adapter/-private/utils/fetch.d.ts.map +1 -0
  15. package/declarations/adapter/-private/utils/parse-response-headers.d.ts +2 -0
  16. package/declarations/adapter/-private/utils/parse-response-headers.d.ts.map +1 -0
  17. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts +7 -0
  18. package/declarations/adapter/-private/utils/serialize-into-hash.d.ts.map +1 -0
  19. package/declarations/adapter/-private/utils/serialize-query-params.d.ts +6 -0
  20. package/declarations/adapter/-private/utils/serialize-query-params.d.ts.map +1 -0
  21. package/declarations/adapter/-private.d.ts +6 -0
  22. package/declarations/adapter/-private.d.ts.map +1 -0
  23. package/declarations/adapter/error.d.ts +188 -0
  24. package/declarations/adapter/error.d.ts.map +1 -0
  25. package/declarations/adapter/json-api.d.ts +234 -0
  26. package/declarations/adapter/json-api.d.ts.map +1 -0
  27. package/declarations/adapter/rest.d.ts +823 -0
  28. package/declarations/adapter/rest.d.ts.map +1 -0
  29. package/declarations/adapter.d.ts +801 -0
  30. package/declarations/adapter.d.ts.map +1 -0
  31. package/declarations/compat/-private.d.ts +14 -0
  32. package/declarations/compat/-private.d.ts.map +1 -0
  33. package/declarations/compat/builders/find-all.d.ts +33 -0
  34. package/declarations/compat/builders/find-all.d.ts.map +1 -0
  35. package/declarations/compat/builders/find-record.d.ts +54 -0
  36. package/declarations/compat/builders/find-record.d.ts.map +1 -0
  37. package/declarations/compat/builders/query.d.ts +61 -0
  38. package/declarations/compat/builders/query.d.ts.map +1 -0
  39. package/declarations/compat/builders/save-record.d.ts +32 -0
  40. package/declarations/compat/builders/save-record.d.ts.map +1 -0
  41. package/declarations/compat/builders/utils.d.ts +4 -0
  42. package/declarations/compat/builders/utils.d.ts.map +1 -0
  43. package/declarations/compat/builders.d.ts +15 -0
  44. package/declarations/compat/builders.d.ts.map +1 -0
  45. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts +47 -0
  46. package/declarations/compat/legacy-network-handler/fetch-manager.d.ts.map +1 -0
  47. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts +3 -0
  48. package/declarations/compat/legacy-network-handler/identifier-has-id.d.ts.map +1 -0
  49. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts +12 -0
  50. package/declarations/compat/legacy-network-handler/legacy-data-fetch.d.ts.map +1 -0
  51. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts +6 -0
  52. package/declarations/compat/legacy-network-handler/legacy-data-utils.d.ts.map +1 -0
  53. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts +3 -0
  54. package/declarations/compat/legacy-network-handler/legacy-network-handler.d.ts.map +1 -0
  55. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts +527 -0
  56. package/declarations/compat/legacy-network-handler/minimum-adapter-interface.d.ts.map +1 -0
  57. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts +224 -0
  58. package/declarations/compat/legacy-network-handler/minimum-serializer-interface.d.ts.map +1 -0
  59. package/declarations/compat/legacy-network-handler/serializer-response.d.ts +7 -0
  60. package/declarations/compat/legacy-network-handler/serializer-response.d.ts.map +1 -0
  61. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts +89 -0
  62. package/declarations/compat/legacy-network-handler/snapshot-record-array.d.ts.map +1 -0
  63. package/declarations/compat/legacy-network-handler/snapshot.d.ts +237 -0
  64. package/declarations/compat/legacy-network-handler/snapshot.d.ts.map +1 -0
  65. package/declarations/compat/utils.d.ts +138 -0
  66. package/declarations/compat/utils.d.ts.map +1 -0
  67. package/declarations/compat.d.ts +134 -0
  68. package/declarations/compat.d.ts.map +1 -0
  69. package/declarations/model/-private/attr.d.ts +165 -0
  70. package/declarations/model/-private/attr.d.ts.map +1 -0
  71. package/declarations/model/-private/attr.type-test.d.ts +2 -0
  72. package/declarations/model/-private/attr.type-test.d.ts.map +1 -0
  73. package/declarations/model/-private/belongs-to.d.ts +173 -0
  74. package/declarations/model/-private/belongs-to.d.ts.map +1 -0
  75. package/declarations/model/-private/belongs-to.type-test.d.ts +2 -0
  76. package/declarations/model/-private/belongs-to.type-test.d.ts.map +1 -0
  77. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts +6 -0
  78. package/declarations/model/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  79. package/declarations/model/-private/errors.d.ts +290 -0
  80. package/declarations/model/-private/errors.d.ts.map +1 -0
  81. package/declarations/model/-private/has-many.d.ts +164 -0
  82. package/declarations/model/-private/has-many.d.ts.map +1 -0
  83. package/declarations/model/-private/has-many.type-test.d.ts +2 -0
  84. package/declarations/model/-private/has-many.type-test.d.ts.map +1 -0
  85. package/declarations/model/-private/hooks.d.ts +11 -0
  86. package/declarations/model/-private/hooks.d.ts.map +1 -0
  87. package/declarations/model/-private/legacy-relationships-support.d.ts +57 -0
  88. package/declarations/model/-private/legacy-relationships-support.d.ts.map +1 -0
  89. package/declarations/model/-private/model-for-mixin.d.ts +4 -0
  90. package/declarations/model/-private/model-for-mixin.d.ts.map +1 -0
  91. package/declarations/model/-private/model-methods.d.ts +35 -0
  92. package/declarations/model/-private/model-methods.d.ts.map +1 -0
  93. package/declarations/model/-private/model.d.ts +1270 -0
  94. package/declarations/model/-private/model.d.ts.map +1 -0
  95. package/declarations/model/-private/model.type-test.d.ts +2 -0
  96. package/declarations/model/-private/model.type-test.d.ts.map +1 -0
  97. package/declarations/model/-private/notify-changes.d.ts +5 -0
  98. package/declarations/model/-private/notify-changes.d.ts.map +1 -0
  99. package/declarations/model/-private/promise-belongs-to.d.ts +40 -0
  100. package/declarations/model/-private/promise-belongs-to.d.ts.map +1 -0
  101. package/declarations/model/-private/promise-many-array.d.ts +126 -0
  102. package/declarations/model/-private/promise-many-array.d.ts.map +1 -0
  103. package/declarations/model/-private/promise-proxy-base.d.ts +3 -0
  104. package/declarations/model/-private/promise-proxy-base.d.ts.map +1 -0
  105. package/declarations/model/-private/record-state.d.ts +78 -0
  106. package/declarations/model/-private/record-state.d.ts.map +1 -0
  107. package/declarations/model/-private/references/belongs-to.d.ts +495 -0
  108. package/declarations/model/-private/references/belongs-to.d.ts.map +1 -0
  109. package/declarations/model/-private/references/has-many.d.ts +504 -0
  110. package/declarations/model/-private/references/has-many.d.ts.map +1 -0
  111. package/declarations/model/-private/schema-provider.d.ts +63 -0
  112. package/declarations/model/-private/schema-provider.d.ts.map +1 -0
  113. package/declarations/model/-private/type-utils.d.ts +57 -0
  114. package/declarations/model/-private/type-utils.d.ts.map +1 -0
  115. package/declarations/model/-private/util.d.ts +6 -0
  116. package/declarations/model/-private/util.d.ts.map +1 -0
  117. package/declarations/model/-private.d.ts +8 -0
  118. package/declarations/model/-private.d.ts.map +1 -0
  119. package/declarations/model/migration-support.d.ts +287 -0
  120. package/declarations/model/migration-support.d.ts.map +1 -0
  121. package/declarations/model/migration-support.type-test.d.ts +2 -0
  122. package/declarations/model/migration-support.type-test.d.ts.map +1 -0
  123. package/declarations/model.d.ts +50 -0
  124. package/declarations/model.d.ts.map +1 -0
  125. package/declarations/serializer/-private/embedded-records-mixin.d.ts +97 -0
  126. package/declarations/serializer/-private/embedded-records-mixin.d.ts.map +1 -0
  127. package/declarations/serializer/-private/transforms/boolean.d.ts +47 -0
  128. package/declarations/serializer/-private/transforms/boolean.d.ts.map +1 -0
  129. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts +2 -0
  130. package/declarations/serializer/-private/transforms/boolean.type-test.d.ts.map +1 -0
  131. package/declarations/serializer/-private/transforms/date.d.ts +28 -0
  132. package/declarations/serializer/-private/transforms/date.d.ts.map +1 -0
  133. package/declarations/serializer/-private/transforms/number.d.ts +29 -0
  134. package/declarations/serializer/-private/transforms/number.d.ts.map +1 -0
  135. package/declarations/serializer/-private/transforms/string.d.ts +29 -0
  136. package/declarations/serializer/-private/transforms/string.d.ts.map +1 -0
  137. package/declarations/serializer/-private/transforms/transform.d.ts +119 -0
  138. package/declarations/serializer/-private/transforms/transform.d.ts.map +1 -0
  139. package/declarations/serializer/-private/utils.d.ts +4 -0
  140. package/declarations/serializer/-private/utils.d.ts.map +1 -0
  141. package/declarations/serializer/json-api.d.ts +496 -0
  142. package/declarations/serializer/json-api.d.ts.map +1 -0
  143. package/declarations/serializer/json.d.ts +1047 -0
  144. package/declarations/serializer/json.d.ts.map +1 -0
  145. package/declarations/serializer/rest.d.ts +554 -0
  146. package/declarations/serializer/rest.d.ts.map +1 -0
  147. package/declarations/serializer/transform.d.ts +6 -0
  148. package/declarations/serializer/transform.d.ts.map +1 -0
  149. package/declarations/serializer.d.ts +258 -0
  150. package/declarations/serializer.d.ts.map +1 -0
  151. package/dist/-private-DFfBszo5.js +1182 -0
  152. package/dist/-private-DFfBszo5.js.map +1 -0
  153. package/dist/adapter/-private.js +1 -0
  154. package/dist/adapter/-private.js.map +1 -0
  155. package/dist/adapter/error.js +254 -0
  156. package/dist/adapter/error.js.map +1 -0
  157. package/dist/adapter/json-api.js +129 -0
  158. package/dist/adapter/json-api.js.map +1 -0
  159. package/dist/adapter/rest.js +1262 -0
  160. package/dist/adapter/rest.js.map +1 -0
  161. package/dist/adapter.js +1284 -0
  162. package/dist/adapter.js.map +1 -0
  163. package/dist/compat/-private.js +1 -0
  164. package/dist/compat/-private.js.map +1 -0
  165. package/dist/compat/builders.js +292 -0
  166. package/dist/compat/builders.js.map +1 -0
  167. package/dist/compat/utils.js +225 -0
  168. package/dist/compat/utils.js.map +1 -0
  169. package/dist/compat.js +999 -0
  170. package/dist/compat.js.map +1 -0
  171. package/dist/errors-D74uk36r.js +2541 -0
  172. package/dist/errors-D74uk36r.js.map +1 -0
  173. package/dist/json-BCH3fil7.js +1349 -0
  174. package/dist/json-BCH3fil7.js.map +1 -0
  175. package/dist/model/-private.js +2 -0
  176. package/dist/model/-private.js.map +1 -0
  177. package/dist/model/migration-support.js +453 -0
  178. package/dist/model/migration-support.js.map +1 -0
  179. package/dist/model.js +736 -0
  180. package/dist/model.js.map +1 -0
  181. package/dist/runtime-BPCpkOf1-BKOwiRJp.js +65 -0
  182. package/dist/runtime-BPCpkOf1-BKOwiRJp.js.map +1 -0
  183. package/dist/schema-provider-CXFLTMjg.js +2228 -0
  184. package/dist/schema-provider-CXFLTMjg.js.map +1 -0
  185. package/dist/serialize-into-hash-BxfqWC8u.js +260 -0
  186. package/dist/serialize-into-hash-BxfqWC8u.js.map +1 -0
  187. package/dist/serializer/json-api.js +514 -0
  188. package/dist/serializer/json-api.js.map +1 -0
  189. package/dist/serializer/json.js +6 -0
  190. package/dist/serializer/json.js.map +1 -0
  191. package/dist/serializer/rest.js +1245 -0
  192. package/dist/serializer/rest.js.map +1 -0
  193. package/dist/serializer/transform.js +313 -0
  194. package/dist/serializer/transform.js.map +1 -0
  195. package/dist/serializer.js +252 -0
  196. package/dist/serializer.js.map +1 -0
  197. package/logos/NCC-1701-a-blue.svg +4 -0
  198. package/logos/NCC-1701-a-gold.svg +4 -0
  199. package/logos/NCC-1701-a-gold_100.svg +1 -0
  200. package/logos/NCC-1701-a-gold_base-64.txt +1 -0
  201. package/logos/NCC-1701-a.svg +4 -0
  202. package/logos/README.md +4 -0
  203. package/logos/docs-badge.svg +2 -0
  204. package/logos/ember-data-logo-dark.svg +12 -0
  205. package/logos/ember-data-logo-light.svg +12 -0
  206. package/logos/github-header.svg +444 -0
  207. package/logos/social1.png +0 -0
  208. package/logos/social2.png +0 -0
  209. package/logos/warp-drive-logo-dark.svg +4 -0
  210. package/logos/warp-drive-logo-gold.svg +4 -0
  211. package/package.json +72 -0
@@ -0,0 +1,119 @@
1
+ import EmberObject from '@ember/object';
2
+ import type { LegacyAttributeField } from '@warp-drive/core/types/schema/fields';
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
+ /**
81
+ When given a deserialized value from a record attribute this
82
+ method must return the serialized value.
83
+
84
+ Example
85
+
86
+ ```javascript
87
+ serialize(deserialized, options) {
88
+ return deserialized ? null : Number(deserialized);
89
+ }
90
+ ```
91
+
92
+ @public
93
+ @param deserialized The deserialized value
94
+ @param options hash of options passed to `attr`
95
+ @return The serialized value
96
+ */
97
+ /**
98
+ When given a serialized value from a JSON object this method must
99
+ return the deserialized value for the record attribute.
100
+
101
+ Example
102
+
103
+ ```javascript
104
+ deserialize(serialized, options) {
105
+ return empty(serialized) ? null : Number(serialized);
106
+ }
107
+ ```
108
+
109
+ @public
110
+ @param serialized The serialized value
111
+ @param options hash of options passed to `attr`
112
+ @return The deserialized value
113
+ */
114
+ export interface Transform {
115
+ serialize(value: unknown, options: LegacyAttributeField['options']): unknown;
116
+ deserialize(value: unknown, options: LegacyAttributeField['options']): unknown;
117
+ }
118
+ export declare const Transform: typeof EmberObject;
119
+ //# sourceMappingURL=transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../src/serializer/-private/transforms/transform.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH;;;;;;;;;;;;;;;;EAgBE;AACF;;;;;;;;;;;;;;;;EAgBE;AACF,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;IAC7E,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;CAChF;AACD,eAAO,MAAM,SAAS,oBAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ type Coercable = string | number | boolean | null | undefined | symbol;
2
+ export declare function coerceId(id: Coercable): string | null;
3
+ export {};
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/serializer/-private/utils.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvE,wBAAgB,QAAQ,CAAC,EAAE,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAUrD"}
@@ -0,0 +1,496 @@
1
+ /**
2
+ * <blockquote style="margin: 1em; padding: .1em 1em .1em 1em; border-left: solid 1em #E34C32; background: #e0e0e0;">
3
+ <p>
4
+ ⚠️ <strong>This is LEGACY documentation</strong> for a feature that is no longer encouraged to be used.
5
+ If starting a new app or thinking of implementing a new adapter, consider writing a
6
+ <a href="/ember-data/release/classes/%3CInterface%3E%20Handler">Handler</a> instead to be used with the <a href="https://github.com/emberjs/data/tree/main/packages/request#readme">RequestManager</a>
7
+ </p>
8
+ </blockquote>
9
+
10
+ In EmberData a Serializer is used to serialize and deserialize
11
+ records when they are transferred in and out of an external source.
12
+ This process involves normalizing property names, transforming
13
+ attribute values and serializing relationships.
14
+
15
+ `JSONAPISerializer` supports the http://jsonapi.org/ spec and is the
16
+ serializer recommended by Ember Data.
17
+
18
+ This serializer normalizes a JSON API payload that looks like:
19
+
20
+ ```js [app/models/player.js]
21
+ import Model, { attr, belongsTo } from '@ember-data/model';
22
+
23
+ export default class Player extends Model {
24
+ @attr('string') name;
25
+ @attr('string') skill;
26
+ @attr('number') gamesPlayed;
27
+ @belongsTo('club') club;
28
+ }
29
+ ```
30
+
31
+ ```js [app/models/club.js]
32
+ import Model, { attr, hasMany } from '@ember-data/model';
33
+
34
+ export default class Club extends Model {
35
+ @attr('string') name;
36
+ @attr('string') location;
37
+ @hasMany('player') players;
38
+ }
39
+ ```
40
+
41
+ ```js
42
+ {
43
+ "data": [
44
+ {
45
+ "attributes": {
46
+ "name": "Benfica",
47
+ "location": "Portugal"
48
+ },
49
+ "id": "1",
50
+ "relationships": {
51
+ "players": {
52
+ "data": [
53
+ {
54
+ "id": "3",
55
+ "type": "players"
56
+ }
57
+ ]
58
+ }
59
+ },
60
+ "type": "clubs"
61
+ }
62
+ ],
63
+ "included": [
64
+ {
65
+ "attributes": {
66
+ "name": "Eusebio Silva Ferreira",
67
+ "skill": "Rocket shot",
68
+ "games-played": 431
69
+ },
70
+ "id": "3",
71
+ "relationships": {
72
+ "club": {
73
+ "data": {
74
+ "id": "1",
75
+ "type": "clubs"
76
+ }
77
+ }
78
+ },
79
+ "type": "players"
80
+ }
81
+ ]
82
+ }
83
+ ```
84
+
85
+ to the format that the Ember Data store expects.
86
+
87
+ ### Customizing meta
88
+
89
+ Since a JSON API Document can have meta defined in multiple locations you can
90
+ use the specific serializer hooks if you need to customize the meta.
91
+
92
+ One scenario would be to camelCase the meta keys of your payload. The example
93
+ below shows how this could be done using `normalizeArrayResponse` and
94
+ `extractRelationship`.
95
+
96
+ ```js [app/serializers/application.js]
97
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
98
+
99
+ export default class ApplicationSerializer extends JSONAPISerializer {
100
+ normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
101
+ let normalizedDocument = super.normalizeArrayResponse(...arguments);
102
+
103
+ // Customize document meta
104
+ normalizedDocument.meta = camelCaseKeys(normalizedDocument.meta);
105
+
106
+ return normalizedDocument;
107
+ }
108
+
109
+ extractRelationship(relationshipHash) {
110
+ let normalizedRelationship = super.extractRelationship(...arguments);
111
+
112
+ // Customize relationship meta
113
+ normalizedRelationship.meta = camelCaseKeys(normalizedRelationship.meta);
114
+
115
+ return normalizedRelationship;
116
+ }
117
+ }
118
+ ```
119
+
120
+ @since 1.13.0
121
+ @class JSONAPISerializer
122
+ @public
123
+ */
124
+ export const JSONAPISerializer: Readonly<Readonly<typeof import("../serializer.js").Serializer> & (new (owner?: import("@ember/-internals/owner").default) => import("../serializer.js").Serializer) & {
125
+ primaryKey: string;
126
+ mergedProperties: any;
127
+ applyTransforms(typeClass: Model, data: any): any;
128
+ normalizeResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
129
+ normalizeFindRecordResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
130
+ normalizeQueryRecordResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
131
+ normalizeFindAllResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
132
+ normalizeFindBelongsToResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
133
+ normalizeFindHasManyResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
134
+ normalizeFindManyResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
135
+ normalizeQueryResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
136
+ normalizeCreateRecordResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
137
+ normalizeDeleteRecordResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
138
+ normalizeUpdateRecordResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
139
+ normalizeSaveResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, ...args: any[]): any;
140
+ normalizeSingleResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string): any;
141
+ normalizeArrayResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string): any;
142
+ _normalizeResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, isSingle: boolean): any;
143
+ normalize(modelClass: any, resourceHash: any): any;
144
+ extractId(modelClass: any, resourceHash: any): string;
145
+ extractAttributes(modelClass: any, resourceHash: any): any;
146
+ extractRelationship(relationshipModelName: any, relationshipHash: any): any;
147
+ extractPolymorphicRelationship(relationshipModelName: any, relationshipHash: any, relationshipOptions: any): any;
148
+ extractRelationships(modelClass: any, resourceHash: any): any;
149
+ modelNameFromPayloadKey(key: string): string;
150
+ normalizeRelationships(typeClass: any, hash: any): void;
151
+ normalizeUsingDeclaredMapping(modelClass: any, hash: any): void;
152
+ _getMappedKey(key: string, modelClass: any): string;
153
+ _canSerialize(key: string): boolean;
154
+ _mustSerialize(key: string): boolean;
155
+ shouldSerializeHasMany(snapshot: Snapshot, key: string, relationship: RelationshipSchema): boolean;
156
+ serialize(snapshot: Snapshot, options: any): any;
157
+ serializeIntoHash(hash: any, typeClass: Model, snapshot: Snapshot, options: any): void;
158
+ serializeAttribute(snapshot: Snapshot, json: any, key: string, attribute: any): void;
159
+ serializeBelongsTo(snapshot: Snapshot, json: any, relationship: any): void;
160
+ serializeHasMany(snapshot: Snapshot, json: any, relationship: any): void;
161
+ serializePolymorphicType(): void;
162
+ extractMeta(store: Store, modelClass: Model, payload: any): any;
163
+ extractErrors(store: Store, typeClass: Model, payload: any, id: (string | number)): any;
164
+ keyForAttribute(key: string, method: string): string;
165
+ keyForRelationship(key: string, typeClass: string, method: string): string;
166
+ keyForLink(key: string, kind: string): string;
167
+ transformFor(attributeType: string, skipAssertion: boolean): Transform;
168
+ }> & (new (owner?: import("@ember/-internals/owner").default) => import("../serializer.js").Serializer) & {
169
+ /**
170
+ @param {Object} documentHash
171
+ @return {Object}
172
+ @private
173
+ */
174
+ _normalizeDocumentHelper(documentHash: any): any;
175
+ /**
176
+ @param {Object} relationshipDataHash
177
+ @return {Object}
178
+ @private
179
+ */
180
+ _normalizeRelationshipDataHelper(relationshipDataHash: any): any;
181
+ /**
182
+ @param {Object} resourceHash
183
+ @return {Object}
184
+ @private
185
+ */
186
+ _normalizeResourceHelper(resourceHash: any): any;
187
+ /**
188
+ Normalize some data and push it into the store.
189
+
190
+ @public
191
+ @param {Store} store
192
+ @param {Object} payload
193
+ */
194
+ pushPayload(store: Store, payload: any): void;
195
+ /**
196
+ @param {Store} store
197
+ @param {Model} primaryModelClass
198
+ @param {Object} payload
199
+ @param {String|Number} id
200
+ @param {String} requestType
201
+ @param {Boolean} isSingle
202
+ @return {Object} JSON-API Document
203
+ @private
204
+ */
205
+ _normalizeResponse(store: Store, primaryModelClass: Model, payload: any, id: string | number, requestType: string, isSingle: boolean): any;
206
+ normalizeQueryRecordResponse(...args: any[]): any;
207
+ extractAttributes(modelClass: any, resourceHash: any): {};
208
+ /**
209
+ Returns a relationship formatted as a JSON-API "relationship object".
210
+
211
+ http://jsonapi.org/format/#document-resource-object-relationships
212
+
213
+ @public
214
+ @param {Object} relationshipHash
215
+ @return {Object}
216
+ */
217
+ extractRelationship(relationshipHash: any): any;
218
+ /**
219
+ Returns the resource's relationships formatted as a JSON-API "relationships object".
220
+
221
+ http://jsonapi.org/format/#document-resource-object-relationships
222
+
223
+ @public
224
+ @param {Object} modelClass
225
+ @param {Object} resourceHash
226
+ @return {Object}
227
+ */
228
+ extractRelationships(modelClass: any, resourceHash: any): any;
229
+ /**
230
+ @param {Model} modelClass
231
+ @param {Object} resourceHash
232
+ @return {String}
233
+ @private
234
+ */
235
+ _extractType(modelClass: Model, resourceHash: any): string;
236
+ /**
237
+ Dasherizes and singularizes the model name in the payload to match
238
+ the format Ember Data uses internally for the model name.
239
+
240
+ For example the key `posts` would be converted to `post` and the
241
+ key `studentAssesments` would be converted to `student-assesment`.
242
+
243
+ @public
244
+ @param {String} key
245
+ @return {String} the model's modelName
246
+ */
247
+ modelNameFromPayloadKey(key: string): string;
248
+ /**
249
+ Converts the model name to a pluralized version of the model name.
250
+
251
+ For example `post` would be converted to `posts` and
252
+ `student-assesment` would be converted to `student-assesments`.
253
+
254
+ @public
255
+ @param {String} modelName
256
+ @return {String}
257
+ */
258
+ payloadKeyFromModelName(modelName: string): string;
259
+ normalize(modelClass: any, resourceHash: any): {
260
+ data: {
261
+ id: any;
262
+ type: string;
263
+ attributes: {};
264
+ relationships: any;
265
+ };
266
+ };
267
+ /**
268
+ `keyForAttribute` can be used to define rules for how to convert an
269
+ attribute name in your model to a key in your JSON.
270
+ By default `JSONAPISerializer` follows the format used on the examples of
271
+ http://jsonapi.org/format and uses dashes as the word separator in the JSON
272
+ attribute keys.
273
+
274
+ This behaviour can be easily customized by extending this method.
275
+
276
+ Example
277
+
278
+ ```js [app/serializers/application.js]
279
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
280
+ import { dasherize } from '<app-name>/utils/string-utils';
281
+
282
+ export default class ApplicationSerializer extends JSONAPISerializer {
283
+ keyForAttribute(attr, method) {
284
+ return dasherize(attr).toUpperCase();
285
+ }
286
+ }
287
+ ```
288
+
289
+ @public
290
+ @param {String} key
291
+ @param {String} method
292
+ @return {String} normalized key
293
+ */
294
+ keyForAttribute(key: string, method: string): string;
295
+ /**
296
+ `keyForRelationship` can be used to define a custom key when
297
+ serializing and deserializing relationship properties.
298
+ By default `JSONAPISerializer` follows the format used on the examples of
299
+ http://jsonapi.org/format and uses dashes as word separators in
300
+ relationship properties.
301
+
302
+ This behaviour can be easily customized by extending this method.
303
+
304
+ Example
305
+
306
+ ```js [app/serializers/post.js]
307
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
308
+ import { underscore } from '<app-name>/utils/string-utils';
309
+
310
+ export default class ApplicationSerializer extends JSONAPISerializer {
311
+ keyForRelationship(key, relationship, method) {
312
+ return underscore(key);
313
+ }
314
+ }
315
+ ```
316
+ @public
317
+ @param {String} key
318
+ @param {String} typeClass
319
+ @param {String} method
320
+ @return {String} normalized key
321
+ */
322
+ keyForRelationship(key: string, typeClass: string, method: string): string;
323
+ /**
324
+ Called when a record is saved in order to convert the
325
+ record into JSON.
326
+
327
+ For example, consider this model:
328
+
329
+ ```js [app/models/comment.js]
330
+ import Model, { attr, belongsTo } from '@ember-data/model';
331
+
332
+ export default class CommentModel extends Model {
333
+ @attr title;
334
+ @attr body;
335
+
336
+ @belongsTo('user', { async: false, inverse: null })
337
+ author;
338
+ }
339
+ ```
340
+
341
+ The default serialization would create a JSON-API resource object like:
342
+
343
+ ```javascript
344
+ {
345
+ "data": {
346
+ "type": "comments",
347
+ "attributes": {
348
+ "title": "Rails is unagi",
349
+ "body": "Rails? Omakase? O_O",
350
+ },
351
+ "relationships": {
352
+ "author": {
353
+ "data": {
354
+ "id": "12",
355
+ "type": "users"
356
+ }
357
+ }
358
+ }
359
+ }
360
+ }
361
+ ```
362
+
363
+ By default, attributes are passed through as-is, unless
364
+ you specified an attribute type (`attr('date')`). If
365
+ you specify a transform, the JavaScript value will be
366
+ serialized when inserted into the attributes hash.
367
+
368
+ Belongs-to relationships are converted into JSON-API
369
+ resource identifier objects.
370
+
371
+ ## IDs
372
+
373
+ `serialize` takes an options hash with a single option:
374
+ `includeId`. If this option is `true`, `serialize` will,
375
+ by default include the ID in the JSON object it builds.
376
+
377
+ The JSONAPIAdapter passes in `includeId: true` when serializing a record
378
+ for `createRecord` or `updateRecord`.
379
+
380
+ ## Customization
381
+
382
+ Your server may expect data in a different format than the
383
+ built-in serialization format.
384
+
385
+ In that case, you can implement `serialize` yourself and
386
+ return data formatted to match your API's expectations, or override
387
+ the invoked adapter method and do the serialization in the adapter directly
388
+ by using the provided snapshot.
389
+
390
+ If your API's format differs greatly from the JSON:API spec, you should
391
+ consider authoring your own adapter and serializer instead of extending
392
+ this class.
393
+
394
+ ```js [app/serializers/post.js]
395
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
396
+
397
+ export default class PostSerializer extends JSONAPISerializer {
398
+ serialize(snapshot, options) {
399
+ let json = {
400
+ POST_TTL: snapshot.attr('title'),
401
+ POST_BDY: snapshot.attr('body'),
402
+ POST_CMS: snapshot.hasMany('comments', { ids: true })
403
+ };
404
+
405
+ if (options.includeId) {
406
+ json.POST_ID_ = snapshot.id;
407
+ }
408
+
409
+ return json;
410
+ }
411
+ }
412
+ ```
413
+
414
+ ## Customizing an App-Wide Serializer
415
+
416
+ If you want to define a serializer for your entire
417
+ application, you'll probably want to use `eachAttribute`
418
+ and `eachRelationship` on the record.
419
+
420
+ ```js [app/serializers/application.js]
421
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
422
+ import { underscore, singularize } from '<app-name>/utils/string-utils';
423
+
424
+ export default class ApplicationSerializer extends JSONAPISerializer {
425
+ serialize(snapshot, options) {
426
+ let json = {};
427
+
428
+ snapshot.eachAttribute((name) => {
429
+ json[serverAttributeName(name)] = snapshot.attr(name);
430
+ });
431
+
432
+ snapshot.eachRelationship((name, relationship) => {
433
+ if (relationship.kind === 'hasMany') {
434
+ json[serverHasManyName(name)] = snapshot.hasMany(name, { ids: true });
435
+ }
436
+ });
437
+
438
+ if (options.includeId) {
439
+ json.ID_ = snapshot.id;
440
+ }
441
+
442
+ return json;
443
+ }
444
+ }
445
+
446
+ function serverAttributeName(attribute) {
447
+ return underscore(attribute).toUpperCase();
448
+ }
449
+
450
+ function serverHasManyName(name) {
451
+ return serverAttributeName(singularize(name)) + '_IDS';
452
+ }
453
+ ```
454
+
455
+ This serializer will generate JSON that looks like this:
456
+
457
+ ```javascript
458
+ {
459
+ "TITLE": "Rails is omakase",
460
+ "BODY": "Yep. Omakase.",
461
+ "COMMENT_IDS": [ "1", "2", "3" ]
462
+ }
463
+ ```
464
+
465
+ ## Tweaking the Default Formatting
466
+
467
+ If you just want to do some small tweaks on the default JSON:API formatted response,
468
+ you can call `super.serialize` first and make the tweaks
469
+ on the returned object.
470
+
471
+ ```js [app/serializers/post.js]
472
+ import JSONAPISerializer from '@ember-data/serializer/json-api';
473
+
474
+ export default class PostSerializer extends JSONAPISerializer {
475
+ serialize(snapshot, options) {
476
+ let json = super.serialize(...arguments);
477
+
478
+ json.data.attributes.subject = json.data.attributes.title;
479
+ delete json.data.attributes.title;
480
+
481
+ return json;
482
+ }
483
+ }
484
+ ```
485
+
486
+ @public
487
+ @param {Snapshot} snapshot
488
+ @param {Object} options
489
+ @return {Object} json
490
+ */
491
+ serialize(snapshot: Snapshot, options: any, ...args: any[]): any;
492
+ serializeAttribute(snapshot: any, json: any, key: any, attribute: any): void;
493
+ serializeBelongsTo(snapshot: any, json: any, relationship: any): void;
494
+ serializeHasMany(snapshot: any, json: any, relationship: any): void;
495
+ };
496
+ //# sourceMappingURL=json-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-api.d.ts","sourceRoot":"","sources":["../../src/serializer/json-api.js"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0HE;AACF;;;+BA0FY,KAAK;6BAiCiS,KAAK,qBAAoB,KAAK;uCAgD3U,KAAK,qBAEN,KAAA;wCAOe,KACjB,qBACU,KAAA;oCAI6R,KAAK,qBAAoB,KAAK;0CAsBvR,KAAK,qBACjD,KAAG;wCAgBW,KAAK,qBAAoB,KAAK;qCAiBrB,KAAK,qBAAqB,KAAI;kCAgBjD,KAAK,qBAIT,KAAC;yCAWc,KAAK,qBAAoB,KAAK;yCAoBrC,KAAK,qBAAoB,KAAK;yCAY5B,KAAK,qBAAoB,KAAK;iCAoBnC,KAAK,qBAEH,KAAK;mCAmBO,KACvB,qBAAoB,KACnB;kCAoBK,KAAK,qBAAoB,KAAK;8BAUV,KAAK,qBAEvB,KAAK;;;;;;;;;;;;;qCA+OotJ,QAAQ,6BAA+C,kBAAkB;wBAA06I,QAAQ;4CAAksD,KAAK,YAAwB,QAAQ;iCAAs0B,QAAQ;iCAAk5C,QAAQ;+BAAy8C,QAAQ;;uBAAs5E,KAAK,cAAoB,KAAK;yBAAw7E,KAAK,aAAoB,KAAK;;;;iEAA88G,SAAS;;IA1mB39tB;;;;MAIE;;IAgCF;;;;MAIE;;IAOF;;;;MAIE;;IAqBF;;;;;;MAME;uBAFQ,KAAK;IAQf;;;;;;;;;MASE;8BARQ,KAAK,qBACL,KAAK,oBAEL,eAAa;;;IA6CvB;;;;;;;;MAQE;;IAkBF;;;;;;;;;MASE;;IA4BF;;;;;MAKE;6BAJQ,KAAK;IASf;;;;;;;;;;MAUE;;IAKF;;;;;;;;;MASE;;;;;;;;;;IA8BF;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BE;;IAKF;;;;;;;;;;;;;;;;;;;;;;;;;;MA0BE;;IAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAuKE;wBAHQ,QAAQ;;;;EAiGjB"}