@strapi/core 0.0.0-experimental.80cf2c74a2003f3c0602abc81888dd9f36dc68a3 → 0.0.0-experimental.9034cc03ac5cf73cd9dcb2ff7c6cadece3f6910d
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.
Potentially problematic release.
This version of @strapi/core might be problematic. Click here for more details.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +6 -2
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +6 -2
- package/dist/Strapi.mjs.map +1 -1
- package/dist/core-api/controller/index.js +5 -5
- package/dist/core-api/controller/index.js.map +1 -1
- package/dist/core-api/controller/index.mjs +6 -6
- package/dist/core-api/controller/index.mjs.map +1 -1
- package/dist/registries/policies.d.ts +22 -10
- package/dist/registries/policies.d.ts.map +1 -1
- package/dist/registries/policies.js +64 -18
- package/dist/registries/policies.js.map +1 -1
- package/dist/registries/policies.mjs +65 -19
- package/dist/registries/policies.mjs.map +1 -1
- package/dist/services/content-api/index.d.ts +18 -0
- package/dist/services/content-api/index.d.ts.map +1 -1
- package/dist/services/content-api/index.js +27 -1
- package/dist/services/content-api/index.js.map +1 -1
- package/dist/services/content-api/index.mjs +27 -1
- package/dist/services/content-api/index.mjs.map +1 -1
- package/dist/services/document-service/index.d.ts.map +1 -1
- package/dist/services/document-service/index.js +4 -0
- package/dist/services/document-service/index.js.map +1 -1
- package/dist/services/document-service/index.mjs +4 -0
- package/dist/services/document-service/index.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +12 -2
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +13 -3
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/populate.js +1 -1
- package/dist/services/document-service/transform/populate.js.map +1 -1
- package/dist/services/document-service/transform/populate.mjs +1 -1
- package/dist/services/document-service/transform/populate.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/extract/data-ids.d.ts.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/extract/data-ids.mjs +2 -2
- package/dist/services/document-service/transform/relations/extract/data-ids.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs +1 -1
- package/dist/services/document-service/transform/relations/transform/data-ids.mjs.map +1 -1
- package/dist/services/entity-service/components.d.ts.map +1 -1
- package/dist/services/entity-service/components.js +1 -4
- package/dist/services/entity-service/components.js.map +1 -1
- package/dist/services/entity-service/components.mjs +1 -4
- package/dist/services/entity-service/components.mjs.map +1 -1
- package/dist/services/entity-service/index.d.ts.map +1 -1
- package/dist/services/entity-service/index.js +14 -15
- package/dist/services/entity-service/index.js.map +1 -1
- package/dist/services/entity-service/index.mjs +15 -16
- package/dist/services/entity-service/index.mjs.map +1 -1
- package/dist/services/query-params.d.ts +7 -0
- package/dist/services/query-params.d.ts.map +1 -0
- package/dist/services/query-params.js +12 -0
- package/dist/services/query-params.js.map +1 -0
- package/dist/services/query-params.mjs +13 -0
- package/dist/services/query-params.mjs.map +1 -0
- package/dist/services/server/compose-endpoint.d.ts.map +1 -1
- package/dist/services/server/compose-endpoint.js +1 -2
- package/dist/services/server/compose-endpoint.js.map +1 -1
- package/dist/services/server/compose-endpoint.mjs +2 -3
- package/dist/services/server/compose-endpoint.mjs.map +1 -1
- package/dist/services/server/policy.d.ts +2 -2
- package/dist/services/server/policy.d.ts.map +1 -1
- package/dist/services/server/policy.js +4 -4
- package/dist/services/server/policy.js.map +1 -1
- package/dist/services/server/policy.mjs +4 -4
- package/dist/services/server/policy.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.d.ts +15 -15
- package/dist/utils/transform-content-types-to-models.d.ts.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +77 -85
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +77 -85
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +14 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-params.mjs","sources":["../../src/services/query-params.ts"],"sourcesContent":["import { queryParams } from '@strapi/utils';\nimport type { Core, UID } from '@strapi/types';\n\nexport default (strapi: Core.Strapi) => {\n const { transformQueryParams } = queryParams.createTransformer({\n getModel: (uid: string) => strapi.getModel(uid as UID.Schema),\n });\n\n return {\n transform: transformQueryParams,\n };\n};\n"],"names":[],"mappings":";AAGA,MAAe,0BAAA,CAAC,WAAwB;AACtC,QAAM,EAAE,qBAAA,IAAyB,YAAY,kBAAkB;AAAA,IAC7D,UAAU,CAAC,QAAgB,OAAO,SAAS,GAAiB;AAAA,EAAA,CAC7D;AAEM,SAAA;AAAA,IACL,WAAW;AAAA,EAAA;AAEf;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.d.ts","sourceRoot":"","sources":["../../../src/services/server/compose-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAO,MAAM,eAAe,CAAC;AAE/C,OAAO,MAAM,MAAM,aAAa,CAAC;iCAoET,KAAK,MAAM,aAIlB,KAAK,KAAK;YAAwB,MAAM;;AAJzD,
|
|
1
|
+
{"version":3,"file":"compose-endpoint.d.ts","sourceRoot":"","sources":["../../../src/services/server/compose-endpoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAO,MAAM,eAAe,CAAC;AAE/C,OAAO,MAAM,MAAM,aAAa,CAAC;iCAoET,KAAK,MAAM,aAIlB,KAAK,KAAK;YAAwB,MAAM;;AAJzD,wBAgCE"}
|
|
@@ -55,13 +55,12 @@ const createEndpointComposer = (strapi) => {
|
|
|
55
55
|
const method = getMethod(route);
|
|
56
56
|
const path = getPath(route);
|
|
57
57
|
const middlewares = middleware.resolveRouteMiddlewares(route, strapi);
|
|
58
|
-
const policies = policy.resolvePolicies(route);
|
|
59
58
|
const action = getAction(route, strapi);
|
|
60
59
|
const routeHandler = compose__default.default([
|
|
61
60
|
createRouteInfoMiddleware(route),
|
|
62
61
|
authenticate,
|
|
63
62
|
authorize,
|
|
64
|
-
|
|
63
|
+
policy.createPolicicesMiddleware(route, strapi),
|
|
65
64
|
...middlewares,
|
|
66
65
|
returnBodyMiddleware,
|
|
67
66
|
..._.castArray(action)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport {
|
|
1
|
+
{"version":3,"file":"compose-endpoint.js","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { createPolicicesMiddleware } from './policy';\n\nconst getMethod = (route: Core.Route) => {\n return trim(toLower(route.method)) as Lowercase<Core.Route['method']>;\n};\n\nconst getPath = (route: Core.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Core.Route): Core.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Core.Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Core.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n createPolicicesMiddleware(route, strapi),\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (\n name: string,\n { pluginName, apiName }: Core.RouteInfo,\n strapi: Core.Strapi\n) => {\n let ctrl: Core.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Core.Route, strapi: Core.Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":["trim","toLower","prop","errors","isNil","resolveRouteMiddlewares","compose","createPolicicesMiddleware","castArray"],"mappings":";;;;;;;;AASA,MAAM,YAAY,CAAC,UAAsB;AACvC,SAAOA,EAAK,KAAAC,EAAA,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAsBD,EAAA,KAAK,MAAM,IAAI;AAEtD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgBE,EAAAA,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAEtB,QAAA,cAAc,OAAO,IAAI,MAAM;AAEjC,MAAA;AACF,UAAM,YAAY,OAAO,MAAM,cAAc,KAAK,CAAC;AAEnD,WAAO,MAAM,KAAK;AAAA,WACX,OAAO;AACV,QAAA,iBAAiBC,mBAAO,mBAAmB;AAC7C,aAAO,IAAI;IACb;AAEI,QAAA,iBAAiBA,mBAA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il } from "lodash/fp";
|
|
|
2
2
|
import { errors } from "@strapi/utils";
|
|
3
3
|
import compose from "koa-compose";
|
|
4
4
|
import { resolveRouteMiddlewares } from "./middleware.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { createPolicicesMiddleware } from "./policy.mjs";
|
|
6
6
|
const getMethod = (route) => {
|
|
7
7
|
return trim(toLower(route.method));
|
|
8
8
|
};
|
|
@@ -52,13 +52,12 @@ const createEndpointComposer = (strapi) => {
|
|
|
52
52
|
const method = getMethod(route);
|
|
53
53
|
const path = getPath(route);
|
|
54
54
|
const middlewares = resolveRouteMiddlewares(route, strapi);
|
|
55
|
-
const policies = resolvePolicies(route);
|
|
56
55
|
const action = getAction(route, strapi);
|
|
57
56
|
const routeHandler = compose([
|
|
58
57
|
createRouteInfoMiddleware(route),
|
|
59
58
|
authenticate,
|
|
60
59
|
authorize,
|
|
61
|
-
|
|
60
|
+
createPolicicesMiddleware(route, strapi),
|
|
62
61
|
...middlewares,
|
|
63
62
|
returnBodyMiddleware,
|
|
64
63
|
...castArray(action)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose-endpoint.mjs","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport {
|
|
1
|
+
{"version":3,"file":"compose-endpoint.mjs","sources":["../../../src/services/server/compose-endpoint.ts"],"sourcesContent":["import { toLower, castArray, trim, prop, isNil } from 'lodash/fp';\nimport type { Core, UID } from '@strapi/types';\nimport { errors } from '@strapi/utils';\nimport Router from '@koa/router';\n\nimport compose from 'koa-compose';\nimport { resolveRouteMiddlewares } from './middleware';\nimport { createPolicicesMiddleware } from './policy';\n\nconst getMethod = (route: Core.Route) => {\n return trim(toLower(route.method)) as Lowercase<Core.Route['method']>;\n};\n\nconst getPath = (route: Core.Route) => trim(route.path);\n\nconst createRouteInfoMiddleware =\n (routeInfo: Core.Route): Core.MiddlewareHandler =>\n (ctx, next) => {\n const route = {\n ...routeInfo,\n config: routeInfo.config || {},\n };\n\n ctx.state.route = route;\n return next();\n };\n\nconst getAuthConfig = prop('config.auth');\n\nconst createAuthorizeMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n const { auth, route } = ctx.state;\n\n const authService = strapi.get('auth');\n\n try {\n await authService.verify(auth, getAuthConfig(route));\n\n return await next();\n } catch (error) {\n if (error instanceof errors.UnauthorizedError) {\n return ctx.unauthorized();\n }\n\n if (error instanceof errors.ForbiddenError) {\n // allow PolicyError as an exception to throw a publicly visible message in the API\n if (error instanceof errors.PolicyError) {\n throw error;\n }\n return ctx.forbidden();\n }\n\n throw error;\n }\n };\n\nconst createAuthenticateMiddleware =\n (strapi: Core.Strapi): Core.MiddlewareHandler =>\n async (ctx, next) => {\n return strapi.get('auth').authenticate(ctx, next);\n };\n\nconst returnBodyMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const values = await next();\n\n if (isNil(ctx.body) && !isNil(values)) {\n ctx.body = values;\n }\n};\n\nexport default (strapi: Core.Strapi) => {\n const authenticate = createAuthenticateMiddleware(strapi);\n const authorize = createAuthorizeMiddleware(strapi);\n\n return (route: Core.Route, { router }: { router: Router }) => {\n try {\n const method = getMethod(route);\n const path = getPath(route);\n\n const middlewares = resolveRouteMiddlewares(route, strapi);\n\n const action = getAction(route, strapi);\n\n const routeHandler = compose([\n createRouteInfoMiddleware(route),\n authenticate,\n authorize,\n createPolicicesMiddleware(route, strapi),\n ...middlewares,\n returnBodyMiddleware,\n ...castArray(action),\n ]);\n\n router[method](path, routeHandler);\n } catch (error) {\n if (error instanceof Error) {\n error.message = `Error creating endpoint ${route.method} ${route.path}: ${error.message}`;\n }\n\n throw error;\n }\n };\n};\n\nconst getController = (\n name: string,\n { pluginName, apiName }: Core.RouteInfo,\n strapi: Core.Strapi\n) => {\n let ctrl: Core.Controller | undefined;\n\n if (pluginName) {\n if (pluginName === 'admin') {\n ctrl = strapi.controller(`admin::${name}`);\n } else {\n ctrl = strapi.plugin(pluginName).controller(name);\n }\n } else if (apiName) {\n ctrl = strapi.controller(`api::${apiName}.${name}`);\n }\n\n if (!ctrl) {\n return strapi.controller(name as UID.Controller);\n }\n\n return ctrl;\n};\n\nconst extractHandlerParts = (name: string) => {\n const controllerName = name.slice(0, name.lastIndexOf('.'));\n const actionName = name.slice(name.lastIndexOf('.') + 1);\n\n return { controllerName, actionName };\n};\n\nconst getAction = (route: Core.Route, strapi: Core.Strapi) => {\n const { handler, info } = route;\n const { pluginName, apiName, type } = info ?? {};\n\n if (Array.isArray(handler) || typeof handler === 'function') {\n return handler;\n }\n\n const { controllerName, actionName } = extractHandlerParts(trim(handler));\n\n const controller = getController(controllerName, { pluginName, apiName, type }, strapi);\n\n if (typeof controller[actionName] !== 'function') {\n throw new Error(`Handler not found \"${handler}\"`);\n }\n\n if (Symbol.for('__type__') in controller[actionName]) {\n (controller[actionName] as any)[Symbol.for('__type__')].push(type);\n } else {\n (controller[actionName] as any)[Symbol.for('__type__')] = [type];\n }\n\n return controller[actionName].bind(controller);\n};\n"],"names":[],"mappings":";;;;;AASA,MAAM,YAAY,CAAC,UAAsB;AACvC,SAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;AACnC;AAEA,MAAM,UAAU,CAAC,UAAsB,KAAK,MAAM,IAAI;AAEtD,MAAM,4BACJ,CAAC,cACD,CAAC,KAAK,SAAS;AACb,QAAM,QAAQ;AAAA,IACZ,GAAG;AAAA,IACH,QAAQ,UAAU,UAAU,CAAC;AAAA,EAAA;AAG/B,MAAI,MAAM,QAAQ;AAClB,SAAO,KAAK;AACd;AAEF,MAAM,gBAAgB,KAAK,aAAa;AAExC,MAAM,4BACJ,CAAC,WACD,OAAO,KAAK,SAAS;AACnB,QAAM,EAAE,MAAM,UAAU,IAAI;AAE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AAU,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI;AAAA,EACjE;AAEA,SAAO,WAAW,UAAU,EAAE,KAAK,UAAU;AAC/C;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Core } from '@strapi/types';
|
|
2
|
-
declare const
|
|
3
|
-
export {
|
|
2
|
+
declare const createPolicicesMiddleware: (route: Core.Route, strapi: Core.Strapi) => Core.MiddlewareHandler;
|
|
3
|
+
export { createPolicicesMiddleware };
|
|
4
4
|
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/services/server/policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,QAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../../src/services/server/policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,QAAA,MAAM,yBAAyB,UAAW,KAAK,KAAK,UAAU,KAAK,MAAM,2BAmBxE,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const strapiUtils = require("@strapi/utils");
|
|
4
|
-
const
|
|
4
|
+
const createPolicicesMiddleware = (route, strapi) => {
|
|
5
5
|
const policiesConfig = route?.config?.policies ?? [];
|
|
6
|
-
const resolvedPolicies =
|
|
6
|
+
const resolvedPolicies = strapi.get("policies").resolve(policiesConfig, route.info);
|
|
7
7
|
const policiesMiddleware = async (ctx, next) => {
|
|
8
8
|
const context = strapiUtils.policy.createPolicyContext("koa", ctx);
|
|
9
9
|
for (const { handler, config } of resolvedPolicies) {
|
|
@@ -14,7 +14,7 @@ const resolvePolicies = (route) => {
|
|
|
14
14
|
}
|
|
15
15
|
await next();
|
|
16
16
|
};
|
|
17
|
-
return
|
|
17
|
+
return policiesMiddleware;
|
|
18
18
|
};
|
|
19
|
-
exports.
|
|
19
|
+
exports.createPolicicesMiddleware = createPolicicesMiddleware;
|
|
20
20
|
//# sourceMappingURL=policy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.js","sources":["../../../src/services/server/policy.ts"],"sourcesContent":["import { policy as policyUtils, errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst
|
|
1
|
+
{"version":3,"file":"policy.js","sources":["../../../src/services/server/policy.ts"],"sourcesContent":["import { policy as policyUtils, errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst createPolicicesMiddleware = (route: Core.Route, strapi: Core.Strapi) => {\n const policiesConfig = route?.config?.policies ?? [];\n const resolvedPolicies = strapi.get('policies').resolve(policiesConfig, route.info);\n\n const policiesMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const context = policyUtils.createPolicyContext('koa', ctx);\n\n for (const { handler, config } of resolvedPolicies) {\n const result = await handler(context, config, { strapi });\n\n if (![true, undefined].includes(result)) {\n throw new errors.PolicyError();\n }\n }\n\n await next();\n };\n\n return policiesMiddleware;\n};\n\nexport { createPolicicesMiddleware };\n"],"names":["policyUtils","errors"],"mappings":";;;AAGM,MAAA,4BAA4B,CAAC,OAAmB,WAAwB;AAC5E,QAAM,iBAAiB,OAAO,QAAQ,YAAY,CAAA;AAC5C,QAAA,mBAAmB,OAAO,IAAI,UAAU,EAAE,QAAQ,gBAAgB,MAAM,IAAI;AAE5E,QAAA,qBAA6C,OAAO,KAAK,SAAS;AACtE,UAAM,UAAUA,YAAA,OAAY,oBAAoB,OAAO,GAAG;AAE1D,eAAW,EAAE,SAAS,OAAO,KAAK,kBAAkB;AAClD,YAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,EAAE,QAAQ;AAExD,UAAI,CAAC,CAAC,MAAM,MAAS,EAAE,SAAS,MAAM,GAAG;AACjC,cAAA,IAAIC,YAAAA,OAAO;MACnB;AAAA,IACF;AAEA,UAAM,KAAK;AAAA,EAAA;AAGN,SAAA;AACT;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { policy, errors } from "@strapi/utils";
|
|
2
|
-
const
|
|
2
|
+
const createPolicicesMiddleware = (route, strapi) => {
|
|
3
3
|
const policiesConfig = route?.config?.policies ?? [];
|
|
4
|
-
const resolvedPolicies =
|
|
4
|
+
const resolvedPolicies = strapi.get("policies").resolve(policiesConfig, route.info);
|
|
5
5
|
const policiesMiddleware = async (ctx, next) => {
|
|
6
6
|
const context = policy.createPolicyContext("koa", ctx);
|
|
7
7
|
for (const { handler, config } of resolvedPolicies) {
|
|
@@ -12,9 +12,9 @@ const resolvePolicies = (route) => {
|
|
|
12
12
|
}
|
|
13
13
|
await next();
|
|
14
14
|
};
|
|
15
|
-
return
|
|
15
|
+
return policiesMiddleware;
|
|
16
16
|
};
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
createPolicicesMiddleware
|
|
19
19
|
};
|
|
20
20
|
//# sourceMappingURL=policy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.mjs","sources":["../../../src/services/server/policy.ts"],"sourcesContent":["import { policy as policyUtils, errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst
|
|
1
|
+
{"version":3,"file":"policy.mjs","sources":["../../../src/services/server/policy.ts"],"sourcesContent":["import { policy as policyUtils, errors } from '@strapi/utils';\nimport type { Core } from '@strapi/types';\n\nconst createPolicicesMiddleware = (route: Core.Route, strapi: Core.Strapi) => {\n const policiesConfig = route?.config?.policies ?? [];\n const resolvedPolicies = strapi.get('policies').resolve(policiesConfig, route.info);\n\n const policiesMiddleware: Core.MiddlewareHandler = async (ctx, next) => {\n const context = policyUtils.createPolicyContext('koa', ctx);\n\n for (const { handler, config } of resolvedPolicies) {\n const result = await handler(context, config, { strapi });\n\n if (![true, undefined].includes(result)) {\n throw new errors.PolicyError();\n }\n }\n\n await next();\n };\n\n return policiesMiddleware;\n};\n\nexport { createPolicicesMiddleware };\n"],"names":["policyUtils"],"mappings":";AAGM,MAAA,4BAA4B,CAAC,OAAmB,WAAwB;AAC5E,QAAM,iBAAiB,OAAO,QAAQ,YAAY,CAAA;AAC5C,QAAA,mBAAmB,OAAO,IAAI,UAAU,EAAE,QAAQ,gBAAgB,MAAM,IAAI;AAE5E,QAAA,qBAA6C,OAAO,KAAK,SAAS;AACtE,UAAM,UAAUA,OAAY,oBAAoB,OAAO,GAAG;AAE1D,eAAW,EAAE,SAAS,OAAO,KAAK,kBAAkB;AAClD,YAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,EAAE,QAAQ;AAExD,UAAI,CAAC,CAAC,MAAM,MAAS,EAAE,SAAS,MAAM,GAAG;AACjC,cAAA,IAAI,OAAO;MACnB;AAAA,IACF;AAEA,UAAM,KAAK;AAAA,EAAA;AAGN,SAAA;AACT;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Model, type
|
|
1
|
+
import { type Model, type Identifiers } from '@strapi/database';
|
|
2
2
|
import type { Struct, Schema } from '@strapi/types';
|
|
3
3
|
import { createId } from '@paralleldrive/cuid2';
|
|
4
4
|
/**
|
|
@@ -13,14 +13,14 @@ import { createId } from '@paralleldrive/cuid2';
|
|
|
13
13
|
* 'collection4f3a_cmps' maps to the unshortened 'collectionname_cmps' rather than 'collectionname_components'
|
|
14
14
|
* Therefore, we only use the identifiers helpers in cases where we do not do any of our own shortening
|
|
15
15
|
*/
|
|
16
|
-
export declare const getComponentJoinTableName: (collectionName: string,
|
|
17
|
-
export declare const getDzJoinTableName: (collectionName: string,
|
|
18
|
-
export declare const getComponentJoinColumnEntityName: (
|
|
19
|
-
export declare const getComponentJoinColumnInverseName: (
|
|
20
|
-
export declare const getComponentTypeColumn: (
|
|
21
|
-
export declare const getComponentFkIndexName: (contentType: string,
|
|
16
|
+
export declare const getComponentJoinTableName: (collectionName: string, identifiers: Identifiers) => string;
|
|
17
|
+
export declare const getDzJoinTableName: (collectionName: string, identifiers: Identifiers) => string;
|
|
18
|
+
export declare const getComponentJoinColumnEntityName: (identifiers: Identifiers) => string;
|
|
19
|
+
export declare const getComponentJoinColumnInverseName: (identifiers: Identifiers) => string;
|
|
20
|
+
export declare const getComponentTypeColumn: (identifiers: Identifiers) => string;
|
|
21
|
+
export declare const getComponentFkIndexName: (contentType: string, identifiers: Identifiers) => string;
|
|
22
22
|
export type LoadedContentTypeModel = Struct.ContentTypeSchema & Required<Pick<Struct.ContentTypeSchema, 'collectionName' | 'uid' | 'modelName'>>;
|
|
23
|
-
export declare const transformAttribute: (name: string, attribute: Schema.Attribute.AnyAttribute, contentType: LoadedContentTypeModel,
|
|
23
|
+
export declare const transformAttribute: (name: string, attribute: Schema.Attribute.AnyAttribute, contentType: LoadedContentTypeModel, identifiers: Identifiers) => (Schema.Attribute.OfType<"biginteger"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"boolean"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<boolean> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"blocks"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"datetime"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateTimeValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"date"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<Schema.Attribute.DateValue> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"decimal"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"email"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.UniqueOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"enumeration"> & Schema.Attribute.EnumerationProperties<string[]> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"float"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"integer"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<number> & Schema.Attribute.MinMaxOption<number> & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.UniqueOption) | (Schema.Attribute.OfType<"json"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.RequiredOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.DefaultOption<import("@strapi/types/dist/utils").JSONPrimitive>) | (Schema.Attribute.OfType<"password"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.DefaultOption<string> & Schema.Attribute.MinMaxLengthOption & Schema.Attribute.PrivateOption & Schema.Attribute.RequiredOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption) | (Schema.Attribute.OfType<"relation"> & Schema.Attribute.ConfigurableOption & Schema.Attribute.PrivateOption & Schema.Attribute.WritableOption & Schema.Attribute.VisibleOption & Schema.Attribute.RequiredOption & {
|
|
24
24
|
useJoinTable?: boolean | undefined;
|
|
25
25
|
} & {
|
|
26
26
|
relation: "morphToOne";
|
|
@@ -74,16 +74,16 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
|
|
|
74
74
|
name: string;
|
|
75
75
|
joinColumn: {
|
|
76
76
|
name: string;
|
|
77
|
-
referencedColumn:
|
|
77
|
+
referencedColumn: "id";
|
|
78
78
|
};
|
|
79
79
|
inverseJoinColumn: {
|
|
80
80
|
name: string;
|
|
81
|
-
referencedColumn:
|
|
81
|
+
referencedColumn: "id";
|
|
82
82
|
};
|
|
83
83
|
on: {
|
|
84
84
|
field: string;
|
|
85
85
|
};
|
|
86
|
-
orderColumnName:
|
|
86
|
+
orderColumnName: "order";
|
|
87
87
|
orderBy: {
|
|
88
88
|
order: string;
|
|
89
89
|
};
|
|
@@ -98,12 +98,12 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
|
|
|
98
98
|
name: string;
|
|
99
99
|
joinColumn: {
|
|
100
100
|
name: string;
|
|
101
|
-
referencedColumn:
|
|
101
|
+
referencedColumn: "id";
|
|
102
102
|
};
|
|
103
103
|
morphColumn: {
|
|
104
104
|
idColumn: {
|
|
105
105
|
name: string;
|
|
106
|
-
referencedColumn:
|
|
106
|
+
referencedColumn: "id";
|
|
107
107
|
};
|
|
108
108
|
typeColumn: {
|
|
109
109
|
name: string;
|
|
@@ -123,10 +123,10 @@ export declare const transformAttribute: (name: string, attribute: Schema.Attrib
|
|
|
123
123
|
target?: undefined;
|
|
124
124
|
morphBy?: undefined;
|
|
125
125
|
};
|
|
126
|
-
export declare const transformAttributes: (contentType: LoadedContentTypeModel,
|
|
126
|
+
export declare const transformAttributes: (contentType: LoadedContentTypeModel, identifiers: Identifiers) => {};
|
|
127
127
|
export declare const hasComponentsOrDz: (contentType: LoadedContentTypeModel) => contentType is Struct.ContentTypeSchema & Required<Pick<Struct.ContentTypeSchema, "uid" | "collectionName" | "modelName">> & {
|
|
128
128
|
type: 'dynamiczone' | 'component';
|
|
129
129
|
};
|
|
130
130
|
export declare const createDocumentId: typeof createId;
|
|
131
|
-
export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[],
|
|
131
|
+
export declare const transformContentTypesToModels: (contentTypes: LoadedContentTypeModel[], identifiers: Identifiers) => Model[];
|
|
132
132
|
//# sourceMappingURL=transform-content-types-to-models.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"transform-content-types-to-models.d.ts","sourceRoot":"","sources":["../../src/utils/transform-content-types-to-models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAIhD;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,yBAAyB,mBAAoB,MAAM,eAAe,WAAW,WAKzF,CAAC;AAEF,eAAO,MAAM,kBAAkB,mBAAoB,MAAM,eAAe,WAAW,WAKlF,CAAC;AAEF,eAAO,MAAM,gCAAgC,gBAAiB,WAAW,WAKxE,CAAC;AAEF,eAAO,MAAM,iCAAiC,gBAAiB,WAAW,WAKzE,CAAC;AAEF,eAAO,MAAM,sBAAsB,gBAAiB,WAAW,WAE9D,CAAC;AAEF,eAAO,MAAM,uBAAuB,gBAAiB,MAAM,eAAe,WAAW,WAMpF,CAAC;AAIF,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,iBAAiB,GAC3D,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,KAAK,GAAG,WAAW,CAAC,CAAC,CAAC;AAGnF,eAAO,MAAM,kBAAkB,SACvB,MAAM,aACD,OAAO,SAAS,CAAC,YAAY,eAC3B,sBAAsB,eACtB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+FzB,CAAC;AAEF,eAAO,MAAM,mBAAmB,gBACjB,sBAAsB,eACtB,WAAW,OAazB,CAAC;AAEF,eAAO,MAAM,iBAAiB,gBACf,sBAAsB;UACc,aAAa,GAAG,WAAW;CAI7E,CAAC;AAEF,eAAO,MAAM,gBAAgB,iBAAW,CAAC;AAgFzC,eAAO,MAAM,6BAA6B,iBAC1B,sBAAsB,EAAE,eACzB,WAAW,KACvB,KAAK,EAiDP,CAAC"}
|
|
@@ -1,64 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const database = require("@strapi/database");
|
|
4
3
|
const cuid2 = require("@paralleldrive/cuid2");
|
|
5
4
|
const assert = require("node:assert");
|
|
6
5
|
const _ = require("lodash/fp");
|
|
7
6
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
7
|
const assert__default = /* @__PURE__ */ _interopDefault(assert);
|
|
9
8
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
{ name: "components", shortName: "cmps", compressible: false }
|
|
16
|
-
],
|
|
17
|
-
options
|
|
18
|
-
);
|
|
9
|
+
const getComponentJoinTableName = (collectionName, identifiers) => {
|
|
10
|
+
return identifiers.getNameFromTokens([
|
|
11
|
+
{ name: collectionName, compressible: true },
|
|
12
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
|
13
|
+
]);
|
|
19
14
|
};
|
|
20
|
-
const getDzJoinTableName = (collectionName,
|
|
21
|
-
return identifiers.getNameFromTokens(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
],
|
|
26
|
-
options
|
|
27
|
-
);
|
|
15
|
+
const getDzJoinTableName = (collectionName, identifiers) => {
|
|
16
|
+
return identifiers.getNameFromTokens([
|
|
17
|
+
{ name: collectionName, compressible: true },
|
|
18
|
+
{ name: "components", shortName: "cmps", compressible: false }
|
|
19
|
+
]);
|
|
28
20
|
};
|
|
29
|
-
const getComponentJoinColumnEntityName = (
|
|
30
|
-
return identifiers.getNameFromTokens(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
],
|
|
35
|
-
options
|
|
36
|
-
);
|
|
21
|
+
const getComponentJoinColumnEntityName = (identifiers) => {
|
|
22
|
+
return identifiers.getNameFromTokens([
|
|
23
|
+
{ name: "entity", compressible: false },
|
|
24
|
+
{ name: "id", compressible: false }
|
|
25
|
+
]);
|
|
37
26
|
};
|
|
38
|
-
const getComponentJoinColumnInverseName = (
|
|
39
|
-
return identifiers.getNameFromTokens(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
options
|
|
45
|
-
);
|
|
27
|
+
const getComponentJoinColumnInverseName = (identifiers) => {
|
|
28
|
+
return identifiers.getNameFromTokens([
|
|
29
|
+
{ name: "component", shortName: "cmp", compressible: false },
|
|
30
|
+
{ name: "id", compressible: false }
|
|
31
|
+
]);
|
|
46
32
|
};
|
|
47
|
-
const getComponentTypeColumn = (
|
|
48
|
-
return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]
|
|
33
|
+
const getComponentTypeColumn = (identifiers) => {
|
|
34
|
+
return identifiers.getNameFromTokens([{ name: "component_type", compressible: false }]);
|
|
49
35
|
};
|
|
50
|
-
const getComponentFkIndexName = (contentType,
|
|
51
|
-
return identifiers.getNameFromTokens(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
],
|
|
57
|
-
options
|
|
58
|
-
);
|
|
36
|
+
const getComponentFkIndexName = (contentType, identifiers) => {
|
|
37
|
+
return identifiers.getNameFromTokens([
|
|
38
|
+
{ name: contentType, compressible: true },
|
|
39
|
+
{ name: "entity", compressible: false },
|
|
40
|
+
{ name: "fk", compressible: false }
|
|
41
|
+
]);
|
|
59
42
|
};
|
|
60
|
-
const
|
|
61
|
-
const transformAttribute = (name, attribute, contentType, options) => {
|
|
43
|
+
const transformAttribute = (name, attribute, contentType, identifiers) => {
|
|
62
44
|
switch (attribute.type) {
|
|
63
45
|
case "media": {
|
|
64
46
|
return {
|
|
@@ -69,10 +51,10 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
69
51
|
};
|
|
70
52
|
}
|
|
71
53
|
case "component": {
|
|
72
|
-
const joinTableName = getComponentJoinTableName(contentType.collectionName,
|
|
73
|
-
const joinColumnEntityName = getComponentJoinColumnEntityName(
|
|
74
|
-
const joinColumnInverseName = getComponentJoinColumnInverseName(
|
|
75
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
54
|
+
const joinTableName = getComponentJoinTableName(contentType.collectionName, identifiers);
|
|
55
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
|
56
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
|
57
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
76
58
|
return {
|
|
77
59
|
type: "relation",
|
|
78
60
|
relation: attribute.repeatable === true ? "oneToMany" : "oneToOne",
|
|
@@ -83,28 +65,33 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
83
65
|
name: joinTableName,
|
|
84
66
|
joinColumn: {
|
|
85
67
|
name: joinColumnEntityName,
|
|
86
|
-
referencedColumn:
|
|
68
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
87
69
|
},
|
|
88
70
|
inverseJoinColumn: {
|
|
89
71
|
name: joinColumnInverseName,
|
|
90
|
-
referencedColumn:
|
|
72
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
91
73
|
},
|
|
92
74
|
on: {
|
|
93
75
|
field: name
|
|
94
76
|
},
|
|
95
|
-
orderColumnName:
|
|
77
|
+
orderColumnName: identifiers.ORDER_COLUMN,
|
|
96
78
|
orderBy: {
|
|
97
79
|
order: "asc"
|
|
98
80
|
},
|
|
99
|
-
pivotColumns: [
|
|
81
|
+
pivotColumns: [
|
|
82
|
+
joinColumnEntityName,
|
|
83
|
+
joinColumnInverseName,
|
|
84
|
+
identifiers.FIELD_COLUMN,
|
|
85
|
+
compTypeColumn
|
|
86
|
+
]
|
|
100
87
|
}
|
|
101
88
|
};
|
|
102
89
|
}
|
|
103
90
|
case "dynamiczone": {
|
|
104
|
-
const joinTableName = getDzJoinTableName(contentType.collectionName,
|
|
105
|
-
const joinColumnEntityName = getComponentJoinColumnEntityName(
|
|
106
|
-
const joinColumnInverseName = getComponentJoinColumnInverseName(
|
|
107
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
91
|
+
const joinTableName = getDzJoinTableName(contentType.collectionName, identifiers);
|
|
92
|
+
const joinColumnEntityName = getComponentJoinColumnEntityName(identifiers);
|
|
93
|
+
const joinColumnInverseName = getComponentJoinColumnInverseName(identifiers);
|
|
94
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
108
95
|
return {
|
|
109
96
|
type: "relation",
|
|
110
97
|
relation: "morphToMany",
|
|
@@ -114,12 +101,12 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
114
101
|
name: joinTableName,
|
|
115
102
|
joinColumn: {
|
|
116
103
|
name: joinColumnEntityName,
|
|
117
|
-
referencedColumn:
|
|
104
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
118
105
|
},
|
|
119
106
|
morphColumn: {
|
|
120
107
|
idColumn: {
|
|
121
108
|
name: joinColumnInverseName,
|
|
122
|
-
referencedColumn:
|
|
109
|
+
referencedColumn: identifiers.ID_COLUMN
|
|
123
110
|
},
|
|
124
111
|
typeColumn: {
|
|
125
112
|
name: compTypeColumn
|
|
@@ -132,7 +119,12 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
132
119
|
orderBy: {
|
|
133
120
|
order: "asc"
|
|
134
121
|
},
|
|
135
|
-
pivotColumns: [
|
|
122
|
+
pivotColumns: [
|
|
123
|
+
joinColumnEntityName,
|
|
124
|
+
joinColumnInverseName,
|
|
125
|
+
identifiers.FIELD_COLUMN,
|
|
126
|
+
compTypeColumn
|
|
127
|
+
]
|
|
136
128
|
}
|
|
137
129
|
};
|
|
138
130
|
}
|
|
@@ -141,7 +133,7 @@ const transformAttribute = (name, attribute, contentType, options) => {
|
|
|
141
133
|
}
|
|
142
134
|
}
|
|
143
135
|
};
|
|
144
|
-
const transformAttributes = (contentType,
|
|
136
|
+
const transformAttributes = (contentType, identifiers) => {
|
|
145
137
|
return Object.keys(contentType.attributes || {}).reduce((attrs, attrName) => {
|
|
146
138
|
return {
|
|
147
139
|
...attrs,
|
|
@@ -149,7 +141,7 @@ const transformAttributes = (contentType, options) => {
|
|
|
149
141
|
attrName,
|
|
150
142
|
contentType.attributes[attrName],
|
|
151
143
|
contentType,
|
|
152
|
-
|
|
144
|
+
identifiers
|
|
153
145
|
)
|
|
154
146
|
};
|
|
155
147
|
}, {});
|
|
@@ -160,19 +152,19 @@ const hasComponentsOrDz = (contentType) => {
|
|
|
160
152
|
);
|
|
161
153
|
};
|
|
162
154
|
const createDocumentId = cuid2.createId;
|
|
163
|
-
const createCompoLinkModel = (contentType,
|
|
164
|
-
const name = getComponentJoinTableName(contentType.collectionName,
|
|
165
|
-
const entityId = getComponentJoinColumnEntityName(
|
|
166
|
-
const componentId = getComponentJoinColumnInverseName(
|
|
167
|
-
const compTypeColumn = getComponentTypeColumn(
|
|
168
|
-
const fkIndex = getComponentFkIndexName(contentType.collectionName,
|
|
155
|
+
const createCompoLinkModel = (contentType, identifiers) => {
|
|
156
|
+
const name = getComponentJoinTableName(contentType.collectionName, identifiers);
|
|
157
|
+
const entityId = getComponentJoinColumnEntityName(identifiers);
|
|
158
|
+
const componentId = getComponentJoinColumnInverseName(identifiers);
|
|
159
|
+
const compTypeColumn = getComponentTypeColumn(identifiers);
|
|
160
|
+
const fkIndex = getComponentFkIndexName(contentType.collectionName, identifiers);
|
|
169
161
|
return {
|
|
170
162
|
// TODO: make sure there can't be any conflicts with a prefix
|
|
171
163
|
singularName: name,
|
|
172
164
|
uid: name,
|
|
173
165
|
tableName: name,
|
|
174
166
|
attributes: {
|
|
175
|
-
[
|
|
167
|
+
[identifiers.ID_COLUMN]: {
|
|
176
168
|
type: "increments"
|
|
177
169
|
},
|
|
178
170
|
[entityId]: {
|
|
@@ -190,10 +182,10 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
190
182
|
[compTypeColumn]: {
|
|
191
183
|
type: "string"
|
|
192
184
|
},
|
|
193
|
-
[
|
|
185
|
+
[identifiers.FIELD_COLUMN]: {
|
|
194
186
|
type: "string"
|
|
195
187
|
},
|
|
196
|
-
[
|
|
188
|
+
[identifiers.ORDER_COLUMN]: {
|
|
197
189
|
type: "float",
|
|
198
190
|
column: {
|
|
199
191
|
unsigned: true,
|
|
@@ -203,11 +195,11 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
203
195
|
},
|
|
204
196
|
indexes: [
|
|
205
197
|
{
|
|
206
|
-
name: identifiers.getIndexName([contentType.collectionName,
|
|
207
|
-
columns: [
|
|
198
|
+
name: identifiers.getIndexName([contentType.collectionName, identifiers.FIELD_COLUMN]),
|
|
199
|
+
columns: [identifiers.FIELD_COLUMN]
|
|
208
200
|
},
|
|
209
201
|
{
|
|
210
|
-
name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]
|
|
202
|
+
name: identifiers.getIndexName([contentType.collectionName, compTypeColumn]),
|
|
211
203
|
columns: [compTypeColumn]
|
|
212
204
|
},
|
|
213
205
|
{
|
|
@@ -216,8 +208,8 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
216
208
|
},
|
|
217
209
|
{
|
|
218
210
|
// NOTE: since we don't include attribute names, we need to be careful not to create another unique index
|
|
219
|
-
name: identifiers.getUniqueIndexName([contentType.collectionName]
|
|
220
|
-
columns: [entityId, componentId,
|
|
211
|
+
name: identifiers.getUniqueIndexName([contentType.collectionName]),
|
|
212
|
+
columns: [entityId, componentId, identifiers.FIELD_COLUMN, compTypeColumn],
|
|
221
213
|
type: "unique"
|
|
222
214
|
}
|
|
223
215
|
],
|
|
@@ -225,21 +217,21 @@ const createCompoLinkModel = (contentType, options) => {
|
|
|
225
217
|
{
|
|
226
218
|
name: fkIndex,
|
|
227
219
|
columns: [entityId],
|
|
228
|
-
referencedColumns: [
|
|
229
|
-
referencedTable: identifiers.getTableName(contentType.collectionName
|
|
220
|
+
referencedColumns: [identifiers.ID_COLUMN],
|
|
221
|
+
referencedTable: identifiers.getTableName(contentType.collectionName),
|
|
230
222
|
onDelete: "CASCADE"
|
|
231
223
|
}
|
|
232
224
|
]
|
|
233
225
|
};
|
|
234
226
|
};
|
|
235
|
-
const transformContentTypesToModels = (contentTypes,
|
|
227
|
+
const transformContentTypesToModels = (contentTypes, identifiers) => {
|
|
236
228
|
const models = [];
|
|
237
229
|
contentTypes.forEach((contentType) => {
|
|
238
230
|
assert__default.default(contentType.collectionName, 'Content type "collectionName" is required');
|
|
239
231
|
assert__default.default(contentType.modelName, 'Content type "modelName" is required');
|
|
240
232
|
assert__default.default(contentType.uid, 'Content type "uid" is required');
|
|
241
233
|
const documentIdAttribute = contentType.modelType === "contentType" ? { documentId: { type: "string", default: createDocumentId } } : {};
|
|
242
|
-
const reservedAttributeNames = ["document_id",
|
|
234
|
+
const reservedAttributeNames = ["document_id", identifiers.ID_COLUMN];
|
|
243
235
|
Object.keys(contentType.attributes || {}).forEach((attributeName) => {
|
|
244
236
|
const snakeCasedAttributeName = ___default.default.snakeCase(attributeName);
|
|
245
237
|
if (reservedAttributeNames.includes(snakeCasedAttributeName)) {
|
|
@@ -249,7 +241,7 @@ const transformContentTypesToModels = (contentTypes, options) => {
|
|
|
249
241
|
}
|
|
250
242
|
});
|
|
251
243
|
if (hasComponentsOrDz(contentType)) {
|
|
252
|
-
const compoLinkModel = createCompoLinkModel(contentType,
|
|
244
|
+
const compoLinkModel = createCompoLinkModel(contentType, identifiers);
|
|
253
245
|
models.push(compoLinkModel);
|
|
254
246
|
}
|
|
255
247
|
const model = {
|
|
@@ -258,11 +250,11 @@ const transformContentTypesToModels = (contentTypes, options) => {
|
|
|
258
250
|
tableName: contentType.collectionName,
|
|
259
251
|
// This gets shortened in metadata.loadModels(), so we don't shorten here or it will happen twice
|
|
260
252
|
attributes: {
|
|
261
|
-
[
|
|
253
|
+
[identifiers.ID_COLUMN]: {
|
|
262
254
|
type: "increments"
|
|
263
255
|
},
|
|
264
256
|
...documentIdAttribute,
|
|
265
|
-
...transformAttributes(contentType,
|
|
257
|
+
...transformAttributes(contentType, identifiers)
|
|
266
258
|
}
|
|
267
259
|
};
|
|
268
260
|
models.push(model);
|