@ember-data/model 5.3.0 → 5.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/addon/-private.js CHANGED
@@ -1,2 +1,2 @@
1
- export { a as attr, b as belongsTo, h as hasMany } from "./has-many-774c4c4b";
2
- export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, M as Model, P as PromiseBelongsTo, a as PromiseManyArray } from "./model-b638e17c";
1
+ export { a as attr, b as belongsTo, h as hasMany } from "./has-many-PdQBns8a";
2
+ export { E as Errors, L as LEGACY_SUPPORT, R as ManyArray, M as Model, P as PromiseBelongsTo, a as PromiseManyArray, l as lookupLegacySupport } from "./model-YsOraZ6y";
@@ -1,107 +1,12 @@
1
- import { macroCondition, getOwnConfig } from '@embroider/macros';
2
1
  import { assert, warn, deprecate } from '@ember/debug';
3
2
  import { computed } from '@ember/object';
4
3
  import { recordIdentifierFor } from '@ember-data/store';
5
4
  import { peekCache } from '@ember-data/store/-private';
6
- import { c as computedMacroWithOptionalParams, n as normalizeModelName, l as lookupLegacySupport } from "./model-b638e17c";
7
- import { A } from '@ember/array';
5
+ import { c as computedMacroWithOptionalParams, n as normalizeModelName } from "./util-3DHZJC9h";
6
+ import { macroCondition, getOwnConfig } from '@embroider/macros';
7
+ import { l as lookupLegacySupport } from "./model-YsOraZ6y";
8
8
  import { dasherize } from '@ember/string';
9
9
  import { singularize } from 'ember-inflector';
10
-
11
- /**
12
- @module @ember-data/model
13
- */
14
-
15
- /**
16
- `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).
17
- By default, attributes are passed through as-is, however you can specify an
18
- optional type to have the value automatically transformed.
19
- Ember Data ships with four basic transform types: `string`, `number`,
20
- `boolean` and `date`. You can define your own transforms by subclassing
21
- [Transform](/ember-data/release/classes/Transform).
22
-
23
- Note that you cannot use `attr` to define an attribute of `id`.
24
-
25
- `attr` takes an optional hash as a second parameter, currently
26
- supported options are:
27
-
28
- - `defaultValue`: Pass a string or a function to be called to set the attribute
29
- to a default value if and only if the key is absent from the payload response.
30
-
31
- Example
32
-
33
- ```app/models/user.js
34
- import Model, { attr } from '@ember-data/model';
35
-
36
- export default class UserModel extends Model {
37
- @attr('string') username;
38
- @attr('string') email;
39
- @attr('boolean', { defaultValue: false }) verified;
40
- }
41
- ```
42
-
43
- Default value can also be a function. This is useful it you want to return
44
- a new object for each attribute.
45
-
46
- ```app/models/user.js
47
- import Model, { attr } from '@ember-data/model';
48
-
49
- export default class UserModel extends Model {
50
- @attr('string') username;
51
- @attr('string') email;
52
-
53
- @attr({
54
- defaultValue() {
55
- return {};
56
- }
57
- })
58
- settings;
59
- }
60
- ```
61
-
62
- The `options` hash is passed as second argument to a transforms'
63
- `serialize` and `deserialize` method. This allows to configure a
64
- transformation and adapt the corresponding value, based on the config:
65
-
66
- ```app/models/post.js
67
- import Model, { attr } from '@ember-data/model';
68
-
69
- export default class PostModel extends Model {
70
- @attr('text', {
71
- uppercase: true
72
- })
73
- text;
74
- }
75
- ```
76
-
77
- ```app/transforms/text.js
78
- export default class TextTransform {
79
- serialize(value, options) {
80
- if (options.uppercase) {
81
- return value.toUpperCase();
82
- }
83
-
84
- return value;
85
- }
86
-
87
- deserialize(value) {
88
- return value;
89
- }
90
-
91
- static create() {
92
- return new this();
93
- }
94
- }
95
- ```
96
-
97
- @method attr
98
- @public
99
- @static
100
- @for @ember-data/model
101
- @param {String|Object} type the attribute type
102
- @param {Object} options a hash of options
103
- @return {Attribute}
104
- */
105
10
  function attr(type, options) {
106
11
  if (typeof type === 'object') {
107
12
  options = type;
@@ -109,10 +14,12 @@ function attr(type, options) {
109
14
  } else {
110
15
  options = options || {};
111
16
  }
112
- let meta = {
17
+ const meta = {
113
18
  type: type,
19
+ kind: 'attribute',
114
20
  isAttribute: true,
115
- options: options
21
+ options: options,
22
+ key: null
116
23
  };
117
24
  return computed({
118
25
  get(key) {
@@ -135,7 +42,7 @@ function attr(type, options) {
135
42
  assert(`Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`, !this.currentState.isDeleted);
136
43
  const identifier = recordIdentifierFor(this);
137
44
  const cache = peekCache(this);
138
- let currentValue = cache.getAttr(identifier, key);
45
+ const currentValue = cache.getAttr(identifier, key);
139
46
  if (currentValue !== value) {
140
47
  cache.setAttr(identifier, key, value);
141
48
  if (!this.isValid) {
@@ -153,112 +60,17 @@ function attr(type, options) {
153
60
  }).meta(meta);
154
61
  }
155
62
  var attr$1 = computedMacroWithOptionalParams(attr);
156
-
157
- /**
158
- @module @ember-data/model
159
- */
160
-
161
- /**
162
- `belongsTo` is used to define One-To-One and One-To-Many
163
- relationships on a [Model](/ember-data/release/classes/Model).
164
-
165
-
166
- `belongsTo` takes an optional hash as a second parameter, currently
167
- supported options are:
168
-
169
- - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.
170
- - `inverse`: A string used to identify the inverse property on a
171
- related model in a One-To-Many relationship. See [Explicit Inverses](#explicit-inverses)
172
- - `polymorphic` A boolean value to mark the relationship as polymorphic
173
-
174
- #### One-To-One
175
- To declare a one-to-one relationship between two models, use
176
- `belongsTo`:
177
-
178
- ```app/models/user.js
179
- import Model, { belongsTo } from '@ember-data/model';
180
-
181
- export default class UserModel extends Model {
182
- @belongsTo('profile') profile;
183
- }
184
- ```
185
-
186
- ```app/models/profile.js
187
- import Model, { belongsTo } from '@ember-data/model';
188
-
189
- export default class ProfileModel extends Model {
190
- @belongsTo('user') user;
191
- }
192
- ```
193
-
194
- #### One-To-Many
195
-
196
- To declare a one-to-many relationship between two models, use
197
- `belongsTo` in combination with `hasMany`, like this:
198
-
199
- ```app/models/post.js
200
- import Model, { hasMany } from '@ember-data/model';
201
-
202
- export default class PostModel extends Model {
203
- @hasMany('comment', { async: false, inverse: 'post' }) comments;
204
- }
205
- ```
206
-
207
- ```app/models/comment.js
208
- import Model, { belongsTo } from '@ember-data/model';
209
-
210
- export default class CommentModel extends Model {
211
- @belongsTo('post', { async: false, inverse: 'comments' }) post;
212
- }
213
- ```
214
-
215
- #### Sync relationships
216
-
217
- Ember Data resolves sync relationships with the related resources
218
- available in its local store, hence it is expected these resources
219
- to be loaded before or along-side the primary resource.
220
-
221
- ```app/models/comment.js
222
- import Model, { belongsTo } from '@ember-data/model';
223
-
224
- export default class CommentModel extends Model {
225
- @belongsTo('post', {
226
- async: false,
227
- inverse: null
228
- })
229
- post;
230
- }
231
- ```
232
-
233
- In contrast to async relationship, accessing a sync relationship
234
- will always return the record (Model instance) for the existing
235
- local resource, or null. But it will error on access when
236
- a related resource is known to exist and it has not been loaded.
237
-
238
- ```
239
- let post = comment.post;
240
-
241
- ```
242
-
243
- @method belongsTo
244
- @public
245
- @static
246
- @for @ember-data/model
247
- @param {String} modelName (optional) type of the relationship
248
- @param {Object} options (optional) a hash of options
249
- @return {Ember.computed} relationship
250
- */
251
63
  function belongsTo(modelName, options) {
252
- let opts = options;
253
- let userEnteredModelName = modelName;
64
+ const opts = options;
65
+ const userEnteredModelName = modelName;
254
66
  assert(`Expected options.async from @belongsTo('${userEnteredModelName}', options) to be a boolean`, opts && typeof opts.async === 'boolean');
255
67
  assert(`Expected options.inverse from @belongsTo('${userEnteredModelName}', options) to be either null or the string type of the related resource.`, opts.inverse === null || typeof opts.inverse === 'string' && opts.inverse.length > 0);
256
- let meta = {
68
+ const meta = {
257
69
  type: normalizeModelName(userEnteredModelName),
258
70
  isRelationship: true,
259
71
  options: opts,
260
72
  kind: 'belongsTo',
261
- name: 'Belongs To',
73
+ name: '<Unknown BelongsTo>',
262
74
  key: null
263
75
  };
264
76
  return computed({
@@ -302,6 +114,10 @@ function belongsTo(modelName, options) {
302
114
  }).meta(meta);
303
115
  }
304
116
  var belongsTo$1 = computedMacroWithOptionalParams(belongsTo);
117
+
118
+ /**
119
+ @module @ember-data/model
120
+ */
305
121
  function normalizeType(type) {
306
122
  if (macroCondition(getOwnConfig().deprecations.DEPRECATE_NON_STRICT_TYPES)) {
307
123
  const result = singularize(dasherize(type));
@@ -467,12 +283,12 @@ function hasMany(type, options) {
467
283
  // the relationship. This is used for introspection and
468
284
  // serialization. Note that `key` is populated lazily
469
285
  // the first time the CP is called.
470
- let meta = {
286
+ const meta = {
471
287
  type: normalizeType(type),
472
288
  options,
473
289
  isRelationship: true,
474
290
  kind: 'hasMany',
475
- name: 'Has Many',
291
+ name: '<Unknown BelongsTo>',
476
292
  key: null
477
293
  };
478
294
  return computed({
@@ -483,7 +299,7 @@ function hasMany(type, options) {
483
299
  }
484
300
  }
485
301
  if (this.isDestroying || this.isDestroyed) {
486
- return A();
302
+ return [];
487
303
  }
488
304
  return lookupLegacySupport(this).getHasMany(key);
489
305
  },
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-many-PdQBns8a.js","sources":["../src/-private/attr.js","../src/-private/belongs-to.js","../src/-private/has-many.js"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\nimport { recordIdentifierFor } from '@ember-data/store';\nimport { peekCache } from '@ember-data/store/-private';\n\nimport { computedMacroWithOptionalParams } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `attr` defines an attribute on a [Model](/ember-data/release/classes/Model).\n By default, attributes are passed through as-is, however you can specify an\n optional type to have the value automatically transformed.\n Ember Data ships with four basic transform types: `string`, `number`,\n `boolean` and `date`. You can define your own transforms by subclassing\n [Transform](/ember-data/release/classes/Transform).\n\n Note that you cannot use `attr` to define an attribute of `id`.\n\n `attr` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `defaultValue`: Pass a string or a function to be called to set the attribute\n to a default value if and only if the key is absent from the payload response.\n\n Example\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n @attr('boolean', { defaultValue: false }) verified;\n }\n ```\n\n Default value can also be a function. This is useful it you want to return\n a new object for each attribute.\n\n ```app/models/user.js\n import Model, { attr } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @attr('string') username;\n @attr('string') email;\n\n @attr({\n defaultValue() {\n return {};\n }\n })\n settings;\n }\n ```\n\n The `options` hash is passed as second argument to a transforms'\n `serialize` and `deserialize` method. This allows to configure a\n transformation and adapt the corresponding value, based on the config:\n\n ```app/models/post.js\n import Model, { attr } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @attr('text', {\n uppercase: true\n })\n text;\n }\n ```\n\n ```app/transforms/text.js\n export default class TextTransform {\n serialize(value, options) {\n if (options.uppercase) {\n return value.toUpperCase();\n }\n\n return value;\n }\n\n deserialize(value) {\n return value;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @method attr\n @public\n @static\n @for @ember-data/model\n @param {String|Object} type the attribute type\n @param {Object} options a hash of options\n @return {Attribute}\n*/\nfunction attr(type, options) {\n if (typeof type === 'object') {\n options = type;\n type = undefined;\n } else {\n options = options || {};\n }\n\n const meta = {\n type: type,\n kind: 'attribute',\n isAttribute: true,\n options: options,\n key: null,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroyed || this.isDestroying) {\n return;\n }\n return peekCache(this).getAttr(recordIdentifierFor(this), key);\n },\n set(key, value) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your attr on ${this.constructor.toString()}`\n );\n }\n }\n assert(\n `Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`,\n !this.currentState.isDeleted\n );\n const identifier = recordIdentifierFor(this);\n const cache = peekCache(this);\n\n const currentValue = cache.getAttr(identifier, key);\n if (currentValue !== value) {\n cache.setAttr(identifier, key, value);\n\n if (!this.isValid) {\n const { errors } = this;\n if (errors.get(key)) {\n errors.remove(key);\n this.currentState.cleanErrorRequests();\n }\n }\n }\n\n return value;\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(attr);\n","import { assert, warn } from '@ember/debug';\nimport { computed } from '@ember/object';\n\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './legacy-relationships-support';\nimport { computedMacroWithOptionalParams, normalizeModelName } from './util';\n\n/**\n @module @ember-data/model\n*/\n\n/**\n `belongsTo` is used to define One-To-One and One-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n\n `belongsTo` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a\n related model in a One-To-Many relationship. See [Explicit Inverses](#explicit-inverses)\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-One\n To declare a one-to-one relationship between two models, use\n `belongsTo`:\n\n ```app/models/user.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class UserModel extends Model {\n @belongsTo('profile') profile;\n }\n ```\n\n ```app/models/profile.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class ProfileModel extends Model {\n @belongsTo('user') user;\n }\n ```\n\n #### One-To-Many\n\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', { async: false, inverse: 'post' }) comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', { async: false, inverse: 'comments' }) post;\n }\n ```\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post', {\n async: false,\n inverse: null\n })\n post;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return the record (Model instance) for the existing\n local resource, or null. But it will error on access when\n a related resource is known to exist and it has not been loaded.\n\n ```\n let post = comment.post;\n\n ```\n\n @method belongsTo\n @public\n @static\n @for @ember-data/model\n @param {String} modelName (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction belongsTo(modelName, options) {\n const opts = options;\n const userEnteredModelName = modelName;\n\n assert(\n `Expected options.async from @belongsTo('${userEnteredModelName}', options) to be a boolean`,\n opts && typeof opts.async === 'boolean'\n );\n assert(\n `Expected options.inverse from @belongsTo('${userEnteredModelName}', options) to be either null or the string type of the related resource.`,\n opts.inverse === null || (typeof opts.inverse === 'string' && opts.inverse.length > 0)\n );\n\n const meta = {\n type: normalizeModelName(userEnteredModelName),\n isRelationship: true,\n options: opts,\n kind: 'belongsTo',\n name: '<Unknown BelongsTo>',\n key: null,\n };\n\n return computed({\n get(key) {\n // this is a legacy behavior we may not carry into a new model setup\n // it's better to error on disconnected records so users find errors\n // in their logic.\n if (this.isDestroying || this.isDestroyed) {\n return null;\n }\n const support = lookupLegacySupport(this);\n\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n if (Object.prototype.hasOwnProperty.call(opts, 'serialize')) {\n warn(\n `You provided a serialize option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See Serializer and it's implementations https://api.emberjs.com/ember-data/release/classes/Serializer`,\n false,\n {\n id: 'ds.model.serialize-option-in-belongs-to',\n }\n );\n }\n\n if (Object.prototype.hasOwnProperty.call(opts, 'embedded')) {\n warn(\n `You provided an embedded option on the \"${key}\" property in the \"${support.identifier.type}\" class, this belongs in the serializer. See EmbeddedRecordsMixin https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin`,\n false,\n {\n id: 'ds.model.embedded-option-in-belongs-to',\n }\n );\n }\n }\n\n return support.getBelongsTo(key);\n },\n set(key, value) {\n const support = lookupLegacySupport(this);\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your belongsTo on ${this.constructor.toString()}`\n );\n }\n }\n this.store._join(() => {\n support.setDirtyBelongsTo(key, value);\n });\n\n return support.getBelongsTo(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(belongsTo);\n","/**\n @module @ember-data/model\n*/\nimport { assert, deprecate } from '@ember/debug';\nimport { computed } from '@ember/object';\nimport { dasherize } from '@ember/string';\n\nimport { singularize } from 'ember-inflector';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@ember-data/deprecations';\nimport { DEBUG } from '@ember-data/env';\n\nimport { lookupLegacySupport } from './legacy-relationships-support';\nimport { computedMacroWithOptionalParams } from './util';\n\nfunction normalizeType(type) {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = singularize(dasherize(type));\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '5.3',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n\n/**\n `hasMany` is used to define One-To-Many and Many-To-Many\n relationships on a [Model](/ember-data/release/classes/Model).\n\n `hasMany` takes an optional hash as a second parameter, currently\n supported options are:\n\n - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.\n - `inverse`: A string used to identify the inverse property on a related model.\n - `polymorphic` A boolean value to mark the relationship as polymorphic\n\n #### One-To-Many\n To declare a one-to-many relationship between two models, use\n `belongsTo` in combination with `hasMany`, like this:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment') comments;\n }\n ```\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') post;\n }\n ```\n\n #### Many-To-Many\n To declare a many-to-many relationship between two models, use\n `hasMany`:\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('tag') tags;\n }\n ```\n\n ```app/models/tag.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class TagModel extends Model {\n @hasMany('post') posts;\n }\n ```\n\n You can avoid passing a string as the first parameter. In that case Ember Data\n will infer the type from the singularized key name.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany tags;\n }\n ```\n\n will lookup for a Tag type.\n\n #### Explicit Inverses\n\n Ember Data will do its best to discover which relationships map to\n one another. In the one-to-many code above, for example, Ember Data\n can figure out that changing the `comments` relationship should update\n the `post` relationship on the inverse because post is the only\n relationship to that model.\n\n However, sometimes you may have multiple `belongsTo`/`hasMany` for the\n same type. You can specify which property on the related model is\n the inverse using `hasMany`'s `inverse` option:\n\n ```app/models/comment.js\n import Model, { belongsTo } from '@ember-data/model';\n\n export default class CommentModel extends Model {\n @belongsTo('post') onePost;\n @belongsTo('post') twoPost\n @belongsTo('post') redPost;\n @belongsTo('post') bluePost;\n }\n ```\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n inverse: 'redPost'\n })\n comments;\n }\n ```\n\n You can also specify an inverse on a `belongsTo`, which works how\n you'd expect.\n\n #### Sync relationships\n\n Ember Data resolves sync relationships with the related resources\n available in its local store, hence it is expected these resources\n to be loaded before or along-side the primary resource.\n\n ```app/models/post.js\n import Model, { hasMany } from '@ember-data/model';\n\n export default class PostModel extends Model {\n @hasMany('comment', {\n async: false\n })\n comments;\n }\n ```\n\n In contrast to async relationship, accessing a sync relationship\n will always return a [ManyArray](/ember-data/release/classes/ManyArray) instance\n containing the existing local resources. But it will error on access\n when any of the known related resources have not been loaded.\n\n ```\n post.comments.forEach((comment) => {\n\n });\n\n ```\n\n If you are using `links` with sync relationships, you have to use\n `ref.reload` to fetch the resources.\n\n @method hasMany\n @public\n @static\n @for @ember-data/model\n @param {String} type (optional) type of the relationship\n @param {Object} options (optional) a hash of options\n @return {Ember.computed} relationship\n*/\nfunction hasMany(type, options) {\n assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');\n\n // Metadata about relationships is stored on the meta of\n // the relationship. This is used for introspection and\n // serialization. Note that `key` is populated lazily\n // the first time the CP is called.\n const meta = {\n type: normalizeType(type),\n options,\n isRelationship: true,\n kind: 'hasMany',\n name: '<Unknown BelongsTo>',\n key: null,\n };\n\n return computed({\n get(key) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n if (this.isDestroying || this.isDestroyed) {\n return [];\n }\n return lookupLegacySupport(this).getHasMany(key);\n },\n set(key, records) {\n if (DEBUG) {\n if (['currentState'].indexOf(key) !== -1) {\n throw new Error(\n `'${key}' is a reserved property name on instances of classes extending Model. Please choose a different property name for your hasMany on ${this.constructor.toString()}`\n );\n }\n }\n const support = lookupLegacySupport(this);\n const manyArray = support.getManyArray(key);\n assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));\n this.store._join(() => {\n manyArray.splice(0, manyArray.length, ...records);\n });\n\n return support.getHasMany(key);\n },\n }).meta(meta);\n}\n\nexport default computedMacroWithOptionalParams(hasMany);\n"],"names":["attr","type","options","undefined","meta","kind","isAttribute","key","computed","get","macroCondition","getOwnConfig","env","DEBUG","indexOf","Error","constructor","toString","isDestroyed","isDestroying","peekCache","getAttr","recordIdentifierFor","set","value","assert","currentState","isDeleted","identifier","cache","currentValue","setAttr","isValid","errors","remove","cleanErrorRequests","computedMacroWithOptionalParams","belongsTo","modelName","opts","userEnteredModelName","async","inverse","length","normalizeModelName","isRelationship","name","support","lookupLegacySupport","Object","prototype","hasOwnProperty","call","warn","id","getBelongsTo","store","_join","setDirtyBelongsTo","normalizeType","deprecations","DEPRECATE_NON_STRICT_TYPES","result","singularize","dasherize","deprecate","until","for","since","available","enabled","hasMany","getHasMany","records","manyArray","getManyArray","Array","isArray","splice"],"mappings":";;;;;;;;;;AAuGA,SAASA,IAAIA,CAACC,IAAI,EAAEC,OAAO,EAAE;AAC3B,EAAA,IAAI,OAAOD,IAAI,KAAK,QAAQ,EAAE;AAC5BC,IAAAA,OAAO,GAAGD,IAAI,CAAA;AACdA,IAAAA,IAAI,GAAGE,SAAS,CAAA;AAClB,GAAC,MAAM;AACLD,IAAAA,OAAO,GAAGA,OAAO,IAAI,EAAE,CAAA;AACzB,GAAA;AAEA,EAAA,MAAME,IAAI,GAAG;AACXH,IAAAA,IAAI,EAAEA,IAAI;AACVI,IAAAA,IAAI,EAAE,WAAW;AACjBC,IAAAA,WAAW,EAAE,IAAI;AACjBJ,IAAAA,OAAO,EAAEA,OAAO;AAChBK,IAAAA,GAAG,EAAE,IAAA;GACN,CAAA;AAED,EAAA,OAAOC,QAAQ,CAAC;IACdC,GAAGA,CAACF,GAAG,EAAE;AACP,MAAA,IAAAG,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;QACT,IAAI,CAAC,cAAc,CAAC,CAACC,OAAO,CAACP,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;AACxC,UAAA,MAAM,IAAIQ,KAAK,CACZ,CAAA,CAAA,EAAGR,GAAI,CAAkI,gIAAA,EAAA,IAAI,CAACS,WAAW,CAACC,QAAQ,EAAG,EACxK,CAAC,CAAA;AACH,SAAA;AACF,OAAA;AACA,MAAA,IAAI,IAAI,CAACC,WAAW,IAAI,IAAI,CAACC,YAAY,EAAE;AACzC,QAAA,OAAA;AACF,OAAA;AACA,MAAA,OAAOC,SAAS,CAAC,IAAI,CAAC,CAACC,OAAO,CAACC,mBAAmB,CAAC,IAAI,CAAC,EAAEf,GAAG,CAAC,CAAA;KAC/D;AACDgB,IAAAA,GAAGA,CAAChB,GAAG,EAAEiB,KAAK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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASsE,OAAOA,CAACtE,IAAI,EAAEC,OAAO,EAAE;EAC9BuB,MAAM,CAAE,CAA+C,8CAAA,CAAA,EAAEvB,OAAO,IAAI,OAAOA,OAAO,CAACuC,KAAK,KAAK,SAAS,CAAC,CAAA;;AAEvG;AACA;AACA;AACA;AACA,EAAA,MAAMrC,IAAI,GAAG;AACXH,IAAAA,IAAI,EAAE0D,aAAa,CAAC1D,IAAI,CAAC;IACzBC,OAAO;AACP2C,IAAAA,cAAc,EAAE,IAAI;AACpBxC,IAAAA,IAAI,EAAE,SAAS;AACfyC,IAAAA,IAAI,EAAE,qBAAqB;AAC3BvC,IAAAA,GAAG,EAAE,IAAA;GACN,CAAA;AAED,EAAA,OAAOC,QAAQ,CAAC;IACdC,GAAGA,CAACF,GAAG,EAAE;AACP,MAAA,IAAAG,cAAA,CAAAC,YAAA,GAAAC,GAAA,CAAAC,KAAA,CAAW,EAAA;QACT,IAAI,CAAC,cAAc,CAAC,CAACC,OAAO,CAACP,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;AACxC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,CAACH,IAAI,CAACA,IAAI,CAAC,CAAA;AACf,CAAA;AAEA,gBAAegC,+BAA+B,CAACmC,OAAO,CAAC;;;;"}
@@ -1,14 +1,12 @@
1
1
  import { getOwner, setOwner } from '@ember/application';
2
2
  import { assert } from '@ember/debug';
3
3
  import { setRecordIdentifier, StoreMap, setCacheFor } from '@ember-data/store/-private';
4
- import { M as Model, n as normalizeModelName } from "./model-b638e17c";
4
+ import { M as Model } from "./model-YsOraZ6y";
5
+ import { n as normalizeModelName } from "./util-3DHZJC9h";
5
6
 
6
7
  /*
7
8
  In case someone defined a relationship to a mixin, for example:
8
- ```
9
- import Model, { belongsTo, hasMany } from '@ember-data/model';
10
- import Mixin from '@ember/object/mixin';
11
-
9
+ ```ts
12
10
  class CommentModel extends Model {
13
11
  @belongsTo('commentable', { polymorphic: true }) owner;
14
12
  }
@@ -23,15 +21,15 @@ import { M as Model, n as normalizeModelName } from "./model-b638e17c";
23
21
  in this case
24
22
  */
25
23
  function modelForMixin(store, normalizedModelName) {
26
- let owner = getOwner(store);
27
- let MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
28
- let mixin = MaybeMixin && MaybeMixin.class;
24
+ const owner = getOwner(store);
25
+ const MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);
26
+ const mixin = MaybeMixin && MaybeMixin.class;
29
27
  if (mixin) {
30
- let ModelForMixin = Model.extend(mixin);
28
+ const ModelForMixin = Model.extend(mixin);
31
29
  ModelForMixin.__isMixin = true;
32
30
  ModelForMixin.__mixin = mixin;
33
31
  //Cache the class as a model
34
- owner.register('model:' + normalizedModelName, ModelForMixin);
32
+ owner.register(`model:${normalizedModelName}`, ModelForMixin);
35
33
  }
36
34
  return owner.factoryFor(`model:${normalizedModelName}`);
37
35
  }
@@ -40,6 +38,26 @@ class ModelSchemaProvider {
40
38
  this.store = store;
41
39
  this._relationshipsDefCache = Object.create(null);
42
40
  this._attributesDefCache = Object.create(null);
41
+ this._fieldsDefCache = Object.create(null);
42
+ }
43
+ fields(identifier) {
44
+ const {
45
+ type
46
+ } = identifier;
47
+ let fieldDefs = this._fieldsDefCache[type];
48
+ if (fieldDefs === undefined) {
49
+ fieldDefs = new Map();
50
+ this._fieldsDefCache[type] = fieldDefs;
51
+ const attributes = this.attributesDefinitionFor(identifier);
52
+ const relationships = this.relationshipsDefinitionFor(identifier);
53
+ for (const attr of Object.values(attributes)) {
54
+ fieldDefs.set(attr.name, attr);
55
+ }
56
+ for (const rel of Object.values(relationships)) {
57
+ fieldDefs.set(rel.name, rel);
58
+ }
59
+ }
60
+ return fieldDefs;
43
61
  }
44
62
 
45
63
  // Following the existing RD implementation
@@ -50,8 +68,8 @@ class ModelSchemaProvider {
50
68
  let attributes;
51
69
  attributes = this._attributesDefCache[type];
52
70
  if (attributes === undefined) {
53
- let modelClass = this.store.modelFor(type);
54
- let attributeMap = modelClass.attributes;
71
+ const modelClass = this.store.modelFor(type);
72
+ const attributeMap = modelClass.attributes;
55
73
  attributes = Object.create(null);
56
74
  attributeMap.forEach((meta, name) => attributes[name] = meta);
57
75
  this._attributesDefCache[type] = attributes;
@@ -67,7 +85,7 @@ class ModelSchemaProvider {
67
85
  let relationships;
68
86
  relationships = this._relationshipsDefCache[type];
69
87
  if (relationships === undefined) {
70
- let modelClass = this.store.modelFor(type);
88
+ const modelClass = this.store.modelFor(type);
71
89
  relationships = modelClass.relationshipsObject || null;
72
90
  this._relationshipsDefCache[type] = relationships;
73
91
  }
@@ -99,9 +117,9 @@ function getModelFactory(store, type) {
99
117
  // we don't cache misses in case someone wants to register a missing model
100
118
  return null;
101
119
  }
102
- let klass = factory.class;
120
+ const klass = factory.class;
103
121
  if (klass.isModel) {
104
- let hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');
122
+ const hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');
105
123
  if (!hasOwnModelNameSet) {
106
124
  Object.defineProperty(klass, 'modelName', {
107
125
  value: type
@@ -138,6 +156,7 @@ function teardownRecord(record) {
138
156
  record.destroy();
139
157
  }
140
158
  function modelFor(modelName) {
159
+ assert(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`, !this.isDestroyed && !this.isDestroying);
141
160
  assert(`You need to pass a model name to the store's modelFor method`, modelName);
142
161
  assert(`Please pass a proper model name to the store's modelFor method`, typeof modelName === 'string' && modelName.length);
143
162
  const type = normalizeModelName(modelName);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks-dXmQbIOF.js","sources":["../src/-private/model-for-mixin.ts","../src/-private/schema-provider.ts","../src/-private/hooks.ts"],"sourcesContent":["import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\n\nimport Model, { type ModelFactory } from './model';\n\n/*\n In case someone defined a relationship to a mixin, for example:\n ```ts\n class CommentModel extends Model {\n @belongsTo('commentable', { polymorphic: true }) owner;\n }\n\n let Commentable = Mixin.create({\n @hasMany('comment') comments;\n });\n ```\n we want to look up a Commentable class which has all the necessary\n relationship meta data. Thus, we look up the mixin and create a mock\n Model, so we can access the relationship CPs of the mixin (`comments`)\n in this case\n */\nexport default function modelForMixin(store: Store, normalizedModelName: string): ModelFactory | undefined {\n const owner = getOwner(store)!;\n const MaybeMixin = owner.factoryFor(`mixin:${normalizedModelName}`);\n const mixin = MaybeMixin && MaybeMixin.class;\n if (mixin) {\n const ModelForMixin = Model.extend(mixin);\n ModelForMixin.__isMixin = true;\n ModelForMixin.__mixin = mixin;\n //Cache the class as a model\n owner.register(`model:${normalizedModelName}`, ModelForMixin);\n }\n return owner.factoryFor(`model:${normalizedModelName}`) as ModelFactory | undefined;\n}\n","import { getOwner } from '@ember/application';\n\nimport type Store from '@ember-data/store';\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\nimport type { RecordIdentifier } from '@warp-drive/core-types/identifier';\nimport type { AttributesSchema, RelationshipsSchema } from '@warp-drive/core-types/schema';\n\nimport type { FactoryCache, ModelFactory, ModelStore } from './model';\nimport type Model from './model';\nimport _modelForMixin from './model-for-mixin';\nimport { normalizeModelName } from './util';\n\nexport class ModelSchemaProvider {\n declare store: ModelStore;\n declare _relationshipsDefCache: Record<string, RelationshipsSchema>;\n declare _attributesDefCache: Record<string, AttributesSchema>;\n declare _fieldsDefCache: Record<string, Map<string, FieldSchema>>;\n\n constructor(store: ModelStore) {\n this.store = store;\n this._relationshipsDefCache = Object.create(null) as Record<string, RelationshipsSchema>;\n this._attributesDefCache = Object.create(null) as Record<string, AttributesSchema>;\n this._fieldsDefCache = Object.create(null) as Record<string, Map<string, FieldSchema>>;\n }\n\n fields(identifier: RecordIdentifier | { type: string }): Map<string, FieldSchema> {\n const { type } = identifier;\n let fieldDefs: Map<string, FieldSchema> | undefined = this._fieldsDefCache[type];\n\n if (fieldDefs === undefined) {\n fieldDefs = new Map();\n this._fieldsDefCache[type] = fieldDefs;\n\n const attributes = this.attributesDefinitionFor(identifier);\n const relationships = this.relationshipsDefinitionFor(identifier);\n\n for (const attr of Object.values(attributes)) {\n fieldDefs.set(attr.name, attr);\n }\n\n for (const rel of Object.values(relationships)) {\n fieldDefs.set(rel.name, rel);\n }\n }\n\n return fieldDefs;\n }\n\n // Following the existing RD implementation\n attributesDefinitionFor(identifier: RecordIdentifier | { type: string }): AttributesSchema {\n const { type } = identifier;\n let attributes: AttributesSchema;\n\n attributes = this._attributesDefCache[type];\n\n if (attributes === undefined) {\n const modelClass = this.store.modelFor(type);\n const attributeMap = modelClass.attributes;\n\n attributes = Object.create(null) as AttributesSchema;\n attributeMap.forEach((meta, name) => (attributes[name] = meta));\n this._attributesDefCache[type] = attributes;\n }\n\n return attributes;\n }\n\n // Following the existing RD implementation\n relationshipsDefinitionFor(identifier: RecordIdentifier | { type: string }): RelationshipsSchema {\n const { type } = identifier;\n let relationships: RelationshipsSchema;\n\n relationships = this._relationshipsDefCache[type];\n\n if (relationships === undefined) {\n const modelClass = this.store.modelFor(type) as typeof Model;\n relationships = modelClass.relationshipsObject || null;\n this._relationshipsDefCache[type] = relationships;\n }\n\n return relationships;\n }\n\n doesTypeExist(modelName: string): boolean {\n const type = normalizeModelName(modelName);\n const factory = getModelFactory(this.store, type);\n\n return factory !== null;\n }\n}\n\nexport function buildSchema(store: Store) {\n return new ModelSchemaProvider(store as ModelStore);\n}\n\nexport function getModelFactory(store: ModelStore, type: string): ModelFactory | null {\n if (!store._modelFactoryCache) {\n store._modelFactoryCache = Object.create(null) as FactoryCache;\n }\n const cache = store._modelFactoryCache;\n let factory: ModelFactory | undefined = cache[type];\n\n if (!factory) {\n const owner = getOwner(store)!;\n factory = owner.factoryFor(`model:${type}`) as ModelFactory | undefined;\n\n if (!factory) {\n //Support looking up mixins as base types for polymorphic relationships\n factory = _modelForMixin(store, type);\n }\n\n if (!factory) {\n // we don't cache misses in case someone wants to register a missing model\n return null;\n }\n\n const klass = factory.class;\n\n if (klass.isModel) {\n const hasOwnModelNameSet = klass.modelName && Object.prototype.hasOwnProperty.call(klass, 'modelName');\n if (!hasOwnModelNameSet) {\n Object.defineProperty(klass, 'modelName', { value: type });\n }\n }\n\n cache[type] = factory;\n }\n\n return factory;\n}\n","import { getOwner, setOwner } from '@ember/application';\nimport { assert } from '@ember/debug';\n\nimport { setCacheFor, setRecordIdentifier, type Store, StoreMap } from '@ember-data/store/-private';\nimport type { StableRecordIdentifier } from '@warp-drive/core-types';\nimport type { Cache } from '@warp-drive/core-types/cache';\n\nimport type { ModelStore } from './model';\nimport type Model from './model';\nimport { getModelFactory } from './schema-provider';\nimport { normalizeModelName } from './util';\n\nfunction recast(context: Store): asserts context is ModelStore {}\n\nexport function instantiateRecord(\n this: Store,\n identifier: StableRecordIdentifier,\n createRecordArgs: { [key: string]: unknown }\n): Model {\n const type = identifier.type;\n\n recast(this);\n\n const cache = this.cache;\n // TODO deprecate allowing unknown args setting\n const createOptions = {\n _createProps: createRecordArgs,\n // TODO @deprecate consider deprecating accessing record properties during init which the below is necessary for\n _secretInit: {\n identifier,\n cache,\n store: this,\n cb: secretInit,\n },\n };\n\n // ensure that `getOwner(this)` works inside a model instance\n setOwner(createOptions, getOwner(this)!);\n const factory = getModelFactory(this, type);\n\n assert(`No model was found for '${type}'`, factory);\n return factory.class.create(createOptions);\n}\n\nexport function teardownRecord(record: Model): void {\n assert(\n `expected to receive an instance of Model from @ember-data/model. If using a custom model make sure you implement teardownRecord`,\n 'destroy' in record\n );\n record.destroy();\n}\n\nexport function modelFor(this: Store, modelName: string): typeof Model | void {\n assert(\n `Attempted to call store.modelFor(), but the store instance has already been destroyed.`,\n !this.isDestroyed && !this.isDestroying\n );\n assert(`You need to pass a model name to the store's modelFor method`, modelName);\n assert(\n `Please pass a proper model name to the store's modelFor method`,\n typeof modelName === 'string' && modelName.length\n );\n recast(this);\n\n const type = normalizeModelName(modelName);\n const maybeFactory = getModelFactory(this, type);\n const klass = maybeFactory && maybeFactory.class ? maybeFactory.class : null;\n\n const ignoreType = !klass || !klass.isModel || this._forceShim;\n if (!ignoreType) {\n return klass;\n }\n assert(\n `No model was found for '${type}' and no schema handles the type`,\n this.getSchemaDefinitionService().doesTypeExist(type)\n );\n}\n\nfunction secretInit(record: Model, cache: Cache, identifier: StableRecordIdentifier, store: Store): void {\n setRecordIdentifier(record, identifier);\n StoreMap.set(record, store);\n setCacheFor(record, cache);\n}\n"],"names":["modelForMixin","store","normalizedModelName","owner","getOwner","MaybeMixin","factoryFor","mixin","class","ModelForMixin","Model","extend","__isMixin","__mixin","register","ModelSchemaProvider","constructor","_relationshipsDefCache","Object","create","_attributesDefCache","_fieldsDefCache","fields","identifier","type","fieldDefs","undefined","Map","attributes","attributesDefinitionFor","relationships","relationshipsDefinitionFor","attr","values","set","name","rel","modelClass","modelFor","attributeMap","forEach","meta","relationshipsObject","doesTypeExist","modelName","normalizeModelName","factory","getModelFactory","buildSchema","_modelFactoryCache","cache","_modelForMixin","klass","isModel","hasOwnModelNameSet","prototype","hasOwnProperty","call","defineProperty","value","instantiateRecord","createRecordArgs","createOptions","_createProps","_secretInit","cb","secretInit","setOwner","assert","teardownRecord","record","destroy","isDestroyed","isDestroying","length","maybeFactory","ignoreType","_forceShim","getSchemaDefinitionService","setRecordIdentifier","StoreMap","setCacheFor"],"mappings":";;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,aAAaA,CAACC,KAAY,EAAEC,mBAA2B,EAA4B;AACzG,EAAA,MAAMC,KAAK,GAAGC,QAAQ,CAACH,KAAK,CAAE,CAAA;EAC9B,MAAMI,UAAU,GAAGF,KAAK,CAACG,UAAU,CAAE,CAAA,MAAA,EAAQJ,mBAAoB,CAAA,CAAC,CAAC,CAAA;AACnE,EAAA,MAAMK,KAAK,GAAGF,UAAU,IAAIA,UAAU,CAACG,KAAK,CAAA;AAC5C,EAAA,IAAID,KAAK,EAAE;AACT,IAAA,MAAME,aAAa,GAAGC,KAAK,CAACC,MAAM,CAACJ,KAAK,CAAC,CAAA;IACzCE,aAAa,CAACG,SAAS,GAAG,IAAI,CAAA;IAC9BH,aAAa,CAACI,OAAO,GAAGN,KAAK,CAAA;AAC7B;IACAJ,KAAK,CAACW,QAAQ,CAAE,CAAA,MAAA,EAAQZ,mBAAoB,CAAC,CAAA,EAAEO,aAAa,CAAC,CAAA;AAC/D,GAAA;AACA,EAAA,OAAON,KAAK,CAACG,UAAU,CAAE,CAAQJ,MAAAA,EAAAA,mBAAoB,EAAC,CAAC,CAAA;AACzD;;ACtBO,MAAMa,mBAAmB,CAAC;EAM/BC,WAAWA,CAACf,KAAiB,EAAE;IAC7B,IAAI,CAACA,KAAK,GAAGA,KAAK,CAAA;IAClB,IAAI,CAACgB,sBAAsB,GAAGC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAwC,CAAA;IACxF,IAAI,CAACC,mBAAmB,GAAGF,MAAM,CAACC,MAAM,CAAC,IAAI,CAAqC,CAAA;IAClF,IAAI,CAACE,eAAe,GAAGH,MAAM,CAACC,MAAM,CAAC,IAAI,CAA6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wB,MAAM,CACH,CAA+D,8DAAA,CAAA,EAChE,OAAOxB,SAAS,KAAK,QAAQ,IAAIA,SAAS,CAAC8B,MAC7C,CAAC,CAAA;AAGD,EAAA,MAAMlD,IAAI,GAAGqB,kBAAkB,CAACD,SAAS,CAAC,CAAA;AAC1C,EAAA,MAAM+B,YAAY,GAAG5B,eAAe,CAAC,IAAI,EAAEvB,IAAI,CAAC,CAAA;AAChD,EAAA,MAAM4B,KAAK,GAAGuB,YAAY,IAAIA,YAAY,CAACnE,KAAK,GAAGmE,YAAY,CAACnE,KAAK,GAAG,IAAI,CAAA;AAE5E,EAAA,MAAMoE,UAAU,GAAG,CAACxB,KAAK,IAAI,CAACA,KAAK,CAACC,OAAO,IAAI,IAAI,CAACwB,UAAU,CAAA;EAC9D,IAAI,CAACD,UAAU,EAAE;AACf,IAAA,OAAOxB,KAAK,CAAA;AACd,GAAA;AACAgB,EAAAA,MAAM,CACH,CAAA,wBAAA,EAA0B5C,IAAK,CAAA,gCAAA,CAAiC,EACjE,IAAI,CAACsD,0BAA0B,EAAE,CAACnC,aAAa,CAACnB,IAAI,CACtD,CAAC,CAAA;AACH,CAAA;AAEA,SAAS0C,UAAUA,CAACI,MAAa,EAAEpB,KAAY,EAAE3B,UAAkC,EAAEtB,KAAY,EAAQ;AACvG8E,EAAAA,mBAAmB,CAACT,MAAM,EAAE/C,UAAU,CAAC,CAAA;AACvCyD,EAAAA,QAAQ,CAAC9C,GAAG,CAACoC,MAAM,EAAErE,KAAK,CAAC,CAAA;AAC3BgF,EAAAA,WAAW,CAACX,MAAM,EAAEpB,KAAK,CAAC,CAAA;AAC5B;;;;"}
package/addon/hooks.js CHANGED
@@ -1 +1 @@
1
- export { b as buildSchema, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-6d5c2fc2";
1
+ export { b as buildSchema, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-dXmQbIOF";
package/addon/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { a as attr, b as belongsTo, h as hasMany } from "./has-many-774c4c4b";
2
- export { M as default } from "./model-b638e17c";
3
- export { M as ModelSchemaProvider, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-6d5c2fc2";
1
+ export { a as attr, b as belongsTo, h as hasMany } from "./has-many-PdQBns8a";
2
+ export { M as default } from "./model-YsOraZ6y";
3
+ export { M as ModelSchemaProvider, i as instantiateRecord, m as modelFor, t as teardownRecord } from "./hooks-dXmQbIOF";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -0,0 +1,118 @@
1
+ import { assert } from '@ember/debug';
2
+ import { recordIdentifierFor } from '@ember-data/store';
3
+ import { u as unloadRecord, s as serialize, b as save, r as rollbackAttributes, c as reload, h as hasMany, E as Errors, d as destroyRecord, e as deleteRecord, f as RecordState, g as changedAttributes, i as belongsTo, j as createSnapshot } from "./model-YsOraZ6y";
4
+ // 'isDestroying', 'isDestroyed'
5
+ const LegacyFields = ['_createSnapshot', 'adapterError', 'belongsTo', 'changedAttributes', 'constructor', 'currentState', 'deleteRecord', 'destroyRecord', 'dirtyType', 'errors', 'hasDirtyAttributes', 'hasMany', 'isDeleted', 'isEmpty', 'isError', 'isLoaded', 'isLoading', 'isNew', 'isSaving', 'isValid', 'reload', 'rollbackAttributes', 'save', 'serialize', 'unloadRecord'];
6
+ const LegacySupport = new WeakMap();
7
+ function legacySupport(record, options, prop) {
8
+ let state = LegacySupport.get(record);
9
+ if (!state) {
10
+ state = {};
11
+ LegacySupport.set(record, state);
12
+ }
13
+ switch (prop) {
14
+ case '_createSnapshot':
15
+ return createSnapshot;
16
+ case 'adapterError':
17
+ return record.currentState.adapterError;
18
+ case 'belongsTo':
19
+ return belongsTo;
20
+ case 'changedAttributes':
21
+ return changedAttributes;
22
+ case 'constructor':
23
+ return state._constructor = state._constructor || {
24
+ isModel: true,
25
+ name: `Record<${recordIdentifierFor(record).type}>`,
26
+ modelName: recordIdentifierFor(record).type
27
+ };
28
+ case 'currentState':
29
+ return state.recordState = state.recordState || new RecordState(record);
30
+ case 'deleteRecord':
31
+ return deleteRecord;
32
+ case 'destroyRecord':
33
+ return destroyRecord;
34
+ case 'dirtyType':
35
+ return record.currentState.dirtyType;
36
+ case 'errors':
37
+ // @ts-expect-error
38
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
39
+ return state.errors = state.errors || Errors.create({
40
+ __record: record
41
+ });
42
+ case 'hasDirtyAttributes':
43
+ return record.currentState.isDirty;
44
+ case 'hasMany':
45
+ return hasMany;
46
+ case 'isDeleted':
47
+ return record.currentState.isDeleted;
48
+ case 'isEmpty':
49
+ return record.currentState.isEmpty;
50
+ case 'isError':
51
+ return record.currentState.isError;
52
+ case 'isLoaded':
53
+ return record.currentState.isLoaded;
54
+ case 'isLoading':
55
+ return record.currentState.isLoading;
56
+ case 'isNew':
57
+ return record.currentState.isNew;
58
+ case 'isSaving':
59
+ return record.currentState.isSaving;
60
+ case 'isValid':
61
+ return record.currentState.isValid;
62
+ case 'reload':
63
+ return reload;
64
+ case 'rollbackAttributes':
65
+ return rollbackAttributes;
66
+ case 'save':
67
+ return save;
68
+ case 'serialize':
69
+ return serialize;
70
+ case 'unloadRecord':
71
+ return unloadRecord;
72
+ default:
73
+ assert(`${prop} is not a supported legacy field`, false);
74
+ }
75
+ }
76
+ function withFields(fields) {
77
+ LegacyFields.forEach(field => {
78
+ fields.push({
79
+ type: '@legacy',
80
+ name: field,
81
+ kind: 'derived'
82
+ });
83
+ });
84
+ fields.push({
85
+ name: 'id',
86
+ kind: '@id',
87
+ type: null
88
+ });
89
+ fields.push({
90
+ name: 'isReloading',
91
+ kind: '@local',
92
+ type: 'boolean',
93
+ options: {
94
+ defaultValue: false
95
+ }
96
+ });
97
+ fields.push({
98
+ name: 'isDestroying',
99
+ kind: '@local',
100
+ type: 'boolean',
101
+ options: {
102
+ defaultValue: false
103
+ }
104
+ });
105
+ fields.push({
106
+ name: 'isDestroyed',
107
+ kind: '@local',
108
+ type: 'boolean',
109
+ options: {
110
+ defaultValue: false
111
+ }
112
+ });
113
+ return fields;
114
+ }
115
+ function registerDerivations(schema) {
116
+ schema.registerDerivation('@legacy', legacySupport);
117
+ }
118
+ export { registerDerivations, withFields };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-support.js","sources":["../src/migration-support.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { recordIdentifierFor } from '@ember-data/store';\nimport type { FieldSchema } from '@ember-data/store/-types/q/schema-service';\n\nimport { Errors } from './-private';\nimport type { MinimalLegacyRecord } from './-private/model-methods';\nimport {\n belongsTo,\n changedAttributes,\n createSnapshot,\n deleteRecord,\n destroyRecord,\n hasMany,\n reload,\n rollbackAttributes,\n save,\n serialize,\n unloadRecord,\n} from './-private/model-methods';\nimport RecordState from './-private/record-state';\n\ntype Derivation<R, T> = (record: R, options: Record<string, unknown> | null, prop: string) => T;\ntype SchemaService = {\n registerDerivation(name: string, derivation: Derivation<unknown, unknown>): void;\n};\n// 'isDestroying', 'isDestroyed'\nconst LegacyFields = [\n '_createSnapshot',\n 'adapterError',\n 'belongsTo',\n 'changedAttributes',\n 'constructor',\n 'currentState',\n 'deleteRecord',\n 'destroyRecord',\n 'dirtyType',\n 'errors',\n 'hasDirtyAttributes',\n 'hasMany',\n 'isDeleted',\n 'isEmpty',\n 'isError',\n 'isLoaded',\n 'isLoading',\n 'isNew',\n 'isSaving',\n 'isValid',\n 'reload',\n 'rollbackAttributes',\n 'save',\n 'serialize',\n 'unloadRecord',\n];\n\nconst LegacySupport = new WeakMap<MinimalLegacyRecord, Record<string, unknown>>();\n\nfunction legacySupport(record: MinimalLegacyRecord, options: Record<string, unknown> | null, prop: string): unknown {\n let state = LegacySupport.get(record);\n if (!state) {\n state = {};\n LegacySupport.set(record, state);\n }\n\n switch (prop) {\n case '_createSnapshot':\n return createSnapshot;\n case 'adapterError':\n return record.currentState.adapterError;\n case 'belongsTo':\n return belongsTo;\n case 'changedAttributes':\n return changedAttributes;\n case 'constructor':\n return (state._constructor = state._constructor || {\n isModel: true,\n name: `Record<${recordIdentifierFor(record).type}>`,\n modelName: recordIdentifierFor(record).type,\n });\n case 'currentState':\n return (state.recordState = state.recordState || new RecordState(record));\n case 'deleteRecord':\n return deleteRecord;\n case 'destroyRecord':\n return destroyRecord;\n case 'dirtyType':\n return record.currentState.dirtyType;\n case 'errors':\n // @ts-expect-error\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n return (state.errors = state.errors || Errors.create({ __record: record }));\n case 'hasDirtyAttributes':\n return record.currentState.isDirty;\n case 'hasMany':\n return hasMany;\n case 'isDeleted':\n return record.currentState.isDeleted;\n case 'isEmpty':\n return record.currentState.isEmpty;\n case 'isError':\n return record.currentState.isError;\n case 'isLoaded':\n return record.currentState.isLoaded;\n case 'isLoading':\n return record.currentState.isLoading;\n case 'isNew':\n return record.currentState.isNew;\n case 'isSaving':\n return record.currentState.isSaving;\n case 'isValid':\n return record.currentState.isValid;\n case 'reload':\n return reload;\n case 'rollbackAttributes':\n return rollbackAttributes;\n case 'save':\n return save;\n case 'serialize':\n return serialize;\n case 'unloadRecord':\n return unloadRecord;\n default:\n assert(`${prop} is not a supported legacy field`, false);\n }\n}\n\nexport function withFields(fields: FieldSchema[]) {\n LegacyFields.forEach((field) => {\n fields.push({\n type: '@legacy',\n name: field,\n kind: 'derived',\n });\n });\n fields.push({\n name: 'id',\n kind: '@id',\n type: null,\n });\n fields.push({\n name: 'isReloading',\n kind: '@local',\n type: 'boolean',\n options: { defaultValue: false },\n });\n fields.push({\n name: 'isDestroying',\n kind: '@local',\n type: 'boolean',\n options: { defaultValue: false },\n });\n fields.push({\n name: 'isDestroyed',\n kind: '@local',\n type: 'boolean',\n options: { defaultValue: false },\n });\n return fields;\n}\n\nexport function registerDerivations(schema: SchemaService) {\n schema.registerDerivation('@legacy', legacySupport as Derivation<unknown, unknown>);\n}\n"],"names":["LegacyFields","LegacySupport","WeakMap","legacySupport","record","options","prop","state","get","set","createSnapshot","currentState","adapterError","belongsTo","changedAttributes","_constructor","isModel","name","recordIdentifierFor","type","modelName","recordState","RecordState","deleteRecord","destroyRecord","dirtyType","errors","Errors","create","__record","isDirty","hasMany","isDeleted","isEmpty","isError","isLoaded","isLoading","isNew","isSaving","isValid","reload","rollbackAttributes","save","serialize","unloadRecord","assert","withFields","fields","forEach","field","push","kind","defaultValue","registerDerivations","schema","registerDerivation"],"mappings":";;;;;;;;;;AA0BA;AACA,MAAMA,YAAY,GAAG,CACnB,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,SAAS,EACT,WAAW,EACX,SAAS,EACT,SAAS,EACT,UAAU,EACV,WAAW,EACX,OAAO,EACP,UAAU,EACV,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,MAAM,EACN,WAAW,EACX,cAAc,CACf,CAAA;AAED,MAAMC,aAAa,GAAG,IAAIC,OAAO,EAAgD,CAAA;AAEjF,SAASC,aAAaA,CAACC,MAA2B,EAAEC,OAAuC,EAAEC,IAAY,EAAW;AAClH,EAAA,IAAIC,KAAK,GAAGN,aAAa,CAACO,GAAG,CAACJ,MAAM,CAAC,CAAA;EACrC,IAAI,CAACG,KAAK,EAAE;IACVA,KAAK,GAAG,EAAE,CAAA;AACVN,IAAAA,aAAa,CAACQ,GAAG,CAACL,MAAM,EAAEG,KAAK,CAAC,CAAA;AAClC,GAAA;AAEA,EAAA,QAAQD,IAAI;AACV,IAAA,KAAK,iBAAiB;AACpB,MAAA,OAAOI,cAAc,CAAA;AACvB,IAAA,KAAK,cAAc;AACjB,MAAA,OAAON,MAAM,CAACO,YAAY,CAACC,YAAY,CAAA;AACzC,IAAA,KAAK,WAAW;AACd,MAAA,OAAOC,SAAS,CAAA;AAClB,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