@contember/engine-content-api 2.1.0-alpha.3 → 2.1.0-alpha.30
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/index.cjs +0 -2
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +0 -2
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/ExecutionContainer.cjs +5 -4
- package/dist/development/src/ExecutionContainer.cjs.map +1 -1
- package/dist/development/src/ExecutionContainer.js +5 -4
- package/dist/development/src/ExecutionContainer.js.map +1 -1
- package/dist/development/src/mapper/Result.cjs +1 -1
- package/dist/development/src/mapper/Result.cjs.map +1 -1
- package/dist/development/src/mapper/Result.js +1 -1
- package/dist/development/src/mapper/Result.js.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.cjs +6 -2
- package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/development/src/mapper/select/ConditionBuilder.js +7 -3
- package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +6 -2
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +6 -2
- package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/development/src/mapper/update/Updater.cjs +15 -3
- package/dist/development/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/development/src/mapper/update/Updater.js +16 -4
- package/dist/development/src/mapper/update/Updater.js.map +1 -1
- package/dist/development/src/resolvers/RefreshViewResolver.cjs +3 -2
- package/dist/development/src/resolvers/RefreshViewResolver.cjs.map +1 -1
- package/dist/development/src/resolvers/RefreshViewResolver.js +3 -2
- package/dist/development/src/resolvers/RefreshViewResolver.js.map +1 -1
- package/dist/development/src/schema/ConditionTypeProvider.cjs +2 -0
- package/dist/development/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/development/src/schema/ConditionTypeProvider.js +2 -0
- package/dist/development/src/schema/ConditionTypeProvider.js.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs +9 -2
- package/dist/development/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
- package/dist/development/src/schema/RefreshViewMutationProvider.js +10 -3
- package/dist/development/src/schema/RefreshViewMutationProvider.js.map +1 -1
- package/dist/production/index.cjs +0 -2
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +0 -2
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/ExecutionContainer.cjs +5 -4
- package/dist/production/src/ExecutionContainer.cjs.map +1 -1
- package/dist/production/src/ExecutionContainer.js +5 -4
- package/dist/production/src/ExecutionContainer.js.map +1 -1
- package/dist/production/src/mapper/Result.cjs +1 -1
- package/dist/production/src/mapper/Result.cjs.map +1 -1
- package/dist/production/src/mapper/Result.js +1 -1
- package/dist/production/src/mapper/Result.js.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.cjs +6 -2
- package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
- package/dist/production/src/mapper/select/ConditionBuilder.js +7 -3
- package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +6 -2
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +6 -2
- package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
- package/dist/production/src/mapper/update/Updater.cjs +15 -3
- package/dist/production/src/mapper/update/Updater.cjs.map +1 -1
- package/dist/production/src/mapper/update/Updater.js +16 -4
- package/dist/production/src/mapper/update/Updater.js.map +1 -1
- package/dist/production/src/resolvers/RefreshViewResolver.cjs +3 -2
- package/dist/production/src/resolvers/RefreshViewResolver.cjs.map +1 -1
- package/dist/production/src/resolvers/RefreshViewResolver.js +3 -2
- package/dist/production/src/resolvers/RefreshViewResolver.js.map +1 -1
- package/dist/production/src/schema/ConditionTypeProvider.cjs +2 -0
- package/dist/production/src/schema/ConditionTypeProvider.cjs.map +1 -1
- package/dist/production/src/schema/ConditionTypeProvider.js +2 -0
- package/dist/production/src/schema/ConditionTypeProvider.js.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs +9 -2
- package/dist/production/src/schema/RefreshViewMutationProvider.cjs.map +1 -1
- package/dist/production/src/schema/RefreshViewMutationProvider.js +10 -3
- package/dist/production/src/schema/RefreshViewMutationProvider.js.map +1 -1
- package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.d.ts.map +1 -0
- package/dist/tests/src/test.d.ts.map +1 -1
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/ExecutionContainer.d.ts +13 -3
- package/dist/types/ExecutionContainer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mapper/Result.d.ts +2 -2
- package/dist/types/mapper/Result.d.ts.map +1 -1
- package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
- package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts +6 -1
- package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
- package/dist/types/mapper/update/Updater.d.ts +1 -5
- package/dist/types/mapper/update/Updater.d.ts.map +1 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts +3 -1
- package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
- package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
- package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/graphql.codegen.yml +1 -1
- package/package.json +10 -10
- package/src/ExecutionContainer.ts +9 -5
- package/src/index.ts +2 -1
- package/src/mapper/Result.ts +2 -2
- package/src/mapper/select/ConditionBuilder.ts +11 -5
- package/src/mapper/select/optimizer/WhereOptimizer.ts +10 -1
- package/src/mapper/update/Updater.ts +16 -5
- package/src/resolvers/RefreshViewResolver.ts +3 -3
- package/src/schema/ConditionTypeProvider.ts +3 -0
- package/src/schema/RefreshViewMutationProvider.ts +9 -2
- package/tests/cases/integration/graphQlRequests/insert/subOperationFail.test.ts +105 -0
- package/tests/cases/integration/graphQlRequests/update/additionalFilter.test.ts +51 -2
- package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
- package/tests/src/test.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WhereOptimizer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers'\nimport { replaceWhere } from './WhereReplacer'\n\ntype ExtendedRelationContext =\n\t& {\n\t\tcontext: Model.AnyRelationContext\n\t\tcanEliminate: boolean\n\t\tisLast: boolean\n\t}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t) {\n\t}\n\n\tpublic optimize(where: Input.OptionalWhere, entity: Model.Entity, { relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {}): Input.OptionalWhere {\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\treturn this.optimize(result, entity)\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand = undefined\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\tprivate optimizeOr(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(operands: Input.OptionalWhere[], entity: Model.Entity, replacement: Input.Condition, relationPath: ExtendedRelationContext[]): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = result.length\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\tlet where = value as Input.OptionalWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t},\n\t\t})\n\t}\n}\n"],"names":["_WhereOptimizer","replaceWhere","optimizeNot","optimizeOr","optimizeAnd","acceptFieldVisitor"],"mappings":";;;;;;;;AAoBO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBAChB;AAFgB,SAAA,QAAA;AACA,SAAA,qBAAA;AAAA,EAAA;AAAA,EAIX,SAAS,OAA4B,QAAsB,EAAE,eAAe,CAAA,GAAI,sBAAsB,GAA+B,IAAA,IAAyB;AACpK,QAAI,wBAAmD,CAAC;AACxD,eAAW,KAAK,cAAc;AACvB,YAAA,KAAK,aAAa,CAAC;AACzB,UAAI,CAACA,iBAAe,oBAAoB,IAAI,GAAG,IAAI,GAAG;AACrD,gCAAwB,CAAC;AAAA,MAAA,OACnB;AACN,8BAAsB,KAAK,EAAE,SAAS,IAAI,cAAc,MAAM,QAAQ,OAAO,CAAC,MAAM,aAAa,OAAA,CAAQ;AAAA,MAAA;AAAA,IAC1G;AAED,QAAI,SAAS,KAAK,cAAc,OAAO,QAAQ,qBAAqB;AAEhE,QAAA,OAAO,WAAW,WAAW;AAChC,aAAO,EAAE,CAAC,OAAO,OAAO,GAAG,EA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E,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,QAAQ,MAAA,KAAW,EAAE,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,QAAQ,KAAK,GAAG;AAAA,UAAA;AAAA,QACxI,OACM;AAEN,gBAAM,eAAe,WAAW,KAAK,aAAa,SAAS,CAAC,EAAE;AAC9D,0BAAgB,KAAK,EAAE,SAAS,QAAQ,OAAO,cAAc;AAAA,QAAA;AAE9D,cAAM,iBAAiB,KAAK,cAAc,OAAO,QAAQ,cAAc,eAAe;AAElF,YAAA,OAAO,mBAAmB,WAAW;AACjC,iBAAA;AAAA,QAAA;AAGR,eAAO,EAAE,CAAC,GAAG,GAAG,eAAe;AAAA,MAAA;AAAA,IAChC,CACA;AAAA,EAAA;AAEH;AA9KC,cADY,iBACG,uBAA0B,oBAAA,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;;"}
|
|
1
|
+
{"version":3,"file":"WhereOptimizer.cjs","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers'\nimport { replaceWhere } from './WhereReplacer'\n\ntype ExtendedRelationContext =\n\t& {\n\t\tcontext: Model.AnyRelationContext\n\t\tcanEliminate: boolean\n\t\tisLast: boolean\n\t}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(where: Input.OptionalWhere, entity: Model.Entity, { relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {}): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\treturn this.optimize(result, entity)\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand = undefined\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\tprivate optimizeOr(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(operands: Input.OptionalWhere[], entity: Model.Entity, replacement: Input.Condition, relationPath: ExtendedRelationContext[]): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\tlet where = value as Input.OptionalWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t},\n\t\t})\n\t}\n}\n"],"names":["_WhereOptimizer","replaceWhere","optimizeNot","optimizeOr","optimizeAnd","acceptFieldVisitor"],"mappings":";;;;;;;;AAyBO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBACA,SAChB;AAHgB,SAAA,QAAA;AACA,SAAA,qBAAA;AACA,SAAA,UAAA;AAAA,EAAA;AAAA,EAIX,SAAS,OAA4B,QAAsB,EAAE,eAAe,CAAA,GAAI,sBAAsB,GAA+B,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, writable: true, value }) : obj[key] = value;
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
7
7
|
const _WhereOptimizer = class _WhereOptimizer2 {
|
|
8
|
-
constructor(model, conditionOptimizer) {
|
|
8
|
+
constructor(model, conditionOptimizer, options) {
|
|
9
9
|
this.model = model;
|
|
10
10
|
this.conditionOptimizer = conditionOptimizer;
|
|
11
|
+
this.options = options;
|
|
11
12
|
}
|
|
12
13
|
optimize(where, entity, { relationPath = [], evaluatedPredicates = [] } = {}) {
|
|
14
|
+
if (this.options?.disable) {
|
|
15
|
+
return where;
|
|
16
|
+
}
|
|
13
17
|
let processedRelationPath = [];
|
|
14
18
|
for (const i in relationPath) {
|
|
15
19
|
const el = relationPath[i];
|
|
@@ -105,7 +109,7 @@ const _WhereOptimizer = class _WhereOptimizer2 {
|
|
|
105
109
|
crossOptimize(operands, entity, replacement, relationPath) {
|
|
106
110
|
let result = operands;
|
|
107
111
|
let copied = false;
|
|
108
|
-
const count = result.length;
|
|
112
|
+
const count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50);
|
|
109
113
|
for (let i = 0; i < count; i++) {
|
|
110
114
|
for (let j = 0; j < count; j++) {
|
|
111
115
|
const a = result[j];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WhereOptimizer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers'\nimport { replaceWhere } from './WhereReplacer'\n\ntype ExtendedRelationContext =\n\t& {\n\t\tcontext: Model.AnyRelationContext\n\t\tcanEliminate: boolean\n\t\tisLast: boolean\n\t}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t) {\n\t}\n\n\tpublic optimize(where: Input.OptionalWhere, entity: Model.Entity, { relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {}): Input.OptionalWhere {\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\treturn this.optimize(result, entity)\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand = undefined\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\tprivate optimizeOr(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(operands: Input.OptionalWhere[], entity: Model.Entity, replacement: Input.Condition, relationPath: ExtendedRelationContext[]): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = result.length\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\tlet where = value as Input.OptionalWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedWhere }\n\t\t\t},\n\t\t})\n\t}\n}\n"],"names":["_WhereOptimizer"],"mappings":";;;;;;AAoBO,MAAM,kBAAN,MAAMA,iBAAe;AAAA,EAG3B,YACkB,OACA,oBAChB;AAFgB,SAAA,QAAA;AACA,SAAA,qBAAA;AAAA,EAAA;AAAA,EAIX,SAAS,OAA4B,QAAsB,EAAE,eAAe,CAAA,GAAI,sBAAsB,GAA+B,IAAA,IAAyB;AACpK,QAAI,wBAAmD,CAAC;AAC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SAAS,MAAM;AAC5F,gBAAA,OAAO,gBAAgB,IAAI;AAC3B,gBAAA,OAAO,KAAM,QAAQ;AAC3B,cAAI,MAAM,iBAAiB,SAAS,gBAAgB,SAAS,qBAAqB,SAAS,qBAAqB;AACvG,oBAAA,aAAa,OAAO,EAAE,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,QAAQ,KAAA,KAAU,EAAE,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,OAAO,KAAK,GAAG;AAC7H,oBAAA,aAAa,OAAO,EAAE,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,QAAQ,MAAA,KAAW,EAAE,CAAC,QAAQ,aAAa,OAAO,GAAG,EAAE,QAAQ,KAAK,GAAG;AAAA,UAAA;AAAA,QACxI,OACM;AAEN,gBAAM,eAAe,WAAW,KAAK,aAAa,SAAS,CAAC,EAAE;AAC9D,0BAAgB,KAAK,EAAE,SAAS,QAAQ,OAAO,cAAc;AAAA,QAAA;AAE9D,cAAM,iBAAiB,KAAK,cAAc,OAAO,QAAQ,cAAc,eAAe;AAElF,YAAA,OAAO,mBAAmB,WAAW;AACjC,iBAAA;AAAA,QAAA;AAGR,eAAO,EAAE,CAAC,GAAG,GAAG,eAAe;AAAA,MAAA;AAAA,IAChC,CACA;AAAA,EAAA;AAEH;AA9KC,cADY,iBACG,uBAA0B,oBAAA,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;"}
|
|
1
|
+
{"version":3,"file":"WhereOptimizer.js","sources":["../../../../../../../packages/engine-content-api/src/mapper/select/optimizer/WhereOptimizer.ts"],"sourcesContent":["import { Input, Model } from '@contember/schema'\nimport { ConditionOptimizer } from './ConditionOptimizer'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { optimizeAnd, optimizeNot, optimizeOr } from './helpers'\nimport { replaceWhere } from './WhereReplacer'\n\ntype ExtendedRelationContext =\n\t& {\n\t\tcontext: Model.AnyRelationContext\n\t\tcanEliminate: boolean\n\t\tisLast: boolean\n\t}\n\nexport interface WhereOptimizationHints {\n\trelationPath?: Model.AnyRelationContext[]\n\tevaluatedPredicates?: Input.OptionalWhere[]\n}\n\ntype OptimizedOperand = Input.OptionalWhere | undefined | boolean\n\nexport type WhereOptimizerOptions = {\n\tdisable?: boolean\n\tmaxCrossOptimizationInput?: number\n}\n\nexport class WhereOptimizer {\n\tprivate static eliminableRelations = new Set<Model.AnyRelationContext['type']>(['oneHasMany', 'oneHasOneInverse', 'oneHasOneOwning'])\n\n\tconstructor(\n\t\tprivate readonly model: Model.Schema,\n\t\tprivate readonly conditionOptimizer: ConditionOptimizer,\n\t\tprivate readonly options?: WhereOptimizerOptions,\n\t) {\n\t}\n\n\tpublic optimize(where: Input.OptionalWhere, entity: Model.Entity, { relationPath = [], evaluatedPredicates = [] }: WhereOptimizationHints = {}): Input.OptionalWhere {\n\t\tif (this.options?.disable) {\n\t\t\treturn where\n\t\t}\n\t\tlet processedRelationPath: ExtendedRelationContext[] = []\n\t\tfor (const i in relationPath) {\n\t\t\tconst el = relationPath[i]\n\t\t\tif (!WhereOptimizer.eliminableRelations.has(el.type)) {\n\t\t\t\tprocessedRelationPath = []\n\t\t\t} else {\n\t\t\t\tprocessedRelationPath.push({ context: el, canEliminate: true, isLast: Number(i) === relationPath.length })\n\t\t\t}\n\t\t}\n\t\tlet result = this.optimizeWhere(where, entity, processedRelationPath)\n\n\t\tif (typeof result === 'boolean') {\n\t\t\treturn { [entity.primary]: { [result ? 'always' : 'never']: true } }\n\t\t}\n\t\tlet changed = false\n\t\tfor (const evaluated of evaluatedPredicates) {\n\t\t\tconst evaluatedPredicate = this.optimize(evaluated, entity)\n\t\t\tconst newResult = replaceWhere(result, evaluatedPredicate, { [entity.primary]: { always: true } })\n\t\t\tif (newResult !== result) {\n\t\t\t\tresult = newResult\n\t\t\t\tchanged = true\n\t\t\t}\n\t\t}\n\t\tif (changed) {\n\t\t\treturn this.optimize(result, entity)\n\t\t}\n\n\t\treturn result\n\t}\n\n\tprivate optimizeWhere(where: Input.OptionalWhere, entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst operands: OptimizedOperand[] = []\n\n\t\tfor (const key in where) {\n\t\t\tconst value = where[key]\n\t\t\tlet operand: OptimizedOperand = undefined\n\t\t\tif (value === undefined || value === null) {\n\t\t\t\tcontinue\n\t\t\t} else if (key === 'and') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === false) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\toperand = this.optimizeAnd(innerOperands, entity, relationPath)\n\t\t\t} else if (key === 'or') {\n\t\t\t\tconst innerOperands: (Input.OptionalWhere | boolean)[] = []\n\t\t\t\tfor (const innerValue of value as readonly Input.OptionalWhere[]) {\n\t\t\t\t\tconst innerOperand = this.optimizeWhere(innerValue, entity, relationPath)\n\t\t\t\t\tif (innerOperand === true) {\n\t\t\t\t\t\toperand = true\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tinnerOperands.push(innerOperand)\n\t\t\t\t}\n\t\t\t\tif (operand !== true) {\n\t\t\t\t\toperand = this.optimizeOr(innerOperands, entity, relationPath)\n\t\t\t\t}\n\n\t\t\t} else if (key === 'not') {\n\t\t\t\toperand = optimizeNot(this.optimizeWhere(value as Input.OptionalWhere, entity, relationPath))\n\n\t\t\t} else {\n\t\t\t\toperand = this.resolveFieldValue(entity, key, value, relationPath)\n\t\t\t}\n\n\t\t\tif (operand === false) {\n\t\t\t\treturn false\n\n\t\t\t} else if (operand !== undefined) {\n\t\t\t\toperands.push(operand)\n\t\t\t}\n\t\t}\n\t\treturn this.optimizeAnd(operands, entity, relationPath)\n\t}\n\n\tprivate optimizeOr(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeOr(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.or)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.or, entity, { never: true }, relationPath)\n\t\tif (result === optimized.or) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeOr(result)\n\t}\n\n\tprivate optimizeAnd(operands: readonly OptimizedOperand[], entity: Model.Entity, relationPath: ExtendedRelationContext[]): Input.OptionalWhere | boolean {\n\t\tconst optimized = optimizeAnd(operands)\n\t\tif (typeof optimized === 'boolean' || !Array.isArray(optimized.and)) {\n\t\t\treturn optimized\n\t\t}\n\t\tconst result = this.crossOptimize(optimized.and, entity, { always: true }, relationPath)\n\t\tif (result === optimized.and) {\n\t\t\treturn optimized\n\t\t}\n\t\treturn optimizeAnd(result)\n\t}\n\n\tprivate crossOptimize(operands: Input.OptionalWhere[], entity: Model.Entity, replacement: Input.Condition, relationPath: ExtendedRelationContext[]): (Input.OptionalWhere | boolean)[] {\n\t\tlet result: (Input.OptionalWhere | boolean)[] = operands\n\t\tlet copied = false\n\t\tconst count = Math.min(result.length, this.options?.maxCrossOptimizationInput ?? 50)\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\tfor (let j = 0; j < count; j++) {\n\t\t\t\tconst a = result[j]\n\t\t\t\tconst b = result[i]\n\t\t\t\tif (i !== j && typeof a !== 'boolean' && typeof b !== 'boolean') {\n\t\t\t\t\tconst elResult = replaceWhere(a, b, { [entity.primary]: replacement }, {\n\t\t\t\t\t\treplaceSubOperands: true,\n\t\t\t\t\t})\n\t\t\t\t\tif (elResult !== a) {\n\t\t\t\t\t\tif (!copied) {\n\t\t\t\t\t\t\tresult = [...result]\n\t\t\t\t\t\t\tcopied = true\n\t\t\t\t\t\t}\n\t\t\t\t\t\tresult[j] = this.optimizeWhere(elResult, entity, relationPath)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate resolveFieldValue(entity: Model.Entity, key: string, value: Input.OptionalWhere[string], relationPath: ExtendedRelationContext[]) {\n\t\treturn acceptFieldVisitor<Input.OptionalWhere | boolean>(this.model, entity, key, {\n\t\t\tvisitColumn: () => {\n\t\t\t\tconst optimizedCondition = this.conditionOptimizer.optimize(value as Input.Condition)\n\n\t\t\t\tif (typeof optimizedCondition === 'boolean') {\n\t\t\t\t\treturn optimizedCondition\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedCondition }\n\t\t\t},\n\t\t\tvisitRelation: context => {\n\t\t\t\tlet where = value as Input.OptionalWhere\n\t\t\t\tconst newRelationPath: ExtendedRelationContext[] = [...relationPath]\n\t\t\t\tconst length = relationPath.length\n\t\t\t\tif (length > 0 && relationPath[length - 1].context.targetRelation?.name === context.relation.name) {\n\t\t\t\t\tconst item = newRelationPath.pop()\n\t\t\t\t\tconst type = item!.context.type\n\t\t\t\t\tif (item?.canEliminate && (type === 'oneHasMany' || type === 'oneHasOneOwning' || type === 'oneHasOneInverse')) {\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: true } }, { [context.targetEntity.primary]: { never: true } })\n\t\t\t\t\t\twhere = replaceWhere(where, { [context.targetEntity.primary]: { isNull: false } }, { [context.targetEntity.primary]: { always: true } })\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// first level relation - we are sure root exists\n\t\t\t\t\tconst canEliminate = length === 0 || relationPath[length - 1].isLast\n\t\t\t\t\tnewRelationPath.push({ context, isLast: false, canEliminate })\n\t\t\t\t}\n\t\t\t\tconst optimizedWhere = this.optimizeWhere(where, context.targetEntity, newRelationPath)\n\n\t\t\t\tif (typeof optimizedWhere === 'boolean') {\n\t\t\t\t\treturn optimizedWhere\n\t\t\t\t}\n\n\t\t\t\treturn { [key]: optimizedWh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cADY,iBACG,uBAA0B,oBAAA,IAAsC,CAAC,cAAc,oBAAoB,iBAAiB,CAAC,CAAA;AAD9H,IAAM,iBAAN;"}
|
|
@@ -7,10 +7,8 @@ const UpdateInputVisitor = require("../../inputProcessing/UpdateInputVisitor.cjs
|
|
|
7
7
|
const Result = require("../Result.cjs");
|
|
8
8
|
const ColumnValue = require("../ColumnValue.cjs");
|
|
9
9
|
class Updater {
|
|
10
|
-
constructor(schema,
|
|
10
|
+
constructor(schema, updateBuilderFactory) {
|
|
11
11
|
this.schema = schema;
|
|
12
|
-
this.schemaDatabaseMetadata = schemaDatabaseMetadata;
|
|
13
|
-
this.predicateFactory = predicateFactory;
|
|
14
12
|
this.updateBuilderFactory = updateBuilderFactory;
|
|
15
13
|
}
|
|
16
14
|
async update(mapper, entity, primaryValue, data, filter) {
|
|
@@ -49,6 +47,20 @@ class Updater {
|
|
|
49
47
|
}
|
|
50
48
|
const result = await updateBuilder.execute(mapper);
|
|
51
49
|
if (!result.executed) {
|
|
50
|
+
if (filter && Object.keys(filter).length > 0) {
|
|
51
|
+
const where = {
|
|
52
|
+
and: [
|
|
53
|
+
filter,
|
|
54
|
+
{
|
|
55
|
+
[entity.primary]: { eq: primaryValue }
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
const count = await mapper.count(entity, where);
|
|
60
|
+
if (!count) {
|
|
61
|
+
return [new Result.MutationEntryNotFoundError([], where)];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
52
64
|
resultList.unshift(new Result.MutationNothingToDo([], Result.NothingToDoReason.noData));
|
|
53
65
|
} else if (result.affectedRows !== 1) {
|
|
54
66
|
return [new Result.MutationNoResultError([])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Updater.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport {
|
|
1
|
+
{"version":3,"file":"Updater.cjs","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { MutationEntryNotFoundError, MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason } from '../Result'\nimport { UpdateBuilder } from './UpdateBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { MapperInput } from '../types'\n\nexport class Updater {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly updateBuilderFactory: UpdateBuilderFactory,\n\t) {}\n\n\tpublic async update(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tconst predicateFields = Object.keys(data)\n\t\tupdateBuilder.addPredicates(predicateFields)\n\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\tupdateBuilder.addOldWhere(filter)\n\t\t}\n\n\t\tconst visitor = new UpdateInputVisitor<SqlUpdateInputProcessorResult>(\n\t\t\tnew SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\t\tconst resultList: MutationResultList = []\n\t\tconst postUpdates: Exclude<SqlUpdateInputProcessorResult, MutationResultList>[] = []\n\n\t\tfor (const key of Object.keys(data)) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostUpdates.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\t\t// direct update was not invoked, but we still need to check if the row matches the filter\n\t\t\t\tconst where: Input.OptionalWhere = {\n\t\t\t\t\tand: [\n\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[entity.primary]: { eq: primaryValue },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t\tconst count = await mapper.count(entity, where)\n\t\t\t\tif (!count) {\n\t\t\t\t\treturn [new MutationEntryNotFoundError([], where)]\n\t\t\t\t}\n\t\t\t}\n\t\t\tresultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData))\n\t\t} else if (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t} else {\n\t\t\tconst okResult = new MutationUpdateOk([], entity, primaryValue, data, rowDataToFieldValues(result.values))\n\t\t\tresultList.unshift(okResult)\n\t\t}\n\n\t\tfor (const postUpdate of postUpdates) {\n\t\t\tconst postInsertResult = await postUpdate({ primary: primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n\n\tpublic async updateCb(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tbuilderCb(updateBuilder)\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\treturn [new MutationNothingToDo([], NothingToDoReason.noData)]\n\t\t}\n\t\tif (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t}\n\t\treturn [new MutationUpdateOk([], entity, primaryValue, {}, rowDataToFieldValues(result.values))]\n\t}\n}\n"],"names":["UpdateInputVisitor","SqlUpdateInputProcessor","acceptFieldVisitor","result","MutationEntryNotFoundError","MutationNothingToDo","NothingToDoReason","MutationNoResultError","MutationUpdateOk","rowDataToFieldValues"],"mappings":";;;;;;;;AAWO,MAAM,QAAQ;AAAA,EACpB,YACkB,QACA,sBAChB;AAFgB,SAAA,SAAA;AACA,SAAA,uBAAA;AAAA,EAAA;AAAA,EAGlB,MAAa,OACZ,QACA,QACA,cACA,MACA,QAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAErE,UAAA,kBAAkB,OAAO,KAAK,IAAI;AACxC,kBAAc,cAAc,eAAe;AAC3C,QAAI,UAAU,OAAO,KAAK,MAAM,EAAE,SAAS,GAAG;AAC7C,oBAAc,YAAY,MAAM;AAAA,IAAA;AAGjC,UAAM,UAAU,IAAIA,mBAAA;AAAA,MACnB,IAAIC,wBAAA,wBAAwB,cAAc,MAAM,eAAe,MAAM;AAAA,MACrE,KAAK;AAAA,MACL;AAAA,IACD;AACA,UAAM,aAAiC,CAAC;AACxC,UAAM,cAA4E,CAAC;AAEnF,eAAW,OAAO,OAAO,KAAK,IAAI,GAAG;AACpC,YAAM,YAAY,MAAMC,YAAA;AAAA,QACvB,KAAK;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACD;AACA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WAAA;AAAA,EAAA;AAAA,EAGR,MAAa,SACZ,QACA,QACA,cACA,WAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAE3E,cAAU,aAAa;AAEvB,UAAM,SAAS,MAAM,cAAc,QAAQ,MAAM;AAE7C,QAAA,CAAC,OAAO,UAAU;AACrB,aAAO,CAAC,IAAIE,OAAA,oBAAoB,CAAI,GAAAC,OAAA,kBAAkB,MAAM,CAAC;AAAA,IAAA;AAE1D,QAAA,OAAO,iBAAiB,GAAG;AAC9B,aAAO,CAAC,IAAIC,6BAAsB,CAAA,CAAE,CAAC;AAAA,IAAA;AAEtC,WAAO,CAAC,IAAIC,OAAAA,iBAAiB,CAAI,GAAA,QAAQ,cAAc,CAAI,GAAAC,iCAAqB,OAAO,MAAM,CAAC,CAAC;AAAA,EAAA;AAEjG;;"}
|
|
@@ -2,13 +2,11 @@ import { SqlUpdateInputProcessor } from "./SqlUpdateInputProcessor.js";
|
|
|
2
2
|
import { acceptFieldVisitor } from "@contember/schema-utils";
|
|
3
3
|
import "@contember/schema";
|
|
4
4
|
import { UpdateInputVisitor } from "../../inputProcessing/UpdateInputVisitor.js";
|
|
5
|
-
import { MutationNothingToDo, NothingToDoReason, MutationNoResultError, MutationUpdateOk } from "../Result.js";
|
|
5
|
+
import { MutationEntryNotFoundError, MutationNothingToDo, NothingToDoReason, MutationNoResultError, MutationUpdateOk } from "../Result.js";
|
|
6
6
|
import { rowDataToFieldValues } from "../ColumnValue.js";
|
|
7
7
|
class Updater {
|
|
8
|
-
constructor(schema,
|
|
8
|
+
constructor(schema, updateBuilderFactory) {
|
|
9
9
|
this.schema = schema;
|
|
10
|
-
this.schemaDatabaseMetadata = schemaDatabaseMetadata;
|
|
11
|
-
this.predicateFactory = predicateFactory;
|
|
12
10
|
this.updateBuilderFactory = updateBuilderFactory;
|
|
13
11
|
}
|
|
14
12
|
async update(mapper, entity, primaryValue, data, filter) {
|
|
@@ -47,6 +45,20 @@ class Updater {
|
|
|
47
45
|
}
|
|
48
46
|
const result = await updateBuilder.execute(mapper);
|
|
49
47
|
if (!result.executed) {
|
|
48
|
+
if (filter && Object.keys(filter).length > 0) {
|
|
49
|
+
const where = {
|
|
50
|
+
and: [
|
|
51
|
+
filter,
|
|
52
|
+
{
|
|
53
|
+
[entity.primary]: { eq: primaryValue }
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
const count = await mapper.count(entity, where);
|
|
58
|
+
if (!count) {
|
|
59
|
+
return [new MutationEntryNotFoundError([], where)];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
50
62
|
resultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData));
|
|
51
63
|
} else if (result.affectedRows !== 1) {
|
|
52
64
|
return [new MutationNoResultError([])];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Updater.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport {
|
|
1
|
+
{"version":3,"file":"Updater.js","sources":["../../../../../../packages/engine-content-api/src/mapper/update/Updater.ts"],"sourcesContent":["import { SqlUpdateInputProcessor, SqlUpdateInputProcessorResult } from './SqlUpdateInputProcessor'\nimport { UpdateInputVisitor } from '../../inputProcessing'\nimport { Input, Model } from '@contember/schema'\nimport { UpdateBuilderFactory } from './UpdateBuilderFactory'\nimport { Mapper } from '../Mapper'\nimport { acceptFieldVisitor } from '@contember/schema-utils'\nimport { MutationEntryNotFoundError, MutationNoResultError, MutationNothingToDo, MutationResultList, MutationUpdateOk, NothingToDoReason } from '../Result'\nimport { UpdateBuilder } from './UpdateBuilder'\nimport { rowDataToFieldValues } from '../ColumnValue'\nimport { MapperInput } from '../types'\n\nexport class Updater {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly updateBuilderFactory: UpdateBuilderFactory,\n\t) {}\n\n\tpublic async update(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tdata: MapperInput.UpdateDataInput,\n\t\tfilter?: Input.OptionalWhere,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tconst predicateFields = Object.keys(data)\n\t\tupdateBuilder.addPredicates(predicateFields)\n\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\tupdateBuilder.addOldWhere(filter)\n\t\t}\n\n\t\tconst visitor = new UpdateInputVisitor<SqlUpdateInputProcessorResult>(\n\t\t\tnew SqlUpdateInputProcessor(primaryValue, data, updateBuilder, mapper),\n\t\t\tthis.schema,\n\t\t\tdata,\n\t\t)\n\t\tconst resultList: MutationResultList = []\n\t\tconst postUpdates: Exclude<SqlUpdateInputProcessorResult, MutationResultList>[] = []\n\n\t\tfor (const key of Object.keys(data)) {\n\t\t\tconst resultSet = await acceptFieldVisitor(\n\t\t\t\tthis.schema,\n\t\t\t\tentity,\n\t\t\t\tkey,\n\t\t\t\tvisitor,\n\t\t\t)\n\t\t\tfor (const result of resultSet) {\n\t\t\t\tif (typeof result === 'function') {\n\t\t\t\t\tpostUpdates.push(result)\n\t\t\t\t} else {\n\t\t\t\t\tfor (const resultItem of await result) {\n\t\t\t\t\t\tresultList.push(resultItem)\n\t\t\t\t\t\tif (resultItem.error) {\n\t\t\t\t\t\t\treturn resultList\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\tif (filter && Object.keys(filter).length > 0) {\n\t\t\t\t// direct update was not invoked, but we still need to check if the row matches the filter\n\t\t\t\tconst where: Input.OptionalWhere = {\n\t\t\t\t\tand: [\n\t\t\t\t\t\tfilter,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t[entity.primary]: { eq: primaryValue },\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t}\n\t\t\t\tconst count = await mapper.count(entity, where)\n\t\t\t\tif (!count) {\n\t\t\t\t\treturn [new MutationEntryNotFoundError([], where)]\n\t\t\t\t}\n\t\t\t}\n\t\t\tresultList.unshift(new MutationNothingToDo([], NothingToDoReason.noData))\n\t\t} else if (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t} else {\n\t\t\tconst okResult = new MutationUpdateOk([], entity, primaryValue, data, rowDataToFieldValues(result.values))\n\t\t\tresultList.unshift(okResult)\n\t\t}\n\n\t\tfor (const postUpdate of postUpdates) {\n\t\t\tconst postInsertResult = await postUpdate({ primary: primaryValue })\n\t\t\tfor (const result of postInsertResult) {\n\t\t\t\tresultList.push(result)\n\t\t\t\tif (result.error) {\n\t\t\t\t\treturn resultList\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn resultList\n\t}\n\n\tpublic async updateCb(\n\t\tmapper: Mapper,\n\t\tentity: Model.Entity,\n\t\tprimaryValue: Input.PrimaryValue,\n\t\tbuilderCb: (builder: UpdateBuilder) => void,\n\t): Promise<MutationResultList> {\n\t\tconst updateBuilder = this.updateBuilderFactory.create(entity, primaryValue)\n\n\t\tbuilderCb(updateBuilder)\n\n\t\tconst result = await updateBuilder.execute(mapper)\n\n\t\tif (!result.executed) {\n\t\t\treturn [new MutationNothingToDo([], NothingToDoReason.noData)]\n\t\t}\n\t\tif (result.affectedRows !== 1) {\n\t\t\treturn [new MutationNoResultError([])]\n\t\t}\n\t\treturn [new MutationUpdateOk([], entity, primaryValue, {}, rowDataToFieldValues(result.values))]\n\t}\n}\n"],"names":["result"],"mappings":";;;;;;AAWO,MAAM,QAAQ;AAAA,EACpB,YACkB,QACA,sBAChB;AAFgB,SAAA,SAAA;AACA,SAAA,uBAAA;AAAA,EAAA;AAAA,EAGlB,MAAa,OACZ,QACA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AQ,IAAI,oBAAoB,CAAA,GAAI,kBAAkB,MAAM,CAAC;AAAA,IAAA,WAC9D,OAAO,iBAAiB,GAAG;AACrC,aAAO,CAAC,IAAI,sBAAsB,CAAA,CAAE,CAAC;AAAA,IAAA,OAC/B;AACA,YAAA,WAAW,IAAI,iBAAiB,CAAA,GAAI,QAAQ,cAAc,MAAM,qBAAqB,OAAO,MAAM,CAAC;AACzG,iBAAW,QAAQ,QAAQ;AAAA,IAAA;AAG5B,eAAW,cAAc,aAAa;AACrC,YAAM,mBAAmB,MAAM,WAAW,EAAE,SAAS,cAAc;AACnE,iBAAWA,WAAU,kBAAkB;AACtC,mBAAW,KAAKA,OAAM;AACtB,YAAIA,QAAO,OAAO;AACV,iBAAA;AAAA,QAAA;AAAA,MACR;AAAA,IACD;AAGM,WAAA;AAAA,EAAA;AAAA,EAGR,MAAa,SACZ,QACA,QACA,cACA,WAC8B;AAC9B,UAAM,gBAAgB,KAAK,qBAAqB,OAAO,QAAQ,YAAY;AAE3E,cAAU,aAAa;AAEvB,UAAM,SAAS,MAAM,cAAc,QAAQ,MAAM;AAE7C,QAAA,CAAC,OAAO,UAAU;AACrB,aAAO,CAAC,IAAI,oBAAoB,CAAI,GAAA,kBAAkB,MAAM,CAAC;AAAA,IAAA;AAE1D,QAAA,OAAO,iBAAiB,GAAG;AAC9B,aAAO,CAAC,IAAI,sBAAsB,CAAA,CAAE,CAAC;AAAA,IAAA;AAEtC,WAAO,CAAC,IAAI,iBAAiB,CAAI,GAAA,QAAQ,cAAc,CAAI,GAAA,qBAAqB,OAAO,MAAM,CAAC,CAAC;AAAA,EAAA;AAEjG;"}
|
|
@@ -6,13 +6,14 @@ class RefreshViewResolver {
|
|
|
6
6
|
this.schema = schema;
|
|
7
7
|
this.mapperFactory = mapperFactory;
|
|
8
8
|
}
|
|
9
|
-
async resolve(entity) {
|
|
9
|
+
async resolve(entity, options) {
|
|
10
10
|
const mapper = this.mapperFactory.create();
|
|
11
11
|
const entityModel = this.schema.model.entities[entity];
|
|
12
12
|
if (!entityModel) {
|
|
13
13
|
throw new Error(`Entity ${entity} not found`);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const concurrently = options?.concurrently ? " CONCURRENTLY" : "";
|
|
16
|
+
await mapper.db.query(`REFRESH MATERIALIZED VIEW${concurrently} ${Database.wrapIdentifier(mapper.db.schema)}.${Database.wrapIdentifier(entityModel.tableName)}`);
|
|
16
17
|
return { ok: true };
|
|
17
18
|
}
|
|
18
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshViewResolver.cjs","sources":["../../../../../packages/engine-content-api/src/resolvers/RefreshViewResolver.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { MapperFactory } from '../mapper'\nimport { wrapIdentifier } from '@contember/database'\
|
|
1
|
+
{"version":3,"file":"RefreshViewResolver.cjs","sources":["../../../../../packages/engine-content-api/src/resolvers/RefreshViewResolver.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { MapperFactory } from '../mapper'\nimport { wrapIdentifier } from '@contember/database'\n\nexport class RefreshViewResolver {\n\tconstructor(\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly mapperFactory: MapperFactory,\n\t) {\n\t}\n\n\tpublic async resolve(entity: string, options?: { concurrently?: boolean }): Promise<{ ok: boolean }> {\n\t\tconst mapper = this.mapperFactory.create()\n\t\tconst entityModel = this.schema.model.entities[entity]\n\t\tif (!entityModel) {\n\t\t\tthrow new Error(`Entity ${entity} not found`)\n\t\t}\n\t\tconst concurrently = options?.concurrently ? ' CONCURRENTLY' : ''\n\t\tawait mapper.db.query(`REFRESH MATERIALIZED VIEW${concurrently} ${wrapIdentifier(mapper.db.schema)}.${wrapIdentifier(entityModel.tableName)}`)\n\n\t\treturn { ok: true }\n\t}\n}\n"],"names":["wrapIdentifier"],"mappings":";;;AAIO,MAAM,oBAAoB;AAAA,EAChC,YACkB,QACA,eAChB;AAFgB,SAAA,SAAA;AACA,SAAA,gBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,QAAQ,QAAgB,SAAgE;AAC9F,UAAA,SAAS,KAAK,cAAc,OAAO;AACzC,UAAM,cAAc,KAAK,OAAO,MAAM,SAAS,MAAM;AACrD,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,MAAM,UAAU,MAAM,YAAY;AAAA,IAAA;AAEvC,UAAA,eAAe,SAAS,eAAe,kBAAkB;AAC/D,UAAM,OAAO,GAAG,MAAM,4BAA4B,YAAY,IAAIA,SAAe,eAAA,OAAO,GAAG,MAAM,CAAC,IAAIA,SAAA,eAAe,YAAY,SAAS,CAAC,EAAE;AAEtI,WAAA,EAAE,IAAI,KAAK;AAAA,EAAA;AAEpB;;"}
|
|
@@ -4,13 +4,14 @@ class RefreshViewResolver {
|
|
|
4
4
|
this.schema = schema;
|
|
5
5
|
this.mapperFactory = mapperFactory;
|
|
6
6
|
}
|
|
7
|
-
async resolve(entity) {
|
|
7
|
+
async resolve(entity, options) {
|
|
8
8
|
const mapper = this.mapperFactory.create();
|
|
9
9
|
const entityModel = this.schema.model.entities[entity];
|
|
10
10
|
if (!entityModel) {
|
|
11
11
|
throw new Error(`Entity ${entity} not found`);
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
const concurrently = options?.concurrently ? " CONCURRENTLY" : "";
|
|
14
|
+
await mapper.db.query(`REFRESH MATERIALIZED VIEW${concurrently} ${wrapIdentifier(mapper.db.schema)}.${wrapIdentifier(entityModel.tableName)}`);
|
|
14
15
|
return { ok: true };
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshViewResolver.js","sources":["../../../../../packages/engine-content-api/src/resolvers/RefreshViewResolver.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { MapperFactory } from '../mapper'\nimport { wrapIdentifier } from '@contember/database'\
|
|
1
|
+
{"version":3,"file":"RefreshViewResolver.js","sources":["../../../../../packages/engine-content-api/src/resolvers/RefreshViewResolver.ts"],"sourcesContent":["import { Schema } from '@contember/schema'\nimport { MapperFactory } from '../mapper'\nimport { wrapIdentifier } from '@contember/database'\n\nexport class RefreshViewResolver {\n\tconstructor(\n\t\tprivate readonly schema: Schema,\n\t\tprivate readonly mapperFactory: MapperFactory,\n\t) {\n\t}\n\n\tpublic async resolve(entity: string, options?: { concurrently?: boolean }): Promise<{ ok: boolean }> {\n\t\tconst mapper = this.mapperFactory.create()\n\t\tconst entityModel = this.schema.model.entities[entity]\n\t\tif (!entityModel) {\n\t\t\tthrow new Error(`Entity ${entity} not found`)\n\t\t}\n\t\tconst concurrently = options?.concurrently ? ' CONCURRENTLY' : ''\n\t\tawait mapper.db.query(`REFRESH MATERIALIZED VIEW${concurrently} ${wrapIdentifier(mapper.db.schema)}.${wrapIdentifier(entityModel.tableName)}`)\n\n\t\treturn { ok: true }\n\t}\n}\n"],"names":[],"mappings":";AAIO,MAAM,oBAAoB;AAAA,EAChC,YACkB,QACA,eAChB;AAFgB,SAAA,SAAA;AACA,SAAA,gBAAA;AAAA,EAAA;AAAA,EAIlB,MAAa,QAAQ,QAAgB,SAAgE;AAC9F,UAAA,SAAS,KAAK,cAAc,OAAO;AACzC,UAAM,cAAc,KAAK,OAAO,MAAM,SAAS,MAAM;AACrD,QAAI,CAAC,aAAa;AACjB,YAAM,IAAI,MAAM,UAAU,MAAM,YAAY;AAAA,IAAA;AAEvC,UAAA,eAAe,SAAS,eAAe,kBAAkB;AAC/D,UAAM,OAAO,GAAG,MAAM,4BAA4B,YAAY,IAAI,eAAe,OAAO,GAAG,MAAM,CAAC,IAAI,eAAe,YAAY,SAAS,CAAC,EAAE;AAEtI,WAAA,EAAE,IAAI,KAAK;AAAA,EAAA;AAEpB;"}
|
|
@@ -50,6 +50,8 @@ class ConditionTypeProvider {
|
|
|
50
50
|
conditions.lte = { type };
|
|
51
51
|
conditions.gt = { type };
|
|
52
52
|
conditions.gte = { type };
|
|
53
|
+
} else {
|
|
54
|
+
conditions.includes = { type };
|
|
53
55
|
}
|
|
54
56
|
if (column.type === schema.Model.ColumnType.String) {
|
|
55
57
|
conditions.contains = { type: graphql.GraphQLString };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":["singletonFactory","Model","GqlTypeName","GraphQLInputObjectType","GraphQLList","GraphQLNonNull","GraphQLBoolean","GraphQLInt","GraphQLString"],"mappings":";;;;;;;;;;AAiBO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,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EAAE,KAAK;AACZ,uBAAA,QAAQ,EAAE,KAAK;AACf,uBAAA,KAAK,EAAE,MAAM,IAAIG,oBAAY,IAAIC,QAAA,eAAe,IAAI,CAAC,EAAE;AACvD,uBAAA,QAAQ,EAAE,MAAM,IAAID,oBAAY,IAAIC,QAAA,eAAe,IAAI,CAAC,EAAE;AAC1D,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AACnB,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AAAA,UAAA;
|
|
1
|
+
{"version":3,"file":"ConditionTypeProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// For JSON columns, add the includes operator\n\t\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":["singletonFactory","Model","GqlTypeName","GraphQLInputObjectType","GraphQLList","GraphQLNonNull","GraphQLBoolean","GraphQLInt","GraphQLString"],"mappings":";;;;;;;;;;AAiBO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAaA,iBAAA;AAAA,MACpB,CAAC,MAAM,CAAC,MAAM,MAAM,MAAM,KAAK,gBAAgB,MAAM,QAAQ,IAAI;AAAA,IAAA,CAClE;AAAA,EAAA;AAAA,EAIO,aAAa,QAAiD;AACpE,UAAM,CAAC,aAAa,QAAQ,IAAI,KAAK,mBAAmB,QAAQ,MAAM;AACtE,UAAM,OAAO,KAAK,WAAW,QAAQ,SAAS,IAAI;AAClD,WAAO,KAAK,WAAW,MAAM,CAAC,UAAU,MAAM,CAAC;AAAA,EAAA;AAAA,EAGxC,WAAW,QAAyB,UAA0B;AACrE,UAAM,SAAS,OAAO,SAASC,OAAM,MAAA,WAAW,OAAO,SAAS;AAC1D,UAAA,cAAc,OAAO,OAAO,SAAS;AAC3C,WAAOC,MAAAA,cAAc,QAAQ,GAAG,MAAM,GAAG,WAAW;AAAA,EAAA;AAAA,EAG7C,gBAAgB,MAAc,QAAyB,MAAmE;AAC3H,UAAA,YAAoC,IAAIC,+BAAuB;AAAA,MACpE;AAAA,MACA,QAAQ,MAAkC;AACzC,cAAM,aAAyC;AAAA,UAC9C,KAAK,EAAE,MAAM,IAAIC,QAAAA,YAAY,IAAIC,QAAA,eAAe,SAAS,CAAC,EAAE;AAAA,UAC5D,IAAI,EAAE,MAAM,IAAID,QAAAA,YAAY,IAAIC,QAAA,eAAe,SAAS,CAAC,EAAE;AAAA,UAC3D,KAAK,EAAE,MAAM,UAA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|
52
|
+
conditions.includes = { type };
|
|
51
53
|
}
|
|
52
54
|
if (column.type === Model.ColumnType.String) {
|
|
53
55
|
conditions.contains = { type: GraphQLString };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConditionTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAiBO,MAAM,sBAAsB;AAAA,EAKlC,YAA6B,oBAAwC;AAAxC,SAAA,qBAAA;AAJ7B,kBAAA,MAAQ,cAAa;AAAA,MACpB,CAAC,MAAM,CAAC,MAAM,MA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IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AAC1D,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AACnB,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AAAA,UAAA;
|
|
1
|
+
{"version":3,"file":"ConditionTypeProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/ConditionTypeProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport {\n\tGraphQLBoolean,\n\tGraphQLEnumType,\n\tGraphQLInputFieldConfigMap,\n\tGraphQLInputObjectType,\n\tGraphQLInt,\n\tGraphQLList,\n\tGraphQLNonNull,\n\tGraphQLScalarType,\n\tGraphQLString,\n} from 'graphql'\nimport { singletonFactory } from '../utils'\nimport { ColumnTypeResolver } from './ColumnTypeResolver'\nimport { GqlTypeName } from './utils'\nimport { ImplementationException } from '../exception'\n\nexport class ConditionTypeProvider {\n\tprivate conditions = singletonFactory<GraphQLInputObjectType, string, [GraphQLScalarType | GraphQLEnumType, Model.AnyColumn]>(\n\t\t(name, [type, column]) => this.createCondition(name, column, type),\n\t)\n\n\tconstructor(private readonly columnTypeResolver: ColumnTypeResolver) {}\n\n\tpublic getCondition(column: Model.AnyColumn): GraphQLInputObjectType {\n\t\tconst [graphqlType, baseType] = this.columnTypeResolver.getType(column)\n\t\tconst name = this.createName(column, baseType.name)\n\t\treturn this.conditions(name, [baseType, column])\n\t}\n\n\tprivate createName(column: Model.AnyColumn, typeName: string): string {\n\t\tconst suffix = column.type === Model.ColumnType.Enum ? 'Enum' : ''\n\t\tconst arraySuffix = column.list ? 'List' : ''\n\t\treturn GqlTypeName`${typeName}${suffix}${arraySuffix}Condition`\n\t}\n\n\tprivate createCondition(name: string, column: Model.AnyColumn, type: GraphQLScalarType | GraphQLEnumType): GraphQLInputObjectType {\n\t\tconst condition: GraphQLInputObjectType = new GraphQLInputObjectType({\n\t\t\tname: name,\n\t\t\tfields: (): GraphQLInputFieldConfigMap => {\n\t\t\t\tconst conditions: GraphQLInputFieldConfigMap = {\n\t\t\t\t\tand: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tor: { type: new GraphQLList(new GraphQLNonNull(condition)) },\n\t\t\t\t\tnot: { type: condition },\n\n\t\t\t\t\tnull: { type: GraphQLBoolean },\n\t\t\t\t\tisNull: { type: GraphQLBoolean },\n\t\t\t\t}\n\t\t\t\tif (column.list) {\n\t\t\t\t\tconditions.minLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.maxLength = { type: GraphQLInt }\n\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t} else {\n\t\t\t\t\tif (column.type !== Model.ColumnType.Json) {\n\t\t\t\t\t\tconditions.eq = { type }\n\t\t\t\t\t\tconditions.notEq = { type }\n\t\t\t\t\t\tconditions.in = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.notIn = { type: new GraphQLList(new GraphQLNonNull(type)) }\n\t\t\t\t\t\tconditions.lt = { type: type }\n\t\t\t\t\t\tconditions.lte = { type: type }\n\t\t\t\t\t\tconditions.gt = { type: type }\n\t\t\t\t\t\tconditions.gte = { type: type }\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// For JSON columns, add the includes operator\n\t\t\t\t\t\tconditions.includes = { type: type }\n\t\t\t\t\t}\n\t\t\t\t\tif (column.type === Model.ColumnType.String) {\n\t\t\t\t\t\tconditions.contains = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWith = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWith = { type: GraphQLString }\n\n\t\t\t\t\t\tconditions.containsCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.startsWithCI = { type: GraphQLString }\n\t\t\t\t\t\tconditions.endsWithCI = { type: GraphQLString }\n\t\t\t\t\t}\n\t\t\t\t}\n\n\n\t\t\t\treturn conditions\n\t\t\t},\n\t\t})\n\t\treturn condition\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;A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AACZ,uBAAA,QAAQ,EAAE,KAAK;AACf,uBAAA,KAAK,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AACvD,uBAAA,QAAQ,EAAE,MAAM,IAAI,YAAY,IAAI,eAAe,IAAI,CAAC,EAAE;AAC1D,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AACnB,uBAAA,KAAK,EAAE,KAAW;AAClB,uBAAA,MAAM,EAAE,KAAW;AAAA,UAAA,OACxB;AAEK,uBAAA,WAAW,EAAE,KAAW;AAAA,UAAA;AAEpC,cAAI,OAAO,SAAS,MAAM,WAAW,QAAQ;AACjC,uBAAA,WAAW,EAAE,MAAM,cAAc;AACjC,uBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,uBAAA,WAAW,EAAE,MAAM,cAAc;AAEjC,uBAAA,aAAa,EAAE,MAAM,cAAc;AACnC,uBAAA,eAAe,EAAE,MAAM,cAAc;AACrC,uBAAA,aAAa,EAAE,MAAM,cAAc;AAAA,UAAA;AAAA,QAC/C;AAIM,eAAA;AAAA,MAAA;AAAA,IACR,CACA;AACM,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -15,6 +15,12 @@ class RefreshViewMutationProvider {
|
|
|
15
15
|
name: "_MaterializedView",
|
|
16
16
|
values: Object.fromEntries(materializedViews.map((it) => [it.name, { value: it.name }]))
|
|
17
17
|
});
|
|
18
|
+
const refreshViewOptions = new graphql.GraphQLInputObjectType({
|
|
19
|
+
name: "RefreshMaterializedViewOptions",
|
|
20
|
+
fields: {
|
|
21
|
+
concurrently: { type: graphql.GraphQLBoolean }
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
return {
|
|
19
25
|
type: new graphql.GraphQLObjectType({
|
|
20
26
|
name: "RefreshMaterializedViewResponse",
|
|
@@ -23,10 +29,11 @@ class RefreshViewMutationProvider {
|
|
|
23
29
|
}
|
|
24
30
|
}),
|
|
25
31
|
args: {
|
|
26
|
-
name: { type: materializedViewsEnum }
|
|
32
|
+
name: { type: materializedViewsEnum },
|
|
33
|
+
options: { type: refreshViewOptions }
|
|
27
34
|
},
|
|
28
35
|
resolve: async (parent, args, context) => {
|
|
29
|
-
return await context.executionContainer.refreshViewResolver.resolve(args.name);
|
|
36
|
+
return await context.executionContainer.refreshViewResolver.resolve(args.name, args.options);
|
|
30
37
|
}
|
|
31
38
|
};
|
|
32
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshViewMutationProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/RefreshViewMutationProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLObjectType } from 'graphql'\nimport { Context } from '../types'\nimport { Authorizator } from '../acl'\n\nexport class RefreshViewMutationProvider {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t) {\n\t}\n\tgetMutation(): GraphQLFieldConfig<any, Context, any> | undefined {\n\t\tconst materializedViews = Object.values(this.schema.entities)\n\t\t\t.filter(it => it.view?.materialized)\n\t\t\t.filter(it => this.authorizator.isRefreshMaterializedViewAllowed(it.name))\n\t\tif (materializedViews.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst materializedViewsEnum = new GraphQLEnumType({\n\t\t\tname: '_MaterializedView',\n\t\t\tvalues: Object.fromEntries(materializedViews.map(it => [it.name, { value: it.name }])),\n\t\t})\n\n\t\treturn {\n\t\t\ttype: new GraphQLObjectType({\n\t\t\t\tname: 'RefreshMaterializedViewResponse',\n\t\t\t\tfields: {\n\t\t\t\t\tok: { type: GraphQLBoolean },\n\t\t\t\t},\n\t\t\t}),\n\t\t\targs: {\n\t\t\t\tname: { type: materializedViewsEnum },\n\t\t\t},\n\t\t\tresolve: async (parent, args, context) => {\n\t\t\t\treturn await context.executionContainer.refreshViewResolver.resolve(args.name)\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["GraphQLEnumType","
|
|
1
|
+
{"version":3,"file":"RefreshViewMutationProvider.cjs","sources":["../../../../../packages/engine-content-api/src/schema/RefreshViewMutationProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLInputObjectType, GraphQLObjectType } from 'graphql'\nimport { Context } from '../types'\nimport { Authorizator } from '../acl'\n\nexport class RefreshViewMutationProvider {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t) {\n\t}\n\tgetMutation(): GraphQLFieldConfig<any, Context, any> | undefined {\n\t\tconst materializedViews = Object.values(this.schema.entities)\n\t\t\t.filter(it => it.view?.materialized)\n\t\t\t.filter(it => this.authorizator.isRefreshMaterializedViewAllowed(it.name))\n\t\tif (materializedViews.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst materializedViewsEnum = new GraphQLEnumType({\n\t\t\tname: '_MaterializedView',\n\t\t\tvalues: Object.fromEntries(materializedViews.map(it => [it.name, { value: it.name }])),\n\t\t})\n\n\t\tconst refreshViewOptions = new GraphQLInputObjectType({\n\t\t\tname: 'RefreshMaterializedViewOptions',\n\t\t\tfields: {\n\t\t\t\tconcurrently: { type: GraphQLBoolean },\n\t\t\t},\n\t\t})\n\t\treturn {\n\t\t\ttype: new GraphQLObjectType({\n\t\t\t\tname: 'RefreshMaterializedViewResponse',\n\t\t\t\tfields: {\n\t\t\t\t\tok: { type: GraphQLBoolean },\n\t\t\t\t},\n\t\t\t}),\n\t\t\targs: {\n\t\t\t\tname: { type: materializedViewsEnum },\n\t\t\t\toptions: { type: refreshViewOptions },\n\t\t\t},\n\t\t\tresolve: async (parent, args, context) => {\n\t\t\t\treturn await context.executionContainer.refreshViewResolver.resolve(args.name, args.options)\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":["GraphQLEnumType","GraphQLInputObjectType","GraphQLBoolean","GraphQLObjectType"],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|
|
2
2
|
class RefreshViewMutationProvider {
|
|
3
3
|
constructor(schema, authorizator) {
|
|
4
4
|
this.schema = schema;
|
|
@@ -13,6 +13,12 @@ class RefreshViewMutationProvider {
|
|
|
13
13
|
name: "_MaterializedView",
|
|
14
14
|
values: Object.fromEntries(materializedViews.map((it) => [it.name, { value: it.name }]))
|
|
15
15
|
});
|
|
16
|
+
const refreshViewOptions = new GraphQLInputObjectType({
|
|
17
|
+
name: "RefreshMaterializedViewOptions",
|
|
18
|
+
fields: {
|
|
19
|
+
concurrently: { type: GraphQLBoolean }
|
|
20
|
+
}
|
|
21
|
+
});
|
|
16
22
|
return {
|
|
17
23
|
type: new GraphQLObjectType({
|
|
18
24
|
name: "RefreshMaterializedViewResponse",
|
|
@@ -21,10 +27,11 @@ class RefreshViewMutationProvider {
|
|
|
21
27
|
}
|
|
22
28
|
}),
|
|
23
29
|
args: {
|
|
24
|
-
name: { type: materializedViewsEnum }
|
|
30
|
+
name: { type: materializedViewsEnum },
|
|
31
|
+
options: { type: refreshViewOptions }
|
|
25
32
|
},
|
|
26
33
|
resolve: async (parent, args, context) => {
|
|
27
|
-
return await context.executionContainer.refreshViewResolver.resolve(args.name);
|
|
34
|
+
return await context.executionContainer.refreshViewResolver.resolve(args.name, args.options);
|
|
28
35
|
}
|
|
29
36
|
};
|
|
30
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RefreshViewMutationProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/RefreshViewMutationProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLObjectType } from 'graphql'\nimport { Context } from '../types'\nimport { Authorizator } from '../acl'\n\nexport class RefreshViewMutationProvider {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t) {\n\t}\n\tgetMutation(): GraphQLFieldConfig<any, Context, any> | undefined {\n\t\tconst materializedViews = Object.values(this.schema.entities)\n\t\t\t.filter(it => it.view?.materialized)\n\t\t\t.filter(it => this.authorizator.isRefreshMaterializedViewAllowed(it.name))\n\t\tif (materializedViews.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst materializedViewsEnum = new GraphQLEnumType({\n\t\t\tname: '_MaterializedView',\n\t\t\tvalues: Object.fromEntries(materializedViews.map(it => [it.name, { value: it.name }])),\n\t\t})\n\n\t\treturn {\n\t\t\ttype: new GraphQLObjectType({\n\t\t\t\tname: 'RefreshMaterializedViewResponse',\n\t\t\t\tfields: {\n\t\t\t\t\tok: { type: GraphQLBoolean },\n\t\t\t\t},\n\t\t\t}),\n\t\t\targs: {\n\t\t\t\tname: { type: materializedViewsEnum },\n\t\t\t},\n\t\t\tresolve: async (parent, args, context) => {\n\t\t\t\treturn await context.executionContainer.refreshViewResolver.resolve(args.name)\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,4BAA4B;AAAA,EACxC,YACkB,QACA,cAChB;AAFgB,SAAA,SAAA;AACA,SAAA,eAAA;AAAA,EAAA;AAAA,EAGlB,cAAiE;AAC1D,UAAA,oBAAoB,OAAO,OAAO,KAAK,OAAO,QAAQ,EAC1D,OAAO,CAAM,OAAA,GAAG,MAAM,YAAY,EAClC,OAAO,CAAM,OAAA,KAAK,aAAa,iCAAiC,GAAG,IAAI,CAAC;AACtE,QAAA,kBAAkB,WAAW,GAAG;AAC5B,aAAA;AAAA,IAAA;AAGF,UAAA,wBAAwB,IAAI,gBAAgB;AAAA,MACjD,MAAM;AAAA,MACN,QAAQ,OAAO,YAAY,kBAAkB,IAAI,CAAM,OAAA,CAAC,GAAG,MAAM,EAAE,OAAO,GAAG,KAAM,CAAA,CAAC,CAAC;AAAA,IAAA,CACrF;
|
|
1
|
+
{"version":3,"file":"RefreshViewMutationProvider.js","sources":["../../../../../packages/engine-content-api/src/schema/RefreshViewMutationProvider.ts"],"sourcesContent":["import { Model } from '@contember/schema'\nimport { GraphQLBoolean, GraphQLEnumType, GraphQLFieldConfig, GraphQLInputObjectType, GraphQLObjectType } from 'graphql'\nimport { Context } from '../types'\nimport { Authorizator } from '../acl'\n\nexport class RefreshViewMutationProvider {\n\tconstructor(\n\t\tprivate readonly schema: Model.Schema,\n\t\tprivate readonly authorizator: Authorizator,\n\t) {\n\t}\n\tgetMutation(): GraphQLFieldConfig<any, Context, any> | undefined {\n\t\tconst materializedViews = Object.values(this.schema.entities)\n\t\t\t.filter(it => it.view?.materialized)\n\t\t\t.filter(it => this.authorizator.isRefreshMaterializedViewAllowed(it.name))\n\t\tif (materializedViews.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst materializedViewsEnum = new GraphQLEnumType({\n\t\t\tname: '_MaterializedView',\n\t\t\tvalues: Object.fromEntries(materializedViews.map(it => [it.name, { value: it.name }])),\n\t\t})\n\n\t\tconst refreshViewOptions = new GraphQLInputObjectType({\n\t\t\tname: 'RefreshMaterializedViewOptions',\n\t\t\tfields: {\n\t\t\t\tconcurrently: { type: GraphQLBoolean },\n\t\t\t},\n\t\t})\n\t\treturn {\n\t\t\ttype: new GraphQLObjectType({\n\t\t\t\tname: 'RefreshMaterializedViewResponse',\n\t\t\t\tfields: {\n\t\t\t\t\tok: { type: GraphQLBoolean },\n\t\t\t\t},\n\t\t\t}),\n\t\t\targs: {\n\t\t\t\tname: { type: materializedViewsEnum },\n\t\t\t\toptions: { type: refreshViewOptions },\n\t\t\t},\n\t\t\tresolve: async (parent, args, context) => {\n\t\t\t\treturn await context.executionContainer.refreshViewResolver.resolve(args.name, args.options)\n\t\t\t},\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";AAKO,MAAM,4BAA4B;AAAA,EACxC,YACkB,QACA,cAChB;AAFgB,SAAA,SAAA;AACA,SAAA,eAAA;AAAA,EAAA;AAAA,EAGlB,cAAiE;AAC1D,UAAA,oBAAoB,OAAO,OAAO,KAAK,OAAO,QAAQ,EAC1D,OAAO,CAAM,OAAA,GAAG,MAAM,YAAY,EAClC,OAAO,CAAM,OAAA,KAAK,aAAa,iCAAiC,GAAG,IAAI,CAAC;AACtE,QAAA,kBAAkB,WAAW,GAAG;AAC5B,aAAA;AAAA,IAAA;AAGF,UAAA,wBAAwB,IAAI,gBAAgB;AAAA,MACjD,MAAM;AAAA,MACN,QAAQ,OAAO,YAAY,kBAAkB,IAAI,CAAM,OAAA,CAAC,GAAG,MAAM,EAAE,OAAO,GAAG,KAAM,CAAA,CAAC,CAAC;AAAA,IAAA,CACrF;AAEK,UAAA,qBAAqB,IAAI,uBAAuB;AAAA,MACrD,MAAM;AAAA,MACN,QAAQ;AAAA,QACP,cAAc,EAAE,MAAM,eAAe;AAAA,MAAA;AAAA,IACtC,CACA;AACM,WAAA;AAAA,MACN,MAAM,IAAI,kBAAkB;AAAA,QAC3B,MAAM;AAAA,QACN,QAAQ;AAAA,UACP,IAAI,EAAE,MAAM,eAAe;AAAA,QAAA;AAAA,MAC5B,CACA;AAAA,MACD,MAAM;AAAA,QACL,MAAM,EAAE,MAAM,sBAAsB;AAAA,QACpC,SAAS,EAAE,MAAM,mBAAmB;AAAA,MACrC;AAAA,MACA,SAAS,OAAO,QAAQ,MAAM,YAAY;AAClC,eAAA,MAAM,QAAQ,mBAAmB,oBAAoB,QAAQ,KAAK,MAAM,KAAK,OAAO;AAAA,MAAA;AAAA,IAE7F;AAAA,EAAA;AAEF;"}
|
|
@@ -61,7 +61,6 @@ const EventManager = require("./src/mapper/EventManager.cjs");
|
|
|
61
61
|
require("node:crypto");
|
|
62
62
|
const Path = require("./src/mapper/select/Path.cjs");
|
|
63
63
|
require("@contember/logger");
|
|
64
|
-
const WhereBuilder = require("./src/mapper/select/WhereBuilder.cjs");
|
|
65
64
|
const Mapper = require("./src/mapper/Mapper.cjs");
|
|
66
65
|
const MapperFactory = require("./src/mapper/MapperFactory.cjs");
|
|
67
66
|
exports.Authorizator = Authorizator.Authorizator;
|
|
@@ -137,7 +136,6 @@ exports.BeforeUpdateEvent = EventManager.BeforeUpdateEvent;
|
|
|
137
136
|
exports.EventManager = EventManager.EventManager;
|
|
138
137
|
exports.Path = Path.Path;
|
|
139
138
|
exports.PathFactory = Path.PathFactory;
|
|
140
|
-
exports.WhereBuilder = WhereBuilder.WhereBuilder;
|
|
141
139
|
exports.Mapper = Mapper.Mapper;
|
|
142
140
|
exports.MapperFactory = MapperFactory.MapperFactory;
|
|
143
141
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/production/index.js
CHANGED
|
@@ -59,7 +59,6 @@ import { AfterCommitEvent, AfterInsertEvent, AfterJunctionUpdateEvent, AfterUpda
|
|
|
59
59
|
import "node:crypto";
|
|
60
60
|
import { Path, PathFactory } from "./src/mapper/select/Path.js";
|
|
61
61
|
import "@contember/logger";
|
|
62
|
-
import { WhereBuilder } from "./src/mapper/select/WhereBuilder.js";
|
|
63
62
|
import { Mapper } from "./src/mapper/Mapper.js";
|
|
64
63
|
import { MapperFactory } from "./src/mapper/MapperFactory.js";
|
|
65
64
|
export {
|
|
@@ -128,7 +127,6 @@ export {
|
|
|
128
127
|
ValidationQueriesProvider,
|
|
129
128
|
ValidationResolver,
|
|
130
129
|
VariableInjector,
|
|
131
|
-
WhereBuilder,
|
|
132
130
|
WhereTypeProvider,
|
|
133
131
|
aliasAwareResolver,
|
|
134
132
|
createAclVariables,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -51,16 +51,17 @@ var __defProp = Object.defineProperty;
|
|
|
51
51
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
52
|
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "", value);
|
|
53
53
|
class ExecutionContainerFactory {
|
|
54
|
-
constructor(providers) {
|
|
54
|
+
constructor(providers, whereOptimizerOptions) {
|
|
55
55
|
this.providers = providers;
|
|
56
|
+
this.whereOptimizerOptions = whereOptimizerOptions;
|
|
56
57
|
__publicField(this, "hooks", []);
|
|
57
58
|
}
|
|
58
59
|
createBuilder(args) {
|
|
59
60
|
const builder = this.createBuilderInternal(args);
|
|
60
61
|
return this.hooks.reduce((acc, cb) => cb(acc), builder);
|
|
61
62
|
}
|
|
62
|
-
createBuilderInternal({ permissions, identityVariables, identityId, db, schema, schemaMeta, systemSchema, stage, project, schemaDatabaseMetadata }) {
|
|
63
|
-
return new dic.Builder({}).addService("systemSchema", () => systemSchema).addService("db", () => db).addService("project", () => project).addService("stage", () => stage).addService("schema", () => schema).addService("schemaMeta", () => schemaMeta).addService("schemaDatabaseMetadata", () => schemaDatabaseMetadata).addService("providers", () => this.providers).addService("variableInjector", ({ schema: schema2 }) => new VariableInjector.VariableInjector(schema2.model, identityVariables)).addService("predicateFactory", ({ variableInjector, schema: schema2 }) => new PredicateFactory.PredicateFactory(permissions, schema2.model, variableInjector)).addService("predicatesInjector", ({ predicateFactory, schema: schema2 }) => new PredicatesInjector.PredicatesInjector(schema2.model, predicateFactory)).addService("joinBuilder", ({ schema: schema2 }) => new JoinBuilder.JoinBuilder(schema2.model)).addService("conditionBuilder", () => new ConditionBuilder.ConditionBuilder()).addService("pathFactory", () => new Path.PathFactory()).addService("whereOptimized", ({ schema: schema2 }) => new WhereOptimizer.WhereOptimizer(schema2.model, new ConditionOptimizer.ConditionOptimizer())).addService("whereBuilder", ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema: schema2 }) => new WhereBuilder.WhereBuilder(
|
|
63
|
+
createBuilderInternal({ permissions, identityVariables, identityId, db, schema, schemaMeta, systemSchema, stage, project, schemaDatabaseMetadata, userInfo }) {
|
|
64
|
+
return new dic.Builder({}).addService("systemSchema", () => systemSchema).addService("db", () => db).addService("project", () => project).addService("stage", () => stage).addService("schema", () => schema).addService("schemaMeta", () => schemaMeta).addService("schemaDatabaseMetadata", () => schemaDatabaseMetadata).addService("userInfo", () => userInfo).addService("providers", () => this.providers).addService("variableInjector", ({ schema: schema2 }) => new VariableInjector.VariableInjector(schema2.model, identityVariables)).addService("predicateFactory", ({ variableInjector, schema: schema2 }) => new PredicateFactory.PredicateFactory(permissions, schema2.model, variableInjector)).addService("predicatesInjector", ({ predicateFactory, schema: schema2 }) => new PredicatesInjector.PredicatesInjector(schema2.model, predicateFactory)).addService("joinBuilder", ({ schema: schema2 }) => new JoinBuilder.JoinBuilder(schema2.model)).addService("conditionBuilder", () => new ConditionBuilder.ConditionBuilder()).addService("pathFactory", () => new Path.PathFactory()).addService("whereOptimized", ({ schema: schema2 }) => new WhereOptimizer.WhereOptimizer(schema2.model, new ConditionOptimizer.ConditionOptimizer(), this.whereOptimizerOptions)).addService("whereBuilder", ({ joinBuilder, conditionBuilder, pathFactory, whereOptimized, schema: schema2 }) => new WhereBuilder.WhereBuilder(
|
|
64
65
|
schema2.model,
|
|
65
66
|
joinBuilder,
|
|
66
67
|
conditionBuilder,
|
|
@@ -86,7 +87,7 @@ class ExecutionContainerFactory {
|
|
|
86
87
|
predicateFactory
|
|
87
88
|
);
|
|
88
89
|
}
|
|
89
|
-
}()).addService("insertBuilderFactory", ({ whereBuilder, pathFactory, schema: schema2, predicateFactory }) => new InsertBuilderFactory.InsertBuilderFactory(schema2.model, whereBuilder, pathFactory, predicateFactory)).addService("updateBuilderFactory", ({ whereBuilder, pathFactory, schema: schema2, predicateFactory }) => new UpdateBuilderFactory.UpdateBuilderFactory(schema2.model, whereBuilder, pathFactory, predicateFactory)).addService("connectJunctionHandler", () => new JunctionTableManager.JunctionConnectHandler()).addService("disconnectJunctionHandler", ({}) => new JunctionTableManager.JunctionDisconnectHandler()).addService("junctionTableManager", ({ predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory, schema: schema2 }) => new JunctionTableManager.JunctionTableManager(schema2.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory)).addService("deleteExecutor", ({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema: schema2 }) => new DeleteExecutor.DeleteExecutor(schema2.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory)).addService("updater", ({
|
|
90
|
+
}()).addService("insertBuilderFactory", ({ whereBuilder, pathFactory, schema: schema2, predicateFactory }) => new InsertBuilderFactory.InsertBuilderFactory(schema2.model, whereBuilder, pathFactory, predicateFactory)).addService("updateBuilderFactory", ({ whereBuilder, pathFactory, schema: schema2, predicateFactory }) => new UpdateBuilderFactory.UpdateBuilderFactory(schema2.model, whereBuilder, pathFactory, predicateFactory)).addService("connectJunctionHandler", () => new JunctionTableManager.JunctionConnectHandler()).addService("disconnectJunctionHandler", ({}) => new JunctionTableManager.JunctionDisconnectHandler()).addService("junctionTableManager", ({ predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory, schema: schema2 }) => new JunctionTableManager.JunctionTableManager(schema2.model, predicateFactory, whereBuilder, connectJunctionHandler, disconnectJunctionHandler, pathFactory)).addService("deleteExecutor", ({ predicateFactory, updateBuilderFactory, whereBuilder, pathFactory, schema: schema2 }) => new DeleteExecutor.DeleteExecutor(schema2.model, predicateFactory, whereBuilder, updateBuilderFactory, pathFactory)).addService("updater", ({ updateBuilderFactory, schema: schema2 }) => new Updater.Updater(schema2.model, updateBuilderFactory)).addService("inserter", ({ insertBuilderFactory, providers, schema: schema2, schemaDatabaseMetadata: schemaDatabaseMetadata2 }) => new Inserter.Inserter(schema2.model, schemaDatabaseMetadata2, insertBuilderFactory, providers, { uuidVersion: schema2.settings.content?.uuidVersion })).addService("mapperFactory", ({ predicatesInjector, selectBuilderFactory, uniqueWhereExpander, whereBuilder, junctionTableManager, deleteExecutor, updater, inserter, pathFactory, providers, schema: schema2, schemaDatabaseMetadata: schemaDatabaseMetadata2 }) => {
|
|
90
91
|
return new MapperFactory.MapperFactory(
|
|
91
92
|
db,
|
|
92
93
|
identityId,
|