@strapi/core 5.0.0-rc.2 → 5.0.0-rc.20
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/Strapi.js +2 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/configuration/get-dirs.js +2 -2
- package/dist/configuration/get-dirs.js.map +1 -1
- package/dist/configuration/index.js +2 -2
- package/dist/configuration/index.js.map +1 -1
- package/dist/core-api/controller/collection-type.js +3 -3
- package/dist/core-api/controller/collection-type.js.map +1 -1
- package/dist/core-api/controller/index.js +2 -2
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/single-type.js +2 -2
- package/dist/core-api/controller/single-type.js.map +1 -1
- package/dist/core-api/controller/transform.js +8 -8
- package/dist/core-api/controller/transform.js.map +1 -1
- package/dist/core-api/service/collection-type.d.ts +2 -2
- package/dist/core-api/service/pagination.js +8 -8
- package/dist/core-api/service/pagination.js.map +1 -1
- package/dist/domain/content-type/index.js +4 -4
- package/dist/domain/content-type/index.js.map +1 -1
- package/dist/ee/index.js +3 -3
- package/dist/ee/index.js.map +1 -1
- package/dist/factories.js +4 -4
- package/dist/factories.js.map +1 -1
- package/dist/factories.mjs.map +1 -1
- package/dist/loaders/apis.js +2 -2
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.d.ts.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +39 -11
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +9 -3
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/loaders/plugins/get-user-plugins-config.js +2 -2
- package/dist/loaders/plugins/get-user-plugins-config.js.map +1 -1
- package/dist/loaders/plugins/index.d.ts.map +1 -1
- package/dist/loaders/plugins/index.js +34 -7
- package/dist/loaders/plugins/index.js.map +1 -1
- package/dist/loaders/plugins/index.mjs +9 -1
- package/dist/loaders/plugins/index.mjs.map +1 -1
- package/dist/middlewares/body.js +2 -2
- package/dist/middlewares/body.js.map +1 -1
- package/dist/middlewares/public.js +2 -2
- package/dist/middlewares/public.js.map +1 -1
- package/dist/middlewares/query.js.map +1 -1
- package/dist/middlewares/query.mjs.map +1 -1
- package/dist/middlewares/responses.js +2 -2
- package/dist/middlewares/responses.js.map +1 -1
- package/dist/middlewares/security.d.ts.map +1 -1
- package/dist/middlewares/security.js +4 -4
- package/dist/middlewares/security.js.map +1 -1
- package/dist/middlewares/security.mjs +1 -1
- package/dist/middlewares/security.mjs.map +1 -1
- package/dist/middlewares/session.js +2 -2
- package/dist/middlewares/session.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts +12 -9
- package/dist/migrations/database/5.0.0-discard-drafts.d.ts.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +50 -11
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +51 -12
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/providers/admin.d.ts.map +1 -1
- package/dist/providers/admin.js.map +1 -1
- package/dist/providers/admin.mjs.map +1 -1
- package/dist/registries/apis.js +2 -2
- package/dist/registries/apis.js.map +1 -1
- package/dist/registries/components.js +2 -2
- package/dist/registries/components.js.map +1 -1
- package/dist/registries/content-types.js +3 -3
- package/dist/registries/content-types.js.map +1 -1
- package/dist/registries/controllers.js +3 -3
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/custom-fields.js +4 -4
- package/dist/registries/custom-fields.js.map +1 -1
- package/dist/registries/hooks.js +2 -2
- package/dist/registries/hooks.js.map +1 -1
- package/dist/registries/middlewares.js +3 -3
- package/dist/registries/middlewares.js.map +1 -1
- package/dist/registries/modules.js +3 -3
- package/dist/registries/modules.js.map +1 -1
- package/dist/registries/plugins.js +2 -2
- package/dist/registries/plugins.js.map +1 -1
- package/dist/registries/policies.d.ts +1 -1
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +5 -5
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +1 -1
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/registries/services.js +3 -3
- package/dist/registries/services.js.map +1 -1
- package/dist/services/auth/index.js +3 -3
- package/dist/services/auth/index.js.map +1 -1
- package/dist/services/content-api/index.d.ts +10 -12
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/index.d.ts +10 -12
- package/dist/services/content-api/permissions/index.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/action.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/action.d.ts.map +1 -1
- package/dist/services/content-api/permissions/providers/condition.d.ts +5 -6
- package/dist/services/content-api/permissions/providers/condition.d.ts.map +1 -1
- package/dist/services/core-store.js +3 -3
- package/dist/services/core-store.js.map +1 -1
- package/dist/services/cron.d.ts +3 -3
- package/dist/services/cron.d.ts.map +1 -1
- package/dist/services/cron.js +3 -3
- package/dist/services/cron.js.map +1 -1
- package/dist/services/cron.mjs.map +1 -1
- package/dist/services/document-service/attributes/index.js +2 -2
- package/dist/services/document-service/attributes/index.js.map +1 -1
- package/dist/services/document-service/attributes/transforms.js +3 -3
- package/dist/services/document-service/attributes/transforms.js.map +1 -1
- package/dist/services/document-service/components.js +15 -15
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/draft-and-publish.js +16 -16
- package/dist/services/document-service/draft-and-publish.js.map +1 -1
- package/dist/services/document-service/entries.js +5 -5
- package/dist/services/document-service/entries.js.map +1 -1
- package/dist/services/document-service/internationalization.js +9 -9
- package/dist/services/document-service/internationalization.js.map +1 -1
- package/dist/services/document-service/params.js +2 -2
- package/dist/services/document-service/params.js.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +51 -15
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +43 -7
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/id-transform.js +2 -2
- package/dist/services/document-service/transform/id-transform.js.map +1 -1
- package/dist/services/document-service/transform/query.js +3 -3
- package/dist/services/document-service/transform/query.js.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +2 -2
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/dp.js +2 -2
- package/dist/services/document-service/transform/relations/utils/dp.js.map +1 -1
- package/dist/services/document-service/transform/relations/utils/map-relation.js +6 -6
- package/dist/services/document-service/transform/relations/utils/map-relation.js.map +1 -1
- package/dist/services/document-service/utils/populate.d.ts.map +1 -1
- package/dist/services/document-service/utils/populate.js +3 -1
- package/dist/services/document-service/utils/populate.js.map +1 -1
- package/dist/services/document-service/utils/populate.mjs +3 -1
- package/dist/services/document-service/utils/populate.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +33 -0
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.js +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs +58 -0
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -0
- package/dist/services/entity-validator/blocks-validator.d.ts +1 -2
- package/dist/services/entity-validator/blocks-validator.d.ts.map +1 -1
- package/dist/services/entity-validator/blocks-validator.js +4 -3
- package/dist/services/entity-validator/blocks-validator.js.map +1 -1
- package/dist/services/entity-validator/blocks-validator.mjs +3 -3
- package/dist/services/entity-validator/blocks-validator.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts +2 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +28 -33
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +14 -19
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/entity-validator/validators.d.ts +32 -23
- package/dist/services/entity-validator/validators.d.ts.map +1 -1
- package/dist/services/entity-validator/validators.js +136 -63
- package/dist/services/entity-validator/validators.js.map +1 -1
- package/dist/services/entity-validator/validators.mjs +135 -63
- package/dist/services/entity-validator/validators.mjs.map +1 -1
- package/dist/services/server/compose-endpoint.js +7 -7
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/koa.js +3 -3
- package/dist/services/server/koa.js.map +1 -1
- package/dist/services/server/middleware.js +3 -3
- package/dist/services/server/middleware.js.map +1 -1
- package/dist/services/server/routing.js +2 -2
- package/dist/services/server/routing.js.map +1 -1
- package/dist/services/utils/dynamic-zones.js +5 -5
- package/dist/services/utils/dynamic-zones.js.map +1 -1
- package/dist/utils/cron.js +3 -3
- package/dist/utils/cron.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts +1 -1
- package/dist/utils/filepath-to-prop-path.d.ts.map +1 -1
- package/dist/utils/filepath-to-prop-path.js +27 -6
- package/dist/utils/filepath-to-prop-path.js.map +1 -1
- package/dist/utils/filepath-to-prop-path.mjs +25 -5
- package/dist/utils/filepath-to-prop-path.mjs.map +1 -1
- package/dist/utils/is-initialized.js +3 -3
- package/dist/utils/is-initialized.js.map +1 -1
- package/dist/utils/startup-logger.js +4 -4
- package/dist/utils/startup-logger.js.map +1 -1
- package/dist/utils/startup-logger.mjs +3 -3
- package/dist/utils/startup-logger.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +2 -2
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +6 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +5 -4
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +15 -15
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;
|
1
|
+
{"version":3,"file":"admin.mjs","sources":["../../src/providers/admin.ts"],"sourcesContent":["import { defineProvider } from './provider';\nimport loadAdmin from '../loaders/admin';\n\nexport default defineProvider({\n init(strapi) {\n // eslint-disable-next-line node/no-missing-require\n strapi.add('admin', () => require('@strapi/admin/strapi-server'));\n },\n\n async register(strapi) {\n await loadAdmin(strapi);\n\n await strapi.get('admin')?.register({ strapi });\n },\n\n async bootstrap(strapi) {\n await strapi.get('admin')?.bootstrap({ strapi });\n },\n\n async destroy(strapi) {\n await strapi.get('admin')?.destroy({ strapi });\n },\n});\n"],"names":[],"mappings":";;AAGA,MAAA,QAAe,eAAe;AAAA,EAC5B,KAAK,QAAQ;AAEX,WAAO,IAAI,SAAS,MAAM,QAAQ,6BAA6B,CAAC;AAAA,EAClE;AAAA,EAEA,MAAM,SAAS,QAAQ;AACrB,UAAM,UAAU,MAAM;AAEtB,UAAM,OAAO,IAAI,OAAO,GAAG,SAAS,EAAE,QAAQ;AAAA,EAChD;AAAA,EAEA,MAAM,UAAU,QAAQ;AACtB,UAAM,OAAO,IAAI,OAAO,GAAG,UAAU,EAAE,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,QAAQ,QAAQ;AACpB,UAAM,OAAO,IAAI,OAAO,GAAG,QAAQ,EAAE,QAAQ;AAAA,EAC/C;AACF,CAAC;"}
|
package/dist/registries/apis.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const apisRegistry = (strapi) => {
|
4
4
|
const apis = {};
|
5
5
|
return {
|
@@ -10,7 +10,7 @@ const apisRegistry = (strapi) => {
|
|
10
10
|
return apis;
|
11
11
|
},
|
12
12
|
add(apiName, apiConfig) {
|
13
|
-
if (
|
13
|
+
if (fp.has(apiName, apis)) {
|
14
14
|
throw new Error(`API ${apiName} has already been registered.`);
|
15
15
|
}
|
16
16
|
const api = strapi.get("modules").add(`api::${apiName}`, apiConfig);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"apis.js","sources":["../../src/registries/apis.ts"],"sourcesContent":["import { has } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nconst apisRegistry = (strapi: Core.Strapi) => {\n const apis: Record<string, unknown> = {};\n\n return {\n get(name: string) {\n return apis[name];\n },\n getAll() {\n return apis;\n },\n add(apiName: string, apiConfig: unknown) {\n if (has(apiName, apis)) {\n throw new Error(`API ${apiName} has already been registered.`);\n }\n\n const api = strapi.get('modules').add(`api::${apiName}`, apiConfig);\n\n apis[apiName] = api;\n\n return apis[apiName];\n },\n };\n};\n\nexport default apisRegistry;\n"],"names":["has"],"mappings":";;AAGM,MAAA,eAAe,CAAC,WAAwB;AAC5C,QAAM,OAAgC,CAAA;AAE/B,SAAA;AAAA,IACL,IAAI,MAAc;AAChB,aAAO,KAAK,IAAI;AAAA,IAClB;AAAA,IACA,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,SAAiB,WAAoB;AACnC,UAAAA,
|
1
|
+
{"version":3,"file":"apis.js","sources":["../../src/registries/apis.ts"],"sourcesContent":["import { has } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\n\nconst apisRegistry = (strapi: Core.Strapi) => {\n const apis: Record<string, unknown> = {};\n\n return {\n get(name: string) {\n return apis[name];\n },\n getAll() {\n return apis;\n },\n add(apiName: string, apiConfig: unknown) {\n if (has(apiName, apis)) {\n throw new Error(`API ${apiName} has already been registered.`);\n }\n\n const api = strapi.get('modules').add(`api::${apiName}`, apiConfig);\n\n apis[apiName] = api;\n\n return apis[apiName];\n },\n };\n};\n\nexport default apisRegistry;\n"],"names":["has"],"mappings":";;AAGM,MAAA,eAAe,CAAC,WAAwB;AAC5C,QAAM,OAAgC,CAAA;AAE/B,SAAA;AAAA,IACL,IAAI,MAAc;AAChB,aAAO,KAAK,IAAI;AAAA,IAClB;AAAA,IACA,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,SAAiB,WAAoB;AACnC,UAAAA,GAAA,IAAI,SAAS,IAAI,GAAG;AACtB,cAAM,IAAI,MAAM,OAAO,OAAO,+BAA+B;AAAA,MAC/D;AAEM,YAAA,MAAM,OAAO,IAAI,SAAS,EAAE,IAAI,QAAQ,OAAO,IAAI,SAAS;AAElE,WAAK,OAAO,IAAI;AAEhB,aAAO,KAAK,OAAO;AAAA,IACrB;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const componentsRegistry = () => {
|
4
4
|
const components = {};
|
5
5
|
return {
|
@@ -25,7 +25,7 @@ const componentsRegistry = () => {
|
|
25
25
|
* Registers a component
|
26
26
|
*/
|
27
27
|
set(uid, component) {
|
28
|
-
if (
|
28
|
+
if (fp.has(uid, components)) {
|
29
29
|
throw new Error(`Component ${uid} has already been registered.`);
|
30
30
|
}
|
31
31
|
components[uid] = component;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../src/registries/components.ts"],"sourcesContent":["import { has } from 'lodash/fp';\nimport type { Struct, UID } from '@strapi/types';\n\nconst componentsRegistry = () => {\n const components: Record<UID.Component, Struct.ComponentSchema> = {};\n\n return {\n /**\n * Returns this list of registered components uids\n */\n keys(): UID.Component[] {\n return Object.keys(components) as UID.Component[];\n },\n\n /**\n * Returns the instance of a component. Instantiate the component if not already done\n */\n get(uid: UID.Component) {\n return components[uid];\n },\n\n /**\n * Returns a map with all the components in a namespace\n */\n getAll() {\n return components;\n },\n\n /**\n * Registers a component\n */\n set(uid: UID.Component, component: Struct.ComponentSchema) {\n if (has(uid, components)) {\n throw new Error(`Component ${uid} has already been registered.`);\n }\n\n components[uid] = component;\n\n return this;\n },\n\n /**\n * Registers a map of components for a specific namespace\n */\n add(newComponents: Record<UID.Component, Struct.ComponentSchema>) {\n for (const uid of Object.keys(newComponents) as UID.Component[]) {\n this.set(uid, newComponents[uid]);\n }\n },\n };\n};\n\nexport default componentsRegistry;\n"],"names":["has"],"mappings":";;AAGA,MAAM,qBAAqB,MAAM;AAC/B,QAAM,aAA4D,CAAA;AAE3D,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAwB;AACf,aAAA,OAAO,KAAK,UAAU;AAAA,IAC/B;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAoB;AACtB,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACA,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAoB,WAAmC;AACrD,UAAAA,
|
1
|
+
{"version":3,"file":"components.js","sources":["../../src/registries/components.ts"],"sourcesContent":["import { has } from 'lodash/fp';\nimport type { Struct, UID } from '@strapi/types';\n\nconst componentsRegistry = () => {\n const components: Record<UID.Component, Struct.ComponentSchema> = {};\n\n return {\n /**\n * Returns this list of registered components uids\n */\n keys(): UID.Component[] {\n return Object.keys(components) as UID.Component[];\n },\n\n /**\n * Returns the instance of a component. Instantiate the component if not already done\n */\n get(uid: UID.Component) {\n return components[uid];\n },\n\n /**\n * Returns a map with all the components in a namespace\n */\n getAll() {\n return components;\n },\n\n /**\n * Registers a component\n */\n set(uid: UID.Component, component: Struct.ComponentSchema) {\n if (has(uid, components)) {\n throw new Error(`Component ${uid} has already been registered.`);\n }\n\n components[uid] = component;\n\n return this;\n },\n\n /**\n * Registers a map of components for a specific namespace\n */\n add(newComponents: Record<UID.Component, Struct.ComponentSchema>) {\n for (const uid of Object.keys(newComponents) as UID.Component[]) {\n this.set(uid, newComponents[uid]);\n }\n },\n };\n};\n\nexport default componentsRegistry;\n"],"names":["has"],"mappings":";;AAGA,MAAM,qBAAqB,MAAM;AAC/B,QAAM,aAA4D,CAAA;AAE3D,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAwB;AACf,aAAA,OAAO,KAAK,UAAU;AAAA,IAC/B;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAoB;AACtB,aAAO,WAAW,GAAG;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA,IAKA,SAAS;AACA,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAoB,WAAmC;AACrD,UAAAA,GAAA,IAAI,KAAK,UAAU,GAAG;AACxB,cAAM,IAAI,MAAM,aAAa,GAAG,+BAA+B;AAAA,MACjE;AAEA,iBAAW,GAAG,IAAI;AAEX,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,eAA8D;AAChE,iBAAW,OAAO,OAAO,KAAK,aAAa,GAAsB;AAC/D,aAAK,IAAI,KAAK,cAAc,GAAG,CAAC;AAAA,MAClC;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const index = require("../domain/content-type/index.js");
|
4
4
|
const namespace = require("./namespace.js");
|
5
5
|
const validateKeySameToSingularName = (contentTypes) => {
|
@@ -31,7 +31,7 @@ const contentTypesRegistry = () => {
|
|
31
31
|
* Returns a map with all the contentTypes in a namespace
|
32
32
|
*/
|
33
33
|
getAll(namespace$1) {
|
34
|
-
return
|
34
|
+
return fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(contentTypes);
|
35
35
|
},
|
36
36
|
/**
|
37
37
|
* Registers a contentType
|
@@ -47,7 +47,7 @@ const contentTypesRegistry = () => {
|
|
47
47
|
validateKeySameToSingularName(newContentTypes);
|
48
48
|
for (const rawCtName of Object.keys(newContentTypes)) {
|
49
49
|
const uid = namespace.addNamespace(rawCtName, namespace$1);
|
50
|
-
if (
|
50
|
+
if (fp.has(uid, contentTypes)) {
|
51
51
|
throw new Error(`Content-type ${uid} has already been registered.`);
|
52
52
|
}
|
53
53
|
contentTypes[uid] = index.createContentType(uid, newContentTypes[rawCtName]);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"content-types.js","sources":["../../src/registries/content-types.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { UID, Struct } from '@strapi/types';\nimport { createContentType, ContentTypeDefinition } from '../domain/content-type';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype ContentTypesInput = Record<string, ContentTypeDefinition>;\ntype ContentTypeExtendFn = (contentType: Struct.ContentTypeSchema) => Struct.ContentTypeSchema;\n\nconst validateKeySameToSingularName = (contentTypes: ContentTypesInput) => {\n for (const ctName of Object.keys(contentTypes)) {\n const contentType = contentTypes[ctName];\n\n if (ctName !== contentType.schema.info.singularName) {\n throw new Error(\n `The key of the content-type should be the same as its singularName. Found ${ctName} and ${contentType.schema.info.singularName}.`\n );\n }\n }\n};\n\nconst contentTypesRegistry = () => {\n const contentTypes: Record<string, Struct.ContentTypeSchema> = {};\n\n return {\n /**\n * Returns this list of registered contentTypes uids\n */\n keys() {\n return Object.keys(contentTypes);\n },\n\n /**\n * Returns the instance of a contentType. Instantiate the contentType if not already done\n */\n get(uid: UID.ContentType) {\n return contentTypes[uid];\n },\n\n /**\n * Returns a map with all the contentTypes in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(contentTypes);\n },\n\n /**\n * Registers a contentType\n */\n set(uid: UID.ContentType, contentType: Struct.ContentTypeSchema) {\n contentTypes[uid] = contentType;\n return this;\n },\n\n /**\n * Registers a map of contentTypes for a specific namespace\n */\n add(namespace: string, newContentTypes: ContentTypesInput) {\n validateKeySameToSingularName(newContentTypes);\n\n for (const rawCtName of Object.keys(newContentTypes)) {\n const uid = addNamespace(rawCtName, namespace);\n\n if (has(uid, contentTypes)) {\n throw new Error(`Content-type ${uid} has already been registered.`);\n }\n\n contentTypes[uid] = createContentType(uid, newContentTypes[rawCtName]);\n }\n },\n\n /**\n * Wraps a contentType to extend it\n */\n extend(ctUID: UID.ContentType, extendFn: ContentTypeExtendFn) {\n const currentContentType = this.get(ctUID);\n\n if (!currentContentType) {\n throw new Error(`Content-Type ${ctUID} doesn't exist`);\n }\n\n extendFn(currentContentType);\n\n return this;\n },\n };\n};\n\nexport default contentTypesRegistry;\n"],"names":["namespace","pickBy","
|
1
|
+
{"version":3,"file":"content-types.js","sources":["../../src/registries/content-types.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { UID, Struct } from '@strapi/types';\nimport { createContentType, ContentTypeDefinition } from '../domain/content-type';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype ContentTypesInput = Record<string, ContentTypeDefinition>;\ntype ContentTypeExtendFn = (contentType: Struct.ContentTypeSchema) => Struct.ContentTypeSchema;\n\nconst validateKeySameToSingularName = (contentTypes: ContentTypesInput) => {\n for (const ctName of Object.keys(contentTypes)) {\n const contentType = contentTypes[ctName];\n\n if (ctName !== contentType.schema.info.singularName) {\n throw new Error(\n `The key of the content-type should be the same as its singularName. Found ${ctName} and ${contentType.schema.info.singularName}.`\n );\n }\n }\n};\n\nconst contentTypesRegistry = () => {\n const contentTypes: Record<string, Struct.ContentTypeSchema> = {};\n\n return {\n /**\n * Returns this list of registered contentTypes uids\n */\n keys() {\n return Object.keys(contentTypes);\n },\n\n /**\n * Returns the instance of a contentType. Instantiate the contentType if not already done\n */\n get(uid: UID.ContentType) {\n return contentTypes[uid];\n },\n\n /**\n * Returns a map with all the contentTypes in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(contentTypes);\n },\n\n /**\n * Registers a contentType\n */\n set(uid: UID.ContentType, contentType: Struct.ContentTypeSchema) {\n contentTypes[uid] = contentType;\n return this;\n },\n\n /**\n * Registers a map of contentTypes for a specific namespace\n */\n add(namespace: string, newContentTypes: ContentTypesInput) {\n validateKeySameToSingularName(newContentTypes);\n\n for (const rawCtName of Object.keys(newContentTypes)) {\n const uid = addNamespace(rawCtName, namespace);\n\n if (has(uid, contentTypes)) {\n throw new Error(`Content-type ${uid} has already been registered.`);\n }\n\n contentTypes[uid] = createContentType(uid, newContentTypes[rawCtName]);\n }\n },\n\n /**\n * Wraps a contentType to extend it\n */\n extend(ctUID: UID.ContentType, extendFn: ContentTypeExtendFn) {\n const currentContentType = this.get(ctUID);\n\n if (!currentContentType) {\n throw new Error(`Content-Type ${ctUID} doesn't exist`);\n }\n\n extendFn(currentContentType);\n\n return this;\n },\n };\n};\n\nexport default contentTypesRegistry;\n"],"names":["namespace","pickBy","hasNamespace","addNamespace","has","createContentType"],"mappings":";;;;AAQA,MAAM,gCAAgC,CAAC,iBAAoC;AACzE,aAAW,UAAU,OAAO,KAAK,YAAY,GAAG;AACxC,UAAA,cAAc,aAAa,MAAM;AAEvC,QAAI,WAAW,YAAY,OAAO,KAAK,cAAc;AACnD,YAAM,IAAI;AAAA,QACR,6EAA6E,MAAM,QAAQ,YAAY,OAAO,KAAK,YAAY;AAAA,MAAA;AAAA,IAEnI;AAAA,EACF;AACF;AAEA,MAAM,uBAAuB,MAAM;AACjC,QAAM,eAAyD,CAAA;AAExD,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AACE,aAAA,OAAO,KAAK,YAAY;AAAA,IACjC;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAsB;AACxB,aAAO,aAAa,GAAG;AAAA,IACzB;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOA,aAAmB;AACjB,aAAAC,GAAA,OAAO,CAAC,GAAG,QAAQC,UAAAA,aAAa,KAAKF,WAAS,CAAC,EAAE,YAAY;AAAA,IACtE;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAsB,aAAuC;AAC/D,mBAAa,GAAG,IAAI;AACb,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,iBAAoC;AACzD,oCAA8B,eAAe;AAE7C,iBAAW,aAAa,OAAO,KAAK,eAAe,GAAG;AAC9C,cAAA,MAAMG,UAAAA,aAAa,WAAWH,WAAS;AAEzC,YAAAI,GAAA,IAAI,KAAK,YAAY,GAAG;AAC1B,gBAAM,IAAI,MAAM,gBAAgB,GAAG,+BAA+B;AAAA,QACpE;AAEA,qBAAa,GAAG,IAAIC,MAAA,kBAAkB,KAAK,gBAAgB,SAAS,CAAC;AAAA,MACvE;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,OAAwB,UAA+B;AACtD,YAAA,qBAAqB,KAAK,IAAI,KAAK;AAEzC,UAAI,CAAC,oBAAoB;AACvB,cAAM,IAAI,MAAM,gBAAgB,KAAK,gBAAgB;AAAA,MACvD;AAEA,eAAS,kBAAkB;AAEpB,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const namespace = require("./namespace.js");
|
4
4
|
const controllersRegistry = (strapi) => {
|
5
5
|
const controllers = {};
|
@@ -28,7 +28,7 @@ const controllersRegistry = (strapi) => {
|
|
28
28
|
* Returns a map with all the controller in a namespace
|
29
29
|
*/
|
30
30
|
getAll(namespace$1) {
|
31
|
-
const filteredControllers =
|
31
|
+
const filteredControllers = fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(controllers);
|
32
32
|
const map = {};
|
33
33
|
for (const uid of Object.keys(filteredControllers)) {
|
34
34
|
Object.defineProperty(map, uid, {
|
@@ -55,7 +55,7 @@ const controllersRegistry = (strapi) => {
|
|
55
55
|
for (const controllerName of Object.keys(newControllers)) {
|
56
56
|
const controller = newControllers[controllerName];
|
57
57
|
const uid = namespace.addNamespace(controllerName, namespace$1);
|
58
|
-
if (
|
58
|
+
if (fp.has(uid, controllers)) {
|
59
59
|
throw new Error(`Controller ${uid} has already been registered.`);
|
60
60
|
}
|
61
61
|
controllers[uid] = controller;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"controllers.js","sources":["../../src/registries/controllers.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nexport type ControllerFactory =\n | ((params: { strapi: Core.Strapi }) => Core.Controller)\n | Core.Controller;\nexport type ControllerFactoryMap = Record<UID.Controller, ControllerFactory>;\nexport type ControllerMap = Record<UID.Controller, Core.Controller>;\nexport type ControllerExtendFn = (service: Core.Controller) => Core.Controller;\n\nconst controllersRegistry = (strapi: Core.Strapi) => {\n const controllers: ControllerFactoryMap = {};\n const instances: ControllerMap = {};\n\n return {\n /**\n * Returns this list of registered controllers uids\n */\n keys() {\n return Object.keys(controllers);\n },\n\n /**\n * Returns the instance of a controller. Instantiate the controller if not already done\n */\n get(uid: UID.Controller) {\n if (instances[uid]) {\n return instances[uid];\n }\n\n const controller = controllers[uid];\n\n if (controller) {\n instances[uid] = typeof controller === 'function' ? controller({ strapi }) : controller;\n return instances[uid];\n }\n },\n\n /**\n * Returns a map with all the controller in a namespace\n */\n getAll(namespace: string) {\n const filteredControllers = pickBy((_, uid) => hasNamespace(uid, namespace))(controllers);\n\n const map = {};\n for (const uid of Object.keys(filteredControllers) as UID.Controller[]) {\n Object.defineProperty(map, uid, {\n enumerable: true,\n get: () => {\n return this.get(uid);\n },\n });\n }\n\n return map;\n },\n\n /**\n * Registers a controller\n */\n set(uid: UID.Controller, value: ControllerFactory) {\n controllers[uid] = value;\n delete instances[uid];\n return this;\n },\n\n /**\n * Registers a map of controllers for a specific namespace\n */\n add(namespace: string, newControllers: ControllerFactoryMap) {\n for (const controllerName of Object.keys(newControllers) as UID.Controller[]) {\n const controller = newControllers[controllerName];\n const uid = addNamespace(controllerName, namespace) as UID.Controller;\n\n if (has(uid, controllers)) {\n throw new Error(`Controller ${uid} has already been registered.`);\n }\n\n controllers[uid] = controller;\n }\n\n return this;\n },\n\n /**\n * Wraps a controller to extend it\n */\n extend(controllerUID: UID.Controller, extendFn: ControllerExtendFn) {\n const currentController = this.get(controllerUID);\n\n if (!currentController) {\n throw new Error(`Controller ${controllerUID} doesn't exist`);\n }\n\n const newController = extendFn(currentController);\n instances[controllerUID] = newController;\n\n return this;\n },\n };\n};\n\nexport default controllersRegistry;\n"],"names":["namespace","pickBy","
|
1
|
+
{"version":3,"file":"controllers.js","sources":["../../src/registries/controllers.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nexport type ControllerFactory =\n | ((params: { strapi: Core.Strapi }) => Core.Controller)\n | Core.Controller;\nexport type ControllerFactoryMap = Record<UID.Controller, ControllerFactory>;\nexport type ControllerMap = Record<UID.Controller, Core.Controller>;\nexport type ControllerExtendFn = (service: Core.Controller) => Core.Controller;\n\nconst controllersRegistry = (strapi: Core.Strapi) => {\n const controllers: ControllerFactoryMap = {};\n const instances: ControllerMap = {};\n\n return {\n /**\n * Returns this list of registered controllers uids\n */\n keys() {\n return Object.keys(controllers);\n },\n\n /**\n * Returns the instance of a controller. Instantiate the controller if not already done\n */\n get(uid: UID.Controller) {\n if (instances[uid]) {\n return instances[uid];\n }\n\n const controller = controllers[uid];\n\n if (controller) {\n instances[uid] = typeof controller === 'function' ? controller({ strapi }) : controller;\n return instances[uid];\n }\n },\n\n /**\n * Returns a map with all the controller in a namespace\n */\n getAll(namespace: string) {\n const filteredControllers = pickBy((_, uid) => hasNamespace(uid, namespace))(controllers);\n\n const map = {};\n for (const uid of Object.keys(filteredControllers) as UID.Controller[]) {\n Object.defineProperty(map, uid, {\n enumerable: true,\n get: () => {\n return this.get(uid);\n },\n });\n }\n\n return map;\n },\n\n /**\n * Registers a controller\n */\n set(uid: UID.Controller, value: ControllerFactory) {\n controllers[uid] = value;\n delete instances[uid];\n return this;\n },\n\n /**\n * Registers a map of controllers for a specific namespace\n */\n add(namespace: string, newControllers: ControllerFactoryMap) {\n for (const controllerName of Object.keys(newControllers) as UID.Controller[]) {\n const controller = newControllers[controllerName];\n const uid = addNamespace(controllerName, namespace) as UID.Controller;\n\n if (has(uid, controllers)) {\n throw new Error(`Controller ${uid} has already been registered.`);\n }\n\n controllers[uid] = controller;\n }\n\n return this;\n },\n\n /**\n * Wraps a controller to extend it\n */\n extend(controllerUID: UID.Controller, extendFn: ControllerExtendFn) {\n const currentController = this.get(controllerUID);\n\n if (!currentController) {\n throw new Error(`Controller ${controllerUID} doesn't exist`);\n }\n\n const newController = extendFn(currentController);\n instances[controllerUID] = newController;\n\n return this;\n },\n };\n};\n\nexport default controllersRegistry;\n"],"names":["namespace","pickBy","hasNamespace","addNamespace","has"],"mappings":";;;AAWM,MAAA,sBAAsB,CAAC,WAAwB;AACnD,QAAM,cAAoC,CAAA;AAC1C,QAAM,YAA2B,CAAA;AAE1B,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AACE,aAAA,OAAO,KAAK,WAAW;AAAA,IAChC;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAqB;AACnB,UAAA,UAAU,GAAG,GAAG;AAClB,eAAO,UAAU,GAAG;AAAA,MACtB;AAEM,YAAA,aAAa,YAAY,GAAG;AAElC,UAAI,YAAY;AACJ,kBAAA,GAAG,IAAI,OAAO,eAAe,aAAa,WAAW,EAAE,QAAQ,IAAI;AAC7E,eAAO,UAAU,GAAG;AAAA,MACtB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOA,aAAmB;AAClB,YAAA,sBAAsBC,GAAAA,OAAO,CAAC,GAAG,QAAQC,uBAAa,KAAKF,WAAS,CAAC,EAAE,WAAW;AAExF,YAAM,MAAM,CAAA;AACZ,iBAAW,OAAO,OAAO,KAAK,mBAAmB,GAAuB;AAC/D,eAAA,eAAe,KAAK,KAAK;AAAA,UAC9B,YAAY;AAAA,UACZ,KAAK,MAAM;AACF,mBAAA,KAAK,IAAI,GAAG;AAAA,UACrB;AAAA,QAAA,CACD;AAAA,MACH;AAEO,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAqB,OAA0B;AACjD,kBAAY,GAAG,IAAI;AACnB,aAAO,UAAU,GAAG;AACb,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,gBAAsC;AAC3D,iBAAW,kBAAkB,OAAO,KAAK,cAAc,GAAuB;AACtE,cAAA,aAAa,eAAe,cAAc;AAC1C,cAAA,MAAMG,UAAAA,aAAa,gBAAgBH,WAAS;AAE9C,YAAAI,GAAA,IAAI,KAAK,WAAW,GAAG;AACzB,gBAAM,IAAI,MAAM,cAAc,GAAG,+BAA+B;AAAA,QAClE;AAEA,oBAAY,GAAG,IAAI;AAAA,MACrB;AAEO,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,eAA+B,UAA8B;AAC5D,YAAA,oBAAoB,KAAK,IAAI,aAAa;AAEhD,UAAI,CAAC,mBAAmB;AACtB,cAAM,IAAI,MAAM,cAAc,aAAa,gBAAgB;AAAA,MAC7D;AAEM,YAAA,gBAAgB,SAAS,iBAAiB;AAChD,gBAAU,aAAa,IAAI;AAEpB,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const ALLOWED_TYPES = [
|
4
4
|
"biginteger",
|
5
5
|
"boolean",
|
@@ -34,7 +34,7 @@ const customFieldsRegistry = (strapi) => {
|
|
34
34
|
add(customField) {
|
35
35
|
const customFieldList = Array.isArray(customField) ? customField : [customField];
|
36
36
|
for (const cf of customFieldList) {
|
37
|
-
if (!
|
37
|
+
if (!fp.has("name", cf) || !fp.has("type", cf)) {
|
38
38
|
throw new Error(`Custom fields require a 'name' and 'type' key`);
|
39
39
|
}
|
40
40
|
const { name, plugin, type, inputSize } = cf;
|
@@ -48,7 +48,7 @@ const customFieldsRegistry = (strapi) => {
|
|
48
48
|
throw new Error(`Custom field name: '${name}' is not a valid object key`);
|
49
49
|
}
|
50
50
|
if (inputSize) {
|
51
|
-
if (!
|
51
|
+
if (!fp.isPlainObject(inputSize) || !fp.has("default", inputSize) || !fp.has("isResizable", inputSize)) {
|
52
52
|
throw new Error(`inputSize should be an object with 'default' and 'isResizable' keys`);
|
53
53
|
}
|
54
54
|
if (![4, 6, 8, 12].includes(inputSize.default)) {
|
@@ -59,7 +59,7 @@ const customFieldsRegistry = (strapi) => {
|
|
59
59
|
}
|
60
60
|
}
|
61
61
|
const uid = plugin && strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;
|
62
|
-
if (
|
62
|
+
if (fp.has(uid, customFields)) {
|
63
63
|
throw new Error(`Custom field: '${uid}' has already been registered`);
|
64
64
|
}
|
65
65
|
customFields[uid] = cf;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"custom-fields.js","sources":["../../src/registries/custom-fields.ts"],"sourcesContent":["import { has, isPlainObject } from 'lodash/fp';\n\nimport type { Core, Modules } from '@strapi/types';\n\nconst ALLOWED_TYPES = [\n 'biginteger',\n 'boolean',\n 'date',\n 'datetime',\n 'decimal',\n 'email',\n 'enumeration',\n 'float',\n 'integer',\n 'json',\n 'password',\n 'richtext',\n 'string',\n 'text',\n 'time',\n 'uid',\n] as const;\n\nconst customFieldsRegistry = (strapi: Core.Strapi) => {\n const customFields: Record<string, unknown> = {};\n\n return {\n getAll() {\n return customFields;\n },\n get(customField: string) {\n const registeredCustomField = customFields[customField];\n if (!registeredCustomField) {\n throw new Error(`Could not find Custom Field: ${customField}`);\n }\n\n return registeredCustomField;\n },\n add(\n customField:\n | Modules.CustomFields.CustomFieldServerOptions\n | Modules.CustomFields.CustomFieldServerOptions[]\n ) {\n const customFieldList = Array.isArray(customField) ? customField : [customField];\n\n for (const cf of customFieldList) {\n if (!has('name', cf) || !has('type', cf)) {\n throw new Error(`Custom fields require a 'name' and 'type' key`);\n }\n\n const { name, plugin, type, inputSize } = cf;\n if (!ALLOWED_TYPES.includes(type)) {\n throw new Error(\n `Custom field type: '${type}' is not a valid Strapi type or it can't be used with a Custom Field`\n );\n }\n\n const isValidObjectKey = /^(?![0-9])[a-zA-Z0-9$_-]+$/g;\n if (!isValidObjectKey.test(name)) {\n throw new Error(`Custom field name: '${name}' is not a valid object key`);\n }\n\n // Validate inputSize when provided\n if (inputSize) {\n if (\n !isPlainObject(inputSize) ||\n !has('default', inputSize) ||\n !has('isResizable', inputSize)\n ) {\n throw new Error(`inputSize should be an object with 'default' and 'isResizable' keys`);\n }\n if (![4, 6, 8, 12].includes(inputSize.default)) {\n throw new Error('Custom fields require a valid default input size');\n }\n if (typeof inputSize.isResizable !== 'boolean') {\n throw new Error('Custom fields should specify if their input is resizable');\n }\n }\n\n // When no plugin is specified, or it isn't found in Strapi, default to global\n const uid =\n plugin && strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;\n\n if (has(uid, customFields)) {\n throw new Error(`Custom field: '${uid}' has already been registered`);\n }\n\n customFields[uid] = cf;\n }\n },\n };\n};\n\nexport default customFieldsRegistry;\n"],"names":["has","isPlainObject"],"mappings":";;AAIA,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEM,MAAA,uBAAuB,CAAC,WAAwB;AACpD,QAAM,eAAwC,CAAA;AAEvC,SAAA;AAAA,IACL,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,aAAqB;AACjB,YAAA,wBAAwB,aAAa,WAAW;AACtD,UAAI,CAAC,uBAAuB;AAC1B,cAAM,IAAI,MAAM,gCAAgC,WAAW,EAAE;AAAA,MAC/D;AAEO,aAAA;AAAA,IACT;AAAA,IACA,IACE,aAGA;AACA,YAAM,kBAAkB,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW;AAE/E,iBAAW,MAAM,iBAAiB;AAC5B,YAAA,CAACA,
|
1
|
+
{"version":3,"file":"custom-fields.js","sources":["../../src/registries/custom-fields.ts"],"sourcesContent":["import { has, isPlainObject } from 'lodash/fp';\n\nimport type { Core, Modules } from '@strapi/types';\n\nconst ALLOWED_TYPES = [\n 'biginteger',\n 'boolean',\n 'date',\n 'datetime',\n 'decimal',\n 'email',\n 'enumeration',\n 'float',\n 'integer',\n 'json',\n 'password',\n 'richtext',\n 'string',\n 'text',\n 'time',\n 'uid',\n] as const;\n\nconst customFieldsRegistry = (strapi: Core.Strapi) => {\n const customFields: Record<string, unknown> = {};\n\n return {\n getAll() {\n return customFields;\n },\n get(customField: string) {\n const registeredCustomField = customFields[customField];\n if (!registeredCustomField) {\n throw new Error(`Could not find Custom Field: ${customField}`);\n }\n\n return registeredCustomField;\n },\n add(\n customField:\n | Modules.CustomFields.CustomFieldServerOptions\n | Modules.CustomFields.CustomFieldServerOptions[]\n ) {\n const customFieldList = Array.isArray(customField) ? customField : [customField];\n\n for (const cf of customFieldList) {\n if (!has('name', cf) || !has('type', cf)) {\n throw new Error(`Custom fields require a 'name' and 'type' key`);\n }\n\n const { name, plugin, type, inputSize } = cf;\n if (!ALLOWED_TYPES.includes(type)) {\n throw new Error(\n `Custom field type: '${type}' is not a valid Strapi type or it can't be used with a Custom Field`\n );\n }\n\n const isValidObjectKey = /^(?![0-9])[a-zA-Z0-9$_-]+$/g;\n if (!isValidObjectKey.test(name)) {\n throw new Error(`Custom field name: '${name}' is not a valid object key`);\n }\n\n // Validate inputSize when provided\n if (inputSize) {\n if (\n !isPlainObject(inputSize) ||\n !has('default', inputSize) ||\n !has('isResizable', inputSize)\n ) {\n throw new Error(`inputSize should be an object with 'default' and 'isResizable' keys`);\n }\n if (![4, 6, 8, 12].includes(inputSize.default)) {\n throw new Error('Custom fields require a valid default input size');\n }\n if (typeof inputSize.isResizable !== 'boolean') {\n throw new Error('Custom fields should specify if their input is resizable');\n }\n }\n\n // When no plugin is specified, or it isn't found in Strapi, default to global\n const uid =\n plugin && strapi.plugin(plugin) ? `plugin::${plugin}.${name}` : `global::${name}`;\n\n if (has(uid, customFields)) {\n throw new Error(`Custom field: '${uid}' has already been registered`);\n }\n\n customFields[uid] = cf;\n }\n },\n };\n};\n\nexport default customFieldsRegistry;\n"],"names":["has","isPlainObject"],"mappings":";;AAIA,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEM,MAAA,uBAAuB,CAAC,WAAwB;AACpD,QAAM,eAAwC,CAAA;AAEvC,SAAA;AAAA,IACL,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,aAAqB;AACjB,YAAA,wBAAwB,aAAa,WAAW;AACtD,UAAI,CAAC,uBAAuB;AAC1B,cAAM,IAAI,MAAM,gCAAgC,WAAW,EAAE;AAAA,MAC/D;AAEO,aAAA;AAAA,IACT;AAAA,IACA,IACE,aAGA;AACA,YAAM,kBAAkB,MAAM,QAAQ,WAAW,IAAI,cAAc,CAAC,WAAW;AAE/E,iBAAW,MAAM,iBAAiB;AAC5B,YAAA,CAACA,GAAAA,IAAI,QAAQ,EAAE,KAAK,CAACA,OAAI,QAAQ,EAAE,GAAG;AAClC,gBAAA,IAAI,MAAM,+CAA+C;AAAA,QACjE;AAEA,cAAM,EAAE,MAAM,QAAQ,MAAM,cAAc;AAC1C,YAAI,CAAC,cAAc,SAAS,IAAI,GAAG;AACjC,gBAAM,IAAI;AAAA,YACR,uBAAuB,IAAI;AAAA,UAAA;AAAA,QAE/B;AAEA,cAAM,mBAAmB;AACzB,YAAI,CAAC,iBAAiB,KAAK,IAAI,GAAG;AAChC,gBAAM,IAAI,MAAM,uBAAuB,IAAI,6BAA6B;AAAA,QAC1E;AAGA,YAAI,WAAW;AACb,cACE,CAACC,GAAA,cAAc,SAAS,KACxB,CAACD,GAAAA,IAAI,WAAW,SAAS,KACzB,CAACA,GAAAA,IAAI,eAAe,SAAS,GAC7B;AACM,kBAAA,IAAI,MAAM,qEAAqE;AAAA,UACvF;AACI,cAAA,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,EAAE,SAAS,UAAU,OAAO,GAAG;AACxC,kBAAA,IAAI,MAAM,kDAAkD;AAAA,UACpE;AACI,cAAA,OAAO,UAAU,gBAAgB,WAAW;AACxC,kBAAA,IAAI,MAAM,0DAA0D;AAAA,UAC5E;AAAA,QACF;AAGA,cAAM,MACJ,UAAU,OAAO,OAAO,MAAM,IAAI,WAAW,MAAM,IAAI,IAAI,KAAK,WAAW,IAAI;AAE7E,YAAAA,GAAA,IAAI,KAAK,YAAY,GAAG;AAC1B,gBAAM,IAAI,MAAM,kBAAkB,GAAG,+BAA+B;AAAA,QACtE;AAEA,qBAAa,GAAG,IAAI;AAAA,MACtB;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
package/dist/registries/hooks.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const namespace = require("./namespace.js");
|
4
4
|
const hooksRegistry = () => {
|
5
5
|
const hooks = {};
|
@@ -20,7 +20,7 @@ const hooksRegistry = () => {
|
|
20
20
|
* Returns a map with all the hooks in a namespace
|
21
21
|
*/
|
22
22
|
getAll(namespace$1) {
|
23
|
-
return
|
23
|
+
return fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(hooks);
|
24
24
|
},
|
25
25
|
/**
|
26
26
|
* Registers a hook
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../src/registries/hooks.ts"],"sourcesContent":["import { pickBy } from 'lodash/fp';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype Handler = (context: any) => any;\n\ntype AsyncHook = {\n handlers: Handler[];\n register(handler: Handler): AsyncHook;\n delete(handler: Handler): AsyncHook;\n call(): Promise<void>;\n};\n\ntype SyncHook = {\n get handlers(): Handler[];\n register(handler: Handler): SyncHook;\n delete(handler: Handler): SyncHook;\n call(): void;\n};\n\nexport type Hook = AsyncHook | SyncHook;\n\ntype HookExtendFn = (hook: Hook) => Hook;\n\nconst hooksRegistry = () => {\n const hooks: Record<string, Hook> = {};\n\n return {\n /**\n * Returns this list of registered hooks uids\n */\n keys() {\n return Object.keys(hooks);\n },\n\n /**\n * Returns the instance of a hook.\n */\n get(uid: string) {\n return hooks[uid];\n },\n\n /**\n * Returns a map with all the hooks in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(hooks);\n },\n\n /**\n * Registers a hook\n */\n set(uid: string, hook: Hook) {\n hooks[uid] = hook;\n return this;\n },\n\n /**\n * Registers a map of hooks for a specific namespace\n */\n add(namespace: string, hooks: Record<string, Hook>) {\n for (const hookName of Object.keys(hooks)) {\n const hook = hooks[hookName];\n const uid = addNamespace(hookName, namespace);\n\n this.set(uid, hook);\n }\n\n return this;\n },\n\n /**\n * Wraps a hook to extend it\n */\n extend(uid: string, extendFn: HookExtendFn) {\n const currentHook = this.get(uid);\n\n if (!currentHook) {\n throw new Error(`Hook ${uid} doesn't exist`);\n }\n\n const newHook = extendFn(currentHook);\n hooks[uid] = newHook;\n\n return this;\n },\n };\n};\n\nexport default hooksRegistry;\n"],"names":["namespace","pickBy","
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../src/registries/hooks.ts"],"sourcesContent":["import { pickBy } from 'lodash/fp';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype Handler = (context: any) => any;\n\ntype AsyncHook = {\n handlers: Handler[];\n register(handler: Handler): AsyncHook;\n delete(handler: Handler): AsyncHook;\n call(): Promise<void>;\n};\n\ntype SyncHook = {\n get handlers(): Handler[];\n register(handler: Handler): SyncHook;\n delete(handler: Handler): SyncHook;\n call(): void;\n};\n\nexport type Hook = AsyncHook | SyncHook;\n\ntype HookExtendFn = (hook: Hook) => Hook;\n\nconst hooksRegistry = () => {\n const hooks: Record<string, Hook> = {};\n\n return {\n /**\n * Returns this list of registered hooks uids\n */\n keys() {\n return Object.keys(hooks);\n },\n\n /**\n * Returns the instance of a hook.\n */\n get(uid: string) {\n return hooks[uid];\n },\n\n /**\n * Returns a map with all the hooks in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(hooks);\n },\n\n /**\n * Registers a hook\n */\n set(uid: string, hook: Hook) {\n hooks[uid] = hook;\n return this;\n },\n\n /**\n * Registers a map of hooks for a specific namespace\n */\n add(namespace: string, hooks: Record<string, Hook>) {\n for (const hookName of Object.keys(hooks)) {\n const hook = hooks[hookName];\n const uid = addNamespace(hookName, namespace);\n\n this.set(uid, hook);\n }\n\n return this;\n },\n\n /**\n * Wraps a hook to extend it\n */\n extend(uid: string, extendFn: HookExtendFn) {\n const currentHook = this.get(uid);\n\n if (!currentHook) {\n throw new Error(`Hook ${uid} doesn't exist`);\n }\n\n const newHook = extendFn(currentHook);\n hooks[uid] = newHook;\n\n return this;\n },\n };\n};\n\nexport default hooksRegistry;\n"],"names":["namespace","pickBy","hasNamespace","hooks","addNamespace"],"mappings":";;;AAuBA,MAAM,gBAAgB,MAAM;AAC1B,QAAM,QAA8B,CAAA;AAE7B,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AACE,aAAA,OAAO,KAAK,KAAK;AAAA,IAC1B;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa;AACf,aAAO,MAAM,GAAG;AAAA,IAClB;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOA,aAAmB;AACjB,aAAAC,GAAA,OAAO,CAAC,GAAG,QAAQC,UAAAA,aAAa,KAAKF,WAAS,CAAC,EAAE,KAAK;AAAA,IAC/D;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,MAAY;AAC3B,YAAM,GAAG,IAAI;AACN,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmBG,QAA6B;AAClD,iBAAW,YAAY,OAAO,KAAKA,MAAK,GAAG;AACnC,cAAA,OAAOA,OAAM,QAAQ;AACrB,cAAA,MAAMC,UAAAA,aAAa,UAAUJ,WAAS;AAEvC,aAAA,IAAI,KAAK,IAAI;AAAA,MACpB;AAEO,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,KAAa,UAAwB;AACpC,YAAA,cAAc,KAAK,IAAI,GAAG;AAEhC,UAAI,CAAC,aAAa;AAChB,cAAM,IAAI,MAAM,QAAQ,GAAG,gBAAgB;AAAA,MAC7C;AAEM,YAAA,UAAU,SAAS,WAAW;AACpC,YAAM,GAAG,IAAI;AAEN,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const namespace = require("./namespace.js");
|
4
4
|
const middlewaresRegistry = () => {
|
5
5
|
const middlewares = {};
|
@@ -20,7 +20,7 @@ const middlewaresRegistry = () => {
|
|
20
20
|
* Returns a map with all the middlewares in a namespace
|
21
21
|
*/
|
22
22
|
getAll(namespace$1) {
|
23
|
-
return
|
23
|
+
return fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(middlewares);
|
24
24
|
},
|
25
25
|
/**
|
26
26
|
* Registers a middleware
|
@@ -36,7 +36,7 @@ const middlewaresRegistry = () => {
|
|
36
36
|
for (const middlewareName of Object.keys(rawMiddlewares)) {
|
37
37
|
const middleware = rawMiddlewares[middlewareName];
|
38
38
|
const uid = namespace.addNamespace(middlewareName, namespace$1);
|
39
|
-
if (
|
39
|
+
if (fp.has(uid, middlewares)) {
|
40
40
|
throw new Error(`Middleware ${uid} has already been registered.`);
|
41
41
|
}
|
42
42
|
middlewares[uid] = middleware;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"middlewares.js","sources":["../../src/registries/middlewares.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype MiddlewareExtendFn = (middleware: Core.Middleware) => Core.Middleware;\n\n// TODO: move instantiation part here instead of in the server service\nconst middlewaresRegistry = () => {\n const middlewares: Record<UID.Middleware, Core.Middleware> = {};\n\n return {\n /**\n * Returns this list of registered middlewares uids\n */\n keys() {\n return Object.keys(middlewares);\n },\n\n /**\n * Returns the instance of a middleware. Instantiate the middleware if not already done\n */\n get(uid: UID.Middleware) {\n return middlewares[uid];\n },\n\n /**\n * Returns a map with all the middlewares in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(middlewares);\n },\n\n /**\n * Registers a middleware\n */\n set(uid: UID.Middleware, middleware: Core.Middleware) {\n middlewares[uid] = middleware;\n return this;\n },\n\n /**\n * Registers a map of middlewares for a specific namespace\n */\n add(namespace: string, rawMiddlewares: Record<string, Core.Middleware> = {}) {\n for (const middlewareName of Object.keys(rawMiddlewares)) {\n const middleware = rawMiddlewares[middlewareName];\n const uid = addNamespace(middlewareName, namespace) as UID.Middleware;\n\n if (has(uid, middlewares)) {\n throw new Error(`Middleware ${uid} has already been registered.`);\n }\n middlewares[uid] = middleware;\n }\n },\n\n /**\n * Wraps a middleware to extend it\n */\n extend(uid: UID.Middleware, extendFn: MiddlewareExtendFn) {\n const currentMiddleware = this.get(uid);\n\n if (!currentMiddleware) {\n throw new Error(`Middleware ${uid} doesn't exist`);\n }\n\n const newMiddleware = extendFn(currentMiddleware);\n middlewares[uid] = newMiddleware;\n\n return this;\n },\n };\n};\n\nexport default middlewaresRegistry;\n"],"names":["namespace","pickBy","
|
1
|
+
{"version":3,"file":"middlewares.js","sources":["../../src/registries/middlewares.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\ntype MiddlewareExtendFn = (middleware: Core.Middleware) => Core.Middleware;\n\n// TODO: move instantiation part here instead of in the server service\nconst middlewaresRegistry = () => {\n const middlewares: Record<UID.Middleware, Core.Middleware> = {};\n\n return {\n /**\n * Returns this list of registered middlewares uids\n */\n keys() {\n return Object.keys(middlewares);\n },\n\n /**\n * Returns the instance of a middleware. Instantiate the middleware if not already done\n */\n get(uid: UID.Middleware) {\n return middlewares[uid];\n },\n\n /**\n * Returns a map with all the middlewares in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(middlewares);\n },\n\n /**\n * Registers a middleware\n */\n set(uid: UID.Middleware, middleware: Core.Middleware) {\n middlewares[uid] = middleware;\n return this;\n },\n\n /**\n * Registers a map of middlewares for a specific namespace\n */\n add(namespace: string, rawMiddlewares: Record<string, Core.Middleware> = {}) {\n for (const middlewareName of Object.keys(rawMiddlewares)) {\n const middleware = rawMiddlewares[middlewareName];\n const uid = addNamespace(middlewareName, namespace) as UID.Middleware;\n\n if (has(uid, middlewares)) {\n throw new Error(`Middleware ${uid} has already been registered.`);\n }\n middlewares[uid] = middleware;\n }\n },\n\n /**\n * Wraps a middleware to extend it\n */\n extend(uid: UID.Middleware, extendFn: MiddlewareExtendFn) {\n const currentMiddleware = this.get(uid);\n\n if (!currentMiddleware) {\n throw new Error(`Middleware ${uid} doesn't exist`);\n }\n\n const newMiddleware = extendFn(currentMiddleware);\n middlewares[uid] = newMiddleware;\n\n return this;\n },\n };\n};\n\nexport default middlewaresRegistry;\n"],"names":["namespace","pickBy","hasNamespace","addNamespace","has"],"mappings":";;;AAOA,MAAM,sBAAsB,MAAM;AAChC,QAAM,cAAuD,CAAA;AAEtD,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AACE,aAAA,OAAO,KAAK,WAAW;AAAA,IAChC;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAqB;AACvB,aAAO,YAAY,GAAG;AAAA,IACxB;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOA,aAAmB;AACjB,aAAAC,GAAA,OAAO,CAAC,GAAG,QAAQC,UAAAA,aAAa,KAAKF,WAAS,CAAC,EAAE,WAAW;AAAA,IACrE;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAqB,YAA6B;AACpD,kBAAY,GAAG,IAAI;AACZ,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,iBAAkD,IAAI;AAC3E,iBAAW,kBAAkB,OAAO,KAAK,cAAc,GAAG;AAClD,cAAA,aAAa,eAAe,cAAc;AAC1C,cAAA,MAAMG,UAAAA,aAAa,gBAAgBH,WAAS;AAE9C,YAAAI,GAAA,IAAI,KAAK,WAAW,GAAG;AACzB,gBAAM,IAAI,MAAM,cAAc,GAAG,+BAA+B;AAAA,QAClE;AACA,oBAAY,GAAG,IAAI;AAAA,MACrB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,KAAqB,UAA8B;AAClD,YAAA,oBAAoB,KAAK,IAAI,GAAG;AAEtC,UAAI,CAAC,mBAAmB;AACtB,cAAM,IAAI,MAAM,cAAc,GAAG,gBAAgB;AAAA,MACnD;AAEM,YAAA,gBAAgB,SAAS,iBAAiB;AAChD,kBAAY,GAAG,IAAI;AAEZ,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const index = require("../domain/module/index.js");
|
4
4
|
const modulesRegistry = (strapi) => {
|
5
5
|
const modules = {};
|
@@ -8,10 +8,10 @@ const modulesRegistry = (strapi) => {
|
|
8
8
|
return modules[namespace];
|
9
9
|
},
|
10
10
|
getAll(prefix = "") {
|
11
|
-
return
|
11
|
+
return fp.pickBy((mod, namespace) => namespace.startsWith(prefix))(modules);
|
12
12
|
},
|
13
13
|
add(namespace, rawModule) {
|
14
|
-
if (
|
14
|
+
if (fp.has(namespace, modules)) {
|
15
15
|
throw new Error(`Module ${namespace} has already been registered.`);
|
16
16
|
}
|
17
17
|
modules[namespace] = index.createModule(namespace, rawModule, strapi);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modules.js","sources":["../../src/registries/modules.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { createModule, RawModule, Module } from '../domain/module';\n\ntype ModuleMap = { [namespace: string]: Module };\n\nconst modulesRegistry = (strapi: Core.Strapi) => {\n const modules: ModuleMap = {};\n\n return {\n get(namespace: string) {\n return modules[namespace];\n },\n getAll(prefix = '') {\n return pickBy<ModuleMap>((mod, namespace) => namespace.startsWith(prefix))(modules);\n },\n add(namespace: string, rawModule: RawModule) {\n if (has(namespace, modules)) {\n throw new Error(`Module ${namespace} has already been registered.`);\n }\n\n modules[namespace] = createModule(namespace, rawModule, strapi);\n modules[namespace].load();\n\n return modules[namespace];\n },\n async bootstrap() {\n for (const mod of Object.values(modules)) {\n await mod.bootstrap();\n }\n },\n async register() {\n for (const mod of Object.values(modules)) {\n await mod.register();\n }\n },\n async destroy() {\n for (const mod of Object.values(modules)) {\n await mod.destroy();\n }\n },\n };\n};\n\nexport default modulesRegistry;\n"],"names":["pickBy","has","createModule"],"mappings":";;;AAMM,MAAA,kBAAkB,CAAC,WAAwB;AAC/C,QAAM,UAAqB,CAAA;AAEpB,SAAA;AAAA,IACL,IAAI,WAAmB;AACrB,aAAO,QAAQ,SAAS;AAAA,IAC1B;AAAA,IACA,OAAO,SAAS,IAAI;AACX,aAAAA,
|
1
|
+
{"version":3,"file":"modules.js","sources":["../../src/registries/modules.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { createModule, RawModule, Module } from '../domain/module';\n\ntype ModuleMap = { [namespace: string]: Module };\n\nconst modulesRegistry = (strapi: Core.Strapi) => {\n const modules: ModuleMap = {};\n\n return {\n get(namespace: string) {\n return modules[namespace];\n },\n getAll(prefix = '') {\n return pickBy<ModuleMap>((mod, namespace) => namespace.startsWith(prefix))(modules);\n },\n add(namespace: string, rawModule: RawModule) {\n if (has(namespace, modules)) {\n throw new Error(`Module ${namespace} has already been registered.`);\n }\n\n modules[namespace] = createModule(namespace, rawModule, strapi);\n modules[namespace].load();\n\n return modules[namespace];\n },\n async bootstrap() {\n for (const mod of Object.values(modules)) {\n await mod.bootstrap();\n }\n },\n async register() {\n for (const mod of Object.values(modules)) {\n await mod.register();\n }\n },\n async destroy() {\n for (const mod of Object.values(modules)) {\n await mod.destroy();\n }\n },\n };\n};\n\nexport default modulesRegistry;\n"],"names":["pickBy","has","createModule"],"mappings":";;;AAMM,MAAA,kBAAkB,CAAC,WAAwB;AAC/C,QAAM,UAAqB,CAAA;AAEpB,SAAA;AAAA,IACL,IAAI,WAAmB;AACrB,aAAO,QAAQ,SAAS;AAAA,IAC1B;AAAA,IACA,OAAO,SAAS,IAAI;AACX,aAAAA,GAAA,OAAkB,CAAC,KAAK,cAAc,UAAU,WAAW,MAAM,CAAC,EAAE,OAAO;AAAA,IACpF;AAAA,IACA,IAAI,WAAmB,WAAsB;AACvC,UAAAC,GAAA,IAAI,WAAW,OAAO,GAAG;AAC3B,cAAM,IAAI,MAAM,UAAU,SAAS,+BAA+B;AAAA,MACpE;AAEA,cAAQ,SAAS,IAAIC,MAAAA,aAAa,WAAW,WAAW,MAAM;AACtD,cAAA,SAAS,EAAE;AAEnB,aAAO,QAAQ,SAAS;AAAA,IAC1B;AAAA,IACA,MAAM,YAAY;AAChB,iBAAW,OAAO,OAAO,OAAO,OAAO,GAAG;AACxC,cAAM,IAAI;MACZ;AAAA,IACF;AAAA,IACA,MAAM,WAAW;AACf,iBAAW,OAAO,OAAO,OAAO,OAAO,GAAG;AACxC,cAAM,IAAI;MACZ;AAAA,IACF;AAAA,IACA,MAAM,UAAU;AACd,iBAAW,OAAO,OAAO,OAAO,OAAO,GAAG;AACxC,cAAM,IAAI;MACZ;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const pluginsRegistry = (strapi) => {
|
4
4
|
const plugins = {};
|
5
5
|
return {
|
@@ -10,7 +10,7 @@ const pluginsRegistry = (strapi) => {
|
|
10
10
|
return plugins;
|
11
11
|
},
|
12
12
|
add(name, pluginConfig) {
|
13
|
-
if (
|
13
|
+
if (fp.has(name, plugins)) {
|
14
14
|
throw new Error(`Plugin ${name} has already been registered.`);
|
15
15
|
}
|
16
16
|
const pluginModule = strapi.get("modules").add(`plugin::${name}`, pluginConfig);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"plugins.js","sources":["../../src/registries/plugins.ts"],"sourcesContent":["import { has } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\n\ntype PluginMap = Record<string, Core.Plugin>;\n\nconst pluginsRegistry = (strapi: Core.Strapi) => {\n const plugins: PluginMap = {};\n\n return {\n get(name: string) {\n return plugins[name];\n },\n getAll() {\n return plugins;\n },\n add(name: string, pluginConfig: Core.Plugin) {\n if (has(name, plugins)) {\n throw new Error(`Plugin ${name} has already been registered.`);\n }\n\n const pluginModule = strapi.get('modules').add(`plugin::${name}`, pluginConfig);\n plugins[name] = pluginModule;\n\n return plugins[name];\n },\n };\n};\n\nexport default pluginsRegistry;\n"],"names":["has"],"mappings":";;AAMM,MAAA,kBAAkB,CAAC,WAAwB;AAC/C,QAAM,UAAqB,CAAA;AAEpB,SAAA;AAAA,IACL,IAAI,MAAc;AAChB,aAAO,QAAQ,IAAI;AAAA,IACrB;AAAA,IACA,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAc,cAA2B;AACvC,UAAAA,
|
1
|
+
{"version":3,"file":"plugins.js","sources":["../../src/registries/plugins.ts"],"sourcesContent":["import { has } from 'lodash/fp';\n\nimport type { Core } from '@strapi/types';\n\ntype PluginMap = Record<string, Core.Plugin>;\n\nconst pluginsRegistry = (strapi: Core.Strapi) => {\n const plugins: PluginMap = {};\n\n return {\n get(name: string) {\n return plugins[name];\n },\n getAll() {\n return plugins;\n },\n add(name: string, pluginConfig: Core.Plugin) {\n if (has(name, plugins)) {\n throw new Error(`Plugin ${name} has already been registered.`);\n }\n\n const pluginModule = strapi.get('modules').add(`plugin::${name}`, pluginConfig);\n plugins[name] = pluginModule;\n\n return plugins[name];\n },\n };\n};\n\nexport default pluginsRegistry;\n"],"names":["has"],"mappings":";;AAMM,MAAA,kBAAkB,CAAC,WAAwB;AAC/C,QAAM,UAAqB,CAAA;AAEpB,SAAA;AAAA,IACL,IAAI,MAAc;AAChB,aAAO,QAAQ,IAAI;AAAA,IACrB;AAAA,IACA,SAAS;AACA,aAAA;AAAA,IACT;AAAA,IACA,IAAI,MAAc,cAA2B;AACvC,UAAAA,GAAA,IAAI,MAAM,OAAO,GAAG;AACtB,cAAM,IAAI,MAAM,UAAU,IAAI,+BAA+B;AAAA,MAC/D;AAEM,YAAA,eAAe,OAAO,IAAI,SAAS,EAAE,IAAI,WAAW,IAAI,IAAI,YAAY;AAC9E,cAAQ,IAAI,IAAI;AAEhB,aAAO,QAAQ,IAAI;AAAA,IACrB;AAAA,EAAA;AAEJ;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;
|
1
|
+
{"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/registries/policies.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAM1C,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,KAAK,YAAY,GAAG,MAAM,GAAG,UAAU,CAAC;AAExC,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAWD,QAAA,MAAM,gBAAgB;IAyDlB;;OAEG;;IAMH;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAG/C;;OAEG;cACO,MAAM,kBAAkB,aAAa;IAK/C;;OAEG;sBACe,MAAM;IAIxB;;OAEG;aACM,MAAM,UAAU,KAAK,MAAM;IAKpC;;OAEG;mBACY,MAAM,eAAe,OAAO,MAAM,EAAE,KAAK,MAAM,CAAC;IAa/D;;OAEG;oBACa,YAAY,GAAG,YAAY,EAAE,kBAAkB,aAAa;;;;CAW/E,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const namespace = require("./namespace.js");
|
4
4
|
const PLUGIN_PREFIX = "plugin::";
|
5
5
|
const API_PREFIX = "api::";
|
@@ -49,7 +49,7 @@ const policiesRegistry = () => {
|
|
49
49
|
* Returns this list of registered policies uids
|
50
50
|
*/
|
51
51
|
keys() {
|
52
|
-
return policies.keys();
|
52
|
+
return Array.from(policies.keys());
|
53
53
|
},
|
54
54
|
/**
|
55
55
|
* Returns the instance of a policy. Instantiate the policy if not already done
|
@@ -68,7 +68,7 @@ const policiesRegistry = () => {
|
|
68
68
|
* Returns a map with all the policies in a namespace
|
69
69
|
*/
|
70
70
|
getAll(namespace$1) {
|
71
|
-
return
|
71
|
+
return fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(Object.fromEntries(policies));
|
72
72
|
},
|
73
73
|
/**
|
74
74
|
* Registers a policy
|
@@ -84,7 +84,7 @@ const policiesRegistry = () => {
|
|
84
84
|
for (const policyName of Object.keys(newPolicies)) {
|
85
85
|
const policy = newPolicies[policyName];
|
86
86
|
const uid = namespace.addNamespace(policyName, namespace$1);
|
87
|
-
if (
|
87
|
+
if (fp.has(uid, policies)) {
|
88
88
|
throw new Error(`Policy ${uid} has already been registered.`);
|
89
89
|
}
|
90
90
|
policies.set(uid, policy);
|
@@ -95,7 +95,7 @@ const policiesRegistry = () => {
|
|
95
95
|
*/
|
96
96
|
resolve(config, namespaceInfo) {
|
97
97
|
const { pluginName, apiName } = namespaceInfo ?? {};
|
98
|
-
return
|
98
|
+
return fp.castArray(config).map((policyConfig) => {
|
99
99
|
return {
|
100
100
|
handler: resolveHandler(policyConfig, { pluginName, apiName }),
|
101
101
|
config: typeof policyConfig === "object" && policyConfig.config || {}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"policies.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","
|
1
|
+
{"version":3,"file":"policies.js","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config","namespace","pickBy","hasNamespace","addNamespace","has","castArray"],"mappings":";;;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AAEA,QAAI,OAAO,WAAW;AACpB,aAAO,UAAU,MAAM;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAChB;AAEO,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AAEL,aAAO,MAAM,KAAK,SAAS,KAAM,CAAA;AAAA,IACnC;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAc,eAA+B;AACxC,aAAA,KAAK,MAAM,aAAa;AAAA,IACjC;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,MAAc,eAA+B;AACzC,YAAA,MAAM,KAAK,MAAM,aAAa;AACpC,aAAO,CAAC,CAAC;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOC,aAAmB;AACxB,aAAOC,UAAO,CAAC,GAAG,QAAQC,UAAAA,aAAa,KAAKF,WAAS,CAAC,EAAE,OAAO,YAAY,QAAQ,CAAC;AAAA,IACtF;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,QAAqB;AAC3B,eAAA,IAAI,KAAK,MAAM;AACjB,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,aAA0C;AAC/D,iBAAW,cAAc,OAAO,KAAK,WAAW,GAAG;AAC3C,cAAA,SAAS,YAAY,UAAU;AAC/B,cAAA,MAAMG,UAAAA,aAAa,YAAYH,WAAS;AAE1C,YAAAI,GAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAOC,GAAU,UAAA,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
|
@@ -48,7 +48,7 @@ const policiesRegistry = () => {
|
|
48
48
|
* Returns this list of registered policies uids
|
49
49
|
*/
|
50
50
|
keys() {
|
51
|
-
return policies.keys();
|
51
|
+
return Array.from(policies.keys());
|
52
52
|
},
|
53
53
|
/**
|
54
54
|
* Returns the instance of a policy. Instantiate the policy if not already done
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n return policies.keys();\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AAEA,QAAI,OAAO,WAAW;AACpB,aAAO,UAAU,MAAM;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAChB;AAEO,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;
|
1
|
+
{"version":3,"file":"policies.mjs","sources":["../../src/registries/policies.ts"],"sourcesContent":["import { pickBy, has, castArray } from 'lodash/fp';\nimport type { Core } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nconst PLUGIN_PREFIX = 'plugin::';\nconst API_PREFIX = 'api::';\n\ninterface PolicyInfo {\n name: string;\n config: unknown;\n}\n\ntype PolicyConfig = string | PolicyInfo;\n\ninterface NamespaceInfo {\n pluginName?: string;\n apiName?: string;\n}\n\nconst parsePolicy = (policy: string | PolicyInfo) => {\n if (typeof policy === 'string') {\n return { policyName: policy, config: {} };\n }\n\n const { name, config } = policy;\n return { policyName: name, config };\n};\n\nconst policiesRegistry = () => {\n const policies = new Map<string, Core.Policy>();\n\n const find = (name: string, namespaceInfo?: NamespaceInfo) => {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n // try to resolve a full name to avoid extra prefixing\n const policy = policies.get(name);\n\n if (policy) {\n return policy;\n }\n\n if (pluginName) {\n return policies.get(`${PLUGIN_PREFIX}${pluginName}.${name}`);\n }\n\n if (apiName) {\n return policies.get(`${API_PREFIX}${apiName}.${name}`);\n }\n };\n\n function resolveHandler(policyConfig: PolicyConfig, namespaceInfo?: NamespaceInfo): Core.Policy;\n function resolveHandler(\n policyConfig: PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy[];\n function resolveHandler(\n policyConfig: PolicyConfig | PolicyConfig[],\n namespaceInfo?: NamespaceInfo\n ): Core.Policy | Core.Policy[] {\n if (Array.isArray(policyConfig)) {\n return policyConfig.map((config) => {\n return resolveHandler(config, namespaceInfo);\n });\n }\n\n const { policyName, config } = parsePolicy(policyConfig);\n\n const policy = find(policyName, namespaceInfo);\n\n if (!policy) {\n throw new Error(`Policy ${policyName} not found.`);\n }\n\n if (typeof policy === 'function') {\n return policy;\n }\n\n if (policy.validator) {\n policy.validator(config);\n }\n\n return policy.handler;\n }\n\n return {\n /**\n * Returns this list of registered policies uids\n */\n keys() {\n // Return an array so format stays the same as controllers, services, etc\n return Array.from(policies.keys());\n },\n\n /**\n * Returns the instance of a policy. Instantiate the policy if not already done\n */\n get(name: string, namespaceInfo?: NamespaceInfo) {\n return find(name, namespaceInfo);\n },\n /**\n * Checks if a policy is registered\n */\n has(name: string, namespaceInfo?: NamespaceInfo) {\n const res = find(name, namespaceInfo);\n return !!res;\n },\n\n /**\n * Returns a map with all the policies in a namespace\n */\n getAll(namespace: string) {\n return pickBy((_, uid) => hasNamespace(uid, namespace))(Object.fromEntries(policies));\n },\n\n /**\n * Registers a policy\n */\n set(uid: string, policy: Core.Policy) {\n policies.set(uid, policy);\n return this;\n },\n\n /**\n * Registers a map of policies for a specific namespace\n */\n add(namespace: string, newPolicies: Record<string, Core.Policy>) {\n for (const policyName of Object.keys(newPolicies)) {\n const policy = newPolicies[policyName];\n const uid = addNamespace(policyName, namespace);\n\n if (has(uid, policies)) {\n throw new Error(`Policy ${uid} has already been registered.`);\n }\n\n policies.set(uid, policy);\n }\n },\n\n /**\n * Resolves a list of policies\n */\n resolve(config: PolicyConfig | PolicyConfig[], namespaceInfo?: NamespaceInfo) {\n const { pluginName, apiName } = namespaceInfo ?? {};\n\n return castArray(config).map((policyConfig) => {\n return {\n handler: resolveHandler(policyConfig, { pluginName, apiName }),\n config: (typeof policyConfig === 'object' && policyConfig.config) || {},\n };\n });\n },\n };\n};\n\nexport default policiesRegistry;\n"],"names":["config"],"mappings":";;AAIA,MAAM,gBAAgB;AACtB,MAAM,aAAa;AAcnB,MAAM,cAAc,CAAC,WAAgC;AAC/C,MAAA,OAAO,WAAW,UAAU;AAC9B,WAAO,EAAE,YAAY,QAAQ,QAAQ,CAAG,EAAA;AAAA,EAC1C;AAEM,QAAA,EAAE,MAAM,OAAW,IAAA;AAClB,SAAA,EAAE,YAAY,MAAM;AAC7B;AAEA,MAAM,mBAAmB,MAAM;AACvB,QAAA,+BAAe;AAEf,QAAA,OAAO,CAAC,MAAc,kBAAkC;AAC5D,UAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAG3C,UAAA,SAAS,SAAS,IAAI,IAAI;AAEhC,QAAI,QAAQ;AACH,aAAA;AAAA,IACT;AAEA,QAAI,YAAY;AACP,aAAA,SAAS,IAAI,GAAG,aAAa,GAAG,UAAU,IAAI,IAAI,EAAE;AAAA,IAC7D;AAEA,QAAI,SAAS;AACJ,aAAA,SAAS,IAAI,GAAG,UAAU,GAAG,OAAO,IAAI,IAAI,EAAE;AAAA,IACvD;AAAA,EAAA;AAQO,WAAA,eACP,cACA,eAC6B;AACzB,QAAA,MAAM,QAAQ,YAAY,GAAG;AACxB,aAAA,aAAa,IAAI,CAACA,YAAW;AAC3B,eAAA,eAAeA,SAAQ,aAAa;AAAA,MAAA,CAC5C;AAAA,IACH;AAEA,UAAM,EAAE,YAAY,OAAO,IAAI,YAAY,YAAY;AAEjD,UAAA,SAAS,KAAK,YAAY,aAAa;AAE7C,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,UAAU,UAAU,aAAa;AAAA,IACnD;AAEI,QAAA,OAAO,WAAW,YAAY;AACzB,aAAA;AAAA,IACT;AAEA,QAAI,OAAO,WAAW;AACpB,aAAO,UAAU,MAAM;AAAA,IACzB;AAEA,WAAO,OAAO;AAAA,EAChB;AAEO,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AAEL,aAAO,MAAM,KAAK,SAAS,KAAM,CAAA;AAAA,IACnC;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,MAAc,eAA+B;AACxC,aAAA,KAAK,MAAM,aAAa;AAAA,IACjC;AAAA;AAAA;AAAA;AAAA,IAIA,IAAI,MAAc,eAA+B;AACzC,YAAA,MAAM,KAAK,MAAM,aAAa;AACpC,aAAO,CAAC,CAAC;AAAA,IACX;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,WAAmB;AACxB,aAAO,OAAO,CAAC,GAAG,QAAQ,aAAa,KAAK,SAAS,CAAC,EAAE,OAAO,YAAY,QAAQ,CAAC;AAAA,IACtF;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,QAAqB;AAC3B,eAAA,IAAI,KAAK,MAAM;AACjB,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,WAAmB,aAA0C;AAC/D,iBAAW,cAAc,OAAO,KAAK,WAAW,GAAG;AAC3C,cAAA,SAAS,YAAY,UAAU;AAC/B,cAAA,MAAM,aAAa,YAAY,SAAS;AAE1C,YAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,UAAU,GAAG,+BAA+B;AAAA,QAC9D;AAES,iBAAA,IAAI,KAAK,MAAM;AAAA,MAC1B;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,QAAQ,QAAuC,eAA+B;AAC5E,YAAM,EAAE,YAAY,YAAY,iBAAiB,CAAA;AAEjD,aAAO,UAAU,MAAM,EAAE,IAAI,CAAC,iBAAiB;AACtC,eAAA;AAAA,UACL,SAAS,eAAe,cAAc,EAAE,YAAY,SAAS;AAAA,UAC7D,QAAS,OAAO,iBAAiB,YAAY,aAAa,UAAW,CAAC;AAAA,QAAA;AAAA,MACxE,CACD;AAAA,IACH;AAAA,EAAA;AAEJ;"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
const
|
2
|
+
const fp = require("lodash/fp");
|
3
3
|
const namespace = require("./namespace.js");
|
4
4
|
const servicesRegistry = (strapi) => {
|
5
5
|
const services = {};
|
@@ -28,7 +28,7 @@ const servicesRegistry = (strapi) => {
|
|
28
28
|
* Returns a map with all the services in a namespace
|
29
29
|
*/
|
30
30
|
getAll(namespace$1) {
|
31
|
-
const filteredServices =
|
31
|
+
const filteredServices = fp.pickBy((_, uid) => namespace.hasNamespace(uid, namespace$1))(services);
|
32
32
|
const map = {};
|
33
33
|
for (const uid of Object.keys(filteredServices)) {
|
34
34
|
Object.defineProperty(map, uid, {
|
@@ -55,7 +55,7 @@ const servicesRegistry = (strapi) => {
|
|
55
55
|
for (const serviceName of Object.keys(newServices)) {
|
56
56
|
const service = newServices[serviceName];
|
57
57
|
const uid = namespace.addNamespace(serviceName, namespace$1);
|
58
|
-
if (
|
58
|
+
if (fp.has(uid, services)) {
|
59
59
|
throw new Error(`Service ${uid} has already been registered.`);
|
60
60
|
}
|
61
61
|
services[uid] = service;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"services.js","sources":["../../src/registries/services.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nexport type ServiceFactory = (params: { strapi: Core.Strapi }) => Core.Service | Core.Service;\nexport type ServiceFactoryMap = Record<string, ServiceFactory>;\nexport type ServiceMap = Record<string, Core.Service>;\nexport type ServiceExtendFn = (service: Core.Service) => Core.Service;\n\nconst servicesRegistry = (strapi: Core.Strapi) => {\n const services: ServiceFactoryMap = {};\n const instantiatedServices: ServiceMap = {};\n\n return {\n /**\n * Returns this list of registered services uids\n */\n keys() {\n return Object.keys(services);\n },\n\n /**\n * Returns the instance of a service. Instantiate the service if not already done\n */\n get(uid: UID.Service) {\n if (instantiatedServices[uid]) {\n return instantiatedServices[uid];\n }\n\n const service = services[uid];\n if (service) {\n instantiatedServices[uid] = typeof service === 'function' ? service({ strapi }) : service;\n return instantiatedServices[uid];\n }\n },\n\n /**\n * Returns a map with all the services in a namespace\n */\n getAll(namespace: string): ServiceMap {\n const filteredServices = pickBy((_, uid) => hasNamespace(uid, namespace))(services);\n\n // create lazy accessor to avoid instantiating the services;\n const map = {};\n for (const uid of Object.keys(filteredServices)) {\n Object.defineProperty(map, uid, {\n enumerable: true,\n get: () => {\n return this.get(uid as UID.Service);\n },\n });\n }\n\n return map;\n },\n\n /**\n * Registers a service\n */\n set(uid: string, service: ServiceFactory) {\n services[uid] = service;\n delete instantiatedServices[uid];\n return this;\n },\n\n /**\n * Registers a map of services for a specific namespace\n */\n add(namespace: string, newServices: ServiceFactoryMap) {\n for (const serviceName of Object.keys(newServices)) {\n const service = newServices[serviceName];\n const uid = addNamespace(serviceName, namespace);\n\n if (has(uid, services)) {\n throw new Error(`Service ${uid} has already been registered.`);\n }\n services[uid] = service;\n }\n\n return this;\n },\n\n /**\n * Wraps a service to extend it\n */\n extend(uid: UID.Service, extendFn: ServiceExtendFn) {\n const currentService = this.get(uid);\n\n if (!currentService) {\n throw new Error(`Service ${uid} doesn't exist`);\n }\n\n const newService = extendFn(currentService);\n instantiatedServices[uid] = newService;\n\n return this;\n },\n };\n};\n\nexport default servicesRegistry;\n"],"names":["namespace","pickBy","
|
1
|
+
{"version":3,"file":"services.js","sources":["../../src/registries/services.ts"],"sourcesContent":["import { pickBy, has } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { addNamespace, hasNamespace } from './namespace';\n\nexport type ServiceFactory = (params: { strapi: Core.Strapi }) => Core.Service | Core.Service;\nexport type ServiceFactoryMap = Record<string, ServiceFactory>;\nexport type ServiceMap = Record<string, Core.Service>;\nexport type ServiceExtendFn = (service: Core.Service) => Core.Service;\n\nconst servicesRegistry = (strapi: Core.Strapi) => {\n const services: ServiceFactoryMap = {};\n const instantiatedServices: ServiceMap = {};\n\n return {\n /**\n * Returns this list of registered services uids\n */\n keys() {\n return Object.keys(services);\n },\n\n /**\n * Returns the instance of a service. Instantiate the service if not already done\n */\n get(uid: UID.Service) {\n if (instantiatedServices[uid]) {\n return instantiatedServices[uid];\n }\n\n const service = services[uid];\n if (service) {\n instantiatedServices[uid] = typeof service === 'function' ? service({ strapi }) : service;\n return instantiatedServices[uid];\n }\n },\n\n /**\n * Returns a map with all the services in a namespace\n */\n getAll(namespace: string): ServiceMap {\n const filteredServices = pickBy((_, uid) => hasNamespace(uid, namespace))(services);\n\n // create lazy accessor to avoid instantiating the services;\n const map = {};\n for (const uid of Object.keys(filteredServices)) {\n Object.defineProperty(map, uid, {\n enumerable: true,\n get: () => {\n return this.get(uid as UID.Service);\n },\n });\n }\n\n return map;\n },\n\n /**\n * Registers a service\n */\n set(uid: string, service: ServiceFactory) {\n services[uid] = service;\n delete instantiatedServices[uid];\n return this;\n },\n\n /**\n * Registers a map of services for a specific namespace\n */\n add(namespace: string, newServices: ServiceFactoryMap) {\n for (const serviceName of Object.keys(newServices)) {\n const service = newServices[serviceName];\n const uid = addNamespace(serviceName, namespace);\n\n if (has(uid, services)) {\n throw new Error(`Service ${uid} has already been registered.`);\n }\n services[uid] = service;\n }\n\n return this;\n },\n\n /**\n * Wraps a service to extend it\n */\n extend(uid: UID.Service, extendFn: ServiceExtendFn) {\n const currentService = this.get(uid);\n\n if (!currentService) {\n throw new Error(`Service ${uid} doesn't exist`);\n }\n\n const newService = extendFn(currentService);\n instantiatedServices[uid] = newService;\n\n return this;\n },\n };\n};\n\nexport default servicesRegistry;\n"],"names":["namespace","pickBy","hasNamespace","addNamespace","has"],"mappings":";;;AASM,MAAA,mBAAmB,CAAC,WAAwB;AAChD,QAAM,WAA8B,CAAA;AACpC,QAAM,uBAAmC,CAAA;AAElC,SAAA;AAAA;AAAA;AAAA;AAAA,IAIL,OAAO;AACE,aAAA,OAAO,KAAK,QAAQ;AAAA,IAC7B;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAkB;AAChB,UAAA,qBAAqB,GAAG,GAAG;AAC7B,eAAO,qBAAqB,GAAG;AAAA,MACjC;AAEM,YAAA,UAAU,SAAS,GAAG;AAC5B,UAAI,SAAS;AACU,6BAAA,GAAG,IAAI,OAAO,YAAY,aAAa,QAAQ,EAAE,QAAQ,IAAI;AAClF,eAAO,qBAAqB,GAAG;AAAA,MACjC;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,OAAOA,aAA+B;AAC9B,YAAA,mBAAmBC,GAAAA,OAAO,CAAC,GAAG,QAAQC,uBAAa,KAAKF,WAAS,CAAC,EAAE,QAAQ;AAGlF,YAAM,MAAM,CAAA;AACZ,iBAAW,OAAO,OAAO,KAAK,gBAAgB,GAAG;AACxC,eAAA,eAAe,KAAK,KAAK;AAAA,UAC9B,YAAY;AAAA,UACZ,KAAK,MAAM;AACF,mBAAA,KAAK,IAAI,GAAkB;AAAA,UACpC;AAAA,QAAA,CACD;AAAA,MACH;AAEO,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,KAAa,SAAyB;AACxC,eAAS,GAAG,IAAI;AAChB,aAAO,qBAAqB,GAAG;AACxB,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,IAAIA,aAAmB,aAAgC;AACrD,iBAAW,eAAe,OAAO,KAAK,WAAW,GAAG;AAC5C,cAAA,UAAU,YAAY,WAAW;AACjC,cAAA,MAAMG,UAAAA,aAAa,aAAaH,WAAS;AAE3C,YAAAI,GAAA,IAAI,KAAK,QAAQ,GAAG;AACtB,gBAAM,IAAI,MAAM,WAAW,GAAG,+BAA+B;AAAA,QAC/D;AACA,iBAAS,GAAG,IAAI;AAAA,MAClB;AAEO,aAAA;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,OAAO,KAAkB,UAA2B;AAC5C,YAAA,iBAAiB,KAAK,IAAI,GAAG;AAEnC,UAAI,CAAC,gBAAgB;AACnB,cAAM,IAAI,MAAM,WAAW,GAAG,gBAAgB;AAAA,MAChD;AAEM,YAAA,aAAa,SAAS,cAAc;AAC1C,2BAAqB,GAAG,IAAI;AAErB,aAAA;AAAA,IACT;AAAA,EAAA;AAEJ;;"}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
const assert = require("assert/strict");
|
3
|
-
const
|
3
|
+
const fp = require("lodash/fp");
|
4
4
|
const strapiUtils = require("@strapi/utils");
|
5
5
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
6
6
|
const assert__default = /* @__PURE__ */ _interopDefault(assert);
|
7
7
|
const INVALID_STRATEGY_MSG = "Invalid auth strategy. Expecting an object with properties {name: string, authenticate: function, verify: function}";
|
8
8
|
const validStrategy = (strategy) => {
|
9
|
-
assert__default.default(
|
9
|
+
assert__default.default(fp.has("authenticate", strategy), INVALID_STRATEGY_MSG);
|
10
10
|
assert__default.default(typeof strategy.authenticate === "function", INVALID_STRATEGY_MSG);
|
11
|
-
if (
|
11
|
+
if (fp.has("verify", strategy)) {
|
12
12
|
assert__default.default(typeof strategy.verify === "function", INVALID_STRATEGY_MSG);
|
13
13
|
}
|
14
14
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/services/auth/index.ts"],"sourcesContent":["import assert from 'assert/strict';\nimport { has } from 'lodash/fp';\n\nimport { errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport type { ParameterizedContext } from 'koa';\n\ninterface AuthenticationResponse {\n authenticated?: boolean;\n credentials?: unknown;\n ability?: unknown;\n error?: Error | null;\n}\n\ninterface AuthenticationInfo {\n strategy: Strategy;\n credentials: unknown;\n ability: unknown;\n}\n\ninterface Strategy {\n name: string;\n authenticate: (ctx: ParameterizedContext) => Promise<AuthenticationResponse>;\n verify?: (auth: AuthenticationInfo, config: Core.RouteConfig['auth']) => Promise<any>;\n}\n\ninterface Authentication {\n register: (type: string, strategy: Strategy) => Authentication;\n authenticate: Core.MiddlewareHandler;\n verify: (auth: AuthenticationInfo, config?: Core.RouteConfig['auth']) => Promise<any>;\n}\n\nconst INVALID_STRATEGY_MSG =\n 'Invalid auth strategy. Expecting an object with properties {name: string, authenticate: function, verify: function}';\n\nconst validStrategy = (strategy: Strategy) => {\n assert(has('authenticate', strategy), INVALID_STRATEGY_MSG);\n assert(typeof strategy.authenticate === 'function', INVALID_STRATEGY_MSG);\n\n if (has('verify', strategy)) {\n assert(typeof strategy.verify === 'function', INVALID_STRATEGY_MSG);\n }\n};\n\nconst createAuthentication = (): Authentication => {\n const strategies: Record<string, Strategy[]> = {};\n\n return {\n register(type, strategy) {\n validStrategy(strategy);\n\n if (!strategies[type]) {\n strategies[type] = [];\n }\n\n strategies[type].push(strategy);\n\n return this;\n },\n\n async authenticate(ctx, next) {\n const route: Core.Route = ctx.state.route;\n\n // use route strategy\n const config = route?.config?.auth;\n\n if (config === false) {\n return next();\n }\n\n const routeStrategies = route.info.type ? strategies[route.info.type] : [];\n const configStrategies = (config?.strategies ?? routeStrategies ?? []) as Array<\n string | Strategy\n >;\n\n const strategiesToUse: Strategy[] = configStrategies.reduce(\n (acc, strategy: string | Strategy) => {\n // Resolve by strategy name\n if (typeof strategy === 'string') {\n const routeStrategy = routeStrategies.find((rs) => rs.name === strategy);\n\n if (routeStrategy) {\n acc.push(routeStrategy);\n }\n }\n\n // Use the given strategy as is\n else if (typeof strategy === 'object') {\n validStrategy(strategy);\n\n acc.push(strategy);\n }\n\n return acc;\n },\n [] as Strategy[]\n );\n\n for (const strategy of strategiesToUse) {\n const result = await strategy.authenticate(ctx);\n\n const { authenticated = false, credentials, ability = null, error = null } = result || {};\n\n if (error !== null) {\n return ctx.unauthorized(error);\n }\n\n if (authenticated) {\n ctx.state.isAuthenticated = true;\n ctx.state.auth = {\n strategy,\n credentials,\n ability,\n };\n\n return next();\n }\n }\n\n return ctx.unauthorized('Missing or invalid credentials');\n },\n\n async verify(auth, config = {}) {\n if (config === false) {\n return;\n }\n\n if (!auth) {\n throw new errors.UnauthorizedError();\n }\n\n if (typeof auth.strategy.verify === 'function') {\n return auth.strategy.verify(auth, config);\n }\n },\n };\n};\n\nexport default createAuthentication;\n"],"names":["assert","has","errors"],"mappings":";;;;;;AAgCA,MAAM,uBACJ;AAEF,MAAM,gBAAgB,CAAC,aAAuB;AAC5CA,kBAAAA,QAAOC,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/services/auth/index.ts"],"sourcesContent":["import assert from 'assert/strict';\nimport { has } from 'lodash/fp';\n\nimport { errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\nimport type { ParameterizedContext } from 'koa';\n\ninterface AuthenticationResponse {\n authenticated?: boolean;\n credentials?: unknown;\n ability?: unknown;\n error?: Error | null;\n}\n\ninterface AuthenticationInfo {\n strategy: Strategy;\n credentials: unknown;\n ability: unknown;\n}\n\ninterface Strategy {\n name: string;\n authenticate: (ctx: ParameterizedContext) => Promise<AuthenticationResponse>;\n verify?: (auth: AuthenticationInfo, config: Core.RouteConfig['auth']) => Promise<any>;\n}\n\ninterface Authentication {\n register: (type: string, strategy: Strategy) => Authentication;\n authenticate: Core.MiddlewareHandler;\n verify: (auth: AuthenticationInfo, config?: Core.RouteConfig['auth']) => Promise<any>;\n}\n\nconst INVALID_STRATEGY_MSG =\n 'Invalid auth strategy. Expecting an object with properties {name: string, authenticate: function, verify: function}';\n\nconst validStrategy = (strategy: Strategy) => {\n assert(has('authenticate', strategy), INVALID_STRATEGY_MSG);\n assert(typeof strategy.authenticate === 'function', INVALID_STRATEGY_MSG);\n\n if (has('verify', strategy)) {\n assert(typeof strategy.verify === 'function', INVALID_STRATEGY_MSG);\n }\n};\n\nconst createAuthentication = (): Authentication => {\n const strategies: Record<string, Strategy[]> = {};\n\n return {\n register(type, strategy) {\n validStrategy(strategy);\n\n if (!strategies[type]) {\n strategies[type] = [];\n }\n\n strategies[type].push(strategy);\n\n return this;\n },\n\n async authenticate(ctx, next) {\n const route: Core.Route = ctx.state.route;\n\n // use route strategy\n const config = route?.config?.auth;\n\n if (config === false) {\n return next();\n }\n\n const routeStrategies = route.info.type ? strategies[route.info.type] : [];\n const configStrategies = (config?.strategies ?? routeStrategies ?? []) as Array<\n string | Strategy\n >;\n\n const strategiesToUse: Strategy[] = configStrategies.reduce(\n (acc, strategy: string | Strategy) => {\n // Resolve by strategy name\n if (typeof strategy === 'string') {\n const routeStrategy = routeStrategies.find((rs) => rs.name === strategy);\n\n if (routeStrategy) {\n acc.push(routeStrategy);\n }\n }\n\n // Use the given strategy as is\n else if (typeof strategy === 'object') {\n validStrategy(strategy);\n\n acc.push(strategy);\n }\n\n return acc;\n },\n [] as Strategy[]\n );\n\n for (const strategy of strategiesToUse) {\n const result = await strategy.authenticate(ctx);\n\n const { authenticated = false, credentials, ability = null, error = null } = result || {};\n\n if (error !== null) {\n return ctx.unauthorized(error);\n }\n\n if (authenticated) {\n ctx.state.isAuthenticated = true;\n ctx.state.auth = {\n strategy,\n credentials,\n ability,\n };\n\n return next();\n }\n }\n\n return ctx.unauthorized('Missing or invalid credentials');\n },\n\n async verify(auth, config = {}) {\n if (config === false) {\n return;\n }\n\n if (!auth) {\n throw new errors.UnauthorizedError();\n }\n\n if (typeof auth.strategy.verify === 'function') {\n return auth.strategy.verify(auth, config);\n }\n },\n };\n};\n\nexport default createAuthentication;\n"],"names":["assert","has","errors"],"mappings":";;;;;;AAgCA,MAAM,uBACJ;AAEF,MAAM,gBAAgB,CAAC,aAAuB;AAC5CA,kBAAAA,QAAOC,GAAAA,IAAI,gBAAgB,QAAQ,GAAG,oBAAoB;AAC1DD,kBAAAA,QAAO,OAAO,SAAS,iBAAiB,YAAY,oBAAoB;AAEpE,MAAAC,GAAA,IAAI,UAAU,QAAQ,GAAG;AAC3BD,oBAAAA,QAAO,OAAO,SAAS,WAAW,YAAY,oBAAoB;AAAA,EACpE;AACF;AAEA,MAAM,uBAAuB,MAAsB;AACjD,QAAM,aAAyC,CAAA;AAExC,SAAA;AAAA,IACL,SAAS,MAAM,UAAU;AACvB,oBAAc,QAAQ;AAElB,UAAA,CAAC,WAAW,IAAI,GAAG;AACV,mBAAA,IAAI,IAAI;MACrB;AAEW,iBAAA,IAAI,EAAE,KAAK,QAAQ;AAEvB,aAAA;AAAA,IACT;AAAA,IAEA,MAAM,aAAa,KAAK,MAAM;AACtB,YAAA,QAAoB,IAAI,MAAM;AAG9B,YAAA,SAAS,OAAO,QAAQ;AAE9B,UAAI,WAAW,OAAO;AACpB,eAAO,KAAK;AAAA,MACd;AAEM,YAAA,kBAAkB,MAAM,KAAK,OAAO,WAAW,MAAM,KAAK,IAAI,IAAI;AACxE,YAAM,mBAAoB,QAAQ,cAAc,mBAAmB,CAAA;AAInE,YAAM,kBAA8B,iBAAiB;AAAA,QACnD,CAAC,KAAK,aAAgC;AAEhC,cAAA,OAAO,aAAa,UAAU;AAChC,kBAAM,gBAAgB,gBAAgB,KAAK,CAAC,OAAO,GAAG,SAAS,QAAQ;AAEvE,gBAAI,eAAe;AACjB,kBAAI,KAAK,aAAa;AAAA,YACxB;AAAA,UAAA,WAIO,OAAO,aAAa,UAAU;AACrC,0BAAc,QAAQ;AAEtB,gBAAI,KAAK,QAAQ;AAAA,UACnB;AAEO,iBAAA;AAAA,QACT;AAAA,QACA,CAAC;AAAA,MAAA;AAGH,iBAAW,YAAY,iBAAiB;AACtC,cAAM,SAAS,MAAM,SAAS,aAAa,GAAG;AAExC,cAAA,EAAE,gBAAgB,OAAO,aAAa,UAAU,MAAM,QAAQ,KAAA,IAAS,UAAU;AAEvF,YAAI,UAAU,MAAM;AACX,iBAAA,IAAI,aAAa,KAAK;AAAA,QAC/B;AAEA,YAAI,eAAe;AACjB,cAAI,MAAM,kBAAkB;AAC5B,cAAI,MAAM,OAAO;AAAA,YACf;AAAA,YACA;AAAA,YACA;AAAA,UAAA;AAGF,iBAAO,KAAK;AAAA,QACd;AAAA,MACF;AAEO,aAAA,IAAI,aAAa,gCAAgC;AAAA,IAC1D;AAAA,IAEA,MAAM,OAAO,MAAM,SAAS,IAAI;AAC9B,UAAI,WAAW,OAAO;AACpB;AAAA,MACF;AAEA,UAAI,CAAC,MAAM;AACH,cAAA,IAAIE,YAAAA,OAAO;MACnB;AAEA,UAAI,OAAO,KAAK,SAAS,WAAW,YAAY;AAC9C,eAAO,KAAK,SAAS,OAAO,MAAM,MAAM;AAAA,MAC1C;AAAA,IACF;AAAA,EAAA;AAEJ;;"}
|