@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'
|
|
2
|
-
import { EntityFieldPersistedData, RuntimeId,
|
|
2
|
+
import { EntityFieldPersistedData, RuntimeId, ServerId, UnpersistedEntityDummyId } from '../accessorTree'
|
|
3
3
|
import { BindingError } from '../BindingError'
|
|
4
4
|
import {
|
|
5
5
|
EntityListSubTreeMarker,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '../markers'
|
|
11
11
|
import { BijectiveIndexedMap } from '../structures'
|
|
12
12
|
import type {
|
|
13
|
-
EntityEventListenerStore,
|
|
13
|
+
EntityEventListenerStore, EntityId,
|
|
14
14
|
EntityListEventListenerStore,
|
|
15
15
|
EntityName,
|
|
16
16
|
FieldEventListenerStore,
|
|
@@ -19,7 +19,6 @@ import type {
|
|
|
19
19
|
} from '../treeParameters'
|
|
20
20
|
import { assertNever } from '../utils'
|
|
21
21
|
import type { AccessorErrorManager } from './AccessorErrorManager'
|
|
22
|
-
import type { Config } from './Config'
|
|
23
22
|
import type { EventManager } from './EventManager'
|
|
24
23
|
import { EntityOperations, FieldOperations, ListOperations } from './operations'
|
|
25
24
|
import { RealmKeyGenerator } from './RealmKeyGenerator'
|
|
@@ -44,27 +43,14 @@ export class StateInitializer {
|
|
|
44
43
|
private readonly listOperations: ListOperations
|
|
45
44
|
|
|
46
45
|
public constructor(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
private readonly config: Config,
|
|
46
|
+
accessorErrorManager: AccessorErrorManager,
|
|
47
|
+
batchUpdatesOptions: BatchUpdatesOptions,
|
|
50
48
|
private readonly eventManager: EventManager,
|
|
51
49
|
private readonly treeStore: TreeStore,
|
|
52
50
|
) {
|
|
53
|
-
this.fieldOperations = new FieldOperations(
|
|
54
|
-
this.entityOperations = new EntityOperations(
|
|
55
|
-
|
|
56
|
-
this.batchUpdatesOptions,
|
|
57
|
-
this.eventManager,
|
|
58
|
-
this,
|
|
59
|
-
this.treeStore,
|
|
60
|
-
)
|
|
61
|
-
this.listOperations = new ListOperations(
|
|
62
|
-
this.accessorErrorManager,
|
|
63
|
-
this.batchUpdatesOptions,
|
|
64
|
-
this.eventManager,
|
|
65
|
-
this,
|
|
66
|
-
this.treeStore,
|
|
67
|
-
)
|
|
51
|
+
this.fieldOperations = new FieldOperations(accessorErrorManager, this.eventManager, this, this.treeStore)
|
|
52
|
+
this.entityOperations = new EntityOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)
|
|
53
|
+
this.listOperations = new ListOperations(accessorErrorManager, batchUpdatesOptions, this.eventManager, this, this.treeStore)
|
|
68
54
|
}
|
|
69
55
|
|
|
70
56
|
public initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {
|
|
@@ -72,7 +58,7 @@ export class StateInitializer {
|
|
|
72
58
|
const persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)
|
|
73
59
|
|
|
74
60
|
if (tree instanceof EntityListSubTreeMarker) {
|
|
75
|
-
const persistedEntityIds: Set<
|
|
61
|
+
const persistedEntityIds: Set<EntityId> = persistedRootData instanceof Set ? persistedRootData : new Set()
|
|
76
62
|
subTreeState = this.initializeEntityListState(
|
|
77
63
|
{ marker: tree, parent: undefined },
|
|
78
64
|
tree.entityName,
|
|
@@ -81,7 +67,7 @@ export class StateInitializer {
|
|
|
81
67
|
} else {
|
|
82
68
|
subTreeState = this.materializeEntityRealm(
|
|
83
69
|
this.initializeEntityRealm(
|
|
84
|
-
persistedRootData instanceof
|
|
70
|
+
persistedRootData instanceof ServerId ? persistedRootData : new UnpersistedEntityDummyId(),
|
|
85
71
|
tree.entityName,
|
|
86
72
|
{
|
|
87
73
|
type: 'subTree',
|
|
@@ -126,7 +112,7 @@ export class StateInitializer {
|
|
|
126
112
|
|
|
127
113
|
return stub
|
|
128
114
|
}
|
|
129
|
-
const realm = this.createEntityRealm(blueprint, realmKey, entity)
|
|
115
|
+
const realm = this.createEntityRealm(blueprint, realmKey, entity, copyFrom)
|
|
130
116
|
|
|
131
117
|
this.registerEntityRealm(realm)
|
|
132
118
|
|
|
@@ -139,7 +125,7 @@ export class StateInitializer {
|
|
|
139
125
|
if (!value || value.type !== 'field') {
|
|
140
126
|
throw new BindingError()
|
|
141
127
|
}
|
|
142
|
-
this.initializeFromFieldMarker(realm, field, value
|
|
128
|
+
this.initializeFromFieldMarker(realm, field, undefined, value)
|
|
143
129
|
} else if (field instanceof HasManyRelationMarker) {
|
|
144
130
|
// todo: get from copyFrom
|
|
145
131
|
this.initializeFromHasManyRelationMarker(realm, field, new Set())
|
|
@@ -168,7 +154,12 @@ export class StateInitializer {
|
|
|
168
154
|
return realm
|
|
169
155
|
}
|
|
170
156
|
|
|
171
|
-
private createEntityRealm(
|
|
157
|
+
private createEntityRealm(
|
|
158
|
+
blueprint: EntityRealmBlueprint,
|
|
159
|
+
realmKey: string,
|
|
160
|
+
entity: EntityState,
|
|
161
|
+
copyFrom?: EntityRealmState,
|
|
162
|
+
): EntityRealmState {
|
|
172
163
|
const entityRealm: EntityRealmState = {
|
|
173
164
|
type: 'entityRealm',
|
|
174
165
|
|
|
@@ -183,7 +174,7 @@ export class StateInitializer {
|
|
|
183
174
|
eventListeners: this.initializeEntityEventListenerStore(blueprint),
|
|
184
175
|
fieldsWithPendingConnectionUpdates: undefined,
|
|
185
176
|
plannedHasOneDeletions: undefined,
|
|
186
|
-
unpersistedChangesCount: 0,
|
|
177
|
+
unpersistedChangesCount: copyFrom?.unpersistedChangesCount ?? 0,
|
|
187
178
|
getAccessor: () => {
|
|
188
179
|
if (entityRealm.accessor === undefined) {
|
|
189
180
|
const entity = entityRealm.entity
|
|
@@ -197,7 +188,7 @@ export class StateInitializer {
|
|
|
197
188
|
// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and
|
|
198
189
|
// keep in sync two copies of the same data. TS hides the extra info anyway.
|
|
199
190
|
entityRealm.children,
|
|
200
|
-
this.treeStore.persistedEntityData.get(entity.id.
|
|
191
|
+
this.treeStore.persistedEntityData.get(entity.id.uniqueValue),
|
|
201
192
|
entityRealm.unpersistedChangesCount !== 0,
|
|
202
193
|
entityRealm.errors,
|
|
203
194
|
getEntityMarker(entityRealm).environment,
|
|
@@ -229,7 +220,7 @@ export class StateInitializer {
|
|
|
229
220
|
// entityRealm.unpersistedChangesCount += 1
|
|
230
221
|
// }
|
|
231
222
|
|
|
232
|
-
const persistedData = this.treeStore.persistedEntityData.get(entity.id.
|
|
223
|
+
const persistedData = this.treeStore.persistedEntityData.get(entity.id.uniqueValue)
|
|
233
224
|
|
|
234
225
|
const marker = getEntityMarker(state)
|
|
235
226
|
const pathBack = this.treeStore.getPathBackToParent(entityRealm)
|
|
@@ -252,7 +243,7 @@ export class StateInitializer {
|
|
|
252
243
|
if (pathBack?.fieldBackToParent === field.parameters.field) {
|
|
253
244
|
runtimeId = pathBack.parent.entity.id
|
|
254
245
|
} else {
|
|
255
|
-
runtimeId = fieldDatum instanceof
|
|
246
|
+
runtimeId = fieldDatum instanceof ServerId ? fieldDatum : new UnpersistedEntityDummyId()
|
|
256
247
|
}
|
|
257
248
|
this.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)
|
|
258
249
|
} else {
|
|
@@ -279,7 +270,7 @@ export class StateInitializer {
|
|
|
279
270
|
}
|
|
280
271
|
|
|
281
272
|
public initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {
|
|
282
|
-
const entityId = id.
|
|
273
|
+
const entityId = id.uniqueValue
|
|
283
274
|
|
|
284
275
|
const existing = this.treeStore.entityStore.get(entityId)
|
|
285
276
|
if (existing !== undefined) {
|
|
@@ -288,7 +279,7 @@ export class StateInitializer {
|
|
|
288
279
|
|
|
289
280
|
const entityState: EntityState = {
|
|
290
281
|
entityName,
|
|
291
|
-
hasIdSetInStone: id instanceof
|
|
282
|
+
hasIdSetInStone: id instanceof ServerId,
|
|
292
283
|
id,
|
|
293
284
|
isScheduledForDeletion: false,
|
|
294
285
|
maidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,
|
|
@@ -302,7 +293,7 @@ export class StateInitializer {
|
|
|
302
293
|
private initializeEntityListState(
|
|
303
294
|
blueprint: EntityListBlueprint,
|
|
304
295
|
entityName: EntityName,
|
|
305
|
-
initialEntityIds: Set<
|
|
296
|
+
initialEntityIds: Set<EntityId>,
|
|
306
297
|
): EntityListState {
|
|
307
298
|
const entityListState: EntityListState = {
|
|
308
299
|
type: 'entityList',
|
|
@@ -334,13 +325,13 @@ export class StateInitializer {
|
|
|
334
325
|
},
|
|
335
326
|
}
|
|
336
327
|
|
|
337
|
-
const initialData: Iterable<
|
|
328
|
+
const initialData: Iterable<EntityId | undefined> =
|
|
338
329
|
initialEntityIds.size === 0
|
|
339
330
|
? Array.from({ length: blueprint.marker.parameters.initialEntityCount })
|
|
340
331
|
: initialEntityIds
|
|
341
332
|
for (const entityId of initialData) {
|
|
342
333
|
this.initializeEntityRealm(
|
|
343
|
-
entityId ? new
|
|
334
|
+
entityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),
|
|
344
335
|
entityListState.entityName,
|
|
345
336
|
{
|
|
346
337
|
type: 'listEntity',
|
|
@@ -359,8 +350,9 @@ export class StateInitializer {
|
|
|
359
350
|
placeholderName: FieldName,
|
|
360
351
|
fieldMarker: FieldMarker,
|
|
361
352
|
persistedValue: Scalar | undefined,
|
|
353
|
+
copyFromState: FieldState | undefined,
|
|
362
354
|
): FieldState {
|
|
363
|
-
const resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null
|
|
355
|
+
const resolvedFieldValue = copyFromState ? copyFromState.value : (persistedValue ?? fieldMarker.defaultValue ?? null)
|
|
364
356
|
|
|
365
357
|
const fieldState: FieldState = {
|
|
366
358
|
type: 'field',
|
|
@@ -373,7 +365,7 @@ export class StateInitializer {
|
|
|
373
365
|
eventListeners: this.initializeFieldEventListenerStore(fieldMarker),
|
|
374
366
|
errors: undefined,
|
|
375
367
|
touchLog: undefined,
|
|
376
|
-
hasUnpersistedChanges: false,
|
|
368
|
+
hasUnpersistedChanges: copyFromState?.hasUnpersistedChanges ?? false,
|
|
377
369
|
|
|
378
370
|
getAccessor: () => {
|
|
379
371
|
if (fieldState.accessor === undefined) {
|
|
@@ -409,15 +401,16 @@ export class StateInitializer {
|
|
|
409
401
|
private initializeFromFieldMarker(
|
|
410
402
|
parent: EntityRealmState,
|
|
411
403
|
field: FieldMarker,
|
|
412
|
-
|
|
404
|
+
persistedValue: EntityFieldPersistedData | undefined,
|
|
405
|
+
copyFromState?: FieldState,
|
|
413
406
|
) {
|
|
414
|
-
if (
|
|
407
|
+
if (persistedValue instanceof Set) {
|
|
415
408
|
throw new BindingError(
|
|
416
409
|
`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +
|
|
417
410
|
`Perhaps you wanted to use a <Repeater />?`,
|
|
418
411
|
)
|
|
419
412
|
}
|
|
420
|
-
if (
|
|
413
|
+
if (persistedValue instanceof ServerId) {
|
|
421
414
|
throw new BindingError(
|
|
422
415
|
`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +
|
|
423
416
|
`Perhaps you wanted to use <HasOne />?`,
|
|
@@ -425,7 +418,7 @@ export class StateInitializer {
|
|
|
425
418
|
}
|
|
426
419
|
parent.children.set(
|
|
427
420
|
field.placeholderName,
|
|
428
|
-
this.initializeFieldState(parent, field.placeholderName, field,
|
|
421
|
+
this.initializeFieldState(parent, field.placeholderName, field, persistedValue, copyFromState),
|
|
429
422
|
)
|
|
430
423
|
}
|
|
431
424
|
|
|
@@ -463,7 +456,7 @@ export class StateInitializer {
|
|
|
463
456
|
private initializeFromHasManyRelationMarker(
|
|
464
457
|
parent: EntityRealmState,
|
|
465
458
|
field: HasManyRelationMarker,
|
|
466
|
-
persistedEntityIds: Set<
|
|
459
|
+
persistedEntityIds: Set<EntityId>,
|
|
467
460
|
) {
|
|
468
461
|
parent.children.set(
|
|
469
462
|
field.placeholderName,
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
EntityListPersistedData,
|
|
4
4
|
ReceivedDataTree,
|
|
5
5
|
RuntimeId,
|
|
6
|
-
|
|
6
|
+
ServerId,
|
|
7
7
|
UnpersistedEntityDummyId,
|
|
8
8
|
} from '../accessorTree'
|
|
9
9
|
import { BindingError } from '../BindingError'
|
|
@@ -63,7 +63,7 @@ export class TreeAugmenter {
|
|
|
63
63
|
}
|
|
64
64
|
this.updateEntityListPersistedData(rootState, rootData)
|
|
65
65
|
} else if (rootState.type === 'entityRealm') {
|
|
66
|
-
if (rootData !== undefined && !(rootData instanceof
|
|
66
|
+
if (rootData !== undefined && !(rootData instanceof ServerId)) {
|
|
67
67
|
continue // This should never happen.
|
|
68
68
|
}
|
|
69
69
|
this.updateRealmIdIfNecessary(rootState, rootData)
|
|
@@ -130,12 +130,12 @@ export class TreeAugmenter {
|
|
|
130
130
|
|
|
131
131
|
private updateRealmIdIfNecessary(
|
|
132
132
|
realm: EntityRealmState | EntityRealmStateStub,
|
|
133
|
-
newId:
|
|
133
|
+
newId: ServerId | undefined | null,
|
|
134
134
|
) {
|
|
135
135
|
const currentId = realm.entity.id
|
|
136
136
|
let idToChangeTo: RuntimeId | undefined = undefined
|
|
137
137
|
|
|
138
|
-
if (currentId instanceof
|
|
138
|
+
if (currentId instanceof ServerId) {
|
|
139
139
|
if (newId === undefined || newId === null) {
|
|
140
140
|
idToChangeTo = new UnpersistedEntityDummyId()
|
|
141
141
|
} else if (currentId.value !== newId.value) {
|
|
@@ -157,14 +157,14 @@ export class TreeAugmenter {
|
|
|
157
157
|
|
|
158
158
|
private updateEntityRealmPersistedData(realm: EntityRealmState) {
|
|
159
159
|
const realmId = realm.entity.id
|
|
160
|
-
const persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.
|
|
160
|
+
const persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined
|
|
161
161
|
|
|
162
162
|
for (const [placeholderName, child] of realm.children) {
|
|
163
163
|
const childData = persistedData?.get(placeholderName)
|
|
164
164
|
|
|
165
165
|
switch (child.type) {
|
|
166
166
|
case 'field': {
|
|
167
|
-
if (childData instanceof
|
|
167
|
+
if (childData instanceof ServerId || childData instanceof Set) {
|
|
168
168
|
throw new BindingError()
|
|
169
169
|
}
|
|
170
170
|
|
|
@@ -181,7 +181,7 @@ export class TreeAugmenter {
|
|
|
181
181
|
}
|
|
182
182
|
case 'entityRealm':
|
|
183
183
|
case 'entityRealmStub': {
|
|
184
|
-
if (!(childData instanceof
|
|
184
|
+
if (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {
|
|
185
185
|
throw new BindingError()
|
|
186
186
|
}
|
|
187
187
|
this.updateRealmIdIfNecessary(child, childData)
|
|
@@ -220,7 +220,7 @@ export class TreeAugmenter {
|
|
|
220
220
|
if (
|
|
221
221
|
// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side
|
|
222
222
|
// id generation didn't quite pan out.
|
|
223
|
-
childRuntimeId instanceof
|
|
223
|
+
childRuntimeId instanceof ServerId ||
|
|
224
224
|
childRuntimeId instanceof ClientGeneratedUuid ||
|
|
225
225
|
// No persisted entity id to allocate to this so that's a goodbye.
|
|
226
226
|
persistedWithoutState.length === 0
|
|
@@ -234,7 +234,7 @@ export class TreeAugmenter {
|
|
|
234
234
|
this.eventManager,
|
|
235
235
|
this.stateInitializer,
|
|
236
236
|
child,
|
|
237
|
-
new
|
|
237
|
+
new ServerId(drawnId, child.entity.entityName),
|
|
238
238
|
)
|
|
239
239
|
}
|
|
240
240
|
} else if (childRuntimeId instanceof ClientGeneratedUuid) {
|
|
@@ -243,7 +243,7 @@ export class TreeAugmenter {
|
|
|
243
243
|
this.eventManager,
|
|
244
244
|
this.stateInitializer,
|
|
245
245
|
child,
|
|
246
|
-
new
|
|
246
|
+
new ServerId(childRuntimeId.value, child.entity.entityName),
|
|
247
247
|
)
|
|
248
248
|
}
|
|
249
249
|
if (child.type === 'entityRealm') {
|
|
@@ -251,7 +251,7 @@ export class TreeAugmenter {
|
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
for (const unclaimedPersistedId of persistedWithoutState) {
|
|
254
|
-
this.stateInitializer.initializeEntityRealm(new
|
|
254
|
+
this.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {
|
|
255
255
|
type: 'listEntity',
|
|
256
256
|
parent: state,
|
|
257
257
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RelationFilter, TreeFilter } from '@contember/client'
|
|
2
|
-
import { EntityListPersistedData,
|
|
2
|
+
import { EntityListPersistedData, ServerId } from '../accessorTree'
|
|
3
3
|
import {
|
|
4
4
|
EntityFieldMarkersContainer,
|
|
5
5
|
EntityListSubTreeMarker,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
HasManyRelationMarker,
|
|
8
8
|
HasOneRelationMarker,
|
|
9
9
|
} from '../markers'
|
|
10
|
-
import type { EntityName } from '../treeParameters'
|
|
10
|
+
import type { EntityId, EntityName } from '../treeParameters'
|
|
11
11
|
import { assertNever } from '../utils'
|
|
12
12
|
import { StateIterator } from './state'
|
|
13
13
|
import type { TreeStore } from './TreeStore'
|
|
@@ -34,7 +34,7 @@ export class TreeFilterGenerator {
|
|
|
34
34
|
|
|
35
35
|
private generateSubTreeFilter(
|
|
36
36
|
subTree: EntitySubTreeMarker | EntityListSubTreeMarker,
|
|
37
|
-
persistedData:
|
|
37
|
+
persistedData: ServerId | EntityListPersistedData | undefined,
|
|
38
38
|
): TreeFilter[] {
|
|
39
39
|
const filters: TreeFilter[] = []
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ export class TreeFilterGenerator {
|
|
|
42
42
|
return filters // Do nothing
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (persistedData instanceof
|
|
45
|
+
if (persistedData instanceof ServerId) {
|
|
46
46
|
const filter = this.generateTopLevelEntityFilter(
|
|
47
47
|
persistedData.value,
|
|
48
48
|
subTree.parameters.entityName,
|
|
@@ -60,7 +60,7 @@ export class TreeFilterGenerator {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
private generateTopLevelEntityFilter(
|
|
63
|
-
id:
|
|
63
|
+
id: EntityId,
|
|
64
64
|
entityName: EntityName,
|
|
65
65
|
fields: EntityFieldMarkersContainer,
|
|
66
66
|
): TreeFilter | undefined {
|
package/src/core/TreeStore.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
NormalizedPersistedData,
|
|
3
|
+
PersistedEntityDataStore,
|
|
4
|
+
ReceivedDataTree,
|
|
5
|
+
SubTreeDataStore,
|
|
6
|
+
UniqueEntityId,
|
|
7
|
+
} from '../accessorTree'
|
|
2
8
|
import { BindingError } from '../BindingError'
|
|
3
9
|
import type { Environment } from '../dao'
|
|
4
10
|
import { MarkerTreeRoot, PlaceholderGenerator } from '../markers'
|
|
@@ -25,7 +31,7 @@ import type { EntityListState, EntityRealmState, EntityRealmStateStub, EntitySta
|
|
|
25
31
|
const emptyEntityIdSet: ReadonlySet<EntityId> = new Set()
|
|
26
32
|
|
|
27
33
|
export class TreeStore {
|
|
28
|
-
public readonly entityStore: Map<
|
|
34
|
+
public readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()
|
|
29
35
|
public readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()
|
|
30
36
|
|
|
31
37
|
// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.
|
|
@@ -168,6 +174,7 @@ export class TreeStore {
|
|
|
168
174
|
environment,
|
|
169
175
|
)
|
|
170
176
|
: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),
|
|
177
|
+
environment,
|
|
171
178
|
)
|
|
172
179
|
} else if (mode === 'entity') {
|
|
173
180
|
placeholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(
|
|
@@ -177,6 +184,7 @@ export class TreeStore {
|
|
|
177
184
|
environment,
|
|
178
185
|
)
|
|
179
186
|
: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),
|
|
187
|
+
environment,
|
|
180
188
|
)
|
|
181
189
|
} else {
|
|
182
190
|
throw new BindingError()
|
|
@@ -189,11 +197,11 @@ export class TreeStore {
|
|
|
189
197
|
return subTreeState
|
|
190
198
|
}
|
|
191
199
|
|
|
192
|
-
public getEntityListPersistedIds(state: EntityListState): ReadonlySet<
|
|
200
|
+
public getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {
|
|
193
201
|
const blueprint = state.blueprint
|
|
194
202
|
|
|
195
203
|
if (blueprint.parent) {
|
|
196
|
-
const entityData = this.persistedEntityData.get(blueprint.parent.entity.id.
|
|
204
|
+
const entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)
|
|
197
205
|
return (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet
|
|
198
206
|
} else {
|
|
199
207
|
return (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet
|
|
@@ -235,8 +243,8 @@ export class TreeStore {
|
|
|
235
243
|
for (const realm of entity.realms.values()) {
|
|
236
244
|
this.disposeOfRealm(realm)
|
|
237
245
|
}
|
|
238
|
-
this.entityStore.delete(entity.id.
|
|
239
|
-
this.persistedEntityData.delete(entity.id.
|
|
246
|
+
this.entityStore.delete(entity.id.uniqueValue)
|
|
247
|
+
this.persistedEntityData.delete(entity.id.uniqueValue)
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
public effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '../../accessors'
|
|
2
|
-
import {
|
|
2
|
+
import { ServerId, UnpersistedEntityDummyId } from '../../accessorTree'
|
|
3
3
|
import { BindingError } from '../../BindingError'
|
|
4
4
|
import { EntityFieldMarkersContainer, HasOneRelationMarker } from '../../markers'
|
|
5
5
|
import type { FieldName } from '../../treeParameters'
|
|
@@ -48,7 +48,7 @@ export class EntityOperations {
|
|
|
48
48
|
this.eventManager.syncOperation(() => {
|
|
49
49
|
const stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)
|
|
50
50
|
const fieldsToConnect = getEntityMarker(stateToConnect).fields
|
|
51
|
-
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.
|
|
51
|
+
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)
|
|
52
52
|
|
|
53
53
|
const entityName = outerState.entity.entityName
|
|
54
54
|
const fieldSchema = this.treeStore.schema.getEntityField(entityName, fieldName)
|
|
@@ -127,16 +127,11 @@ export class EntityOperations {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)
|
|
130
|
-
if (persistedId instanceof
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
changesDelta++ // We're changing it from the persisted id.
|
|
135
|
-
}
|
|
130
|
+
if (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {
|
|
131
|
+
changesDelta-- // It was removed from the list but now we're adding it back.
|
|
132
|
+
} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {
|
|
133
|
+
changesDelta++ // We're changing it from the persisted id.
|
|
136
134
|
} else if (!previouslyConnectedState.entity.id.existsOnServer) {
|
|
137
|
-
// This assumes the invariant enforced above that we cannot connect unpersisted entities.
|
|
138
|
-
// Hence the previouslyConnectedState still refers to the entity created initially.
|
|
139
|
-
|
|
140
135
|
if (
|
|
141
136
|
persistedId === null || // We're updating.
|
|
142
137
|
(persistedId === undefined && // We're creating.
|
|
@@ -145,6 +140,9 @@ export class EntityOperations {
|
|
|
145
140
|
changesDelta++
|
|
146
141
|
}
|
|
147
142
|
}
|
|
143
|
+
if (stateToConnect.type === 'entityRealm') {
|
|
144
|
+
changesDelta += stateToConnect.unpersistedChangesCount
|
|
145
|
+
}
|
|
148
146
|
|
|
149
147
|
// TODO do something about the existing state…
|
|
150
148
|
|
|
@@ -152,6 +150,7 @@ export class EntityOperations {
|
|
|
152
150
|
stateToConnect.entity.id,
|
|
153
151
|
stateToConnect.entity.entityName,
|
|
154
152
|
previouslyConnectedState.blueprint,
|
|
153
|
+
stateToConnect,
|
|
155
154
|
)
|
|
156
155
|
|
|
157
156
|
this.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)
|
|
@@ -167,7 +166,7 @@ export class EntityOperations {
|
|
|
167
166
|
initializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,
|
|
168
167
|
) {
|
|
169
168
|
this.eventManager.syncOperation(() => {
|
|
170
|
-
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.
|
|
169
|
+
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)
|
|
171
170
|
|
|
172
171
|
for (const state of StateIterator.eachSiblingRealm(outerState)) {
|
|
173
172
|
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(
|
|
@@ -194,7 +193,7 @@ export class EntityOperations {
|
|
|
194
193
|
}
|
|
195
194
|
const persistedId = persistedData?.get(targetHasOneMarker.placeholderName)
|
|
196
195
|
|
|
197
|
-
if (persistedId instanceof
|
|
196
|
+
if (persistedId instanceof ServerId) {
|
|
198
197
|
if (persistedId.value === stateToDisconnect.entity.id.value) {
|
|
199
198
|
changesDelta++ // Disconnecting the persisted entity.
|
|
200
199
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validate as uuidValidate } from 'uuid'
|
|
2
2
|
import { ErrorAccessor, FieldAccessor } from '../../accessors'
|
|
3
|
-
import { ClientGeneratedUuid } from '../../accessorTree'
|
|
3
|
+
import { ClientGeneratedUuid, ServerId } from '../../accessorTree'
|
|
4
4
|
import { BindingError } from '../../BindingError'
|
|
5
5
|
import { PRIMARY_KEY_NAME } from '../../bindingTypes'
|
|
6
6
|
import type { FieldValue } from '../../treeParameters'
|
|
@@ -66,7 +66,7 @@ export class FieldOperations {
|
|
|
66
66
|
`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,
|
|
67
67
|
)
|
|
68
68
|
}
|
|
69
|
-
if (this.treeStore.entityStore.has(newValue)) {
|
|
69
|
+
if (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {
|
|
70
70
|
throw new BindingError(
|
|
71
71
|
`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +
|
|
72
72
|
`It is already in use by an existing entity.`,
|
|
@@ -11,7 +11,7 @@ import { EntityListState, getEntityMarker, StateIterator } from '../state'
|
|
|
11
11
|
import type { StateInitializer } from '../StateInitializer'
|
|
12
12
|
import type { TreeStore } from '../TreeStore'
|
|
13
13
|
import { OperationsHelpers } from './OperationsHelpers'
|
|
14
|
-
import { EventListenersStore } from '../../treeParameters'
|
|
14
|
+
import { EntityId, EventListenersStore } from '../../treeParameters'
|
|
15
15
|
|
|
16
16
|
export class ListOperations {
|
|
17
17
|
public constructor(
|
|
@@ -106,7 +106,8 @@ export class ListOperations {
|
|
|
106
106
|
if (persistedEntityIds.has(idToConnect.value)) {
|
|
107
107
|
// It was removed from the list but now we're adding it back.
|
|
108
108
|
changesDelta--
|
|
109
|
-
} else {
|
|
109
|
+
} else if (idToConnect.existsOnServer) {
|
|
110
|
+
// ignoring unpersisted entities
|
|
110
111
|
changesDelta++
|
|
111
112
|
}
|
|
112
113
|
if (stateToConnect.type === 'entityRealm') {
|
|
@@ -185,14 +186,14 @@ export class ListOperations {
|
|
|
185
186
|
})
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
public getChildEntityById(state: EntityListState, id:
|
|
189
|
+
public getChildEntityById(state: EntityListState, id: EntityId) {
|
|
189
190
|
const realm = state.children.get(id)
|
|
190
191
|
if (realm === undefined) {
|
|
191
|
-
const isRuntimeId = uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)
|
|
192
|
+
const isRuntimeId = typeof id === 'number' || uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)
|
|
192
193
|
if (isRuntimeId) {
|
|
193
194
|
throw new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`)
|
|
194
195
|
}
|
|
195
|
-
const looksLikeKey = this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id)
|
|
196
|
+
const looksLikeKey = typeof id === 'string' && (this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id))
|
|
196
197
|
throw new BindingError(
|
|
197
198
|
`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` +
|
|
198
199
|
(looksLikeKey
|
|
@@ -54,8 +54,8 @@ export class OperationsHelpers {
|
|
|
54
54
|
) {
|
|
55
55
|
const previousId = entity.id
|
|
56
56
|
|
|
57
|
-
treeStore.entityStore.delete(previousId.
|
|
58
|
-
treeStore.entityStore.set(newId.
|
|
57
|
+
treeStore.entityStore.delete(previousId.uniqueValue)
|
|
58
|
+
treeStore.entityStore.set(newId.uniqueValue, entity)
|
|
59
59
|
|
|
60
60
|
let counter = 0
|
|
61
61
|
for (const realm of entity.realms.values()) {
|
|
@@ -19,7 +19,7 @@ const standaloneUuidPrefix = uuidToAliasReplacement
|
|
|
19
19
|
export class MutationAlias {
|
|
20
20
|
public static encodeTopLevel(operation: TopLevelMutationOperation): string {
|
|
21
21
|
const treeRootId = operation.treeRootId === undefined ? 'u' : `t${operation.treeRootId.replace('-', '_')}t`
|
|
22
|
-
const entityId = operation.entityId.replace(uuidToAliasRegex, uuidToAliasReplacement)
|
|
22
|
+
const entityId = String(operation.entityId).replace(uuidToAliasRegex, uuidToAliasReplacement)
|
|
23
23
|
|
|
24
24
|
const alias = `${treeRootId}${operation.subTreePlaceholder}__${operation.type}${operation.subTreeType}${entityId}`
|
|
25
25
|
|
|
@@ -57,10 +57,12 @@ export class MutationAlias {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
public static encodeEntityId(entityId: RuntimeId): string {
|
|
60
|
-
return `${standaloneUuidPrefix}${entityId.value.replace(uuidToAliasRegex, uuidToAliasReplacement)}`
|
|
60
|
+
return `${standaloneUuidPrefix}${String(entityId.value).replace(uuidToAliasRegex, uuidToAliasReplacement)}`
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
public static decodeEntityId(alias: string): RuntimeId['value'] {
|
|
64
|
-
|
|
64
|
+
const stringId = `${alias.substring(standaloneUuidPrefix.length).replace(aliasToUuidRegex, aliasToUuidReplacement)}`
|
|
65
|
+
const intId = parseInt(stringId)
|
|
66
|
+
return intId.toString() === stringId ? intId : stringId
|
|
65
67
|
}
|
|
66
68
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { EntityName } from '../../treeParameters'
|
|
2
2
|
import type { SchemaColumn } from './SchemaColumn'
|
|
3
3
|
import type { SchemaRelation } from './SchemaRelation'
|
|
4
|
-
import type { SchemaUniqueConstraint } from './SchemaUniqueConstraint'
|
|
5
4
|
|
|
6
5
|
export type RawSchemaFields = Array<SchemaRelation | SchemaColumn>
|
|
7
6
|
|
|
@@ -9,5 +8,5 @@ export interface RawSchemaEntity {
|
|
|
9
8
|
name: EntityName
|
|
10
9
|
customPrimaryAllowed: boolean
|
|
11
10
|
fields: RawSchemaFields
|
|
12
|
-
unique:
|
|
11
|
+
unique: { fields: string[] }[]
|
|
13
12
|
}
|
|
@@ -32,7 +32,7 @@ export class SchemaPreprocessor {
|
|
|
32
32
|
customPrimaryAllowed: entity.customPrimaryAllowed,
|
|
33
33
|
fields: this.processRawFields(entity.fields),
|
|
34
34
|
name: entity.name,
|
|
35
|
-
unique: entity.unique,
|
|
35
|
+
unique: entity.unique.map(it => ({ fields: new Set(it.fields) })),
|
|
36
36
|
})
|
|
37
37
|
}
|
|
38
38
|
|