@contember/binding 1.0.3 → 1.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/development/accessorPropagation/useExtendTree.js +25 -0
- package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/development/accessorTree/AccessorTree.js +9 -4
- package/dist/development/accessorTree/AccessorTree.js.map +1 -1
- package/dist/development/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +17 -4
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/development/accessors/EntityAccessor.js +0 -32
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +1 -1
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +3 -0
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/DataBinding.js +11 -23
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/DirtinessTracker.js +4 -13
- package/dist/development/core/DirtinessTracker.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.js +12 -7
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/MarkerComparator.js +1 -1
- package/dist/development/core/MarkerMerger.js +1 -4
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +100 -94
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/RequestResponseNormalizer.js +27 -31
- package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/core/StateInitializer.js +23 -26
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeAugmenter.js +10 -10
- package/dist/development/core/TreeAugmenter.js.map +1 -1
- package/dist/development/core/TreeFilterGenerator.js +2 -2
- package/dist/development/core/TreeFilterGenerator.js.map +1 -1
- package/dist/development/core/TreeStore.js +3 -3
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.js +4 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +13 -12
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.js +2 -2
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +3 -3
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.js +2 -2
- package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js +5 -3
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/core/schema/Schema.js +3 -0
- package/dist/development/core/schema/Schema.js.map +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js +4 -12
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/coreComponents/EntitySubTree.js +4 -22
- package/dist/development/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/development/coreComponents/Field.js +5 -1
- package/dist/development/coreComponents/Field.js.map +1 -1
- package/dist/development/coreComponents/HasMany.js +3 -5
- package/dist/development/coreComponents/HasMany.js.map +1 -1
- package/dist/development/coreComponents/HasOne.js +3 -5
- package/dist/development/coreComponents/HasOne.js.map +1 -1
- package/dist/development/dao/Environment.js +147 -94
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +159 -0
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -0
- package/dist/development/helperComponents/If.js +39 -0
- package/dist/development/helperComponents/If.js.map +1 -0
- package/dist/development/helperComponents/SugaredField.js +1 -1
- package/dist/development/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/development/index.js +4 -1
- package/dist/development/index.js.map +1 -1
- package/dist/development/queryLanguage/MarkerFactory.js +4 -3
- package/dist/development/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/development/queryLanguage/Parser.js +18 -6
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
- package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
- package/dist/production/accessorPropagation/useExtendTree.js +25 -0
- package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
- package/dist/production/accessorTree/AccessorTree.js +9 -4
- package/dist/production/accessorTree/AccessorTree.js.map +1 -1
- package/dist/production/accessorTree/AccessorTreeStateContext.js +6 -0
- package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
- package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js +17 -4
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessorTree/useAccessorTreeState.js +5 -0
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/production/accessors/EntityAccessor.js +0 -32
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +1 -1
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +3 -0
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/DataBinding.js +11 -14
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/DirtinessTracker.js +4 -13
- package/dist/production/core/DirtinessTracker.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.js +11 -6
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/MarkerComparator.js +1 -1
- package/dist/production/core/MarkerMerger.js +1 -4
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +100 -94
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/RequestResponseNormalizer.js +27 -31
- package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/core/StateInitializer.js +23 -26
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeAugmenter.js +10 -10
- package/dist/production/core/TreeAugmenter.js.map +1 -1
- package/dist/production/core/TreeFilterGenerator.js +2 -2
- package/dist/production/core/TreeFilterGenerator.js.map +1 -1
- package/dist/production/core/TreeStore.js +3 -3
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.js +4 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +13 -12
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js +3 -3
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.js +2 -2
- package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js +5 -3
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/core/schema/Schema.js +3 -0
- package/dist/production/core/schema/Schema.js.map +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js +4 -12
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/coreComponents/EntitySubTree.js +4 -22
- package/dist/production/coreComponents/EntitySubTree.js.map +1 -1
- package/dist/production/coreComponents/Field.js +5 -1
- package/dist/production/coreComponents/Field.js.map +1 -1
- package/dist/production/coreComponents/HasMany.js +3 -5
- package/dist/production/coreComponents/HasMany.js.map +1 -1
- package/dist/production/coreComponents/HasOne.js +3 -5
- package/dist/production/coreComponents/HasOne.js.map +1 -1
- package/dist/production/dao/Environment.js +147 -94
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +159 -0
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -0
- package/dist/production/helperComponents/If.js +39 -0
- package/dist/production/helperComponents/If.js.map +1 -0
- package/dist/production/helperComponents/SugaredField.js +1 -1
- package/dist/production/helperComponents/helpers/FilterEvaluator.js +38 -0
- package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +41 -0
- package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
- package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
- package/dist/production/index.js +4 -1
- package/dist/production/index.js.map +1 -1
- package/dist/production/queryLanguage/MarkerFactory.js +4 -3
- package/dist/production/queryLanguage/MarkerFactory.js.map +1 -1
- package/dist/production/queryLanguage/Parser.js +15 -6
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/types/accessorPropagation/index.d.ts +1 -0
- package/dist/types/accessorPropagation/index.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
- package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
- package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
- package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
- package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +4 -4
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
- package/dist/types/accessorTree/PersistResult.d.ts +2 -1
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
- package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
- package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
- package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
- package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
- package/dist/types/accessorTree/index.d.ts +1 -0
- package/dist/types/accessorTree/index.d.ts.map +1 -1
- package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
- package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
- package/dist/types/accessors/EntityAccessor.d.ts +1 -3
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/DirtinessTracker.d.ts +2 -5
- package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts +2 -2
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
- package/dist/types/core/EventManager.d.ts +1 -1
- package/dist/types/core/EventManager.d.ts.map +1 -1
- package/dist/types/core/MarkerMerger.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +1 -5
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts +3 -3
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/VariableInputTransformer.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts +2 -1
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
- package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
- package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/Schema.d.ts +2 -0
- package/dist/types/core/schema/Schema.d.ts.map +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
- package/dist/types/core/schema/index.d.ts +0 -1
- package/dist/types/core/schema/index.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts +1 -1
- package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
- package/dist/types/coreComponents/Field.d.ts.map +1 -1
- package/dist/types/coreComponents/HasMany.d.ts +1 -1
- package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
- package/dist/types/coreComponents/HasOne.d.ts +1 -1
- package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +81 -42
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts +19 -0
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -0
- package/dist/types/helperComponents/If.d.ts +14 -0
- package/dist/types/helperComponents/If.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
- package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
- package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
- package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +1 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -1
- package/dist/types/queryLanguage/MarkerFactory.d.ts.map +1 -1
- package/dist/types/queryLanguage/Parser.d.ts.map +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
- package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -6
- package/src/accessorPropagation/index.ts +1 -0
- package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
- package/src/accessorPropagation/useEntitySubTree.ts +8 -1
- package/src/accessorPropagation/useExtendTree.ts +28 -0
- package/src/accessorTree/AccessorTree.tsx +18 -12
- package/src/accessorTree/AccessorTreeStateContext.ts +6 -0
- package/src/accessorTree/MutationRequestResponse.ts +3 -1
- package/src/accessorTree/NormalizedPersistedData.ts +4 -4
- package/src/accessorTree/PersistResult.ts +2 -1
- package/src/accessorTree/QueryRequestResponse.ts +17 -14
- package/src/accessorTree/RuntimeId.ts +27 -6
- package/src/accessorTree/index.ts +1 -0
- package/src/accessorTree/useAccessorTreeState.ts +4 -0
- package/src/accessors/EntityAccessor.ts +2 -51
- package/src/accessors/EntityListAccessor.ts +3 -3
- package/src/core/AccessorErrorManager.ts +3 -0
- package/src/core/DataBinding.ts +11 -33
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/ErrorsPreprocessor.ts +2 -2
- package/src/core/EventManager.ts +14 -8
- package/src/core/MarkerMerger.ts +1 -4
- package/src/core/MutationGenerator.ts +137 -130
- package/src/core/RequestResponseNormalizer.ts +37 -38
- package/src/core/StateInitializer.ts +35 -42
- package/src/core/TreeAugmenter.ts +11 -11
- package/src/core/TreeFilterGenerator.ts +5 -5
- package/src/core/TreeStore.ts +12 -6
- package/src/core/VariableInputTransformer.ts +7 -4
- package/src/core/operations/EntityOperations.ts +12 -13
- package/src/core/operations/FieldOperations.ts +2 -2
- package/src/core/operations/ListOperations.ts +6 -5
- package/src/core/operations/OperationsHelpers.ts +2 -2
- package/src/core/requestAliases/MutationAlias.ts +5 -3
- package/src/core/schema/RawSchemaEntity.ts +1 -2
- package/src/core/schema/Schema.ts +5 -0
- package/src/core/schema/SchemaEntity.ts +1 -1
- package/src/core/schema/SchemaPreprocessor.ts +1 -1
- package/src/core/schema/index.ts +0 -1
- package/src/coreComponents/EntityListSubTree.tsx +5 -16
- package/src/coreComponents/EntitySubTree.tsx +17 -32
- package/src/coreComponents/Field.tsx +4 -0
- package/src/coreComponents/HasMany.tsx +4 -6
- package/src/coreComponents/HasOne.tsx +6 -7
- package/src/dao/Environment.ts +221 -126
- package/src/dao/TreeNodeEnvironmentFactory.ts +228 -0
- package/src/helperComponents/If.tsx +71 -0
- package/src/helperComponents/helpers/FilterEvaluator.ts +48 -0
- package/src/helperComponents/helpers/FilterFieldsCollector.ts +49 -0
- package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/queryLanguage/MarkerFactory.ts +5 -3
- package/src/queryLanguage/Parser.ts +24 -11
- package/src/treeParameters/primitives/EntityId.ts +1 -1
- package/dist/development/core/schema/SchemaValidator.js +0 -116
- package/dist/development/core/schema/SchemaValidator.js.map +0 -1
- package/dist/types/core/schema/SchemaValidator.d.ts +0 -14
- package/dist/types/core/schema/SchemaValidator.d.ts.map +0 -1
- package/src/core/schema/SchemaValidator.ts +0 -238
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Environment } from './Environment'
|
|
2
|
+
import {
|
|
3
|
+
HasOneRelation,
|
|
4
|
+
SugaredQualifiedEntityList,
|
|
5
|
+
SugaredQualifiedSingleEntity,
|
|
6
|
+
SugaredRelativeEntityList,
|
|
7
|
+
SugaredRelativeSingleEntity,
|
|
8
|
+
SugaredRelativeSingleField,
|
|
9
|
+
SugaredUnconstrainedQualifiedEntityList,
|
|
10
|
+
SugaredUnconstrainedQualifiedSingleEntity,
|
|
11
|
+
} from '../treeParameters'
|
|
12
|
+
import { QueryLanguage } from '../queryLanguage'
|
|
13
|
+
import { BindingError } from '../BindingError'
|
|
14
|
+
import { NIL_UUID } from '../bindingTypes'
|
|
15
|
+
import { whereToFilter } from '@contember/client'
|
|
16
|
+
import { BaseRelation, Schema, SchemaColumn, SchemaEntity, SchemaField, SchemaRelation } from '../core/schema'
|
|
17
|
+
import levenshtein from 'js-levenshtein'
|
|
18
|
+
|
|
19
|
+
export class TreeNodeEnvironmentFactory {
|
|
20
|
+
|
|
21
|
+
public static createEnvironmentForEntityListSubtree(
|
|
22
|
+
environment: Environment,
|
|
23
|
+
sugaredEntityList: SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,
|
|
24
|
+
): Environment {
|
|
25
|
+
let entityList
|
|
26
|
+
let rootWhere
|
|
27
|
+
let expectedCardinality: Environment.SubTreeNode['expectedCardinality']
|
|
28
|
+
|
|
29
|
+
if (sugaredEntityList.isCreating) {
|
|
30
|
+
entityList = QueryLanguage.desugarUnconstrainedQualifiedEntityList(sugaredEntityList, environment)
|
|
31
|
+
rootWhere = { id: { eq: NIL_UUID } } as const
|
|
32
|
+
expectedCardinality = 'zero'
|
|
33
|
+
|
|
34
|
+
} else {
|
|
35
|
+
entityList = QueryLanguage.desugarQualifiedEntityList(sugaredEntityList, environment)
|
|
36
|
+
rootWhere = entityList.filter ?? {}
|
|
37
|
+
expectedCardinality = 'zero-to-many'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const entitySchema = this.resolveEntity(environment.getSchema(), entityList.entityName, 'entity list')
|
|
41
|
+
|
|
42
|
+
return environment.withSubTree({
|
|
43
|
+
type: 'subtree-entity-list',
|
|
44
|
+
entity: entitySchema,
|
|
45
|
+
expectedCardinality,
|
|
46
|
+
filter: rootWhere,
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public static createEnvironmentForEntitySubtree(
|
|
51
|
+
environment: Environment,
|
|
52
|
+
sugaredEntityList: SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,
|
|
53
|
+
): Environment {
|
|
54
|
+
let entity
|
|
55
|
+
let rootWhere
|
|
56
|
+
let expectedCardinality: Environment.SubTreeNode['expectedCardinality']
|
|
57
|
+
|
|
58
|
+
if (sugaredEntityList.isCreating) {
|
|
59
|
+
rootWhere = { id: { eq: NIL_UUID } } as const
|
|
60
|
+
expectedCardinality = 'zero'
|
|
61
|
+
entity = QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(sugaredEntityList, environment)
|
|
62
|
+
|
|
63
|
+
} else {
|
|
64
|
+
entity = QueryLanguage.desugarQualifiedSingleEntity(sugaredEntityList, environment, { missingSetOnCreate: 'fill' })
|
|
65
|
+
rootWhere = whereToFilter(entity.where)
|
|
66
|
+
expectedCardinality = entity.setOnCreate ? 'zero-or-one' : 'one'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const entitySchema = this.resolveEntity(environment.getSchema(), entity.entityName, 'entity')
|
|
70
|
+
|
|
71
|
+
return environment.withSubTree({
|
|
72
|
+
type: 'subtree-entity',
|
|
73
|
+
entity: entitySchema,
|
|
74
|
+
expectedCardinality: expectedCardinality,
|
|
75
|
+
filter: rootWhere,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public static createEnvironmentForEntityList(
|
|
80
|
+
environment: Environment,
|
|
81
|
+
sugaredRelativeEntityList: SugaredRelativeEntityList,
|
|
82
|
+
): Environment {
|
|
83
|
+
const relativeEntityList = QueryLanguage.desugarRelativeEntityList(sugaredRelativeEntityList, environment)
|
|
84
|
+
const hasOneEnvironment = this.traverseHasOnePath(environment, relativeEntityList.hasOneRelationPath)
|
|
85
|
+
const hasManyField = relativeEntityList.hasManyRelation.field
|
|
86
|
+
|
|
87
|
+
const field = this.assertHasManyRelation(hasOneEnvironment, hasManyField)
|
|
88
|
+
|
|
89
|
+
const targetEntity = environment.getSchema().getEntity(field.targetEntity)
|
|
90
|
+
if (!targetEntity) {
|
|
91
|
+
throw new BindingError('should not happen')
|
|
92
|
+
}
|
|
93
|
+
return hasOneEnvironment.withSubTreeChild({
|
|
94
|
+
type: 'entity-list',
|
|
95
|
+
field,
|
|
96
|
+
entity: targetEntity,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public static createEnvironmentForEntity(
|
|
101
|
+
environment: Environment,
|
|
102
|
+
sugaredRelativeSingleEntity: SugaredRelativeSingleEntity,
|
|
103
|
+
) {
|
|
104
|
+
const relativeSingleEntity = QueryLanguage.desugarRelativeSingleEntity(sugaredRelativeSingleEntity, environment)
|
|
105
|
+
|
|
106
|
+
return this.traverseHasOnePath(environment, relativeSingleEntity.hasOneRelationPath)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public static createEnvironmentForField(
|
|
110
|
+
environment: Environment,
|
|
111
|
+
sugaredRelativeSingleField: SugaredRelativeSingleField,
|
|
112
|
+
) {
|
|
113
|
+
const relativeSingleField = QueryLanguage.desugarRelativeSingleField(sugaredRelativeSingleField, environment)
|
|
114
|
+
const hasOneEnvironment = this.traverseHasOnePath(environment, relativeSingleField.hasOneRelationPath)
|
|
115
|
+
|
|
116
|
+
const field = this.resolveColumn(hasOneEnvironment, relativeSingleField.field)
|
|
117
|
+
|
|
118
|
+
return hasOneEnvironment.withSubTreeChild({
|
|
119
|
+
type: 'column',
|
|
120
|
+
entity: environment.getSubTreeNode().entity,
|
|
121
|
+
field,
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private static traverseHasOnePath(
|
|
126
|
+
environment: Environment,
|
|
127
|
+
hasOneRelationPath: HasOneRelation[],
|
|
128
|
+
): Environment {
|
|
129
|
+
for (const pathItem of hasOneRelationPath) {
|
|
130
|
+
const field = this.resolveHasOneRelation(environment, pathItem.field, !!pathItem.reducedBy)
|
|
131
|
+
const targetEntity = environment.getSchema().getEntity(field.targetEntity)
|
|
132
|
+
if (!targetEntity) {
|
|
133
|
+
throw new BindingError('should not happen')
|
|
134
|
+
}
|
|
135
|
+
environment = environment.withSubTreeChild({
|
|
136
|
+
type: 'entity',
|
|
137
|
+
field,
|
|
138
|
+
entity: targetEntity,
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
return environment
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private static resolveHasOneRelation(environment: Environment, field: string, isReduced: boolean): SchemaRelation {
|
|
145
|
+
if (isReduced) {
|
|
146
|
+
return this.resolveRelation(environment, field, 'reduced has-one relation', ['ManyHasMany', 'OneHasMany'])
|
|
147
|
+
}
|
|
148
|
+
return this.resolveRelation(environment, field, 'a has-one relation', ['ManyHasOne', 'OneHasOne'])
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private static assertHasManyRelation(environment: Environment, field: string): SchemaRelation {
|
|
152
|
+
return this.resolveRelation(environment, field, 'a has-many relation', ['ManyHasMany', 'OneHasMany'])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
private static resolveRelation(environment: Environment, field: string, relationDescription: string, expectedRelationType: BaseRelation['type'][]): SchemaRelation {
|
|
157
|
+
return this.resolveField(environment, field, (field): field is SchemaRelation => {
|
|
158
|
+
return field.__typename === '_Relation' && expectedRelationType.includes(field.type)
|
|
159
|
+
}, relationDescription)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private static resolveEntity(schema: Schema, entityName: string, type: 'entity' | 'entity list'): SchemaEntity {
|
|
163
|
+
const entity = schema.getEntity(entityName)
|
|
164
|
+
if (!entity) {
|
|
165
|
+
const alternative = this.recommendAlternative(entityName, schema.store.entities.keys())
|
|
166
|
+
const didYouMean = alternative ? `Did you mean '${alternative}'?` : ''
|
|
167
|
+
throw new BindingError(`Invalid ${type} sub tree: Entity '${entityName}' doesn't exist. ${didYouMean}`)
|
|
168
|
+
}
|
|
169
|
+
return entity
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
private static resolveColumn(environment: Environment, fieldName: string): SchemaColumn {
|
|
173
|
+
return this.resolveField(environment, fieldName, (field): field is SchemaColumn => field.__typename === '_Column', 'an ordinary field')
|
|
174
|
+
// TODO check that defaultValue matches the type
|
|
175
|
+
// TODO run custom validators
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private static resolveField<T extends SchemaField>(environment: Environment, fieldName: string, matcher: (field: SchemaField) => field is T, expectedDescription: string): T {
|
|
179
|
+
const treeLocation = environment.getSubTreeNode()
|
|
180
|
+
const entity = treeLocation.entity
|
|
181
|
+
const field = entity.fields.get(fieldName)
|
|
182
|
+
if (!field) {
|
|
183
|
+
const alternative = this.recommendAlternative(
|
|
184
|
+
fieldName,
|
|
185
|
+
Array.from(entity.fields)
|
|
186
|
+
.filter(([, field]) => matcher(field))
|
|
187
|
+
.map(([fieldName]) => fieldName),
|
|
188
|
+
)
|
|
189
|
+
const didYouMean = alternative ? `Did you mean '${alternative}'?` : ''
|
|
190
|
+
throw new BindingError(`Field '${fieldName}' doesn't exist on ${this.describeLocation(environment)}. ${didYouMean}`)
|
|
191
|
+
}
|
|
192
|
+
if (!matcher(field)) {
|
|
193
|
+
const actual = field.__typename === '_Column' ? 'an ordinary field' : `a ${field.type} relation`
|
|
194
|
+
throw new BindingError(
|
|
195
|
+
`Invalid field: the name '${field.name}' on ${this.describeLocation(environment)} ` +
|
|
196
|
+
`refers to ${actual} but is being used as a ${expectedDescription}.`,
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
return field
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private static describeLocation(environment: Environment): string {
|
|
203
|
+
const path = []
|
|
204
|
+
const loc = environment.getSubTreeNode()
|
|
205
|
+
for (let env = environment;; env = env.getParent()) {
|
|
206
|
+
const node = env.getSubTreeNode()
|
|
207
|
+
if (node.type === 'subtree-entity' || node.type === 'subtree-entity-list') {
|
|
208
|
+
return `entity '${loc.entity.name}' in path '${[node.entity.name, ...path].join('.')}'`
|
|
209
|
+
}
|
|
210
|
+
path.push(node.field.name)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public static recommendAlternative(original: string, possibleAlternatives: Iterable<string>): string | undefined {
|
|
215
|
+
let bestAlternative: string | undefined = undefined
|
|
216
|
+
let bestAlternativeDistance = Number.MAX_SAFE_INTEGER
|
|
217
|
+
|
|
218
|
+
for (const alternative of possibleAlternatives) {
|
|
219
|
+
const distance = levenshtein(original, alternative)
|
|
220
|
+
|
|
221
|
+
if (distance < bestAlternativeDistance) {
|
|
222
|
+
bestAlternative = alternative
|
|
223
|
+
bestAlternativeDistance = distance
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return bestAlternative
|
|
227
|
+
}
|
|
228
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { useMemo } from 'react'
|
|
3
|
+
import { Component, Field } from '../coreComponents'
|
|
4
|
+
import { EntityAccessor } from '../accessors'
|
|
5
|
+
import { QueryLanguage } from '../queryLanguage'
|
|
6
|
+
import { useEntity, useEnvironment } from '../accessorPropagation'
|
|
7
|
+
import { Filter } from '../treeParameters'
|
|
8
|
+
import { FilterFieldsCollector } from './helpers/FilterFieldsCollector'
|
|
9
|
+
import { FilterEvaluator } from './helpers/FilterEvaluator'
|
|
10
|
+
|
|
11
|
+
export type IfProps =
|
|
12
|
+
| IfFilterProps
|
|
13
|
+
| IfCallbackProps
|
|
14
|
+
|
|
15
|
+
export interface IfFilterProps {
|
|
16
|
+
condition: string | Filter
|
|
17
|
+
children?: ReactNode
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface IfCallbackProps {
|
|
21
|
+
condition: (accessor: EntityAccessor) => boolean
|
|
22
|
+
children?: ReactNode
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const If = Component<IfProps>(props => {
|
|
26
|
+
return typeof props.condition !== 'function'
|
|
27
|
+
? <IfFilter condition={props.condition}>{props.children}</IfFilter>
|
|
28
|
+
: <IfCallback condition={props.condition}>{props.condition}</IfCallback>
|
|
29
|
+
},
|
|
30
|
+
'If',
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const IfCallback = Component<IfCallbackProps>(
|
|
34
|
+
({ children, condition }) => {
|
|
35
|
+
const entity = useEntity()
|
|
36
|
+
const evaluated = useMemo(() => condition(entity), [condition, entity])
|
|
37
|
+
|
|
38
|
+
return evaluated ? <>{children}</> : null
|
|
39
|
+
},
|
|
40
|
+
({ children }) => {
|
|
41
|
+
return <>{children}</>
|
|
42
|
+
},
|
|
43
|
+
'IfCallback',
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const IfFilter = Component<IfFilterProps>(
|
|
47
|
+
({ children, condition }) => {
|
|
48
|
+
const env = useEnvironment()
|
|
49
|
+
const entity = useEntity()
|
|
50
|
+
|
|
51
|
+
const schema = env.getSchema()
|
|
52
|
+
const evaluated = useMemo(
|
|
53
|
+
() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),
|
|
54
|
+
[condition, entity, env, schema],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
return evaluated ? <>{children}</> : null
|
|
58
|
+
},
|
|
59
|
+
({ children, condition }, env) => {
|
|
60
|
+
const desugaredFilter = QueryLanguage.desugarFilter(condition, env)
|
|
61
|
+
const collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)
|
|
62
|
+
const additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>
|
|
63
|
+
|
|
64
|
+
return <>
|
|
65
|
+
{additionalFields}
|
|
66
|
+
{children}
|
|
67
|
+
</>
|
|
68
|
+
},
|
|
69
|
+
'IfFilter',
|
|
70
|
+
)
|
|
71
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Schema } from '../../core/schema'
|
|
2
|
+
import { Input } from '@contember/client'
|
|
3
|
+
import { EntityAccessor } from '../../accessors'
|
|
4
|
+
import { Filter } from '../../treeParameters'
|
|
5
|
+
import { BindingError } from '../../BindingError'
|
|
6
|
+
import { evaluateCondition } from './evaluateCondition'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class FilterEvaluator {
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly schema: Schema,
|
|
12
|
+
) {
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
evaluateFilter(entity: EntityAccessor, filter: Filter): boolean {
|
|
16
|
+
const entitySchema = this.schema.getEntity(entity.name)
|
|
17
|
+
if (!entitySchema) {
|
|
18
|
+
throw new BindingError()
|
|
19
|
+
}
|
|
20
|
+
let acc = true
|
|
21
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
22
|
+
if (key === 'and' || key === 'or') {
|
|
23
|
+
if (!Array.isArray(value)) {
|
|
24
|
+
throw new BindingError()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const operation = key === 'and' ? 'every' : 'some' as const
|
|
28
|
+
acc &&= value[operation](it => this.evaluateFilter(entity, it))
|
|
29
|
+
|
|
30
|
+
} else if (key === 'not') {
|
|
31
|
+
acc &&= !this.evaluateFilter(entity, value as Filter)
|
|
32
|
+
|
|
33
|
+
} else {
|
|
34
|
+
const field = entitySchema.fields.get(key)
|
|
35
|
+
if (!field) {
|
|
36
|
+
throw new BindingError()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (field.__typename === '_Column') {
|
|
40
|
+
acc &&= evaluateCondition(entity.getField(key).value, value as Input.Condition)
|
|
41
|
+
} else {
|
|
42
|
+
acc &&= this.evaluateFilter(entity.getEntity(key), value as Filter)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return acc
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Schema, SchemaEntity } from '../../core/schema'
|
|
2
|
+
import { Filter } from '../../treeParameters'
|
|
3
|
+
import { BindingError } from '../../BindingError'
|
|
4
|
+
|
|
5
|
+
export class FilterFieldsCollector {
|
|
6
|
+
constructor(
|
|
7
|
+
private readonly schema: Schema,
|
|
8
|
+
private readonly rootFilter: Filter,
|
|
9
|
+
) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
collectFields(entity: SchemaEntity): Set<string> {
|
|
14
|
+
const result = new Set<string>()
|
|
15
|
+
this.collectFieldsInternal(this.rootFilter, entity, [], result)
|
|
16
|
+
return result
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private collectFieldsInternal(filter: Filter, entity: SchemaEntity, path: string[], result: Set<string>): void {
|
|
20
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
21
|
+
if (key === 'and' || key === 'or') {
|
|
22
|
+
if (!Array.isArray(value)) {
|
|
23
|
+
throw new BindingError()
|
|
24
|
+
}
|
|
25
|
+
value?.forEach(it => this.collectFieldsInternal(it, entity, path, result))
|
|
26
|
+
|
|
27
|
+
} else if (key === 'not') {
|
|
28
|
+
this.collectFieldsInternal(value as Filter, entity, path, result)
|
|
29
|
+
|
|
30
|
+
} else {
|
|
31
|
+
const field = entity.fields.get(key)
|
|
32
|
+
if (!field) {
|
|
33
|
+
throw new BindingError(`Invalid field: the name "${key}" does not exist on entity "${entity.name}" `
|
|
34
|
+
+ `in a ${path.length === 0 ? 'root' : `path "${path.join('.')}"`} of a following filter:\n`
|
|
35
|
+
+ JSON.stringify(this.rootFilter, null, ' '))
|
|
36
|
+
}
|
|
37
|
+
if (field.__typename === '_Column') {
|
|
38
|
+
result.add([...path, key].join('.'))
|
|
39
|
+
} else {
|
|
40
|
+
const entity = this.schema.getEntity(field.targetEntity)
|
|
41
|
+
if (!entity) {
|
|
42
|
+
throw new BindingError()
|
|
43
|
+
}
|
|
44
|
+
this.collectFieldsInternal(value as Filter, entity, [...path, key], result)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { GraphQlLiteral, Input } from '@contember/client'
|
|
2
|
+
import { Scalar } from '../../treeParameters'
|
|
3
|
+
import { BindingError } from '../../BindingError'
|
|
4
|
+
|
|
5
|
+
const unwrapGraphqlLiteral = (value: Input.ColumnValue<GraphQlLiteral>): any => {
|
|
6
|
+
if (value instanceof GraphQlLiteral) {
|
|
7
|
+
return value.value
|
|
8
|
+
}
|
|
9
|
+
return value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const evaluateCondition = (value: Scalar | null, condition: Input.Condition<Input.ColumnValue<GraphQlLiteral>>) => {
|
|
13
|
+
const handlers: {
|
|
14
|
+
[K in keyof Required<Input.Condition<any>>]: (
|
|
15
|
+
param: Exclude<Input.Condition<any>[K], undefined>,
|
|
16
|
+
) => boolean
|
|
17
|
+
} = {
|
|
18
|
+
and: expr => expr.every(it => evaluateCondition(value, it)),
|
|
19
|
+
or: expr => expr.some(it => evaluateCondition(value, it)),
|
|
20
|
+
not: expr => !evaluateCondition(value, expr),
|
|
21
|
+
eq: expr => value === unwrapGraphqlLiteral(expr),
|
|
22
|
+
notEq: expr => value !== unwrapGraphqlLiteral(expr),
|
|
23
|
+
isNull: expr => (value === null) === expr,
|
|
24
|
+
in: expr => expr.map(unwrapGraphqlLiteral).includes(value),
|
|
25
|
+
notIn: expr => !expr.map(unwrapGraphqlLiteral).includes(value),
|
|
26
|
+
lt: expr => value !== null && value < unwrapGraphqlLiteral(expr),
|
|
27
|
+
lte: expr => value !== null && value <= unwrapGraphqlLiteral(expr),
|
|
28
|
+
gt: expr => value !== null && value > unwrapGraphqlLiteral(expr),
|
|
29
|
+
gte: expr => value !== null && value >= unwrapGraphqlLiteral(expr),
|
|
30
|
+
contains: expr => typeof value === 'string' && value.includes(unwrapGraphqlLiteral(expr)),
|
|
31
|
+
startsWith: expr => typeof value === 'string' && value.startsWith(unwrapGraphqlLiteral(expr)),
|
|
32
|
+
endsWith: expr => typeof value === 'string' && value.endsWith(unwrapGraphqlLiteral(expr)),
|
|
33
|
+
containsCI: expr => typeof value === 'string' && value.toLowerCase().includes(unwrapGraphqlLiteral(expr).toLowerCase()),
|
|
34
|
+
startsWithCI: expr => typeof value === 'string' && value.toLowerCase().startsWith(unwrapGraphqlLiteral(expr).toLowerCase()),
|
|
35
|
+
endsWithCI: expr => typeof value === 'string' && value.toLowerCase().endsWith(unwrapGraphqlLiteral(expr).toLowerCase()),
|
|
36
|
+
never: () => false,
|
|
37
|
+
always: () => true,
|
|
38
|
+
// deprecated
|
|
39
|
+
null: expr => (value === null) === expr,
|
|
40
|
+
}
|
|
41
|
+
return Object.entries(condition).every(([operator, argument]) => {
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
const handlerKey = operator as keyof typeof handlers
|
|
46
|
+
const handler = handlers[handlerKey]
|
|
47
|
+
if (!handler) {
|
|
48
|
+
throw new BindingError()
|
|
49
|
+
}
|
|
50
|
+
return handler(argument)
|
|
51
|
+
})
|
|
52
|
+
}
|
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
import { assertNever } from '../utils'
|
|
29
29
|
import { QueryLanguage } from './QueryLanguage'
|
|
30
30
|
import { GraphQlLiteral } from '@contember/client'
|
|
31
|
+
import { BindingError } from '../BindingError'
|
|
31
32
|
|
|
32
33
|
export class MarkerFactory {
|
|
33
34
|
private static createSubTreeMarker<
|
|
@@ -191,7 +192,7 @@ export class MarkerFactory {
|
|
|
191
192
|
)
|
|
192
193
|
return this.wrapRelativeEntityFieldMarkers(
|
|
193
194
|
relativeEntityList.hasOneRelationPath,
|
|
194
|
-
environment,
|
|
195
|
+
environment.getParent(),
|
|
195
196
|
this.createEntityFieldMarkersContainer(hasManyRelationMarker),
|
|
196
197
|
)
|
|
197
198
|
}
|
|
@@ -210,7 +211,7 @@ export class MarkerFactory {
|
|
|
210
211
|
return new EntityFieldsWithHoistablesMarker(
|
|
211
212
|
this.wrapRelativeEntityFieldMarkers(
|
|
212
213
|
relativeEntityList.hasOneRelationPath,
|
|
213
|
-
environment,
|
|
214
|
+
environment.getParent(),
|
|
214
215
|
this.createEntityFieldMarkersContainer(hasManyRelationMarker),
|
|
215
216
|
),
|
|
216
217
|
fields.subTrees,
|
|
@@ -236,7 +237,7 @@ export class MarkerFactory {
|
|
|
236
237
|
|
|
237
238
|
return this.wrapRelativeEntityFieldMarkers(
|
|
238
239
|
relativeSingleField.hasOneRelationPath,
|
|
239
|
-
environment,
|
|
240
|
+
environment.getParent(),
|
|
240
241
|
this.createEntityFieldMarkersContainer(getMarker(relativeSingleField)),
|
|
241
242
|
)
|
|
242
243
|
}
|
|
@@ -248,6 +249,7 @@ export class MarkerFactory {
|
|
|
248
249
|
): EntityFieldMarkersContainer {
|
|
249
250
|
for (let i = hasOneRelationPath.length - 1; i >= 0; i--) {
|
|
250
251
|
const marker = this.createHasOneRelationMarker(hasOneRelationPath[i], environment, fields)
|
|
252
|
+
environment = environment.getParent()
|
|
251
253
|
fields = this.createEntityFieldMarkersContainer(marker)
|
|
252
254
|
}
|
|
253
255
|
return fields
|
|
@@ -21,6 +21,7 @@ import type {
|
|
|
21
21
|
import { CacheStore } from './CacheStore'
|
|
22
22
|
import { QueryLanguageError } from './QueryLanguageError'
|
|
23
23
|
import { tokenList, TokenRegExps, tokens } from './tokenList'
|
|
24
|
+
import { BindingError } from '../BindingError'
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
27
|
* TODO:
|
|
@@ -33,7 +34,7 @@ class Parser extends EmbeddedActionsParser {
|
|
|
33
34
|
private static rawInput: string = ''
|
|
34
35
|
private static lexer = new Lexer(tokenList)
|
|
35
36
|
private static parser = new Parser()
|
|
36
|
-
private static environment: Environment =
|
|
37
|
+
private static environment: Environment = Environment.create()
|
|
37
38
|
private static cacheStore: CacheStore = new CacheStore()
|
|
38
39
|
|
|
39
40
|
private qualifiedEntityList = this.RULE<ParsedQualifiedEntityList>('qualifiedEntityList', () => {
|
|
@@ -722,25 +723,37 @@ class Parser extends EmbeddedActionsParser {
|
|
|
722
723
|
return new GraphQlBuilder.GraphQlLiteral(image)
|
|
723
724
|
})
|
|
724
725
|
|
|
725
|
-
private variable = this.RULE<
|
|
726
|
+
private variable = this.RULE<Environment.ResolvedValue>('variable', () => {
|
|
726
727
|
this.CONSUME(tokens.DollarSign)
|
|
727
728
|
const variableName = this.CONSUME(tokens.Identifier).image
|
|
728
729
|
|
|
729
730
|
return this.ACTION(() => {
|
|
730
|
-
if (
|
|
731
|
-
|
|
731
|
+
if (import.meta.env.DEV && variableName === 'rootWhereAsFilter') {
|
|
732
|
+
console.warn('$rootWhereAsFilter is deprecated, use $rootFilter')
|
|
733
|
+
}
|
|
734
|
+
switch (variableName) {
|
|
735
|
+
case 'rootWhereAsFilter':
|
|
736
|
+
case 'rootFilter':
|
|
737
|
+
return Parser.environment.getSubTree().filter
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
if (Parser.environment.hasVariable(variableName)) {
|
|
741
|
+
return Parser.environment.getVariable(variableName)
|
|
742
|
+
}
|
|
743
|
+
if (Parser.environment.hasParameter(variableName)) {
|
|
744
|
+
return Parser.environment.getParameter(variableName)
|
|
732
745
|
}
|
|
733
746
|
if (Parser.environment.hasDimension(variableName)) {
|
|
734
747
|
const dimensionValue = Parser.environment.getDimension(variableName)
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
}
|
|
739
|
-
throw new QueryLanguageError(
|
|
740
|
-
`The variable \$${variableName} resolved to a dimension which exists but contains ${dimensionValue.length} values. It has to contain exactly one. ` +
|
|
748
|
+
if (dimensionValue.length > 1) {
|
|
749
|
+
throw new BindingError(
|
|
750
|
+
`The variable \$${variableName} resolved to a dimension which exists but contains ${dimensionValue.length} values. It has to contain exactly one. ` +
|
|
741
751
|
`Perhaps you forgot to set the 'maxItems' prop of your DimensionsSwitcher?`,
|
|
742
|
-
|
|
752
|
+
)
|
|
753
|
+
}
|
|
754
|
+
return dimensionValue[0]
|
|
743
755
|
}
|
|
756
|
+
|
|
744
757
|
throw new QueryLanguageError(`Undefined variable \$${variableName}.`)
|
|
745
758
|
})
|
|
746
759
|
})
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This *CAN* include dummy values, not just uuids
|
|
2
|
-
export type EntityId = string
|
|
2
|
+
export type EntityId = string | number
|