@ember-data/model 5.3.2 → 5.3.4

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 (92) hide show
  1. package/README.md +19 -0
  2. package/addon-main.cjs +5 -0
  3. package/blueprints/model/index.js +18 -5
  4. package/blueprints/model-test/index.js +16 -10
  5. package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +4 -5
  6. package/{addon → dist}/-private.js +2 -2
  7. package/dist/has-many-78F2FHCC.js +674 -0
  8. package/dist/has-many-78F2FHCC.js.map +1 -0
  9. package/dist/hooks-BgrTI_ff.js +75 -0
  10. package/dist/hooks-BgrTI_ff.js.map +1 -0
  11. package/dist/hooks.js +2 -0
  12. package/{addon → dist}/hooks.js.map +1 -1
  13. package/dist/index.js +4 -0
  14. package/{addon → dist}/index.js.map +1 -1
  15. package/dist/migration-support.js +210 -0
  16. package/dist/migration-support.js.map +1 -0
  17. package/{addon/model-YsOraZ6y.js → dist/model-BFnMMaye.js} +889 -424
  18. package/dist/model-BFnMMaye.js.map +1 -0
  19. package/dist/schema-provider-Cgpcwfn7.js +256 -0
  20. package/dist/schema-provider-Cgpcwfn7.js.map +1 -0
  21. package/ember-data-logo-dark.svg +12 -0
  22. package/ember-data-logo-light.svg +12 -0
  23. package/package.json +48 -75
  24. package/unstable-preview-types/-private/attr.d.ts +174 -0
  25. package/unstable-preview-types/-private/attr.d.ts.map +1 -0
  26. package/unstable-preview-types/-private/attr.type-test.d.ts +4 -0
  27. package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
  28. package/unstable-preview-types/-private/belongs-to.d.ts +180 -0
  29. package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
  30. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -0
  31. package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
  32. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -0
  33. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
  34. package/unstable-preview-types/-private/errors.d.ts +305 -0
  35. package/unstable-preview-types/-private/errors.d.ts.map +1 -0
  36. package/unstable-preview-types/-private/has-many.d.ts +169 -0
  37. package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
  38. package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -0
  39. package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
  40. package/unstable-preview-types/-private/hooks.d.ts +13 -0
  41. package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
  42. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -0
  43. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
  44. package/unstable-preview-types/-private/many-array.d.ts +196 -0
  45. package/unstable-preview-types/-private/many-array.d.ts.map +1 -0
  46. package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -0
  47. package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
  48. package/unstable-preview-types/-private/model-methods.d.ts +37 -0
  49. package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
  50. package/unstable-preview-types/-private/model.d.ts +1306 -0
  51. package/unstable-preview-types/-private/model.d.ts.map +1 -0
  52. package/unstable-preview-types/-private/model.type-test.d.ts +4 -0
  53. package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
  54. package/unstable-preview-types/-private/notify-changes.d.ts +8 -0
  55. package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
  56. package/unstable-preview-types/-private/promise-belongs-to.d.ts +48 -0
  57. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
  58. package/unstable-preview-types/-private/promise-many-array.d.ts +131 -0
  59. package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
  60. package/unstable-preview-types/-private/record-state.d.ts +90 -0
  61. package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
  62. package/unstable-preview-types/-private/references/belongs-to.d.ts +503 -0
  63. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
  64. package/unstable-preview-types/-private/references/has-many.d.ts +515 -0
  65. package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
  66. package/unstable-preview-types/-private/schema-provider.d.ts +64 -0
  67. package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
  68. package/unstable-preview-types/-private/type-utils.d.ts +64 -0
  69. package/unstable-preview-types/-private/type-utils.d.ts.map +1 -0
  70. package/unstable-preview-types/-private/util.d.ts +11 -0
  71. package/unstable-preview-types/-private/util.d.ts.map +1 -0
  72. package/unstable-preview-types/-private.d.ts +13 -0
  73. package/unstable-preview-types/-private.d.ts.map +1 -0
  74. package/unstable-preview-types/hooks.d.ts +5 -0
  75. package/unstable-preview-types/hooks.d.ts.map +1 -0
  76. package/unstable-preview-types/index.d.ts +76 -0
  77. package/unstable-preview-types/index.d.ts.map +1 -0
  78. package/unstable-preview-types/migration-support.d.ts +56 -0
  79. package/unstable-preview-types/migration-support.d.ts.map +1 -0
  80. package/addon/has-many-PdQBns8a.js +0 -323
  81. package/addon/has-many-PdQBns8a.js.map +0 -1
  82. package/addon/hooks-dXmQbIOF.js +0 -176
  83. package/addon/hooks-dXmQbIOF.js.map +0 -1
  84. package/addon/hooks.js +0 -1
  85. package/addon/index.js +0 -3
  86. package/addon/migration-support.js +0 -118
  87. package/addon/migration-support.js.map +0 -1
  88. package/addon/model-YsOraZ6y.js.map +0 -1
  89. package/addon/util-3DHZJC9h.js +0 -38
  90. package/addon/util-3DHZJC9h.js.map +0 -1
  91. package/addon-main.js +0 -93
  92. /package/{addon → dist}/-private.js.map +0 -0
@@ -0,0 +1,13 @@
1
+ declare module '@ember-data/model/-private' {
2
+ export { attr } from '@ember-data/model/-private/attr';
3
+ export { belongsTo } from '@ember-data/model/-private/belongs-to';
4
+ export { hasMany } from '@ember-data/model/-private/has-many';
5
+ export { Model } from '@ember-data/model/-private/model';
6
+ export type { ModelStore } from '@ember-data/model/-private/model';
7
+ export { Errors } from '@ember-data/model/-private/errors';
8
+ export { RelatedCollection as ManyArray } from '@ember-data/model/-private/many-array';
9
+ export { PromiseBelongsTo } from '@ember-data/model/-private/promise-belongs-to';
10
+ export { PromiseManyArray } from '@ember-data/model/-private/promise-many-array';
11
+ export { lookupLegacySupport, LEGACY_SUPPORT } from '@ember-data/model/-private/legacy-relationships-support';
12
+ }
13
+ //# sourceMappingURL=-private.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"-private.d.ts","sourceRoot":"","sources":["../src/-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC"}
@@ -0,0 +1,5 @@
1
+ declare module '@ember-data/model/hooks' {
2
+ export { instantiateRecord, teardownRecord, modelFor } from '@ember-data/model/-private/hooks';
3
+ export { buildSchema } from '@ember-data/model/-private/schema-provider';
4
+ }
5
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,76 @@
1
+ /// <reference path="./-private.d.ts" />
2
+ /// <reference path="./hooks.d.ts" />
3
+ /// <reference path="./migration-support.d.ts" />
4
+ /// <reference path="./-private/util.d.ts" />
5
+ /// <reference path="./-private/model.d.ts" />
6
+ /// <reference path="./-private/hooks.d.ts" />
7
+ /// <reference path="./-private/record-state.d.ts" />
8
+ /// <reference path="./-private/attr.type-test.d.ts" />
9
+ /// <reference path="./-private/legacy-relationships-support.d.ts" />
10
+ /// <reference path="./-private/has-many.d.ts" />
11
+ /// <reference path="./-private/promise-many-array.d.ts" />
12
+ /// <reference path="./-private/model-for-mixin.d.ts" />
13
+ /// <reference path="./-private/belongs-to.type-test.d.ts" />
14
+ /// <reference path="./-private/notify-changes.d.ts" />
15
+ /// <reference path="./-private/belongs-to.d.ts" />
16
+ /// <reference path="./-private/many-array.d.ts" />
17
+ /// <reference path="./-private/has-many.type-test.d.ts" />
18
+ /// <reference path="./-private/errors.d.ts" />
19
+ /// <reference path="./-private/type-utils.d.ts" />
20
+ /// <reference path="./-private/schema-provider.d.ts" />
21
+ /// <reference path="./-private/model-methods.d.ts" />
22
+ /// <reference path="./-private/promise-belongs-to.d.ts" />
23
+ /// <reference path="./-private/model.type-test.d.ts" />
24
+ /// <reference path="./-private/attr.d.ts" />
25
+ /// <reference path="./-private/debug/assert-polymorphic-type.d.ts" />
26
+ /// <reference path="./-private/references/has-many.d.ts" />
27
+ /// <reference path="./-private/references/belongs-to.d.ts" />
28
+ declare module '@ember-data/model' {
29
+ /**
30
+ * This package provides a Presentation Model for resource data in an EmberData Cache.
31
+ *
32
+ * Models are defined as classes extending from `import Model from '@ember-data/model';` and the
33
+ * attributes and relationships on these classes are parsed at runtime to supply static "schema"
34
+ * to EmberData's SchemaService.
35
+ *
36
+ * Resource data for individual resources fetched from your API is presented to the UI via instances
37
+ * of the `Model`s you define. An instantiated `Model` is referred to as a `record`.
38
+
39
+ When we refer to the `ModelClass` as opposed to a `Model` or `Record` we are referring
40
+ specifically to the class definition and the static schema methods present on it.
41
+
42
+ When we refer to a `record` we refer to a specific class instance presenting
43
+ the resource data for a given `type` and `id`.
44
+
45
+ ### Defining a Model
46
+
47
+ ```app/models/person.js
48
+ import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
49
+
50
+ export default class PersonModel extends Model {
51
+ @attr name;
52
+
53
+ @belongsTo('pet', { inverse: 'owners', async: false }) dog;
54
+
55
+ @hasMany('person', { inverse: 'friends', async: true }) friends;
56
+ }
57
+ ```
58
+
59
+ ### modelName convention
60
+
61
+ By convention, the name of a given model (its `type`) matches the name
62
+ of the file in the `app/models` folder and should be lowercase, singular
63
+ and dasherized.
64
+
65
+ @module @ember-data/model
66
+ @main @ember-data/model
67
+ */
68
+ export { Model as default, attr, belongsTo, hasMany } from '@ember-data/model/-private';
69
+ export type { PromiseBelongsTo as AsyncBelongsTo } from '@ember-data/model/-private/promise-belongs-to';
70
+ export type { PromiseManyArray as AsyncHasMany } from '@ember-data/model/-private/promise-many-array';
71
+ export type { RelatedCollection as ManyArray } from '@ember-data/model/-private/many-array';
72
+ export type { RelatedCollection as HasMany } from '@ember-data/model/-private/many-array';
73
+ export { instantiateRecord, teardownRecord, modelFor } from '@ember-data/model/-private/hooks';
74
+ export { ModelSchemaProvider } from '@ember-data/model/-private/schema-provider';
75
+ }
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExE,YAAY,EAAE,gBAAgB,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACxF,YAAY,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACtF,YAAY,EAAE,iBAAiB,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC5E,YAAY,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,56 @@
1
+ declare module '@ember-data/model/migration-support' {
2
+ import type Store from '@ember-data/store';
3
+ import type { SchemaService } from '@ember-data/store/types';
4
+ import type { StableRecordIdentifier } from '@warp-drive/core-types';
5
+ import type { ObjectValue } from '@warp-drive/core-types/json/raw';
6
+ import type { Derivation, HashFn, Transformation } from '@warp-drive/core-types/schema/concepts';
7
+ import type { ArrayField, DerivedField, FieldSchema, GenericField, HashField, ObjectField, ResourceSchema } from '@warp-drive/core-types/schema/fields';
8
+ import type { WithPartial } from '@warp-drive/core-types/utils';
9
+ type AttributesSchema = ReturnType<Exclude<SchemaService['attributesDefinitionFor'], undefined>>;
10
+ type RelationshipsSchema = ReturnType<Exclude<SchemaService['relationshipsDefinitionFor'], undefined>>;
11
+ export function withDefaults(schema: WithPartial<ResourceSchema, 'legacy' | 'identity'>): ResourceSchema;
12
+ export function registerDerivations(schema: SchemaService): void;
13
+ export interface DelegatingSchemaService {
14
+ attributesDefinitionFor?(resource: StableRecordIdentifier | {
15
+ type: string;
16
+ }): AttributesSchema;
17
+ relationshipsDefinitionFor?(resource: StableRecordIdentifier | {
18
+ type: string;
19
+ }): RelationshipsSchema;
20
+ doesTypeExist?(type: string): boolean;
21
+ }
22
+ export class DelegatingSchemaService implements SchemaService {
23
+ _preferred: SchemaService;
24
+ _secondary: SchemaService;
25
+ constructor(store: Store, schema: SchemaService);
26
+ hasResource(resource: StableRecordIdentifier | {
27
+ type: string;
28
+ }): boolean;
29
+ hasTrait(type: string): boolean;
30
+ resourceHasTrait(resource: StableRecordIdentifier | {
31
+ type: string;
32
+ }, trait: string): boolean;
33
+ fields(resource: StableRecordIdentifier | {
34
+ type: string;
35
+ }): Map<string, FieldSchema>;
36
+ transformation(field: GenericField | ObjectField | ArrayField | {
37
+ type: string;
38
+ }): Transformation;
39
+ hashFn(field: HashField | {
40
+ type: string;
41
+ }): HashFn;
42
+ derivation(field: DerivedField | {
43
+ type: string;
44
+ }): Derivation;
45
+ resource(resource: StableRecordIdentifier | {
46
+ type: string;
47
+ }): ResourceSchema;
48
+ registerResources(schemas: ResourceSchema[]): void;
49
+ registerResource(schema: ResourceSchema): void;
50
+ registerTransformation(transform: Transformation): void;
51
+ registerDerivation<R, T, FM extends ObjectValue | null>(derivation: Derivation<R, T, FM>): void;
52
+ registerHashFn(hashFn: HashFn): void;
53
+ }
54
+ export {};
55
+ }
56
+ //# sourceMappingURL=migration-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration-support.d.ts","sourceRoot":"","sources":["../src/migration-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,WAAW,EACX,cAAc,EACf,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAoBhE,KAAK,gBAAgB,GAAG,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC;AACjG,KAAK,mBA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CAAC,KAAK,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAGnD,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;IAG9D,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc;IAM7E,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,IAAI;IAGlD,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI;IAG9C,sBAAsB,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI;IAGvD,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,SAAS,WAAW,GAAG,IAAI,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,IAAI;IAG/F,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;CAGrC"}
@@ -1,323 +0,0 @@
1
- import { assert, warn, deprecate } from '@ember/debug';
2
- import { computed } from '@ember/object';
3
- import { recordIdentifierFor } from '@ember-data/store';
4
- import { peekCache } from '@ember-data/store/-private';
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
- import { dasherize } from '@ember/string';
9
- import { singularize } from 'ember-inflector';
10
- function attr(type, options) {
11
- if (typeof type === 'object') {
12
- options = type;
13
- type = undefined;
14
- } else {
15
- options = options || {};
16
- }
17
- const meta = {
18
- type: type,
19
- kind: 'attribute',
20
- isAttribute: true,
21
- options: options,
22
- key: null
23
- };
24
- return computed({
25
- get(key) {
26
- if (macroCondition(getOwnConfig().env.DEBUG)) {
27
- if (['currentState'].indexOf(key) !== -1) {
28
- throw new Error(`'${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()}`);
29
- }
30
- }
31
- if (this.isDestroyed || this.isDestroying) {
32
- return;
33
- }
34
- return peekCache(this).getAttr(recordIdentifierFor(this), key);
35
- },
36
- set(key, value) {
37
- if (macroCondition(getOwnConfig().env.DEBUG)) {
38
- if (['currentState'].indexOf(key) !== -1) {
39
- throw new Error(`'${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()}`);
40
- }
41
- }
42
- assert(`Attempted to set '${key}' on the deleted record ${recordIdentifierFor(this)}`, !this.currentState.isDeleted);
43
- const identifier = recordIdentifierFor(this);
44
- const cache = peekCache(this);
45
- const currentValue = cache.getAttr(identifier, key);
46
- if (currentValue !== value) {
47
- cache.setAttr(identifier, key, value);
48
- if (!this.isValid) {
49
- const {
50
- errors
51
- } = this;
52
- if (errors.get(key)) {
53
- errors.remove(key);
54
- this.currentState.cleanErrorRequests();
55
- }
56
- }
57
- }
58
- return value;
59
- }
60
- }).meta(meta);
61
- }
62
- var attr$1 = computedMacroWithOptionalParams(attr);
63
- function belongsTo(modelName, options) {
64
- const opts = options;
65
- const userEnteredModelName = modelName;
66
- assert(`Expected options.async from @belongsTo('${userEnteredModelName}', options) to be a boolean`, opts && typeof opts.async === 'boolean');
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);
68
- const meta = {
69
- type: normalizeModelName(userEnteredModelName),
70
- isRelationship: true,
71
- options: opts,
72
- kind: 'belongsTo',
73
- name: '<Unknown BelongsTo>',
74
- key: null
75
- };
76
- return computed({
77
- get(key) {
78
- // this is a legacy behavior we may not carry into a new model setup
79
- // it's better to error on disconnected records so users find errors
80
- // in their logic.
81
- if (this.isDestroying || this.isDestroyed) {
82
- return null;
83
- }
84
- const support = lookupLegacySupport(this);
85
- if (macroCondition(getOwnConfig().env.DEBUG)) {
86
- if (['currentState'].indexOf(key) !== -1) {
87
- throw new Error(`'${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()}`);
88
- }
89
- if (Object.prototype.hasOwnProperty.call(opts, 'serialize')) {
90
- warn(`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`, false, {
91
- id: 'ds.model.serialize-option-in-belongs-to'
92
- });
93
- }
94
- if (Object.prototype.hasOwnProperty.call(opts, 'embedded')) {
95
- warn(`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`, false, {
96
- id: 'ds.model.embedded-option-in-belongs-to'
97
- });
98
- }
99
- }
100
- return support.getBelongsTo(key);
101
- },
102
- set(key, value) {
103
- const support = lookupLegacySupport(this);
104
- if (macroCondition(getOwnConfig().env.DEBUG)) {
105
- if (['currentState'].indexOf(key) !== -1) {
106
- throw new Error(`'${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()}`);
107
- }
108
- }
109
- this.store._join(() => {
110
- support.setDirtyBelongsTo(key, value);
111
- });
112
- return support.getBelongsTo(key);
113
- }
114
- }).meta(meta);
115
- }
116
- var belongsTo$1 = computedMacroWithOptionalParams(belongsTo);
117
-
118
- /**
119
- @module @ember-data/model
120
- */
121
- function normalizeType(type) {
122
- if (macroCondition(getOwnConfig().deprecations.DEPRECATE_NON_STRICT_TYPES)) {
123
- const result = singularize(dasherize(type));
124
- deprecate(`The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`, result === type, {
125
- id: 'ember-data:deprecate-non-strict-types',
126
- until: '6.0',
127
- for: 'ember-data',
128
- since: {
129
- available: '5.3',
130
- enabled: '5.3'
131
- }
132
- });
133
- return result;
134
- }
135
- return type;
136
- }
137
-
138
- /**
139
- `hasMany` is used to define One-To-Many and Many-To-Many
140
- relationships on a [Model](/ember-data/release/classes/Model).
141
-
142
- `hasMany` takes an optional hash as a second parameter, currently
143
- supported options are:
144
-
145
- - `async`: A boolean value used to explicitly declare this to be an async relationship. The default is true.
146
- - `inverse`: A string used to identify the inverse property on a related model.
147
- - `polymorphic` A boolean value to mark the relationship as polymorphic
148
-
149
- #### One-To-Many
150
- To declare a one-to-many relationship between two models, use
151
- `belongsTo` in combination with `hasMany`, like this:
152
-
153
- ```app/models/post.js
154
- import Model, { hasMany } from '@ember-data/model';
155
-
156
- export default class PostModel extends Model {
157
- @hasMany('comment') comments;
158
- }
159
- ```
160
-
161
- ```app/models/comment.js
162
- import Model, { belongsTo } from '@ember-data/model';
163
-
164
- export default class CommentModel extends Model {
165
- @belongsTo('post') post;
166
- }
167
- ```
168
-
169
- #### Many-To-Many
170
- To declare a many-to-many relationship between two models, use
171
- `hasMany`:
172
-
173
- ```app/models/post.js
174
- import Model, { hasMany } from '@ember-data/model';
175
-
176
- export default class PostModel extends Model {
177
- @hasMany('tag') tags;
178
- }
179
- ```
180
-
181
- ```app/models/tag.js
182
- import Model, { hasMany } from '@ember-data/model';
183
-
184
- export default class TagModel extends Model {
185
- @hasMany('post') posts;
186
- }
187
- ```
188
-
189
- You can avoid passing a string as the first parameter. In that case Ember Data
190
- will infer the type from the singularized key name.
191
-
192
- ```app/models/post.js
193
- import Model, { hasMany } from '@ember-data/model';
194
-
195
- export default class PostModel extends Model {
196
- @hasMany tags;
197
- }
198
- ```
199
-
200
- will lookup for a Tag type.
201
-
202
- #### Explicit Inverses
203
-
204
- Ember Data will do its best to discover which relationships map to
205
- one another. In the one-to-many code above, for example, Ember Data
206
- can figure out that changing the `comments` relationship should update
207
- the `post` relationship on the inverse because post is the only
208
- relationship to that model.
209
-
210
- However, sometimes you may have multiple `belongsTo`/`hasMany` for the
211
- same type. You can specify which property on the related model is
212
- the inverse using `hasMany`'s `inverse` option:
213
-
214
- ```app/models/comment.js
215
- import Model, { belongsTo } from '@ember-data/model';
216
-
217
- export default class CommentModel extends Model {
218
- @belongsTo('post') onePost;
219
- @belongsTo('post') twoPost
220
- @belongsTo('post') redPost;
221
- @belongsTo('post') bluePost;
222
- }
223
- ```
224
-
225
- ```app/models/post.js
226
- import Model, { hasMany } from '@ember-data/model';
227
-
228
- export default class PostModel extends Model {
229
- @hasMany('comment', {
230
- inverse: 'redPost'
231
- })
232
- comments;
233
- }
234
- ```
235
-
236
- You can also specify an inverse on a `belongsTo`, which works how
237
- you'd expect.
238
-
239
- #### Sync relationships
240
-
241
- Ember Data resolves sync relationships with the related resources
242
- available in its local store, hence it is expected these resources
243
- to be loaded before or along-side the primary resource.
244
-
245
- ```app/models/post.js
246
- import Model, { hasMany } from '@ember-data/model';
247
-
248
- export default class PostModel extends Model {
249
- @hasMany('comment', {
250
- async: false
251
- })
252
- comments;
253
- }
254
- ```
255
-
256
- In contrast to async relationship, accessing a sync relationship
257
- will always return a [ManyArray](/ember-data/release/classes/ManyArray) instance
258
- containing the existing local resources. But it will error on access
259
- when any of the known related resources have not been loaded.
260
-
261
- ```
262
- post.comments.forEach((comment) => {
263
-
264
- });
265
-
266
- ```
267
-
268
- If you are using `links` with sync relationships, you have to use
269
- `ref.reload` to fetch the resources.
270
-
271
- @method hasMany
272
- @public
273
- @static
274
- @for @ember-data/model
275
- @param {String} type (optional) type of the relationship
276
- @param {Object} options (optional) a hash of options
277
- @return {Ember.computed} relationship
278
- */
279
- function hasMany(type, options) {
280
- assert(`Expected hasMany options.async to be a boolean`, options && typeof options.async === 'boolean');
281
-
282
- // Metadata about relationships is stored on the meta of
283
- // the relationship. This is used for introspection and
284
- // serialization. Note that `key` is populated lazily
285
- // the first time the CP is called.
286
- const meta = {
287
- type: normalizeType(type),
288
- options,
289
- isRelationship: true,
290
- kind: 'hasMany',
291
- name: '<Unknown BelongsTo>',
292
- key: null
293
- };
294
- return computed({
295
- get(key) {
296
- if (macroCondition(getOwnConfig().env.DEBUG)) {
297
- if (['currentState'].indexOf(key) !== -1) {
298
- throw new Error(`'${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()}`);
299
- }
300
- }
301
- if (this.isDestroying || this.isDestroyed) {
302
- return [];
303
- }
304
- return lookupLegacySupport(this).getHasMany(key);
305
- },
306
- set(key, records) {
307
- if (macroCondition(getOwnConfig().env.DEBUG)) {
308
- if (['currentState'].indexOf(key) !== -1) {
309
- throw new Error(`'${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()}`);
310
- }
311
- }
312
- const support = lookupLegacySupport(this);
313
- const manyArray = support.getManyArray(key);
314
- assert(`You must pass an array of records to set a hasMany relationship`, Array.isArray(records));
315
- this.store._join(() => {
316
- manyArray.splice(0, manyArray.length, ...records);
317
- });
318
- return support.getHasMany(key);
319
- }
320
- }).meta(meta);
321
- }
322
- var hasMany$1 = computedMacroWithOptionalParams(hasMany);
323
- export { attr$1 as a, belongsTo$1 as b, hasMany$1 as h };
@@ -1 +0,0 @@
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,YA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,CAAC,CAAA;AAED,IAAA,OAAOR,MAAM,CAAA;AACf,GAAA;AAEA,EAAA,OAAO7D,IAAI,CAAA;AACb,CAAA;;AAEA;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;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,QA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