@oak-digital/types-4-strapi-2 0.2.3 → 0.2.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.
- package/README.md +1 -0
- package/lib/interface/Attributes.d.ts +1 -1
- package/lib/interface/Attributes.js +46 -46
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,11 +9,11 @@ var Attributes = /** @class */ (function () {
|
|
|
9
9
|
Attributes.prototype.isAttributeOptional = function (attr) {
|
|
10
10
|
// If it is a component / relation / dynamiczone it is always optional due to population
|
|
11
11
|
switch (attr.type) {
|
|
12
|
-
case
|
|
12
|
+
case 'nested':
|
|
13
13
|
return attr.nullable === true;
|
|
14
|
-
case
|
|
15
|
-
case
|
|
16
|
-
case
|
|
14
|
+
case 'component':
|
|
15
|
+
case 'dynamiczone':
|
|
16
|
+
case 'relation':
|
|
17
17
|
return true;
|
|
18
18
|
default:
|
|
19
19
|
break;
|
|
@@ -26,18 +26,18 @@ var Attributes = /** @class */ (function () {
|
|
|
26
26
|
var attr = this.Attrs[attrName];
|
|
27
27
|
var dependencyNames = [];
|
|
28
28
|
switch (attr.type) {
|
|
29
|
-
case
|
|
29
|
+
case 'nested':
|
|
30
30
|
var attrs = new Attributes(attr.fields, this.RelationNames);
|
|
31
31
|
dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
|
|
32
32
|
break;
|
|
33
|
-
case
|
|
33
|
+
case 'relation':
|
|
34
34
|
dependencyNames.push(attr.target);
|
|
35
35
|
break;
|
|
36
|
-
case
|
|
36
|
+
case 'component':
|
|
37
37
|
dependencyNames.push(attr.component);
|
|
38
38
|
break;
|
|
39
|
-
case
|
|
40
|
-
dependencyNames.push(
|
|
39
|
+
case 'media':
|
|
40
|
+
dependencyNames.push('builtins::Media');
|
|
41
41
|
break;
|
|
42
42
|
default:
|
|
43
43
|
continue;
|
|
@@ -55,70 +55,70 @@ var Attributes = /** @class */ (function () {
|
|
|
55
55
|
return dependencies;
|
|
56
56
|
};
|
|
57
57
|
Attributes.prototype.attributeToString = function (attrName, attr) {
|
|
58
|
-
var _a
|
|
58
|
+
var _a;
|
|
59
59
|
var optionalString = this.isAttributeOptional(attr) ? '?' : '';
|
|
60
60
|
var str = " ".concat(attrName).concat(optionalString, ": ");
|
|
61
61
|
var isArray = false;
|
|
62
62
|
switch (attr.type) {
|
|
63
63
|
// types-4-strapi-2 specific, used for builtin types
|
|
64
|
-
case
|
|
64
|
+
case 'nested':
|
|
65
65
|
// Be careful with recursion
|
|
66
66
|
// console.log(attr);
|
|
67
67
|
var newAttrs = new Attributes(attr.fields, this.RelationNames);
|
|
68
68
|
str += newAttrs.toString();
|
|
69
69
|
break;
|
|
70
|
-
case
|
|
70
|
+
case 'relation':
|
|
71
71
|
var apiName = attr.target;
|
|
72
72
|
// console.log(this.RelationNames, apiName)
|
|
73
73
|
var dependencyName = this.RelationNames[apiName].name;
|
|
74
|
-
|
|
75
|
-
str += dependencyName;
|
|
74
|
+
var relationMultipleString = attr.relation.endsWith('ToMany') ? '[]' : ' | null';
|
|
75
|
+
str += "{ data: ".concat(dependencyName).concat(relationMultipleString, "; }");
|
|
76
76
|
break;
|
|
77
|
-
case
|
|
77
|
+
case 'component':
|
|
78
78
|
var componentName = attr.component;
|
|
79
79
|
var relationNameObj = this.RelationNames[componentName];
|
|
80
80
|
var dependencyComponentName = relationNameObj.name;
|
|
81
81
|
isArray = (_a = attr.repeatable) !== null && _a !== void 0 ? _a : false;
|
|
82
82
|
str += dependencyComponentName;
|
|
83
83
|
break;
|
|
84
|
-
case
|
|
85
|
-
var mediaOptional = attr.required !== true ?
|
|
86
|
-
|
|
87
|
-
|
|
84
|
+
case 'media':
|
|
85
|
+
var mediaOptional = attr.required !== true ? '?' : '';
|
|
86
|
+
var mediaMultipleString = attr.multiple ? '[]' : ' | null';
|
|
87
|
+
str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames['builtins::Media'].name).concat(mediaMultipleString, "; }");
|
|
88
88
|
break;
|
|
89
|
-
case
|
|
89
|
+
case 'password':
|
|
90
90
|
return null;
|
|
91
|
-
case
|
|
92
|
-
var hasDefault =
|
|
91
|
+
case 'enumeration':
|
|
92
|
+
var hasDefault = 'default' in attr;
|
|
93
93
|
var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
|
|
94
|
-
enums.push(
|
|
95
|
-
var typeString = enums.join(
|
|
94
|
+
enums.push('null');
|
|
95
|
+
var typeString = enums.join(' | ');
|
|
96
96
|
str += typeString;
|
|
97
97
|
break;
|
|
98
|
-
case
|
|
99
|
-
case
|
|
100
|
-
case
|
|
101
|
-
case
|
|
102
|
-
case
|
|
103
|
-
str +=
|
|
98
|
+
case 'string':
|
|
99
|
+
case 'text':
|
|
100
|
+
case 'richtext':
|
|
101
|
+
case 'email':
|
|
102
|
+
case 'uid':
|
|
103
|
+
str += 'string';
|
|
104
104
|
break;
|
|
105
|
-
case
|
|
106
|
-
case
|
|
107
|
-
case
|
|
108
|
-
case
|
|
109
|
-
str +=
|
|
105
|
+
case 'integer':
|
|
106
|
+
case 'biginteger':
|
|
107
|
+
case 'decimal':
|
|
108
|
+
case 'float':
|
|
109
|
+
str += 'number';
|
|
110
110
|
break;
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
case
|
|
114
|
-
str +=
|
|
111
|
+
case 'date':
|
|
112
|
+
case 'datetime':
|
|
113
|
+
case 'time':
|
|
114
|
+
str += 'Date';
|
|
115
115
|
break;
|
|
116
|
-
case
|
|
116
|
+
case 'boolean':
|
|
117
117
|
str += attr.type;
|
|
118
118
|
break;
|
|
119
|
-
case
|
|
119
|
+
case 'json':
|
|
120
120
|
default:
|
|
121
|
-
str +=
|
|
121
|
+
str += 'any';
|
|
122
122
|
break;
|
|
123
123
|
}
|
|
124
124
|
var isArrayString = isArray ? '[]' : '';
|
|
@@ -135,13 +135,13 @@ var Attributes = /** @class */ (function () {
|
|
|
135
135
|
}
|
|
136
136
|
strings.push(attrString);
|
|
137
137
|
}
|
|
138
|
-
return strings.map(function (s) { return "".concat(s, "\n"); }).join(
|
|
138
|
+
return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
|
|
139
139
|
};
|
|
140
140
|
Attributes.prototype.toString = function () {
|
|
141
|
-
var strings = [
|
|
141
|
+
var strings = ['{'];
|
|
142
142
|
strings.push(this.toFieldsString());
|
|
143
|
-
strings.push(
|
|
144
|
-
return strings.join(
|
|
143
|
+
strings.push('}');
|
|
144
|
+
return strings.join('\n');
|
|
145
145
|
};
|
|
146
146
|
return Attributes;
|
|
147
147
|
}());
|