@contember/binding-legacy 2.1.0-alpha.9 → 2.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/index.cjs +8 -8
- package/dist/development/index.js +4 -4
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.js +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/src/core/Config.cjs.map +1 -1
- package/dist/development/src/core/Config.js.map +1 -1
- package/dist/development/src/core/DataBinding.cjs +10 -7
- package/dist/development/src/core/DataBinding.cjs.map +1 -1
- package/dist/development/src/core/DataBinding.js +10 -7
- package/dist/development/src/core/DataBinding.js.map +1 -1
- package/dist/development/src/core/DirtinessTracker.cjs.map +1 -1
- package/dist/development/src/core/DirtinessTracker.js.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/src/core/EventManager.cjs.map +1 -1
- package/dist/development/src/core/EventManager.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/development/src/core/QueryGenerator.js.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/src/core/StateInitializer.cjs +24 -2
- package/dist/development/src/core/StateInitializer.cjs.map +1 -1
- package/dist/development/src/core/StateInitializer.js +25 -3
- package/dist/development/src/core/StateInitializer.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs +2 -5
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/development/src/core/TreeAugmenter.js +2 -5
- package/dist/development/src/core/TreeAugmenter.js.map +1 -1
- package/dist/development/src/core/TreeStore.cjs.map +1 -1
- package/dist/development/src/core/TreeStore.js.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.cjs +1 -3
- package/dist/development/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.js +1 -3
- package/dist/development/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/ListOperations.js.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/development/src/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/development/src/core/state/StateIterator.js.map +1 -1
- package/dist/development/src/core/utils/getCombinedSignal.cjs.map +1 -1
- package/dist/development/src/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +3 -3
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js +3 -3
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -1
- package/dist/development/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
- package/dist/development/src/utils/isEmptyObject.cjs.map +1 -1
- package/dist/development/src/utils/isEmptyObject.js.map +1 -1
- package/dist/production/index.cjs +8 -8
- package/dist/production/index.js +4 -4
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.js +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/src/core/Config.cjs.map +1 -1
- package/dist/production/src/core/Config.js.map +1 -1
- package/dist/production/src/core/DataBinding.cjs +10 -7
- package/dist/production/src/core/DataBinding.cjs.map +1 -1
- package/dist/production/src/core/DataBinding.js +10 -7
- package/dist/production/src/core/DataBinding.js.map +1 -1
- package/dist/production/src/core/DirtinessTracker.cjs.map +1 -1
- package/dist/production/src/core/DirtinessTracker.js.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/src/core/EventManager.cjs.map +1 -1
- package/dist/production/src/core/EventManager.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/production/src/core/QueryGenerator.js.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/src/core/StateInitializer.cjs +24 -2
- package/dist/production/src/core/StateInitializer.cjs.map +1 -1
- package/dist/production/src/core/StateInitializer.js +25 -3
- package/dist/production/src/core/StateInitializer.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs +2 -5
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/production/src/core/TreeAugmenter.js +2 -5
- package/dist/production/src/core/TreeAugmenter.js.map +1 -1
- package/dist/production/src/core/TreeStore.cjs.map +1 -1
- package/dist/production/src/core/TreeStore.js.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.cjs +1 -3
- package/dist/production/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.js +1 -3
- package/dist/production/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/ListOperations.js.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/production/src/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/production/src/core/state/StateIterator.js.map +1 -1
- package/dist/production/src/core/utils/getCombinedSignal.cjs.map +1 -1
- package/dist/production/src/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs +3 -3
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js +3 -3
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.cjs.map +1 -1
- package/dist/production/src/utils/generateEnumerabilityPreventingEntropy.js.map +1 -1
- package/dist/production/src/utils/isEmptyObject.cjs.map +1 -1
- package/dist/production/src/utils/isEmptyObject.js.map +1 -1
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessorImpl.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/ErrorsPreprocessor.d.ts.map +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/QueryGenerator.d.ts.map +1 -1
- package/dist/types/core/RealmKeyGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts +1 -0
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/core/TreeStore.d.ts.map +1 -1
- package/dist/types/core/operations/FieldOperations.d.ts.map +1 -1
- package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
- package/dist/types/core/state/EntityListState.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -5
- package/src/accessorTree/NormalizedPersistedData.ts +1 -1
- package/src/accessors/EntityAccessorImpl.ts +13 -11
- package/src/accessors/EntityListAccessorImpl.ts +16 -7
- package/src/core/AccessorErrorManager.ts +2 -2
- package/src/core/DataBinding.ts +24 -15
- package/src/core/ErrorsPreprocessor.ts +4 -5
- package/src/core/EventManager.ts +34 -46
- package/src/core/MutationGenerator.ts +23 -27
- package/src/core/QueryGenerator.ts +4 -5
- package/src/core/RealmKeyGenerator.ts +5 -3
- package/src/core/RequestResponseNormalizer.ts +3 -8
- package/src/core/StateInitializer.ts +34 -19
- package/src/core/TreeAugmenter.ts +8 -15
- package/src/core/TreeStore.ts +5 -4
- package/src/core/operations/EntityOperations.ts +25 -25
- package/src/core/operations/FieldOperations.ts +15 -17
- package/src/core/operations/ListOperations.ts +15 -15
- package/src/core/operations/OperationsHelpers.ts +2 -2
- package/src/core/state/EntityListState.ts +3 -9
- package/src/fieldHelpers/helpers/TemporalFieldHelper.ts +3 -3
- package/src/utils/assertNever.ts +4 -4
- package/tests/example.test.ts +2 -2
|
@@ -48,7 +48,6 @@ class ErrorsPreprocessor {
|
|
|
48
48
|
} else {
|
|
49
49
|
return assertNever(subTreeType)
|
|
50
50
|
}
|
|
51
|
-
|
|
52
51
|
}
|
|
53
52
|
return treeRoot
|
|
54
53
|
}
|
|
@@ -80,7 +79,7 @@ class ErrorsPreprocessor {
|
|
|
80
79
|
const pathNode = path[i]
|
|
81
80
|
|
|
82
81
|
if (currentNode.nodeType === 'leaf') {
|
|
83
|
-
(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'
|
|
82
|
+
;(currentNode as any as ErrorsPreprocessor.ErrorINode).nodeType = 'iNode'
|
|
84
83
|
;(currentNode as any as ErrorsPreprocessor.ErrorINode).children = new Map()
|
|
85
84
|
}
|
|
86
85
|
|
|
@@ -92,9 +91,9 @@ class ErrorsPreprocessor {
|
|
|
92
91
|
const nextPathNode = path[nextIndex]
|
|
93
92
|
|
|
94
93
|
if (
|
|
95
|
-
'index' in nextPathNode
|
|
96
|
-
typeof nextPathNode.alias === 'string'
|
|
97
|
-
nextPathNode.alias.startsWith(pathNode.field)
|
|
94
|
+
'index' in nextPathNode
|
|
95
|
+
&& typeof nextPathNode.alias === 'string'
|
|
96
|
+
&& nextPathNode.alias.startsWith(pathNode.field)
|
|
98
97
|
) {
|
|
99
98
|
// We're dealing with a reduced hasMany relation.
|
|
100
99
|
i++
|
package/src/core/EventManager.ts
CHANGED
|
@@ -13,16 +13,7 @@ import type { PlaceholderName } from '@contember/binding-common'
|
|
|
13
13
|
import { assertNever } from '@contember/binding-common'
|
|
14
14
|
import type { Config } from './Config'
|
|
15
15
|
import type { DirtinessTracker } from './DirtinessTracker'
|
|
16
|
-
import {
|
|
17
|
-
EntityListState,
|
|
18
|
-
EntityRealmState,
|
|
19
|
-
FieldState,
|
|
20
|
-
getEntityMarker,
|
|
21
|
-
RootStateNode,
|
|
22
|
-
StateINode,
|
|
23
|
-
StateIterator,
|
|
24
|
-
StateNode,
|
|
25
|
-
} from './state'
|
|
16
|
+
import { EntityListState, EntityRealmState, FieldState, getEntityMarker, RootStateNode, StateINode, StateIterator, StateNode } from './state'
|
|
26
17
|
import type { TreeStore } from './TreeStore'
|
|
27
18
|
import type { UpdateMetadata } from './UpdateMetadata'
|
|
28
19
|
import type { EventListenersStore } from '@contember/binding-common'
|
|
@@ -120,9 +111,9 @@ export class EventManager {
|
|
|
120
111
|
|
|
121
112
|
if (this.isFrozenWhileUpdating) {
|
|
122
113
|
throw new BindingError(
|
|
123
|
-
`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused `
|
|
124
|
-
`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. `
|
|
125
|
-
`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,
|
|
114
|
+
`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused `
|
|
115
|
+
+ `by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. `
|
|
116
|
+
+ `If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,
|
|
126
117
|
)
|
|
127
118
|
}
|
|
128
119
|
|
|
@@ -222,8 +213,8 @@ export class EventManager {
|
|
|
222
213
|
if (import.meta.env.DEV) {
|
|
223
214
|
if (justUpdated.unpersistedChangesCount < 0) {
|
|
224
215
|
console.error(
|
|
225
|
-
`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) `
|
|
226
|
-
`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,
|
|
216
|
+
`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) `
|
|
217
|
+
+ `go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,
|
|
227
218
|
)
|
|
228
219
|
}
|
|
229
220
|
}
|
|
@@ -233,7 +224,10 @@ export class EventManager {
|
|
|
233
224
|
if (parent === undefined) {
|
|
234
225
|
this.rootsWithPendingUpdates.add(justUpdated)
|
|
235
226
|
|
|
236
|
-
if (
|
|
227
|
+
if (
|
|
228
|
+
!(justUpdated.blueprint.type === 'subTree' && justUpdated.blueprint.marker.parameters.isCreating
|
|
229
|
+
&& justUpdated.blueprint.marker.parameters.isUnpersisted)
|
|
230
|
+
) {
|
|
237
231
|
this.dirtinessTracker.increaseBy(changesDelta)
|
|
238
232
|
}
|
|
239
233
|
} else {
|
|
@@ -263,12 +257,11 @@ export class EventManager {
|
|
|
263
257
|
|
|
264
258
|
for (const state of agenda) {
|
|
265
259
|
// yes, the calls are same, but this way we can avoid type casting
|
|
266
|
-
const updateListeners =
|
|
267
|
-
state
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])
|
|
260
|
+
const updateListeners = state.type === 'field'
|
|
261
|
+
? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])
|
|
262
|
+
: state.type === 'entityRealm'
|
|
263
|
+
? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])
|
|
264
|
+
: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])
|
|
272
265
|
|
|
273
266
|
if (updateListeners !== undefined) {
|
|
274
267
|
for (const handler of updateListeners) {
|
|
@@ -412,8 +405,8 @@ export class EventManager {
|
|
|
412
405
|
if (import.meta.env.DEV) {
|
|
413
406
|
if (callbackQueue.length) {
|
|
414
407
|
throw new BindingError(
|
|
415
|
-
`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. `
|
|
416
|
-
`If that's not the case, raise the settle limit from DataBindingProvider.`,
|
|
408
|
+
`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. `
|
|
409
|
+
+ `If that's not the case, raise the settle limit from DataBindingProvider.`,
|
|
417
410
|
)
|
|
418
411
|
}
|
|
419
412
|
}
|
|
@@ -441,7 +434,7 @@ export class EventManager {
|
|
|
441
434
|
switch (state.type) {
|
|
442
435
|
case 'field':
|
|
443
436
|
for (const listener of listeners) {
|
|
444
|
-
(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())
|
|
437
|
+
;(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())
|
|
445
438
|
}
|
|
446
439
|
break
|
|
447
440
|
case 'entityRealm':
|
|
@@ -458,8 +451,8 @@ export class EventManager {
|
|
|
458
451
|
this.triggerOnInitialize()
|
|
459
452
|
}
|
|
460
453
|
throw new BindingError(
|
|
461
|
-
`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. `
|
|
462
|
-
`This likely means there is an infinite feedback loop in your code.`,
|
|
454
|
+
`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. `
|
|
455
|
+
+ `This likely means there is an infinite feedback loop in your code.`,
|
|
463
456
|
)
|
|
464
457
|
})
|
|
465
458
|
}
|
|
@@ -468,12 +461,11 @@ export class EventManager {
|
|
|
468
461
|
this.syncTransaction(() => {
|
|
469
462
|
for (const state of this.newlyInitializedWithListeners) {
|
|
470
463
|
// yes, the calls are same, but this way we can avoid type casting
|
|
471
|
-
const listeners =
|
|
472
|
-
state
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])
|
|
464
|
+
const listeners = state.type === 'field'
|
|
465
|
+
? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])
|
|
466
|
+
: state.type === 'entityRealm'
|
|
467
|
+
? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])
|
|
468
|
+
: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])
|
|
477
469
|
|
|
478
470
|
if (listeners) {
|
|
479
471
|
for (const listener of listeners) {
|
|
@@ -495,10 +487,9 @@ export class EventManager {
|
|
|
495
487
|
for (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {
|
|
496
488
|
for (const iNode of StateIterator.depthFirstINodes(subTreeState)) {
|
|
497
489
|
// yes, the calls are same, but this way we can avoid type casting
|
|
498
|
-
const dispatchers =
|
|
499
|
-
iNode
|
|
500
|
-
|
|
501
|
-
: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])
|
|
490
|
+
const dispatchers = iNode.type === 'entityRealm'
|
|
491
|
+
? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])
|
|
492
|
+
: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])
|
|
502
493
|
if (dispatchers === undefined) {
|
|
503
494
|
continue
|
|
504
495
|
}
|
|
@@ -533,8 +524,7 @@ export class EventManager {
|
|
|
533
524
|
|
|
534
525
|
public getEventListeners<
|
|
535
526
|
State extends StateNode,
|
|
536
|
-
EventListenerTypes extends
|
|
537
|
-
Exclude<State['eventListeners'], undefined> extends EventListenersStore<infer Map> ? [keyof Map, Map] : never,
|
|
527
|
+
EventListenerTypes extends Exclude<State['eventListeners'], undefined> extends EventListenersStore<infer Map> ? [keyof Map, Map] : never,
|
|
538
528
|
EventType extends EventListenerTypes[0],
|
|
539
529
|
>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {
|
|
540
530
|
if (!state.eventListeners) {
|
|
@@ -547,8 +537,7 @@ export class EventManager {
|
|
|
547
537
|
|
|
548
538
|
public getEventDispatchers<
|
|
549
539
|
State extends StateNode,
|
|
550
|
-
EventListenerTypes extends
|
|
551
|
-
Exclude<State['eventListeners'], undefined> extends EventListenersStore<infer Map> ? [keyof Map, Map] : never,
|
|
540
|
+
EventListenerTypes extends Exclude<State['eventListeners'], undefined> extends EventListenersStore<infer Map> ? [keyof Map, Map] : never,
|
|
552
541
|
EventType extends EventListenerTypes[0],
|
|
553
542
|
>(
|
|
554
543
|
state: State,
|
|
@@ -572,13 +561,12 @@ export class EventManager {
|
|
|
572
561
|
rejections.forEach(it => console.error(it.reason))
|
|
573
562
|
if (import.meta.env.DEV) {
|
|
574
563
|
throw new BindingError(
|
|
575
|
-
`A ${handler} handler returned a promise that rejected. `
|
|
576
|
-
`This is a no-op that will fail silently in production.`,
|
|
564
|
+
`A ${handler} handler returned a promise that rejected. `
|
|
565
|
+
+ `This is a no-op that will fail silently in production.`,
|
|
577
566
|
)
|
|
578
567
|
}
|
|
579
568
|
}
|
|
580
569
|
|
|
581
|
-
|
|
582
570
|
private validateWithoutChanges(initialCount: number, eventType: string): void {
|
|
583
571
|
const changesCountAfter = this.dirtinessTracker.getTotalTouchCount()
|
|
584
572
|
if (import.meta.env.DEV) {
|
|
@@ -586,8 +574,8 @@ export class EventManager {
|
|
|
586
574
|
// This isn't bulletproof. They could e.g. undo a change and make another one which would
|
|
587
575
|
// slip through this detection. But for most cases, it should be good enough and not too expensive.
|
|
588
576
|
throw new BindingError(
|
|
589
|
-
`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. `
|
|
590
|
-
|
|
577
|
+
`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. `
|
|
578
|
+
+ `To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,
|
|
591
579
|
)
|
|
592
580
|
}
|
|
593
581
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'
|
|
2
|
-
import { ClientGeneratedUuid,
|
|
2
|
+
import { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'
|
|
3
3
|
import { BindingError } from '@contember/binding-common'
|
|
4
4
|
import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'
|
|
5
5
|
import { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'
|
|
@@ -12,7 +12,6 @@ import { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, F
|
|
|
12
12
|
import type { TreeStore } from './TreeStore'
|
|
13
13
|
import { EntityFieldPersistedData, EntityFieldPersistedValue } from '../accessorTree'
|
|
14
14
|
|
|
15
|
-
|
|
16
15
|
type ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>
|
|
17
16
|
|
|
18
17
|
export type SubMutationOperation =
|
|
@@ -34,7 +33,6 @@ export type PersistMutationResult = {
|
|
|
34
33
|
|
|
35
34
|
// TODO enforce correct expected mutations in dev mode.
|
|
36
35
|
export class MutationGenerator {
|
|
37
|
-
|
|
38
36
|
private aliasCounter = 1
|
|
39
37
|
private processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
|
|
40
38
|
private processedDeletes = new Set<string>()
|
|
@@ -59,7 +57,10 @@ export class MutationGenerator {
|
|
|
59
57
|
continue
|
|
60
58
|
}
|
|
61
59
|
if (subTreeState.type === 'entityRealm') {
|
|
62
|
-
if (
|
|
60
|
+
if (
|
|
61
|
+
subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating
|
|
62
|
+
&& subTreeState.blueprint.marker.parameters.isUnpersisted
|
|
63
|
+
) {
|
|
63
64
|
continue
|
|
64
65
|
}
|
|
65
66
|
const subMutation = this.createMutation(
|
|
@@ -73,7 +74,10 @@ export class MutationGenerator {
|
|
|
73
74
|
operations.push(subMutation[1])
|
|
74
75
|
}
|
|
75
76
|
} else if (subTreeState.type === 'entityList') {
|
|
76
|
-
if (
|
|
77
|
+
if (
|
|
78
|
+
subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating
|
|
79
|
+
&& subTreeState.blueprint.marker.parameters.isUnpersisted
|
|
80
|
+
) {
|
|
77
81
|
continue
|
|
78
82
|
}
|
|
79
83
|
for (const childState of subTreeState.children.values()) {
|
|
@@ -198,7 +202,7 @@ export class MutationGenerator {
|
|
|
198
202
|
): ContentMutation<any> {
|
|
199
203
|
return this.qb.delete(entityName, {
|
|
200
204
|
by: { [PRIMARY_KEY_NAME]: deletedId },
|
|
201
|
-
}, it
|
|
205
|
+
}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
private createUpdateMutation(
|
|
@@ -245,7 +249,7 @@ export class MutationGenerator {
|
|
|
245
249
|
let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)
|
|
246
250
|
|
|
247
251
|
if (processedPlaceholders === undefined) {
|
|
248
|
-
this.processedPlaceholdersByEntity.set(currentState.entity,
|
|
252
|
+
this.processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = new Set())
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
if (currentState.type === 'entityRealmStub') {
|
|
@@ -255,12 +259,13 @@ export class MutationGenerator {
|
|
|
255
259
|
|
|
256
260
|
const result: Input.CreateDataInput = {}
|
|
257
261
|
for (const siblingState of StateIterator.eachSiblingRealm(currentState)) {
|
|
258
|
-
|
|
259
262
|
const pathBack = this.treeStore.getPathBackToParent(siblingState)
|
|
260
263
|
|
|
261
|
-
const nonbearingFields: Array
|
|
262
|
-
|
|
263
|
-
|
|
264
|
+
const nonbearingFields: Array<
|
|
265
|
+
| { type: 'field'; marker: FieldMarker; fieldState: FieldState }
|
|
266
|
+
| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }
|
|
267
|
+
| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }
|
|
268
|
+
> = []
|
|
264
269
|
|
|
265
270
|
for (const [placeholderName, fieldState] of siblingState.children) {
|
|
266
271
|
if (processedPlaceholders.has(placeholderName)) {
|
|
@@ -274,8 +279,8 @@ export class MutationGenerator {
|
|
|
274
279
|
const placeholderName = marker.placeholderName
|
|
275
280
|
|
|
276
281
|
if (
|
|
277
|
-
placeholderName === TYPENAME_KEY_NAME
|
|
278
|
-
(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))
|
|
282
|
+
placeholderName === TYPENAME_KEY_NAME
|
|
283
|
+
|| (placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))
|
|
279
284
|
) {
|
|
280
285
|
continue
|
|
281
286
|
}
|
|
@@ -407,9 +412,9 @@ export class MutationGenerator {
|
|
|
407
412
|
const field = setOnCreate[key]
|
|
408
413
|
|
|
409
414
|
if (
|
|
410
|
-
typeof field === 'string'
|
|
411
|
-
typeof field === 'number'
|
|
412
|
-
field === null
|
|
415
|
+
typeof field === 'string'
|
|
416
|
+
|| typeof field === 'number'
|
|
417
|
+
|| field === null
|
|
413
418
|
) {
|
|
414
419
|
result[key] = field
|
|
415
420
|
} else {
|
|
@@ -488,7 +493,7 @@ export class MutationGenerator {
|
|
|
488
493
|
let processedPlaceholders = this.processedPlaceholdersByEntity.get(currentState.entity)
|
|
489
494
|
|
|
490
495
|
if (processedPlaceholders === undefined) {
|
|
491
|
-
this.processedPlaceholdersByEntity.set(currentState.entity,
|
|
496
|
+
this.processedPlaceholdersByEntity.set(currentState.entity, processedPlaceholders = new Set())
|
|
492
497
|
}
|
|
493
498
|
|
|
494
499
|
const pathBack = this.treeStore.getPathBackToParent(currentState)
|
|
@@ -530,13 +535,10 @@ export class MutationGenerator {
|
|
|
530
535
|
|
|
531
536
|
const persistedValue = entityData?.get?.(placeholderName)?.value
|
|
532
537
|
if (reducedBy === undefined) {
|
|
533
|
-
|
|
534
538
|
const relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, placeholderName)
|
|
535
539
|
if (relationData !== undefined) {
|
|
536
540
|
result[marker.parameters.field] = relationData
|
|
537
541
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
542
|
} else {
|
|
541
543
|
const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, placeholderName, reducedBy)
|
|
542
544
|
if (relationData !== undefined) {
|
|
@@ -547,7 +549,6 @@ export class MutationGenerator {
|
|
|
547
549
|
result[marker.parameters.field] = relationData
|
|
548
550
|
}
|
|
549
551
|
}
|
|
550
|
-
|
|
551
552
|
}
|
|
552
553
|
break
|
|
553
554
|
}
|
|
@@ -595,7 +596,7 @@ export class MutationGenerator {
|
|
|
595
596
|
if (persistedValue.value === runtimeId.value) {
|
|
596
597
|
// The persisted and currently referenced ids match, and so this is an update.
|
|
597
598
|
if (fieldState.type === 'entityRealmStub') {
|
|
598
|
-
return undefined// …unless we're dealing with a stub. There cannot be any updates there.
|
|
599
|
+
return undefined // …unless we're dealing with a stub. There cannot be any updates there.
|
|
599
600
|
}
|
|
600
601
|
const input = this.getUpdateDataInput(fieldState)
|
|
601
602
|
if (input === undefined) {
|
|
@@ -628,7 +629,6 @@ export class MutationGenerator {
|
|
|
628
629
|
return {
|
|
629
630
|
connect: { [PRIMARY_KEY_NAME]: runtimeId.value },
|
|
630
631
|
}
|
|
631
|
-
|
|
632
632
|
}
|
|
633
633
|
// The currently present entity doesn't exist on the server. Try if creating yields anything…
|
|
634
634
|
const createInput = this.getCreateDataInput(fieldState)
|
|
@@ -667,7 +667,6 @@ export class MutationGenerator {
|
|
|
667
667
|
placeholderName: PlaceholderName,
|
|
668
668
|
reducedBy: UniqueWhere,
|
|
669
669
|
): Input.UpdateManyRelationInput | undefined {
|
|
670
|
-
|
|
671
670
|
const runtimeId = fieldState.entity.id
|
|
672
671
|
const alias = MutationAlias.encodeEntityId(runtimeId)
|
|
673
672
|
|
|
@@ -747,7 +746,6 @@ export class MutationGenerator {
|
|
|
747
746
|
fieldState: EntityListState,
|
|
748
747
|
persistedEntityIds: Set<EntityId>,
|
|
749
748
|
): Input.UpdateManyRelationInput | undefined {
|
|
750
|
-
|
|
751
749
|
const input: Input.UpdateManyRelationInput = []
|
|
752
750
|
for (const childState of fieldState.children.values()) {
|
|
753
751
|
const runtimeId = childState.entity.id
|
|
@@ -798,7 +796,6 @@ export class MutationGenerator {
|
|
|
798
796
|
alias,
|
|
799
797
|
delete: { [PRIMARY_KEY_NAME]: removedId },
|
|
800
798
|
})
|
|
801
|
-
|
|
802
799
|
} else if (removalType === 'disconnect') {
|
|
803
800
|
// TODO also potentially update
|
|
804
801
|
|
|
@@ -815,7 +812,6 @@ export class MutationGenerator {
|
|
|
815
812
|
return input.length === 0 ? undefined : input
|
|
816
813
|
}
|
|
817
814
|
|
|
818
|
-
|
|
819
815
|
private createAlias(): string {
|
|
820
816
|
return `op_${this.aliasCounter++}`
|
|
821
817
|
}
|
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
EntityFieldMarkers,
|
|
4
4
|
EntityListSubTreeMarker,
|
|
5
5
|
EntitySubTreeMarker,
|
|
6
|
-
FieldMarker,
|
|
6
|
+
FieldMarker,
|
|
7
|
+
FieldMeta,
|
|
7
8
|
HasManyRelationMarker,
|
|
8
9
|
HasOneRelationMarker,
|
|
9
10
|
MarkerTreeRoot,
|
|
@@ -11,7 +12,6 @@ import {
|
|
|
11
12
|
} from '@contember/binding-common'
|
|
12
13
|
import { ContentEntitySelection, ContentQuery, ContentQueryBuilder } from '@contember/client'
|
|
13
14
|
|
|
14
|
-
|
|
15
15
|
export class QueryGenerator {
|
|
16
16
|
constructor(
|
|
17
17
|
private tree: MarkerTreeRoot,
|
|
@@ -44,7 +44,7 @@ export class QueryGenerator {
|
|
|
44
44
|
by: subTree.parameters.where,
|
|
45
45
|
filter: subTree.parameters.filter,
|
|
46
46
|
},
|
|
47
|
-
it =>
|
|
47
|
+
it => QueryGenerator.registerQueryPart(subTree.fields.markers, it),
|
|
48
48
|
)
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -60,7 +60,7 @@ export class QueryGenerator {
|
|
|
60
60
|
offset: subTree.parameters.offset,
|
|
61
61
|
limit: subTree.parameters.limit,
|
|
62
62
|
},
|
|
63
|
-
it =>
|
|
63
|
+
it => QueryGenerator.registerQueryPart(subTree.fields.markers, it),
|
|
64
64
|
)
|
|
65
65
|
}
|
|
66
66
|
|
|
@@ -100,7 +100,6 @@ export class QueryGenerator {
|
|
|
100
100
|
} else if (fieldValue instanceof HasManyRelationMarker) {
|
|
101
101
|
const relation = fieldValue.parameters
|
|
102
102
|
|
|
103
|
-
|
|
104
103
|
selection = selection.$(
|
|
105
104
|
relation.field,
|
|
106
105
|
{
|
|
@@ -24,9 +24,11 @@ export class RealmKeyGenerator {
|
|
|
24
24
|
container: EntityFieldMarkersContainer,
|
|
25
25
|
): EntityRealmKey {
|
|
26
26
|
// The static prefix serves to really emphasize that this is *NOT* just a uuid
|
|
27
|
-
return `key${GLUE}${
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
return `key${GLUE}${
|
|
28
|
+
this.parentStateIdCache.getOptionalKeyId(
|
|
29
|
+
parent,
|
|
30
|
+
)
|
|
31
|
+
}${GLUE}${placeholderName}${id}${GLUE}${this.markerIdCache.getId(container)}`
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
public static getRealmKey(id: RuntimeId, blueprint: EntityRealmBlueprint): EntityRealmKey {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ReceivedDataTree,
|
|
3
|
-
ReceivedEntityData,
|
|
4
|
-
ServerId,
|
|
5
|
-
} from '@contember/binding-common'
|
|
1
|
+
import { ReceivedDataTree, ReceivedEntityData, ServerId } from '@contember/binding-common'
|
|
6
2
|
import { BindingError } from '@contember/binding-common'
|
|
7
3
|
import { PRIMARY_KEY_NAME } from '@contember/binding-common'
|
|
8
4
|
import { EntityId } from '@contember/binding-common'
|
|
@@ -60,7 +56,6 @@ export class RequestResponseNormalizer {
|
|
|
60
56
|
newPersistedData: ReceivedDataTree,
|
|
61
57
|
operations: SubMutationOperation[],
|
|
62
58
|
): void {
|
|
63
|
-
|
|
64
59
|
const { subTreeDataStore, persistedEntityDataStore } = original
|
|
65
60
|
|
|
66
61
|
for (const operation of operations) {
|
|
@@ -85,7 +80,7 @@ export class RequestResponseNormalizer {
|
|
|
85
80
|
|
|
86
81
|
if (list instanceof Set) {
|
|
87
82
|
// TODO this is somewhat dubious because we're essentially just guessing the order of the entities
|
|
88
|
-
//
|
|
83
|
+
// and just carelessly put the new one at the end.
|
|
89
84
|
list.add(id.value)
|
|
90
85
|
} else if (list === undefined) {
|
|
91
86
|
// That's fine. This is probably just an isCreating sub-tree.
|
|
@@ -99,7 +94,7 @@ export class RequestResponseNormalizer {
|
|
|
99
94
|
} else if (operation.type === 'delete') {
|
|
100
95
|
const id = this.extractId(receivedData)
|
|
101
96
|
// TODO there are potentially some references to entityId that this whole process won't quite remove.
|
|
102
|
-
//
|
|
97
|
+
// That's a memory leak. Probably not particularly severe in most cases but still.
|
|
103
98
|
persistedEntityDataStore.delete(id.uniqueValue)
|
|
104
99
|
if (subTreeType === 'single') {
|
|
105
100
|
subTreeDataStore.delete(subTreePlaceholder)
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { BatchUpdatesOptions, EntityAccessor, FieldAccessor } from '@contember/binding-common'
|
|
2
|
-
import {
|
|
2
|
+
import { RuntimeId, ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'
|
|
3
3
|
import { BindingError } from '@contember/binding-common'
|
|
4
|
-
import {
|
|
5
|
-
EntityListSubTreeMarker,
|
|
6
|
-
EntitySubTreeMarker,
|
|
7
|
-
FieldMarker,
|
|
8
|
-
HasManyRelationMarker,
|
|
9
|
-
HasOneRelationMarker,
|
|
10
|
-
} from '@contember/binding-common'
|
|
4
|
+
import { EntityListSubTreeMarker, EntitySubTreeMarker, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'
|
|
11
5
|
import { BijectiveIndexedMap } from '@contember/utilities'
|
|
12
6
|
import type {
|
|
13
7
|
EntityEventListenerStore,
|
|
@@ -137,7 +131,7 @@ export class StateInitializer {
|
|
|
137
131
|
this.initializeFromHasManyRelationMarker(realm, field, new Set(value.children.keys()))
|
|
138
132
|
} else if (field instanceof HasOneRelationMarker) {
|
|
139
133
|
let runtimeId: RuntimeId
|
|
140
|
-
let subCopyFrom: EntityRealmState | undefined
|
|
134
|
+
let subCopyFrom: EntityRealmState | undefined
|
|
141
135
|
if (pathBack?.fieldBackToParent === field.parameters.field && !field.parameters.reducedBy) {
|
|
142
136
|
runtimeId = pathBack.parent.entity.id
|
|
143
137
|
} else {
|
|
@@ -190,12 +184,11 @@ export class StateInitializer {
|
|
|
190
184
|
entity.id,
|
|
191
185
|
entityRealm.realmKey,
|
|
192
186
|
entity.entityName,
|
|
193
|
-
|
|
194
187
|
// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and
|
|
195
188
|
// keep in sync two copies of the same data. TS hides the extra info anyway.
|
|
196
189
|
entityRealm.children,
|
|
197
190
|
this.treeStore.persistedEntityData.get(entity.id.uniqueValue),
|
|
198
|
-
entityRealm.unpersistedChangesCount !== 0,
|
|
191
|
+
entityRealm.unpersistedChangesCount !== 0 || this.hasConnectionChangedFromPersisted(entityRealm),
|
|
199
192
|
entityRealm.errors,
|
|
200
193
|
getEntityMarker(entityRealm).environment,
|
|
201
194
|
entityRealm.getAccessor,
|
|
@@ -207,6 +200,29 @@ export class StateInitializer {
|
|
|
207
200
|
return entityRealm
|
|
208
201
|
}
|
|
209
202
|
|
|
203
|
+
private hasConnectionChangedFromPersisted(entityRealm: EntityRealmState): boolean {
|
|
204
|
+
if (entityRealm.blueprint.type !== 'hasOne') {
|
|
205
|
+
return false
|
|
206
|
+
}
|
|
207
|
+
const parentState = entityRealm.blueprint.parent
|
|
208
|
+
const parentPersistedData = this.treeStore.persistedEntityData.get(parentState.entity.id.uniqueValue)
|
|
209
|
+
if (!parentPersistedData) {
|
|
210
|
+
return false
|
|
211
|
+
}
|
|
212
|
+
const persistedField = parentPersistedData.get(entityRealm.blueprint.marker.placeholderName)
|
|
213
|
+
if (persistedField === undefined) {
|
|
214
|
+
return false
|
|
215
|
+
}
|
|
216
|
+
const persistedValue = persistedField.value
|
|
217
|
+
if (persistedValue instanceof ServerId) {
|
|
218
|
+
return persistedValue.value !== entityRealm.entity.id.value
|
|
219
|
+
}
|
|
220
|
+
if (persistedValue === null) {
|
|
221
|
+
return entityRealm.entity.id.existsOnServer
|
|
222
|
+
}
|
|
223
|
+
return false
|
|
224
|
+
}
|
|
225
|
+
|
|
210
226
|
private materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {
|
|
211
227
|
if (state.type === 'entityRealm') {
|
|
212
228
|
return state
|
|
@@ -332,10 +348,9 @@ export class StateInitializer {
|
|
|
332
348
|
},
|
|
333
349
|
}
|
|
334
350
|
|
|
335
|
-
const initialData: Iterable<EntityId | undefined> =
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
: initialEntityIds
|
|
351
|
+
const initialData: Iterable<EntityId | undefined> = initialEntityIds.size === 0
|
|
352
|
+
? Array.from({ length: blueprint.marker.parameters.initialEntityCount })
|
|
353
|
+
: initialEntityIds
|
|
339
354
|
for (const entityId of initialData) {
|
|
340
355
|
this.initializeEntityRealm(
|
|
341
356
|
entityId ? new ServerId(entityId, entityName) : new UnpersistedEntityDummyId(),
|
|
@@ -408,14 +423,14 @@ export class StateInitializer {
|
|
|
408
423
|
) {
|
|
409
424
|
if (persistedValue instanceof Set) {
|
|
410
425
|
throw new BindingError(
|
|
411
|
-
`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. `
|
|
412
|
-
`Perhaps you wanted to use a <Repeater />?`,
|
|
426
|
+
`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. `
|
|
427
|
+
+ `Perhaps you wanted to use a <Repeater />?`,
|
|
413
428
|
)
|
|
414
429
|
}
|
|
415
430
|
if (persistedValue instanceof ServerId) {
|
|
416
431
|
throw new BindingError(
|
|
417
|
-
`Received a referenced entity where a single '${field.fieldName}' field was expected. `
|
|
418
|
-
`Perhaps you wanted to use <HasOne />?`,
|
|
432
|
+
`Received a referenced entity where a single '${field.fieldName}' field was expected. `
|
|
433
|
+
+ `Perhaps you wanted to use <HasOne />?`,
|
|
419
434
|
)
|
|
420
435
|
}
|
|
421
436
|
parent.children.set(
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClientGeneratedUuid,
|
|
3
|
-
HasOneRelationMarker,
|
|
4
|
-
ReceivedDataTree,
|
|
5
|
-
RuntimeId,
|
|
6
|
-
ServerId,
|
|
7
|
-
UnpersistedEntityDummyId,
|
|
8
|
-
} from '@contember/binding-common'
|
|
1
|
+
import { ClientGeneratedUuid, HasOneRelationMarker, ReceivedDataTree, RuntimeId, ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'
|
|
9
2
|
import { BindingError } from '@contember/binding-common'
|
|
10
3
|
import type { MarkerTreeRoot } from '@contember/binding-common'
|
|
11
4
|
import type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'
|
|
@@ -142,7 +135,7 @@ export class TreeAugmenter {
|
|
|
142
135
|
newId: ServerId | undefined | null,
|
|
143
136
|
) {
|
|
144
137
|
const currentId = realm.entity.id
|
|
145
|
-
let idToChangeTo: RuntimeId | undefined
|
|
138
|
+
let idToChangeTo: RuntimeId | undefined
|
|
146
139
|
|
|
147
140
|
if (currentId instanceof ServerId) {
|
|
148
141
|
if (newId === undefined || newId === null) {
|
|
@@ -227,14 +220,14 @@ export class TreeAugmenter {
|
|
|
227
220
|
if (
|
|
228
221
|
// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side
|
|
229
222
|
// id generation didn't quite pan out.
|
|
230
|
-
childRuntimeId instanceof ServerId
|
|
231
|
-
childRuntimeId instanceof ClientGeneratedUuid
|
|
223
|
+
childRuntimeId instanceof ServerId
|
|
224
|
+
|| childRuntimeId instanceof ClientGeneratedUuid
|
|
232
225
|
// No persisted entity id to allocate to this so that's a goodbye.
|
|
233
|
-
persistedWithoutState.size === 0
|
|
226
|
+
|| persistedWithoutState.size === 0
|
|
234
227
|
// not a persisted entity
|
|
235
|
-
child.type === 'entityRealmStub'
|
|
228
|
+
|| child.type === 'entityRealmStub'
|
|
236
229
|
// We couldn't find a matching persisted entity
|
|
237
|
-
!this.tryAssignIdToMatching(child, persistedWithoutState)
|
|
230
|
+
|| !this.tryAssignIdToMatching(child, persistedWithoutState)
|
|
238
231
|
) {
|
|
239
232
|
state.getAccessor().disconnectEntity(child.getAccessor())
|
|
240
233
|
continue
|
|
@@ -330,7 +323,7 @@ export class TreeAugmenter {
|
|
|
330
323
|
if (childData !== undefined && !(childData instanceof Set)) {
|
|
331
324
|
throw new BindingError()
|
|
332
325
|
}
|
|
333
|
-
if (!childData){
|
|
326
|
+
if (!childData) {
|
|
334
327
|
break
|
|
335
328
|
}
|
|
336
329
|
if (childData?.size !== child.children.size) {
|
package/src/core/TreeStore.ts
CHANGED
|
@@ -63,8 +63,9 @@ export class TreeStore {
|
|
|
63
63
|
| {
|
|
64
64
|
fieldBackToParent: FieldName
|
|
65
65
|
parent: EntityRealmState
|
|
66
|
-
|
|
67
|
-
| undefined
|
|
66
|
+
}
|
|
67
|
+
| undefined
|
|
68
|
+
{
|
|
68
69
|
const blueprint = entityRealm.blueprint
|
|
69
70
|
if (blueprint.parent === undefined) {
|
|
70
71
|
return undefined
|
|
@@ -153,7 +154,7 @@ export class TreeStore {
|
|
|
153
154
|
? QueryLanguage.desugarUnconstrainedQualifiedEntityList(
|
|
154
155
|
aliasOrParameters as SugaredUnconstrainedQualifiedEntityList,
|
|
155
156
|
environment,
|
|
156
|
-
|
|
157
|
+
)
|
|
157
158
|
: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),
|
|
158
159
|
environment,
|
|
159
160
|
)
|
|
@@ -163,7 +164,7 @@ export class TreeStore {
|
|
|
163
164
|
? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(
|
|
164
165
|
aliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,
|
|
165
166
|
environment,
|
|
166
|
-
|
|
167
|
+
)
|
|
167
168
|
: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),
|
|
168
169
|
environment,
|
|
169
170
|
)
|