@contember/binding-legacy 2.0.0-alpha.32 → 2.0.0-alpha.36
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/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.map +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.map +1 -1
- 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.map +1 -1
- package/dist/development/src/core/StateInitializer.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- 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/isEmptyObject.cjs.map +1 -1
- package/dist/development/src/utils/isEmptyObject.js.map +1 -1
- 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.map +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.map +1 -1
- 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.map +1 -1
- package/dist/production/src/core/StateInitializer.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- 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.map +1 -1
- 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.map +1 -1
- 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/isEmptyObject.cjs.map +1 -1
- package/dist/production/src/utils/isEmptyObject.js.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/tests/example.test.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeStore.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, SubTreeDataStore } from '../accessorTree'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tEnvironment,\n\tFieldName,\n\tPlaceholderName,\n\tReceivedDataTree,\n\tSchema,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n\tUniqueEntityId,\n} from '@contember/binding-common'\nimport { BindingError, MarkerComparator, MarkerTreeRoot, PlaceholderGenerator, QueryLanguage } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\tfieldBackToParent: FieldName\n\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["NormalizedPersistedData","RequestResponseNormalizer","assertNever","BindingError","PlaceholderGenerator","QueryLanguage","MarkerComparator"],"mappings":";;;;;;;;AAwBA,MAAM,uCAA8C;AAE7C,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAAA;AAXF,kBAAA,MAAA,mCAAoD,IAAI,CAAA;AACxD,kBAAA,MAAA,wCAAqF,IAAI,CAAA;AAIzF,kBAAA,MAAA,mCAA+D,IAAI,CAAA;AACnE,kBAAA,MAAA,2CAA4F,IAAI,CAAA;AAEhG,kBAAA,MAAA,iBAAyC,IAAIA,wBAAwB,wBAAA,oBAAI,OAAO,oBAAI,IAAK,CAAA,CAAA;AAAA,EAItG;AAAA,EAEI,qBAAqB,UAA4B,YAAkC;AACzFC,8BAAA,0BAA0B,qBAAqB,KAAK,eAAe,UAAU,UAAU;AAAA,EACxF;AAAA,EAEO,wBAAwB,UAA4B,YAA0C;AACpGA,8BAAA,0BAA0B,wBAAwB,KAAK,eAAe,UAAU,UAAU;AAAA,EAC3F;AAAA,EAEA,IAAW,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA,EAC3B;AAAA,EAEA,IAAW,uBAAyC;AACnD,WAAO,KAAK,cAAc;AA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gBAAQ,MAAM,MAAM;AAAA,UACnB,KAAK;AACJ;AAAA,UACD,KAAK;AAAA,UACL,KAAK,mBAAmB;AACvB,iBAAK,eAAe,KAAK;AACzB;AAAA,UACD;AAAA,UACA,KAAK,cAAc;AAClB,uBAAW,aAAa,MAAM,SAAS,OAAA,GAAU;AAChD,mBAAK,eAAe,SAAS;AAAA,YAC9B;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAS,iBAAiB;AAC5B,QAAA,OAAO,OAAO,SAAS,GAAG;AAC7B,WAAK,gBAAgB,MAAM;AAAA,IAC5B;AAAA,EACD;AAAA,EAEO,gBAAgB,QAAqB;AAC3C,eAAW,SAAS,OAAO,OAAO,OAAA,GAAU;AAC3C,WAAK,eAAe,KAAK;AAAA,IAC1B;AACA,SAAK,YAAY,OAAO,OAAO,GAAG,WAAW;AAC7C,SAAK,oBAAoB,OAAO,OAAO,GAAG,WAAW;AAAA,EACtD;AAAA,EAEO,uBAAuB,eAAwC;AACrE,mBAA2B,YAAA,oBAAoB,cAAc,SAAS,UAAU;AAC3E,UAAA,iBAAiB,WAAW,YAAY;AAE3C;AAAA,MACD;AACA,iBAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC7C,mBAAW,yBAAyB,KAAK,SAAS,OAAA,GAAU;AAC3D,gBAAM,WAAWG,cAAA,iBAAiB,kBAAkB,kBAAkB,qBAAqB;AAC3F,cAAI,UAAU;AACJ,qBAAA;AAAA,UACV;AAAA,QACD;AAAA,MACD;AACO,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AACD;;"}
|
|
1
|
+
{"version":3,"file":"TreeStore.cjs","sources":["../../../../../packages/binding-legacy/src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, SubTreeDataStore } from '../accessorTree'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tEnvironment,\n\tFieldName,\n\tPlaceholderName,\n\tReceivedDataTree,\n\tSchema,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n\tUniqueEntityId,\n} from '@contember/binding-common'\nimport { BindingError, MarkerComparator, MarkerTreeRoot, PlaceholderGenerator, QueryLanguage } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\tfieldBackToParent: FieldName\n\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":["NormalizedPersistedData","RequestResponseNormalizer","assertNever","BindingError","PlaceholderGenerator","QueryLanguage","MarkerComparator"],"mappings":";;;;;;;;AAwBA,MAAM,uCAA8C,IAAI;AAEjD,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAA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/C,uBAAuB,eAAwC;AACrE,mBAA2B,YAAA,oBAAoB,cAAc,SAAS,UAAU;AAC3E,UAAA,iBAAiB,WAAW,YAAY;AAE3C;AAAA,MAAA;AAED,iBAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC7C,mBAAW,yBAAyB,KAAK,SAAS,OAAA,GAAU;AAC3D,gBAAM,WAAWG,cAAA,iBAAiB,kBAAkB,kBAAkB,qBAAqB;AAC3F,cAAI,UAAU;AACJ,qBAAA;AAAA,UAAA;AAAA,QACV;AAAA,MACD;AAEM,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeStore.js","sources":["../../../../../packages/binding-legacy/src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, SubTreeDataStore } from '../accessorTree'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tEnvironment,\n\tFieldName,\n\tPlaceholderName,\n\tReceivedDataTree,\n\tSchema,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n\tUniqueEntityId,\n} from '@contember/binding-common'\nimport { BindingError, MarkerComparator, MarkerTreeRoot, PlaceholderGenerator, QueryLanguage } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\tfieldBackToParent: FieldName\n\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAwBA,MAAM,uCAA8C;AAE7C,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAAA;AAXF,kBAAA,MAAA,mCAAoD,IAAI,CAAA;AACxD,kBAAA,MAAA,wCAAqF,IAAI,CAAA;AAIzF,kBAAA,MAAA,mCAA+D,IAAI,CAAA;AACnE,kBAAA,MAAA,2CAA4F,IAAI,CAAA;AAEhG,kBAAA,MAAA,iBAAyC,IAAI,wBAAwB,oBAAI,OAAO,oBAAI,IAAK,CAAA,CAAA;AAAA,EAItG;AAAA,EAEI,qBAAqB,UAA4B,YAAkC;AACzF,8BAA0B,qBAAqB,KAAK,eAAe,UAAU,UAAU;AAAA,EACxF;AAAA,EAEO,wBAAwB,UAA4B,YAA0C;AACpG,8BAA0B,wBAAwB,KAAK,eAAe,UAAU,UAAU;AAAA,EAC3F;AAAA,EAEA,IAAW,sBAAgD;AAC1D,WAAO,KAAK,cAAc;AAAA,EAC3B;AAAA,EAEA,IAAW,uBAAyC;AACnD,WAAO,KAAK,cAAc;AAAA,EAC3B;AAAA,EAEA,IAAW,SAAiB;AAC3B,WAAO,KAAK;AAAA,EACb;AAAA,EAEO,oBAAoB,aAKd;AACZ,UA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SAAS,OAAA,GAAU;AAChD,mBAAK,eAAe,SAAS;AAAA,YAC9B;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,UAAM,SAAS,iBAAiB;AAC5B,QAAA,OAAO,OAAO,SAAS,GAAG;AAC7B,WAAK,gBAAgB,MAAM;AAAA,IAC5B;AAAA,EACD;AAAA,EAEO,gBAAgB,QAAqB;AAC3C,eAAW,SAAS,OAAO,OAAO,OAAA,GAAU;AAC3C,WAAK,eAAe,KAAK;AAAA,IAC1B;AACA,SAAK,YAAY,OAAO,OAAO,GAAG,WAAW;AAC7C,SAAK,oBAAoB,OAAO,OAAO,GAAG,WAAW;AAAA,EACtD;AAAA,EAEO,uBAAuB,eAAwC;AACrE,mBAA2B,YAAA,oBAAoB,cAAc,SAAS,UAAU;AAC3E,UAAA,iBAAiB,WAAW,YAAY;AAE3C;AAAA,MACD;AACA,iBAAW,QAAQ,KAAK,YAAY,OAAA,GAAU;AAC7C,mBAAW,yBAAyB,KAAK,SAAS,OAAA,GAAU;AAC3D,gBAAM,WAAW,iBAAiB,kBAAkB,kBAAkB,qBAAqB;AAC3F,cAAI,UAAU;AACJ,qBAAA;AAAA,UACV;AAAA,QACD;AAAA,MACD;AACO,aAAA;AAAA,IACR;AACO,WAAA;AAAA,EACR;AACD;"}
|
|
1
|
+
{"version":3,"file":"TreeStore.js","sources":["../../../../../packages/binding-legacy/src/core/TreeStore.ts"],"sourcesContent":["import { NormalizedPersistedData, PersistedEntityDataStore, SubTreeDataStore } from '../accessorTree'\nimport type {\n\tAlias,\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tEnvironment,\n\tFieldName,\n\tPlaceholderName,\n\tReceivedDataTree,\n\tSchema,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n\tUniqueEntityId,\n} from '@contember/binding-common'\nimport { BindingError, MarkerComparator, MarkerTreeRoot, PlaceholderGenerator, QueryLanguage } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { RequestResponseNormalizer } from './RequestResponseNormalizer'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, RootStateNode } from './state'\nimport { SubMutationOperation } from './MutationGenerator'\n\nconst emptyEntityIdSet: ReadonlySet<EntityId> = new Set()\n\nexport class TreeStore {\n\tpublic readonly entityStore: Map<UniqueEntityId, EntityState> = new Map()\n\tpublic readonly entityRealmStore: Map<EntityRealmKey, EntityRealmState | EntityRealmStateStub> = new Map()\n\n\t// This is tricky. We allow placeholder name duplicates, only the (TreeRootId, PlaceholderName) tuple is unique.\n\t// This is useful when the tree is extended to contain a sub-tree with the same placeholder.\n\tpublic readonly markerTrees: Map<TreeRootId | undefined, MarkerTreeRoot> = new Map()\n\tpublic readonly subTreeStatesByRoot: Map<TreeRootId | undefined, Map<PlaceholderName, RootStateNode>> = new Map()\n\n\tpublic readonly persistedData: NormalizedPersistedData = new NormalizedPersistedData(new Map(), new Map())\n\n\tpublic constructor(\n\t\tprivate readonly _schema: Schema,\n\t) {}\n\n\tpublic mergeInQueryResponse(response: ReceivedDataTree, markerTree: MarkerTreeRoot): void {\n\t\tRequestResponseNormalizer.mergeInQueryResponse(this.persistedData, response, markerTree)\n\t}\n\n\tpublic mergeInMutationResponse(response: ReceivedDataTree, operations: SubMutationOperation[]): void {\n\t\tRequestResponseNormalizer.mergeInMutationResponse(this.persistedData, response, operations)\n\t}\n\n\tpublic get persistedEntityData(): PersistedEntityDataStore {\n\t\treturn this.persistedData.persistedEntityDataStore\n\t}\n\n\tpublic get subTreePersistedData(): SubTreeDataStore {\n\t\treturn this.persistedData.subTreeDataStore\n\t}\n\n\tpublic get schema(): Schema {\n\t\treturn this._schema\n\t}\n\n\tpublic getPathBackToParent(entityRealm: EntityRealmState | EntityRealmStateStub):\n\t\t| {\n\t\t\tfieldBackToParent: FieldName\n\t\t\tparent: EntityRealmState\n\t\t }\n\t\t| undefined {\n\t\tconst blueprint = entityRealm.blueprint\n\t\tif (blueprint.parent === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tlet parentEntityName: EntityName\n\t\tlet relationFromParent: FieldName\n\t\tlet parent: EntityRealmState\n\n\t\tif (blueprint.type === 'hasOne') {\n\t\t\tparentEntityName = blueprint.parent.entity.entityName\n\t\t\trelationFromParent = blueprint.marker.parameters.field\n\t\t\tparent = blueprint.parent\n\t\t} else if (blueprint.type === 'listEntity') {\n\t\t\tconst grandparentBlueprint = blueprint.parent.blueprint\n\n\t\t\tif (grandparentBlueprint.parent === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tparentEntityName = grandparentBlueprint.parent.entity.entityName\n\t\t\trelationFromParent = grandparentBlueprint.marker.parameters.field\n\t\t\tparent = grandparentBlueprint.parent\n\t\t} else {\n\t\t\treturn assertNever(blueprint)\n\t\t}\n\n\t\tconst relationSchema = this.schema.getEntityRelation(parentEntityName, relationFromParent)\n\t\tconst fieldBack = (relationSchema.ownedBy || relationSchema.inversedBy) ?? null\n\n\t\t// console.log(parentEntityName, relationFromParent, entityRealm.entity.entityName, fieldBack)\n\t\tif (fieldBack === null) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tparent,\n\t\t\tfieldBackToParent: fieldBack,\n\t\t}\n\t}\n\n\tpublic getSubTreeState(\n\t\tmode: 'entity',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): EntityRealmState\n\tpublic getSubTreeState(\n\t\tmode: 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): EntityListState\n\tpublic getSubTreeState(\n\t\tmode: 'entity' | 'entityList',\n\t\ttreeRootId: TreeRootId | undefined,\n\t\taliasOrParameters:\n\t\t\t| Alias\n\t\t\t| SugaredQualifiedSingleEntity\n\t\t\t| SugaredUnconstrainedQualifiedSingleEntity\n\t\t\t| SugaredQualifiedEntityList\n\t\t\t| SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): RootStateNode {\n\t\tconst markerRoot = this.markerTrees.get(treeRootId)\n\t\tconst subTreeStates = this.subTreeStatesByRoot.get(treeRootId)\n\n\t\tif (subTreeStates === undefined || markerRoot === undefined) {\n\t\t\tif (treeRootId) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`Invalid tree id '${treeRootId}'. Make sure you use the one supplied by the correct extendTree call.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new BindingError(`Failed to retrieve a sub tree.`)\n\t\t}\n\n\t\tlet placeholderName: string\n\n\t\tif (typeof aliasOrParameters === 'string') {\n\t\t\tconst placeholderByAlias = markerRoot.placeholdersByAliases.get(aliasOrParameters)\n\n\t\t\tif (placeholderByAlias === undefined) {\n\t\t\t\tthrow new BindingError(`Undefined sub-tree alias '${aliasOrParameters}'.`)\n\t\t\t}\n\t\t\tplaceholderName = placeholderByAlias\n\t\t} else if (mode === 'entityList') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntityListSubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedEntityList(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedEntityList,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedEntityList(aliasOrParameters as SugaredQualifiedEntityList, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else if (mode === 'entity') {\n\t\t\tplaceholderName = PlaceholderGenerator.getEntitySubTreePlaceholder(\n\t\t\t\taliasOrParameters.isCreating\n\t\t\t\t\t? QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(\n\t\t\t\t\t\taliasOrParameters as SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\t\t\t\tenvironment,\n\t\t\t\t\t )\n\t\t\t\t\t: QueryLanguage.desugarQualifiedSingleEntity(aliasOrParameters as SugaredQualifiedSingleEntity, environment),\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tconst subTreeState = subTreeStates.get(placeholderName)\n\n\t\tif (subTreeState === undefined) {\n\t\t\tthrow new BindingError(`Trying to retrieve a non-existent sub-tree '${placeholderName}'.`)\n\t\t}\n\t\treturn subTreeState\n\t}\n\n\tpublic getEntityListPersistedIds(state: EntityListState): ReadonlySet<EntityId> {\n\t\tconst blueprint = state.blueprint\n\n\t\tif (blueprint.parent) {\n\t\t\tconst entityData = this.persistedEntityData.get(blueprint.parent.entity.id.uniqueValue)\n\t\t\treturn (entityData?.get(blueprint.marker.placeholderName) as Set<string> | undefined) ?? emptyEntityIdSet\n\t\t} else {\n\t\t\treturn (this.subTreePersistedData.get(blueprint.marker.placeholderName) as Set<string>) ?? emptyEntityIdSet\n\t\t}\n\t}\n\n\tpublic disposeOfRealm(realmToDisposeOf: EntityRealmState | EntityRealmStateStub) {\n\t\tthis.entityRealmStore.delete(realmToDisposeOf.realmKey)\n\t\trealmToDisposeOf.entity.realms.delete(realmToDisposeOf.realmKey)\n\n\t\tif (realmToDisposeOf.type === 'entityRealm') {\n\t\t\trealmToDisposeOf.blueprint.parent?.childrenWithPendingUpdates?.delete(realmToDisposeOf)\n\n\t\t\tfor (const child of realmToDisposeOf.children.values()) {\n\t\t\t\tswitch (child.type) {\n\t\t\t\t\tcase 'field':\n\t\t\t\t\t\tcontinue\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\t\tthis.disposeOfRealm(child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tfor (const listChild of child.children.values()) {\n\t\t\t\t\t\t\tthis.disposeOfRealm(listChild)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst entity = realmToDisposeOf.entity\n\t\tif (entity.realms.size === 0) {\n\t\t\tthis.disposeOfEntity(entity)\n\t\t}\n\t}\n\n\tpublic disposeOfEntity(entity: EntityState) {\n\t\tfor (const realm of entity.realms.values()) {\n\t\t\tthis.disposeOfRealm(realm)\n\t\t}\n\t\tthis.entityStore.delete(entity.id.uniqueValue)\n\t\tthis.persistedEntityData.delete(entity.id.uniqueValue)\n\t}\n\n\tpublic effectivelyHasTreeRoot(candidateRoot: MarkerTreeRoot): boolean {\n\t\tcandidateRoots: for (const candidateSubTree of candidateRoot.subTrees.values()) {\n\t\t\tif (candidateSubTree.parameters.isCreating) {\n\t\t\t\t// This, by definition, won't trigger a query.\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const root of this.markerTrees.values()) {\n\t\t\t\tfor (const alreadyPresentSubTree of root.subTrees.values()) {\n\t\t\t\t\tconst isSubset = MarkerComparator.isSubTreeSubsetOf(candidateSubTree, alreadyPresentSubTree)\n\t\t\t\t\tif (isSubset) {\n\t\t\t\t\t\tcontinue candidateRoots\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAwBA,MAAM,uCAA8C,IAAI;AAEjD,MAAM,UAAU;AAAA,EAWf,YACW,SAChB;AADgB,SAAA,UAAA;AAXF,kBAAA,MAAA,mCAAoD,IAAI,CAAA;AACxD,kBAAA,MAAA,wCAAqF,IAAI,CAAA;AAIzF,kBAAA,MAAA,mCAA+D,IAAI,CAAA;AACnE,kBAAA,MAAA,2CAA4F,IAAI,CAAA;AAEhG,kBAAA,MAAA,iBAAyC,IAAI,wBAAwB,oBAAI,IAAO,GAAA,oBAAI,KAAK,CAAA;AAAA,EAAA;AAAA,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AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorLocator.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '@contember/binding-common'\nimport type { StateNode } from '../state'\nimport type { MeaningfulMarker } from '@contember/binding-common'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: MeaningfulMarker[]): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasManyRelationMarker(hasMany)]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn stateToPath(state).join(this.GLUE)\n\t}\n}\n"],"names":["MarkerSugarer","state","TreeParameterSugarer","assertNever"],"mappings":";;;;;;;;AAMO,MAAM,aAAa;AAAA,EAGzB,OAAc,iBAAiB,MAAkC;AACzD,WAAA,KAAK,IAAI,CAAA,WAAUA,
|
|
1
|
+
{"version":3,"file":"ErrorLocator.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '@contember/binding-common'\nimport type { StateNode } from '../state'\nimport type { MeaningfulMarker } from '@contember/binding-common'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: MeaningfulMarker[]): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasManyRelationMarker(hasMany)]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn stateToPath(state).join(this.GLUE)\n\t}\n}\n"],"names":["MarkerSugarer","state","TreeParameterSugarer","assertNever"],"mappings":";;;;;;;;AAMO,MAAM,aAAa;AAAA,EAGzB,OAAc,iBAAiB,MAAkC;AACzD,WAAA,KAAK,IAAI,CAAA,WAAUA,cAAc,cAAA,YAAY,MAAM,CAAC,EAAE,KAAK,KAAK,IAAI;AAAA,EAAA;AAAA,EA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,GAAA;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorLocator.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '@contember/binding-common'\nimport type { StateNode } from '../state'\nimport type { MeaningfulMarker } from '@contember/binding-common'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: MeaningfulMarker[]): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasManyRelationMarker(hasMany)]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn stateToPath(state).join(this.GLUE)\n\t}\n}\n"],"names":["state"],"mappings":";;;;;;AAMO,MAAM,aAAa;AAAA,EAGzB,OAAc,iBAAiB,MAAkC;AACzD,WAAA,KAAK,IAAI,CAAA,WAAU,cAAc,YAAY,MAAM,CAAC,EAAE,KAAK,KAAK,IAAI;AAAA,
|
|
1
|
+
{"version":3,"file":"ErrorLocator.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/ErrorLocator.ts"],"sourcesContent":["import { assertNever } from '@contember/binding-common'\nimport type { StateNode } from '../state'\nimport type { MeaningfulMarker } from '@contember/binding-common'\nimport { MarkerSugarer } from './MarkerSugarer'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class ErrorLocator {\n\tprivate static readonly GLUE = '.'\n\n\tpublic static locateMarkerPath(path: MeaningfulMarker[]): string {\n\t\treturn path.map(marker => MarkerSugarer.sugarMarker(marker)).join(this.GLUE)\n\t}\n\n\tpublic static locateInternalState(state: StateNode): string {\n\t\tfunction stateToPath(state: StateNode | undefined): string[] {\n\t\t\tif (state === undefined) {\n\t\t\t\treturn []\n\t\t\t}\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'field':\n\t\t\t\t\treturn [...stateToPath(state.parent), TreeParameterSugarer.sugarField(state.fieldMarker.fieldName)]\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\t\t\t\t\tif (blueprint.type === 'subTree') {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntity(\n\t\t\t\t\t\t\t\tstate.entity.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.where,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'listEntity') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent)]\n\t\t\t\t\t}\n\t\t\t\t\tif (blueprint.type === 'hasOne') {\n\t\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasOneRelationMarker(blueprint.marker)]\n\t\t\t\t\t}\n\t\t\t\t\treturn assertNever(blueprint)\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst blueprint = state.blueprint\n\n\t\t\t\t\tif (blueprint.parent === undefined) {\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tTreeParameterSugarer.sugarRootEntityList(\n\t\t\t\t\t\t\t\tstate.entityName,\n\t\t\t\t\t\t\t\tblueprint.marker.parameters.isCreating ? undefined : blueprint.marker.parameters.filter,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t]\n\t\t\t\t\t}\n\t\t\t\t\tconst hasMany = blueprint.marker\n\t\t\t\t\treturn [...stateToPath(blueprint.parent), MarkerSugarer.sugarHasManyRelationMarker(hasMany)]\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn stateToPath(state).join(this.GLUE)\n\t}\n}\n"],"names":["state"],"mappings":";;;;;;AAMO,MAAM,aAAa;AAAA,EAGzB,OAAc,iBAAiB,MAAkC;AACzD,WAAA,KAAK,IAAI,CAAA,WAAU,cAAc,YAAY,MAAM,CAAC,EAAE,KAAK,KAAK,IAAI;AAAA,EAAA;AAAA,EAG5E,OAAc,oBAAoB,O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erSugarer.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/MarkerSugarer.ts"],"sourcesContent":["import {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMeaningfulMarker,\n} from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class MarkerSugarer {\n\tpublic static sugarMarker(marker: MeaningfulMarker): string {\n\t\tif (marker instanceof FieldMarker) {\n\t\t\treturn this.sugarFieldMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasOneRelationMarker) {\n\t\t\treturn this.sugarHasOneRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasManyRelationMarker) {\n\t\t\treturn this.sugarHasManyRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.sugarEntityListSubTreeMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\treturn this.sugarEntitySubTreeMarker(marker)\n\t\t}\n\t\treturn assertNever(marker)\n\t}\n\n\tpublic static sugarFieldMarker(field: FieldMarker) {\n\t\treturn TreeParameterSugarer.sugarField(field.fieldName)\n\t}\n\n\tpublic static sugarHasOneRelationMarker(hasOne: HasOneRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasOneRelation(\n\t\t\thasOne.parameters.field,\n\t\t\thasOne.parameters.reducedBy,\n\t\t\thasOne.parameters.filter,\n\t\t)\n\t}\n\n\tpublic static sugarHasManyRelationMarker(hasMany: HasManyRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasManyRelation(hasMany.parameters.field, hasMany.parameters.filter)\n\t}\n\n\tpublic static sugarEntitySubTreeMarker(subTree: EntitySubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, subTree.parameters.where)\n\t}\n\n\tpublic static sugarEntityListSubTreeMarker(subTree: EntityListSubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, subTree.parameters.filter)\n\t}\n}\n"],"names":["FieldMarker","HasOneRelationMarker","HasManyRelationMarker","EntityListSubTreeMarker","EntitySubTreeMarker","assertNever","TreeParameterSugarer"],"mappings":";;;;AAWO,MAAM,cAAc;AAAA,EAC1B,OAAc,YAAY,QAAkC;AAC3D,QAAI,kBAAkBA,cAAAA,aAAa;AAC3B,aAAA,KAAK,iBAAiB,MAAM;AAAA,
|
|
1
|
+
{"version":3,"file":"MarkerSugarer.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/MarkerSugarer.ts"],"sourcesContent":["import {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMeaningfulMarker,\n} from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class MarkerSugarer {\n\tpublic static sugarMarker(marker: MeaningfulMarker): string {\n\t\tif (marker instanceof FieldMarker) {\n\t\t\treturn this.sugarFieldMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasOneRelationMarker) {\n\t\t\treturn this.sugarHasOneRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasManyRelationMarker) {\n\t\t\treturn this.sugarHasManyRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.sugarEntityListSubTreeMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\treturn this.sugarEntitySubTreeMarker(marker)\n\t\t}\n\t\treturn assertNever(marker)\n\t}\n\n\tpublic static sugarFieldMarker(field: FieldMarker) {\n\t\treturn TreeParameterSugarer.sugarField(field.fieldName)\n\t}\n\n\tpublic static sugarHasOneRelationMarker(hasOne: HasOneRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasOneRelation(\n\t\t\thasOne.parameters.field,\n\t\t\thasOne.parameters.reducedBy,\n\t\t\thasOne.parameters.filter,\n\t\t)\n\t}\n\n\tpublic static sugarHasManyRelationMarker(hasMany: HasManyRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasManyRelation(hasMany.parameters.field, hasMany.parameters.filter)\n\t}\n\n\tpublic static sugarEntitySubTreeMarker(subTree: EntitySubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, subTree.parameters.where)\n\t}\n\n\tpublic static sugarEntityListSubTreeMarker(subTree: EntityListSubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, subTree.parameters.filter)\n\t}\n}\n"],"names":["FieldMarker","HasOneRelationMarker","HasManyRelationMarker","EntityListSubTreeMarker","EntitySubTreeMarker","assertNever","TreeParameterSugarer"],"mappings":";;;;AAWO,MAAM,cAAc;AAAA,EAC1B,OAAc,YAAY,QAAkC;AAC3D,QAAI,kBAAkBA,cAAAA,aAAa;AAC3B,aAAA,KAAK,iBAAiB,MAAM;AAAA,IAAA;AAEpC,QAAI,kBAAkBC,cAAAA,sBAAsB;AACpC,aAAA,KAAK,0BAA0B,MAAM;AAAA,IAAA;AAE7C,QAAI,kBAAkBC,cAAAA,uBAAuB;AACrC,aAAA,KAAK,2BAA2B,MAAM;AAAA,IAAA;AAE9C,QAAI,kBAAkBC,cAAAA,yBAAyB;AACvC,aAAA,KAAK,6BAA6B,MAAM;AAAA,IAAA;AAEhD,QAAI,kBAAkBC,cAAAA,qBAAqB;AACnC,aAAA,KAAK,yBAAyB,MAAM;AAAA,IAAA;AAE5C,WAAOC,cAAAA,YAAY,MAAM;AAAA,EAAA;AAAA,EAG1B,OAAc,iBAAiB,OAAoB;AAC3C,WAAAC,0CAAqB,WAAW,MAAM,SAAS;AAAA,EAAA;AAAA,EAGvD,OAAc,0BAA0B,QAA8B;AACrE,WAAOA,qBAAqB,qBAAA;AAAA,MAC3B,OAAO,WAAW;AAAA,MAClB,OAAO,WAAW;AAAA,MAClB,OAAO,WAAW;AAAA,IACnB;AAAA,EAAA;AAAA,EAGD,OAAc,2BAA2B,SAAgC;AACxE,WAAOA,0CAAqB,qBAAqB,QAAQ,WAAW,OAAO,QAAQ,WAAW,MAAM;AAAA,EAAA;AAAA,EAGrG,OAAc,yBAAyB,SAA8B;AAChE,QAAA,QAAQ,WAAW,YAAY;AAClC,aAAOA,qBAAqB,qBAAA,gBAAgB,QAAQ,YAAY,MAAS;AAAA,IAAA;AAE1E,WAAOA,qBAAAA,qBAAqB,gBAAgB,QAAQ,YAAY,QAAQ,WAAW,KAAK;AAAA,EAAA;AAAA,EAGzF,OAAc,6BAA6B,SAAkC;AACxE,QAAA,QAAQ,WAAW,YAAY;AAClC,aAAOA,qBAAqB,qBAAA,oBAAoB,QAAQ,YAAY,MAAS;AAAA,IAAA;AAE9E,WAAOA,qBAAAA,qBAAqB,oBAAoB,QAAQ,YAAY,QAAQ,WAAW,MAAM;AAAA,EAAA;AAE/F;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkerSugarer.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/MarkerSugarer.ts"],"sourcesContent":["import {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMeaningfulMarker,\n} from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class MarkerSugarer {\n\tpublic static sugarMarker(marker: MeaningfulMarker): string {\n\t\tif (marker instanceof FieldMarker) {\n\t\t\treturn this.sugarFieldMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasOneRelationMarker) {\n\t\t\treturn this.sugarHasOneRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasManyRelationMarker) {\n\t\t\treturn this.sugarHasManyRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.sugarEntityListSubTreeMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\treturn this.sugarEntitySubTreeMarker(marker)\n\t\t}\n\t\treturn assertNever(marker)\n\t}\n\n\tpublic static sugarFieldMarker(field: FieldMarker) {\n\t\treturn TreeParameterSugarer.sugarField(field.fieldName)\n\t}\n\n\tpublic static sugarHasOneRelationMarker(hasOne: HasOneRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasOneRelation(\n\t\t\thasOne.parameters.field,\n\t\t\thasOne.parameters.reducedBy,\n\t\t\thasOne.parameters.filter,\n\t\t)\n\t}\n\n\tpublic static sugarHasManyRelationMarker(hasMany: HasManyRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasManyRelation(hasMany.parameters.field, hasMany.parameters.filter)\n\t}\n\n\tpublic static sugarEntitySubTreeMarker(subTree: EntitySubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, subTree.parameters.where)\n\t}\n\n\tpublic static sugarEntityListSubTreeMarker(subTree: EntityListSubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, subTree.parameters.filter)\n\t}\n}\n"],"names":[],"mappings":";;AAWO,MAAM,cAAc;AAAA,EAC1B,OAAc,YAAY,QAAkC;AAC3D,QAAI,kBAAkB,aAAa;AAC3B,aAAA,KAAK,iBAAiB,MAAM;AAAA,
|
|
1
|
+
{"version":3,"file":"MarkerSugarer.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/MarkerSugarer.ts"],"sourcesContent":["import {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMeaningfulMarker,\n} from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport { TreeParameterSugarer } from './TreeParameterSugarer'\n\nexport class MarkerSugarer {\n\tpublic static sugarMarker(marker: MeaningfulMarker): string {\n\t\tif (marker instanceof FieldMarker) {\n\t\t\treturn this.sugarFieldMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasOneRelationMarker) {\n\t\t\treturn this.sugarHasOneRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof HasManyRelationMarker) {\n\t\t\treturn this.sugarHasManyRelationMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntityListSubTreeMarker) {\n\t\t\treturn this.sugarEntityListSubTreeMarker(marker)\n\t\t}\n\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\treturn this.sugarEntitySubTreeMarker(marker)\n\t\t}\n\t\treturn assertNever(marker)\n\t}\n\n\tpublic static sugarFieldMarker(field: FieldMarker) {\n\t\treturn TreeParameterSugarer.sugarField(field.fieldName)\n\t}\n\n\tpublic static sugarHasOneRelationMarker(hasOne: HasOneRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasOneRelation(\n\t\t\thasOne.parameters.field,\n\t\t\thasOne.parameters.reducedBy,\n\t\t\thasOne.parameters.filter,\n\t\t)\n\t}\n\n\tpublic static sugarHasManyRelationMarker(hasMany: HasManyRelationMarker) {\n\t\treturn TreeParameterSugarer.sugarHasManyRelation(hasMany.parameters.field, hasMany.parameters.filter)\n\t}\n\n\tpublic static sugarEntitySubTreeMarker(subTree: EntitySubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntity(subTree.entityName, subTree.parameters.where)\n\t}\n\n\tpublic static sugarEntityListSubTreeMarker(subTree: EntityListSubTreeMarker) {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, undefined)\n\t\t}\n\t\treturn TreeParameterSugarer.sugarRootEntityList(subTree.entityName, subTree.parameters.filter)\n\t}\n}\n"],"names":[],"mappings":";;AAWO,MAAM,cAAc;AAAA,EAC1B,OAAc,YAAY,QAAkC;AAC3D,QAAI,kBAAkB,aAAa;AAC3B,aAAA,KAAK,iBAAiB,MAAM;AAAA,IAAA;AAEpC,QAAI,kBAAkB,sBAAsB;AACpC,aAAA,KAAK,0BAA0B,MAAM;AAAA,IAAA;AAE7C,QAAI,kBAAkB,uBAAuB;AACrC,aAAA,KAAK,2BAA2B,MAAM;AAAA,IAAA;AAE9C,QAAI,kBAAkB,yBAAyB;AACvC,aAAA,KAAK,6BAA6B,MAAM;AAAA,IAAA;AAEhD,QAAI,kBAAkB,qBAAqB;AACnC,aAAA,KAAK,yBAAyB,MAAM;AAAA,IAAA;AAE5C,WAAO,YAAY,MAAM;AAAA,EAAA;AAAA,EAG1B,OAAc,iBAAiB,OAAoB;AAC3C,WAAA,qBAAqB,WAAW,MAAM,SAAS;AAAA,EAAA;AAAA,EAGvD,OAAc,0BAA0B,QAA8B;AACrE,WAAO,qBAAqB;AAAA,MAC3B,OAAO,WAAW;AAAA,MAClB,OAAO,WAAW;AAAA,MAClB,OAAO,WAAW;AAAA,IACnB;AAAA,EAAA;AAAA,EAGD,OAAc,2BAA2B,SAAgC;AACxE,WAAO,qBAAqB,qBAAqB,QAAQ,WAAW,OAAO,QAAQ,WAAW,MAAM;AAAA,EAAA;AAAA,EAGrG,OAAc,yBAAyB,SAA8B;AAChE,QAAA,QAAQ,WAAW,YAAY;AAClC,aAAO,qBAAqB,gBAAgB,QAAQ,YAAY,MAAS;AAAA,IAAA;AAE1E,WAAO,qBAAqB,gBAAgB,QAAQ,YAAY,QAAQ,WAAW,KAAK;AAAA,EAAA;AAAA,EAGzF,OAAc,6BAA6B,SAAkC;AACxE,QAAA,QAAQ,WAAW,YAAY;AAClC,aAAO,qBAAqB,oBAAoB,QAAQ,YAAY,MAAS;AAAA,IAAA;AAE9E,WAAO,qBAAqB,oBAAoB,QAAQ,YAAY,QAAQ,WAAW,MAAM;AAAA,EAAA;AAE/F;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeParameterSugarer.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/TreeParameterSugarer.ts"],"sourcesContent":["import type { EntityName, FieldName, Filter, UniqueWhere } from '@contember/binding-common'\n\nexport class TreeParameterSugarer {\n\tpublic static sugarField(fieldName: FieldName) {\n\t\treturn fieldName\n\t}\n\n\tpublic static sugarHasOneRelation(\n\t\tfieldName: FieldName,\n\t\treducedBy: UniqueWhere | undefined,\n\t\tfilter: Filter | undefined,\n\t) {\n\t\treturn `${fieldName}${this.sugarUniqueWhere(reducedBy)}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarHasManyRelation(fieldName: FieldName, filter: Filter | undefined) {\n\t\treturn `${fieldName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarRootEntity(entityName: EntityName, where: UniqueWhere | undefined) {\n\t\treturn `${entityName}${this.sugarUniqueWhere(where)}`\n\t}\n\n\tpublic static sugarRootEntityList(entityName: EntityName, filter: Filter | undefined) {\n\t\treturn `${entityName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarUniqueWhere(where: UniqueWhere | undefined): string {\n\t\tif (where === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `(…)` // TODO\n\t}\n\n\tpublic static sugarFilter(filter: Filter | undefined): string {\n\t\tif (filter === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `[…]` // TODO\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB;AAAA,EACjC,OAAc,WAAW,WAAsB;AACvC,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"TreeParameterSugarer.cjs","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/TreeParameterSugarer.ts"],"sourcesContent":["import type { EntityName, FieldName, Filter, UniqueWhere } from '@contember/binding-common'\n\nexport class TreeParameterSugarer {\n\tpublic static sugarField(fieldName: FieldName) {\n\t\treturn fieldName\n\t}\n\n\tpublic static sugarHasOneRelation(\n\t\tfieldName: FieldName,\n\t\treducedBy: UniqueWhere | undefined,\n\t\tfilter: Filter | undefined,\n\t) {\n\t\treturn `${fieldName}${this.sugarUniqueWhere(reducedBy)}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarHasManyRelation(fieldName: FieldName, filter: Filter | undefined) {\n\t\treturn `${fieldName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarRootEntity(entityName: EntityName, where: UniqueWhere | undefined) {\n\t\treturn `${entityName}${this.sugarUniqueWhere(where)}`\n\t}\n\n\tpublic static sugarRootEntityList(entityName: EntityName, filter: Filter | undefined) {\n\t\treturn `${entityName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarUniqueWhere(where: UniqueWhere | undefined): string {\n\t\tif (where === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `(…)` // TODO\n\t}\n\n\tpublic static sugarFilter(filter: Filter | undefined): string {\n\t\tif (filter === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `[…]` // TODO\n\t}\n}\n"],"names":[],"mappings":";;AAEO,MAAM,qBAAqB;AAAA,EACjC,OAAc,WAAW,WAAsB;AACvC,WAAA;AAAA,EAAA;AAAA,EAGR,OAAc,oBACb,WACA,WACA,QACC;AACM,WAAA,GAAG,SAAS,GAAG,KAAK,iBAAiB,SAAS,CAAC,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAGlF,OAAc,qBAAqB,WAAsB,QAA4B;AACpF,WAAO,GAAG,SAAS,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAG/C,OAAc,gBAAgB,YAAwB,OAAgC;AACrF,WAAO,GAAG,UAAU,GAAG,KAAK,iBAAiB,KAAK,CAAC;AAAA,EAAA;AAAA,EAGpD,OAAc,oBAAoB,YAAwB,QAA4B;AACrF,WAAO,GAAG,UAAU,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAGhD,OAAc,iBAAiB,OAAwC;AACtE,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,EAAA;AAAA,EAGR,OAAc,YAAY,QAAoC;AAC7D,QAAI,WAAW,QAAW;AAClB,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,EAAA;AAET;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeParameterSugarer.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/TreeParameterSugarer.ts"],"sourcesContent":["import type { EntityName, FieldName, Filter, UniqueWhere } from '@contember/binding-common'\n\nexport class TreeParameterSugarer {\n\tpublic static sugarField(fieldName: FieldName) {\n\t\treturn fieldName\n\t}\n\n\tpublic static sugarHasOneRelation(\n\t\tfieldName: FieldName,\n\t\treducedBy: UniqueWhere | undefined,\n\t\tfilter: Filter | undefined,\n\t) {\n\t\treturn `${fieldName}${this.sugarUniqueWhere(reducedBy)}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarHasManyRelation(fieldName: FieldName, filter: Filter | undefined) {\n\t\treturn `${fieldName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarRootEntity(entityName: EntityName, where: UniqueWhere | undefined) {\n\t\treturn `${entityName}${this.sugarUniqueWhere(where)}`\n\t}\n\n\tpublic static sugarRootEntityList(entityName: EntityName, filter: Filter | undefined) {\n\t\treturn `${entityName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarUniqueWhere(where: UniqueWhere | undefined): string {\n\t\tif (where === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `(…)` // TODO\n\t}\n\n\tpublic static sugarFilter(filter: Filter | undefined): string {\n\t\tif (filter === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `[…]` // TODO\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,qBAAqB;AAAA,EACjC,OAAc,WAAW,WAAsB;AACvC,WAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"TreeParameterSugarer.js","sources":["../../../../../../packages/binding-legacy/src/core/exceptions/TreeParameterSugarer.ts"],"sourcesContent":["import type { EntityName, FieldName, Filter, UniqueWhere } from '@contember/binding-common'\n\nexport class TreeParameterSugarer {\n\tpublic static sugarField(fieldName: FieldName) {\n\t\treturn fieldName\n\t}\n\n\tpublic static sugarHasOneRelation(\n\t\tfieldName: FieldName,\n\t\treducedBy: UniqueWhere | undefined,\n\t\tfilter: Filter | undefined,\n\t) {\n\t\treturn `${fieldName}${this.sugarUniqueWhere(reducedBy)}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarHasManyRelation(fieldName: FieldName, filter: Filter | undefined) {\n\t\treturn `${fieldName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarRootEntity(entityName: EntityName, where: UniqueWhere | undefined) {\n\t\treturn `${entityName}${this.sugarUniqueWhere(where)}`\n\t}\n\n\tpublic static sugarRootEntityList(entityName: EntityName, filter: Filter | undefined) {\n\t\treturn `${entityName}${this.sugarFilter(filter)}`\n\t}\n\n\tpublic static sugarUniqueWhere(where: UniqueWhere | undefined): string {\n\t\tif (where === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `(…)` // TODO\n\t}\n\n\tpublic static sugarFilter(filter: Filter | undefined): string {\n\t\tif (filter === undefined) {\n\t\t\treturn ''\n\t\t}\n\t\treturn `[…]` // TODO\n\t}\n}\n"],"names":[],"mappings":"AAEO,MAAM,qBAAqB;AAAA,EACjC,OAAc,WAAW,WAAsB;AACvC,WAAA;AAAA,EAAA;AAAA,EAGR,OAAc,oBACb,WACA,WACA,QACC;AACM,WAAA,GAAG,SAAS,GAAG,KAAK,iBAAiB,SAAS,CAAC,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAGlF,OAAc,qBAAqB,WAAsB,QAA4B;AACpF,WAAO,GAAG,SAAS,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAG/C,OAAc,gBAAgB,YAAwB,OAAgC;AACrF,WAAO,GAAG,UAAU,GAAG,KAAK,iBAAiB,KAAK,CAAC;AAAA,EAAA;AAAA,EAGpD,OAAc,oBAAoB,YAAwB,QAA4B;AACrF,WAAO,GAAG,UAAU,GAAG,KAAK,YAAY,MAAM,CAAC;AAAA,EAAA;AAAA,EAGhD,OAAc,iBAAiB,OAAwC;AACtE,QAAI,UAAU,QAAW;AACjB,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,EAAA;AAAA,EAGR,OAAc,YAAY,QAAoC;AAC7D,QAAI,WAAW,QAAW;AAClB,aAAA;AAAA,IAAA;AAED,WAAA;AAAA,EAAA;AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBatchUpdatesOptions.cjs","sources":["../../../../../../packages/binding-legacy/src/core/factories/createBatchUpdatesOptions.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { Environment } from '@contember/binding-common'\nimport type {\n\tAlias,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '@contember/binding-common'\nimport type { TreeStore } from '../TreeStore'\n\nexport const createBatchUpdatesOptions = (rootEnvironment: Environment, treeStore: TreeStore): BatchUpdatesOptions =>\n\tObject.freeze({\n\t\tgetEntityByKey: (key: string | (() => EntityAccessor)) => {\n\t\t\tif (typeof key === 'function') {\n\t\t\t\treturn key()\n\t\t\t}\n\t\t\tconst realm = treeStore.entityRealmStore.get(key)\n\n\t\t\tif (realm === undefined) {\n\t\t\t\tthrow new BindingError(`Trying to retrieve a non-existent entity: key '${key}' was not found.`)\n\t\t\t}\n\t\t\treturn realm.getAccessor()\n\t\t},\n\t\tgetEntityListSubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityListAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entityList', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t\tgetEntitySubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entity', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t})\n"],"names":["BindingError"],"mappings":";;;AAaO,MAAM,4BAA4B,CAAC,iBAA8B,cACvE,OAAO,OAAO;AAAA,EACb,gBAAgB,CAAC,QAAyC;AACrD,QAAA,OAAO,QAAQ,YAAY;AAC9B,aAAO,IAAI;AAAA,
|
|
1
|
+
{"version":3,"file":"createBatchUpdatesOptions.cjs","sources":["../../../../../../packages/binding-legacy/src/core/factories/createBatchUpdatesOptions.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { Environment } from '@contember/binding-common'\nimport type {\n\tAlias,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '@contember/binding-common'\nimport type { TreeStore } from '../TreeStore'\n\nexport const createBatchUpdatesOptions = (rootEnvironment: Environment, treeStore: TreeStore): BatchUpdatesOptions =>\n\tObject.freeze({\n\t\tgetEntityByKey: (key: string | (() => EntityAccessor)) => {\n\t\t\tif (typeof key === 'function') {\n\t\t\t\treturn key()\n\t\t\t}\n\t\t\tconst realm = treeStore.entityRealmStore.get(key)\n\n\t\t\tif (realm === undefined) {\n\t\t\t\tthrow new BindingError(`Trying to retrieve a non-existent entity: key '${key}' was not found.`)\n\t\t\t}\n\t\t\treturn realm.getAccessor()\n\t\t},\n\t\tgetEntityListSubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityListAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entityList', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t\tgetEntitySubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entity', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t})\n"],"names":["BindingError"],"mappings":";;;AAaO,MAAM,4BAA4B,CAAC,iBAA8B,cACvE,OAAO,OAAO;AAAA,EACb,gBAAgB,CAAC,QAAyC;AACrD,QAAA,OAAO,QAAQ,YAAY;AAC9B,aAAO,IAAI;AAAA,IAAA;AAEZ,UAAM,QAAQ,UAAU,iBAAiB,IAAI,GAAG;AAEhD,QAAI,UAAU,QAAW;AACxB,YAAM,IAAIA,cAAAA,aAAa,kDAAkD,GAAG,kBAAkB;AAAA,IAAA;AAE/F,WAAO,MAAM,YAAY;AAAA,EAC1B;AAAA,EACA,sBAAsB,CACrB,mBACA,QACA,cAAc,oBACU;AACxB,WAAO,UAAU,gBAAgB,cAAc,QAAQ,mBAAmB,WAAW,EAAE,YAAY;AAAA,EACpG;AAAA,EACA,kBAAkB,CACjB,mBACA,QACA,cAAc,oBACM;AACpB,WAAO,UAAU,gBAAgB,UAAU,QAAQ,mBAAmB,WAAW,EAAE,YAAY;AAAA,EAAA;AAEjG,CAAC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBatchUpdatesOptions.js","sources":["../../../../../../packages/binding-legacy/src/core/factories/createBatchUpdatesOptions.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { Environment } from '@contember/binding-common'\nimport type {\n\tAlias,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '@contember/binding-common'\nimport type { TreeStore } from '../TreeStore'\n\nexport const createBatchUpdatesOptions = (rootEnvironment: Environment, treeStore: TreeStore): BatchUpdatesOptions =>\n\tObject.freeze({\n\t\tgetEntityByKey: (key: string | (() => EntityAccessor)) => {\n\t\t\tif (typeof key === 'function') {\n\t\t\t\treturn key()\n\t\t\t}\n\t\t\tconst realm = treeStore.entityRealmStore.get(key)\n\n\t\t\tif (realm === undefined) {\n\t\t\t\tthrow new BindingError(`Trying to retrieve a non-existent entity: key '${key}' was not found.`)\n\t\t\t}\n\t\t\treturn realm.getAccessor()\n\t\t},\n\t\tgetEntityListSubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityListAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entityList', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t\tgetEntitySubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entity', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t})\n"],"names":[],"mappings":";AAaO,MAAM,4BAA4B,CAAC,iBAA8B,cACvE,OAAO,OAAO;AAAA,EACb,gBAAgB,CAAC,QAAyC;AACrD,QAAA,OAAO,QAAQ,YAAY;AAC9B,aAAO,IAAI;AAAA,
|
|
1
|
+
{"version":3,"file":"createBatchUpdatesOptions.js","sources":["../../../../../../packages/binding-legacy/src/core/factories/createBatchUpdatesOptions.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport type { Environment } from '@contember/binding-common'\nimport type {\n\tAlias,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tTreeRootId,\n} from '@contember/binding-common'\nimport type { TreeStore } from '../TreeStore'\n\nexport const createBatchUpdatesOptions = (rootEnvironment: Environment, treeStore: TreeStore): BatchUpdatesOptions =>\n\tObject.freeze({\n\t\tgetEntityByKey: (key: string | (() => EntityAccessor)) => {\n\t\t\tif (typeof key === 'function') {\n\t\t\t\treturn key()\n\t\t\t}\n\t\t\tconst realm = treeStore.entityRealmStore.get(key)\n\n\t\t\tif (realm === undefined) {\n\t\t\t\tthrow new BindingError(`Trying to retrieve a non-existent entity: key '${key}' was not found.`)\n\t\t\t}\n\t\t\treturn realm.getAccessor()\n\t\t},\n\t\tgetEntityListSubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityListAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entityList', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t\tgetEntitySubTree: (\n\t\t\taliasOrParameters: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,\n\t\t\ttreeId: TreeRootId | undefined,\n\t\t\tenvironment = rootEnvironment,\n\t\t): EntityAccessor => {\n\t\t\treturn treeStore.getSubTreeState('entity', treeId, aliasOrParameters, environment).getAccessor()\n\t\t},\n\t})\n"],"names":[],"mappings":";AAaO,MAAM,4BAA4B,CAAC,iBAA8B,cACvE,OAAO,OAAO;AAAA,EACb,gBAAgB,CAAC,QAAyC;AACrD,QAAA,OAAO,QAAQ,YAAY;AAC9B,aAAO,IAAI;AAAA,IAAA;AAEZ,UAAM,QAAQ,UAAU,iBAAiB,IAAI,GAAG;AAEhD,QAAI,UAAU,QAAW;AACxB,YAAM,IAAI,aAAa,kDAAkD,GAAG,kBAAkB;AAAA,IAAA;AAE/F,WAAO,MAAM,YAAY;AAAA,EAC1B;AAAA,EACA,sBAAsB,CACrB,mBACA,QACA,cAAc,oBACU;AACxB,WAAO,UAAU,gBAAgB,cAAc,QAAQ,mBAAmB,WAAW,EAAE,YAAY;AAAA,EACpG;AAAA,EACA,kBAAkB,CACjB,mBACA,QACA,cAAc,oBACM;AACpB,WAAO,UAAU,gBAAgB,UAAU,QAAQ,mBAAmB,WAAW,EAAE,YAAY;AAAA,EAAA;AAEjG,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":["EventListenersStore","OperationsHelpers","getEntityMarker","BindingError","ErrorLocator","StateIterator","MarkerComparator","LocalizedBindingError","ServerId","UnpersistedEntityDummyId","assertNever","HasOneRelationMarker"],"mappings":";;;;;;;AAiBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,aAAa,KAAK;AAAA,EAC7D;AAAA,EAEO,iBACN,OACA,OACA,UACC;AACG,QAAA,MAAM,mBAAmB,QAAW;AACjC,YAAA,iBAAiB,IAAIA,cAAAA;IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,aAAa,OAAyB,gBAAoD;AAC3F,SAAA,aAAa,cAAc,MAAM;AACtB,qBAAA,MAAM,aAAa,KAAK,mBAAmB;AAAA,IAAA,CAC1D;AAAA,EACF;AAAA,EAEO,qBAAqB,YAA8B,WAAsB,iBAAiC;AAC3G,SAAA,aAAa,cAAc,MAAM;AACrC,YAAM,iBAAiBC,kBAAAA,kBAAkB,iCAAiC,KAAK,WAAW,eAAe;AACnG,YAAA,kBAAkB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IAAA,CACA;AAAA,EACF;AAAA,EAEA,CAAS,6BACR,WACA,OACA,MACA,YACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AACA,YAAM,IAAIP,cAAAA,aAAa,UAAU,IAAI,cAAc,KAAK,iDAAiD;AAAA,IAC1G;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,EAAE,0BAA0BQ,cAAAA,uBAAuB;AACtD,cAAM,IAAIR,cAAAA,aAAa,UAAU,IAAI,cAAc,KAAK,8CAA8C;AAAA,MACvG;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"EntityOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":["EventListenersStore","OperationsHelpers","getEntityMarker","BindingError","ErrorLocator","StateIterator","MarkerComparator","LocalizedBindingError","ServerId","UnpersistedEntityDummyId","assertNever","HasOneRelationMarker"],"mappings":";;;;;;;AAiBO,MAAM,iB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AAAA,MAAA;AAEjG,YAAA;AAAA,IAAA;AAAA,EACP;AAEF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityOperations.js","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAiBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,aAAa,KAAK;AAAA,EAC7D;AAAA,EAEO,iBACN,OACA,OACA,UACC;AACG,QAAA,MAAM,mBAAmB,QAAW;AACjC,YAAA,iBAAiB,IAAI;IAC5B;AACA,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAChD;AAAA,EAEO,aAAa,OAAyB,gBAAoD;AAC3F,SAAA,aAAa,cAAc,MAAM;AACtB,qBAAA,MAAM,aAAa,KAAK,mBAAmB;AAAA,IAAA,CAC1D;AAAA,EACF;AAAA,EAEO,qBAAqB,YAA8B,WAAsB,iBAAiC;AAC3G,SAAA,a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C,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B,UAAI,CAAC,YAAY;AAChB;AAAA,MACD;AACA,YAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,iDAAiD;AAAA,IAC1G;AACA,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,EAAE,0BAA0B,uBAAuB;AACtD,cAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,8CAA8C;AAAA,MACvG;AACM,YAAA;AAAA,IACP;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"EntityOperations.js","sources":["../../../../../../packages/binding-legacy/src/core/operations/EntityOperations.ts"],"sourcesContent":["import type { BatchUpdatesOptions, EntityAccessor, ErrorAccessor } from '@contember/binding-common'\nimport { ServerId, UnpersistedEntityDummyId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { EntityFieldMarkersContainer, HasOneRelationMarker } from '@contember/binding-common'\nimport type { FieldName } from '@contember/binding-common'\nimport { assertNever } from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport type { EventManager } from '../EventManager'\nimport { LocalizedBindingError } from '@contember/binding-common'\nimport { MarkerComparator } from '@contember/binding-common'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '@contember/binding-common'\nimport { ErrorLocator } from '../exceptions/ErrorLocator'\n\nexport class EntityOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(entityRealm, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tstate: EntityRealmState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityRealmState, performUpdates: EntityAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntityAtField(outerState: EntityRealmState, fieldName: FieldName, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst fieldsToConnect = getEntityMarker(stateToConnect).fields\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tconst entityName = outerState.entity.entityName\n\t\t\tconst fieldSchema = this.treeStore.schema.getEntityFieldOrUndefined(entityName, fieldName)\n\n\t\t\tif (fieldSchema === undefined) {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Unknown field ${entityName}.${fieldName}.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t} else if (fieldSchema.__typename === '_Column') {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`EntityAccessor.connectEntityAtField: Cannot connect at field ${entityName}.${fieldName} because ` +\n\t\t\t\t\t\t`it's not a has-one relation.\\n\\n` +\n\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === undefined ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'field' ||\n\t\t\t\t\t\tpreviouslyConnectedState.type === 'entityList'\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (previouslyConnectedState.entity.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`EntityAccessor.connectEntityAtField: Attempting to connect at field ${entityName}.${fieldName} ` +\n\t\t\t\t\t\t\t\t`an entity of type '${stateToConnect.entity.entityName}' but ` +\n\t\t\t\t\t\t\t\t`'${previouslyConnectedState.entity.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(targetHasOneMarker.fields, fieldsToConnect)\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t\t`EntityAccessor: cannot connect entity with key '${entityToConnect.key}' because its fields are` +\n\t\t\t\t\t\t\t\t\t`incompatible with entities found at field '${fieldName}'. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow error\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tpreviouslyConnectedState === stateToConnect ||\n\t\t\t\t\t\tpreviouslyConnectedState.entity.id.value === stateToConnect.entity.id.value\n\t\t\t\t\t) {\n\t\t\t\t\t\tcontinue // Do nothing.\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO remove from planned deletions if appropriate\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(previouslyConnectedState)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (previouslyConnectedState.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= previouslyConnectedState.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\t\t\t\t\tif (persistedId instanceof ServerId && persistedId.value === stateToConnect.entity.id.value) {\n\t\t\t\t\t\tchangesDelta-- // It was removed from the list but now we're adding it back.\n\t\t\t\t\t} else if (persistedId instanceof ServerId && persistedId.value === previouslyConnectedState.entity.id.value) {\n\t\t\t\t\t\tchangesDelta++ // We're changing it from the persisted id.\n\t\t\t\t\t} else if (!previouslyConnectedState.entity.id.existsOnServer) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tpersistedId === null || // We're updating.\n\t\t\t\t\t\t\t(persistedId === undefined && // We're creating.\n\t\t\t\t\t\t\t\t(!fieldsToConnect.hasAtLeastOneBearingField || !targetHasOneMarker.parameters.isNonbearing))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\t// TODO do something about the existing state…\n\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tstateToConnect.entity.id,\n\t\t\t\t\t\tstateToConnect.entity.entityName,\n\t\t\t\t\t\tpreviouslyConnectedState.blueprint,\n\t\t\t\t\t\tstateToConnect,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntityAtField(\n\t\touterState: EntityRealmState,\n\t\tfieldName: FieldName,\n\t\tinitializeReplacement: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealm(outerState)) {\n\t\t\t\tconst targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect', state === outerState)\n\t\t\t\tfor (const targetHasOneMarker of targetHasOneMarkers) {\n\t\t\t\t\tconst stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tstateToDisconnect === undefined ||\n\t\t\t\t\t\t(stateToDisconnect.type !== 'entityRealm' && stateToDisconnect.type !== 'entityRealmStub')\n\t\t\t\t\t) {\n\t\t\t\t\t\tOperationsHelpers.rejectInvalidAccessorTree()\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.disposeOfRealm(stateToDisconnect)\n\n\t\t\t\t\tlet changesDelta = 0\n\n\t\t\t\t\tif (stateToDisconnect.type === 'entityRealm') {\n\t\t\t\t\t\tchangesDelta -= stateToDisconnect.unpersistedChangesCount\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedId = persistedData?.get(targetHasOneMarker.placeholderName)\n\n\t\t\t\t\tif (persistedId instanceof ServerId) {\n\t\t\t\t\t\tif (persistedId.value === stateToDisconnect.entity.id.value) {\n\t\t\t\t\t\t\tchangesDelta++ // Disconnecting the persisted entity.\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Do nothing. The entity that is being disconnected is already different from the one that is persisted,\n\t\t\t\t\t\t\t// and so we must have already accounted for this change.\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (persistedId === undefined || persistedId === null) {\n\t\t\t\t\t\tif (stateToDisconnect.entity.id.existsOnServer) {\n\t\t\t\t\t\t\t// We had connected a persisted entity, which increased the changes count,\n\t\t\t\t\t\t\t// but now are disconnecting it again.\n\t\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Do nothing. Disconnecting unpersisted entities doesn't change the count.\n\t\t\t\t\t}\n\n\t\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\tstateToDisconnect.entity.entityName,\n\t\t\t\t\t\tstateToDisconnect.blueprint,\n\t\t\t\t\t)\n\t\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initializeReplacement)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(state, targetHasOneMarker.placeholderName)\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic deleteEntity(realm: EntityRealmState) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst outerState = realm.entity\n\t\t\touterState.isScheduledForDeletion = true\n\n\t\t\tconst entityId = outerState.id\n\n\t\t\tfor (const realmToDelete of outerState.realms.values()) {\n\t\t\t\tlet parent: EntityRealmState | EntityRealmStateStub | EntityListState | undefined\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (realmToDelete.blueprint.type === 'listEntity') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tparent.children.delete(entityId.value)\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedRemovals === undefined) {\n\t\t\t\t\t\t\tparent.plannedRemovals = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedRemovals.set(entityId.value, 'delete')\n\t\t\t\t\t}\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'hasOne') {\n\t\t\t\t\tparent = realmToDelete.blueprint.parent\n\t\t\t\t\tconst placeholderName = realmToDelete.blueprint.marker.placeholderName\n\n\t\t\t\t\tif (entityId.existsOnServer) {\n\t\t\t\t\t\tif (parent.plannedHasOneDeletions === undefined) {\n\t\t\t\t\t\t\tparent.plannedHasOneDeletions = new Map()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t\tparent.plannedHasOneDeletions.set(placeholderName, realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.stateInitializer.initializeEntityRealm(\n\t\t\t\t\t\tnew UnpersistedEntityDummyId(),\n\t\t\t\t\t\touterState.entityName,\n\t\t\t\t\t\trealmToDelete.blueprint,\n\t\t\t\t\t)\n\n\t\t\t\t\tthis.eventManager.registerUpdatedConnection(parent, placeholderName)\n\t\t\t\t} else if (realmToDelete.blueprint.type === 'subTree') {\n\t\t\t\t\tparent = undefined\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(realmToDelete, 1)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(realmToDelete.blueprint)\n\t\t\t\t}\n\n\t\t\t\tif (parent) {\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\t// Undoing whatever this had caused\n\t\t\t\t\t\tchangesDelta -= realmToDelete.unpersistedChangesCount\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(parent, changesDelta)\n\n\t\t\t\t\tif (realmToDelete.type === 'entityRealm') {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates?.delete(realmToDelete)\n\t\t\t\t\t}\n\t\t\t\t\tthis.treeStore.disposeOfRealm(realmToDelete)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate *resolveHasOneRelationMarkers(\n\t\tcontainer: EntityFieldMarkersContainer,\n\t\tfield: FieldName,\n\t\ttype: 'connect' | 'disconnect',\n\t\tmustExists: boolean,\n\t): IterableIterator<HasOneRelationMarker> {\n\t\tconst placeholders = container.placeholders.get(field)\n\n\t\tif (placeholders === undefined) {\n\t\t\tif (!mustExists) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)\n\t\t}\n\t\tconst normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]\n\n\t\tfor (const placeholderName of normalizedPlaceholders) {\n\t\t\tconst hasOneRelation = container.markers.get(placeholderName)\n\n\t\t\tif (!(hasOneRelation instanceof HasOneRelationMarker)) {\n\t\t\t\tthrow new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)\n\t\t\t}\n\t\t\tyield hasOneRelation\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;AAiBO,MAAM,iBAAiB;AAAA,EACtB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;AALgB,SAAA,uBAAA;AACA,SAAA,sBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGX,SAAS,aAA+B,OAAwC;AACtF,WAAO,KAAK,qBAAqB,SAAS,a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,aAAa,oBAAoB,eAAe,CAAC;AAAA,UAAA;AAAA,QACvD,OACM;AACC,iBAAA,YAAY,cAAc,SAAS;AAAA,QAAA;AAG3C,YAAI,QAAQ;AACP,cAAA,cAAc,SAAS,eAAe;AAEzC,4BAAgB,cAAc;AAAA,UAAA;AAG1B,eAAA,aAAa,oBAAoB,QAAQ,YAAY;AAEtD,cAAA,cAAc,SAAS,eAAe;AAClC,mBAAA,4BAA4B,OAAO,aAAa;AAAA,UAAA;AAEnD,eAAA,UAAU,eAAe,aAAa;AAAA,QAAA;AAAA,MAC5C;AAAA,IACD,CACA;AAAA,EAAA;AAAA,EAGF,CAAS,6BACR,WACA,OACA,MACA,YACyC;AACzC,UAAM,eAAe,UAAU,aAAa,IAAI,KAAK;AAErD,QAAI,iBAAiB,QAAW;AAC/B,UAAI,CAAC,YAAY;AAChB;AAAA,MAAA;AAED,YAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,iDAAiD;AAAA,IAAA;AAE1G,UAAM,yBAAyB,wBAAwB,MAAM,eAAe,CAAC,YAAY;AAEzF,eAAW,mBAAmB,wBAAwB;AACrD,YAAM,iBAAiB,UAAU,QAAQ,IAAI,eAAe;AAExD,UAAA,EAAE,0BAA0B,uBAAuB;AACtD,cAAM,IAAI,aAAa,UAAU,IAAI,cAAc,KAAK,8CAA8C;AAAA,MAAA;AAEjG,YAAA;AAAA,IAAA;AAAA,EACP;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { FieldValue } from '@contember/binding-common'\nimport {\n\tBindingError,\n\tClientGeneratedUuid,\n\tErrorAccessor,\n\tEventListenersStore,\n\tFieldAccessor,\n\tPRIMARY_KEY_NAME,\n\tServerId,\n} from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = 'user' }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\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\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["EventListenersStore","PRIMARY_KEY_NAME","BindingError","uuidValidate","ServerId","OperationsHelpers","ClientGeneratedUuid","StateIterator","getEntityMarker","EventManager"],"mappings":";;;;;;;;AAkBO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"FieldOperations.cjs","sources":["../../../../../../packages/binding-legacy/src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { FieldValue } from '@contember/binding-common'\nimport {\n\tBindingError,\n\tClientGeneratedUuid,\n\tErrorAccessor,\n\tEventListenersStore,\n\tFieldAccessor,\n\tPRIMARY_KEY_NAME,\n\tServerId,\n} from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = 'user' }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\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\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["EventListenersStore","PRIMARY_KEY_NAME","BindingError","uuidValidate","ServerId","OperationsHelpers","ClientGeneratedUuid","StateIterator","getEntityMarker","EventManager"],"mappings":";;;;;;;;AAkBO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGX,SAAS,YAA6B,OAAwC;AACpF,WAAO,KAAK,qBAAqB,SAAS,YAAY,KAAK;AAAA,EAAA;AAAA,EAGrD,YAAY,YAAmC;AAC9C,WAAA,KAAK,qBAAqB,mBAAmB,UAAU;AAAA,EAAA;AAAA,EAGxD,iBAIN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W;AAC3B,gBAAA,+BAAe,IAAI;AAAA,QAAA;AAEpB,cAAA,SAAS,IAAI,KAAK;AACxB,cAAM,QAAQ;AAER,cAAA,gBACL,MAAM,YAAY,iBAAiB,SAChC,WACA,aAAa,OACZ,MAAM,YAAY,eAClB;AACL,cAAM,2BAA2B,MAAM,mBAAmB,SAAY,OAAO,MAAM;AACnF,cAAM,8BAA8B,MAAM;AAC1C,cAAM,2BAA2B,kBAAkB;AACnD,cAAM,wBAAwB;AAE9B,cAAM,6BACL,CAACC,gBAAAA,gBAAgB,MAAM,EAAE,OAAO,6BAChC,CAAC,MAAM,YAAY,gBACnB,MAAM,mBAAmB;AAE1B,YAAI,eAAeC,aAAAA,aAAa;AAEhC,YAAI,4BAA4B;AAC3B,cAAA,CAAC,+BAA+B,0BAA0B;AAC7D;AAAA,UAAA,WACU,+BAA+B,CAAC,0BAA0B;AACpE;AAAA,UAAA;AAAA,QACD;AAGI,aAAA,aAAa,oBAAoB,OAAO,YAAY;AAAA,MAAA;AAAA,IAC1D,CACA;AAAA,EAAA;AAEH;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldOperations.js","sources":["../../../../../../packages/binding-legacy/src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { FieldValue } from '@contember/binding-common'\nimport {\n\tBindingError,\n\tClientGeneratedUuid,\n\tErrorAccessor,\n\tEventListenersStore,\n\tFieldAccessor,\n\tPRIMARY_KEY_NAME,\n\tServerId,\n} from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = 'user' }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\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\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;AAkBO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"FieldOperations.js","sources":["../../../../../../packages/binding-legacy/src/core/operations/FieldOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { FieldValue } from '@contember/binding-common'\nimport {\n\tBindingError,\n\tClientGeneratedUuid,\n\tErrorAccessor,\n\tEventListenersStore,\n\tFieldAccessor,\n\tPRIMARY_KEY_NAME,\n\tServerId,\n} from '@contember/binding-common'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { FieldState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\n\nexport class FieldOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void {\n\t\treturn this.accessorErrorManager.addError(fieldState, error)\n\t}\n\n\tpublic clearErrors(fieldState: FieldState<any>): void {\n\t\treturn this.accessorErrorManager.clearErrorsByState(fieldState)\n\t}\n\n\tpublic addEventListener<\n\t\tType extends keyof FieldAccessor.FieldEventListenerMap,\n\t\tValue extends FieldValue = FieldValue,\n\t>(\n\t\tstate: FieldState<Value>,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\tif (!state.eventListeners) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic updateValue<Value extends FieldValue = FieldValue>(\n\t\tfieldState: FieldState<Value>,\n\t\tnewValue: Value | null,\n\t\t{ agent = 'user' }: FieldAccessor.UpdateOptions = {},\n\t) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst { placeholderName, parent } = fieldState\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME) {\n\t\t\t\tconst entity = fieldState.parent.entity\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (newValue !== fieldState.value && (fieldState.touchLog !== undefined || entity.hasIdSetInStone)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field for the second time. This is prohibited.\\n` +\n\t\t\t\t\t\t\t\t`Once set, it is immutable.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof newValue !== 'string' || !uuidValidate(newValue)) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Invalid value supplied for the '${PRIMARY_KEY_NAME}' field. ` +\n\t\t\t\t\t\t\t\t`Expecting a valid uuid but '${newValue}' was given.\\n` +\n\t\t\t\t\t\t\t\t`Hint: you may use 'FieldAccessor.asUuid.setToUuid()'.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tif (this.treeStore.entityStore.has(ServerId.formatUniqueValue(newValue, entity.entityName))) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Trying to set the '${PRIMARY_KEY_NAME}' field to '${newValue}' which is a valid uuid but is not unique. ` +\n\t\t\t\t\t\t\t\t`It is already in use by an existing entity.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (typeof newValue !== 'string') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tOperationsHelpers.changeEntityId(\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\tentity,\n\t\t\t\t\tnew ClientGeneratedUuid(newValue),\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const field of StateIterator.eachSiblingRealmChild(this.treeStore, fieldState)) {\n\t\t\t\tif (newValue === field.value) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (field.touchLog === undefined) {\n\t\t\t\t\tfield.touchLog = new Set()\n\t\t\t\t}\n\t\t\t\tfield.touchLog.add(agent)\n\t\t\t\tfield.value = newValue\n\n\t\t\t\tconst resolvedValue =\n\t\t\t\t\tfield.fieldMarker.defaultValue === undefined\n\t\t\t\t\t\t? newValue\n\t\t\t\t\t\t: newValue === null\n\t\t\t\t\t\t\t? field.fieldMarker.defaultValue\n\t\t\t\t\t\t\t: newValue\n\t\t\t\tconst normalizedPersistedValue = field.persistedValue === undefined ? null : field.persistedValue\n\t\t\t\tconst hadUnpersistedChangesBefore = field.hasUnpersistedChanges\n\t\t\t\tconst hasUnpersistedChangesNow = resolvedValue !== normalizedPersistedValue\n\t\t\t\tfield.hasUnpersistedChanges = hasUnpersistedChangesNow\n\n\t\t\t\tconst shouldInfluenceUpdateCount =\n\t\t\t\t\t!getEntityMarker(parent).fields.hasAtLeastOneBearingField ||\n\t\t\t\t\t!field.fieldMarker.isNonbearing ||\n\t\t\t\t\tfield.persistedValue !== undefined\n\n\t\t\t\tlet changesDelta = EventManager.NO_CHANGES_DIFFERENCE\n\n\t\t\t\tif (shouldInfluenceUpdateCount) {\n\t\t\t\t\tif (!hadUnpersistedChangesBefore && hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta++\n\t\t\t\t\t} else if (hadUnpersistedChangesBefore && !hasUnpersistedChangesNow) {\n\t\t\t\t\t\tchangesDelta--\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(field, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;AAkBO,MAAM,gBAAgB;AAAA,EACrB,YACW,sBACA,cACA,kBACA,WAChB;AAJgB,SAAA,uBAAA;AACA,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EAAA;AAAA,EAGX,SAAS,YAA6B,OAAwC;AACpF,WAAO,KAAK,qBAAqB,SAAS,YAAY,KAAK;AAAA,EAAA;AAAA,EAGrD,YAAY,YAAmC;AAC9C,WAAA,KAAK,qBAAqB,mBAAmB,UAAU;AAAA,EAAA;AAAA,EAGxD,iBAIN,OACA,OACA,UACa;AACT,QAAA,CAAC,MAAM,gBAAgB;AACpB,YAAA,iBAAiB,IAAI,oBAAoB;AAAA,IAAA;AAEhD,WAAO,MAAM,eAAe,IAAI,OAAO,QAAQ;AAAA,EAAA;AAAA,EAGzC,YACN,YACA,UACA,EAAE,QAAQ,OAAO,IAAiC,IACjD;AACI,SAAA,aAAa,cAAc,MAAM;AAC/B,YAAA,EAAE,iBAAiB,OAAA,IAAW;AACpC,UAAI,oBAAoB,kBAAkB;AACnC,cAAA,SAAS,WAAW,OAAO;AAER;AACxB,cAAI,aAAa,WAAW,UAAU,WAAW,aAAa,UAAa,OAAO,kBAAkB;A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