@ember-data/model 4.12.0-beta.8 → 4.12.0
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/README.md +42 -18
- package/addon/-private.js +2 -2
- package/addon/{has-many-c84372b4.js → has-many-465843f4.js} +69 -18
- package/addon/has-many-465843f4.js.map +1 -0
- package/addon/index.js +1 -1
- package/blueprints/model/HELP.md +26 -0
- package/blueprints/model/files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model/index.js +150 -0
- package/blueprints/model/native-files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model-test/index.js +33 -0
- package/blueprints/model-test/mocha-files/__root__/__path__/__test__.js +18 -0
- package/blueprints/model-test/mocha-rfc-232-files/__root__/__path__/__test__.js +15 -0
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +14 -0
- package/package.json +18 -17
- package/addon/has-many-c84372b4.js.map +0 -1
package/addon/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as attr, b as belongsTo, M as default, h as hasMany } from "./has-many-
|
|
1
|
+
export { a as attr, b as belongsTo, M as default, h as hasMany } from "./has-many-465843f4";
|
|
@@ -0,0 +1,26 @@
|
|
|
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', { async: false, inverse: null }) filling;
|
|
21
|
+
@hasMany('topping', { async: false, inverse: null }) toppings;
|
|
22
|
+
@attr('string') name;
|
|
23
|
+
@attr('number') price;
|
|
24
|
+
@attr misc;
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,150 @@
|
|
|
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
|
+
result = "@belongsTo('" + name + "', { async: false, inverse: null })";
|
|
122
|
+
} else if (type === 'has-many') {
|
|
123
|
+
result = "@hasMany('" + name + "', { async: false, inverse: null })";
|
|
124
|
+
} else if (type === '') {
|
|
125
|
+
result = '@attr';
|
|
126
|
+
} else {
|
|
127
|
+
result = "@attr('" + type + "')";
|
|
128
|
+
}
|
|
129
|
+
return result + ' ' + propertyName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function classicAttr(attr) {
|
|
133
|
+
let name = attr.name,
|
|
134
|
+
type = attr.type,
|
|
135
|
+
propertyName = attr.propertyName,
|
|
136
|
+
result;
|
|
137
|
+
|
|
138
|
+
if (type === 'belongs-to') {
|
|
139
|
+
result = "belongsTo('" + name + "', { async: false, inverse: null })";
|
|
140
|
+
} else if (type === 'has-many') {
|
|
141
|
+
result = "hasMany('" + name + "', { async: false, inverse: null })";
|
|
142
|
+
} else if (type === '') {
|
|
143
|
+
//"If you don't specify the type of the attribute, it will be whatever was provided by the server"
|
|
144
|
+
//https://emberjs.com/guides/models/defining-models/
|
|
145
|
+
result = 'attr()';
|
|
146
|
+
} else {
|
|
147
|
+
result = "attr('" + type + "')";
|
|
148
|
+
}
|
|
149
|
+
return propertyName + ': ' + result;
|
|
150
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-data/model",
|
|
3
|
-
"version": "4.12.0
|
|
4
|
-
"description": "A presentation layer for
|
|
3
|
+
"version": "4.12.0",
|
|
4
|
+
"description": "A basic Ember implementation of a resource presentation layer for use with @ember-data/store",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
7
7
|
],
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"version": 1
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
|
+
"blueprints",
|
|
22
23
|
"addon-main.js",
|
|
23
24
|
"addon",
|
|
24
25
|
"README.md",
|
|
@@ -27,12 +28,12 @@
|
|
|
27
28
|
"ember-data-logo-light.svg"
|
|
28
29
|
],
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@ember-data/debug": "4.12.0
|
|
31
|
-
"@ember-data/json-api": "4.12.0
|
|
32
|
-
"@ember-data/legacy-compat": "4.12.0
|
|
33
|
-
"@ember-data/graph": "4.12.0
|
|
34
|
-
"@ember-data/store": "4.12.0
|
|
35
|
-
"@ember-data/tracking": "4.12.0
|
|
31
|
+
"@ember-data/debug": "4.12.0",
|
|
32
|
+
"@ember-data/json-api": "4.12.0",
|
|
33
|
+
"@ember-data/legacy-compat": "4.12.0",
|
|
34
|
+
"@ember-data/graph": "4.12.0",
|
|
35
|
+
"@ember-data/store": "4.12.0",
|
|
36
|
+
"@ember-data/tracking": "4.12.0",
|
|
36
37
|
"@ember/string": "^3.0.1",
|
|
37
38
|
"ember-inflector": "^4.0.2"
|
|
38
39
|
},
|
|
@@ -53,7 +54,7 @@
|
|
|
53
54
|
}
|
|
54
55
|
},
|
|
55
56
|
"dependencies": {
|
|
56
|
-
"@ember-data/private-build-infra": "4.12.0
|
|
57
|
+
"@ember-data/private-build-infra": "4.12.0",
|
|
57
58
|
"@ember/edition-utils": "^1.2.0",
|
|
58
59
|
"@embroider/macros": "^1.10.0",
|
|
59
60
|
"ember-cached-decorator-polyfill": "^1.0.1",
|
|
@@ -63,33 +64,33 @@
|
|
|
63
64
|
"inflection": "~2.0.1"
|
|
64
65
|
},
|
|
65
66
|
"devDependencies": {
|
|
66
|
-
"@babel/core": "^7.21.
|
|
67
|
+
"@babel/core": "^7.21.4",
|
|
67
68
|
"@babel/cli": "^7.21.0",
|
|
68
69
|
"@glimmer/component": "^1.1.2",
|
|
69
|
-
"ember-source": "~4.
|
|
70
|
+
"ember-source": "~4.12.0",
|
|
70
71
|
"@embroider/addon-dev": "^3.0.0",
|
|
71
72
|
"rollup": "^3.20.2",
|
|
72
73
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
73
74
|
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
74
75
|
"@babel/plugin-proposal-decorators": "^7.21.0",
|
|
75
76
|
"@babel/plugin-transform-typescript": "^7.21.3",
|
|
76
|
-
"@babel/plugin-transform-runtime": "^7.21.
|
|
77
|
-
"@babel/preset-typescript": "^7.21.
|
|
78
|
-
"@babel/preset-env": "^7.
|
|
77
|
+
"@babel/plugin-transform-runtime": "^7.21.4",
|
|
78
|
+
"@babel/preset-typescript": "^7.21.4",
|
|
79
|
+
"@babel/preset-env": "^7.21.4",
|
|
79
80
|
"@babel/runtime": "^7.21.0",
|
|
80
81
|
"@rollup/plugin-babel": "^6.0.3",
|
|
81
82
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
82
83
|
"tslib": "^2.5.0",
|
|
83
84
|
"walk-sync": "^3.0.0",
|
|
84
|
-
"typescript": "^
|
|
85
|
+
"typescript": "^5.0.3"
|
|
85
86
|
},
|
|
86
87
|
"engines": {
|
|
87
|
-
"node": "
|
|
88
|
+
"node": "16.* || >= 18.*"
|
|
88
89
|
},
|
|
89
90
|
"volta": {
|
|
90
91
|
"extends": "../../package.json"
|
|
91
92
|
},
|
|
92
|
-
"packageManager": "pnpm@
|
|
93
|
+
"packageManager": "pnpm@8.1.0",
|
|
93
94
|
"scripts": {
|
|
94
95
|
"build": "rollup --config && babel ./addon --out-dir addon --plugins=../private-build-infra/src/transforms/babel-plugin-transform-ext.js",
|
|
95
96
|
"start": "rollup --config --watch"
|