@oak-digital/types-4-strapi-2 0.1.0 → 0.1.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/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oak-digital/types-4-strapi-2",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
7
7
|
},
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc -p .",
|
|
10
|
-
"testtypes": "node ./bin/index.js
|
|
10
|
+
"testtypes": "node ./bin/index.js",
|
|
11
11
|
"t4s": "node ./bin/index.js"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
@@ -20,7 +20,7 @@ export default class Attributes {
|
|
|
20
20
|
break;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return
|
|
23
|
+
return false;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
getDependencies(strapiName: string) {
|
|
@@ -68,6 +68,13 @@ export default class Attributes {
|
|
|
68
68
|
break;
|
|
69
69
|
case "password":
|
|
70
70
|
return null;
|
|
71
|
+
case "enumeration":
|
|
72
|
+
const hasDefault = "default" in attr;
|
|
73
|
+
const enums = attr.enum.map((en: string) => `"${en}"`)
|
|
74
|
+
enums.push("null")
|
|
75
|
+
const typeString = enums.join(" | ");
|
|
76
|
+
str += typeString;
|
|
77
|
+
break;
|
|
71
78
|
case "string":
|
|
72
79
|
case "text":
|
|
73
80
|
case "richtext":
|
|
@@ -99,8 +106,8 @@ export default class Attributes {
|
|
|
99
106
|
return str;
|
|
100
107
|
}
|
|
101
108
|
|
|
102
|
-
|
|
103
|
-
const strings = [
|
|
109
|
+
toFieldsString() : string {
|
|
110
|
+
const strings = [];
|
|
104
111
|
for (const attrName in this.Attrs) {
|
|
105
112
|
const attr = this.Attrs[attrName];
|
|
106
113
|
const attrString = this.attributeToString(attrName, attr);
|
|
@@ -109,7 +116,13 @@ export default class Attributes {
|
|
|
109
116
|
}
|
|
110
117
|
strings.push(attrString)
|
|
111
118
|
}
|
|
112
|
-
strings.
|
|
119
|
+
return strings.map(s => `${s}\n`).join("");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toString() : string {
|
|
123
|
+
const strings = [ "{" ];
|
|
124
|
+
strings.push(this.toFieldsString());
|
|
125
|
+
strings.push("}")
|
|
113
126
|
return strings.join("\n");
|
|
114
127
|
}
|
|
115
128
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { prefixDotSlash } from "../utils";
|
|
2
1
|
import Interface from "./Interface";
|
|
3
2
|
|
|
4
3
|
export default class ComponentInterface extends Interface {
|
|
@@ -7,10 +6,22 @@ export default class ComponentInterface extends Interface {
|
|
|
7
6
|
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, prefix: string = "") {
|
|
8
7
|
super(baseName, attributes, relativeDirectoryPath, prefix);
|
|
9
8
|
this.Category = category;
|
|
9
|
+
// this.Attributes.id = {
|
|
10
|
+
// type: "number", // Components have a id field with a number
|
|
11
|
+
// required: true,
|
|
12
|
+
// };
|
|
10
13
|
this.updateStrapiName();
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
updateStrapiName() {
|
|
14
17
|
this.StrapiName = `${this.Category}.${this.getBaseName()}`
|
|
15
18
|
}
|
|
19
|
+
|
|
20
|
+
getInterfaceFieldsString() {
|
|
21
|
+
const attrs = this.getAttributes();
|
|
22
|
+
let str = '';
|
|
23
|
+
str += ` id: number;\n`;
|
|
24
|
+
str += ` __component: "${this.getStrapiName()}";\n`
|
|
25
|
+
return str + attrs.toFieldsString();
|
|
26
|
+
}
|
|
16
27
|
}
|
|
@@ -8,7 +8,7 @@ export default class Interface {
|
|
|
8
8
|
private RelationNames: Record<string, [string, Interface]> = {};
|
|
9
9
|
private RelationNamesCounter: Record<string, number> = {};
|
|
10
10
|
private NamePrefix: string = "";
|
|
11
|
-
|
|
11
|
+
protected Attributes: any;
|
|
12
12
|
private RelativeDirectoryPath: string;
|
|
13
13
|
protected StrapiName: string;
|
|
14
14
|
|
|
@@ -90,8 +90,12 @@ export default class Interface {
|
|
|
90
90
|
}).filter(s => s).join("\n");
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
getAttributes() : Attributes {
|
|
94
|
+
return new Attributes(this.Attributes, this.RelationNames);
|
|
95
|
+
}
|
|
96
|
+
|
|
93
97
|
attributesToString() {
|
|
94
|
-
const attrs =
|
|
98
|
+
const attrs = this.getAttributes();
|
|
95
99
|
return attrs.toString();
|
|
96
100
|
}
|
|
97
101
|
|