@oak-digital/types-4-strapi-2 0.4.0 → 0.5.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.
|
@@ -13,6 +13,7 @@ var Attributes = /** @class */ (function () {
|
|
|
13
13
|
case 'nested':
|
|
14
14
|
// we need to check equality since it could be undefined
|
|
15
15
|
return attr.nullable === true;
|
|
16
|
+
case 'media': // media is also always populatable
|
|
16
17
|
case 'component':
|
|
17
18
|
case 'dynamiczone':
|
|
18
19
|
case 'relation':
|
|
@@ -82,12 +83,14 @@ var Attributes = /** @class */ (function () {
|
|
|
82
83
|
};
|
|
83
84
|
Attributes.prototype.attributeToString = function (attrName, attr) {
|
|
84
85
|
var _this = this;
|
|
85
|
-
var _a, _b, _c
|
|
86
|
+
var _a, _b, _c;
|
|
86
87
|
var isPopulatable = this.isAttributePopulatable(attr);
|
|
87
88
|
var isOptional = isPopulatable;
|
|
88
89
|
var optionalString = isOptional ? '?' : '';
|
|
89
90
|
var orNull = ' | null';
|
|
90
|
-
|
|
91
|
+
// TODO: only add this in non paranoid mode
|
|
92
|
+
/* const requiredString = attr.required !== true ? orNull : ''; */
|
|
93
|
+
var requiredString = (attr === null || attr === void 0 ? void 0 : attr[constants_1.CERTAINLY_REQUIRED_KEY]) === true ? '' : orNull;
|
|
91
94
|
var str = " ".concat(attrName).concat(optionalString, ": ");
|
|
92
95
|
var isArray = false;
|
|
93
96
|
switch (attr.type) {
|
|
@@ -123,8 +126,13 @@ var Attributes = /** @class */ (function () {
|
|
|
123
126
|
var relationNameObj = this.RelationNames[componentName];
|
|
124
127
|
/* console.log(this.RelationNames); */
|
|
125
128
|
var dependencyComponentName = relationNameObj.name;
|
|
126
|
-
isArray =
|
|
129
|
+
/* isArray = attr.repeatable ?? false; */
|
|
130
|
+
isArray = false; // we already handle this here.
|
|
127
131
|
str += dependencyComponentName;
|
|
132
|
+
if (attr.repeatable) {
|
|
133
|
+
str += '[]';
|
|
134
|
+
}
|
|
135
|
+
str += requiredString; // resolves #20. components can be null.
|
|
128
136
|
break;
|
|
129
137
|
case 'media':
|
|
130
138
|
var mediaMultipleString = attr.multiple
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.POPULATE_GENERIC_NAME = void 0;
|
|
3
|
+
exports.CERTAINLY_REQUIRED_KEY = exports.POPULATE_GENERIC_NAME = void 0;
|
|
4
4
|
exports.POPULATE_GENERIC_NAME = 'Populate';
|
|
5
|
+
exports.CERTAINLY_REQUIRED_KEY = '__t4s_required';
|
|
@@ -4,21 +4,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createMediaFormatInterface = exports.createMediaInterface = void 0;
|
|
7
|
+
var constants_1 = require("../constants");
|
|
7
8
|
var BuiltinComponentInterface_1 = __importDefault(require("./BuiltinComponentInterface"));
|
|
8
9
|
var BuiltinInterface_1 = __importDefault(require("./BuiltinInterface"));
|
|
9
10
|
function createMediaInterface(directory, caseTypeName, prefix) {
|
|
10
11
|
var stringRequiredFields = [
|
|
11
12
|
'name',
|
|
12
|
-
'alternativeText',
|
|
13
|
-
'caption',
|
|
14
13
|
'hash',
|
|
15
14
|
'ext',
|
|
16
15
|
'mime',
|
|
17
16
|
'url',
|
|
18
17
|
'provider',
|
|
19
18
|
];
|
|
20
|
-
var stringFields = [
|
|
21
|
-
|
|
19
|
+
var stringFields = [
|
|
20
|
+
'previewUrl',
|
|
21
|
+
'provider_metadata',
|
|
22
|
+
'alternativeText',
|
|
23
|
+
'caption', // nullable in plain text
|
|
24
|
+
];
|
|
25
|
+
var numberRequiredFields = ['size'];
|
|
26
|
+
// Nullable if you have a plain text file
|
|
27
|
+
var numberFields = ['width', 'height'];
|
|
22
28
|
var mediaFormat = {
|
|
23
29
|
type: 'component',
|
|
24
30
|
repeatable: false,
|
|
@@ -38,13 +44,28 @@ function createMediaInterface(directory, caseTypeName, prefix) {
|
|
|
38
44
|
},
|
|
39
45
|
};
|
|
40
46
|
stringRequiredFields.forEach(function (s) {
|
|
41
|
-
|
|
47
|
+
var _a;
|
|
48
|
+
mediaAttrs[s] = (_a = {
|
|
49
|
+
type: 'string',
|
|
50
|
+
required: true
|
|
51
|
+
},
|
|
52
|
+
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
53
|
+
_a);
|
|
42
54
|
});
|
|
43
55
|
stringFields.forEach(function (s) {
|
|
44
56
|
mediaAttrs[s] = { type: 'string' };
|
|
45
57
|
});
|
|
46
58
|
numberFields.forEach(function (s) {
|
|
47
|
-
mediaAttrs[s] = { type: 'integer'
|
|
59
|
+
mediaAttrs[s] = { type: 'integer' };
|
|
60
|
+
});
|
|
61
|
+
numberRequiredFields.forEach(function (s) {
|
|
62
|
+
var _a;
|
|
63
|
+
mediaAttrs[s] = (_a = {
|
|
64
|
+
type: 'integer',
|
|
65
|
+
required: true
|
|
66
|
+
},
|
|
67
|
+
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
68
|
+
_a);
|
|
48
69
|
});
|
|
49
70
|
// const dataAttrs = {
|
|
50
71
|
// data: {
|