@oak-digital/types-4-strapi-2 0.5.3 → 0.5.5
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 +4 -3
- package/lib/content-types/reader.d.ts +2 -2
- package/lib/content-types/reader.js +7 -7
- package/lib/events/index.d.ts +6 -1
- package/lib/events/index.js +5 -0
- package/lib/interface/Interface.js +5 -0
- package/lib/plugins/PluginManager.d.ts +8 -4
- package/lib/plugins/PluginManager.js +11 -6
- package/lib/plugins/draft-and-publish/index.d.ts +3 -0
- package/lib/plugins/draft-and-publish/index.js +36 -0
- package/lib/plugins/i18n/index.d.ts +3 -0
- package/lib/plugins/i18n/index.js +41 -0
- package/lib/plugins/index.js +7 -0
- package/lib/plugins/types.d.ts +3 -1
- package/lib/plugins/types.js +1 -0
- package/lib/plugins/url-alias/index.d.ts +2 -2
- package/lib/plugins/url-alias/index.js +14 -1
- package/lib/plugins/url-alias/type.d.ts +8 -0
- package/lib/plugins/url-alias/type.js +41 -0
- package/lib/program/InterfaceManager.d.ts +4 -2
- package/lib/program/InterfaceManager.js +34 -17
- package/package.json +9 -8
- package/lib/.prettierrc.json +0 -7
- package/lib/case/index.d.ts +0 -4
- package/lib/case/index.js +0 -47
- package/lib/interface/Attributes.d.ts +0 -11
- package/lib/interface/Attributes.js +0 -167
- package/lib/interface/InterfaceManager.d.ts +0 -39
- package/lib/interface/InterfaceManager.js +0 -396
- package/lib/interface/interfaceCreator.d.ts +0 -0
- package/lib/interface/interfaceCreator.js +0 -7
- package/lib/interface/interfaceWriter.d.ts +0 -2
- package/lib/interface/interfaceWriter.js +0 -46
- package/lib/interface/schemaReader.d.ts +0 -14
- package/lib/interface/schemaReader.js +0 -177
- package/lib/src/index.d.ts +0 -1
- package/lib/src/index.js +0 -25
- package/lib/src/interface/Attributes.d.ts +0 -11
- package/lib/src/interface/Attributes.js +0 -148
- package/lib/src/interface/BuiltinComponentInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinComponentInterface.js +0 -36
- package/lib/src/interface/BuiltinInterface.d.ts +0 -5
- package/lib/src/interface/BuiltinInterface.js +0 -33
- package/lib/src/interface/ComponentInterface.d.ts +0 -8
- package/lib/src/interface/ComponentInterface.js +0 -58
- package/lib/src/interface/Interface.d.ts +0 -31
- package/lib/src/interface/Interface.js +0 -112
- package/lib/src/interface/InterfaceManager.d.ts +0 -25
- package/lib/src/interface/InterfaceManager.js +0 -288
- package/lib/src/interface/builtinInterfaces.d.ts +0 -4
- package/lib/src/interface/builtinInterfaces.js +0 -81
- package/lib/src/interface/schemaReader.d.ts +0 -14
- package/lib/src/interface/schemaReader.js +0 -172
- package/lib/src/utils/index.d.ts +0 -3
- package/lib/src/utils/index.js +0 -67
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
function writeInterface(inter) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
41
|
-
return __generator(this, function (_a) {
|
|
42
|
-
return [2 /*return*/];
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
exports.default = writeInterface;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare function readSchema(schemaPath: string): Promise<any>;
|
|
2
|
-
export declare function getApiFolders(strapiSrcRoot: string): Promise<string[]>;
|
|
3
|
-
export declare function getComponentCategoryFolders(strapiSrcRoot: string): Promise<string[]>;
|
|
4
|
-
export declare function getComponentSchemas(strapiSrcRoot: string): Promise<{
|
|
5
|
-
category: string;
|
|
6
|
-
schemas: {
|
|
7
|
-
name: string;
|
|
8
|
-
attributes: any;
|
|
9
|
-
}[];
|
|
10
|
-
}[]>;
|
|
11
|
-
export declare function getApiSchemas(strapiSrcRoot: string): Promise<{
|
|
12
|
-
name: string;
|
|
13
|
-
attributes: any;
|
|
14
|
-
}[]>;
|
|
@@ -1,177 +0,0 @@
|
|
|
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 node_fs_1 = require("node:fs");
|
|
41
|
-
var promises_1 = require("node:fs/promises");
|
|
42
|
-
var posix_1 = require("node:path/posix");
|
|
43
|
-
var utils_1 = require("../utils");
|
|
44
|
-
function readSchema(schemaPath) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var schemaData, e_1;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0:
|
|
50
|
-
_a.trys.push([0, 2, , 3]);
|
|
51
|
-
return [4 /*yield*/, (0, promises_1.readFile)(schemaPath)];
|
|
52
|
-
case 1:
|
|
53
|
-
schemaData = _a.sent();
|
|
54
|
-
return [2 /*return*/, JSON.parse(schemaData.toString()).attributes];
|
|
55
|
-
case 2:
|
|
56
|
-
e_1 = _a.sent();
|
|
57
|
-
return [2 /*return*/, null];
|
|
58
|
-
case 3: return [2 /*return*/];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
exports.readSchema = readSchema;
|
|
64
|
-
function getApiFolders(strapiSrcRoot) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
-
var path, folders;
|
|
67
|
-
return __generator(this, function (_a) {
|
|
68
|
-
switch (_a.label) {
|
|
69
|
-
case 0:
|
|
70
|
-
path = (0, posix_1.join)(strapiSrcRoot, 'api');
|
|
71
|
-
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
72
|
-
case 1:
|
|
73
|
-
folders = _a.sent();
|
|
74
|
-
return [2 /*return*/, folders];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
exports.getApiFolders = getApiFolders;
|
|
80
|
-
function getComponentCategoryFolders(strapiSrcRoot) {
|
|
81
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var path, folders;
|
|
83
|
-
return __generator(this, function (_a) {
|
|
84
|
-
switch (_a.label) {
|
|
85
|
-
case 0:
|
|
86
|
-
path = (0, posix_1.join)(strapiSrcRoot, 'components');
|
|
87
|
-
// If there exists no components, just fallback to an empty array.
|
|
88
|
-
if (!(0, node_fs_1.existsSync)(path)) {
|
|
89
|
-
return [2 /*return*/, []];
|
|
90
|
-
}
|
|
91
|
-
return [4 /*yield*/, (0, utils_1.readDirFiltered)(path)];
|
|
92
|
-
case 1:
|
|
93
|
-
folders = _a.sent();
|
|
94
|
-
return [2 /*return*/, folders];
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
exports.getComponentCategoryFolders = getComponentCategoryFolders;
|
|
100
|
-
function getComponentSchemas(strapiSrcRoot) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var categories, nestedSchemasPromises, nestedSchemasArr;
|
|
103
|
-
var _this = this;
|
|
104
|
-
return __generator(this, function (_a) {
|
|
105
|
-
switch (_a.label) {
|
|
106
|
-
case 0: return [4 /*yield*/, getComponentCategoryFolders(strapiSrcRoot)];
|
|
107
|
-
case 1:
|
|
108
|
-
categories = _a.sent();
|
|
109
|
-
nestedSchemasPromises = categories.map(function (category) { return __awaiter(_this, void 0, void 0, function () {
|
|
110
|
-
var schemaFilesPath, schemaFiles, schemaNamesWithAttributesPromises, schemaNamesWithAttributes;
|
|
111
|
-
var _this = this;
|
|
112
|
-
return __generator(this, function (_a) {
|
|
113
|
-
switch (_a.label) {
|
|
114
|
-
case 0:
|
|
115
|
-
schemaFilesPath = (0, posix_1.join)(strapiSrcRoot, 'components', category);
|
|
116
|
-
return [4 /*yield*/, (0, utils_1.readDirFiltered)(schemaFilesPath)];
|
|
117
|
-
case 1:
|
|
118
|
-
schemaFiles = _a.sent();
|
|
119
|
-
schemaNamesWithAttributesPromises = schemaFiles.map(function (file) { return __awaiter(_this, void 0, void 0, function () {
|
|
120
|
-
var schemaPath, attributes, name;
|
|
121
|
-
return __generator(this, function (_a) {
|
|
122
|
-
switch (_a.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
schemaPath = (0, posix_1.join)(schemaFilesPath, file);
|
|
125
|
-
return [4 /*yield*/, readSchema(schemaPath)];
|
|
126
|
-
case 1:
|
|
127
|
-
attributes = _a.sent();
|
|
128
|
-
name = file.split('.')[0];
|
|
129
|
-
return [2 /*return*/, { name: name, attributes: attributes }];
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}); });
|
|
133
|
-
return [4 /*yield*/, Promise.all(schemaNamesWithAttributesPromises)];
|
|
134
|
-
case 2:
|
|
135
|
-
schemaNamesWithAttributes = _a.sent();
|
|
136
|
-
return [2 /*return*/, { category: category, schemas: schemaNamesWithAttributes }];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}); });
|
|
140
|
-
return [4 /*yield*/, Promise.all(nestedSchemasPromises)];
|
|
141
|
-
case 2:
|
|
142
|
-
nestedSchemasArr = _a.sent();
|
|
143
|
-
return [2 /*return*/, nestedSchemasArr];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
exports.getComponentSchemas = getComponentSchemas;
|
|
149
|
-
function getApiSchemas(strapiSrcRoot) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
151
|
-
var apiFolders, schemasWithAttributesPromises, schemasWithAttributes;
|
|
152
|
-
var _this = this;
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (_a.label) {
|
|
155
|
-
case 0: return [4 /*yield*/, getApiFolders(strapiSrcRoot)];
|
|
156
|
-
case 1:
|
|
157
|
-
apiFolders = _a.sent();
|
|
158
|
-
schemasWithAttributesPromises = apiFolders.map(function (folder) { return __awaiter(_this, void 0, void 0, function () {
|
|
159
|
-
var schemaPath, attributes;
|
|
160
|
-
return __generator(this, function (_a) {
|
|
161
|
-
switch (_a.label) {
|
|
162
|
-
case 0:
|
|
163
|
-
schemaPath = (0, posix_1.join)(strapiSrcRoot, 'api', folder, 'content-types', folder, 'schema.json');
|
|
164
|
-
return [4 /*yield*/, readSchema(schemaPath)];
|
|
165
|
-
case 1:
|
|
166
|
-
attributes = _a.sent();
|
|
167
|
-
return [2 /*return*/, { name: folder, attributes: attributes }];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
}); });
|
|
171
|
-
schemasWithAttributes = Promise.all(schemasWithAttributesPromises);
|
|
172
|
-
return [2 /*return*/, schemasWithAttributes];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
exports.getApiSchemas = getApiSchemas;
|
package/lib/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/src/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var commander_1 = require("commander");
|
|
7
|
-
var InterfaceManager_1 = __importDefault(require("./interface/InterfaceManager"));
|
|
8
|
-
commander_1.program
|
|
9
|
-
.name('t4s');
|
|
10
|
-
commander_1.program
|
|
11
|
-
.option('-i, --in <dir>', 'The src directory for strapi', './src')
|
|
12
|
-
.option('-o, --out <dir>', 'The output directory to output the types to', './types')
|
|
13
|
-
.option('--component-prefix <prefix>', 'A prefix for components', '')
|
|
14
|
-
.option('--prettier <file>', 'The prettier config file to use for formatting typescript interfaces');
|
|
15
|
-
commander_1.program.parse();
|
|
16
|
-
var options = commander_1.program.opts();
|
|
17
|
-
console.log(options);
|
|
18
|
-
var input = options.in, out = options.out, componentPrefix = options.componentPrefix, prettierFile = options.prettier;
|
|
19
|
-
var manager = new InterfaceManager_1.default(out, input, {
|
|
20
|
-
componentPrefix: componentPrefix,
|
|
21
|
-
prettierFile: prettierFile,
|
|
22
|
-
});
|
|
23
|
-
manager.run().catch(function (err) {
|
|
24
|
-
console.error(err);
|
|
25
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { RelationNames } from './Interface';
|
|
2
|
-
export default class Attributes {
|
|
3
|
-
Attrs: Record<string, Record<string, any>>;
|
|
4
|
-
private RelationNames;
|
|
5
|
-
constructor(attr: Record<string, Record<string, any>>, relationNames: RelationNames);
|
|
6
|
-
isAttributeOptional(attr: any): boolean;
|
|
7
|
-
getDependencies(): any[];
|
|
8
|
-
attributeToString(attrName: string, attr: any): string;
|
|
9
|
-
toFieldsString(): string;
|
|
10
|
-
toString(): string;
|
|
11
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var Attributes = /** @class */ (function () {
|
|
4
|
-
function Attributes(attr, relationNames) {
|
|
5
|
-
this.RelationNames = {};
|
|
6
|
-
this.Attrs = attr;
|
|
7
|
-
this.RelationNames = relationNames;
|
|
8
|
-
}
|
|
9
|
-
Attributes.prototype.isAttributeOptional = function (attr) {
|
|
10
|
-
// If it is a component / relation / dynamiczone it is always optional due to population
|
|
11
|
-
switch (attr.type) {
|
|
12
|
-
case 'nested':
|
|
13
|
-
return attr.nullable === true;
|
|
14
|
-
case 'component':
|
|
15
|
-
case 'dynamiczone':
|
|
16
|
-
case 'relation':
|
|
17
|
-
return true;
|
|
18
|
-
default:
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
};
|
|
23
|
-
Attributes.prototype.getDependencies = function () {
|
|
24
|
-
var dependencies = [];
|
|
25
|
-
for (var attrName in this.Attrs) {
|
|
26
|
-
var attr = this.Attrs[attrName];
|
|
27
|
-
var dependencyNames = [];
|
|
28
|
-
switch (attr.type) {
|
|
29
|
-
case 'nested':
|
|
30
|
-
var attrs = new Attributes(attr.fields, this.RelationNames);
|
|
31
|
-
dependencyNames.push.apply(dependencyNames, attrs.getDependencies());
|
|
32
|
-
break;
|
|
33
|
-
case 'relation':
|
|
34
|
-
dependencyNames.push(attr.target);
|
|
35
|
-
break;
|
|
36
|
-
case 'component':
|
|
37
|
-
dependencyNames.push(attr.component);
|
|
38
|
-
break;
|
|
39
|
-
case 'media':
|
|
40
|
-
dependencyNames.push('builtins::Media');
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
// // If the current dependency is the interface itself, do not report it as a dependency
|
|
46
|
-
// if (dependencyName === strapiName) {
|
|
47
|
-
// continue;
|
|
48
|
-
// }
|
|
49
|
-
dependencyNames.forEach(function (dependencyName) {
|
|
50
|
-
if (!dependencies.includes(dependencyName)) {
|
|
51
|
-
dependencies.push(dependencyName);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
return dependencies;
|
|
56
|
-
};
|
|
57
|
-
Attributes.prototype.attributeToString = function (attrName, attr) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
var optionalString = this.isAttributeOptional(attr) ? '?' : '';
|
|
60
|
-
var str = " ".concat(attrName).concat(optionalString, ": ");
|
|
61
|
-
var isArray = false;
|
|
62
|
-
switch (attr.type) {
|
|
63
|
-
// types-4-strapi-2 specific, used for builtin types
|
|
64
|
-
case 'nested':
|
|
65
|
-
// Be careful with recursion
|
|
66
|
-
// console.log(attr);
|
|
67
|
-
var newAttrs = new Attributes(attr.fields, this.RelationNames);
|
|
68
|
-
str += newAttrs.toString();
|
|
69
|
-
break;
|
|
70
|
-
case 'relation':
|
|
71
|
-
var apiName = attr.target;
|
|
72
|
-
// console.log(this.RelationNames, apiName)
|
|
73
|
-
var dependencyName = this.RelationNames[apiName].name;
|
|
74
|
-
isArray = attr.relation.endsWith('ToMany');
|
|
75
|
-
str += dependencyName;
|
|
76
|
-
break;
|
|
77
|
-
case 'component':
|
|
78
|
-
var componentName = attr.component;
|
|
79
|
-
var relationNameObj = this.RelationNames[componentName];
|
|
80
|
-
var dependencyComponentName = relationNameObj.name;
|
|
81
|
-
isArray = (_a = attr.repeatable) !== null && _a !== void 0 ? _a : false;
|
|
82
|
-
str += dependencyComponentName;
|
|
83
|
-
break;
|
|
84
|
-
case 'media':
|
|
85
|
-
var mediaOptional = attr.required !== true ? '?' : '';
|
|
86
|
-
str += "{ data".concat(mediaOptional, ": ").concat(this.RelationNames['builtins::Media'].name, "; }");
|
|
87
|
-
isArray = (_b = attr.multiple) !== null && _b !== void 0 ? _b : false;
|
|
88
|
-
break;
|
|
89
|
-
case 'password':
|
|
90
|
-
return null;
|
|
91
|
-
case 'enumeration':
|
|
92
|
-
var hasDefault = 'default' in attr;
|
|
93
|
-
var enums = attr.enum.map(function (en) { return "\"".concat(en, "\""); });
|
|
94
|
-
enums.push('null');
|
|
95
|
-
var typeString = enums.join(' | ');
|
|
96
|
-
str += typeString;
|
|
97
|
-
break;
|
|
98
|
-
case 'string':
|
|
99
|
-
case 'text':
|
|
100
|
-
case 'richtext':
|
|
101
|
-
case 'email':
|
|
102
|
-
case 'uid':
|
|
103
|
-
str += 'string';
|
|
104
|
-
break;
|
|
105
|
-
case 'integer':
|
|
106
|
-
case 'biginteger':
|
|
107
|
-
case 'decimal':
|
|
108
|
-
case 'float':
|
|
109
|
-
str += 'number';
|
|
110
|
-
break;
|
|
111
|
-
case 'date':
|
|
112
|
-
case 'datetime':
|
|
113
|
-
case 'time':
|
|
114
|
-
str += 'Date';
|
|
115
|
-
break;
|
|
116
|
-
case 'boolean':
|
|
117
|
-
str += attr.type;
|
|
118
|
-
break;
|
|
119
|
-
case 'json':
|
|
120
|
-
default:
|
|
121
|
-
str += 'any';
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
var isArrayString = isArray ? '[]' : '';
|
|
125
|
-
str += "".concat(isArrayString, ";");
|
|
126
|
-
return str;
|
|
127
|
-
};
|
|
128
|
-
Attributes.prototype.toFieldsString = function () {
|
|
129
|
-
var strings = [];
|
|
130
|
-
for (var attrName in this.Attrs) {
|
|
131
|
-
var attr = this.Attrs[attrName];
|
|
132
|
-
var attrString = this.attributeToString(attrName, attr);
|
|
133
|
-
if (attrString === null) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
strings.push(attrString);
|
|
137
|
-
}
|
|
138
|
-
return strings.map(function (s) { return "".concat(s, "\n"); }).join('');
|
|
139
|
-
};
|
|
140
|
-
Attributes.prototype.toString = function () {
|
|
141
|
-
var strings = ['{'];
|
|
142
|
-
strings.push(this.toFieldsString());
|
|
143
|
-
strings.push('}');
|
|
144
|
-
return strings.join('\n');
|
|
145
|
-
};
|
|
146
|
-
return Attributes;
|
|
147
|
-
}());
|
|
148
|
-
exports.default = Attributes;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
var ComponentInterface_1 = __importDefault(require("./ComponentInterface"));
|
|
22
|
-
var BuiltinComponentInterface = /** @class */ (function (_super) {
|
|
23
|
-
__extends(BuiltinComponentInterface, _super);
|
|
24
|
-
function BuiltinComponentInterface(baseName, attributes, relativeDirectoryPath, prefix) {
|
|
25
|
-
if (prefix === void 0) { prefix = ''; }
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath, 'builtins', prefix, {
|
|
27
|
-
hasId: false,
|
|
28
|
-
hasComponent: false,
|
|
29
|
-
}) || this;
|
|
30
|
-
}
|
|
31
|
-
BuiltinComponentInterface.prototype.updateStrapiName = function () {
|
|
32
|
-
this.StrapiName = "builtins::".concat(this.BaseName);
|
|
33
|
-
};
|
|
34
|
-
return BuiltinComponentInterface;
|
|
35
|
-
}(ComponentInterface_1.default));
|
|
36
|
-
exports.default = BuiltinComponentInterface;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
var Interface_1 = __importDefault(require("./Interface"));
|
|
22
|
-
var BuiltinInterface = /** @class */ (function (_super) {
|
|
23
|
-
__extends(BuiltinInterface, _super);
|
|
24
|
-
function BuiltinInterface(baseName, attributes, relativeDirectoryPath, prefix) {
|
|
25
|
-
if (prefix === void 0) { prefix = ''; }
|
|
26
|
-
return _super.call(this, baseName, attributes, relativeDirectoryPath, prefix) || this;
|
|
27
|
-
}
|
|
28
|
-
BuiltinInterface.prototype.updateStrapiName = function () {
|
|
29
|
-
this.StrapiName = "builtins::".concat(this.BaseName);
|
|
30
|
-
};
|
|
31
|
-
return BuiltinInterface;
|
|
32
|
-
}(Interface_1.default));
|
|
33
|
-
exports.default = BuiltinInterface;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import Interface from './Interface';
|
|
2
|
-
export default class ComponentInterface extends Interface {
|
|
3
|
-
protected Category: string;
|
|
4
|
-
protected Options: Record<string, any>;
|
|
5
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, category: string, prefix?: string, options?: Record<string, any>);
|
|
6
|
-
updateStrapiName(): void;
|
|
7
|
-
getInterfaceFieldsString(): string;
|
|
8
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
-
};
|
|
20
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
var Interface_1 = __importDefault(require("./Interface"));
|
|
22
|
-
var ComponentInterface = /** @class */ (function (_super) {
|
|
23
|
-
__extends(ComponentInterface, _super);
|
|
24
|
-
function ComponentInterface(baseName, attributes, relativeDirectoryPath, category, prefix, options) {
|
|
25
|
-
if (prefix === void 0) { prefix = ''; }
|
|
26
|
-
if (options === void 0) { options = {}; }
|
|
27
|
-
var _this = _super.call(this, baseName, attributes, relativeDirectoryPath, prefix) || this;
|
|
28
|
-
_this.Options = {
|
|
29
|
-
hasId: true,
|
|
30
|
-
hasComponent: true,
|
|
31
|
-
};
|
|
32
|
-
_this.Category = category;
|
|
33
|
-
// this.Attributes.id = {
|
|
34
|
-
// type: "number", // Components have a id field with a number
|
|
35
|
-
// required: true,
|
|
36
|
-
// };
|
|
37
|
-
_this.updateStrapiName();
|
|
38
|
-
Object.assign(_this.Options, options);
|
|
39
|
-
return _this;
|
|
40
|
-
}
|
|
41
|
-
ComponentInterface.prototype.updateStrapiName = function () {
|
|
42
|
-
this.StrapiName = "".concat(this.Category, ".").concat(this.getBaseName());
|
|
43
|
-
};
|
|
44
|
-
ComponentInterface.prototype.getInterfaceFieldsString = function () {
|
|
45
|
-
var attrs = this.getAttributes();
|
|
46
|
-
var str = '';
|
|
47
|
-
var _a = this.Options, hasId = _a.hasId, hasComponent = _a.hasComponent;
|
|
48
|
-
if (hasId) {
|
|
49
|
-
str += ' id: number;\n';
|
|
50
|
-
}
|
|
51
|
-
if (hasComponent) {
|
|
52
|
-
str += " __component: \"".concat(this.getStrapiName(), "\";\n");
|
|
53
|
-
}
|
|
54
|
-
return str + attrs.toFieldsString();
|
|
55
|
-
};
|
|
56
|
-
return ComponentInterface;
|
|
57
|
-
}(Interface_1.default));
|
|
58
|
-
exports.default = ComponentInterface;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import Attributes from './Attributes';
|
|
2
|
-
export declare type RelationNames = Record<string, {
|
|
3
|
-
name: string;
|
|
4
|
-
inter: Interface;
|
|
5
|
-
}>;
|
|
6
|
-
export default class Interface {
|
|
7
|
-
protected BaseName: string;
|
|
8
|
-
private Relations;
|
|
9
|
-
private RelationNames;
|
|
10
|
-
private RelationNamesCounter;
|
|
11
|
-
private NamePrefix;
|
|
12
|
-
protected Attributes: any;
|
|
13
|
-
private RelativeDirectoryPath;
|
|
14
|
-
protected StrapiName: string;
|
|
15
|
-
constructor(baseName: string, attributes: any, relativeDirectoryPath: string, prefix?: string);
|
|
16
|
-
protected updateStrapiName(): void;
|
|
17
|
-
getBaseName(): string;
|
|
18
|
-
getStrapiName(): string;
|
|
19
|
-
getDependencies(): any[];
|
|
20
|
-
getFullInterfaceName(): string;
|
|
21
|
-
getRelativeRootPath(): any;
|
|
22
|
-
getRelativeRootDir(): string;
|
|
23
|
-
getRelativeRootPathFile(): string;
|
|
24
|
-
setRelations(relations: Interface[]): void;
|
|
25
|
-
private getTsImports;
|
|
26
|
-
getAttributes(): Attributes;
|
|
27
|
-
attributesToString(): string;
|
|
28
|
-
getInerfaceString(): string;
|
|
29
|
-
getInterfaceFieldsString(): string;
|
|
30
|
-
toString(): string;
|
|
31
|
-
}
|