@oak-digital/types-4-strapi-2 0.2.1 → 0.2.2
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/.editorconfig +9 -0
- package/.eslintrc.json +52 -0
- package/.prettierrc.json +7 -0
- package/README.md +1 -1
- package/lib/.prettierrc.json +7 -0
- package/lib/index.js +5 -3
- package/lib/interface/InterfaceManager.d.ts +3 -0
- package/lib/interface/InterfaceManager.js +44 -17
- package/lib/src/index.d.ts +1 -0
- package/lib/src/index.js +25 -0
- package/lib/src/interface/Attributes.d.ts +11 -0
- package/lib/src/interface/Attributes.js +148 -0
- package/lib/src/interface/BuiltinComponentInterface.d.ts +5 -0
- package/lib/src/interface/BuiltinComponentInterface.js +36 -0
- package/lib/src/interface/BuiltinInterface.d.ts +5 -0
- package/lib/src/interface/BuiltinInterface.js +33 -0
- package/lib/src/interface/ComponentInterface.d.ts +8 -0
- package/lib/src/interface/ComponentInterface.js +58 -0
- package/lib/src/interface/Interface.d.ts +31 -0
- package/lib/src/interface/Interface.js +112 -0
- package/lib/src/interface/InterfaceManager.d.ts +25 -0
- package/lib/src/interface/InterfaceManager.js +288 -0
- package/lib/src/interface/builtinInterfaces.d.ts +4 -0
- package/lib/src/interface/builtinInterfaces.js +81 -0
- package/lib/src/interface/schemaReader.d.ts +14 -0
- package/lib/src/interface/schemaReader.js +172 -0
- package/lib/src/utils/index.d.ts +3 -0
- package/lib/src/utils/index.js +67 -0
- package/package.json +8 -2
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getApiSchemas = exports.getComponentSchemas = exports.getComponentCategoryFolders = exports.getApiFolders = exports.readSchema = void 0;
|
|
40
|
+
var promises_1 = require("node:fs/promises");
|
|
41
|
+
var node_path_1 = require("node:path");
|
|
42
|
+
var utils_1 = require("../utils");
|
|
43
|
+
function readSchema(schemaPath) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
+
var schemaData, e_1;
|
|
46
|
+
return __generator(this, function (_a) {
|
|
47
|
+
switch (_a.label) {
|
|
48
|
+
case 0:
|
|
49
|
+
_a.trys.push([0, 2, , 3]);
|
|
50
|
+
return [4 /*yield*/, (0, promises_1.readFile)(schemaPath)];
|
|
51
|
+
case 1:
|
|
52
|
+
schemaData = _a.sent();
|
|
53
|
+
return [2 /*return*/, JSON.parse(schemaData.toString()).attributes];
|
|
54
|
+
case 2:
|
|
55
|
+
e_1 = _a.sent();
|
|
56
|
+
return [2 /*return*/, null];
|
|
57
|
+
case 3: return [2 /*return*/];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
exports.readSchema = readSchema;
|
|
63
|
+
function getApiFolders(strapiSrcRoot) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var path, folders;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
path = (0, node_path_1.join)(strapiSrcRoot, 'api');
|
|
70
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
71
|
+
case 1:
|
|
72
|
+
folders = _a.sent();
|
|
73
|
+
return [2 /*return*/, folders];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.getApiFolders = getApiFolders;
|
|
79
|
+
function getComponentCategoryFolders(strapiSrcRoot) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
81
|
+
var path, folders;
|
|
82
|
+
return __generator(this, function (_a) {
|
|
83
|
+
switch (_a.label) {
|
|
84
|
+
case 0:
|
|
85
|
+
path = (0, node_path_1.join)(strapiSrcRoot, 'components');
|
|
86
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
87
|
+
case 1:
|
|
88
|
+
folders = _a.sent();
|
|
89
|
+
return [2 /*return*/, folders];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.getComponentCategoryFolders = getComponentCategoryFolders;
|
|
95
|
+
function getComponentSchemas(strapiSrcRoot) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
+
var categories, nestedSchemasPromises, nestedSchemasArr;
|
|
98
|
+
var _this = this;
|
|
99
|
+
return __generator(this, function (_a) {
|
|
100
|
+
switch (_a.label) {
|
|
101
|
+
case 0: return [4 /*yield*/, getComponentCategoryFolders(strapiSrcRoot)];
|
|
102
|
+
case 1:
|
|
103
|
+
categories = _a.sent();
|
|
104
|
+
nestedSchemasPromises = categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
105
|
+
var schemaFilesPath, schemaFiles, schemaNamesWithAttributesPromises, schemaNamesWithAttributes;
|
|
106
|
+
var _this = this;
|
|
107
|
+
return __generator(this, function (_a) {
|
|
108
|
+
switch (_a.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
schemaFilesPath = (0, node_path_1.join)(strapiSrcRoot, 'components', category);
|
|
111
|
+
return [4 /*yield*/, (0, utils_1.readDirFiltered)(schemaFilesPath)];
|
|
112
|
+
case 1:
|
|
113
|
+
schemaFiles = _a.sent();
|
|
114
|
+
schemaNamesWithAttributesPromises = schemaFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
115
|
+
var schemaPath, attributes, name;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
schemaPath = (0, node_path_1.join)(schemaFilesPath, file);
|
|
120
|
+
return [4 /*yield*/, readSchema(schemaPath)];
|
|
121
|
+
case 1:
|
|
122
|
+
attributes = _a.sent();
|
|
123
|
+
name = file.split('.')[0];
|
|
124
|
+
return [2 /*return*/, { name: name, attributes: attributes }];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); });
|
|
128
|
+
return [4 /*yield*/, Promise.all(schemaNamesWithAttributesPromises)];
|
|
129
|
+
case 2:
|
|
130
|
+
schemaNamesWithAttributes = _a.sent();
|
|
131
|
+
return [2 /*return*/, { category: category, schemas: schemaNamesWithAttributes }];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}); });
|
|
135
|
+
return [4 /*yield*/, Promise.all(nestedSchemasPromises)];
|
|
136
|
+
case 2:
|
|
137
|
+
nestedSchemasArr = _a.sent();
|
|
138
|
+
return [2 /*return*/, nestedSchemasArr];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.getComponentSchemas = getComponentSchemas;
|
|
144
|
+
function getApiSchemas(strapiSrcRoot) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
146
|
+
var apiFolders, schemasWithAttributesPromises, schemasWithAttributes;
|
|
147
|
+
var _this = this;
|
|
148
|
+
return __generator(this, function (_a) {
|
|
149
|
+
switch (_a.label) {
|
|
150
|
+
case 0: return [4 /*yield*/, getApiFolders(strapiSrcRoot)];
|
|
151
|
+
case 1:
|
|
152
|
+
apiFolders = _a.sent();
|
|
153
|
+
schemasWithAttributesPromises = apiFolders.map(function (folder) { return __awaiter(_this, void 0, void 0, function () {
|
|
154
|
+
var schemaPath, attributes;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0:
|
|
158
|
+
schemaPath = (0, node_path_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
|
|
159
|
+
return [4 /*yield*/, readSchema(schemaPath)];
|
|
160
|
+
case 1:
|
|
161
|
+
attributes = _a.sent();
|
|
162
|
+
return [2 /*return*/, { name: folder, attributes: attributes }];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}); });
|
|
166
|
+
schemasWithAttributes = Promise.all(schemasWithAttributesPromises);
|
|
167
|
+
return [2 /*return*/, schemasWithAttributes];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.getApiSchemas = getApiSchemas;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.prefixDotSlash = exports.readDirFiltered = exports.pascalCase = void 0;
|
|
40
|
+
var promises_1 = require("fs/promises");
|
|
41
|
+
function pascalCase(name) {
|
|
42
|
+
var words = name.match(/[a-z]+/gi);
|
|
43
|
+
var pascalName = words.map(function (word) {
|
|
44
|
+
return word.charAt(0).toUpperCase() + word.substring(1).toLowerCase();
|
|
45
|
+
}).join('');
|
|
46
|
+
// console.log(pascalName)
|
|
47
|
+
return pascalName;
|
|
48
|
+
}
|
|
49
|
+
exports.pascalCase = pascalCase;
|
|
50
|
+
function readDirFiltered(dir) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var folders;
|
|
53
|
+
return __generator(this, function (_a) {
|
|
54
|
+
switch (_a.label) {
|
|
55
|
+
case 0: return [4 /*yield*/, (0, promises_1.readdir)(dir)];
|
|
56
|
+
case 1:
|
|
57
|
+
folders = _a.sent();
|
|
58
|
+
return [2 /*return*/, folders.filter(function (folder) { return !folder.startsWith('.'); })];
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
exports.readDirFiltered = readDirFiltered;
|
|
64
|
+
function prefixDotSlash(path) {
|
|
65
|
+
return (/^\.?\.\//).test(path) ? path : './' + path;
|
|
66
|
+
}
|
|
67
|
+
exports.prefixDotSlash = prefixDotSlash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oak-digital/types-4-strapi-2",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Typescript interface generator for Strapi 4 models",
|
|
5
5
|
"bin": {
|
|
6
6
|
"t4s": "./bin/index.js"
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc -p .",
|
|
10
10
|
"testtypes": "node ./bin/index.js",
|
|
11
|
+
"lint": "eslint src/",
|
|
11
12
|
"t4s": "node ./bin/index.js"
|
|
12
13
|
},
|
|
13
14
|
"repository": {
|
|
@@ -28,9 +29,14 @@
|
|
|
28
29
|
"homepage": "https://github.com/Oak-Digital/types-4-strapi-2",
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"@types/node": "^18.7.2",
|
|
32
|
+
"@types/prettier": "^2.7.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^5.33.1",
|
|
34
|
+
"@typescript-eslint/parser": "^5.33.1",
|
|
35
|
+
"eslint": "^8.22.0",
|
|
31
36
|
"typescript": "^4.7.4"
|
|
32
37
|
},
|
|
33
38
|
"dependencies": {
|
|
34
|
-
"commander": "^9.4.0"
|
|
39
|
+
"commander": "^9.4.0",
|
|
40
|
+
"prettier": "^2.7.1"
|
|
35
41
|
}
|
|
36
42
|
}
|