@contember/binding-legacy 2.0.0-alpha.19 → 2.0.0-alpha.20
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/src/core/DataBinding.cjs +0 -5
- package/dist/development/src/core/DataBinding.cjs.map +1 -1
- package/dist/development/src/core/DataBinding.js +0 -5
- package/dist/development/src/core/DataBinding.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs +7 -8
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js +7 -8
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/QueryGenerator.cjs +9 -13
- package/dist/development/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/development/src/core/QueryGenerator.js +9 -13
- package/dist/development/src/core/QueryGenerator.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs +152 -12
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/development/src/core/TreeAugmenter.js +153 -13
- package/dist/development/src/core/TreeAugmenter.js.map +1 -1
- package/dist/production/src/core/DataBinding.cjs +0 -5
- package/dist/production/src/core/DataBinding.cjs.map +1 -1
- package/dist/production/src/core/DataBinding.js +0 -5
- package/dist/production/src/core/DataBinding.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs +7 -8
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js +7 -8
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/QueryGenerator.cjs +9 -13
- package/dist/production/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/production/src/core/QueryGenerator.js +9 -13
- package/dist/production/src/core/QueryGenerator.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs +152 -12
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/production/src/core/TreeAugmenter.js +153 -13
- package/dist/production/src/core/TreeAugmenter.js.map +1 -1
- package/dist/types/core/DataBinding.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/TreeAugmenter.d.ts +3 -0
- package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/core/DataBinding.ts +1 -6
- package/src/core/MutationGenerator.ts +8 -9
- package/src/core/QueryGenerator.ts +10 -14
- package/src/core/TreeAugmenter.ts +165 -15
- package/dist/development/src/core/TreeFilterGenerator.cjs +0 -79
- package/dist/development/src/core/TreeFilterGenerator.cjs.map +0 -1
- package/dist/development/src/core/TreeFilterGenerator.js +0 -79
- package/dist/development/src/core/TreeFilterGenerator.js.map +0 -1
- package/dist/production/src/core/TreeFilterGenerator.cjs +0 -79
- package/dist/production/src/core/TreeFilterGenerator.cjs.map +0 -1
- package/dist/production/src/core/TreeFilterGenerator.js +0 -79
- package/dist/production/src/core/TreeFilterGenerator.js.map +0 -1
- package/dist/types/core/TreeFilterGenerator.d.ts +0 -13
- package/dist/types/core/TreeFilterGenerator.d.ts.map +0 -1
- package/src/core/TreeFilterGenerator.ts +0 -117
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { MarkerTreeRoot } from '@contember/binding-common'\nimport type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { EntityListPersistedData } from '../accessorTree'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity list root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity realm root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":["ServerId","assertNever","BindingError","EventManager","OperationsHelpers","UnpersistedEntityDummyId","ClientGeneratedUuid"],"mappings":";;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;A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eAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tHasOneRelationMarker,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { MarkerTreeRoot } from '@contember/binding-common'\nimport type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { EntityListPersistedData } from '../accessorTree'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity list root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity realm root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState = new Set<EntityId>()\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.add(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.size === 0 ||\n\t\t\t\t\t// not a persisted entity\n\t\t\t\t\tchild.type === 'entityRealmStub' ||\n\t\t\t\t\t// We couldn't find a matching persisted entity\n\t\t\t\t\t!this.tryAssignIdToMatching(child, persistedWithoutState)\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n\n\tprivate tryAssignIdToMatching(realm: EntityRealmState, ids: Set<EntityId>) {\n\t\tfor (const candidateId of ids) {\n\t\t\tif (this.isEntityMatching(realm, candidateId)) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\trealm,\n\t\t\t\t\tnew ServerId(candidateId, realm.entity.entityName),\n\t\t\t\t)\n\t\t\t\tids.delete(candidateId)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate isEntityMatching(realm: EntityRealmState, id: EntityId) {\n\t\tconst uniqueId = ServerId.formatUniqueValue(id, realm.entity.entityName)\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(uniqueId)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst value = child.value ?? child.fieldMarker.defaultValue ?? null\n\t\t\t\t\tif (value !== null && childData !== value) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (child.entity.id.existsOnServer || child.entity.id instanceof ClientGeneratedUuid) {\n\t\t\t\t\t\tif (child.entity.id.value !== childData?.value) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (childData) {\n\t\t\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (child.type !== 'entityRealm' || !this.isEntityMatching(child, childData.value)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (child.type === 'entityRealmStub') {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (!childData){\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tif (childData?.size !== child.children.size) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tconst remainingIds = new Set(childData)\n\n\t\t\t\t\t// first check items with known ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif ((childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid)) {\n\t\t\t\t\t\t\tif (!childData.has(childItem.entity.id.value)) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tremainingIds.delete(childItem.entity.id.value)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// then check items with unknown ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif (!(childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) && childItem.type === 'entityRealm') {\n\t\t\t\t\t\t\tlet hasMatch = false\n\t\t\t\t\t\t\tfor (const id of remainingIds) {\n\t\t\t\t\t\t\t\tif (this.isEntityMatching(childItem, id)) {\n\t\t\t\t\t\t\t\t\tremainingIds.delete(id)\n\t\t\t\t\t\t\t\t\thasMatch = true\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!hasMatch) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (remainingIds.size !== 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tprivate isEmptyEntity(entity: EntityRealmState) {\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entity)\n\t\tfor (const [placeholderName, child] of entity.children) {\n\t\t\tif (child.type === 'field') {\n\t\t\t\tif (child.fieldMarker.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif ((child.value !== null || child.fieldMarker.defaultValue !== null)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityRealm') {\n\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\tconst isNonBearing = marker.parameters.isNonbearing\n\t\t\t\tif (isNonBearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityList') {\n\t\t\t\tif (child.blueprint.marker.parameters.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\tif (childItem.type === 'entityRealm' && !this.isEmptyEntity(childItem)) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["ServerId","assertNever","BindingError","EventManager","OperationsHelpers","UnpersistedEntityDummyId","ClientGeneratedUuid","getEntityMarker","HasOneRelationMarker","id"],"mappings":";;;;;;AAoBO,MAA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AAO,WAAW,cAAc;AACnD;AAAA,QACD;AACA,mBAAW,aAAa,MAAM,SAAS,OAAA,GAAU;AAChD,cAAI,UAAU,SAAS,iBAAiB,CAAC,KAAK,cAAc,SAAS,GAAG;AAChE,mBAAA;AAAA,UACR;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ServerId, assertNever, BindingError, UnpersistedEntityDummyId, ClientGeneratedUuid } from "@contember/binding-common";
|
|
1
|
+
import { ServerId, assertNever, BindingError, UnpersistedEntityDummyId, ClientGeneratedUuid, HasOneRelationMarker } from "@contember/binding-common";
|
|
2
2
|
import { EventManager } from "./EventManager.js";
|
|
3
3
|
import { OperationsHelpers } from "./operations/OperationsHelpers.js";
|
|
4
|
+
import { getEntityMarker } from "./state/getEntityMarker.js";
|
|
4
5
|
class TreeAugmenter {
|
|
5
6
|
constructor(eventManager, stateInitializer, treeStore, skipStateUpdateAfterPersist = false) {
|
|
6
7
|
this.eventManager = eventManager;
|
|
@@ -159,10 +160,10 @@ class TreeAugmenter {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
updateEntityListPersistedData(state, newPersistedIds) {
|
|
162
|
-
const persistedWithoutState =
|
|
163
|
+
const persistedWithoutState = /* @__PURE__ */ new Set();
|
|
163
164
|
for (const persistedId of newPersistedIds) {
|
|
164
165
|
if (!state.children.has(persistedId)) {
|
|
165
|
-
persistedWithoutState.
|
|
166
|
+
persistedWithoutState.add(persistedId);
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
169
|
for (const [stateId, child] of state.children) {
|
|
@@ -172,19 +173,12 @@ class TreeAugmenter {
|
|
|
172
173
|
// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side
|
|
173
174
|
// id generation didn't quite pan out.
|
|
174
175
|
childRuntimeId instanceof ServerId || childRuntimeId instanceof ClientGeneratedUuid || // No persisted entity id to allocate to this so that's a goodbye.
|
|
175
|
-
persistedWithoutState.
|
|
176
|
+
persistedWithoutState.size === 0 || // not a persisted entity
|
|
177
|
+
child.type === "entityRealmStub" || // We couldn't find a matching persisted entity
|
|
178
|
+
!this.tryAssignIdToMatching(child, persistedWithoutState)
|
|
176
179
|
) {
|
|
177
180
|
state.getAccessor().disconnectEntity(child.getAccessor());
|
|
178
181
|
continue;
|
|
179
|
-
} else {
|
|
180
|
-
const drawnId = persistedWithoutState.shift();
|
|
181
|
-
OperationsHelpers.changeRealmId(
|
|
182
|
-
this.treeStore,
|
|
183
|
-
this.eventManager,
|
|
184
|
-
this.stateInitializer,
|
|
185
|
-
child,
|
|
186
|
-
new ServerId(drawnId, child.entity.entityName)
|
|
187
|
-
);
|
|
188
182
|
}
|
|
189
183
|
} else if (childRuntimeId instanceof ClientGeneratedUuid) {
|
|
190
184
|
OperationsHelpers.changeRealmId(
|
|
@@ -207,6 +201,152 @@ class TreeAugmenter {
|
|
|
207
201
|
}
|
|
208
202
|
state.children.changeKeyOrder(newPersistedIds);
|
|
209
203
|
}
|
|
204
|
+
tryAssignIdToMatching(realm, ids) {
|
|
205
|
+
for (const candidateId of ids) {
|
|
206
|
+
if (this.isEntityMatching(realm, candidateId)) {
|
|
207
|
+
OperationsHelpers.changeRealmId(
|
|
208
|
+
this.treeStore,
|
|
209
|
+
this.eventManager,
|
|
210
|
+
this.stateInitializer,
|
|
211
|
+
realm,
|
|
212
|
+
new ServerId(candidateId, realm.entity.entityName)
|
|
213
|
+
);
|
|
214
|
+
ids.delete(candidateId);
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
isEntityMatching(realm, id) {
|
|
221
|
+
const uniqueId = ServerId.formatUniqueValue(id, realm.entity.entityName);
|
|
222
|
+
const persistedData = this.treeStore.persistedEntityData.get(uniqueId);
|
|
223
|
+
const pathBack = this.treeStore.getPathBackToParent(realm);
|
|
224
|
+
for (const [placeholderName, child] of realm.children) {
|
|
225
|
+
const childData = persistedData?.get(placeholderName);
|
|
226
|
+
switch (child.type) {
|
|
227
|
+
case "field": {
|
|
228
|
+
if (childData instanceof ServerId || childData instanceof Set) {
|
|
229
|
+
throw new BindingError();
|
|
230
|
+
}
|
|
231
|
+
const value = child.value ?? child.fieldMarker.defaultValue ?? null;
|
|
232
|
+
if (value !== null && childData !== value) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "entityRealm":
|
|
238
|
+
case "entityRealmStub": {
|
|
239
|
+
if (!(childData instanceof ServerId) && childData !== void 0 && childData !== null) {
|
|
240
|
+
throw new BindingError();
|
|
241
|
+
}
|
|
242
|
+
if (child.entity.id.existsOnServer || child.entity.id instanceof ClientGeneratedUuid) {
|
|
243
|
+
if (child.entity.id.value !== childData?.value) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
} else if (childData) {
|
|
247
|
+
const marker = getEntityMarker(child);
|
|
248
|
+
if (!(marker instanceof HasOneRelationMarker)) {
|
|
249
|
+
throw new BindingError();
|
|
250
|
+
}
|
|
251
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (child.type !== "entityRealm" || !this.isEntityMatching(child, childData.value)) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
} else if (child.type === "entityRealmStub") {
|
|
258
|
+
break;
|
|
259
|
+
} else {
|
|
260
|
+
if (!this.isEmptyEntity(child)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case "entityList": {
|
|
267
|
+
if (childData !== void 0 && !(childData instanceof Set)) {
|
|
268
|
+
throw new BindingError();
|
|
269
|
+
}
|
|
270
|
+
if (!childData) {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
if (childData?.size !== child.children.size) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const remainingIds = new Set(childData);
|
|
277
|
+
for (const childItem of child.children.values()) {
|
|
278
|
+
if (childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) {
|
|
279
|
+
if (!childData.has(childItem.entity.id.value)) {
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
remainingIds.delete(childItem.entity.id.value);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
for (const childItem of child.children.values()) {
|
|
286
|
+
if (!(childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) && childItem.type === "entityRealm") {
|
|
287
|
+
let hasMatch = false;
|
|
288
|
+
for (const id2 of remainingIds) {
|
|
289
|
+
if (this.isEntityMatching(childItem, id2)) {
|
|
290
|
+
remainingIds.delete(id2);
|
|
291
|
+
hasMatch = true;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if (!hasMatch) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (remainingIds.size !== 0) {
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
break;
|
|
304
|
+
}
|
|
305
|
+
default: {
|
|
306
|
+
return assertNever(child);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
isEmptyEntity(entity) {
|
|
313
|
+
const pathBack = this.treeStore.getPathBackToParent(entity);
|
|
314
|
+
for (const [placeholderName, child] of entity.children) {
|
|
315
|
+
if (child.type === "field") {
|
|
316
|
+
if (child.fieldMarker.isNonbearing) {
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
if (child.value !== null || child.fieldMarker.defaultValue !== null) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
} else if (child.type === "entityRealm") {
|
|
323
|
+
const marker = getEntityMarker(child);
|
|
324
|
+
const isNonBearing = marker.parameters.isNonbearing;
|
|
325
|
+
if (isNonBearing) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (!(marker instanceof HasOneRelationMarker)) {
|
|
329
|
+
throw new BindingError();
|
|
330
|
+
}
|
|
331
|
+
if (pathBack?.fieldBackToParent === marker.parameters.field) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (!this.isEmptyEntity(child)) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
} else if (child.type === "entityList") {
|
|
338
|
+
if (child.blueprint.marker.parameters.isNonbearing) {
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
for (const childItem of child.children.values()) {
|
|
342
|
+
if (childItem.type === "entityRealm" && !this.isEmptyEntity(childItem)) {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
210
350
|
}
|
|
211
351
|
export {
|
|
212
352
|
TreeAugmenter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.js","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { MarkerTreeRoot } from '@contember/binding-common'\nimport type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { EntityListPersistedData } from '../accessorTree'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity list root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity realm root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAC3D,QAAI,KAAK,6BAA6B;AACrC;AAAA,IACD;AACK,SAAA,aAAa,gBAAgB,M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AA0B;AAAA,UAE1B,sBAAsB,WAAW;AAAA,UAChC;AACD,gBAAM,YAAY,EAAE,iBAAiB,MAAM,YAAa,CAAA;AACxD;AAAA,QAAA,OACM;AACA,gBAAA,UAAU,sBAAsB;AACpB,4BAAA;AAAA,YACjB,KAAK;AAAA,YACL,KAAK;AAAA,YACL,KAAK;AAAA,YACL;AAAA,YACA,IAAI,SAAS,SAAS,MAAM,OAAO,UAAU;AAAA,UAAA;AAAA,QAE/C;AAAA,MAAA,WACU,0BAA0B,qBAAqB;AACvC,0BAAA;AAAA,UACjB,KAAK;AAAA,UACL,KAAK;AAAA,UACL,KAAK;AAAA,UACL;AAAA,UACA,IAAI,SAAS,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.js","sources":["../../../../../packages/binding-legacy/src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tHasOneRelationMarker,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { MarkerTreeRoot } from '@contember/binding-common'\nimport type { EntityId, PlaceholderName, TreeRootId } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { EntityListPersistedData } from '../accessorTree'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity list root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tif (rootState.blueprint.parent !== undefined) {\n\t\t\t\t\t\tthrow new BindingError('Entity realm root should not have a parent.')\n\t\t\t\t\t}\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState = new Set<EntityId>()\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.add(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.size === 0 ||\n\t\t\t\t\t// not a persisted entity\n\t\t\t\t\tchild.type === 'entityRealmStub' ||\n\t\t\t\t\t// We couldn't find a matching persisted entity\n\t\t\t\t\t!this.tryAssignIdToMatching(child, persistedWithoutState)\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n\n\tprivate tryAssignIdToMatching(realm: EntityRealmState, ids: Set<EntityId>) {\n\t\tfor (const candidateId of ids) {\n\t\t\tif (this.isEntityMatching(realm, candidateId)) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\trealm,\n\t\t\t\t\tnew ServerId(candidateId, realm.entity.entityName),\n\t\t\t\t)\n\t\t\t\tids.delete(candidateId)\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tprivate isEntityMatching(realm: EntityRealmState, id: EntityId) {\n\t\tconst uniqueId = ServerId.formatUniqueValue(id, realm.entity.entityName)\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(uniqueId)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst value = child.value ?? child.fieldMarker.defaultValue ?? null\n\t\t\t\t\tif (value !== null && childData !== value) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (child.entity.id.existsOnServer || child.entity.id instanceof ClientGeneratedUuid) {\n\t\t\t\t\t\tif (child.entity.id.value !== childData?.value) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (childData) {\n\t\t\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (child.type !== 'entityRealm' || !this.isEntityMatching(child, childData.value)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (child.type === 'entityRealmStub') {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (!childData){\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tif (childData?.size !== child.children.size) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tconst remainingIds = new Set(childData)\n\n\t\t\t\t\t// first check items with known ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif ((childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid)) {\n\t\t\t\t\t\t\tif (!childData.has(childItem.entity.id.value)) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tremainingIds.delete(childItem.entity.id.value)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// then check items with unknown ids\n\t\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\t\tif (!(childItem.entity.id.existsOnServer || childItem.entity.id instanceof ClientGeneratedUuid) && childItem.type === 'entityRealm') {\n\t\t\t\t\t\t\tlet hasMatch = false\n\t\t\t\t\t\t\tfor (const id of remainingIds) {\n\t\t\t\t\t\t\t\tif (this.isEntityMatching(childItem, id)) {\n\t\t\t\t\t\t\t\t\tremainingIds.delete(id)\n\t\t\t\t\t\t\t\t\thasMatch = true\n\t\t\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!hasMatch) {\n\t\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (remainingIds.size !== 0) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\tprivate isEmptyEntity(entity: EntityRealmState) {\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entity)\n\t\tfor (const [placeholderName, child] of entity.children) {\n\t\t\tif (child.type === 'field') {\n\t\t\t\tif (child.fieldMarker.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif ((child.value !== null || child.fieldMarker.defaultValue !== null)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityRealm') {\n\t\t\t\tconst marker = getEntityMarker(child)\n\t\t\t\tconst isNonBearing = marker.parameters.isNonbearing\n\t\t\t\tif (isNonBearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (!this.isEmptyEntity(child)) {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t} else if (child.type === 'entityList') {\n\t\t\t\tif (child.blueprint.marker.parameters.isNonbearing) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tfor (const childItem of child.children.values()) {\n\t\t\t\t\tif (childItem.type === 'entityRealm' && !this.isEmptyEntity(childItem)) {\n\t\t\t\t\t\treturn false\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["id"],"mappings":";;;;AAoBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WACA,8BAAuC,OACvD;AAJgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AACA,SAAA,8BAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB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AAU,QAAQ,MAAM,YAAY,iBAAiB,MAAO;AAC/D,iBAAA;AAAA,QACR;AAAA,MAAA,WACU,MAAM,SAAS,eAAe;AAClC,cAAA,SAAS,gBAAgB,KAAK;AAC9B,cAAA,eAAe,OAAO,WAAW;AACvC,YAAI,cAAc;AACjB;AAAA,QACD;AAEI,YAAA,EAAE,kBAAkB,uBAAuB;AAC9C,gBAAM,IAAI,aAAa;AAAA,QACxB;AACA,YAAI,UAAU,sBAAsB,OAAO,WAAW,OAAO;AAC5D;AAAA,QACD;AACA,YAAI,CAAC,KAAK,cAAc,KAAK,GAAG;AACxB,iBAAA;AAAA,QACR;AAAA,MAAA,WACU,MAAM,SAAS,cAAc;AACvC,YAAI,MAAM,UAAU,OAAO,WAAW,cAAc;AACnD;AAAA,QACD;AACA,mBAAW,aAAa,MAAM,SAAS,OAAA,GAAU;AAChD,cAAI,UAAU,SAAS,iBAAiB,CAAC,KAAK,cAAc,SAAS,GAAG;AAChE,mBAAA;AAAA,UACR;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.d.ts","sourceRoot":"","sources":["../../../src/core/DataBinding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,aAAa,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"DataBinding.d.ts","sourceRoot":"","sources":["../../../src/core/DataBinding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACzG,OAAO,KAAK,EAA0C,WAAW,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAChI,OAAO,EAMN,iBAAiB,EAIjB,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EAChB,MAAM,2BAA2B,CAAA;AAYlC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAOvC,qBAAa,WAAW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,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,EAC/E,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,EACxE,gBAAgB,EAAE,CAAC,MAAM,EAAE,uBAAuB,EAAE,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,KAAK,IAAI,EACvF,OAAO,EAAE;QACzB,2BAA2B,EAAE,OAAO,CAAA;KACpC;YA2CY,OAAO;YAmEP,wBAAwB;YAYxB,2BAA2B;YAU3B,8BAA8B;IAyC5C,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,gBAAgB,CAEvB;IAOD,OAAO,CAAC,iBAAiB,CAOX;IAED,UAAU,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAuC/F,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAC9G,IAAI,EAAE,gBAAgB,CAAA;QACtB,cAAc,EAAE,cAAc,CAAA;KAC9B,GAAG,SAAS,CAAC;YAaA,0BAA0B;YA4C1B,kBAAkB;IAyBhC,OAAO,CAAC,+BAA+B;IAuCvC,OAAO,CAAC,MAAM,CAAC,qBAAqB,CAGhC;IAEJ,OAAO,CAAC,gBAAgB;CAOxB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationGenerator.d.ts","sourceRoot":"","sources":["../../../src/core/MutationGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"MutationGenerator.d.ts","sourceRoot":"","sources":["../../../src/core/M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BAAoB;IAyB5B,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,kBAAkB;IA0L1B,OAAO,CAAC,yBAAyB;IAgCjC,OAAO,CAAC,0BAA0B;IA2BlC,OAAO,CAAC,4BAA4B;IAUpC,OAAO,CAAC,kBAAkB;IAqG1B,OAAO,CAAC,yBAAyB;IAuEjC,OAAO,CAAC,oCAAoC;IAgF5C,OAAO,CAAC,0BAA0B;IAqElC,OAAO,CAAC,WAAW;CAGnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryGenerator.d.ts","sourceRoot":"","sources":["../../../src/core/QueryGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,kBAAkB,
|
|
1
|
+
{"version":3,"file":"QueryGenerator.d.ts","sourceRoot":"","sources":["../../../src/core/QueryGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,kBAAkB,EAMlB,cAAc,EAEd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAG7F,qBAAa,cAAc;IAEzB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,EAAE;gBADF,IAAI,EAAE,cAAc,EACpB,EAAE,EAAE,mBAAmB;IAGzB,YAAY,IAAI,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC;IAexD,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,eAAe;WAgBT,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,sBAAsB,GAAG,sBAAsB;CAuDtH"}
|
|
@@ -18,5 +18,8 @@ export declare class TreeAugmenter {
|
|
|
18
18
|
private updateRealmIdIfNecessary;
|
|
19
19
|
private updateEntityRealmPersistedData;
|
|
20
20
|
private updateEntityListPersistedData;
|
|
21
|
+
private tryAssignIdToMatching;
|
|
22
|
+
private isEntityMatching;
|
|
23
|
+
private isEmptyEntity;
|
|
21
24
|
}
|
|
22
25
|
//# sourceMappingURL=TreeAugmenter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeAugmenter.d.ts","sourceRoot":"","sources":["../../../src/core/TreeAugmenter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TreeAugmenter.d.ts","sourceRoot":"","sources":["../../../src/core/TreeAugmenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,gBAAgB,EAIhB,MAAM,2BAA2B,CAAA;AAElC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAA6B,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAG1D,qBAAa,aAAa;IAExB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,2BAA2B;gBAH3B,YAAY,EAAE,YAAY,EAC1B,gBAAgB,EAAE,gBAAgB,EAClC,SAAS,EAAE,SAAS,EACpB,2BAA2B,GAAE,OAAe;IAGvD,mBAAmB,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,cAAc;IAKlF,gBAAgB,CAAC,SAAS,EAAE,UAAU,GAAG,SAAS,EAAE,aAAa,EAAE,cAAc,GAAG,IAAI;IAYxF,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,UAAU,EAAE,oBAAoB,EAAE;IAsClF,qBAAqB;IAwD5B,OAAO,CAAC,wBAAwB;IA2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