@contember/binding 1.1.0-alpha.0 → 1.1.0-alpha.3
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 +27 -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 +7 -6
- 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/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 +5 -5
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +12 -11
- 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/SchemaPreprocessor.js +1 -1
- package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/development/dao/Environment.js +12 -2
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/development/helperComponents/DeferredSubTrees.js +4 -2
- package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
- 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/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js +1 -1
- package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js +4 -4
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/utils/Hashing.js +21 -6
- package/dist/development/utils/Hashing.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 +27 -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 +7 -6
- 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/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 +5 -5
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +12 -11
- 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/SchemaPreprocessor.js +1 -1
- package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
- package/dist/production/dao/Environment.js +12 -2
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -2
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/helperComponents/DeferredSubTrees.js +4 -2
- package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
- 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/markers/EntityListSubTreeMarker.js +1 -1
- package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js +1 -1
- package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js +4 -4
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/utils/Hashing.js +21 -6
- package/dist/production/utils/Hashing.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/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/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/SchemaEntity.d.ts +1 -1
- package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +7 -5
- package/dist/types/dao/Environment.d.ts.map +1 -1
- 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/markers/PlaceholderGenerator.d.ts +3 -2
- package/dist/types/markers/PlaceholderGenerator.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/dist/types/utils/Hashing.d.ts +3 -2
- package/dist/types/utils/Hashing.d.ts.map +1 -1
- package/package.json +7 -5
- 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 +30 -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 +6 -7
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/ErrorsPreprocessor.ts +2 -2
- package/src/core/EventManager.ts +14 -8
- 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 +14 -6
- 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/SchemaEntity.ts +1 -1
- package/src/core/schema/SchemaPreprocessor.ts +1 -1
- package/src/dao/Environment.ts +18 -7
- package/src/dao/TreeNodeEnvironmentFactory.ts +2 -2
- package/src/helperComponents/DeferredSubTrees.tsx +4 -4
- 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/markers/EntityListSubTreeMarker.ts +1 -1
- package/src/markers/EntitySubTreeMarker.ts +1 -1
- package/src/markers/PlaceholderGenerator.ts +5 -2
- package/src/treeParameters/primitives/EntityId.ts +1 -1
- package/src/utils/Hashing.ts +23 -8
package/src/dao/Environment.ts
CHANGED
|
@@ -107,24 +107,35 @@ class Environment {
|
|
|
107
107
|
newVariables[newName] = resolvedValue
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
return new Environment({
|
|
110
|
+
return new Environment({
|
|
111
|
+
...this.options,
|
|
112
|
+
variables: newVariables,
|
|
113
|
+
parent: this,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public getAllVariables() {
|
|
118
|
+
return this.options.variables
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
public hasParameter(key: string): boolean {
|
|
114
122
|
return key in this.options.parameters
|
|
115
123
|
}
|
|
116
124
|
|
|
117
|
-
public getParameter<F>(key: string): string {
|
|
118
|
-
if (!(key in this.options.parameters)
|
|
125
|
+
public getParameter<F>(key: string): string | number {
|
|
126
|
+
if (!(key in this.options.parameters)) {
|
|
119
127
|
throw new BindingError(`Parameter ${key} not found`)
|
|
120
128
|
}
|
|
121
|
-
return this.options.parameters[key] as string
|
|
129
|
+
return this.options.parameters[key] as string | number
|
|
122
130
|
}
|
|
123
131
|
|
|
124
|
-
public getParameterOrElse<F>(key: string, fallback: F): string | F {
|
|
132
|
+
public getParameterOrElse<F>(key: string, fallback: F): string | number | F {
|
|
125
133
|
return this.options.parameters[key] ?? fallback
|
|
126
134
|
}
|
|
127
135
|
|
|
136
|
+
public getAllParameters() {
|
|
137
|
+
return this.options.parameters
|
|
138
|
+
}
|
|
128
139
|
|
|
129
140
|
public withParameters(parameters: Environment.Parameters): Environment {
|
|
130
141
|
return new Environment({ ...this.options, parameters })
|
|
@@ -275,8 +286,8 @@ namespace Environment {
|
|
|
275
286
|
[key: string]: string[]
|
|
276
287
|
}
|
|
277
288
|
|
|
278
|
-
export
|
|
279
|
-
[
|
|
289
|
+
export type Parameters = {
|
|
290
|
+
[K in string]?: string | number
|
|
280
291
|
}
|
|
281
292
|
|
|
282
293
|
export interface CustomVariables {
|
|
@@ -201,11 +201,11 @@ export class TreeNodeEnvironmentFactory {
|
|
|
201
201
|
|
|
202
202
|
private static describeLocation(environment: Environment): string {
|
|
203
203
|
const path = []
|
|
204
|
+
const loc = environment.getSubTreeNode()
|
|
204
205
|
for (let env = environment;; env = env.getParent()) {
|
|
205
206
|
const node = env.getSubTreeNode()
|
|
206
207
|
if (node.type === 'subtree-entity' || node.type === 'subtree-entity-list') {
|
|
207
|
-
|
|
208
|
-
return `entity '${node.entity.name}'${pathText}`
|
|
208
|
+
return `entity '${loc.entity.name}' in path '${[node.entity.name, ...path].join('.')}'`
|
|
209
209
|
}
|
|
210
210
|
path.push(node.field.name)
|
|
211
211
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode, useCallback, useEffect, useState } from 'react'
|
|
2
|
-
import { TreeRootIdProvider, useBindingOperations } from '../accessorPropagation'
|
|
2
|
+
import { TreeRootIdProvider, useBindingOperations, useEnvironment } from '../accessorPropagation'
|
|
3
3
|
import { useMutationState } from '../accessorTree'
|
|
4
4
|
import { Component } from '../coreComponents'
|
|
5
5
|
import { useEntityBeforePersist } from '../entityEvents'
|
|
@@ -29,7 +29,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
|
|
|
29
29
|
|
|
30
30
|
const [abortController] = useState(() => new AbortController())
|
|
31
31
|
const signal = abortController.signal
|
|
32
|
-
|
|
32
|
+
const environment = useEnvironment()
|
|
33
33
|
useEntityBeforePersist(
|
|
34
34
|
useCallback(getAccessor => {
|
|
35
35
|
// This is a hack. We're really just circumventing the change of ids after a creation so that nested
|
|
@@ -55,7 +55,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
|
|
|
55
55
|
|
|
56
56
|
const newFragment = <OnlyKeepSubTrees>{props.children}</OnlyKeepSubTrees>
|
|
57
57
|
|
|
58
|
-
extendTree(newFragment, { signal })
|
|
58
|
+
extendTree(newFragment, { signal, environment })
|
|
59
59
|
.then(treeRootId => !signal.aborted && setLoadState({ name: 'success', treeRootId }))
|
|
60
60
|
.catch(error => {
|
|
61
61
|
if (signal.aborted) {
|
|
@@ -63,7 +63,7 @@ export const DeferredSubTrees = Component<DeferredSubTreesProps>(
|
|
|
63
63
|
}
|
|
64
64
|
throw error
|
|
65
65
|
})
|
|
66
|
-
}, [extendTree, isMutating, loadState.name, props.children, signal])
|
|
66
|
+
}, [environment, extendTree, isMutating, loadState.name, props.children, signal])
|
|
67
67
|
|
|
68
68
|
switch (loadState.name) {
|
|
69
69
|
case 'initial':
|
|
@@ -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.children}</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
|
+
}
|
|
@@ -11,7 +11,7 @@ export class EntityListSubTreeMarker {
|
|
|
11
11
|
public readonly fields: EntityFieldMarkersContainer,
|
|
12
12
|
public readonly environment: Environment,
|
|
13
13
|
) {
|
|
14
|
-
this.placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(this.parameters)
|
|
14
|
+
this.placeholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(this.parameters, this.environment)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
public get entityName() {
|
|
@@ -11,7 +11,7 @@ export class EntitySubTreeMarker {
|
|
|
11
11
|
public readonly fields: EntityFieldMarkersContainer,
|
|
12
12
|
public readonly environment: Environment,
|
|
13
13
|
) {
|
|
14
|
-
this.placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(this.parameters)
|
|
14
|
+
this.placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(this.parameters, this.environment)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
public get entityName() {
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
UnconstrainedQualifiedSingleEntity,
|
|
9
9
|
} from '../treeParameters'
|
|
10
10
|
import { Hashing } from '../utils'
|
|
11
|
+
import { Environment } from '../dao'
|
|
11
12
|
|
|
12
13
|
export class PlaceholderGenerator {
|
|
13
14
|
public static getFieldPlaceholder(fieldName: FieldName): string {
|
|
@@ -24,13 +25,15 @@ export class PlaceholderGenerator {
|
|
|
24
25
|
|
|
25
26
|
public static getEntitySubTreePlaceholder(
|
|
26
27
|
subTreeParameters: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,
|
|
28
|
+
environment: Environment,
|
|
27
29
|
): string {
|
|
28
|
-
return `est_${Hashing.hashEntitySubTreeParameters(subTreeParameters)}`
|
|
30
|
+
return `est_${Hashing.hashEntitySubTreeParameters(subTreeParameters, environment)}`
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
public static getEntityListSubTreePlaceholder(
|
|
32
34
|
subTreeParameters: QualifiedEntityList | UnconstrainedQualifiedEntityList,
|
|
35
|
+
environment: Environment,
|
|
33
36
|
): string {
|
|
34
|
-
return `lst_${Hashing.hashEntityListSubTreeParameters(subTreeParameters)}`
|
|
37
|
+
return `lst_${Hashing.hashEntityListSubTreeParameters(subTreeParameters, environment)}`
|
|
35
38
|
}
|
|
36
39
|
}
|
|
@@ -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
|
package/src/utils/Hashing.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
Filter,
|
|
3
2
|
HasManyRelation,
|
|
4
3
|
HasOneRelation,
|
|
5
|
-
OrderBy,
|
|
6
4
|
QualifiedEntityList,
|
|
7
5
|
QualifiedSingleEntity,
|
|
8
6
|
UnconstrainedQualifiedEntityList,
|
|
9
7
|
UnconstrainedQualifiedSingleEntity,
|
|
10
|
-
UniqueWhere,
|
|
11
8
|
} from '../treeParameters'
|
|
9
|
+
import { Environment } from '../dao'
|
|
12
10
|
|
|
13
11
|
// TODO update hashing so that for offset, 0 == undefined
|
|
14
12
|
export class Hashing {
|
|
15
13
|
public static hashHasOneRelation(relation: HasOneRelation): number {
|
|
16
|
-
const where
|
|
14
|
+
const where = [
|
|
17
15
|
'upToOne',
|
|
18
16
|
relation.field,
|
|
19
17
|
relation.filter,
|
|
@@ -24,7 +22,7 @@ export class Hashing {
|
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
public static hashHasManyRelation(relation: HasManyRelation): number {
|
|
27
|
-
const where
|
|
25
|
+
const where = [
|
|
28
26
|
'possiblyMany',
|
|
29
27
|
relation.field,
|
|
30
28
|
relation.filter,
|
|
@@ -38,9 +36,14 @@ export class Hashing {
|
|
|
38
36
|
|
|
39
37
|
public static hashEntityListSubTreeParameters(
|
|
40
38
|
parameters: QualifiedEntityList | UnconstrainedQualifiedEntityList,
|
|
39
|
+
environment: Environment,
|
|
41
40
|
): number {
|
|
42
41
|
if (parameters.isCreating) {
|
|
43
|
-
return Hashing.hashArray([
|
|
42
|
+
return Hashing.hashArray([
|
|
43
|
+
parameters.isCreating,
|
|
44
|
+
parameters.entityName,
|
|
45
|
+
environment.getAllVariables(),
|
|
46
|
+
])
|
|
44
47
|
}
|
|
45
48
|
return Hashing.hashArray([
|
|
46
49
|
parameters.isCreating,
|
|
@@ -49,16 +52,28 @@ export class Hashing {
|
|
|
49
52
|
parameters.orderBy,
|
|
50
53
|
parameters.offset,
|
|
51
54
|
parameters.limit,
|
|
55
|
+
environment.getAllVariables(),
|
|
52
56
|
])
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
public static hashEntitySubTreeParameters(
|
|
56
60
|
parameters: QualifiedSingleEntity | UnconstrainedQualifiedSingleEntity,
|
|
61
|
+
environment: Environment,
|
|
57
62
|
): number {
|
|
58
63
|
if (parameters.isCreating) {
|
|
59
|
-
return Hashing.hashArray([
|
|
64
|
+
return Hashing.hashArray([
|
|
65
|
+
parameters.isCreating,
|
|
66
|
+
parameters.entityName,
|
|
67
|
+
environment.getAllVariables(),
|
|
68
|
+
])
|
|
60
69
|
}
|
|
61
|
-
return Hashing.hashArray([
|
|
70
|
+
return Hashing.hashArray([
|
|
71
|
+
parameters.isCreating,
|
|
72
|
+
parameters.where,
|
|
73
|
+
parameters.entityName,
|
|
74
|
+
parameters.filter,
|
|
75
|
+
environment.getAllVariables(),
|
|
76
|
+
])
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
private static hashArray(array: any[]): number {
|