@contember/binding 1.1.0-alpha.1 → 1.1.0-alpha.4
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/useAccessorTreeState.js +5 -0
- package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/development/core/DataBinding.js +1 -1
- 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/EventManager.js +12 -7
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/MutationGenerator.js +95 -89
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/StateInitializer.js +15 -18
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeStore.js +2 -2
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +8 -7
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.js +1 -1
- package/dist/development/core/operations/ListOperations.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/Entity.js +1 -1
- package/dist/development/coreComponents/Entity.js.map +1 -1
- package/dist/development/coreComponents/EntityList.js +1 -1
- package/dist/development/coreComponents/EntityList.js.map +1 -1
- package/dist/development/dao/Environment.js +11 -1
- 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 +16 -8
- 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 +3 -0
- 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/useAccessorTreeState.js +5 -0
- package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
- package/dist/production/core/DataBinding.js +1 -1
- 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/EventManager.js +11 -6
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/MutationGenerator.js +95 -89
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/StateInitializer.js +15 -18
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeStore.js +2 -2
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +8 -7
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.js +1 -1
- package/dist/production/core/operations/ListOperations.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/Entity.js +1 -1
- package/dist/production/coreComponents/Entity.js.map +1 -1
- package/dist/production/coreComponents/EntityList.js +1 -1
- package/dist/production/coreComponents/EntityList.js.map +1 -1
- package/dist/production/dao/Environment.js +11 -1
- 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 +16 -8
- 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 +3 -0
- 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/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/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/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/StateInitializer.d.ts +1 -5
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- 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.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 +2 -0
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/helperComponents/DeferredSubTrees.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/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/index.ts +1 -0
- package/src/accessorTree/useAccessorTreeState.ts +4 -0
- package/src/core/DataBinding.ts +0 -1
- package/src/core/DirtinessTracker.ts +4 -16
- package/src/core/EventManager.ts +14 -8
- package/src/core/MutationGenerator.ts +132 -125
- package/src/core/StateInitializer.ts +22 -29
- package/src/core/TreeStore.ts +2 -0
- package/src/core/operations/EntityOperations.ts +8 -9
- package/src/core/operations/ListOperations.ts +2 -1
- 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/coreComponents/Entity.tsx +1 -1
- package/src/coreComponents/EntityList.tsx +1 -1
- package/src/dao/Environment.ts +12 -1
- package/src/dao/TreeNodeEnvironmentFactory.ts +2 -2
- package/src/helperComponents/DeferredSubTrees.tsx +19 -13
- 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/utils/Hashing.ts +23 -8
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/binding",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.1.0-alpha.
|
|
4
|
+
"version": "1.1.0-alpha.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
],
|
|
20
20
|
"typings": "./dist/types/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@contember/client": "1.1.0-alpha.
|
|
23
|
-
"@contember/react-client": "1.1.0-alpha.
|
|
24
|
-
"@contember/react-multipass-rendering": "1.1.0-alpha.
|
|
25
|
-
"@contember/react-utils": "1.1.0-alpha.
|
|
22
|
+
"@contember/client": "1.1.0-alpha.4",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.4",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.4",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.4",
|
|
26
26
|
"chevrotain": "6.5.0",
|
|
27
27
|
"fast-deep-equal": "^3.1.3",
|
|
28
28
|
"js-levenshtein": "1.1.6",
|
|
@@ -42,6 +42,8 @@
|
|
|
42
42
|
"build": "pnpm run build:js:dev && pnpm run build:js:prod",
|
|
43
43
|
"build:js:dev": "vite build --mode development",
|
|
44
44
|
"build:js:prod": "vite build --mode production",
|
|
45
|
+
"ae:build": "api-extractor run --local",
|
|
46
|
+
"ae:test": "api-extractor run",
|
|
45
47
|
"test": "vitest"
|
|
46
48
|
}
|
|
47
49
|
}
|
|
@@ -20,6 +20,7 @@ export * from './useEntityListSubTreeParameters'
|
|
|
20
20
|
export * from './useEntitySubTree'
|
|
21
21
|
export * from './useEntitySubTreeParameters'
|
|
22
22
|
export * from './useEnvironment'
|
|
23
|
+
export * from './useExtendTree'
|
|
23
24
|
export * from './useField'
|
|
24
25
|
export * from './useGetEntityByKey'
|
|
25
26
|
export * from './useGetEntityListSubTree'
|
|
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEn
|
|
|
4
4
|
import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
|
|
5
5
|
import { useEntityListSubTreeParameters } from './useEntityListSubTreeParameters'
|
|
6
6
|
import { useGetEntityListSubTree } from './useGetEntityListSubTree'
|
|
7
|
+
import { TreeRootId } from '../treeParameters'
|
|
7
8
|
|
|
8
9
|
export const useEntityListSubTree = (
|
|
9
10
|
qualifiedEntityList: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,
|
|
11
|
+
...treeId: [TreeRootId | undefined] | []
|
|
10
12
|
): EntityListAccessor => {
|
|
11
13
|
const getSubTree = useGetEntityListSubTree()
|
|
12
14
|
const parameters = useEntityListSubTreeParameters(qualifiedEntityList)
|
|
13
|
-
const
|
|
15
|
+
const hasTreeId = treeId.length > 0
|
|
16
|
+
const treeIdVal = treeId[0]
|
|
17
|
+
const getAccessor = useCallback(
|
|
18
|
+
() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
|
|
19
|
+
[getSubTree, hasTreeId, parameters, treeIdVal],
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
// if (typeof parameters !== 'string' && parameters.value.hasOneRelationPath.length) {
|
|
16
23
|
// throw new BindingError(`useEntityListSubTree: cannot use hasOneRelationPath!`)
|
|
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedSingleEntity, SugaredUnconstrainedQualified
|
|
|
4
4
|
import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
|
|
5
5
|
import { useEntitySubTreeParameters } from './useEntitySubTreeParameters'
|
|
6
6
|
import { useGetEntitySubTree } from './useGetEntitySubTree'
|
|
7
|
+
import { TreeRootId } from '../treeParameters'
|
|
7
8
|
|
|
8
9
|
export const useEntitySubTree = (
|
|
9
10
|
qualifiedSingleEntity: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,
|
|
11
|
+
...treeId: [TreeRootId | undefined] | []
|
|
10
12
|
): EntityAccessor => {
|
|
11
13
|
const getSubTree = useGetEntitySubTree()
|
|
12
14
|
const parameters = useEntitySubTreeParameters(qualifiedSingleEntity)
|
|
13
|
-
const
|
|
15
|
+
const hasTreeId = treeId.length > 0
|
|
16
|
+
const treeIdVal = treeId[0]
|
|
17
|
+
const getAccessor = useCallback(
|
|
18
|
+
() => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
|
|
19
|
+
[getSubTree, hasTreeId, parameters, treeIdVal],
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
// if (typeof parameters !== 'string' && parameters.hasOneRelationPath.length) {
|
|
16
23
|
// throw new BindingError(`useEntitySubTree: cannot use hasOneRelationPath!`)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReactNode, useCallback } from 'react'
|
|
2
|
+
import { useAbortController, useIsMounted } from '@contember/react-utils'
|
|
3
|
+
import { useBindingOperations } from './useBindingOperations'
|
|
4
|
+
import { TreeRootId } from '../treeParameters'
|
|
5
|
+
import { ExtendTreeOptions } from '../accessors'
|
|
6
|
+
import { DataBindingExtendAborted } from '../core'
|
|
7
|
+
import { useEnvironment } from './useEnvironment'
|
|
8
|
+
|
|
9
|
+
export const useExtendTree = () => {
|
|
10
|
+
const abort = useAbortController()
|
|
11
|
+
const { extendTree } = useBindingOperations()
|
|
12
|
+
const isMountedRef = useIsMounted()
|
|
13
|
+
const environment = useEnvironment()
|
|
14
|
+
return useCallback(async (newFragment: ReactNode, options?: Omit<ExtendTreeOptions, 'signal'>): Promise<TreeRootId | undefined> => {
|
|
15
|
+
try {
|
|
16
|
+
const newTreeRootId = await extendTree(newFragment,
|
|
17
|
+
{ environment, ...options, signal: abort() },
|
|
18
|
+
)
|
|
19
|
+
if (!isMountedRef.current) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
return newTreeRootId
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (e === DataBindingExtendAborted) {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
throw e
|
|
28
|
+
}
|
|
29
|
+
}, [abort, environment, extendTree, isMountedRef])
|
|
30
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react'
|
|
2
2
|
import { BindingOperationsProvider } from '../accessorPropagation'
|
|
3
3
|
import type { AccessorTreeState } from './AccessorTreeState'
|
|
4
|
+
import { AccessorTreeStateContext } from './AccessorTreeStateContext'
|
|
4
5
|
import { DirtinessContext } from './DirtinessContext'
|
|
5
6
|
import { MutationStateContext } from './MutationStateContext'
|
|
6
7
|
|
|
@@ -14,21 +15,26 @@ export function AccessorTree({ state, children }: AccessorTreeProps) {
|
|
|
14
15
|
// remounts.
|
|
15
16
|
if (state.name === 'initialized') {
|
|
16
17
|
return (
|
|
17
|
-
<
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
{
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
<AccessorTreeStateContext.Provider value={state}>
|
|
19
|
+
<DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>
|
|
20
|
+
<MutationStateContext.Provider value={state.data.isMutating}>
|
|
21
|
+
<BindingOperationsProvider bindingOperations={state.data.bindingOperations}>
|
|
22
|
+
{children}
|
|
23
|
+
</BindingOperationsProvider>
|
|
24
|
+
</MutationStateContext.Provider>
|
|
25
|
+
</DirtinessContext.Provider>
|
|
26
|
+
</AccessorTreeStateContext.Provider>
|
|
24
27
|
)
|
|
25
28
|
}
|
|
26
29
|
return (
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
<AccessorTreeStateContext.Provider value={state}>
|
|
31
|
+
<DirtinessContext.Provider value={false}>
|
|
32
|
+
<MutationStateContext.Provider value={false}>
|
|
33
|
+
<BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>
|
|
34
|
+
</MutationStateContext.Provider>
|
|
35
|
+
</DirtinessContext.Provider>
|
|
36
|
+
</AccessorTreeStateContext.Provider>
|
|
32
37
|
)
|
|
33
38
|
}
|
|
39
|
+
|
|
34
40
|
AccessorTree.displayName = 'AccessorTree'
|
|
@@ -13,6 +13,7 @@ export * from './PersistResult'
|
|
|
13
13
|
export * from './QueryRequestResponse'
|
|
14
14
|
export * from './RequestError'
|
|
15
15
|
export * from './RuntimeId'
|
|
16
|
+
export * from './useAccessorTreeState'
|
|
16
17
|
export * from './useDataBinding'
|
|
17
18
|
export * from './useDirtinessState'
|
|
18
19
|
export * from './useMutationState'
|
package/src/core/DataBinding.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
export class DirtinessTracker {
|
|
2
2
|
private changesCount = 0
|
|
3
|
-
private
|
|
3
|
+
private touchedCount = 0
|
|
4
4
|
|
|
5
|
-
public
|
|
6
|
-
return this.
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public getTotalChangesCount() {
|
|
10
|
-
return this.totalChangesCount
|
|
5
|
+
public getTotalTouchCount() {
|
|
6
|
+
return this.touchedCount
|
|
11
7
|
}
|
|
12
8
|
|
|
13
9
|
public hasChanges() {
|
|
@@ -18,16 +14,8 @@ export class DirtinessTracker {
|
|
|
18
14
|
this.changesCount = 0
|
|
19
15
|
}
|
|
20
16
|
|
|
21
|
-
public increment() {
|
|
22
|
-
this.totalChangesCount++
|
|
23
|
-
this.changesCount++
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public decrement() {
|
|
27
|
-
this.changesCount--
|
|
28
|
-
}
|
|
29
|
-
|
|
30
17
|
public increaseBy(delta: number) {
|
|
31
18
|
this.changesCount += delta
|
|
19
|
+
this.touchedCount++
|
|
32
20
|
}
|
|
33
21
|
}
|
package/src/core/EventManager.ts
CHANGED
|
@@ -346,9 +346,12 @@ export class EventManager {
|
|
|
346
346
|
|
|
347
347
|
for (const [state, callback] of callbackQueue) {
|
|
348
348
|
correspondingStates.push(state)
|
|
349
|
+
const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
|
|
350
|
+
let validateChanges = false
|
|
349
351
|
try {
|
|
350
352
|
const result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.
|
|
351
353
|
if (result instanceof Promise) {
|
|
354
|
+
validateChanges = true
|
|
352
355
|
promiseReturns.push(result)
|
|
353
356
|
} else {
|
|
354
357
|
promiseReturns.push(Promise.resolve(result))
|
|
@@ -356,10 +359,15 @@ export class EventManager {
|
|
|
356
359
|
} catch (e) {
|
|
357
360
|
promiseReturns.push(Promise.reject(e))
|
|
358
361
|
}
|
|
362
|
+
if (validateChanges) {
|
|
363
|
+
this.validateWithoutChanges(changesCountBefore, eventType)
|
|
364
|
+
}
|
|
359
365
|
}
|
|
360
366
|
// TODO timeout
|
|
361
367
|
|
|
362
|
-
const
|
|
368
|
+
const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
|
|
369
|
+
const newCallbacks = await Promise.allSettled(promiseReturns)
|
|
370
|
+
this.validateWithoutChanges(changesCountBefore, eventType)
|
|
363
371
|
|
|
364
372
|
callbackQueue.length = 0 // Empties the queue
|
|
365
373
|
|
|
@@ -561,20 +569,18 @@ export class EventManager {
|
|
|
561
569
|
}
|
|
562
570
|
}
|
|
563
571
|
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
const changesCountAfter = this.dirtinessTracker.getTotalChangesCount()
|
|
572
|
+
|
|
573
|
+
private validateWithoutChanges(initialCount: number, eventType: string): void {
|
|
574
|
+
const changesCountAfter = this.dirtinessTracker.getTotalTouchCount()
|
|
568
575
|
if (import.meta.env.DEV) {
|
|
569
|
-
if (
|
|
576
|
+
if (initialCount !== changesCountAfter) {
|
|
570
577
|
// This isn't bulletproof. They could e.g. undo a change and make another one which would
|
|
571
578
|
// slip through this detection. But for most cases, it should be good enough and not too expensive.
|
|
572
579
|
throw new BindingError(
|
|
573
580
|
`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +
|
|
574
|
-
|
|
581
|
+
`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,
|
|
575
582
|
)
|
|
576
583
|
}
|
|
577
584
|
}
|
|
578
|
-
return result
|
|
579
585
|
}
|
|
580
586
|
}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
EntityRealmStateStub,
|
|
16
16
|
EntityState,
|
|
17
17
|
FieldState,
|
|
18
|
-
getEntityMarker,
|
|
18
|
+
getEntityMarker, RootStateNode, StateIterator,
|
|
19
19
|
} from './state'
|
|
20
20
|
import type { TreeStore } from './TreeStore'
|
|
21
21
|
|
|
@@ -25,15 +25,20 @@ type ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>
|
|
|
25
25
|
|
|
26
26
|
// TODO enforce correct expected mutations in dev mode.
|
|
27
27
|
export class MutationGenerator {
|
|
28
|
-
public constructor(private readonly treeStore: TreeStore) {
|
|
28
|
+
public constructor(private readonly treeStore: TreeStore) {
|
|
29
|
+
}
|
|
29
30
|
|
|
30
31
|
public getPersistMutation(): string | undefined {
|
|
31
32
|
try {
|
|
32
33
|
let builder: QueryBuilder = new CrudQueryBuilder.CrudQueryBuilder()
|
|
33
34
|
const processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
|
|
37
|
+
for (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {
|
|
38
|
+
for (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {
|
|
39
|
+
if (subTreeState.unpersistedChangesCount <= 0) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
37
42
|
if (subTreeState.type === 'entityRealm') {
|
|
38
43
|
builder = this.addSubMutation(
|
|
39
44
|
processedPlaceholdersByEntity,
|
|
@@ -88,6 +93,7 @@ export class MutationGenerator {
|
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
}
|
|
96
|
+
|
|
91
97
|
return builder.inTransaction(undefined, { deferForeignKeyConstraints: true }).getGql()
|
|
92
98
|
} catch (e) {
|
|
93
99
|
return undefined
|
|
@@ -287,142 +293,143 @@ export class MutationGenerator {
|
|
|
287
293
|
return builder
|
|
288
294
|
}
|
|
289
295
|
|
|
290
|
-
const
|
|
296
|
+
for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
|
|
291
297
|
|
|
292
|
-
|
|
293
|
-
| { type: 'field'; marker: FieldMarker; fieldState: FieldState }
|
|
294
|
-
| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }
|
|
295
|
-
| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }
|
|
296
|
-
> = []
|
|
297
|
-
|
|
298
|
-
for (const [placeholderName, fieldState] of currentState.children) {
|
|
299
|
-
if (processedPlaceholders.has(placeholderName)) {
|
|
300
|
-
continue
|
|
301
|
-
}
|
|
302
|
-
processedPlaceholders.add(placeholderName)
|
|
298
|
+
const pathBack = this.treeStore.getPathBackToParent(siblingState)
|
|
303
299
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const placeholderName = marker.placeholderName
|
|
300
|
+
const nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }
|
|
301
|
+
| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }
|
|
302
|
+
| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []
|
|
308
303
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
) {
|
|
313
|
-
continue
|
|
314
|
-
}
|
|
315
|
-
if (marker.isNonbearing) {
|
|
316
|
-
nonbearingFields.push({
|
|
317
|
-
type: 'field',
|
|
318
|
-
marker,
|
|
319
|
-
fieldState,
|
|
320
|
-
})
|
|
321
|
-
continue
|
|
322
|
-
}
|
|
323
|
-
builder = this.registerCreateFieldPart(fieldState, marker, builder)
|
|
324
|
-
break
|
|
325
|
-
}
|
|
326
|
-
case 'entityRealmStub':
|
|
327
|
-
case 'entityRealm': {
|
|
328
|
-
const marker = getEntityMarker(fieldState)
|
|
329
|
-
if (!(marker instanceof HasOneRelationMarker)) {
|
|
330
|
-
throw new BindingError()
|
|
331
|
-
}
|
|
332
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
333
|
-
continue
|
|
334
|
-
}
|
|
335
|
-
if (marker.parameters.isNonbearing) {
|
|
336
|
-
nonbearingFields.push({
|
|
337
|
-
type: 'hasOne',
|
|
338
|
-
marker,
|
|
339
|
-
fieldState,
|
|
340
|
-
})
|
|
341
|
-
continue
|
|
342
|
-
}
|
|
343
|
-
builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)
|
|
344
|
-
break
|
|
345
|
-
}
|
|
346
|
-
case 'entityList': {
|
|
347
|
-
const marker = fieldState.blueprint.marker
|
|
348
|
-
if (!(marker instanceof HasManyRelationMarker)) {
|
|
349
|
-
throw new BindingError()
|
|
350
|
-
}
|
|
351
|
-
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
352
|
-
continue
|
|
353
|
-
}
|
|
354
|
-
if (marker.parameters.isNonbearing) {
|
|
355
|
-
nonbearingFields.push({
|
|
356
|
-
type: 'hasMany',
|
|
357
|
-
marker,
|
|
358
|
-
fieldState,
|
|
359
|
-
})
|
|
360
|
-
continue
|
|
361
|
-
}
|
|
362
|
-
builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)
|
|
363
|
-
break
|
|
304
|
+
for (const [placeholderName, fieldState] of siblingState.children) {
|
|
305
|
+
if (processedPlaceholders.has(placeholderName)) {
|
|
306
|
+
continue
|
|
364
307
|
}
|
|
365
|
-
|
|
366
|
-
return assertNever(fieldState)
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
308
|
+
processedPlaceholders.add(placeholderName)
|
|
370
309
|
|
|
371
|
-
|
|
372
|
-
// currentState.blueprint.creationParameters.forceCreation &&
|
|
373
|
-
// (builder.data === undefined || isEmptyObject(builder.data))
|
|
374
|
-
// ) {
|
|
375
|
-
// builder = builder.set('_dummy_field_', true)
|
|
376
|
-
// }
|
|
377
|
-
|
|
378
|
-
if (
|
|
379
|
-
(builder.data !== undefined && !isEmptyObject(builder.data)) ||
|
|
380
|
-
!getEntityMarker(currentState).fields.hasAtLeastOneBearingField
|
|
381
|
-
) {
|
|
382
|
-
for (const field of nonbearingFields) {
|
|
383
|
-
switch (field.type) {
|
|
310
|
+
switch (fieldState.type) {
|
|
384
311
|
case 'field': {
|
|
385
|
-
|
|
312
|
+
const marker = fieldState.fieldMarker
|
|
313
|
+
const placeholderName = marker.placeholderName
|
|
314
|
+
|
|
315
|
+
if (
|
|
316
|
+
placeholderName === TYPENAME_KEY_NAME ||
|
|
317
|
+
(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))
|
|
318
|
+
) {
|
|
319
|
+
continue
|
|
320
|
+
}
|
|
321
|
+
if (marker.isNonbearing) {
|
|
322
|
+
nonbearingFields.push({
|
|
323
|
+
type: 'field',
|
|
324
|
+
marker,
|
|
325
|
+
fieldState,
|
|
326
|
+
})
|
|
327
|
+
continue
|
|
328
|
+
}
|
|
329
|
+
builder = this.registerCreateFieldPart(fieldState, marker, builder)
|
|
386
330
|
break
|
|
387
331
|
}
|
|
388
|
-
case '
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
)
|
|
332
|
+
case 'entityRealmStub':
|
|
333
|
+
case 'entityRealm': {
|
|
334
|
+
const marker = getEntityMarker(fieldState)
|
|
335
|
+
if (!(marker instanceof HasOneRelationMarker)) {
|
|
336
|
+
throw new BindingError()
|
|
337
|
+
}
|
|
338
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
339
|
+
continue
|
|
340
|
+
}
|
|
341
|
+
if (marker.parameters.isNonbearing) {
|
|
342
|
+
nonbearingFields.push({
|
|
343
|
+
type: 'hasOne',
|
|
344
|
+
marker,
|
|
345
|
+
fieldState,
|
|
346
|
+
})
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
builder = this.registerCreateEntityPart(processedPlaceholdersByEntity, fieldState, marker, builder)
|
|
395
350
|
break
|
|
396
351
|
}
|
|
397
|
-
case '
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
352
|
+
case 'entityList': {
|
|
353
|
+
const marker = fieldState.blueprint.marker
|
|
354
|
+
if (!(marker instanceof HasManyRelationMarker)) {
|
|
355
|
+
throw new BindingError()
|
|
356
|
+
}
|
|
357
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
358
|
+
continue
|
|
359
|
+
}
|
|
360
|
+
if (marker.parameters.isNonbearing) {
|
|
361
|
+
nonbearingFields.push({
|
|
362
|
+
type: 'hasMany',
|
|
363
|
+
marker,
|
|
364
|
+
fieldState,
|
|
365
|
+
})
|
|
366
|
+
continue
|
|
367
|
+
}
|
|
368
|
+
builder = this.registerCreateEntityListPart(processedPlaceholdersByEntity, fieldState, marker, builder)
|
|
404
369
|
break
|
|
405
370
|
}
|
|
406
|
-
default:
|
|
407
|
-
assertNever(
|
|
371
|
+
default: {
|
|
372
|
+
return assertNever(fieldState)
|
|
373
|
+
}
|
|
408
374
|
}
|
|
409
375
|
}
|
|
410
|
-
}
|
|
411
376
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
377
|
+
// if (
|
|
378
|
+
// currentState.blueprint.creationParameters.forceCreation &&
|
|
379
|
+
// (builder.data === undefined || isEmptyObject(builder.data))
|
|
380
|
+
// ) {
|
|
381
|
+
// builder = builder.set('_dummy_field_', true)
|
|
382
|
+
// }
|
|
383
|
+
|
|
384
|
+
if (
|
|
385
|
+
(builder.data !== undefined && !isEmptyObject(builder.data)) ||
|
|
386
|
+
!getEntityMarker(siblingState).fields.hasAtLeastOneBearingField
|
|
387
|
+
) {
|
|
388
|
+
for (const field of nonbearingFields) {
|
|
389
|
+
switch (field.type) {
|
|
390
|
+
case 'field': {
|
|
391
|
+
builder = this.registerCreateFieldPart(field.fieldState, field.marker, builder)
|
|
392
|
+
break
|
|
393
|
+
}
|
|
394
|
+
case 'hasOne': {
|
|
395
|
+
builder = this.registerCreateEntityPart(
|
|
396
|
+
processedPlaceholdersByEntity,
|
|
397
|
+
field.fieldState,
|
|
398
|
+
field.marker,
|
|
399
|
+
builder,
|
|
400
|
+
)
|
|
401
|
+
break
|
|
402
|
+
}
|
|
403
|
+
case 'hasMany': {
|
|
404
|
+
builder = this.registerCreateEntityListPart(
|
|
405
|
+
processedPlaceholdersByEntity,
|
|
406
|
+
field.fieldState,
|
|
407
|
+
field.marker,
|
|
408
|
+
builder,
|
|
409
|
+
)
|
|
410
|
+
break
|
|
411
|
+
}
|
|
412
|
+
default:
|
|
413
|
+
assertNever(field)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate
|
|
419
|
+
if (setOnCreate && builder.data !== undefined && !isEmptyObject(builder.data)) {
|
|
420
|
+
for (const key in setOnCreate) {
|
|
421
|
+
const field = setOnCreate[key]
|
|
422
|
+
|
|
423
|
+
if (
|
|
424
|
+
typeof field === 'string' ||
|
|
425
|
+
typeof field === 'number' ||
|
|
426
|
+
field === null ||
|
|
427
|
+
field instanceof GraphQlBuilder.GraphQlLiteral
|
|
428
|
+
) {
|
|
429
|
+
builder = builder.set(key, field)
|
|
430
|
+
} else {
|
|
431
|
+
builder = builder.one(key, builder => builder.connect(field))
|
|
432
|
+
}
|
|
426
433
|
}
|
|
427
434
|
}
|
|
428
435
|
}
|