@ember-data/model 4.10.0-alpha.2 → 4.10.0-alpha.21

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 (40) hide show
  1. package/addon/{-private/diff-array.ts → -private.js} +41 -13
  2. package/addon/-private.js.map +1 -0
  3. package/addon/has-many-357b6265.js +6277 -0
  4. package/addon/has-many-357b6265.js.map +1 -0
  5. package/addon/index.js +1 -0
  6. package/addon/index.js.map +1 -0
  7. package/addon-main.js +90 -0
  8. package/package.json +43 -15
  9. package/addon/-private/attr.js +0 -162
  10. package/addon/-private/belongs-to.js +0 -268
  11. package/addon/-private/debug/assert-polymorphic-type.js +0 -71
  12. package/addon/-private/deprecated-promise-proxy.ts +0 -76
  13. package/addon/-private/errors.ts +0 -425
  14. package/addon/-private/has-many.js +0 -280
  15. package/addon/-private/index.ts +0 -14
  16. package/addon/-private/legacy-data-fetch.js +0 -395
  17. package/addon/-private/legacy-data-utils.ts +0 -92
  18. package/addon/-private/legacy-relationships-support.ts +0 -774
  19. package/addon/-private/many-array.ts +0 -401
  20. package/addon/-private/model-for-mixin.ts +0 -38
  21. package/addon/-private/model.js +0 -2516
  22. package/addon/-private/notify-changes.ts +0 -72
  23. package/addon/-private/promise-belongs-to.ts +0 -73
  24. package/addon/-private/promise-many-array.ts +0 -425
  25. package/addon/-private/promise-proxy-base.js +0 -4
  26. package/addon/-private/record-state.ts +0 -468
  27. package/addon/-private/references/belongs-to.ts +0 -624
  28. package/addon/-private/references/has-many.ts +0 -669
  29. package/addon/-private/relationship-meta.ts +0 -98
  30. package/addon/-private/util.ts +0 -31
  31. package/addon/index.ts +0 -39
  32. package/blueprints/model/HELP.md +0 -26
  33. package/blueprints/model/files/__root__/__path__/__name__.js +0 -5
  34. package/blueprints/model/index.js +0 -158
  35. package/blueprints/model/native-files/__root__/__path__/__name__.js +0 -5
  36. package/blueprints/model-test/index.js +0 -33
  37. package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +0 -18
  38. package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +0 -15
  39. package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +0 -14
  40. package/index.js +0 -47
@@ -1,98 +0,0 @@
1
- import { dasherize } from '@ember/string';
2
- import { DEBUG } from '@glimmer/env';
3
-
4
- import { singularize } from 'ember-inflector';
5
-
6
- import type Store from '@ember-data/store';
7
- import type { RelationshipSchema } from '@ember-data/types/q/record-data-schemas';
8
-
9
- function typeForRelationshipMeta(meta) {
10
- let modelName = dasherize(meta.type || meta.key);
11
-
12
- if (meta.kind === 'hasMany') {
13
- modelName = singularize(modelName);
14
- }
15
-
16
- return modelName;
17
- }
18
-
19
- function shouldFindInverse(relationshipMeta) {
20
- let options = relationshipMeta.options;
21
- return !(options && options.inverse === null);
22
- }
23
-
24
- class RelationshipDefinition implements RelationshipSchema {
25
- declare _type: string;
26
- declare __inverseKey: string;
27
- declare __hasCalculatedInverse: boolean;
28
- declare parentModelName: string;
29
- declare inverseIsAsync: string | null;
30
- declare meta: any;
31
-
32
- constructor(meta: any) {
33
- this._type = '';
34
- this.__inverseKey = '';
35
- this.__hasCalculatedInverse = false;
36
- this.parentModelName = meta.parentModelName;
37
- this.meta = meta;
38
- }
39
-
40
- /**
41
- * @internal
42
- * @deprecated
43
- */
44
- get key(): string {
45
- return this.meta.key;
46
- }
47
- get kind(): 'belongsTo' | 'hasMany' {
48
- return this.meta.kind;
49
- }
50
- get type(): string {
51
- if (this._type) {
52
- return this._type;
53
- }
54
- this._type = typeForRelationshipMeta(this.meta);
55
- return this._type;
56
- }
57
- get options(): { [key: string]: any } {
58
- return this.meta.options;
59
- }
60
- get name(): string {
61
- return this.meta.name;
62
- }
63
-
64
- _inverseKey(store: Store, modelClass): string {
65
- if (this.__hasCalculatedInverse === false) {
66
- this._calculateInverse(store, modelClass);
67
- }
68
- return this.__inverseKey;
69
- }
70
-
71
- _calculateInverse(store: Store, modelClass): void {
72
- this.__hasCalculatedInverse = true;
73
- let inverseKey;
74
- let inverse: any = null;
75
-
76
- if (shouldFindInverse(this.meta)) {
77
- inverse = modelClass.inverseFor(this.key, store);
78
- }
79
- // TODO make this error again for the non-polymorphic case
80
- if (DEBUG) {
81
- if (!this.options.polymorphic) {
82
- modelClass.typeForRelationship(this.key, store);
83
- }
84
- }
85
-
86
- if (inverse) {
87
- inverseKey = inverse.name;
88
- } else {
89
- inverseKey = null;
90
- }
91
- this.__inverseKey = inverseKey;
92
- }
93
- }
94
- export type { RelationshipDefinition };
95
-
96
- export function relationshipFromMeta(meta: RelationshipSchema): RelationshipDefinition {
97
- return new RelationshipDefinition(meta);
98
- }
@@ -1,31 +0,0 @@
1
- import { gte } from 'ember-compatibility-helpers';
2
-
3
- export type DecoratorPropertyDescriptor = (PropertyDescriptor & { initializer?: any }) | undefined;
4
-
5
- export function isElementDescriptor(args: any[]): args is [object, string, DecoratorPropertyDescriptor] {
6
- let [maybeTarget, maybeKey, maybeDesc] = args;
7
-
8
- return (
9
- // Ensure we have the right number of args
10
- args.length === 3 &&
11
- // Make sure the target is a class or object (prototype)
12
- (typeof maybeTarget === 'function' || (typeof maybeTarget === 'object' && maybeTarget !== null)) &&
13
- // Make sure the key is a string
14
- typeof maybeKey === 'string' &&
15
- // Make sure the descriptor is the right shape
16
- ((typeof maybeDesc === 'object' &&
17
- maybeDesc !== null &&
18
- 'enumerable' in maybeDesc &&
19
- 'configurable' in maybeDesc) ||
20
- // TS compatibility
21
- maybeDesc === undefined)
22
- );
23
- }
24
-
25
- export function computedMacroWithOptionalParams(fn) {
26
- if (gte('3.10.0')) {
27
- return (...maybeDesc: any[]) => (isElementDescriptor(maybeDesc) ? fn()(...maybeDesc) : fn(...maybeDesc));
28
- } else {
29
- return fn;
30
- }
31
- }
package/addon/index.ts DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- In EmberData a `Model` is a class defining the attributes and relationships
3
- of a specific resource `type` (model name). In this sense it represents a static "schema".
4
-
5
- Data for individual resources fetched from your API is presented
6
- to the UI via instances of the `Model`s you define.
7
-
8
- An instantiated `Model` is referred to as a `record`.
9
-
10
- When we refer to the `ModelClass` we are referring to the class definition
11
- and the static schema methods present on it.
12
-
13
- When we refer to a `record` we refer to a specific class instance presenting
14
- the resource data for a given `type` and `id`.
15
-
16
- ### Defining a Model
17
-
18
- ```app/models/person.js
19
- import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
20
-
21
- export default class PersonModel extends Model {
22
- @attr name;
23
-
24
- @belongsTo('pet', { inverse: 'owners', async: false }) dog;
25
-
26
- @hasMany('person', { inverse: 'friends', async: true }) friends;
27
- }
28
- ```
29
-
30
- ### modelName convention
31
-
32
- By convention, the name of a given model (its `type`) matches the name
33
- of the file in the `app/models` folder and should be lowercase, singular
34
- and dasherized.
35
-
36
- @module @ember-data/model
37
- @main @ember-data/model
38
- */
39
- export { Model as default, attr, belongsTo, hasMany } from './-private';
@@ -1,26 +0,0 @@
1
- <grey>You may generate models with as many attrs as you would like to pass. The following attribute types are supported:</grey>
2
- <yellow><attr-name></yellow>
3
- <yellow><attr-name></yellow>:array
4
- <yellow><attr-name></yellow>:boolean
5
- <yellow><attr-name></yellow>:date
6
- <yellow><attr-name></yellow>:object
7
- <yellow><attr-name></yellow>:number
8
- <yellow><attr-name></yellow>:string
9
- <yellow><attr-name></yellow>:your-custom-transform
10
- <yellow><attr-name></yellow>:belongs-to:<yellow><model-name></yellow>
11
- <yellow><attr-name></yellow>:has-many:<yellow><model-name></yellow>
12
-
13
- For instance: <green>\`ember generate model taco filling:belongs-to:protein toppings:has-many:toppings name:string price:number misc\`</green>
14
- would result in the following model:
15
-
16
- ```js
17
- import Model, { belongsTo, hasMany, attr } from '@ember-data/model';
18
-
19
- export default class TacoModel extends Model {
20
- @belongsTo('protein') filling;
21
- @hasMany('topping') toppings;
22
- @attr('string') name;
23
- @attr('number') price;
24
- @attr misc;
25
- }
26
- ```
@@ -1,5 +0,0 @@
1
- import Model<%= importedModules.length ? `, { ${importedModules} }` : '' %> from '@ember-data/model';
2
-
3
- export default Model.extend({
4
- <%= attrs.length ? attrs : '' %>
5
- });
@@ -1,158 +0,0 @@
1
- const EOL = require('os').EOL;
2
-
3
- const inflection = require('inflection');
4
- const stringUtils = require('ember-cli-string-utils');
5
- const useEditionDetector = require('@ember-data/private-build-infra/src/utilities/edition-detector');
6
- const { has } = require('@ember/edition-utils');
7
-
8
- module.exports = useEditionDetector({
9
- description: 'Generates an ember-data model.',
10
-
11
- anonymousOptions: ['name', 'attr:type'],
12
-
13
- root: __dirname,
14
-
15
- locals(options) {
16
- let attrs = [];
17
- let needs = [];
18
- let entityOptions = options.entity.options;
19
- let includeHasMany = false;
20
- let includeBelongsTo = false;
21
- let includeAttr = false;
22
-
23
- for (let name in entityOptions) {
24
- let type = entityOptions[name] || '';
25
- let foreignModel = name;
26
- if (type.indexOf(':') > -1) {
27
- foreignModel = type.split(':')[1];
28
- type = type.split(':')[0];
29
- }
30
- let dasherizedName = stringUtils.dasherize(name);
31
- let camelizedName = stringUtils.camelize(name);
32
- let dasherizedType = stringUtils.dasherize(type);
33
- let dasherizedForeignModel = stringUtils.dasherize(foreignModel);
34
- let dasherizedForeignModelSingular = inflection.singularize(dasherizedForeignModel);
35
-
36
- let attr;
37
- if (/has-many/.test(dasherizedType)) {
38
- includeHasMany = true;
39
- let camelizedNamePlural = inflection.pluralize(camelizedName);
40
- attr = {
41
- name: dasherizedForeignModelSingular,
42
- type: dasherizedType,
43
- propertyName: camelizedNamePlural,
44
- };
45
- } else if (/belongs-to/.test(dasherizedType)) {
46
- includeBelongsTo = true;
47
- attr = {
48
- name: dasherizedForeignModel,
49
- type: dasherizedType,
50
- propertyName: camelizedName,
51
- };
52
- } else {
53
- includeAttr = true;
54
- attr = {
55
- name: dasherizedName,
56
- type: dasherizedType,
57
- propertyName: camelizedName,
58
- };
59
- }
60
- attrs.push(attr);
61
-
62
- if (/has-many|belongs-to/.test(dasherizedType)) {
63
- needs.push("'model:" + dasherizedForeignModelSingular + "'");
64
- }
65
- }
66
-
67
- if (attrs.length) {
68
- let attrTransformer, attrSeparator;
69
-
70
- let hasOctane = has('octane');
71
- if (hasOctane && process.env.EMBER_EDITION === 'classic') {
72
- hasOctane = false; //forcible override
73
- }
74
- if (hasOctane) {
75
- attrTransformer = nativeAttr;
76
- attrSeparator = ';';
77
- } else {
78
- attrTransformer = classicAttr;
79
- attrSeparator = ',';
80
- }
81
-
82
- attrs = attrs.map(attrTransformer);
83
- attrs = ' ' + attrs.join(attrSeparator + EOL + ' ');
84
- if (hasOctane) {
85
- attrs = attrs + attrSeparator;
86
- }
87
- }
88
-
89
- let needsDeduplicated = needs.filter(function (need, i) {
90
- return needs.indexOf(need) === i;
91
- });
92
- needs = ' needs: [' + needsDeduplicated.join(', ') + ']';
93
-
94
- let importedModules = [];
95
- if (includeAttr) {
96
- importedModules.push('attr');
97
- }
98
- if (includeBelongsTo) {
99
- importedModules.push('belongsTo');
100
- }
101
- if (includeHasMany) {
102
- importedModules.push('hasMany');
103
- }
104
- importedModules = importedModules.join(', ');
105
-
106
- return {
107
- importedModules,
108
- attrs,
109
- needs,
110
- };
111
- },
112
- });
113
-
114
- function nativeAttr(attr) {
115
- let name = attr.name,
116
- type = attr.type,
117
- propertyName = attr.propertyName,
118
- result;
119
-
120
- if (type === 'belongs-to') {
121
- if (name === propertyName) {
122
- result = '@belongsTo';
123
- } else {
124
- result = "@belongsTo('" + name + "')";
125
- }
126
- } else if (type === 'has-many') {
127
- if (inflection.pluralize(name) === propertyName) {
128
- result = '@hasMany';
129
- } else {
130
- result = "@hasMany('" + name + "')";
131
- }
132
- } else if (type === '') {
133
- result = '@attr()';
134
- } else {
135
- result = "@attr('" + type + "')";
136
- }
137
- return result + ' ' + propertyName;
138
- }
139
-
140
- function classicAttr(attr) {
141
- let name = attr.name,
142
- type = attr.type,
143
- propertyName = attr.propertyName,
144
- result;
145
-
146
- if (type === 'belongs-to') {
147
- result = "belongsTo('" + name + "')";
148
- } else if (type === 'has-many') {
149
- result = "hasMany('" + name + "')";
150
- } else if (type === '') {
151
- //"If you don't specify the type of the attribute, it will be whatever was provided by the server"
152
- //https://emberjs.com/guides/models/defining-models/
153
- result = 'attr()';
154
- } else {
155
- result = "attr('" + type + "')";
156
- }
157
- return propertyName + ': ' + result;
158
- }
@@ -1,5 +0,0 @@
1
- import Model<%= importedModules.length ? `, { ${importedModules} }` : '' %> from '@ember-data/model';
2
-
3
- export default class <%= classifiedModuleName %>Model extends Model {
4
- <%= attrs.length ? attrs : '' %>
5
- }
@@ -1,33 +0,0 @@
1
- const path = require('path');
2
-
3
- const testInfo = require('ember-cli-test-info');
4
- const useTestFrameworkDetector = require('@ember-data/private-build-infra/src/utilities/test-framework-detector');
5
- const modulePrefixForProject = require('@ember-data/private-build-infra/src/utilities/module-prefix-for-project');
6
-
7
- const ModelBlueprint = require('../model');
8
-
9
- module.exports = useTestFrameworkDetector({
10
- description: 'Generates a model unit test.',
11
-
12
- root: __dirname,
13
-
14
- fileMapTokens(options) {
15
- return {
16
- __root__() {
17
- return 'tests';
18
- },
19
- __path__() {
20
- return path.join('unit', 'models');
21
- },
22
- };
23
- },
24
-
25
- locals(options) {
26
- const result = ModelBlueprint.locals.apply(this, arguments);
27
-
28
- result.friendlyTestDescription = testInfo.description(options.entity.name, 'Unit', 'Model');
29
- result.modulePrefix = modulePrefixForProject(options.project);
30
-
31
- return result;
32
- },
33
- });
@@ -1,18 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it } from 'mocha';
3
-
4
- import { setupModelTest } from 'ember-mocha';
5
-
6
- describe('<%= friendlyTestDescription %>', function () {
7
- setupModelTest('<%= dasherizedModuleName %>', {
8
- // Specify the other units that are required for this test.
9
- <%= typeof needs !== 'undefined' ? needs : '' %>,
10
- });
11
-
12
- // Replace this with your real tests.
13
- it('exists', function () {
14
- let model = this.subject();
15
- // var store = this.store();
16
- expect(model).to.be.ok;
17
- });
18
- });
@@ -1,15 +0,0 @@
1
- import { expect } from 'chai';
2
- import { describe, it } from 'mocha';
3
-
4
- import { setupTest } from '<%= modulePrefix %>/tests/helpers';
5
-
6
- describe('<%= friendlyTestDescription %>', function () {
7
- setupTest();
8
-
9
- // Replace this with your real tests.
10
- it('exists', function () {
11
- let store = this.owner.lookup('service:store');
12
- let model = store.createRecord('<%= dasherizedModuleName %>', {});
13
- expect(model).to.be.ok;
14
- });
15
- });
@@ -1,14 +0,0 @@
1
- import { module, test } from 'qunit';
2
-
3
- import { setupTest } from '<%= modulePrefix %>/tests/helpers';
4
-
5
- module('<%= friendlyTestDescription %>', function (hooks) {
6
- setupTest(hooks);
7
-
8
- // Replace this with your real tests.
9
- test('it exists', function (assert) {
10
- let store = this.owner.lookup('service:store');
11
- let model = store.createRecord('<%= dasherizedModuleName %>', {});
12
- assert.ok(model);
13
- });
14
- });
package/index.js DELETED
@@ -1,47 +0,0 @@
1
- 'use strict';
2
-
3
- const addonBuildConfigForDataPackage = require('@ember-data/private-build-infra/src/addon-build-config-for-data-package');
4
-
5
- const name = require('./package').name;
6
-
7
- const addonBaseConfig = addonBuildConfigForDataPackage(name);
8
-
9
- module.exports = Object.assign({}, addonBaseConfig, {
10
- shouldRollupPrivate: true,
11
- externalDependenciesForPrivateModule() {
12
- return [
13
- 'ember-cached-decorator-polyfill',
14
-
15
- '@ember-data/canary-features',
16
- '@ember-data/store',
17
- '@ember-data/store/-private',
18
- '@embroider/macros',
19
- '@ember/string',
20
- '@embroider/macros/es-compat',
21
- '@ember-data/tracking/-private',
22
-
23
- '@ember/object/proxy',
24
- '@ember/object/promise-proxy-mixin',
25
- '@ember/application',
26
- '@ember/array',
27
- '@ember/array/mutable',
28
- '@ember/array/proxy',
29
- '@ember/debug',
30
- '@ember/error',
31
- '@ember/object',
32
- '@ember/object/compat',
33
- '@ember/object/computed',
34
- '@ember/object/internals',
35
- '@ember/polyfills',
36
- '@ember/runloop',
37
- '@ember/utils',
38
- '@ember/service',
39
-
40
- '@glimmer/tracking/primitives/cache',
41
- '@glimmer/tracking',
42
- 'ember-inflector',
43
- 'ember',
44
- 'rsvp',
45
- ];
46
- },
47
- });