@oak-digital/types-4-strapi-2 0.5.5 → 1.0.0-beta.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/.eslintrc.json +2 -1
- package/CHANGELOG.md +7 -0
- package/README.md +17 -5
- package/lib/attributes/Attributes.d.ts +4 -3
- package/lib/attributes/Attributes.js +102 -78
- package/lib/content-types/reader.js +49 -145
- package/lib/extra-types/ExtraType.d.ts +2 -2
- package/lib/extra-types/ExtraType.js +19 -38
- package/lib/extra-types/createExtraTypes.d.ts +1 -1
- package/lib/extra-types/createExtraTypes.js +11 -12
- package/lib/file/File.d.ts +1 -1
- package/lib/file/File.js +44 -43
- package/lib/index.js +57 -19
- package/lib/interface/BuiltinComponentInterface.js +9 -27
- package/lib/interface/BuiltinInterface.d.ts +0 -1
- package/lib/interface/BuiltinInterface.js +5 -26
- package/lib/interface/ComponentInterface.d.ts +2 -1
- package/lib/interface/ComponentInterface.js +30 -48
- package/lib/interface/Interface.d.ts +6 -2
- package/lib/interface/Interface.js +69 -70
- package/lib/interface/builtinInterfaces.d.ts +1941 -2
- package/lib/interface/builtinInterfaces.js +56 -46
- package/lib/plugins/PluginManager.d.ts +8 -2
- package/lib/plugins/PluginManager.js +28 -35
- package/lib/plugins/draft-and-publish/index.d.ts +1 -1
- package/lib/plugins/draft-and-publish/index.js +17 -21
- package/lib/plugins/i18n/index.d.ts +1 -1
- package/lib/plugins/i18n/index.js +17 -22
- package/lib/plugins/index.js +4 -4
- package/lib/plugins/types.d.ts +1 -1
- package/lib/plugins/types.js +1 -4
- package/lib/plugins/url-alias/index.js +12 -15
- package/lib/plugins/url-alias/type.js +21 -32
- package/lib/program/InterfaceManager.d.ts +374 -24
- package/lib/program/InterfaceManager.js +128 -376
- package/lib/readers/by-file.d.ts +321 -0
- package/lib/readers/by-file.js +116 -0
- package/lib/readers/load-strapi/index.d.ts +319 -0
- package/lib/readers/load-strapi/index.js +106 -0
- package/lib/readers/load-strapi/remote.d.ts +1 -0
- package/lib/readers/load-strapi/remote.js +29 -0
- package/lib/readers/types/attributes.d.ts +1639 -0
- package/lib/readers/types/attributes.js +144 -0
- package/lib/readers/types/component.d.ts +723 -0
- package/lib/readers/types/component.js +11 -0
- package/lib/readers/types/content-type-reader.d.ts +16 -0
- package/lib/readers/types/content-type-reader.js +2 -0
- package/lib/readers/types/content-type.d.ts +766 -0
- package/lib/readers/types/content-type.js +16 -0
- package/lib/utils/casing/index.js +2 -2
- package/lib/utils/index.js +5 -39
- package/lib/writers/basic-writer.d.ts +24 -0
- package/lib/writers/basic-writer.js +75 -0
- package/lib/writers/types/writer.d.ts +4 -0
- package/lib/writers/types/writer.js +2 -0
- package/package.json +4 -2
- package/tests/strapi-project/.editorconfig +16 -0
- package/tests/strapi-project/.env.example +6 -0
- package/tests/strapi-project/README.md +57 -0
- package/tests/strapi-project/config/admin.ts +13 -0
- package/tests/strapi-project/config/api.ts +7 -0
- package/tests/strapi-project/config/database.ts +93 -0
- package/tests/strapi-project/config/middlewares.ts +12 -0
- package/tests/strapi-project/config/server.ts +10 -0
- package/tests/strapi-project/database/migrations/.gitkeep +0 -0
- package/tests/strapi-project/favicon.png +0 -0
- package/tests/strapi-project/package-lock.json +16125 -0
- package/tests/strapi-project/package.json +30 -0
- package/tests/strapi-project/public/robots.txt +3 -0
- package/tests/strapi-project/public/uploads/.gitkeep +0 -0
- package/tests/strapi-project/src/admin/app.example.tsx +35 -0
- package/tests/strapi-project/src/admin/webpack.config.example.js +9 -0
- package/tests/strapi-project/src/api/.gitkeep +0 -0
- package/tests/strapi-project/src/api/collection-1/content-types/collection-1/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/content-types/generated-type/schema.json +18 -0
- package/tests/strapi-project/src/api/collection-1/controllers/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/controllers/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/routes/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/collection-1.ts +7 -0
- package/tests/strapi-project/src/api/collection-1/services/generated-type.ts +7 -0
- package/tests/strapi-project/src/api/standalone-controller/controllers/standalone-controller.ts +13 -0
- package/tests/strapi-project/src/components/my-category/all-types.json +88 -0
- package/tests/strapi-project/src/components/other-category/sub-component.json +12 -0
- package/tests/strapi-project/src/extensions/.gitkeep +0 -0
- package/tests/strapi-project/src/index.ts +18 -0
|
@@ -3,12 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMediaFormatInterface = exports.createMediaInterface = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
exports.createMediaFormatInterface = exports.createMediaInterface = exports.attributeWithNested = exports.nestedAttribute = void 0;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const attributes_1 = require("../readers/types/attributes");
|
|
10
|
+
const BuiltinComponentInterface_1 = __importDefault(require("./BuiltinComponentInterface"));
|
|
11
|
+
const BuiltinInterface_1 = __importDefault(require("./BuiltinInterface"));
|
|
12
|
+
exports.nestedAttribute = zod_1.z.object({
|
|
13
|
+
type: zod_1.z.literal('nested'),
|
|
14
|
+
nullable: zod_1.z.boolean().optional(),
|
|
15
|
+
fields: zod_1.z.record(attributes_1.contentTypeAttribute),
|
|
16
|
+
});
|
|
17
|
+
exports.attributeWithNested = zod_1.z.union([attributes_1.contentTypeAttribute, exports.nestedAttribute]);
|
|
18
|
+
function createMediaInterface(caseTypeName, prefix) {
|
|
19
|
+
const stringRequiredFields = [
|
|
12
20
|
'name',
|
|
13
21
|
'hash',
|
|
14
22
|
'ext',
|
|
@@ -16,21 +24,21 @@ function createMediaInterface(directory, caseTypeName, prefix) {
|
|
|
16
24
|
'url',
|
|
17
25
|
'provider',
|
|
18
26
|
];
|
|
19
|
-
|
|
27
|
+
const stringFields = [
|
|
20
28
|
'previewUrl',
|
|
21
29
|
'provider_metadata',
|
|
22
30
|
'alternativeText',
|
|
23
31
|
'caption', // nullable in plain text
|
|
24
32
|
];
|
|
25
|
-
|
|
33
|
+
const numberRequiredFields = ['size'];
|
|
26
34
|
// Nullable if you have a plain text file
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
const numberFields = ['width', 'height'];
|
|
36
|
+
const mediaFormat = {
|
|
29
37
|
type: 'component',
|
|
30
38
|
repeatable: false,
|
|
31
39
|
component: 'builtins::MediaFormat',
|
|
32
40
|
};
|
|
33
|
-
|
|
41
|
+
const mediaAttrs = {
|
|
34
42
|
formats: {
|
|
35
43
|
// types-4-strapi-2 specific
|
|
36
44
|
type: 'nested',
|
|
@@ -43,29 +51,25 @@ function createMediaInterface(directory, caseTypeName, prefix) {
|
|
|
43
51
|
},
|
|
44
52
|
},
|
|
45
53
|
};
|
|
46
|
-
stringRequiredFields.forEach(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
53
|
-
_a);
|
|
54
|
+
stringRequiredFields.forEach((s) => {
|
|
55
|
+
mediaAttrs[s] = {
|
|
56
|
+
type: 'text',
|
|
57
|
+
required: true,
|
|
58
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
59
|
+
};
|
|
54
60
|
});
|
|
55
|
-
stringFields.forEach(
|
|
56
|
-
mediaAttrs[s] = { type: '
|
|
61
|
+
stringFields.forEach((s) => {
|
|
62
|
+
mediaAttrs[s] = { type: 'text' };
|
|
57
63
|
});
|
|
58
|
-
numberFields.forEach(
|
|
64
|
+
numberFields.forEach((s) => {
|
|
59
65
|
mediaAttrs[s] = { type: 'integer' };
|
|
60
66
|
});
|
|
61
|
-
numberRequiredFields.forEach(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
68
|
-
_a);
|
|
67
|
+
numberRequiredFields.forEach((s) => {
|
|
68
|
+
mediaAttrs[s] = {
|
|
69
|
+
type: 'integer',
|
|
70
|
+
required: true,
|
|
71
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
72
|
+
};
|
|
69
73
|
});
|
|
70
74
|
// const dataAttrs = {
|
|
71
75
|
// data: {
|
|
@@ -74,29 +78,35 @@ function createMediaInterface(directory, caseTypeName, prefix) {
|
|
|
74
78
|
// nullable: true,
|
|
75
79
|
// },
|
|
76
80
|
// };
|
|
77
|
-
return new BuiltinInterface_1.default('Media', mediaAttrs,
|
|
81
|
+
return new BuiltinInterface_1.default('Media', mediaAttrs, '', caseTypeName, prefix);
|
|
78
82
|
}
|
|
79
83
|
exports.createMediaInterface = createMediaInterface;
|
|
80
|
-
function createMediaFormatInterface(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
stringRequiredFields.forEach(
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
function createMediaFormatInterface(caseTypeName, prefix) {
|
|
85
|
+
const stringRequiredFields = ['name', 'hash', 'ext', 'mime', 'url'];
|
|
86
|
+
const stringFields = ['path'];
|
|
87
|
+
const numberRequiredFields = ['size', 'width', 'height']; // TODO: not sure if this is corrext
|
|
88
|
+
const numberFields = [];
|
|
89
|
+
const mediaAttrs = {};
|
|
90
|
+
stringRequiredFields.forEach((s) => {
|
|
91
|
+
mediaAttrs[s] = {
|
|
92
|
+
type: 'string',
|
|
93
|
+
required: true,
|
|
94
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
95
|
+
};
|
|
89
96
|
});
|
|
90
|
-
stringFields.forEach(
|
|
97
|
+
stringFields.forEach((s) => {
|
|
91
98
|
mediaAttrs[s] = { type: 'string' };
|
|
92
99
|
});
|
|
93
|
-
numberRequiredFields.forEach(
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
numberRequiredFields.forEach((s) => {
|
|
101
|
+
mediaAttrs[s] = {
|
|
102
|
+
type: 'integer',
|
|
103
|
+
required: true,
|
|
104
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
105
|
+
};
|
|
96
106
|
});
|
|
97
|
-
numberFields.forEach(
|
|
107
|
+
numberFields.forEach((s) => {
|
|
98
108
|
mediaAttrs[s] = { type: 'integer' };
|
|
99
109
|
});
|
|
100
|
-
return new BuiltinComponentInterface_1.default('MediaFormat', mediaAttrs,
|
|
110
|
+
return new BuiltinComponentInterface_1.default('MediaFormat', mediaAttrs, '', caseTypeName, prefix);
|
|
101
111
|
}
|
|
102
112
|
exports.createMediaFormatInterface = createMediaFormatInterface;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Events } from '../events';
|
|
2
2
|
import InterfaceManager from '../program/InterfaceManager';
|
|
3
|
+
import { ContentTypeReader } from '../readers/types/content-type-reader';
|
|
4
|
+
declare type Schemas = {
|
|
5
|
+
apiSchemas: Awaited<ReturnType<ContentTypeReader['readContentTypes']>>;
|
|
6
|
+
componentSchemas: Awaited<ReturnType<ContentTypeReader['readComponents']>>;
|
|
7
|
+
};
|
|
3
8
|
export declare type HookTypes = {
|
|
4
|
-
[Events.BeforeReadSchema]: (state: InterfaceManager, schema:
|
|
5
|
-
[Events.AfterReadSchema]: (state: InterfaceManager, schema:
|
|
9
|
+
[Events.BeforeReadSchema]: (state: InterfaceManager, schema: Schemas) => void;
|
|
10
|
+
[Events.AfterReadSchema]: (state: InterfaceManager, schema: Schemas) => void;
|
|
6
11
|
[Events.BeforeReadSchemas]: (state: InterfaceManager) => void;
|
|
7
12
|
[Events.AfterReadSchemas]: (state: InterfaceManager) => void;
|
|
8
13
|
[Events.ModifySchemas]: (state: InterfaceManager) => void;
|
|
@@ -22,3 +27,4 @@ export declare class PluginManager {
|
|
|
22
27
|
sortHooks(): void;
|
|
23
28
|
invoke<Hook extends keyof HookTypes>(hook: Hook, ...args: Parameters<HookTypes[Hook]>): void;
|
|
24
29
|
}
|
|
30
|
+
export {};
|
|
@@ -1,46 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PluginManager = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
_a);
|
|
4
|
+
const events_1 = require("../events");
|
|
5
|
+
class PluginManager {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.hooks = {
|
|
8
|
+
[events_1.Events.BeforeReadSchema]: [],
|
|
9
|
+
[events_1.Events.BeforeReadSchemas]: [],
|
|
10
|
+
[events_1.Events.AfterReadSchema]: [],
|
|
11
|
+
[events_1.Events.AfterReadSchemas]: [],
|
|
12
|
+
[events_1.Events.ModifySchemas]: [],
|
|
13
|
+
[events_1.Events.BeforeInjectDependencies]: [],
|
|
14
|
+
[events_1.Events.AfterInjectDependencies]: [],
|
|
15
|
+
};
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
for (var hook in hooks) {
|
|
17
|
+
registerPlugin(hooks) {
|
|
18
|
+
for (const hook in hooks) {
|
|
21
19
|
if (hooks[hook]) {
|
|
22
|
-
|
|
20
|
+
this.hooks[hook].push(...hooks[hook]);
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
this.hooks[hook].push({ fn
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
for (
|
|
31
|
-
this.hooks[hook].sort(
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
PluginManager.prototype.invoke = function (hook) {
|
|
35
|
-
var args = [];
|
|
36
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
37
|
-
args[_i - 1] = arguments[_i];
|
|
23
|
+
}
|
|
24
|
+
registerHook(hook, fn, priority) {
|
|
25
|
+
this.hooks[hook].push({ fn, priority });
|
|
26
|
+
}
|
|
27
|
+
sortHooks() {
|
|
28
|
+
for (const hook in this.hooks) {
|
|
29
|
+
this.hooks[hook].sort((a, b) => a.priority - b.priority);
|
|
38
30
|
}
|
|
39
|
-
|
|
31
|
+
}
|
|
32
|
+
invoke(hook, ...args) {
|
|
33
|
+
this.hooks[hook].forEach((hook) => {
|
|
40
34
|
// @ts-ignore we know that it is the correct type, sunce HooksType is built from HookTypes
|
|
41
|
-
hook.fn
|
|
35
|
+
hook.fn(...args);
|
|
42
36
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}());
|
|
37
|
+
}
|
|
38
|
+
}
|
|
46
39
|
exports.PluginManager = PluginManager;
|
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
apiSchemas.forEach(
|
|
8
|
-
|
|
9
|
-
var attributes = schema.attributes, _b = schema.options, options = _b === void 0 ? {} : _b;
|
|
3
|
+
const constants_1 = require("../../constants");
|
|
4
|
+
const events_1 = require("../../events");
|
|
5
|
+
const addFieldsToContentTypes = (state, schema) => {
|
|
6
|
+
const { apiSchemas } = schema;
|
|
7
|
+
Object.entries(apiSchemas).forEach(([strapiName, schema]) => {
|
|
8
|
+
const { attributes, options = {} } = schema.contentType;
|
|
10
9
|
if ((options === null || options === void 0 ? void 0 : options.draftAndPublish) !== true) {
|
|
11
10
|
return;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
fieldNames.forEach(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
_a[constants_1.CERTAINLY_REQUIRED_KEY] = true,
|
|
21
|
-
_a);
|
|
12
|
+
const fieldNames = ['publishedAt', 'createdAt', 'updatedAt'];
|
|
13
|
+
fieldNames.forEach((fieldName) => {
|
|
14
|
+
attributes[fieldName] = {
|
|
15
|
+
type: 'string',
|
|
16
|
+
required: true,
|
|
17
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
18
|
+
};
|
|
22
19
|
});
|
|
23
20
|
});
|
|
24
21
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_a[events_1.Events.AfterReadSchema] = [
|
|
22
|
+
const register = () => {
|
|
23
|
+
return {
|
|
24
|
+
[events_1.Events.AfterReadSchema]: [
|
|
29
25
|
{
|
|
30
26
|
fn: addFieldsToContentTypes,
|
|
31
27
|
priority: 10,
|
|
32
28
|
},
|
|
33
29
|
],
|
|
34
|
-
|
|
30
|
+
};
|
|
35
31
|
};
|
|
36
32
|
exports.default = register;
|
|
@@ -1,41 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var name = _a.name, schema = _a.schema;
|
|
11
|
-
var attributes = schema.attributes;
|
|
12
|
-
if (((_d = (_c = schema === null || schema === void 0 ? void 0 : schema.pluginOptions) === null || _c === void 0 ? void 0 : _c.i18n) === null || _d === void 0 ? void 0 : _d.localized) !== true) {
|
|
3
|
+
const constants_1 = require("../../constants");
|
|
4
|
+
const events_1 = require("../../events");
|
|
5
|
+
const addLocaleToLocalizedContentTypes = (state, { apiSchemas }) => {
|
|
6
|
+
Object.entries(apiSchemas).forEach(([strapiName, schema]) => {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
const { attributes } = schema.contentType;
|
|
9
|
+
if (((_c = (_b = (_a = schema.contentType) === null || _a === void 0 ? void 0 : _a.pluginOptions) === null || _b === void 0 ? void 0 : _b.i18n) === null || _c === void 0 ? void 0 : _c.localized) !== true) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
// Add locale to all localized content types
|
|
16
|
-
attributes.locale =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_b);
|
|
13
|
+
attributes.locale = {
|
|
14
|
+
type: 'string',
|
|
15
|
+
required: true,
|
|
16
|
+
[constants_1.CERTAINLY_REQUIRED_KEY]: true,
|
|
17
|
+
};
|
|
22
18
|
// Add populatable field for localizations
|
|
23
19
|
attributes.localizations = {
|
|
24
20
|
type: 'relation',
|
|
25
21
|
relation: 'oneToMany',
|
|
26
|
-
target:
|
|
22
|
+
target: strapiName
|
|
27
23
|
};
|
|
28
24
|
});
|
|
29
25
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
_a[events_1.Events.AfterReadSchema] = [
|
|
26
|
+
const register = () => {
|
|
27
|
+
return {
|
|
28
|
+
[events_1.Events.AfterReadSchema]: [
|
|
34
29
|
{
|
|
35
30
|
fn: addLocaleToLocalizedContentTypes,
|
|
36
31
|
priority: 10,
|
|
37
32
|
},
|
|
38
33
|
],
|
|
39
|
-
|
|
34
|
+
};
|
|
40
35
|
};
|
|
41
36
|
exports.default = register;
|
package/lib/plugins/index.js
CHANGED
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.registerBuiltinPlugins = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const url_alias_1 = __importDefault(require("./url-alias"));
|
|
8
|
+
const draft_and_publish_1 = __importDefault(require("./draft-and-publish"));
|
|
9
|
+
const i18n_1 = __importDefault(require("./i18n"));
|
|
10
|
+
const registerBuiltinPlugins = (pluginManager, pluginNames) => {
|
|
11
11
|
// Draft and publish is always registered since it is built into Strapi
|
|
12
12
|
pluginManager.registerPlugin((0, draft_and_publish_1.default)());
|
|
13
13
|
if (pluginNames.has('url-alias')) {
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HooksType } from
|
|
1
|
+
import { HooksType } from './PluginManager';
|
|
2
2
|
export declare const supportedPluginNames: readonly ["url-alias", "i18n"];
|
|
3
3
|
export declare type SupportedPluginNamesType = typeof supportedPluginNames[number];
|
|
4
4
|
export declare type PluginRegister = () => Partial<HooksType>;
|
package/lib/plugins/types.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var name = _a.name, schema = _a.schema;
|
|
9
|
-
var attributes = schema.attributes;
|
|
3
|
+
const events_1 = require("../../events");
|
|
4
|
+
const type_1 = require("./type");
|
|
5
|
+
const addUrlAliasToAllContentTypes = (state, { apiSchemas }) => {
|
|
6
|
+
Object.entries(apiSchemas).forEach(([strapiName, schema]) => {
|
|
7
|
+
const { attributes } = schema.contentType;
|
|
10
8
|
// TODO: write comment here if it is intentional that it it can be null
|
|
11
9
|
attributes.url_path = {
|
|
12
10
|
type: 'string',
|
|
@@ -19,25 +17,24 @@ var addUrlAliasToAllContentTypes = function (state, _a) {
|
|
|
19
17
|
// };
|
|
20
18
|
});
|
|
21
19
|
};
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const addUrlAliasGetType = (state) => {
|
|
21
|
+
const urlAliasGet = new type_1.UrlAliasGet();
|
|
24
22
|
state.addType(urlAliasGet.getStrapiName(), urlAliasGet);
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_a[events_1.Events.AfterReadSchema] = [
|
|
24
|
+
const register = () => {
|
|
25
|
+
return {
|
|
26
|
+
[events_1.Events.AfterReadSchema]: [
|
|
30
27
|
{
|
|
31
28
|
fn: addUrlAliasToAllContentTypes,
|
|
32
29
|
priority: 10,
|
|
33
30
|
},
|
|
34
31
|
],
|
|
35
|
-
|
|
32
|
+
[events_1.Events.AfterReadSchemas]: [
|
|
36
33
|
{
|
|
37
34
|
fn: addUrlAliasGetType,
|
|
38
35
|
priority: 10,
|
|
39
36
|
},
|
|
40
37
|
],
|
|
41
|
-
|
|
38
|
+
};
|
|
42
39
|
};
|
|
43
40
|
exports.default = register;
|
|
@@ -1,41 +1,30 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.UrlAliasGet = void 0;
|
|
19
|
-
|
|
4
|
+
const File_1 = require("../../file/File");
|
|
20
5
|
/* import Interface from "../../interface/Interface"; */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return _super.call(this, baseName, 'plugins/url-alias', 'pascal') || this;
|
|
6
|
+
class UrlAliasGet extends File_1.File {
|
|
7
|
+
constructor() {
|
|
8
|
+
const baseName = 'url-alias';
|
|
9
|
+
super(baseName, 'plugins/url-alias', 'pascal'); // TODO: figure out how to change the casing
|
|
26
10
|
}
|
|
27
|
-
|
|
11
|
+
getStrapiName() {
|
|
28
12
|
return 'plugins::url-alias.get';
|
|
29
|
-
}
|
|
30
|
-
|
|
13
|
+
}
|
|
14
|
+
getFullName() {
|
|
31
15
|
return 'UrlAliasGet';
|
|
32
|
-
}
|
|
33
|
-
|
|
16
|
+
}
|
|
17
|
+
getDependencies() {
|
|
34
18
|
return [];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
19
|
+
}
|
|
20
|
+
toString() {
|
|
21
|
+
return `
|
|
22
|
+
export type ${this.getFullName()}<ContentType extends { attributes: {} }> = ContentType & {
|
|
23
|
+
attributes: {
|
|
24
|
+
contentType: string;
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
41
30
|
exports.UrlAliasGet = UrlAliasGet;
|