@warp-drive/legacy 5.8.0 → 5.8.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/blueprints/model/HELP.md +26 -0
- package/blueprints/model/files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model/index.js +163 -0
- package/blueprints/model/native-files/__root__/__path__/__name__.js +5 -0
- package/blueprints/model-test/index.js +39 -0
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +13 -0
- package/package.json +12 -7
|
@@ -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,163 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const EOL = require('os').EOL;
|
|
3
|
+
|
|
4
|
+
const { has } = require('@ember/edition-utils');
|
|
5
|
+
|
|
6
|
+
const inflection = require('inflection');
|
|
7
|
+
const stringUtils = require('ember-cli-string-utils');
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
description: 'Generates an ember-data Model.',
|
|
11
|
+
|
|
12
|
+
anonymousOptions: ['name', 'attr:type'],
|
|
13
|
+
|
|
14
|
+
root: __dirname,
|
|
15
|
+
|
|
16
|
+
filesPath() {
|
|
17
|
+
let hasOctane = has('octane');
|
|
18
|
+
if (hasOctane && process.env.EMBER_EDITION === 'classic') {
|
|
19
|
+
hasOctane = false; //forcible override
|
|
20
|
+
}
|
|
21
|
+
let rootPath = hasOctane ? 'native-files' : 'files';
|
|
22
|
+
return path.join(__dirname, rootPath);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
locals(options) {
|
|
27
|
+
let attrs = [];
|
|
28
|
+
let needs = [];
|
|
29
|
+
let entityOptions = options.entity.options;
|
|
30
|
+
let includeHasMany = false;
|
|
31
|
+
let includeBelongsTo = false;
|
|
32
|
+
let includeAttr = false;
|
|
33
|
+
|
|
34
|
+
for (let name in entityOptions) {
|
|
35
|
+
let type = entityOptions[name] || '';
|
|
36
|
+
let foreignModel = name;
|
|
37
|
+
if (type.indexOf(':') > -1) {
|
|
38
|
+
foreignModel = type.split(':')[1];
|
|
39
|
+
type = type.split(':')[0];
|
|
40
|
+
}
|
|
41
|
+
let dasherizedName = stringUtils.dasherize(name);
|
|
42
|
+
let camelizedName = stringUtils.camelize(name);
|
|
43
|
+
let dasherizedType = stringUtils.dasherize(type);
|
|
44
|
+
let dasherizedForeignModel = stringUtils.dasherize(foreignModel);
|
|
45
|
+
let dasherizedForeignModelSingular = inflection.singularize(dasherizedForeignModel);
|
|
46
|
+
|
|
47
|
+
let attr;
|
|
48
|
+
if (/has-many/.test(dasherizedType)) {
|
|
49
|
+
includeHasMany = true;
|
|
50
|
+
let camelizedNamePlural = inflection.pluralize(camelizedName);
|
|
51
|
+
attr = {
|
|
52
|
+
name: dasherizedForeignModelSingular,
|
|
53
|
+
type: dasherizedType,
|
|
54
|
+
propertyName: camelizedNamePlural,
|
|
55
|
+
};
|
|
56
|
+
} else if (/belongs-to/.test(dasherizedType)) {
|
|
57
|
+
includeBelongsTo = true;
|
|
58
|
+
attr = {
|
|
59
|
+
name: dasherizedForeignModel,
|
|
60
|
+
type: dasherizedType,
|
|
61
|
+
propertyName: camelizedName,
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
includeAttr = true;
|
|
65
|
+
attr = {
|
|
66
|
+
name: dasherizedName,
|
|
67
|
+
type: dasherizedType,
|
|
68
|
+
propertyName: camelizedName,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
attrs.push(attr);
|
|
72
|
+
|
|
73
|
+
if (/has-many|belongs-to/.test(dasherizedType)) {
|
|
74
|
+
needs.push("'model:" + dasherizedForeignModelSingular + "'");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (attrs.length) {
|
|
79
|
+
let attrTransformer, attrSeparator;
|
|
80
|
+
|
|
81
|
+
let hasOctane = has('octane');
|
|
82
|
+
if (hasOctane && process.env.EMBER_EDITION === 'classic') {
|
|
83
|
+
hasOctane = false; //forcible override
|
|
84
|
+
}
|
|
85
|
+
if (hasOctane) {
|
|
86
|
+
attrTransformer = nativeAttr;
|
|
87
|
+
attrSeparator = ';';
|
|
88
|
+
} else {
|
|
89
|
+
attrTransformer = classicAttr;
|
|
90
|
+
attrSeparator = ',';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
attrs = attrs.map(attrTransformer);
|
|
94
|
+
attrs = ' ' + attrs.join(attrSeparator + EOL + ' ');
|
|
95
|
+
if (hasOctane) {
|
|
96
|
+
attrs = attrs + attrSeparator;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
let needsDeduplicated = needs.filter(function (need, i) {
|
|
101
|
+
return needs.indexOf(need) === i;
|
|
102
|
+
});
|
|
103
|
+
needs = ' needs: [' + needsDeduplicated.join(', ') + ']';
|
|
104
|
+
|
|
105
|
+
let importedModules = [];
|
|
106
|
+
if (includeAttr) {
|
|
107
|
+
importedModules.push('attr');
|
|
108
|
+
}
|
|
109
|
+
if (includeBelongsTo) {
|
|
110
|
+
importedModules.push('belongsTo');
|
|
111
|
+
}
|
|
112
|
+
if (includeHasMany) {
|
|
113
|
+
importedModules.push('hasMany');
|
|
114
|
+
}
|
|
115
|
+
importedModules = importedModules.join(', ');
|
|
116
|
+
|
|
117
|
+
return {
|
|
118
|
+
importedModules,
|
|
119
|
+
attrs,
|
|
120
|
+
needs,
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function nativeAttr(attr) {
|
|
126
|
+
let name = attr.name,
|
|
127
|
+
type = attr.type,
|
|
128
|
+
propertyName = attr.propertyName,
|
|
129
|
+
result;
|
|
130
|
+
|
|
131
|
+
if (type === 'belongs-to') {
|
|
132
|
+
result = "@belongsTo('" + name + "', { async: false, inverse: null })";
|
|
133
|
+
} else if (type === 'has-many') {
|
|
134
|
+
result = "@hasMany('" + name + "', { async: false, inverse: null })";
|
|
135
|
+
} else if (type === '') {
|
|
136
|
+
result = '@attr';
|
|
137
|
+
} else {
|
|
138
|
+
result = "@attr('" + type + "')";
|
|
139
|
+
}
|
|
140
|
+
return result + ' ' + propertyName;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function classicAttr(attr) {
|
|
144
|
+
let name = attr.name,
|
|
145
|
+
type = attr.type,
|
|
146
|
+
propertyName = attr.propertyName,
|
|
147
|
+
result;
|
|
148
|
+
|
|
149
|
+
if (type === 'belongs-to') {
|
|
150
|
+
result = "belongsTo('" + name + "', { async: false, inverse: null })";
|
|
151
|
+
} else if (type === 'has-many') {
|
|
152
|
+
result = "hasMany('" + name + "', { async: false, inverse: null })";
|
|
153
|
+
} else if (type === '') {
|
|
154
|
+
//"If you don't specify the type of the attribute, it will be whatever was provided by the server"
|
|
155
|
+
//https://emberjs.com/guides/models/defining-models/
|
|
156
|
+
result = 'attr()';
|
|
157
|
+
} else {
|
|
158
|
+
result = "attr('" + type + "')";
|
|
159
|
+
}
|
|
160
|
+
return propertyName + ': ' + result;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
const testInfo = require('ember-cli-test-info');
|
|
4
|
+
const { dasherize } = require('ember-cli-string-utils');
|
|
5
|
+
|
|
6
|
+
const ModelBlueprint = require('../model');
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
description: 'Generates an EmberData Model unit test',
|
|
10
|
+
supportsAddon() { return false; },
|
|
11
|
+
|
|
12
|
+
root: __dirname,
|
|
13
|
+
|
|
14
|
+
fileMapTokens() {
|
|
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
|
+
const modulePrefix = dasherize(options.project.config().modulePrefix);
|
|
28
|
+
return {
|
|
29
|
+
...result,
|
|
30
|
+
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Model'),
|
|
31
|
+
modulePrefix,
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
filesPath() {
|
|
36
|
+
return path.join(__dirname, 'qunit-files')
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { setupTest } from '<%= modulePrefix %>/tests/helpers';
|
|
2
|
+
import { module, test } from 'qunit';
|
|
3
|
+
|
|
4
|
+
module('<%= friendlyTestDescription %>', function (hooks) {
|
|
5
|
+
setupTest(hooks);
|
|
6
|
+
|
|
7
|
+
// Replace this with your real tests.
|
|
8
|
+
test('it exists', function (assert) {
|
|
9
|
+
const store = this.owner.lookup('service:store');
|
|
10
|
+
const model = store.createRecord('<%= dasherizedModuleName %>', {});
|
|
11
|
+
assert.ok(model, 'model exists');
|
|
12
|
+
});
|
|
13
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warp-drive/legacy",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.1",
|
|
4
4
|
"description": "Decommissioned Packages for WarpDrive | Things your app might still want to maintain use of for a little longer.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ember-addon"
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"directory": "warp-drive-packages/legacy"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
+
"blueprints",
|
|
16
17
|
"dist",
|
|
17
18
|
"declarations",
|
|
18
19
|
"addon-main.cjs",
|
|
@@ -40,20 +41,24 @@
|
|
|
40
41
|
}
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"@warp-drive/core": "5.8.
|
|
44
|
-
"@warp-drive/utilities": "5.8.
|
|
44
|
+
"@warp-drive/core": "5.8.1",
|
|
45
|
+
"@warp-drive/utilities": "5.8.1"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@
|
|
48
|
+
"@ember/edition-utils": "^1.2.0",
|
|
49
|
+
"@embroider/macros": "^1.18.1",
|
|
50
|
+
"ember-cli-string-utils": "^1.1.0",
|
|
51
|
+
"ember-cli-test-info": "^1.0.0",
|
|
52
|
+
"inflection": "~3.0.2"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
55
|
"@babel/core": "^7.28.3",
|
|
51
56
|
"@babel/plugin-transform-typescript": "^7.28.0",
|
|
52
57
|
"@babel/preset-typescript": "^7.27.1",
|
|
53
58
|
"@types/jquery": "^3.5.33",
|
|
54
|
-
"@warp-drive/internal-config": "5.8.
|
|
55
|
-
"@warp-drive/core": "5.8.
|
|
56
|
-
"@warp-drive/utilities": "5.8.
|
|
59
|
+
"@warp-drive/internal-config": "5.8.1",
|
|
60
|
+
"@warp-drive/core": "5.8.1",
|
|
61
|
+
"@warp-drive/utilities": "5.8.1",
|
|
57
62
|
"ember-source": "~6.6.0",
|
|
58
63
|
"decorator-transforms": "^2.3.0",
|
|
59
64
|
"expect-type": "^1.2.2",
|