@contember/engine-http 2.1.0-beta.1 → 2.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/content/ContentApiControllerFactory.cjs +2 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +2 -1
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs +2 -0
- package/dist/development/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentQueryHandlerFactory.js +2 -0
- package/dist/development/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.cjs +3 -3
- package/dist/development/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/development/src/content/GraphQlSchemaFactory.js +3 -3
- package/dist/development/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/development/src/content/triggeredActionsListener.cjs +18 -0
- package/dist/development/src/content/triggeredActionsListener.cjs.map +1 -0
- package/dist/development/src/content/triggeredActionsListener.js +18 -0
- package/dist/development/src/content/triggeredActionsListener.js.map +1 -0
- package/dist/development/src/prometheus/CustomMetric.cjs +17 -4
- package/dist/development/src/prometheus/CustomMetric.cjs.map +1 -1
- package/dist/development/src/prometheus/CustomMetric.js +17 -4
- package/dist/development/src/prometheus/CustomMetric.js.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.cjs +5 -2
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.js +5 -2
- package/dist/development/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.cjs +5 -1
- package/dist/development/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ExportExecutor.js +5 -1
- package/dist/development/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.cjs +48 -22
- package/dist/development/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/development/src/transfer/ImportExecutor.js +48 -22
- package/dist/development/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +2 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +2 -1
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs +2 -0
- package/dist/production/src/content/ContentQueryHandlerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentQueryHandlerFactory.js +2 -0
- package/dist/production/src/content/ContentQueryHandlerFactory.js.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.cjs +3 -3
- package/dist/production/src/content/GraphQlSchemaFactory.cjs.map +1 -1
- package/dist/production/src/content/GraphQlSchemaFactory.js +3 -3
- package/dist/production/src/content/GraphQlSchemaFactory.js.map +1 -1
- package/dist/production/src/content/triggeredActionsListener.cjs +18 -0
- package/dist/production/src/content/triggeredActionsListener.cjs.map +1 -0
- package/dist/production/src/content/triggeredActionsListener.js +18 -0
- package/dist/production/src/content/triggeredActionsListener.js.map +1 -0
- package/dist/production/src/prometheus/CustomMetric.cjs +17 -4
- package/dist/production/src/prometheus/CustomMetric.cjs.map +1 -1
- package/dist/production/src/prometheus/CustomMetric.js +17 -4
- package/dist/production/src/prometheus/CustomMetric.js.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.cjs +5 -2
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.cjs.map +1 -1
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.js +5 -2
- package/dist/production/src/transfer/ContentSchemaTransferMappingFactory.js.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.cjs +5 -1
- package/dist/production/src/transfer/ExportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ExportExecutor.js +5 -1
- package/dist/production/src/transfer/ExportExecutor.js.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.cjs +48 -22
- package/dist/production/src/transfer/ImportExecutor.cjs.map +1 -1
- package/dist/production/src/transfer/ImportExecutor.js +48 -22
- package/dist/production/src/transfer/ImportExecutor.js.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/content/ContentQueryHandlerFactory.d.ts.map +1 -1
- package/dist/types/content/GraphQlSchemaFactory.d.ts +1 -0
- package/dist/types/content/GraphQlSchemaFactory.d.ts.map +1 -1
- package/dist/types/content/triggeredActionsListener.d.ts +4 -0
- package/dist/types/content/triggeredActionsListener.d.ts.map +1 -0
- package/dist/types/prometheus/CustomMetric.d.ts +1 -0
- package/dist/types/prometheus/CustomMetric.d.ts.map +1 -1
- package/dist/types/transfer/ContentSchemaTransferMappingFactory.d.ts.map +1 -1
- package/dist/types/transfer/ExportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/ImportExecutor.d.ts.map +1 -1
- package/dist/types/transfer/TransferMapping.d.ts +5 -1
- package/dist/types/transfer/TransferMapping.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -3
- package/src/content/ContentApiControllerFactory.ts +2 -1
- package/src/content/ContentQueryHandlerFactory.ts +2 -0
- package/src/content/GraphQlSchemaFactory.ts +4 -3
- package/src/content/triggeredActionsListener.ts +17 -0
- package/src/prometheus/CustomMetric.ts +18 -4
- package/src/transfer/ContentSchemaTransferMappingFactory.ts +3 -0
- package/src/transfer/ExportExecutor.ts +9 -1
- package/src/transfer/ImportExecutor.ts +51 -17
- package/src/transfer/TransferMapping.ts +10 -5
- package/tests/cases/unit/contentApiSpecificCache.tst.js +1 -1
- package/vitest.config.ts +0 -3
|
@@ -61,7 +61,7 @@ class ContentApiControllerFactory {
|
|
|
61
61
|
context.requestDebugMode = true;
|
|
62
62
|
}
|
|
63
63
|
const projectRoles = memberships.map((it) => it.role);
|
|
64
|
-
const { schema: graphQlSchema, permissions } = await timer(
|
|
64
|
+
const { schema: graphQlSchema, permissions, allPermissions } = await timer(
|
|
65
65
|
"GraphQLSchemaCreate",
|
|
66
66
|
() => this.graphQlSchemaFactory.create(schema, {
|
|
67
67
|
projectRoles
|
|
@@ -101,6 +101,7 @@ class ContentApiControllerFactory {
|
|
|
101
101
|
schemaMeta: { id: schemaWithMeta.meta.id },
|
|
102
102
|
schemaDatabaseMetadata,
|
|
103
103
|
permissions,
|
|
104
|
+
allPermissions,
|
|
104
105
|
systemSchema: projectContainer.systemDatabaseContextFactory.schemaName,
|
|
105
106
|
stage,
|
|
106
107
|
project,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application'\nimport { HttpErrorResponse, HttpResponse } from '../common'\nimport { GraphQLKoaState } from '../graphql'\nimport { ProjectContextResolver } from '../project-common'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory'\nimport { NotModifiedChecker } from './NotModifiedChecker'\n\nconst debugHeader = 'x-contember-debug'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst systemDatabase = projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation }) => {\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst connection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst contentDatabase = connection.createClient(stage.schema, { module: 'content' })\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: koa.request.headers['user-agent'] ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t}))\n\t\t\t\tlogger.debug('Content query finished')\n\t\t\t})\n\n\t\t\tnotModifiedRes?.setResponseHeader(context.response)\n\t\t}\n\t}\n}\n"],"names":["logger"],"mappings":";;;AAWA,MAAM,cAAc;AAE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,UACT,KAAK,OAAO;AAAA,UACZ,aAAa,QAAQ;AAAA,UACrB,UAAU;AAAA,YACT,YAAY,WAAW;AAAA,YACvB,UAAU,WAAW,YAAY;AAAA,YACjC,OAAO,WAAW;AAAA,UAAA;AAAA,QACnB,CACA;AAAA,MAAA;AAGH,aAAO,MAAM,uBAAuB,EAAE,YAAA,CAAa;AAEnD,YAAM,mBAAmB,QAAQ,QAAQ,WAAW;AACpD,UAAI,MAAM,QAAQ,gBAAgB,GAAG;AACpC,eAAO,IAAI,kBAAkB,KAAK,qBAAqB,WAAW,EAAE;AAAA,MACrE;AACA,YAAM,eAAe,qBAAqB,OAAO,mBAAmB,KAAK,CAAA,OAAM,OAAO,IAAI,MAAM,GAAG,IAAI,GAAG,KAAK;AAC/G,UAAI,cAAc;AACjB,gBAAQ,mBAAmB;AAAA,MAC5B;AAEA,YAAM,eAAe,YAAY,IAAI,CAAA,OAAM,GAAG,IAAI;AAElD,YAAM,EAAE,QAAQ,eAAe,
|
|
1
|
+
{"version":3,"file":"ContentApiControllerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentApiControllerFactory.ts"],"sourcesContent":["import { createAclVariables, ExecutionContainerFactory } from '@contember/engine-content-api'\nimport { StageBySlugQuery } from '@contember/engine-system-api'\nimport { GraphQLSchema } from 'graphql'\nimport { HttpController } from '../application'\nimport { HttpErrorResponse, HttpResponse } from '../common'\nimport { GraphQLKoaState } from '../graphql'\nimport { ProjectContextResolver } from '../project-common'\nimport { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryHandlerFactory'\nimport { GraphQlSchemaFactory } from './GraphQlSchemaFactory'\nimport { NotModifiedChecker } from './NotModifiedChecker'\n\nconst debugHeader = 'x-contember-debug'\n\nexport class ContentApiControllerFactory {\n\tconstructor(\n\t\tprivate readonly notModifiedChecker: NotModifiedChecker,\n\t\tprivate readonly executionContainerFactory: ExecutionContainerFactory,\n\t\tprivate readonly handlerFactory: ContentQueryHandlerFactory,\n\t\tprivate readonly projectContextResolver: ProjectContextResolver,\n\t\tprivate readonly graphQlSchemaFactory: GraphQlSchemaFactory,\n\t) {\n\t}\n\n\tcreate(): HttpController {\n\t\tconst handlerCache = new WeakMap<GraphQLSchema, ContentQueryHandler>()\n\t\treturn async context => {\n\t\t\tconst { params, timer, projectGroup, authResult, request, koa, clientIp } = context\n\t\t\tif (!authResult) {\n\t\t\t\treturn new HttpErrorResponse(401, 'Authentication required')\n\t\t\t}\n\t\t\tconst { projectContainer, project } = await this.projectContextResolver.resolve(context)\n\n\t\t\tconst logger = context.logger.child({\n\t\t\t\tproject: project.slug,\n\t\t\t})\n\n\t\t\tconst systemDatabase = projectContainer.systemReadDatabaseContext\n\t\t\tconst stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))\n\t\t\tif (!stage) {\n\t\t\t\treturn new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)\n\t\t\t}\n\t\t\tconst notModifiedRes = await this.notModifiedChecker.checkNotModified({\n\t\t\t\trequest: context.request,\n\t\t\t\tbody: context.body,\n\t\t\t\ttimer: context.timer,\n\t\t\t\tsystemDatabase,\n\t\t\t\tstageId: stage.id,\n\t\t\t})\n\t\t\tif (notModifiedRes?.isModified === false) {\n\t\t\t\treturn new HttpResponse(304)\n\t\t\t}\n\n\t\t\tconst schemaWithMeta = await projectContainer.contentSchemaResolver.getSchema({ db: systemDatabase, stage: stage.slug, normalize: true })\n\t\t\tconst schema = schemaWithMeta.schema\n\t\t\tconst { effective: memberships, fetched: fetchedMemberships } = await timer(\n\t\t\t\t'MembershipFetch',\n\t\t\t\t() =>\n\t\t\t\t\tprojectGroup.projectMembershipResolver.resolveMemberships({\n\t\t\t\t\t\trequest: koa,\n\t\t\t\t\t\tacl: schema.acl,\n\t\t\t\t\t\tprojectSlug: project.slug,\n\t\t\t\t\t\tidentity: {\n\t\t\t\t\t\t\tidentityId: authResult.identityId,\n\t\t\t\t\t\t\tpersonId: authResult.personId ?? undefined,\n\t\t\t\t\t\t\troles: authResult.roles,\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\t\t\t)\n\n\t\t\tlogger.debug('Memberships fetched', { memberships })\n\n\t\t\tconst debugHeaderValue = request.headers[debugHeader]\n\t\t\tif (Array.isArray(debugHeaderValue)) {\n\t\t\t\treturn new HttpErrorResponse(400, `Invalid format of ${debugHeader}`)\n\t\t\t}\n\t\t\tconst requestDebug = debugHeaderValue === '1' && fetchedMemberships.some(it => schema.acl.roles[it.role]?.debug)\n\t\t\tif (requestDebug) {\n\t\t\t\tcontext.requestDebugMode = true\n\t\t\t}\n\n\t\t\tconst projectRoles = memberships.map(it => it.role)\n\n\t\t\tconst { schema: graphQlSchema, permissions, allPermissions } = await timer(\n\t\t\t\t'GraphQLSchemaCreate',\n\t\t\t\t() =>\n\t\t\t\t\tthis.graphQlSchemaFactory.create(schema, {\n\t\t\t\t\t\tprojectRoles: projectRoles,\n\t\t\t\t\t}, project),\n\t\t\t)\n\n\t\t\tconst schemaDatabaseMetadata = await projectContainer.projectDatabaseMetadataResolver.resolveDatabaseMetadata(systemDatabase, schema, stage.schema)\n\n\t\t\tconst handler = await (async () => {\n\t\t\t\tconst existingHandler = handlerCache.get(graphQlSchema)\n\t\t\t\tif (existingHandler) {\n\t\t\t\t\treturn existingHandler\n\t\t\t\t}\n\t\t\t\tconst newHandler = await this.handlerFactory.create(graphQlSchema)\n\t\t\t\thandlerCache.set(graphQlSchema, newHandler)\n\t\t\t\treturn newHandler\n\t\t\t})()\n\n\t\t\tawait logger.scope(async logger => {\n\t\t\t\tlogger.debug('Content query processing started')\n\n\t\t\t\tawait timer('GraphQL', () =>\n\t\t\t\t\thandler({\n\t\t\t\t\t\trequest: koa.request,\n\t\t\t\t\t\tresponse: koa.response,\n\t\t\t\t\t\tcreateContext: ({ operation }) => {\n\t\t\t\t\t\t\t;(koa.state as GraphQLKoaState).graphql = {\n\t\t\t\t\t\t\t\toperationName: operation,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst connection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection\n\t\t\t\t\t\t\tconst contentDatabase = connection.createClient(stage.schema, { module: 'content' })\n\n\t\t\t\t\t\t\tconst identityVariables = createAclVariables(schema.acl, memberships)\n\t\t\t\t\t\t\tlet identityId = authResult.identityId\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tauthResult.assumedIdentityId\n\t\t\t\t\t\t\t\t&& memberships.some(it => schema.acl.roles[it.role].system?.assumeIdentity)\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tidentityId = authResult.assumedIdentityId\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst executionContainer = this.executionContainerFactory.create({\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tschemaMeta: { id: schemaWithMeta.meta.id },\n\t\t\t\t\t\t\t\tschemaDatabaseMetadata,\n\t\t\t\t\t\t\t\tpermissions,\n\t\t\t\t\t\t\t\tallPermissions,\n\t\t\t\t\t\t\t\tsystemSchema: projectContainer.systemDatabaseContextFactory.schemaName,\n\t\t\t\t\t\t\t\tstage,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t\tuserInfo: {\n\t\t\t\t\t\t\t\t\tipAddress: clientIp,\n\t\t\t\t\t\t\t\t\tuserAgent: koa.request.headers['user-agent'] ?? null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t})\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\tdb: contentDatabase,\n\t\t\t\t\t\t\t\tidentityVariables,\n\t\t\t\t\t\t\t\tidentityId,\n\t\t\t\t\t\t\t\texecutionContainer,\n\t\t\t\t\t\t\t\ttimer,\n\t\t\t\t\t\t\t\trequestDebug,\n\t\t\t\t\t\t\t\tproject,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t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|
3
3
|
const dbQueriesListener = require("../graphql/dbQueriesListener.cjs");
|
|
4
4
|
const execution = require("../graphql/execution.cjs");
|
|
5
|
+
const triggeredActionsListener = require("./triggeredActionsListener.cjs");
|
|
5
6
|
class ContentQueryHandlerFactory {
|
|
6
7
|
constructor(debug) {
|
|
7
8
|
this.debug = debug;
|
|
@@ -9,6 +10,7 @@ class ContentQueryHandlerFactory {
|
|
|
9
10
|
create(graphQlSchema) {
|
|
10
11
|
const listeners = [];
|
|
11
12
|
listeners.push(dbQueriesListener.createDbQueriesListener((context) => context.db, this.debug));
|
|
13
|
+
listeners.push(triggeredActionsListener.createTriggeredActionsListener());
|
|
12
14
|
return execution.createGraphQLQueryHandler({
|
|
13
15
|
schema: graphQlSchema,
|
|
14
16
|
listeners
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentQueryHandlerFactory.cjs","sources":["../../../../../packages/engine-http/src/content/ContentQueryHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { createDbQueriesListener, createGraphQLQueryHandler, GraphQLListener, GraphQLQueryHandler } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\n\nexport type ContentQueryHandler = GraphQLQueryHandler<ContentGraphqlContext>\n\nexport class ContentQueryHandlerFactory {\n\tconstructor(private readonly debug: boolean) {}\n\n\tpublic create(graphQlSchema: GraphQLSchema): ContentQueryHandler {\n\t\tconst listeners: GraphQLListener<ContentGraphqlContext>[] = []\n\t\tlisteners.push(createDbQueriesListener(context => context.db, this.debug))\n\n\t\treturn createGraphQLQueryHandler<ContentGraphqlContext>({\n\t\t\tschema: graphQlSchema,\n\t\t\tlisteners,\n\t\t})\n\t}\n}\n"],"names":["createDbQueriesListener","createGraphQLQueryHandler"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentQueryHandlerFactory.cjs","sources":["../../../../../packages/engine-http/src/content/ContentQueryHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { createDbQueriesListener, createGraphQLQueryHandler, GraphQLListener, GraphQLQueryHandler } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\nimport { createTriggeredActionsListener } from './triggeredActionsListener'\n\nexport type ContentQueryHandler = GraphQLQueryHandler<ContentGraphqlContext>\n\nexport class ContentQueryHandlerFactory {\n\tconstructor(private readonly debug: boolean) {}\n\n\tpublic create(graphQlSchema: GraphQLSchema): ContentQueryHandler {\n\t\tconst listeners: GraphQLListener<ContentGraphqlContext>[] = []\n\t\tlisteners.push(createDbQueriesListener(context => context.db, this.debug))\n\t\tlisteners.push(createTriggeredActionsListener())\n\n\t\treturn createGraphQLQueryHandler<ContentGraphqlContext>({\n\t\t\tschema: graphQlSchema,\n\t\t\tlisteners,\n\t\t})\n\t}\n}\n"],"names":["createDbQueriesListener","createTriggeredActionsListener","createGraphQLQueryHandler"],"mappings":";;;;;AAOO,MAAM,2BAA2B;AAAA,EACvC,YAA6B,OAAgB;AAAhB,SAAA,QAAA;AAAA,EAAiB;AAAA,EAEvC,OAAO,eAAmD;AAChE,UAAM,YAAsD,CAAA;AAC5D,cAAU,KAAKA,kBAAAA,wBAAwB,CAAA,YAAW,QAAQ,IAAI,KAAK,KAAK,CAAC;AACzE,cAAU,KAAKC,yBAAAA,gCAAgC;AAE/C,WAAOC,oCAAiD;AAAA,MACvD,QAAQ;AAAA,MACR;AAAA,IAAA,CACA;AAAA,EACF;AACD;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createDbQueriesListener } from "../graphql/dbQueriesListener.js";
|
|
2
2
|
import { createGraphQLQueryHandler } from "../graphql/execution.js";
|
|
3
|
+
import { createTriggeredActionsListener } from "./triggeredActionsListener.js";
|
|
3
4
|
class ContentQueryHandlerFactory {
|
|
4
5
|
constructor(debug) {
|
|
5
6
|
this.debug = debug;
|
|
@@ -7,6 +8,7 @@ class ContentQueryHandlerFactory {
|
|
|
7
8
|
create(graphQlSchema) {
|
|
8
9
|
const listeners = [];
|
|
9
10
|
listeners.push(createDbQueriesListener((context) => context.db, this.debug));
|
|
11
|
+
listeners.push(createTriggeredActionsListener());
|
|
10
12
|
return createGraphQLQueryHandler({
|
|
11
13
|
schema: graphQlSchema,
|
|
12
14
|
listeners
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentQueryHandlerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentQueryHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { createDbQueriesListener, createGraphQLQueryHandler, GraphQLListener, GraphQLQueryHandler } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\n\nexport type ContentQueryHandler = GraphQLQueryHandler<ContentGraphqlContext>\n\nexport class ContentQueryHandlerFactory {\n\tconstructor(private readonly debug: boolean) {}\n\n\tpublic create(graphQlSchema: GraphQLSchema): ContentQueryHandler {\n\t\tconst listeners: GraphQLListener<ContentGraphqlContext>[] = []\n\t\tlisteners.push(createDbQueriesListener(context => context.db, this.debug))\n\n\t\treturn createGraphQLQueryHandler<ContentGraphqlContext>({\n\t\t\tschema: graphQlSchema,\n\t\t\tlisteners,\n\t\t})\n\t}\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentQueryHandlerFactory.js","sources":["../../../../../packages/engine-http/src/content/ContentQueryHandlerFactory.ts"],"sourcesContent":["import { GraphQLSchema } from 'graphql'\nimport { createDbQueriesListener, createGraphQLQueryHandler, GraphQLListener, GraphQLQueryHandler } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\nimport { createTriggeredActionsListener } from './triggeredActionsListener'\n\nexport type ContentQueryHandler = GraphQLQueryHandler<ContentGraphqlContext>\n\nexport class ContentQueryHandlerFactory {\n\tconstructor(private readonly debug: boolean) {}\n\n\tpublic create(graphQlSchema: GraphQLSchema): ContentQueryHandler {\n\t\tconst listeners: GraphQLListener<ContentGraphqlContext>[] = []\n\t\tlisteners.push(createDbQueriesListener(context => context.db, this.debug))\n\t\tlisteners.push(createTriggeredActionsListener())\n\n\t\treturn createGraphQLQueryHandler<ContentGraphqlContext>({\n\t\t\tschema: graphQlSchema,\n\t\t\tlisteners,\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;AAOO,MAAM,2BAA2B;AAAA,EACvC,YAA6B,OAAgB;AAAhB,SAAA,QAAA;AAAA,EAAiB;AAAA,EAEvC,OAAO,eAAmD;AAChE,UAAM,YAAsD,CAAA;AAC5D,cAAU,KAAK,wBAAwB,CAAA,YAAW,QAAQ,IAAI,KAAK,KAAK,CAAC;AACzE,cAAU,KAAK,gCAAgC;AAE/C,WAAO,0BAAiD;AAAA,MACvD,QAAQ;AAAA,MACR;AAAA,IAAA,CACA;AAAA,EACF;AACD;"}
|
|
@@ -14,9 +14,9 @@ class GraphQlSchemaFactory {
|
|
|
14
14
|
const contributorsKey = this.schemaContributors.map((it) => it.getCacheKey?.({ schema, identity, project }) ?? "").join("ÿ");
|
|
15
15
|
const cacheKey = `${rolesKey}ÿÿ${contributorsKey}`;
|
|
16
16
|
return this.cache.fetch(schema, cacheKey, () => {
|
|
17
|
-
const permissions = this.permissionFactory.
|
|
17
|
+
const { root: permissions, all: allPermissions } = this.permissionFactory.createContextual(schema, identity.projectRoles);
|
|
18
18
|
const authorizator = new engineContentApi.Authorizator(
|
|
19
|
-
|
|
19
|
+
allPermissions,
|
|
20
20
|
schema.acl.customPrimary ?? false,
|
|
21
21
|
Object.values(schema.acl.roles).some((it) => it.content?.refreshMaterializedView)
|
|
22
22
|
);
|
|
@@ -56,7 +56,7 @@ class GraphQlSchemaFactory {
|
|
|
56
56
|
queries,
|
|
57
57
|
types
|
|
58
58
|
});
|
|
59
|
-
return { schema: graphQlSchema, permissions };
|
|
59
|
+
return { schema: graphQlSchema, permissions, allPermissions };
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphQlSchemaFactory.cjs","sources":["../../../../../packages/engine-http/src/content/GraphQlSchemaFactory.ts"],"sourcesContent":["import {\n\tAuthorizator,\n\tContext,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { Acl, Schema } from '@contember/schema'\nimport { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'\nimport { GraphQLSchemaContributor } from './GraphQLSchemaContributor'\nimport { Identity } from './Identity'\nimport { ContentApiSpecificCache } from './ContentApiSpecificCache'\nimport { ProjectConfig } from '../project/config'\n\nexport interface GraphQLSchemaFactoryResult {\n\tpermissions: Acl.Permissions\n\tschema: GraphQLSchema\n}\n\nexport class GraphQlSchemaFactory {\n\tconstructor(\n\t\tprivate readonly cache: ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t\tprivate readonly permissionFactory: PermissionFactory,\n\t\tprivate readonly schemaContributors: GraphQLSchemaContributor[],\n\t) {}\n\n\tpublic create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {\n\t\tconst rolesKey = [...identity.projectRoles].sort().join('\\xff')\n\t\tconst contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\\xff')\n\t\tconst cacheKey = `${rolesKey}\\xff\\xff${contributorsKey}`\n\n\t\treturn this.cache.fetch(schema, cacheKey, () => {\n\t\t\tconst permissions = this.permissionFactory.
|
|
1
|
+
{"version":3,"file":"GraphQlSchemaFactory.cjs","sources":["../../../../../packages/engine-http/src/content/GraphQlSchemaFactory.ts"],"sourcesContent":["import {\n\tAuthorizator,\n\tContext,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { Acl, Schema } from '@contember/schema'\nimport { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'\nimport { GraphQLSchemaContributor } from './GraphQLSchemaContributor'\nimport { Identity } from './Identity'\nimport { ContentApiSpecificCache } from './ContentApiSpecificCache'\nimport { ProjectConfig } from '../project/config'\n\nexport interface GraphQLSchemaFactoryResult {\n\tpermissions: Acl.Permissions\n\tallPermissions?: Acl.Permissions\n\tschema: GraphQLSchema\n}\n\nexport class GraphQlSchemaFactory {\n\tconstructor(\n\t\tprivate readonly cache: ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t\tprivate readonly permissionFactory: PermissionFactory,\n\t\tprivate readonly schemaContributors: GraphQLSchemaContributor[],\n\t) {}\n\n\tpublic create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {\n\t\tconst rolesKey = [...identity.projectRoles].sort().join('\\xff')\n\t\tconst contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\\xff')\n\t\tconst cacheKey = `${rolesKey}\\xff\\xff${contributorsKey}`\n\n\t\treturn this.cache.fetch(schema, cacheKey, () => {\n\t\t\tconst { root: permissions, all: allPermissions } = this.permissionFactory.createContextual(schema, identity.projectRoles)\n\n\t\t\tconst authorizator = new Authorizator(\n\t\t\t\tallPermissions,\n\t\t\t\tschema.acl.customPrimary ?? false,\n\t\t\t\tObject.values(schema.acl.roles).some(it => it.content?.refreshMaterializedView),\n\t\t\t)\n\t\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(\n\t\t\t\tnew IntrospectionSchemaFactory(\n\t\t\t\t\tschema.model,\n\t\t\t\t\tnew EntityRulesResolver(schema.validation, schema.model),\n\t\t\t\t\tauthorizator,\n\t\t\t\t),\n\t\t\t)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.createConfig()\n\n\t\t\tconst otherSchemas = this.schemaContributors\n\t\t\t\t.map(it => it.createSchema({ schema, identity, project }))\n\t\t\t\t.filter(<T>(it: T | undefined): it is T => it !== undefined)\n\n\t\t\tconst queries = new Map<string, GraphQLFieldConfig<any, Context, any>>()\n\t\t\tconst mutations = new Map<string, GraphQLFieldConfig<any, Context, any>>()\n\t\t\tconst types: GraphQLNamedType[] = []\n\n\t\t\tfor (const schema of [introspectionSchema, ...otherSchemas]) {\n\t\t\t\tif (schema instanceof GraphQLSchema) {\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tqueries.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tmutations.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.query?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tqueries.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.mutation?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tmutations.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\ttypes.push(...(schema.types ?? []))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst graphQlSchema = dataSchemaBuilder.build({\n\t\t\t\tmutations,\n\t\t\t\tqueries,\n\t\t\t\ttypes,\n\t\t\t})\n\n\t\t\treturn { schema: graphQlSchema, permissions, allPermissions }\n\t\t})\n\t}\n}\n"],"names":["Authorizator","IntrospectionSchemaDefinitionFactory","IntrospectionSchemaFactory","EntityRulesResolver","schema","GraphQLSchema"],"mappings":";;;;AAsBO,MAAM,qBAAqB;AAAA,EACjC,YACkB,OACA,6BACA,mBACA,oBAChB;AAJgB,SAAA,QAAA;AACA,SAAA,8BAAA;AACA,SA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AC,OAAO,MAAM,KAAK,OAAO,QAAQD,QAAO,aAAA,GAAgB,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AAC7F,oBAAQ,IAAI,OAAO,MAAM;AAAA,UAC1B;AACA,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,aAAA,GAAgB,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AAC7F,sBAAU,IAAI,OAAO,MAAM;AAAA,UAC5B;AAAA,QACD,OAAO;AACN,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,OAAO,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AACpF,oBAAQ,IAAI,OAAO,MAAM;AAAA,UAC1B;AACA,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,UAAU,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AACvF,sBAAU,IAAI,OAAO,MAAM;AAAA,UAC5B;AACA,gBAAM,KAAK,GAAIA,QAAO,SAAS,CAAA,CAAG;AAAA,QACnC;AAAA,MACD;AAEA,YAAM,gBAAgB,kBAAkB,MAAM;AAAA,QAC7C;AAAA,QACA;AAAA,QACA;AAAA,MAAA,CACA;AAED,aAAO,EAAE,QAAQ,eAAe,aAAa,eAAA;AAAA,IAC9C,CAAC;AAAA,EACF;AACD;;"}
|
|
@@ -12,9 +12,9 @@ class GraphQlSchemaFactory {
|
|
|
12
12
|
const contributorsKey = this.schemaContributors.map((it) => it.getCacheKey?.({ schema, identity, project }) ?? "").join("ÿ");
|
|
13
13
|
const cacheKey = `${rolesKey}ÿÿ${contributorsKey}`;
|
|
14
14
|
return this.cache.fetch(schema, cacheKey, () => {
|
|
15
|
-
const permissions = this.permissionFactory.
|
|
15
|
+
const { root: permissions, all: allPermissions } = this.permissionFactory.createContextual(schema, identity.projectRoles);
|
|
16
16
|
const authorizator = new Authorizator(
|
|
17
|
-
|
|
17
|
+
allPermissions,
|
|
18
18
|
schema.acl.customPrimary ?? false,
|
|
19
19
|
Object.values(schema.acl.roles).some((it) => it.content?.refreshMaterializedView)
|
|
20
20
|
);
|
|
@@ -54,7 +54,7 @@ class GraphQlSchemaFactory {
|
|
|
54
54
|
queries,
|
|
55
55
|
types
|
|
56
56
|
});
|
|
57
|
-
return { schema: graphQlSchema, permissions };
|
|
57
|
+
return { schema: graphQlSchema, permissions, allPermissions };
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphQlSchemaFactory.js","sources":["../../../../../packages/engine-http/src/content/GraphQlSchemaFactory.ts"],"sourcesContent":["import {\n\tAuthorizator,\n\tContext,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { Acl, Schema } from '@contember/schema'\nimport { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'\nimport { GraphQLSchemaContributor } from './GraphQLSchemaContributor'\nimport { Identity } from './Identity'\nimport { ContentApiSpecificCache } from './ContentApiSpecificCache'\nimport { ProjectConfig } from '../project/config'\n\nexport interface GraphQLSchemaFactoryResult {\n\tpermissions: Acl.Permissions\n\tschema: GraphQLSchema\n}\n\nexport class GraphQlSchemaFactory {\n\tconstructor(\n\t\tprivate readonly cache: ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t\tprivate readonly permissionFactory: PermissionFactory,\n\t\tprivate readonly schemaContributors: GraphQLSchemaContributor[],\n\t) {}\n\n\tpublic create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {\n\t\tconst rolesKey = [...identity.projectRoles].sort().join('\\xff')\n\t\tconst contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\\xff')\n\t\tconst cacheKey = `${rolesKey}\\xff\\xff${contributorsKey}`\n\n\t\treturn this.cache.fetch(schema, cacheKey, () => {\n\t\t\tconst permissions = this.permissionFactory.
|
|
1
|
+
{"version":3,"file":"GraphQlSchemaFactory.js","sources":["../../../../../packages/engine-http/src/content/GraphQlSchemaFactory.ts"],"sourcesContent":["import {\n\tAuthorizator,\n\tContext,\n\tEntityRulesResolver,\n\tGraphQlSchemaBuilderFactory,\n\tIntrospectionSchemaDefinitionFactory,\n\tIntrospectionSchemaFactory,\n\tPermissionFactory,\n} from '@contember/engine-content-api'\nimport { Acl, Schema } from '@contember/schema'\nimport { GraphQLFieldConfig, GraphQLNamedType, GraphQLSchema } from 'graphql'\nimport { GraphQLSchemaContributor } from './GraphQLSchemaContributor'\nimport { Identity } from './Identity'\nimport { ContentApiSpecificCache } from './ContentApiSpecificCache'\nimport { ProjectConfig } from '../project/config'\n\nexport interface GraphQLSchemaFactoryResult {\n\tpermissions: Acl.Permissions\n\tallPermissions?: Acl.Permissions\n\tschema: GraphQLSchema\n}\n\nexport class GraphQlSchemaFactory {\n\tconstructor(\n\t\tprivate readonly cache: ContentApiSpecificCache<Schema, GraphQLSchemaFactoryResult>,\n\t\tprivate readonly graphqlSchemaBuilderFactory: GraphQlSchemaBuilderFactory,\n\t\tprivate readonly permissionFactory: PermissionFactory,\n\t\tprivate readonly schemaContributors: GraphQLSchemaContributor[],\n\t) {}\n\n\tpublic create(schema: Schema, identity: Identity, project: ProjectConfig): GraphQLSchemaFactoryResult {\n\t\tconst rolesKey = [...identity.projectRoles].sort().join('\\xff')\n\t\tconst contributorsKey = this.schemaContributors.map(it => it.getCacheKey?.({ schema, identity, project }) ?? '').join('\\xff')\n\t\tconst cacheKey = `${rolesKey}\\xff\\xff${contributorsKey}`\n\n\t\treturn this.cache.fetch(schema, cacheKey, () => {\n\t\t\tconst { root: permissions, all: allPermissions } = this.permissionFactory.createContextual(schema, identity.projectRoles)\n\n\t\t\tconst authorizator = new Authorizator(\n\t\t\t\tallPermissions,\n\t\t\t\tschema.acl.customPrimary ?? false,\n\t\t\t\tObject.values(schema.acl.roles).some(it => it.content?.refreshMaterializedView),\n\t\t\t)\n\t\t\tconst dataSchemaBuilder = this.graphqlSchemaBuilderFactory.create(schema.model, authorizator)\n\t\t\tconst introspectionSchemaFactory = new IntrospectionSchemaDefinitionFactory(\n\t\t\t\tnew IntrospectionSchemaFactory(\n\t\t\t\t\tschema.model,\n\t\t\t\t\tnew EntityRulesResolver(schema.validation, schema.model),\n\t\t\t\t\tauthorizator,\n\t\t\t\t),\n\t\t\t)\n\t\t\tconst introspectionSchema = introspectionSchemaFactory.createConfig()\n\n\t\t\tconst otherSchemas = this.schemaContributors\n\t\t\t\t.map(it => it.createSchema({ schema, identity, project }))\n\t\t\t\t.filter(<T>(it: T | undefined): it is T => it !== undefined)\n\n\t\t\tconst queries = new Map<string, GraphQLFieldConfig<any, Context, any>>()\n\t\t\tconst mutations = new Map<string, GraphQLFieldConfig<any, Context, any>>()\n\t\t\tconst types: GraphQLNamedType[] = []\n\n\t\t\tfor (const schema of [introspectionSchema, ...otherSchemas]) {\n\t\t\t\tif (schema instanceof GraphQLSchema) {\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tqueries.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.getQueryType()?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tmutations.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.query?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tqueries.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\tfor (const [field, config] of Object.entries(schema.mutation?.toConfig().fields ?? {})) {\n\t\t\t\t\t\tmutations.set(field, config)\n\t\t\t\t\t}\n\t\t\t\t\ttypes.push(...(schema.types ?? []))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst graphQlSchema = dataSchemaBuilder.build({\n\t\t\t\tmutations,\n\t\t\t\tqueries,\n\t\t\t\ttypes,\n\t\t\t})\n\n\t\t\treturn { schema: graphQlSchema, permissions, allPermissions }\n\t\t})\n\t}\n}\n"],"names":["schema"],"mappings":";;AAsBO,MAAM,qBAAqB;AAAA,EACjC,YACkB,OACA,6BACA,mBACA,oBAChB;AAJgB,SAAA,QAAA;AACA,SAAA,8BAAA;AACA,SAAA,oBAAA;AACA,SAAA,qBAAA;AAAA,EACf;AAAA,EAEI,OAAO,QAAgB,UAAoB,SAAoD;AACrG,UAAM,WAAW,CAAC,GAAG,SAAS,YAAY,EAAE,KAAA,EAAO,KAAK,GAAM;AAC9D,UAAM,kBAAkB,KAAK,mBAAmB,IAAI,CAAA,OAAM,GAAG,cAAc,EAAE,QAAQ,UAAU,SAAS,KAAK,EAAE,EAAE,KAAK,GAAM;AAC5H,UAAM,WAAW,GAAG,QAAQ,KAAW,eAAe;AAEtD,WAAO,KAAK,MAAM,MAAM,QAAQ,UAAU,MAAM;AAC/C,YAAM,EAAE,MAAM,aAAa,KAAK,eAAA,IAAmB,KAAK,kBAAkB,iBAAiB,QAAQ,SAAS,YAAY;AAExH,YAAM,eAAe,IAAI;AAAA,QACxB;AAAA,QACA,OAAO,IAAI,iBAAiB;AAAA,QAC5B,OAAO,OAAO,OAAO,IAAI,KAAK,EAAE,KAAK,CAAA,OAAM,GAAG,SAAS,uBAAuB;AAAA,MAAA;AAE/E,YAAM,oBAAoB,KAAK,4BAA4B,OAAO,OAAO,OAAO,YAAY;AAC5F,YAAM,6BAA6B,IAAI;AAAA,QACtC,IAAI;AAAA,UACH,OAAO;AAAA,UACP,IAAI,oBAAoB,OAAO,YAAY,OAAO,KAAK;AAAA,UACvD;AAAA,QAAA;AAAA,MACD;AAED,YAAM,sBAAsB,2BAA2B,aAAA;AAEvD,YAAM,eAAe,KAAK,mBACxB,IAAI,CAAA,OAAM,GAAG,aAAa,EAAE,QAAQ,UAAU,QAAA,CAAS,CAAC,EACxD,OAAO,CAAI,OAA+B,OAAO,MAAS;AAE5D,YAAM,8BAAc,IAAA;AACpB,YAAM,gCAAgB,IAAA;AACtB,YAAM,QAA4B,CAAA;AAElC,iBAAWA,WAAU,CAAC,qBAAqB,GAAG,YAAY,GAAG;AAC5D,YAAIA,mBAAkB,eAAe;AACpC,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,aAAA,GAAgB,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AAC7F,oBAAQ,IAAI,OAAO,MAAM;AAAA,UAC1B;AACA,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,aAAA,GAAgB,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AAC7F,sBAAU,IAAI,OAAO,MAAM;AAAA,UAC5B;AAAA,QACD,OAAO;AACN,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,OAAO,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AACpF,oBAAQ,IAAI,OAAO,MAAM;AAAA,UAC1B;AACA,qBAAW,CAAC,OAAO,MAAM,KAAK,OAAO,QAAQA,QAAO,UAAU,SAAA,EAAW,UAAU,CAAA,CAAE,GAAG;AACvF,sBAAU,IAAI,OAAO,MAAM;AAAA,UAC5B;AACA,gBAAM,KAAK,GAAIA,QAAO,SAAS,CAAA,CAAG;AAAA,QACnC;AAAA,MACD;AAEA,YAAM,gBAAgB,kBAAkB,MAAM;AAAA,QAC7C;AAAA,QACA;AAAA,QACA;AAAA,MAAA,CACA;AAED,aAAO,EAAE,QAAQ,eAAe,aAAa,eAAA;AAAA,IAC9C,CAAC;AAAA,EACF;AACD;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createTriggeredActionsListener = () => ({
|
|
4
|
+
onResponse: ({ response, context }) => {
|
|
5
|
+
const collector = context.executionContainer.triggeredActionsCollector;
|
|
6
|
+
if (!collector) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const events = collector.getEvents();
|
|
10
|
+
if (events.length === 0) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
response.extensions ?? (response.extensions = {});
|
|
14
|
+
response.extensions.triggeredActions = { events: [...events] };
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
exports.createTriggeredActionsListener = createTriggeredActionsListener;
|
|
18
|
+
//# sourceMappingURL=triggeredActionsListener.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggeredActionsListener.cjs","sources":["../../../../../packages/engine-http/src/content/triggeredActionsListener.ts"],"sourcesContent":["import { GraphQLListener } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\n\nexport const createTriggeredActionsListener = (): GraphQLListener<ContentGraphqlContext> => ({\n\tonResponse: ({ response, context }) => {\n\t\tconst collector = context.executionContainer.triggeredActionsCollector\n\t\tif (!collector) {\n\t\t\treturn\n\t\t}\n\t\tconst events = collector.getEvents()\n\t\tif (events.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tresponse.extensions ??= {}\n\t\tresponse.extensions.triggeredActions = { events: [...events] }\n\t},\n})\n"],"names":[],"mappings":";;AAGO,MAAM,iCAAiC,OAA+C;AAAA,EAC5F,YAAY,CAAC,EAAE,UAAU,cAAc;AACtC,UAAM,YAAY,QAAQ,mBAAmB;AAC7C,QAAI,CAAC,WAAW;AACf;AAAA,IACD;AACA,UAAM,SAAS,UAAU,UAAA;AACzB,QAAI,OAAO,WAAW,GAAG;AACxB;AAAA,IACD;AACA,aAAS,eAAT,SAAS,aAAe,CAAA;AACxB,aAAS,WAAW,mBAAmB,EAAE,QAAQ,CAAC,GAAG,MAAM,EAAA;AAAA,EAC5D;AACD;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const createTriggeredActionsListener = () => ({
|
|
2
|
+
onResponse: ({ response, context }) => {
|
|
3
|
+
const collector = context.executionContainer.triggeredActionsCollector;
|
|
4
|
+
if (!collector) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const events = collector.getEvents();
|
|
8
|
+
if (events.length === 0) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
response.extensions ?? (response.extensions = {});
|
|
12
|
+
response.extensions.triggeredActions = { events: [...events] };
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
export {
|
|
16
|
+
createTriggeredActionsListener
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=triggeredActionsListener.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triggeredActionsListener.js","sources":["../../../../../packages/engine-http/src/content/triggeredActionsListener.ts"],"sourcesContent":["import { GraphQLListener } from '../graphql'\nimport { ContentGraphqlContext } from './ContentGraphqlContext'\n\nexport const createTriggeredActionsListener = (): GraphQLListener<ContentGraphqlContext> => ({\n\tonResponse: ({ response, context }) => {\n\t\tconst collector = context.executionContainer.triggeredActionsCollector\n\t\tif (!collector) {\n\t\t\treturn\n\t\t}\n\t\tconst events = collector.getEvents()\n\t\tif (events.length === 0) {\n\t\t\treturn\n\t\t}\n\t\tresponse.extensions ??= {}\n\t\tresponse.extensions.triggeredActions = { events: [...events] }\n\t},\n})\n"],"names":[],"mappings":"AAGO,MAAM,iCAAiC,OAA+C;AAAA,EAC5F,YAAY,CAAC,EAAE,UAAU,cAAc;AACtC,UAAM,YAAY,QAAQ,mBAAmB;AAC7C,QAAI,CAAC,WAAW;AACf;AAAA,IACD;AACA,UAAM,SAAS,UAAU,UAAA;AACzB,QAAI,OAAO,WAAW,GAAG;AACxB;AAAA,IACD;AACA,aAAS,eAAT,SAAS,aAAe,CAAA;AACxB,aAAS,WAAW,mBAAmB,EAAE,QAAQ,CAAC,GAAG,MAAM,EAAA;AAAA,EAC5D;AACD;"}
|
|
@@ -6,13 +6,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
|
6
6
|
class CustomMetric {
|
|
7
7
|
constructor(options) {
|
|
8
8
|
this.options = options;
|
|
9
|
-
__publicField(this, "values",
|
|
9
|
+
__publicField(this, "values", /* @__PURE__ */ new Map());
|
|
10
10
|
}
|
|
11
11
|
reset() {
|
|
12
|
-
this.values
|
|
12
|
+
this.values.clear();
|
|
13
13
|
}
|
|
14
14
|
add(labels, value) {
|
|
15
|
-
this.
|
|
15
|
+
const key = this.labelKey(labels);
|
|
16
|
+
const existing = this.values.get(key);
|
|
17
|
+
if (existing) {
|
|
18
|
+
existing.value += value;
|
|
19
|
+
} else {
|
|
20
|
+
this.values.set(key, { labels, value });
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
23
|
get name() {
|
|
18
24
|
return this.options.name;
|
|
@@ -22,10 +28,17 @@ class CustomMetric {
|
|
|
22
28
|
help: this.options.help,
|
|
23
29
|
name: this.options.name,
|
|
24
30
|
type: this.options.type,
|
|
25
|
-
values: this.values,
|
|
31
|
+
values: Array.from(this.values.values()),
|
|
26
32
|
aggregator: "sum"
|
|
27
33
|
};
|
|
28
34
|
}
|
|
35
|
+
labelKey(labels) {
|
|
36
|
+
const parts = [];
|
|
37
|
+
for (const name of this.options.labelNames) {
|
|
38
|
+
parts.push(`${name}=${labels[name] ?? ""}`);
|
|
39
|
+
}
|
|
40
|
+
return parts.join("\0");
|
|
41
|
+
}
|
|
29
42
|
}
|
|
30
43
|
exports.CustomMetric = CustomMetric;
|
|
31
44
|
//# sourceMappingURL=CustomMetric.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomMetric.cjs","sources":["../../../../../packages/engine-http/src/prometheus/CustomMetric.ts"],"sourcesContent":["type LabelValues<T extends string> = Partial<Record<T, string | number>>\n\nexport class CustomMetric<T extends string> {\n\tprivate values
|
|
1
|
+
{"version":3,"file":"CustomMetric.cjs","sources":["../../../../../packages/engine-http/src/prometheus/CustomMetric.ts"],"sourcesContent":["type LabelValues<T extends string> = Partial<Record<T, string | number>>\n\nexport class CustomMetric<T extends string> {\n\tprivate values = new Map<string, { labels: LabelValues<T>; value: number }>()\n\n\tconstructor(\n\t\tprivate readonly options: {\n\t\t\tname: string\n\t\t\thelp: string\n\t\t\ttype: string\n\t\t\tlabelNames: T[]\n\t\t},\n\t) {\n\t}\n\n\treset() {\n\t\tthis.values.clear()\n\t}\n\n\tadd(labels: LabelValues<T>, value: number) {\n\t\tconst key = this.labelKey(labels)\n\t\tconst existing = this.values.get(key)\n\t\tif (existing) {\n\t\t\texisting.value += value\n\t\t} else {\n\t\t\tthis.values.set(key, { labels, value })\n\t\t}\n\t}\n\n\tget name() {\n\t\treturn this.options.name\n\t}\n\n\tget() {\n\t\treturn {\n\t\t\thelp: this.options.help,\n\t\t\tname: this.options.name,\n\t\t\ttype: this.options.type,\n\t\t\tvalues: Array.from(this.values.values()),\n\t\t\taggregator: 'sum',\n\t\t}\n\t}\n\n\tprivate labelKey(labels: LabelValues<T>): string {\n\t\tconst parts: string[] = []\n\t\tfor (const name of this.options.labelNames) {\n\t\t\tparts.push(`${name}=${labels[name] ?? ''}`)\n\t\t}\n\t\treturn parts.join('\\x00')\n\t}\n}\n"],"names":[],"mappings":";;;;;AAEO,MAAM,aAA+B;AAAA,EAG3C,YACkB,SAMhB;AANgB,SAAA,UAAA;AAHlB,kBAAA,MAAQ,8BAAa,IAAA,CAAuD;AAAA,EAU5E;AAAA,EAEA,QAAQ;AACP,SAAK,OAAO,MAAA;AAAA,EACb;AAAA,EAEA,IAAI,QAAwB,OAAe;AAC1C,UAAM,MAAM,KAAK,SAAS,MAAM;AAChC,UAAM,WAAW,KAAK,OAAO,IAAI,GAAG;AACpC,QAAI,UAAU;AACb,eAAS,SAAS;AAAA,IACnB,OAAO;AACN,WAAK,OAAO,IAAI,KAAK,EAAE,QAAQ,OAAO;AAAA,IACvC;AAAA,EACD;AAAA,EAEA,IAAI,OAAO;AACV,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,MAAM;AACL,WAAO;AAAA,MACN,MAAM,KAAK,QAAQ;AAAA,MACnB,MAAM,KAAK,QAAQ;AAAA,MACnB,MAAM,KAAK,QAAQ;AAAA,MACnB,QAAQ,MAAM,KAAK,KAAK,OAAO,QAAQ;AAAA,MACvC,YAAY;AAAA,IAAA;AAAA,EAEd;AAAA,EAEQ,SAAS,QAAgC;AAChD,UAAM,QAAkB,CAAA;AACxB,eAAW,QAAQ,KAAK,QAAQ,YAAY;AAC3C,YAAM,KAAK,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,EAAE,EAAE;AAAA,IAC3C;AACA,WAAO,MAAM,KAAK,IAAM;AAAA,EACzB;AACD;;"}
|
|
@@ -4,13 +4,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
|
4
4
|
class CustomMetric {
|
|
5
5
|
constructor(options) {
|
|
6
6
|
this.options = options;
|
|
7
|
-
__publicField(this, "values",
|
|
7
|
+
__publicField(this, "values", /* @__PURE__ */ new Map());
|
|
8
8
|
}
|
|
9
9
|
reset() {
|
|
10
|
-
this.values
|
|
10
|
+
this.values.clear();
|
|
11
11
|
}
|
|
12
12
|
add(labels, value) {
|
|
13
|
-
this.
|
|
13
|
+
const key = this.labelKey(labels);
|
|
14
|
+
const existing = this.values.get(key);
|
|
15
|
+
if (existing) {
|
|
16
|
+
existing.value += value;
|
|
17
|
+
} else {
|
|
18
|
+
this.values.set(key, { labels, value });
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
get name() {
|
|
16
22
|
return this.options.name;
|
|
@@ -20,10 +26,17 @@ class CustomMetric {
|
|
|
20
26
|
help: this.options.help,
|
|
21
27
|
name: this.options.name,
|
|
22
28
|
type: this.options.type,
|
|
23
|
-
values: this.values,
|
|
29
|
+
values: Array.from(this.values.values()),
|
|
24
30
|
aggregator: "sum"
|
|
25
31
|
};
|
|
26
32
|
}
|
|
33
|
+
labelKey(labels) {
|
|
34
|
+
const parts = [];
|
|
35
|
+
for (const name of this.options.labelNames) {
|
|
36
|
+
parts.push(`${name}=${labels[name] ?? ""}`);
|
|
37
|
+
}
|
|
38
|
+
return parts.join("\0");
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
export {
|
|
29
42
|
CustomMetric
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomMetric.js","sources":["../../../../../packages/engine-http/src/prometheus/CustomMetric.ts"],"sourcesContent":["type LabelValues<T extends string> = Partial<Record<T, string | number>>\n\nexport class CustomMetric<T extends string> {\n\tprivate values
|
|
1
|
+
{"version":3,"file":"CustomMetric.js","sources":["../../../../../packages/engine-http/src/prometheus/CustomMetric.ts"],"sourcesContent":["type LabelValues<T extends string> = Partial<Record<T, string | number>>\n\nexport class CustomMetric<T extends string> {\n\tprivate values = new Map<string, { labels: LabelValues<T>; value: number }>()\n\n\tconstructor(\n\t\tprivate readonly options: {\n\t\t\tname: string\n\t\t\thelp: string\n\t\t\ttype: string\n\t\t\tlabelNames: T[]\n\t\t},\n\t) {\n\t}\n\n\treset() {\n\t\tthis.values.clear()\n\t}\n\n\tadd(labels: LabelValues<T>, value: number) {\n\t\tconst key = this.labelKey(labels)\n\t\tconst existing = this.values.get(key)\n\t\tif (existing) {\n\t\t\texisting.value += value\n\t\t} else {\n\t\t\tthis.values.set(key, { labels, value })\n\t\t}\n\t}\n\n\tget name() {\n\t\treturn this.options.name\n\t}\n\n\tget() {\n\t\treturn {\n\t\t\thelp: this.options.help,\n\t\t\tname: this.options.name,\n\t\t\ttype: this.options.type,\n\t\t\tvalues: Array.from(this.values.values()),\n\t\t\taggregator: 'sum',\n\t\t}\n\t}\n\n\tprivate labelKey(labels: LabelValues<T>): string {\n\t\tconst parts: string[] = []\n\t\tfor (const name of this.options.labelNames) {\n\t\t\tparts.push(`${name}=${labels[name] ?? ''}`)\n\t\t}\n\t\treturn parts.join('\\x00')\n\t}\n}\n"],"names":[],"mappings":";;;AAEO,MAAM,aAA+B;AAAA,EAG3C,YACkB,SAMhB;AANgB,SAAA,UAAA;AAHlB,kBAAA,MAAQ,8BAAa,IAAA,CAAuD;AAAA,EAU5E;AAAA,EAEA,QAAQ;AACP,SAAK,OAAO,MAAA;AAAA,EACb;AAAA,EAEA,IAAI,QAAwB,OAAe;AAC1C,UAAM,MAAM,KAAK,SAAS,MAAM;AAChC,UAAM,WAAW,KAAK,OAAO,IAAI,GAAG;AACpC,QAAI,UAAU;AACb,eAAS,SAAS;AAAA,IACnB,OAAO;AACN,WAAK,OAAO,IAAI,KAAK,EAAE,QAAQ,OAAO;AAAA,IACvC;AAAA,EACD;AAAA,EAEA,IAAI,OAAO;AACV,WAAO,KAAK,QAAQ;AAAA,EACrB;AAAA,EAEA,MAAM;AACL,WAAO;AAAA,MACN,MAAM,KAAK,QAAQ;AAAA,MACnB,MAAM,KAAK,QAAQ;AAAA,MACnB,MAAM,KAAK,QAAQ;AAAA,MACnB,QAAQ,MAAM,KAAK,KAAK,OAAO,QAAQ;AAAA,MACvC,YAAY;AAAA,IAAA;AAAA,EAEd;AAAA,EAEQ,SAAS,QAAgC;AAChD,UAAM,QAAkB,CAAA;AACxB,eAAW,QAAQ,KAAK,QAAQ,YAAY;AAC3C,YAAM,KAAK,GAAG,IAAI,IAAI,OAAO,IAAI,KAAK,EAAE,EAAE;AAAA,IAC3C;AACA,WAAO,MAAM,KAAK,IAAM;AAAA,EACzB;AACD;"}
|
|
@@ -32,20 +32,23 @@ class ContentSchemaTransferMappingFactory {
|
|
|
32
32
|
name: column2.columnName,
|
|
33
33
|
type: column2.type,
|
|
34
34
|
nullable: column2.nullable,
|
|
35
|
-
values: schema$1.enums[column2.columnType]
|
|
35
|
+
values: schema$1.enums[column2.columnType],
|
|
36
|
+
list: column2.list
|
|
36
37
|
};
|
|
37
38
|
} else if (column2.type === schema.Model.ColumnType.Int) {
|
|
38
39
|
return {
|
|
39
40
|
name: column2.columnName,
|
|
40
41
|
type: column2.type,
|
|
41
42
|
nullable: column2.nullable,
|
|
43
|
+
list: column2.list,
|
|
42
44
|
sequence: column2.sequence !== void 0
|
|
43
45
|
};
|
|
44
46
|
} else {
|
|
45
47
|
return {
|
|
46
48
|
name: column2.columnName,
|
|
47
49
|
type: column2.type,
|
|
48
|
-
nullable: column2.nullable
|
|
50
|
+
nullable: column2.nullable,
|
|
51
|
+
list: column2.list
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSchemaTransferMappingFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema, options: {\n\t\texcludeTables?: readonly string[]\n\t} = {}): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined && !options.excludeTables?.includes(entity.tableName)) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\tif (!options.excludeTables?.includes(joiningTable.name)) {\n\t\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["schema","acceptFieldVisitor","column","Model","entity"],"mappings":";;;;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAuB,UAE9C,IAAqB;AACxB,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,UAAI,OAAO,SAAS,UAAa,CAAC,QAAQ,eAAe,SAAS,OAAO,SAAS,GAAG;AACpF,eAAO,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AACrF,YAAI,CAAC,QAAQ,eAAe,SAAS,aAAa,IAAI,GAAG;AACxD,iBAAO,aAAa,IAAI,IAAI;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAEA,WAAO,EAAE,OAAA;AAAA,EACV;AAAA,EAEQ,uBAAuBA,UAAsB,QAAyC;AAC7F,UAAM,UAA6B,CAAA;AAEnC,eAAW,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG;AACjD,YAAM,SAASC,YAAAA,mBAA0CD,UAAQ,QAAQ,OAAO;AAAA,QAC/E,aAAa,CAAC,EAAE,QAAAE,cAAa;AAC5B,cAAIA,QAAO,SAASC,aAAM,WAAW,MAAM;AAC1C,mBAAO;AAAA,cACN,MAAMD,QAAO;AAAA,cACb,MAAMA,QAAO;AAAA,cACb,UAAUA,QAAO;AAAA,cACjB,QAAQF,SAAO,MAAME,QAAO,UAAU;AAAA,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"ContentSchemaTransferMappingFactory.cjs","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema, options: {\n\t\texcludeTables?: readonly string[]\n\t} = {}): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined && !options.excludeTables?.includes(entity.tableName)) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\tif (!options.excludeTables?.includes(joiningTable.name)) {\n\t\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["schema","acceptFieldVisitor","column","Model","entity"],"mappings":";;;;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAuB,UAE9C,IAAqB;AACxB,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,UAAI,OAAO,SAAS,UAAa,CAAC,QAAQ,eAAe,SAAS,OAAO,SAAS,GAAG;AACpF,eAAO,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AACrF,YAAI,CAAC,QAAQ,eAAe,SAAS,aAAa,IAAI,GAAG;AACxD,iBAAO,aAAa,IAAI,IAAI;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAEA,W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;AAAA,QACvB,uBAAuB,MAAM;AAAA,MAAA,CAC7B;AAED,UAAI,WAAW,MAAM;AACpB,gBAAQ,OAAO,IAAI,IAAI;AAAA,MACxB;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAEQ,wBAAwBF,SAAsB,QAA8C;AACnG,UAAM,gBAAgB,CAAA;AAEtB,eAAW,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG;AACjD,YAAM,eAAeC,YAAAA,mBAAgDD,SAAQ,QAAQ,OAAO;AAAA,QAC3F,aAAa,MAAM;AAAA,QACnB,sBAAsB,MAAM;AAAA,QAC5B,iBAAiB,MAAM;AAAA,QACvB,wBAAwB,CAAC,EAAE,QAAAI,SAAQ,UAAU,oBAAoB;AAAA,UAChE,MAAM,SAAS,aAAa;AAAA,UAC5B,SAAS;AAAA,YACR,CAAC,SAAS,aAAa,cAAc,UAAU,GAAG;AAAA,cACjD,MAAM,SAAS,aAAa,cAAc;AAAA,cAC1C,MAAMA,QAAO,OAAOA,QAAO,OAAO,EAAE;AAAA,cACpC,UAAU;AAAA,YAAA;AAAA,YAEX,CAAC,SAAS,aAAa,qBAAqB,UAAU,GAAG;AAAA,cACxD,MAAM,SAAS,aAAa,qBAAqB;AAAA,cACjD,MAAM,aAAa,OAAO,aAAa,OAAO,EAAE;AAAA,cAChD,UAAU;AAAA,YAAA;AAAA,UACX;AAAA,QACD;AAAA,QAED,yBAAyB,MAAM;AAAA,QAC/B,iBAAiB,MAAM;AAAA,QACvB,uBAAuB,MAAM;AAAA,MAAA,CAC7B;AAED,UAAI,iBAAiB,MAAM;AAC1B,sBAAc,KAAK,YAAY;AAAA,MAChC;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AACD;;"}
|
|
@@ -30,20 +30,23 @@ class ContentSchemaTransferMappingFactory {
|
|
|
30
30
|
name: column2.columnName,
|
|
31
31
|
type: column2.type,
|
|
32
32
|
nullable: column2.nullable,
|
|
33
|
-
values: schema.enums[column2.columnType]
|
|
33
|
+
values: schema.enums[column2.columnType],
|
|
34
|
+
list: column2.list
|
|
34
35
|
};
|
|
35
36
|
} else if (column2.type === Model.ColumnType.Int) {
|
|
36
37
|
return {
|
|
37
38
|
name: column2.columnName,
|
|
38
39
|
type: column2.type,
|
|
39
40
|
nullable: column2.nullable,
|
|
41
|
+
list: column2.list,
|
|
40
42
|
sequence: column2.sequence !== void 0
|
|
41
43
|
};
|
|
42
44
|
} else {
|
|
43
45
|
return {
|
|
44
46
|
name: column2.columnName,
|
|
45
47
|
type: column2.type,
|
|
46
|
-
nullable: column2.nullable
|
|
48
|
+
nullable: column2.nullable,
|
|
49
|
+
list: column2.list
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
52
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSchemaTransferMappingFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema, options: {\n\t\texcludeTables?: readonly string[]\n\t} = {}): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined && !options.excludeTables?.includes(entity.tableName)) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\tif (!options.excludeTables?.includes(joiningTable.name)) {\n\t\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["column","entity"],"mappings":";;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAuB,UAE9C,IAAqB;AACxB,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,UAAI,OAAO,SAAS,UAAa,CAAC,QAAQ,eAAe,SAAS,OAAO,SAAS,GAAG;AACpF,eAAO,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AACrF,YAAI,CAAC,QAAQ,eAAe,SAAS,aAAa,IAAI,GAAG;AACxD,iBAAO,aAAa,IAAI,IAAI;AAAA,QAC7B;AAAA,MACD;AAAA,IACD;AAEA,WAAO,EAAE,OAAA;AAAA,EACV;AAAA,EAEQ,uBAAuB,QAAsB,QAAyC;AAC7F,UAAM,UAA6B,CAAA;AAEnC,eAAW,SAAS,OAAO,OAAO,OAAO,MAAM,GAAG;AACjD,YAAM,SAAS,mBAA0C,QAAQ,QAAQ,OAAO;AAAA,QAC/E,aAAa,CAAC,EAAE,QAAAA,cAAa;AAC5B,cAAIA,QAAO,SAAS,MAAM,WAAW,MAAM;AAC1C,mBAAO;AAAA,cACN,MAAMA,QAAO;AAAA,cACb,MAAMA,QAAO;AAAA,cACb,UAAUA,QAAO;AAAA,cACjB,QAAQ,OAAO,MAAMA,QAAO,UAAU;AAAA,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"ContentSchemaTransferMappingFactory.js","sources":["../../../../../packages/engine-http/src/transfer/ContentSchemaTransferMappingFactory.ts"],"sourcesContent":["import { Model, Schema } from '@contember/schema'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { DbColumnSchema, DbColumnSchemaMap, TransferMapping, TransferTableMapping } from './TransferMapping'\n\nexport class ContentSchemaTransferMappingFactory {\n\tcreateContentSchemaMapping(contentSchema: Schema, options: {\n\t\texcludeTables?: readonly string[]\n\t} = {}): TransferMapping {\n\t\tconst tables: Record<string, TransferTableMapping> = {}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tif (entity.view === undefined && !options.excludeTables?.includes(entity.tableName)) {\n\t\t\t\ttables[entity.tableName] = {\n\t\t\t\t\tname: entity.tableName,\n\t\t\t\t\tcolumns: this.buildDbColumnSchemaMap(contentSchema.model, entity),\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tfor (const entity of Object.values(contentSchema.model.entities)) {\n\t\t\tfor (const joiningTable of this.collectManyHasManyOwned(contentSchema.model, entity)) {\n\t\t\t\tif (!options.excludeTables?.includes(joiningTable.name)) {\n\t\t\t\t\ttables[joiningTable.name] = joiningTable\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { tables }\n\t}\n\n\tprivate buildDbColumnSchemaMap(schema: Model.Schema, entity: Model.Entity): DbColumnSchemaMap {\n\t\tconst columns: DbColumnSchemaMap = {}\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst column = acceptFieldVisitor<DbColumnSchema | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: ({ column }) => {\n\t\t\t\t\tif (column.type === Model.ColumnType.Enum) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tvalues: schema.enums[column.columnType],\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (column.type === Model.ColumnType.Int) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t\tsequence: column.sequence !== undefined,\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tname: column.columnName,\n\t\t\t\t\t\t\ttype: column.type,\n\t\t\t\t\t\t\tnullable: column.nullable,\n\t\t\t\t\t\t\tlist: column.list,\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tvisitOneHasOneOwning: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasOne: ({ relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningColumn.columnName,\n\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\tnullable: relation.nullable,\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyOwning: () => null,\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (column !== null) {\n\t\t\t\tcolumns[column.name] = column\n\t\t\t}\n\t\t}\n\n\t\treturn columns\n\t}\n\n\tprivate collectManyHasManyOwned(schema: Model.Schema, entity: Model.Entity): TransferTableMapping[] {\n\t\tconst joiningTables = []\n\n\t\tfor (const field of Object.values(entity.fields)) {\n\t\t\tconst joiningTable = acceptFieldVisitor<TransferTableMapping | null>(schema, entity, field, {\n\t\t\t\tvisitColumn: () => null,\n\t\t\t\tvisitOneHasOneOwning: () => null,\n\t\t\t\tvisitManyHasOne: () => null,\n\t\t\t\tvisitManyHasManyOwning: ({ entity, relation, targetEntity }) => ({\n\t\t\t\t\tname: relation.joiningTable.tableName,\n\t\t\t\t\tcolumns: {\n\t\t\t\t\t\t[relation.joiningTable.joiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.joiningColumn.columnName,\n\t\t\t\t\t\t\ttype: entity.fields[entity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t[relation.joiningTable.inverseJoiningColumn.columnName]: {\n\t\t\t\t\t\t\tname: relation.joiningTable.inverseJoiningColumn.columnName,\n\t\t\t\t\t\t\ttype: targetEntity.fields[targetEntity.primary].type as (Model.ColumnType.Uuid | Model.ColumnType.Int),\n\t\t\t\t\t\t\tnullable: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t\tvisitManyHasManyInverse: () => null,\n\t\t\t\tvisitOneHasMany: () => null,\n\t\t\t\tvisitOneHasOneInverse: () => null,\n\t\t\t})\n\n\t\t\tif (joiningTable !== null) {\n\t\t\t\tjoiningTables.push(joiningTable)\n\t\t\t}\n\t\t}\n\n\t\treturn joiningTables\n\t}\n}\n"],"names":["column","entity"],"mappings":";;AAIO,MAAM,oCAAoC;AAAA,EAChD,2BAA2B,eAAuB,UAE9C,IAAqB;AACxB,UAAM,SAA+C,CAAA;AAErD,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,UAAI,OAAO,SAAS,UAAa,CAAC,QAAQ,eAAe,SAAS,OAAO,SAAS,GAAG;AACpF,eAAO,OAAO,SAAS,IAAI;AAAA,UAC1B,MAAM,OAAO;AAAA,UACb,SAAS,KAAK,uBAAuB,cAAc,OAAO,MAAM;AAAA,QAAA;AAAA,MAElE;AAAA,IACD;AAEA,eAAW,UAAU,OAAO,OAAO,cAAc,MAAM,QAAQ,GAAG;AACjE,iBAAW,gBAAgB,KAAK,wBAAwB,cAAc,OAAO,MAAM,GAAG;AACrF,YAAI,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
let builder = db.selectBuilder().from(table.name);
|
|
114
114
|
for (const column of Object.values(table.columns)) {
|
|
115
|
-
if (column.type === schema.Model.ColumnType.Json || column.type === schema.Model.ColumnType.Date || column.type === schema.Model.ColumnType.DateTime) {
|
|
115
|
+
if (column.list && (column.type === schema.Model.ColumnType.Enum || column.type === schema.Model.ColumnType.Json || column.type === schema.Model.ColumnType.Date || column.type === schema.Model.ColumnType.DateTime)) {
|
|
116
|
+
builder = builder.select((expr) => expr.raw(`${Database.wrapIdentifier(column.name)}::text[]`));
|
|
117
|
+
} else if (column.list) {
|
|
118
|
+
builder = builder.select(column.name);
|
|
119
|
+
} else if (column.type === schema.Model.ColumnType.Json || column.type === schema.Model.ColumnType.Date || column.type === schema.Model.ColumnType.DateTime) {
|
|
116
120
|
builder = builder.select((expr) => expr.raw(`${Database.wrapIdentifier(column.name)}::text`));
|
|
117
121
|
} else {
|
|
118
122
|
builder = builder.select(column.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncIterableTransaction","db","Model","wrapIdentifier","Compiler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,gBAAgBA,oBAAS,OAAO;AAAA;AAAA,EAE5C,UAAUA,oBAAS,MAAMA,oBAAS;AAAA,IACjCA,oBAAS,OAAO;AAAA,MACf,MAAMA,oBAAS;AAAA,MACf,QAAQA,oBAAS;AAAA,IAAA,CACjB;AAAA,IACDA,oBAAS,QAAQ;AAAA,MAChB,YAAYA,oBAAS;AAAA,MACrB,eAAeA,oBAAS,MAAMA,oBAAS,MAAM;AAAA,IAAA,CAC7C;AAAA,EAAA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;AAChF,gBAAQ;AAAA,MACT;AAEA,YAAM,CAAC,aAAa,OAAO,OAAO,GAAG,CAAC;AAAA,IACvC;AAEA,QAAI,CAAC,OAAO;AACX,YAAM,CAAC,WAAW;AAAA,IACnB;AAAA,EACD;AAAA,EAEQ,WAAW,IAAwC,OAA6B;AACvF,QAAI,UAAU,GAAG,cAAA,EAAgB,KAAK,MAAM,IAAI;AAEhD,eAAW,UAAU,OAAO,OAAO,MAAM,OAAO,GAAG;AAClD,UAAI,OAAO,SAASD,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,UAAU;AAChI,kBAAU,QAAQ,OAAO,CAAA,SAAQ,KAAK,IAAI,GAAGC,SAAAA,eAAe,OAAO,IAAI,CAAC,QAAQ,CAAC;AAAA,MAClF,OAAO;AACN,kBAAU,QAAQ,OAAO,OAAO,IAAI;AAAA,MACrC;AAAA,IACD;AAEA,UAAM,mBAAmB,IAAIC,kBAAS,QAAQ,GAAG,QAAQ,oBAAI,KAAK;AAClE,WAAO,QAAQ,YAAY,gBAAgB;AAAA,EAC5C;AAAA,EAEA,OAAe,YAAY,IAAwC,WAAmB,KAAa,aAA6B,CAAA,GAAI;AACnI,UAAM,GAAG,MAAM,iDAAiD,GAAG,IAAI,UAAU;AAEjF,UAAM,WAAW,SAAS,OAAO,SAAS,CAAC;AAC3C,QAAI,gBAAmD,GAAG,MAAM,QAAQ;AAExE,WAAO,kBAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,uBAAiB,OAAO,YAAY,KAAK,YAAY,OAAO,GAAG,MAAM,QAAQ;AAC7E,aAAO,OAAO;AAAA,IACf;AAEA,UAAM,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;;;"}
|
|
1
|
+
{"version":3,"file":"ExportExecutor.cjs","sources":["../../../../../packages/engine-http/src/transfer/ExportExecutor.ts"],"sourcesContent":["import { asyncIterableTransaction, Client, Compiler, Connection, wrapIdentifier } from '@contember/database'\nimport { Command } from './Command'\nimport { TransferMapping, TransferTableMapping } from './TransferMapping'\nimport { Model } from '@contember/schema'\nimport { ContentSchemaTransferMappingFactory } from './ContentSchemaTransferMappingFactory'\nimport { SystemSchemaTransferMappingFactory } from './SystemSchemaTransferMappingFactory'\nimport * as Typesafe from '@contember/typesafe'\nimport { StagesQuery } from '@contember/engine-system-api'\nimport { ProjectContainer } from '../project'\n\nexport type ExportRequest = ReturnType<typeof ExportRequest>\nexport const ExportRequest = Typesafe.object({\n\t// tenant: Typesafe.boolean,\n\tprojects: Typesafe.array(Typesafe.intersection(\n\t\tTypesafe.object({\n\t\t\tslug: Typesafe.string,\n\t\t\tsystem: Typesafe.boolean,\n\t\t}),\n\t\tTypesafe.partial({\n\t\t\ttargetSlug: Typesafe.string,\n\t\t\texcludeTables: Typesafe.array(Typesafe.string),\n\t\t}),\n\t)),\n})\n\nexport class ExportExecutor {\n\tconstructor(\n\t\tprivate readonly contentSchemaTransferMappingFactory: ContentSchemaTransferMappingFactory,\n\t\tprivate readonly systemSchemaTransferMappingFactory: SystemSchemaTransferMappingFactory,\n\t) {\n\t}\n\n\tasync *export(request: ExportRequest, projectContainers: Record<string, ProjectContainer>): AsyncIterable<Command> {\n\t\tfor (const project of request.projects) {\n\t\t\tconst projectContainer = projectContainers[project.slug]\n\t\t\tconst systemContext = projectContainer.systemDatabaseContext\n\n\t\t\tif (project.system) {\n\t\t\t\tconst systemMapping = this.systemSchemaTransferMappingFactory.build({\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tyield ['importSystemSchemaBegin', { project: project.targetSlug ?? project.slug, tables: Object.keys(systemMapping.tables) }]\n\t\t\t\tyield* this.exportSchema(systemContext.client, systemMapping)\n\t\t\t}\n\n\t\t\tfor (const stage of await systemContext.queryHandler.fetch(new StagesQuery())) {\n\t\t\t\tconst contentSchema = await projectContainer.contentSchemaResolver.getSchema({ db: systemContext, stage: stage.slug })\n\t\t\t\tconst contentMapping = this.contentSchemaTransferMappingFactory.createContentSchemaMapping(contentSchema.schema, {\n\t\t\t\t\texcludeTables: project.excludeTables ?? [],\n\t\t\t\t})\n\t\t\t\tconst contentDatabaseClient = projectContainer.connection.createClient(stage.schema, {})\n\n\t\t\t\tyield [\n\t\t\t\t\t'importContentSchemaBegin',\n\t\t\t\t\t{\n\t\t\t\t\t\tproject: project.targetSlug ?? project.slug,\n\t\t\t\t\t\tstage: stage.slug,\n\t\t\t\t\t\tschemaVersion: contentSchema.meta.version ?? '0000-00-00-000000',\n\t\t\t\t\t\ttables: Object.keys(contentMapping.tables),\n\t\t\t\t\t},\n\t\t\t\t]\n\n\t\t\t\tyield* this.exportSchema(contentDatabaseClient, contentMapping)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportSchema(db: Client, mapping: TransferMapping): AsyncIterable<Command> {\n\t\tconst that = this\n\t\tyield* asyncIterableTransaction(db, async function*(db) {\n\t\t\tawait db.query('SET LOCAL statement_timeout = 0')\n\t\t\tawait db.query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE')\n\t\t\tfor (const table of Object.values(mapping.tables)) {\n\t\t\t\tyield* that.exportSequences(db, table)\n\t\t\t\tyield* that.exportTable(db, table)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async *exportSequences(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (column.type === Model.ColumnType.Int && column.sequence) {\n\t\t\t\tconst seqNameResult = await db.query<{ name: string }>(\n\t\t\t\t\t'SELECT pg_get_serial_sequence(?, ?) AS name',\n\t\t\t\t\t[`${db.schema}.${table.name}`, column.name],\n\t\t\t\t)\n\n\t\t\t\tconst seqNameQuoted = seqNameResult.rows[0].name.split('.').map(it => wrapIdentifier(it)).join('.')\n\t\t\t\tconst seqValueResult = await db.query<{ last_value: number | string }>(`SELECT last_value FROM ${seqNameQuoted}`)\n\t\t\t\tconst seqValue = seqValueResult.rows[0].last_value\n\t\t\t\tyield ['importSequence', { table: table.name, column: column.name, value: Number(seqValue) }]\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async *exportTable(db: Client<Connection.TransactionLike>, table: TransferTableMapping): AsyncIterable<Command> {\n\t\tconst DB_FETCH_BATCH_SIZE = 100\n\t\tconst query = (table.createSelect ?? this.buildQuery)(db, table)\n\t\tlet empty = true\n\n\t\tfor await (const row of this.cursorQuery(db, DB_FETCH_BATCH_SIZE, query.sql, query.parameters)) {\n\t\t\tif (empty) {\n\t\t\t\tyield ['insertBegin', { table: table.name, columns: Object.keys(table.columns) }]\n\t\t\t\tempty = false\n\t\t\t}\n\n\t\t\tyield ['insertRow', Object.values(row)]\n\t\t}\n\n\t\tif (!empty) {\n\t\t\tyield ['insertEnd']\n\t\t}\n\t}\n\n\tprivate buildQuery(db: Client<Connection.TransactionLike>, table: TransferTableMapping) {\n\t\tlet builder = db.selectBuilder().from(table.name)\n\n\t\tfor (const column of Object.values(table.columns)) {\n\t\t\tif (\n\t\t\t\tcolumn.list\n\t\t\t\t&& (column.type === Model.ColumnType.Enum || column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date\n\t\t\t\t\t|| column.type === Model.ColumnType.DateTime)\n\t\t\t) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text[]`))\n\t\t\t} else if (column.list) {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t} else if (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {\n\t\t\t\tbuilder = builder.select(expr => expr.raw(`${wrapIdentifier(column.name)}::text`))\n\t\t\t} else {\n\t\t\t\tbuilder = builder.select(column.name)\n\t\t\t}\n\t\t}\n\n\t\tconst namespaceContext = new Compiler.Context(db.schema, new Set())\n\t\treturn builder.createQuery(namespaceContext)\n\t}\n\n\tprivate async *cursorQuery(db: Client<Connection.TransactionLike>, batchSize: number, sql: string, parameters: readonly any[] = []) {\n\t\tawait db.query(`DECLARE contember_cursor NO SCROLL CURSOR FOR ${sql}`, parameters)\n\n\t\tconst fetchSql = `FETCH ${Number(batchSize)} FROM contember_cursor`\n\t\tlet resultPromise: Promise<Connection.Result> | null = db.query(fetchSql)\n\n\t\twhile (resultPromise !== null) {\n\t\t\tconst result: Connection.Result = await resultPromise\n\t\t\tresultPromise = (result.rowCount ?? 0) < batchSize ? null : db.query(fetchSql) // pipeline\n\t\t\tyield* result.rows\n\t\t}\n\n\t\tawait db.query(`CLOSE contember_cursor`)\n\t}\n}\n"],"names":["Typesafe","StagesQuery","asyncIterableTransaction","db","Model","wrapIdentifier","Compiler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWO,MAAM,gBAAgBA,oBAAS,OAAO;AAAA;AAAA,EAE5C,UAAUA,oBAAS,MAAMA,oBAAS;AAAA,IACjCA,oBAAS,OAAO;AAAA,MACf,MAAMA,oBAAS;AAAA,MACf,QAAQA,oBAAS;AAAA,IAAA,CACjB;AAAA,IACDA,oBAAS,QAAQ;AAAA,MAChB,YAAYA,oBAAS;AAAA,MACrB,eAAeA,oBAAS,MAAMA,oBAAS,MAAM;AAAA,IAAA,CAC7C;AAAA,EAAA,CACD;AACF,CAAC;AAEM,MAAM,eAAe;AAAA,EAC3B,YACkB,qCACA,oCAChB;AAFgB,SAAA,sCAAA;AACA,SAAA,qCAAA;AAAA,EAElB;AAAA,EAEA,OAAO,OAAO,SAAwB,mBAA6E;AAClH,eAAW,WAAW,QAAQ,UAAU;AACvC,YAAM,mBAAmB,kBAAkB,QAAQ,IAAI;AACvD,YAAM,gBAAgB,iBAAiB;AAEvC,UAAI,QAAQ,QAAQ;AACnB,cAAM,gBAAgB,KAAK,mCAAmC,MAAM;AAAA,UACnE,eAAe,QAAQ,iBAAiB,CAAA;AAAA,QAAC,CACzC;AACD,cAAM,CAAC,2BAA2B,EAAE,SAAS,QAAQ,cAAc,QAAQ,MA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M,WAAW,WACpC;AACD,kBAAU,QAAQ,OAAO,CAAA,SAAQ,KAAK,IAAI,GAAGC,SAAAA,eAAe,OAAO,IAAI,CAAC,UAAU,CAAC;AAAA,MACpF,WAAW,OAAO,MAAM;AACvB,kBAAU,QAAQ,OAAO,OAAO,IAAI;AAAA,MACrC,WAAW,OAAO,SAASD,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,QAAQ,OAAO,SAASA,OAAAA,MAAM,WAAW,UAAU;AACvI,kBAAU,QAAQ,OAAO,CAAA,SAAQ,KAAK,IAAI,GAAGC,SAAAA,eAAe,OAAO,IAAI,CAAC,QAAQ,CAAC;AAAA,MAClF,OAAO;AACN,kBAAU,QAAQ,OAAO,OAAO,IAAI;AAAA,MACrC;AAAA,IACD;AAEA,UAAM,mBAAmB,IAAIC,kBAAS,QAAQ,GAAG,QAAQ,oBAAI,KAAK;AAClE,WAAO,QAAQ,YAAY,gBAAgB;AAAA,EAC5C;AAAA,EAEA,OAAe,YAAY,IAAwC,WAAmB,KAAa,aAA6B,CAAA,GAAI;AACnI,UAAM,GAAG,MAAM,iDAAiD,GAAG,IAAI,UAAU;AAEjF,UAAM,WAAW,SAAS,OAAO,SAAS,CAAC;AAC3C,QAAI,gBAAmD,GAAG,MAAM,QAAQ;AAExE,WAAO,kBAAkB,MAAM;AAC9B,YAAM,SAA4B,MAAM;AACxC,uBAAiB,OAAO,YAAY,KAAK,YAAY,OAAO,GAAG,MAAM,QAAQ;AAC7E,aAAO,OAAO;AAAA,IACf;AAEA,UAAM,GAAG,MAAM,wBAAwB;AAAA,EACxC;AACD;;;"}
|
|
@@ -93,7 +93,11 @@ class ExportExecutor {
|
|
|
93
93
|
buildQuery(db, table) {
|
|
94
94
|
let builder = db.selectBuilder().from(table.name);
|
|
95
95
|
for (const column of Object.values(table.columns)) {
|
|
96
|
-
if (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {
|
|
96
|
+
if (column.list && (column.type === Model.ColumnType.Enum || column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime)) {
|
|
97
|
+
builder = builder.select((expr) => expr.raw(`${wrapIdentifier(column.name)}::text[]`));
|
|
98
|
+
} else if (column.list) {
|
|
99
|
+
builder = builder.select(column.name);
|
|
100
|
+
} else if (column.type === Model.ColumnType.Json || column.type === Model.ColumnType.Date || column.type === Model.ColumnType.DateTime) {
|
|
97
101
|
builder = builder.select((expr) => expr.raw(`${wrapIdentifier(column.name)}::text`));
|
|
98
102
|
} else {
|
|
99
103
|
builder = builder.select(column.name);
|