@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,221 @@
1
+ import { tracked, cached } from '@glimmer/tracking';
2
+ import { Context } from '@warp-drive/core/reactive/-private';
3
+ import { a as decorateFieldV2, i as initializeDeferredDecorator, d as decorateMethodV2 } from "./runtime-BPCpkOf1-BKOwiRJp.js";
4
+ class Fragment {
5
+ static {
6
+ decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
7
+ return false;
8
+ });
9
+ }
10
+ #isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
11
+ static {
12
+ decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
13
+ return false;
14
+ });
15
+ }
16
+ #isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
17
+ get hasDirtyAttributes() {
18
+ const {
19
+ path,
20
+ resourceKey,
21
+ store
22
+ } = this[Context];
23
+ const record = store.peekRecord(resourceKey);
24
+ if (record.hasDirtyAttributes && path) {
25
+ const root = path.at(0);
26
+ return root in record.changedAttributes();
27
+ }
28
+ return false;
29
+ }
30
+ static {
31
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
32
+ }
33
+ get isFragment() {
34
+ return true;
35
+ }
36
+ get $type() {
37
+ const {
38
+ field
39
+ } = this[Context];
40
+ return field?.type;
41
+ }
42
+ rollbackAttributes() {
43
+ const {
44
+ path,
45
+ resourceKey,
46
+ store
47
+ } = this[Context];
48
+ if (path) {
49
+ const oldValue = store.cache.getRemoteAttr(resourceKey, path);
50
+ store.cache.setAttr(resourceKey, path, oldValue);
51
+ }
52
+ }
53
+ }
54
+ const FragmentExtension = {
55
+ kind: 'object',
56
+ name: 'fragment',
57
+ features: Fragment
58
+ };
59
+ class FragmentArray {
60
+ static {
61
+ decorateFieldV2(this.prototype, "isDestroying", [tracked], function () {
62
+ return false;
63
+ });
64
+ }
65
+ #isDestroying = (initializeDeferredDecorator(this, "isDestroying"), void 0); // We might want to check the parent values once we move this code to warp-drive.
66
+ static {
67
+ decorateFieldV2(this.prototype, "isDestroyed", [tracked], function () {
68
+ return false;
69
+ });
70
+ }
71
+ #isDestroyed = (initializeDeferredDecorator(this, "isDestroyed"), void 0);
72
+ get hasDirtyAttributes() {
73
+ const {
74
+ path,
75
+ resourceKey,
76
+ store
77
+ } = this[Context];
78
+ const record = store.peekRecord(resourceKey);
79
+ if (record.hasDirtyAttributes && path) {
80
+ const root = path.at(0);
81
+ return root in record.changedAttributes();
82
+ }
83
+ return false;
84
+ }
85
+ static {
86
+ decorateMethodV2(this.prototype, "hasDirtyAttributes", [cached]);
87
+ }
88
+ addFragment(fragment) {
89
+ if (!fragment) {
90
+ return;
91
+ }
92
+ return this.addObject(fragment);
93
+ }
94
+ createFragment(fragment) {
95
+ if (!fragment) {
96
+ return;
97
+ }
98
+ return this.pushObject(fragment);
99
+ }
100
+ removeFragment(fragment) {
101
+ if (!fragment) {
102
+ return;
103
+ }
104
+ const index = this.indexOf(fragment);
105
+ if (index !== -1) {
106
+ this.splice(index, 1);
107
+ }
108
+ }
109
+ rollbackAttributes() {
110
+ for (const fragment of this) {
111
+ // @ts-expect-error TODO: fix these types
112
+ fragment?.rollbackAttributes?.();
113
+ }
114
+ }
115
+ }
116
+ const FragmentArrayExtension = {
117
+ kind: 'array',
118
+ name: 'fragment-array',
119
+ features: FragmentArray
120
+ };
121
+
122
+ // if modelFor turns out to be a bottleneck we should replace with a Map
123
+ // and clear it during store teardown.
124
+ const AvailableShims = new WeakMap();
125
+ function getShimClass(store, modelName) {
126
+ let shims = AvailableShims.get(store);
127
+ if (!shims) {
128
+ shims = Object.create(null);
129
+ AvailableShims.set(store, shims);
130
+ }
131
+ let shim = shims[modelName];
132
+ if (shim === undefined) {
133
+ shim = shims[modelName] = new ShimModelClass(store, modelName);
134
+ }
135
+ return shim;
136
+ }
137
+ const AttributeKinds = ['field', 'attribute', 'object', 'array', 'schema-object', 'schema-array'];
138
+
139
+ // Mimics the static apis of @warp-drive/legacy/model
140
+ class ShimModelClass {
141
+ constructor(store, modelName) {
142
+ this.__store = store;
143
+ this.modelName = modelName;
144
+ }
145
+ get fields() {
146
+ const fields = new Map();
147
+ const fieldSchemas = this.__store.schema.fields({
148
+ type: this.modelName
149
+ });
150
+ fieldSchemas.forEach((schema, key) => {
151
+ // @ts-expect-error checking if a string is a valid string
152
+ if (AttributeKinds.includes(schema.kind)) {
153
+ fields.set(key, 'attribute');
154
+ } else if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
155
+ fields.set(key, schema.kind);
156
+ }
157
+ });
158
+ return fields;
159
+ }
160
+ get attributes() {
161
+ const attrs = new Map();
162
+ const fields = this.__store.schema.fields({
163
+ type: this.modelName
164
+ });
165
+ fields.forEach((schema, key) => {
166
+ if (schema.kind === 'attribute') {
167
+ attrs.set(key, schema);
168
+ // @ts-expect-error checking if a string is a valid string
169
+ } else if (AttributeKinds.includes(schema.kind)) {
170
+ attrs.set(key, {
171
+ kind: 'attribute',
172
+ name: key,
173
+ type: null,
174
+ options: schema.options ?? {}
175
+ });
176
+ }
177
+ });
178
+ return attrs;
179
+ }
180
+ get relationshipsByName() {
181
+ const rels = new Map();
182
+ const fields = this.__store.schema.fields({
183
+ type: this.modelName
184
+ });
185
+ fields.forEach((schema, key) => {
186
+ if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
187
+ rels.set(key, schema);
188
+ }
189
+ });
190
+ return rels;
191
+ }
192
+ eachAttribute(callback, binding) {
193
+ this.attributes.forEach((schema, key) => {
194
+ callback.call(binding, key, schema);
195
+ });
196
+ }
197
+ eachRelationship(callback, binding) {
198
+ this.__store.schema.fields({
199
+ type: this.modelName
200
+ }).forEach((schema, key) => {
201
+ if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {
202
+ callback.call(binding, key, schema);
203
+ }
204
+ });
205
+ }
206
+ eachTransformedAttribute(callback, binding) {
207
+ this.__store.schema.fields({
208
+ type: this.modelName
209
+ }).forEach((schema, key) => {
210
+ if (schema.kind === 'attribute') {
211
+ const type = schema.type;
212
+ if (type) callback.call(binding, key, type);
213
+ }
214
+ });
215
+ }
216
+ }
217
+ function fragmentsModelFor(modelName) {
218
+ return getShimClass(this, modelName);
219
+ }
220
+ const modelFor = fragmentsModelFor;
221
+ export { FragmentExtension as F, FragmentArrayExtension as a, FragmentArray as b, Fragment as c, fragmentsModelFor as f, modelFor as m };
@@ -0,0 +1,76 @@
1
+ import { singularize, pluralize } from '@warp-drive/utilities/string';
2
+ import { withDefaults } from './model/migration-support.js';
3
+ import { F as FragmentExtension, a as FragmentArrayExtension } from "./model-for-CqXsIKws.js";
4
+ export { c as Fragment, b as FragmentArray, m as modelFor } from "./model-for-CqXsIKws.js";
5
+
6
+ /**
7
+ * Used as a helper to setup the relevant parts of an array
8
+ * schema and add extensions etc.
9
+ *
10
+ * @param arrayName The name of the array
11
+ * @returns The schema for an array
12
+ */
13
+ function withArrayDefaults(arrayName) {
14
+ return {
15
+ kind: 'array',
16
+ name: arrayName,
17
+ type: `array:${singularize(arrayName)}`,
18
+ options: {
19
+ arrayExtensions: ['ember-object', 'ember-array-like', 'fragment-array']
20
+ }
21
+ };
22
+ }
23
+
24
+ /**
25
+ * Used as a helper to setup the relevant parts of a fragment schema
26
+ * and add extensions etc.
27
+ *
28
+ * @param fragmentType The type of the fragment
29
+ * @param fragmentName The optional name of the fragment. If not provided, it will default to the fragmentType.
30
+ * @returns The schema for a fragment
31
+ */
32
+ function withFragmentDefaults(fragmentType, fragmentName) {
33
+ return {
34
+ kind: 'schema-object',
35
+ type: `fragment:${fragmentType}`,
36
+ name: fragmentName ?? fragmentType,
37
+ options: {
38
+ objectExtensions: ['ember-object', 'fragment']
39
+ }
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Used as a helper to setup the relevant parts of a fragment-array
45
+ * schema and add extensions etc.
46
+ *
47
+ * @param fragmentArrayType The type of the fragment-array
48
+ * @param fragmentArrayName The name of the fragment-array
49
+ * @returns The schema for a fragment-array
50
+ */
51
+ function withFragmentArrayDefaults(fragmentArrayType, fragmentArrayName) {
52
+ return {
53
+ kind: 'schema-array',
54
+ type: `fragment:${singularize(fragmentArrayType)}`,
55
+ name: fragmentArrayName ?? pluralize(fragmentArrayType),
56
+ options: {
57
+ arrayExtensions: ['ember-object', 'ember-array-like', 'fragment-array'],
58
+ defaultValue: true
59
+ }
60
+ };
61
+ }
62
+ function withLegacy(schema) {
63
+ return withDefaults({
64
+ ...schema,
65
+ identity: {
66
+ kind: '@id',
67
+ name: 'id'
68
+ },
69
+ objectExtensions: ['ember-object', 'fragment']
70
+ });
71
+ }
72
+ function registerFragmentExtensions(schema) {
73
+ schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentExtension);
74
+ schema.CAUTION_MEGA_DANGER_ZONE_registerExtension?.(FragmentArrayExtension);
75
+ }
76
+ export { FragmentArrayExtension, FragmentExtension, registerFragmentExtensions, withArrayDefaults, withFragmentArrayDefaults, withFragmentDefaults, withLegacy };
package/dist/model.js CHANGED
@@ -4,12 +4,11 @@ import { RecordStore } from '@warp-drive/core/types/symbols';
4
4
  import { i as isElementDescriptor, n as normalizeModelName } from "./util-Dul6TZts.js";
5
5
  import { macroCondition, getGlobalConfig } from '@embroider/macros';
6
6
  import { warn, deprecate } from '@ember/debug';
7
- import { assertPrivateStore, setRecordIdentifier, StoreMap } from '@warp-drive/core/store/-private';
8
- import { l as lookupLegacySupport } from "./errors-8kD2mSe_.js";
7
+ import { assertPrivateStore } from '@warp-drive/core/store/-private';
8
+ import { l as lookupLegacySupport } from "./errors-Cz5KrzBk.js";
9
9
  import { singularize, dasherize } from '@warp-drive/utilities/string';
10
- import { l as getModelFactory } from "./schema-provider-DQu4Rjco.js";
11
- export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-DQu4Rjco.js";
12
- import { setOwner, getOwner } from '@ember/application';
10
+ export { M as Model, b as buildSchema, M as default, m as restoreDeprecatedModelRequestBehaviors } from "./schema-provider-DJCV_6AF.js";
11
+ export { i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-D6diaM34.js";
13
12
  function _attr(type, options) {
14
13
  if (typeof type === 'object') {
15
14
  options = type;
@@ -87,12 +86,12 @@ function _attr(type, options) {
87
86
  */
88
87
 
89
88
  /**
90
- `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
89
+ `attr` defines an attribute on a {@link Model}.
91
90
  By default, attributes are passed through as-is, however you can specify an
92
91
  optional type to have the value automatically transformed.
93
- EmberData ships with four basic transform types: `string`, `number`,
92
+ WarpDrive ships with four basic transform types: `string`, `number`,
94
93
  `boolean` and `date`. You can define your own transforms by subclassing
95
- [Transform](/ember-data/release/classes/Transform).
94
+ {@link Transform}.
96
95
 
97
96
  Note that you cannot use `attr` to define an attribute of `id`.
98
97
 
@@ -169,9 +168,8 @@ function _attr(type, options) {
169
168
  ```
170
169
 
171
170
  @public
172
- @param {String|Object} type the attribute type
173
- @param {Object} options a hash of options
174
- @return {Attribute}
171
+ @param type the attribute type
172
+ @param options a hash of options
175
173
  */
176
174
 
177
175
  // see note on DataDecorator for why void
@@ -258,7 +256,7 @@ function _belongsTo(type, options) {
258
256
 
259
257
  /**
260
258
  `belongsTo` is used to define One-To-One and One-To-Many, and One-To-None
261
- relationships on a [Model](/ember-data/release/classes/Model).
259
+ relationships on a {@link Model}.
262
260
 
263
261
  `belongsTo` takes a configuration hash as a second parameter, currently
264
262
  supported options are:
@@ -340,7 +338,7 @@ function _belongsTo(type, options) {
340
338
 
341
339
  #### Sync vs Async Relationships
342
340
 
343
- EmberData fulfills relationships using resource data available in
341
+ WarpDrive fulfills relationships using resource data available in
344
342
  the cache.
345
343
 
346
344
  Sync relationships point directly to the known related resources.
@@ -408,9 +406,8 @@ function _belongsTo(type, options) {
408
406
  type each record satisfies on both sides.
409
407
 
410
408
  @public
411
- @param {String} type (optional) the name of the related resource
412
- @param {Object} options (optional) a hash of options
413
- @return {PropertyDescriptor} relationship
409
+ @param type the name of the related resource
410
+ @param options a hash of options
414
411
  */
415
412
 
416
413
  // export function belongsTo<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
@@ -497,7 +494,7 @@ function _hasMany(type, options) {
497
494
 
498
495
  /**
499
496
  `hasMany` is used to define Many-To-One and Many-To-Many, and Many-To-None
500
- relationships on a [Model](/ember-data/release/classes/Model).
497
+ relationships on a {@link Model}.
501
498
 
502
499
  `hasMany` takes a configuration hash as a second parameter, currently
503
500
  supported options are:
@@ -580,7 +577,7 @@ function _hasMany(type, options) {
580
577
 
581
578
  #### Sync vs Async Relationships
582
579
 
583
- EmberData fulfills relationships using resource data available in
580
+ WarpDrive fulfills relationships using resource data available in
584
581
  the cache.
585
582
 
586
583
  Sync relationships point directly to the known related resources.
@@ -648,9 +645,8 @@ function _hasMany(type, options) {
648
645
  type each record satisfies on both sides.
649
646
 
650
647
  @public
651
- @param {String} type (optional) the name of the related resource
652
- @param {Object} options (optional) a hash of options
653
- @return {PropertyDescriptor} relationship
648
+ @param type the name of the related resource
649
+ @param options a hash of options
654
650
  */
655
651
 
656
652
  // export function hasMany<K extends Promise<unknown>, T extends Awaited<K> = Awaited<K>>(
@@ -668,72 +664,4 @@ function hasMany(type, options) {
668
664
  }
669
665
  return _hasMany(type, options);
670
666
  }
671
- function instantiateRecord(identifier, createRecordArgs) {
672
- const type = identifier.type;
673
-
674
- // TODO deprecate allowing unknown args setting
675
- const createOptions = {
676
- _createProps: createRecordArgs,
677
- // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for
678
- _secretInit: {
679
- identifier,
680
- store: this,
681
- cb: secretInit
682
- }
683
- };
684
-
685
- // ensure that `getOwner(this)` works inside a model instance
686
- setOwner(createOptions, getOwner(this));
687
- const factory = getModelFactory(this, type);
688
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
689
- if (!test) {
690
- throw new Error(`No model was found for '${type}'`);
691
- }
692
- })(factory) : {};
693
- return factory.class.create(createOptions);
694
- }
695
- function teardownRecord(record) {
696
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
697
- if (!test) {
698
- throw new Error(`expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`);
699
- }
700
- })('destroy' in record) : {};
701
- record.destroy();
702
- }
703
- function modelFor(modelName) {
704
- assertPrivateStore(this);
705
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
706
- if (!test) {
707
- throw new Error(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`);
708
- }
709
- })(!this.isDestroyed && !this.isDestroying) : {};
710
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
711
- if (!test) {
712
- throw new Error(`You need to pass a model name to the store's modelFor method`);
713
- }
714
- })(modelName) : {};
715
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
716
- if (!test) {
717
- throw new Error(`Please pass a proper model name to the store's modelFor method`);
718
- }
719
- })(typeof modelName === 'string' && modelName.length) : {};
720
- const type = normalizeModelName(modelName);
721
- const maybeFactory = getModelFactory(this, type);
722
- const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;
723
- const ignoreType = !klass || !klass.isModel || this._forceShim;
724
- if (!ignoreType) {
725
- return klass;
726
- }
727
- macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
728
- if (!test) {
729
- throw new Error(`No model was found for '${type}' and no schema handles the type`);
730
- }
731
- })(this.schema.hasResource({
732
- type
733
- })) : {};
734
- }
735
- function secretInit(record, identifier, store) {
736
- setRecordIdentifier(record, identifier);
737
- StoreMap.set(record, store);
738
- }
739
- export { attr, belongsTo, hasMany, instantiateRecord, modelFor, teardownRecord };
667
+ export { attr, belongsTo, hasMany };