@strapi/core 5.19.0 → 5.21.0
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/dist/core-api/routes/index.d.ts +4 -22
- package/dist/core-api/routes/index.d.ts.map +1 -1
- package/dist/core-api/routes/index.js +150 -8
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +131 -8
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/validation/attributes.d.ts +244 -0
- package/dist/core-api/routes/validation/attributes.d.ts.map +1 -0
- package/dist/core-api/routes/validation/attributes.js +560 -0
- package/dist/core-api/routes/validation/attributes.js.map +1 -0
- package/dist/core-api/routes/validation/attributes.mjs +521 -0
- package/dist/core-api/routes/validation/attributes.mjs.map +1 -0
- package/dist/core-api/routes/validation/common.d.ts +105 -0
- package/dist/core-api/routes/validation/common.d.ts.map +1 -0
- package/dist/core-api/routes/validation/common.js +116 -0
- package/dist/core-api/routes/validation/common.js.map +1 -0
- package/dist/core-api/routes/validation/common.mjs +95 -0
- package/dist/core-api/routes/validation/common.mjs.map +1 -0
- package/dist/core-api/routes/validation/component.d.ts +34 -0
- package/dist/core-api/routes/validation/component.d.ts.map +1 -0
- package/dist/core-api/routes/validation/component.js +45 -0
- package/dist/core-api/routes/validation/component.js.map +1 -0
- package/dist/core-api/routes/validation/component.mjs +43 -0
- package/dist/core-api/routes/validation/component.mjs.map +1 -0
- package/dist/core-api/routes/validation/constants.d.ts +8 -0
- package/dist/core-api/routes/validation/constants.d.ts.map +1 -0
- package/dist/core-api/routes/validation/constants.js +18 -0
- package/dist/core-api/routes/validation/constants.js.map +1 -0
- package/dist/core-api/routes/validation/constants.mjs +16 -0
- package/dist/core-api/routes/validation/constants.mjs.map +1 -0
- package/dist/core-api/routes/validation/content-type.d.ts +128 -0
- package/dist/core-api/routes/validation/content-type.d.ts.map +1 -0
- package/dist/core-api/routes/validation/content-type.js +201 -0
- package/dist/core-api/routes/validation/content-type.js.map +1 -0
- package/dist/core-api/routes/validation/content-type.mjs +180 -0
- package/dist/core-api/routes/validation/content-type.mjs.map +1 -0
- package/dist/core-api/routes/validation/index.d.ts +5 -0
- package/dist/core-api/routes/validation/index.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.d.ts +105 -0
- package/dist/core-api/routes/validation/mappers.d.ts.map +1 -0
- package/dist/core-api/routes/validation/mappers.js +238 -0
- package/dist/core-api/routes/validation/mappers.js.map +1 -0
- package/dist/core-api/routes/validation/mappers.mjs +214 -0
- package/dist/core-api/routes/validation/mappers.mjs.map +1 -0
- package/dist/core-api/routes/validation/utils.d.ts +47 -0
- package/dist/core-api/routes/validation/utils.d.ts.map +1 -0
- package/dist/core-api/routes/validation/utils.js +112 -0
- package/dist/core-api/routes/validation/utils.js.map +1 -0
- package/dist/core-api/routes/validation/utils.mjs +90 -0
- package/dist/core-api/routes/validation/utils.mjs.map +1 -0
- package/dist/domain/content-type/index.d.ts.map +1 -1
- package/dist/domain/content-type/index.js +17 -1
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/domain/content-type/index.mjs +17 -1
- package/dist/domain/content-type/index.mjs.map +1 -1
- package/dist/domain/module/index.d.ts.map +1 -1
- package/dist/domain/module/index.js +3 -0
- package/dist/domain/module/index.js.map +1 -1
- package/dist/domain/module/index.mjs +3 -0
- package/dist/domain/module/index.mjs.map +1 -1
- package/dist/factories.d.ts +3 -1
- package/dist/factories.d.ts.map +1 -1
- package/dist/factories.js +10 -2
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs +10 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts +9 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js +39 -17
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs +39 -18
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/first-published-at.d.ts +4 -0
- package/dist/migrations/first-published-at.d.ts.map +1 -0
- package/dist/migrations/first-published-at.js +51 -0
- package/dist/migrations/first-published-at.js.map +1 -0
- package/dist/migrations/first-published-at.mjs +49 -0
- package/dist/migrations/first-published-at.mjs.map +1 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +5 -0
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs +5 -0
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/package.json.js +13 -12
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +13 -12
- package/dist/package.json.mjs.map +1 -1
- package/dist/services/document-service/first-published-at.d.ts +7 -0
- package/dist/services/document-service/first-published-at.d.ts.map +1 -0
- package/dist/services/document-service/first-published-at.js +31 -0
- package/dist/services/document-service/first-published-at.js.map +1 -0
- package/dist/services/document-service/first-published-at.mjs +28 -0
- package/dist/services/document-service/first-published-at.mjs.map +1 -0
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +7 -4
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +7 -4
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/metrics/index.d.ts +1 -1
- package/dist/services/metrics/index.d.ts.map +1 -1
- package/dist/services/metrics/index.js +9 -8
- package/dist/services/metrics/index.js.map +1 -1
- package/dist/services/metrics/index.mjs +9 -8
- package/dist/services/metrics/index.mjs.map +1 -1
- package/dist/services/server/register-routes.js +22 -2
- package/dist/services/server/register-routes.js.map +1 -1
- package/dist/services/server/register-routes.mjs +22 -2
- package/dist/services/server/register-routes.mjs.map +1 -1
- package/dist/services/server/routing.d.ts +10 -0
- package/dist/services/server/routing.d.ts.map +1 -1
- package/dist/services/server/routing.js +7 -1
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/server/routing.mjs +7 -1
- package/dist/services/server/routing.mjs.map +1 -1
- package/package.json +13 -12
@@ -0,0 +1,112 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var strapiUtils = require('@strapi/utils');
|
4
|
+
var z = require('zod/v4');
|
5
|
+
|
6
|
+
function _interopNamespaceDefault(e) {
|
7
|
+
var n = Object.create(null);
|
8
|
+
if (e) {
|
9
|
+
Object.keys(e).forEach(function (k) {
|
10
|
+
if (k !== 'default') {
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () { return e[k]; }
|
15
|
+
});
|
16
|
+
}
|
17
|
+
});
|
18
|
+
}
|
19
|
+
n.default = e;
|
20
|
+
return Object.freeze(n);
|
21
|
+
}
|
22
|
+
|
23
|
+
var z__namespace = /*#__PURE__*/_interopNamespaceDefault(z);
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Safely adds or updates a schema in Zod's global registry.
|
27
|
+
*
|
28
|
+
* If a schema with the given `id` already exists, it will be removed before adding the new one.
|
29
|
+
*
|
30
|
+
* This is useful for hot-reloading or preventing issues with cyclical dependencies.
|
31
|
+
*
|
32
|
+
* @param id - The unique identifier for the schema in the global registry.
|
33
|
+
* @param schema - The Zod schema to register.
|
34
|
+
* @example
|
35
|
+
* ```typescript
|
36
|
+
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
37
|
+
* ```
|
38
|
+
*/ const safeGlobalRegistrySet = (id, schema)=>{
|
39
|
+
try {
|
40
|
+
const { _idmap: idMap } = z__namespace.globalRegistry;
|
41
|
+
const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
|
42
|
+
if (idMap.has(transformedId)) {
|
43
|
+
// Remove existing schema to prevent conflicts
|
44
|
+
strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
|
45
|
+
idMap.delete(transformedId);
|
46
|
+
}
|
47
|
+
// Register the new schema with the transformed ID
|
48
|
+
strapi.log.debug(`Registering schema ${transformedId} in global registry`);
|
49
|
+
z__namespace.globalRegistry.add(schema, {
|
50
|
+
id: transformedId
|
51
|
+
});
|
52
|
+
} catch (error) {
|
53
|
+
strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
|
54
|
+
throw error;
|
55
|
+
}
|
56
|
+
};
|
57
|
+
/**
|
58
|
+
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
59
|
+
*
|
60
|
+
* If a schema with the given `id` already exists in the global registry, it returns the existing schema.
|
61
|
+
*
|
62
|
+
* Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
|
63
|
+
* and then replaces the temporary schema with the actual one in the registry.
|
64
|
+
*
|
65
|
+
* This prevents infinite loops in cases of cyclical dependencies.
|
66
|
+
*
|
67
|
+
* @param id - The unique identifier for the schema in the global registry.
|
68
|
+
* @param callback - A function that returns the Zod schema to be created and registered.
|
69
|
+
* @returns The created or retrieved Zod schema.
|
70
|
+
* @example
|
71
|
+
* ```typescript
|
72
|
+
* const CategorySchema = safeSchemaCreation("Category", () =>
|
73
|
+
* z.object({
|
74
|
+
* name: z.string(),
|
75
|
+
* products: z.array(safeSchemaCreation("Product", () =>
|
76
|
+
* z.object({
|
77
|
+
* name: z.string(),
|
78
|
+
* category: z.lazy(() => CategorySchema) // Cyclical reference
|
79
|
+
* })
|
80
|
+
* ))
|
81
|
+
* })
|
82
|
+
* );
|
83
|
+
* ```
|
84
|
+
*/ const safeSchemaCreation = (id, callback)=>{
|
85
|
+
try {
|
86
|
+
const { _idmap: idMap } = z__namespace.globalRegistry;
|
87
|
+
const transformedId = strapiUtils.transformUidToValidOpenApiName(id);
|
88
|
+
// Return existing schema if already registered
|
89
|
+
const mapItem = idMap.get(transformedId);
|
90
|
+
if (mapItem) {
|
91
|
+
strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);
|
92
|
+
return mapItem;
|
93
|
+
}
|
94
|
+
strapi.log.warn(`Schema ${transformedId} not found in global registry, creating an any placeholder`);
|
95
|
+
// Temporary any placeholder before replacing with the actual schema type
|
96
|
+
// Used to prevent infinite loops in cyclical data structures
|
97
|
+
safeGlobalRegistrySet(id, z__namespace.any());
|
98
|
+
// Generate the actual schema using the callback
|
99
|
+
const schema = callback();
|
100
|
+
// Replace the placeholder with the real schema
|
101
|
+
safeGlobalRegistrySet(id, schema);
|
102
|
+
strapi.log.debug(`Schema ${transformedId} successfully created and registered`);
|
103
|
+
return schema;
|
104
|
+
} catch (error) {
|
105
|
+
strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
|
106
|
+
throw error;
|
107
|
+
}
|
108
|
+
};
|
109
|
+
|
110
|
+
exports.safeGlobalRegistrySet = safeGlobalRegistrySet;
|
111
|
+
exports.safeSchemaCreation = safeSchemaCreation;
|
112
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n if (idMap.has(transformedId)) {\n // Remove existing schema to prevent conflicts\n strapi.log.debug(`Removing existing schema ${transformedId} from registry`);\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(`Registering schema ${transformedId} in global registry`);\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);\n return mapItem;\n }\n\n strapi.log.warn(\n `Schema ${transformedId} not found in global registry, creating an any placeholder`\n );\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n strapi.log.debug(`Schema ${transformedId} successfully created and registered`);\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","has","strapi","log","debug","delete","add","error","safeSchemaCreation","callback","mapItem","get","warn","any"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAIA;;;;;;;;;;;;;AAaC,IACM,MAAMA,qBAAwB,GAAA,CAACC,EAAyBC,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OAAAA;AACT;QAEAR,MAAOC,CAAAA,GAAG,CAACS,IAAI,CACb,CAAC,OAAO,EAAEb,aAAc,CAAA,0DAA0D,CAAC,CAAA;;;QAKrFP,qBAAsBC,CAAAA,EAAAA,EAAII,aAAEgB,GAAG,EAAA,CAAA;;AAG/B,QAAA,MAAMnB,MAASe,GAAAA,QAAAA,EAAAA;;AAGfjB,QAAAA,qBAAAA,CAAsBC,EAAIC,EAAAA,MAAAA,CAAAA;QAE1BQ,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,OAAO,EAAEL,aAAc,CAAA,oCAAoC,CAAC,CAAA;QAE9E,OAAOL,MAAAA;AACT,KAAA,CAAE,OAAOa,KAAO,EAAA;QACdL,MAAOC,CAAAA,GAAG,CAACI,KAAK,CAAC,CAAC,gDAAgD,EAAEd,GAAG,CAAC,CAAA;QAExE,MAAMc,KAAAA;AACR;AACF;;;;;"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
import { transformUidToValidOpenApiName } from '@strapi/utils';
|
2
|
+
import * as z from 'zod/v4';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Safely adds or updates a schema in Zod's global registry.
|
6
|
+
*
|
7
|
+
* If a schema with the given `id` already exists, it will be removed before adding the new one.
|
8
|
+
*
|
9
|
+
* This is useful for hot-reloading or preventing issues with cyclical dependencies.
|
10
|
+
*
|
11
|
+
* @param id - The unique identifier for the schema in the global registry.
|
12
|
+
* @param schema - The Zod schema to register.
|
13
|
+
* @example
|
14
|
+
* ```typescript
|
15
|
+
* safeGlobalRegistrySet("mySchema", z.object({ name: z.string() }));
|
16
|
+
* ```
|
17
|
+
*/ const safeGlobalRegistrySet = (id, schema)=>{
|
18
|
+
try {
|
19
|
+
const { _idmap: idMap } = z.globalRegistry;
|
20
|
+
const transformedId = transformUidToValidOpenApiName(id);
|
21
|
+
if (idMap.has(transformedId)) {
|
22
|
+
// Remove existing schema to prevent conflicts
|
23
|
+
strapi.log.debug(`Removing existing schema ${transformedId} from registry`);
|
24
|
+
idMap.delete(transformedId);
|
25
|
+
}
|
26
|
+
// Register the new schema with the transformed ID
|
27
|
+
strapi.log.debug(`Registering schema ${transformedId} in global registry`);
|
28
|
+
z.globalRegistry.add(schema, {
|
29
|
+
id: transformedId
|
30
|
+
});
|
31
|
+
} catch (error) {
|
32
|
+
strapi.log.error(`Schema registration failed: Failed to register schema ${id} in global registry`);
|
33
|
+
throw error;
|
34
|
+
}
|
35
|
+
};
|
36
|
+
/**
|
37
|
+
* Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.
|
38
|
+
*
|
39
|
+
* If a schema with the given `id` already exists in the global registry, it returns the existing schema.
|
40
|
+
*
|
41
|
+
* Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,
|
42
|
+
* and then replaces the temporary schema with the actual one in the registry.
|
43
|
+
*
|
44
|
+
* This prevents infinite loops in cases of cyclical dependencies.
|
45
|
+
*
|
46
|
+
* @param id - The unique identifier for the schema in the global registry.
|
47
|
+
* @param callback - A function that returns the Zod schema to be created and registered.
|
48
|
+
* @returns The created or retrieved Zod schema.
|
49
|
+
* @example
|
50
|
+
* ```typescript
|
51
|
+
* const CategorySchema = safeSchemaCreation("Category", () =>
|
52
|
+
* z.object({
|
53
|
+
* name: z.string(),
|
54
|
+
* products: z.array(safeSchemaCreation("Product", () =>
|
55
|
+
* z.object({
|
56
|
+
* name: z.string(),
|
57
|
+
* category: z.lazy(() => CategorySchema) // Cyclical reference
|
58
|
+
* })
|
59
|
+
* ))
|
60
|
+
* })
|
61
|
+
* );
|
62
|
+
* ```
|
63
|
+
*/ const safeSchemaCreation = (id, callback)=>{
|
64
|
+
try {
|
65
|
+
const { _idmap: idMap } = z.globalRegistry;
|
66
|
+
const transformedId = transformUidToValidOpenApiName(id);
|
67
|
+
// Return existing schema if already registered
|
68
|
+
const mapItem = idMap.get(transformedId);
|
69
|
+
if (mapItem) {
|
70
|
+
strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);
|
71
|
+
return mapItem;
|
72
|
+
}
|
73
|
+
strapi.log.warn(`Schema ${transformedId} not found in global registry, creating an any placeholder`);
|
74
|
+
// Temporary any placeholder before replacing with the actual schema type
|
75
|
+
// Used to prevent infinite loops in cyclical data structures
|
76
|
+
safeGlobalRegistrySet(id, z.any());
|
77
|
+
// Generate the actual schema using the callback
|
78
|
+
const schema = callback();
|
79
|
+
// Replace the placeholder with the real schema
|
80
|
+
safeGlobalRegistrySet(id, schema);
|
81
|
+
strapi.log.debug(`Schema ${transformedId} successfully created and registered`);
|
82
|
+
return schema;
|
83
|
+
} catch (error) {
|
84
|
+
strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);
|
85
|
+
throw error;
|
86
|
+
}
|
87
|
+
};
|
88
|
+
|
89
|
+
export { safeGlobalRegistrySet, safeSchemaCreation };
|
90
|
+
//# sourceMappingURL=utils.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../../src/core-api/routes/validation/utils.ts"],"sourcesContent":["import { transformUidToValidOpenApiName } from '@strapi/utils';\nimport type { Internal } from '@strapi/types';\nimport * as z from 'zod/v4';\n\n/**\n * Safely adds or updates a schema in Zod's global registry.\n *\n * If a schema with the given `id` already exists, it will be removed before adding the new one.\n *\n * This is useful for hot-reloading or preventing issues with cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param schema - The Zod schema to register.\n * @example\n * ```typescript\n * safeGlobalRegistrySet(\"mySchema\", z.object({ name: z.string() }));\n * ```\n */\nexport const safeGlobalRegistrySet = (id: Internal.UID.Schema, schema: z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n if (idMap.has(transformedId)) {\n // Remove existing schema to prevent conflicts\n strapi.log.debug(`Removing existing schema ${transformedId} from registry`);\n idMap.delete(transformedId);\n }\n\n // Register the new schema with the transformed ID\n strapi.log.debug(`Registering schema ${transformedId} in global registry`);\n z.globalRegistry.add(schema, { id: transformedId });\n } catch (error) {\n strapi.log.error(\n `Schema registration failed: Failed to register schema ${id} in global registry`\n );\n\n throw error;\n }\n};\n\n/**\n * Safely creates and registers a Zod schema in the global registry, particularly useful for handling cyclical data structures.\n *\n * If a schema with the given `id` already exists in the global registry, it returns the existing schema.\n *\n * Otherwise, it registers a temporary `z.any()` schema, calls the provided `callback` to create the actual schema,\n * and then replaces the temporary schema with the actual one in the registry.\n *\n * This prevents infinite loops in cases of cyclical dependencies.\n *\n * @param id - The unique identifier for the schema in the global registry.\n * @param callback - A function that returns the Zod schema to be created and registered.\n * @returns The created or retrieved Zod schema.\n * @example\n * ```typescript\n * const CategorySchema = safeSchemaCreation(\"Category\", () =>\n * z.object({\n * name: z.string(),\n * products: z.array(safeSchemaCreation(\"Product\", () =>\n * z.object({\n * name: z.string(),\n * category: z.lazy(() => CategorySchema) // Cyclical reference\n * })\n * ))\n * })\n * );\n * ```\n */\nexport const safeSchemaCreation = (id: Internal.UID.Schema, callback: () => z.ZodType) => {\n try {\n const { _idmap: idMap } = z.globalRegistry;\n\n const transformedId = transformUidToValidOpenApiName(id);\n\n // Return existing schema if already registered\n const mapItem = idMap.get(transformedId);\n if (mapItem) {\n strapi.log.debug(`Schema ${transformedId} found in registry, returning existing schema`);\n return mapItem;\n }\n\n strapi.log.warn(\n `Schema ${transformedId} not found in global registry, creating an any placeholder`\n );\n\n // Temporary any placeholder before replacing with the actual schema type\n // Used to prevent infinite loops in cyclical data structures\n safeGlobalRegistrySet(id, z.any());\n\n // Generate the actual schema using the callback\n const schema = callback();\n\n // Replace the placeholder with the real schema\n safeGlobalRegistrySet(id, schema);\n\n strapi.log.debug(`Schema ${transformedId} successfully created and registered`);\n\n return schema;\n } catch (error) {\n strapi.log.error(`Schema creation failed: Failed to create schema ${id}`);\n\n throw error;\n }\n};\n"],"names":["safeGlobalRegistrySet","id","schema","_idmap","idMap","z","globalRegistry","transformedId","transformUidToValidOpenApiName","has","strapi","log","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AAS,EAAA;YACXR,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,OAAO,EAAEL,aAAc,CAAA,6CAA6C,CAAC,CAAA;YACvF,OAAOW,OAAAA;AACT;QAEAR,MAAOC,CAAAA,GAAG,CAACS,IAAI,CACb,CAAC,OAAO,EAAEb,aAAc,CAAA,0DAA0D,CAAC,CAAA;;;QAKrFP,qBAAsBC,CAAAA,EAAAA,EAAII,EAAEgB,GAAG,EAAA,CAAA;;AAG/B,QAAA,MAAMnB,MAASe,GAAAA,QAAAA,EAAAA;;AAGfjB,QAAAA,qBAAAA,CAAsBC,EAAIC,EAAAA,MAAAA,CAAAA;QAE1BQ,MAAOC,CAAAA,GAAG,CAACC,KAAK,CAAC,CAAC,OAAO,EAAEL,aAAc,CAAA,oCAAoC,CAAC,CAAA;QAE9E,OAAOL,MAAAA;AACT,KAAA,CAAE,OAAOa,KAAO,EAAA;QACdL,MAAOC,CAAAA,GAAG,CAACI,KAAK,CAAC,CAAC,gDAAgD,EAAEd,GAAG,CAAC,CAAA;QAExE,MAAMc,KAAAA;AACR;AACF;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/domain/content-type/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAG5C,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAWF,QAAA,MAAM,iBAAiB,QAAS,MAAM,cAAc,qBAAqB,0DAmCxE,CAAC;AA0EF,QAAA,MAAM,WAAW,WAAY,OAAO,WAAW,WAAW,MAAM,WAK/D,CAAC;AAmBF,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC"}
|
@@ -5,7 +5,7 @@ var _ = require('lodash');
|
|
5
5
|
var strapiUtils = require('@strapi/utils');
|
6
6
|
var validator = require('./validator.js');
|
7
7
|
|
8
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
8
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
9
9
|
const createContentType = (uid, definition)=>{
|
10
10
|
try {
|
11
11
|
validator.validateContentTypeDefinition(definition);
|
@@ -31,6 +31,7 @@ const createContentType = (uid, definition)=>{
|
|
31
31
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
32
32
|
addDraftAndPublish(schema);
|
33
33
|
addCreatorFields(schema);
|
34
|
+
addFirstPublishedAt(schema);
|
34
35
|
return schema;
|
35
36
|
};
|
36
37
|
const addTimestamps = (schema)=>{
|
@@ -59,6 +60,21 @@ const addDraftAndPublish = (schema)=>{
|
|
59
60
|
}
|
60
61
|
};
|
61
62
|
};
|
63
|
+
const addFirstPublishedAt = (schema)=>{
|
64
|
+
const isEnabled = strapiUtils.contentTypes.hasFirstPublishedAtField(schema);
|
65
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
66
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
67
|
+
if (isEnabled) {
|
68
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
69
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
70
|
+
type: 'datetime',
|
71
|
+
configurable: false,
|
72
|
+
writable: true,
|
73
|
+
visible: false,
|
74
|
+
private: !isEnabled
|
75
|
+
};
|
76
|
+
}
|
77
|
+
};
|
62
78
|
const addCreatorFields = (schema)=>{
|
63
79
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
64
80
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,yBAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAAI;QACFC,uCAA8BD,CAAAA,UAAAA,CAAAA;AAChC,KAAA,CAAE,OAAOE,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;YACpC,MAAM,IAAIC,KAAM,CAAA,CAAC,uCAAuC,EAAEN,GAAI,CAAA,IAAI,EAAEG,CAAAA,CAAEI,MAAM,CAAC,CAAC,CAAA;AAChF;QAEA,MAAMJ,CAAAA;AACR;IAEA,MAAM,EAAEK,MAAM,EAAEC,OAAO,EAAEC,UAAU,EAAE,GAAGC,YAAUV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EAAAA,MAAAA,GAAAA;AAC/C,IAAA,MAAM9B,SAAYV,GAAAA,MAAAA,CAAOW,IAAI,CAACC,YAAY;IAC1C,MAAM6B,QAAAA,GAAWD,SAAS,CAAC,EAAEA,OAAO,CAAC,EAAE9B,SAAU,CAAA,CAAC,GAAGA,SAAAA;IAErD,OAAOV,MAAAA,CAAOyC,QAAQ,IAAItB,CAAAA,CAAEuB,UAAU,CAACvB,CAAAA,CAAEwB,SAAS,CAACF,QAAAA,CAAAA,CAAAA;AACrD;AAEA,MAAMhC,aAAa,CAACmC,KAAAA,GAAAA;AAClB,IAAA,MAAM5C,SAASmB,CAAEhB,CAAAA,SAAS,CACxBgB,CAAE0B,CAAAA,IAAI,CAACD,KAAO,EAAA;AACZ,QAAA,YAAA;AACA,QAAA,gBAAA;AACA,QAAA,MAAA;AACA,QAAA,SAAA;AACA,QAAA,eAAA;AACA,QAAA,YAAA;AACA,QAAA;AACD,KAAA,CAAA,CAAA;AAGH5C,IAAAA,MAAAA,CAAOO,IAAI,GAAGqC,KAAMrC,CAAAA,IAAI,IAAI,gBAAA;IAC5B,OAAOP,MAAAA;AACT,CAAA;;;;;"}
|
@@ -3,7 +3,7 @@ import _ from 'lodash';
|
|
3
3
|
import { contentTypes, yup } from '@strapi/utils';
|
4
4
|
import { validateContentTypeDefinition } from './validator.mjs';
|
5
5
|
|
6
|
-
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
6
|
+
const { CREATED_AT_ATTRIBUTE, UPDATED_AT_ATTRIBUTE, PUBLISHED_AT_ATTRIBUTE, FIRST_PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
|
7
7
|
const createContentType = (uid, definition)=>{
|
8
8
|
try {
|
9
9
|
validateContentTypeDefinition(definition);
|
@@ -29,6 +29,7 @@ const createContentType = (uid, definition)=>{
|
|
29
29
|
// In case it is not enabled, value will be always published, and it will not contain a draft
|
30
30
|
addDraftAndPublish(schema);
|
31
31
|
addCreatorFields(schema);
|
32
|
+
addFirstPublishedAt(schema);
|
32
33
|
return schema;
|
33
34
|
};
|
34
35
|
const addTimestamps = (schema)=>{
|
@@ -57,6 +58,21 @@ const addDraftAndPublish = (schema)=>{
|
|
57
58
|
}
|
58
59
|
};
|
59
60
|
};
|
61
|
+
const addFirstPublishedAt = (schema)=>{
|
62
|
+
const isEnabled = contentTypes.hasFirstPublishedAtField(schema);
|
63
|
+
// Note: As an expertimental feature, we are okay if this data is deleted if this feature is
|
64
|
+
// switched off. Once "preserve_attributes" come into play, this will be updated.
|
65
|
+
if (isEnabled) {
|
66
|
+
strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);
|
67
|
+
schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {
|
68
|
+
type: 'datetime',
|
69
|
+
configurable: false,
|
70
|
+
writable: true,
|
71
|
+
visible: false,
|
72
|
+
private: !isEnabled
|
73
|
+
};
|
74
|
+
}
|
75
|
+
};
|
60
76
|
const addCreatorFields = (schema)=>{
|
61
77
|
const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);
|
62
78
|
schema.attributes[CREATED_BY_ATTRIBUTE] = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","attributes","type","_","has","set","configurable","writable","visible","default","Date","isPrivate","get","relation","target","useJoinTable","
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/domain/content-type/index.ts"],"sourcesContent":["import { cloneDeep } from 'lodash/fp';\nimport _ from 'lodash';\nimport { yup, contentTypes as contentTypesUtils } from '@strapi/utils';\nimport type { Schema } from '@strapi/types';\nimport { validateContentTypeDefinition } from './validator';\n\nexport type ContentTypeDefinition = {\n schema: Schema.ContentType;\n actions: Record<string, unknown>;\n lifecycles: Record<string, unknown>;\n};\n\nconst {\n CREATED_AT_ATTRIBUTE,\n UPDATED_AT_ATTRIBUTE,\n PUBLISHED_AT_ATTRIBUTE,\n FIRST_PUBLISHED_AT_ATTRIBUTE,\n CREATED_BY_ATTRIBUTE,\n UPDATED_BY_ATTRIBUTE,\n} = contentTypesUtils.constants;\n\nconst createContentType = (uid: string, definition: ContentTypeDefinition) => {\n try {\n validateContentTypeDefinition(definition);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`Content Type Definition is invalid for ${uid}'.\\n${e.errors}`);\n }\n\n throw e;\n }\n\n const { schema, actions, lifecycles } = cloneDeep(definition);\n\n // general info\n Object.assign(schema, {\n uid,\n modelType: 'contentType',\n kind: schema.kind || 'collectionType',\n __schema__: pickSchema(definition.schema),\n modelName: definition.schema.info.singularName,\n actions,\n lifecycles,\n });\n\n addTimestamps(schema);\n\n // Published at is added regardless of draft and publish being enabled\n // In case it is not enabled, value will be always published, and it will not contain a draft\n addDraftAndPublish(schema);\n\n addCreatorFields(schema);\n\n addFirstPublishedAt(schema);\n\n return schema;\n};\n\nconst addTimestamps = (schema: Schema.ContentType) => {\n // attributes\n Object.assign(schema.attributes, {\n [CREATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n // TODO: handle on edit set to new date\n [UPDATED_AT_ATTRIBUTE]: {\n type: 'datetime',\n },\n });\n};\n\nconst addDraftAndPublish = (schema: Schema.ContentType) => {\n if (!_.has(schema, 'options.draftAndPublish')) {\n _.set(schema, 'options.draftAndPublish', false); // Disabled by default\n }\n\n schema.attributes[PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n default() {\n return new Date();\n },\n };\n};\n\nconst addFirstPublishedAt = (schema: Schema.ContentType) => {\n const isEnabled = contentTypesUtils.hasFirstPublishedAtField(schema);\n\n // Note: As an expertimental feature, we are okay if this data is deleted if this feature is\n // switched off. Once \"preserve_attributes\" come into play, this will be updated.\n if (isEnabled) {\n strapi.log.warn(`Experimental feature enabled: firstPublishedAt on ${schema.collectionName}`);\n schema.attributes[FIRST_PUBLISHED_AT_ATTRIBUTE] = {\n type: 'datetime',\n configurable: false,\n writable: true,\n visible: false,\n private: !isEnabled,\n };\n }\n};\n\nconst addCreatorFields = (schema: Schema.ContentType) => {\n const isPrivate = !_.get(schema, 'options.populateCreatorFields', false);\n\n schema.attributes[CREATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n\n schema.attributes[UPDATED_BY_ATTRIBUTE] = {\n type: 'relation',\n relation: 'oneToOne',\n target: 'admin::user',\n configurable: false,\n writable: false,\n visible: false,\n useJoinTable: false,\n private: isPrivate,\n };\n};\n\nconst getGlobalId = (schema: Schema.ContentType, prefix?: string) => {\n const modelName = schema.info.singularName;\n const globalId = prefix ? `${prefix}-${modelName}` : modelName;\n\n return schema.globalId || _.upperFirst(_.camelCase(globalId));\n};\n\nconst pickSchema = (model: Schema.ContentType) => {\n const schema = _.cloneDeep(\n _.pick(model, [\n 'connection',\n 'collectionName',\n 'info',\n 'options',\n 'pluginOptions',\n 'attributes',\n 'kind',\n ])\n );\n\n schema.kind = model.kind || 'collectionType';\n return schema;\n};\n\nexport { createContentType, getGlobalId };\n"],"names":["CREATED_AT_ATTRIBUTE","UPDATED_AT_ATTRIBUTE","PUBLISHED_AT_ATTRIBUTE","FIRST_PUBLISHED_AT_ATTRIBUTE","CREATED_BY_ATTRIBUTE","UPDATED_BY_ATTRIBUTE","contentTypesUtils","constants","createContentType","uid","definition","validateContentTypeDefinition","e","yup","ValidationError","Error","errors","schema","actions","lifecycles","cloneDeep","Object","assign","modelType","kind","__schema__","pickSchema","modelName","info","singularName","addTimestamps","addDraftAndPublish","addCreatorFields","addFirstPublishedAt","attributes","type","_","has","set","configurable","writable","visible","default","Date","isEnabled","hasFirstPublishedAtField","strapi","log","warn","collectionName","private","isPrivate","get","relation","target","useJoinTable","getGlobalId","prefix","globalId","upperFirst","camelCase","model","pick"],"mappings":";;;;;AAYA,MAAM,EACJA,oBAAoB,EACpBC,oBAAoB,EACpBC,sBAAsB,EACtBC,4BAA4B,EAC5BC,oBAAoB,EACpBC,oBAAoB,EACrB,GAAGC,aAAkBC,SAAS;AAEzBC,MAAAA,iBAAAA,GAAoB,CAACC,GAAaC,EAAAA,UAAAA,GAAAA;IACtC,IAA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AAG,CAAC,CAAC;IAC1D,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,KAAK,MAAM,CAAC,iBAAiB,CAAC;IACnE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC;IAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,UAAU,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;IAChE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,UAAU,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC;IAChE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;CAC9C;AAiBD,eAAO,MAAM,YAAY,cACZ,MAAM,aACN,SAAS,UACZ,KAAK,MAAM,KAClB,MAwFF,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,WAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,0BAAgBD,GAAKJ,EAAAA,WAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,EAAAA,MAAAA,GAAAA;IAEAf,CAAEgB,CAAAA,QAAQ,CAACF,SAAWT,EAAAA,aAAAA,CAAAA;IAEtB,IAAI;QACFY,yBAAeH,CAAAA,SAAAA,CAAAA;AACjB,KAAA,CAAE,OAAOI,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,eAAIC,CAAAA,eAAe,EAAE;AACpC,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,iCAAiC,EAAEtB,SAAU,CAAA,IAAI,EAAEmB,CAAAA,CAAEI,MAAM,CAACC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC3F;AACF;AAEA,IAAA,MAAMC,SAA0B,EAAC;IACjC,OAAO;QACL,MAAMC,SAAAA,CAAAA,GAAAA;YACJ,IAAID,MAAAA,CAAOC,SAAS,EA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AA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n set routes(routes: Record<string, Core.Router>) {\n rawModule.routes = routes;\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,WAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,0BAAgBD,GAAKJ,EAAAA,WAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,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W,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,SAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,gBAAgBD,GAAKJ,EAAAA,SAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,EAAAA,MAAAA,GAAAA;IAEAf,CAAEgB,CAAAA,QAAQ,CAACF,SAAWT,EAAAA,aAAAA,CAAAA;IAEtB,IAAI;QACFY,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,cAA8B,EAAA;AACvC,YAAA,OAAO7B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE6C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAIhC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcG,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBe,WAAab,EAAAA,SAAAA,CAAAA;AAC3C,SAAA;AACA8C,QAAAA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/domain/module/index.ts"],"sourcesContent":["import _, { type PropertyPath, flatten } from 'lodash';\nimport { yup } from '@strapi/utils';\nimport type { Core, UID, Struct } from '@strapi/types';\n\nimport { removeNamespace } from '../../registries/namespace';\nimport { validateModule } from './validation';\n\ninterface LifecyclesState {\n bootstrap?: boolean;\n register?: boolean;\n destroy?: boolean;\n}\n\nexport interface RawModule {\n config?: Record<string, unknown>;\n routes?: Core.Module['routes'];\n controllers?: Core.Module['controllers'];\n services?: Core.Module['services'];\n contentTypes?: Core.Module['contentTypes'];\n policies?: Core.Module['policies'];\n middlewares?: Core.Module['middlewares'];\n bootstrap?: (params: { strapi: Core.Strapi }) => Promise<void>;\n register?: (params: { strapi: Core.Strapi }) => Promise<void>;\n destroy?: (params: { strapi: Core.Strapi }) => Promise<void>;\n}\n\nexport interface Module {\n bootstrap: () => Promise<void>;\n register: () => Promise<void>;\n destroy: () => Promise<void>;\n load: () => void;\n routes: Core.Module['routes'];\n config<T = unknown>(key: PropertyPath, defaultVal?: T): T; // TODO: this mirrors ConfigProvider.get, we should use it directly\n contentType: (ctName: UID.ContentType) => Struct.ContentTypeSchema;\n contentTypes: Record<string, Struct.ContentTypeSchema>;\n service: (serviceName: UID.Service) => Core.Service;\n services: Record<string, Core.Service>;\n policy: (policyName: UID.Policy) => Core.Policy;\n policies: Record<string, Core.Policy>;\n middleware: (middlewareName: UID.Middleware) => Core.Middleware;\n middlewares: Record<string, Core.Middleware>;\n controller: (controllerName: UID.Controller) => Core.Controller;\n controllers: Record<string, Core.Controller>;\n}\n\n// Removes the namespace from a map with keys prefixed with a namespace\nconst removeNamespacedKeys = <T extends Record<string, unknown>>(map: T, namespace: string) => {\n return _.mapKeys(map, (value, key) => removeNamespace(key, namespace));\n};\n\nconst defaultModule = {\n config: {},\n routes: [],\n controllers: {},\n services: {},\n contentTypes: {},\n policies: {},\n middlewares: {},\n};\n\nexport const createModule = (\n namespace: string,\n rawModule: RawModule,\n strapi: Core.Strapi\n): Module => {\n _.defaults(rawModule, defaultModule);\n\n try {\n validateModule(rawModule);\n } catch (e) {\n if (e instanceof yup.ValidationError) {\n throw new Error(`strapi-server.js is invalid for '${namespace}'.\\n${e.errors.join('\\n')}`);\n }\n }\n\n const called: LifecyclesState = {};\n return {\n async bootstrap() {\n if (called.bootstrap) {\n throw new Error(`Bootstrap for ${namespace} has already been called`);\n }\n called.bootstrap = true;\n await (rawModule.bootstrap && rawModule.bootstrap({ strapi }));\n },\n async register() {\n if (called.register) {\n throw new Error(`Register for ${namespace} has already been called`);\n }\n called.register = true;\n await (rawModule.register && rawModule.register({ strapi }));\n },\n async destroy() {\n if (called.destroy) {\n throw new Error(`Destroy for ${namespace} has already been called`);\n }\n called.destroy = true;\n await (rawModule.destroy && rawModule.destroy({ strapi }));\n },\n load() {\n strapi.get('content-types').add(namespace, rawModule.contentTypes);\n strapi.get('services').add(namespace, rawModule.services);\n strapi.get('policies').add(namespace, rawModule.policies);\n strapi.get('middlewares').add(namespace, rawModule.middlewares);\n strapi.get('controllers').add(namespace, rawModule.controllers);\n strapi.get('config').set(namespace, rawModule.config);\n },\n get routes() {\n return rawModule.routes ?? {};\n },\n set routes(routes: Record<string, Core.Router>) {\n rawModule.routes = routes;\n },\n config(path: PropertyPath, defaultValue: unknown) {\n const pathArray = flatten([namespace, path]);\n return strapi.get('config').get(pathArray, defaultValue);\n },\n contentType(ctName: UID.ContentType) {\n return strapi.get('content-types').get(`${namespace}.${ctName}`);\n },\n get contentTypes() {\n const contentTypes = strapi.get('content-types').getAll(namespace);\n return removeNamespacedKeys(contentTypes, namespace);\n },\n service(serviceName: UID.Service) {\n return strapi.get('services').get(`${namespace}.${serviceName}`);\n },\n get services() {\n const services = strapi.get('services').getAll(namespace);\n return removeNamespacedKeys(services, namespace);\n },\n policy(policyName: UID.Policy) {\n return strapi.get('policies').get(`${namespace}.${policyName}`);\n },\n get policies() {\n const policies = strapi.get('policies').getAll(namespace);\n return removeNamespacedKeys(policies, namespace);\n },\n middleware(middlewareName: UID.Middleware) {\n return strapi.get('middlewares').get(`${namespace}.${middlewareName}`);\n },\n get middlewares() {\n const middlewares = strapi.get('middlewares').getAll(namespace);\n return removeNamespacedKeys(middlewares, namespace);\n },\n controller(controllerName: UID.Controller) {\n return strapi.get('controllers').get(`${namespace}.${controllerName}`);\n },\n get controllers() {\n const controllers = strapi.get('controllers').getAll(namespace);\n return removeNamespacedKeys(controllers, namespace);\n },\n };\n};\n"],"names":["removeNamespacedKeys","map","namespace","_","mapKeys","value","key","removeNamespace","defaultModule","config","routes","controllers","services","contentTypes","policies","middlewares","createModule","rawModule","strapi","defaults","validateModule","e","yup","ValidationError","Error","errors","join","called","bootstrap","register","destroy","load","get","add","set","path","defaultValue","pathArray","flatten","contentType","ctName","getAll","service","serviceName","policy","policyName","middleware","middlewareName","controller","controllerName"],"mappings":";;;;;AA6CA;AACA,MAAMA,oBAAAA,GAAuB,CAAoCC,GAAQC,EAAAA,SAAAA,GAAAA;IACvE,OAAOC,CAAAA,CAAEC,OAAO,CAACH,GAAAA,EAAK,CAACI,KAAOC,EAAAA,GAAAA,GAAQC,gBAAgBD,GAAKJ,EAAAA,SAAAA,CAAAA,CAAAA;AAC7D,CAAA;AAEA,MAAMM,aAAgB,GAAA;AACpBC,IAAAA,MAAAA,EAAQ,EAAC;AACTC,IAAAA,MAAAA,EAAQ,EAAE;AACVC,IAAAA,WAAAA,EAAa,EAAC;AACdC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,YAAAA,EAAc,EAAC;AACfC,IAAAA,QAAAA,EAAU,EAAC;AACXC,IAAAA,WAAAA,EAAa;AACf,CAAA;AAEaC,MAAAA,YAAAA,GAAe,CAC1Bd,SAAAA,EACAe,SACAC,EAAAA,MAAAA,GAAAA;IAEAf,CAAEgB,CAAAA,QAAQ,CAACF,SAAWT,EAAAA,aAAAA,CAAAA;IAEtB,IAAI;QACFY,cAAeH,CAAAA,SAAAA,CAAAA;AACjB,KAAA,CAAE,OAAOI,CAAG,EAAA;QACV,IAAIA,CAAAA,YAAaC,GAAIC,CAAAA,eAAe,EAAE;AACpC,YAAA,MAAM,IAAIC,KAAAA,CAAM,CAAC,iCAAiC,EAAEtB,SAAU,CAAA,IAAI,EAAEmB,CAAAA,CAAEI,MAAM,CAACC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC3F;AACF;AAEA,IAAA,MAAMC,SAA0B,EAAC;IACjC,OAAO;QACL,MAAMC,SAAAA,CAAAA,GAAAA;YACJ,IAAID,MAAAA,CAAOC,SAAS,EAAE;AACpB,gBAAA,MAAM,IAAIJ,KAAM,CAAA,CAAC,cAAc,EAAEtB,SAAAA,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AAAA;AAC3C,SAAA;AACA8C,QAAAA,UAAAA,CAAAA,CAAWC,cAA8B,EAAA;AACvC,YAAA,OAAO/B,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeA,GAAG,CAAC,CAAC,EAAE9B,SAAU,CAAA,CAAC,EAAE+C,cAAAA,CAAe,CAAC,CAAA;AACvE,SAAA;AACA,QAAA,IAAItC,WAAc,CAAA,GAAA;AAChB,YAAA,MAAMA,cAAcO,MAAOc,CAAAA,GAAG,CAAC,aAAA,CAAA,CAAeS,MAAM,CAACvC,SAAAA,CAAAA;AACrD,YAAA,OAAOF,qBAAqBW,WAAaT,EAAAA,SAAAA,CAAAA;AAC3C;AACF,KAAA;AACF;;;;"}
|
package/dist/factories.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { Core, UID, Utils } from '@strapi/types';
|
2
|
+
import { CoreContentTypeRouteValidator } from './core-api/routes/validation';
|
2
3
|
type WithStrapiCallback<T> = T | (<S extends {
|
3
4
|
strapi: Core.Strapi;
|
4
5
|
}>(params: S) => T);
|
@@ -9,6 +10,7 @@ declare function createCoreService<TUID extends UID.ContentType, TService extend
|
|
9
10
|
strapi: Core.Strapi;
|
10
11
|
}) => TService & Core.CoreAPI.Service.ContentType<TUID>;
|
11
12
|
declare function createCoreRouter<T extends UID.ContentType>(uid: T, cfg?: Core.CoreAPI.Router.RouterConfig<T>): Core.CoreAPI.Router.Router;
|
13
|
+
declare const createCoreValidator: <T extends UID.ContentType>(uid: T, strapi: Core.Strapi) => CoreContentTypeRouteValidator;
|
12
14
|
declare const isCustomController: <T extends Core.Controller>(controller: T) => boolean;
|
13
|
-
export { createCoreController, createCoreService, createCoreRouter, isCustomController };
|
15
|
+
export { createCoreController, createCoreService, createCoreRouter, createCoreValidator, isCustomController, };
|
14
16
|
//# sourceMappingURL=factories.d.ts.map
|
package/dist/factories.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"factories.d.ts","sourceR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