@contember/binding 1.3.0-alpha.6 → 1.3.0-alpha.8
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/accessorTree/RuntimeId.cjs +5 -5
- package/dist/development/accessorTree/RuntimeId.cjs.map +1 -1
- package/dist/development/accessorTree/RuntimeId.js +5 -5
- package/dist/development/accessorTree/RuntimeId.js.map +1 -1
- package/dist/development/accessors/EntityAccessor.cjs.map +1 -1
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/core/AccessorErrorManager.cjs +1 -1
- package/dist/development/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/development/core/AccessorErrorManager.js +1 -1
- package/dist/development/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/core/Config.cjs +3 -3
- package/dist/development/core/Config.cjs.map +1 -1
- package/dist/development/core/Config.js +3 -3
- package/dist/development/core/Config.js.map +1 -1
- package/dist/development/core/DataBinding.cjs +3 -3
- package/dist/development/core/DataBinding.cjs.map +1 -1
- package/dist/development/core/DataBinding.js +3 -3
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/core/EventManager.cjs.map +1 -1
- package/dist/development/core/EventManager.js.map +1 -1
- package/dist/development/core/MarkerComparator.cjs.map +1 -1
- package/dist/development/core/MarkerComparator.js.map +1 -1
- package/dist/development/core/MarkerMerger.cjs.map +1 -1
- package/dist/development/core/MarkerMerger.js.map +1 -1
- package/dist/development/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/QueryGenerator.cjs.map +1 -1
- package/dist/development/core/QueryGenerator.js.map +1 -1
- package/dist/development/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/development/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/core/StateInitializer.cjs.map +1 -1
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/TreeParameterMerger.cjs.map +1 -1
- package/dist/development/core/TreeParameterMerger.js.map +1 -1
- package/dist/development/core/TreeStore.cjs.map +1 -1
- package/dist/development/core/TreeStore.js.map +1 -1
- package/dist/development/core/VariableInputTransformer.cjs.map +1 -1
- package/dist/development/core/VariableInputTransformer.js.map +1 -1
- package/dist/development/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/development/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/development/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/development/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/core/operations/ListOperations.cjs.map +1 -1
- package/dist/development/core/operations/ListOperations.js.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/core/schema/Schema.cjs.map +1 -1
- package/dist/development/core/schema/Schema.js.map +1 -1
- package/dist/development/dao/Environment.cjs.map +1 -1
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.cjs.map +1 -1
- package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/development/queryLanguage/Parser.cjs +6 -6
- package/dist/development/queryLanguage/Parser.cjs.map +1 -1
- package/dist/development/queryLanguage/Parser.js +6 -6
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/development/queryLanguage/QueryLanguage.cjs +13 -13
- package/dist/development/queryLanguage/QueryLanguage.cjs.map +1 -1
- package/dist/development/queryLanguage/QueryLanguage.js +13 -13
- package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/development/treeParameters/EventListenersStore.cjs.map +1 -1
- package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/development/utils/TreeNodeUtils.cjs.map +1 -1
- package/dist/development/utils/TreeNodeUtils.js.map +1 -1
- package/dist/development/utils/assert.cjs.map +1 -1
- package/dist/development/utils/assert.js.map +1 -1
- package/dist/development/utils/ucfirst.cjs.map +1 -1
- package/dist/development/utils/ucfirst.js.map +1 -1
- package/dist/production/accessorTree/RuntimeId.cjs +5 -5
- package/dist/production/accessorTree/RuntimeId.cjs.map +1 -1
- package/dist/production/accessorTree/RuntimeId.js +5 -5
- package/dist/production/accessorTree/RuntimeId.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.cjs.map +1 -1
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/core/AccessorErrorManager.cjs +1 -1
- package/dist/production/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/production/core/AccessorErrorManager.js +1 -1
- package/dist/production/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/core/Config.cjs +3 -3
- package/dist/production/core/Config.cjs.map +1 -1
- package/dist/production/core/Config.js +3 -3
- package/dist/production/core/Config.js.map +1 -1
- package/dist/production/core/DataBinding.cjs +3 -3
- package/dist/production/core/DataBinding.cjs.map +1 -1
- package/dist/production/core/DataBinding.js +3 -3
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/core/EventManager.cjs.map +1 -1
- package/dist/production/core/EventManager.js.map +1 -1
- package/dist/production/core/MarkerComparator.cjs.map +1 -1
- package/dist/production/core/MarkerComparator.js.map +1 -1
- package/dist/production/core/MarkerMerger.cjs.map +1 -1
- package/dist/production/core/MarkerMerger.js.map +1 -1
- package/dist/production/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/QueryGenerator.cjs.map +1 -1
- package/dist/production/core/QueryGenerator.js.map +1 -1
- package/dist/production/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/production/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/core/StateInitializer.cjs.map +1 -1
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/TreeParameterMerger.cjs.map +1 -1
- package/dist/production/core/TreeParameterMerger.js.map +1 -1
- package/dist/production/core/TreeStore.cjs.map +1 -1
- package/dist/production/core/TreeStore.js.map +1 -1
- package/dist/production/core/VariableInputTransformer.cjs.map +1 -1
- package/dist/production/core/VariableInputTransformer.js.map +1 -1
- package/dist/production/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/production/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/production/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/core/operations/ListOperations.cjs.map +1 -1
- package/dist/production/core/operations/ListOperations.js.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/core/schema/Schema.cjs.map +1 -1
- package/dist/production/core/schema/Schema.js.map +1 -1
- package/dist/production/dao/Environment.cjs.map +1 -1
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.cjs.map +1 -1
- package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
- package/dist/production/queryLanguage/Parser.cjs +6 -6
- package/dist/production/queryLanguage/Parser.cjs.map +1 -1
- package/dist/production/queryLanguage/Parser.js +6 -6
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/production/queryLanguage/QueryLanguage.cjs +13 -13
- package/dist/production/queryLanguage/QueryLanguage.cjs.map +1 -1
- package/dist/production/queryLanguage/QueryLanguage.js +13 -13
- package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
- package/dist/production/treeParameters/EventListenersStore.cjs.map +1 -1
- package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
- package/dist/production/utils/TreeNodeUtils.cjs.map +1 -1
- package/dist/production/utils/TreeNodeUtils.js.map +1 -1
- package/dist/production/utils/assert.cjs.map +1 -1
- package/dist/production/utils/assert.js.map +1 -1
- package/dist/production/utils/ucfirst.cjs.map +1 -1
- package/dist/production/utils/ucfirst.js.map +1 -1
- package/dist/types/accessors/EntityAccessor.d.ts +2 -2
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/treeParameters/EventListenersStore.d.ts +2 -1
- package/dist/types/treeParameters/EventListenersStore.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/accessors/EntityAccessor.ts +2 -2
- package/src/treeParameters/EventListenersStore.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { EntityFieldMarkers, HasManyRelationMarker, HasOneRelationMarker, PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tHasManyRelation,\n\tHasOneRelation,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\nimport { getEntityMarker } from '../core/state'\nimport { TreeNodeUtils } from '../utils/TreeNodeUtils'\nimport { PlaceholderParametersGenerator } from '../markers/PlaceholderParametersGenerator'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly state: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {\n\t}\n\n\tpublic get idOnServer(): EntityId | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.state, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.state, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.state, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.state)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\tconst entity = this.getRelativeSingleEntity(field)\n\t\tconst fieldPlaceholder = PlaceholderGenerator.getFieldPlaceholder(field.field)\n\t\tconst accessor = entity.fieldData.get(fieldPlaceholder)\n\t\tif (accessor) {\n\t\t\treturn accessor.getAccessor() as FieldAccessor<Value>\n\t\t}\n\n\t\tTreeNodeUtils.resolveColumn(entity.environment, field.field)\n\n\t\tthrow new BindingError(''\n\t\t\t+ 'EntityAccessor: cannot access field '\n\t\t\t+ `'${field.field}' on ${TreeNodeUtils.describeLocation(entity.environment)}.\\n`\n\t\t\t+ 'The cause of the error is that this relation has not been registered during the static rendering process. As a result, it lacks a required marker and accessor.',\n\t\t)\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\tconst fieldPlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation)\n\t\t\tconst accessor = relativeTo.fieldData.get(fieldPlaceholder)\n\t\t\tif (!accessor) {\n\t\t\t\treturn this.raiseInvalidHasOneRelationError(relativeTo, hasOneRelation)\n\t\t\t}\n\n\t\t\trelativeTo = accessor.getAccessor() as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\tconst entity = this.getRelativeSingleEntity(entityList)\n\t\tconst fieldPlaceholder = PlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation)\n\t\tconst accessor = entity.fieldData.get(fieldPlaceholder)\n\t\tif (!accessor) {\n\t\t\treturn this.raiseInvalidHasManyRelationError(entity, entityList.hasManyRelation)\n\t\t}\n\n\t\treturn accessor.getAccessor() as EntityListAccessor\n\t}\n\n\tprivate raiseInvalidHasOneRelationError(relativeTo: EntityAccessor, hasOneRelation: HasOneRelation): never {\n\t\tTreeNodeUtils.resolveHasOneRelation(relativeTo.environment, hasOneRelation.field, !!hasOneRelation.reducedBy)\n\n\t\tconst entityMarker = relativeTo.getMarker()\n\t\tconst possibleMarkers = this.getMarkersOfType(entityMarker.fields.markers, HasOneRelationMarker, hasOneRelation.field)\n\t\tconst markerParams = possibleMarkers.map(it => PlaceholderParametersGenerator.createHasOneRelationParameters(it.parameters))\n\n\t\tconst relationParams = PlaceholderParametersGenerator.createHasOneRelationParameters(hasOneRelation)\n\n\t\tthis.raiseUndefinedRelationError(hasOneRelation.field, relativeTo.environment, relationParams, markerParams)\n\t}\n\n\tprivate raiseInvalidHasManyRelationError(entity: EntityAccessor, hasManyRelation: HasManyRelation): never {\n\t\tTreeNodeUtils.resolveHasManyRelation(entity.environment, hasManyRelation.field)\n\n\t\tconst entityMarker = entity.getMarker()\n\t\tconst possibleMarkers = this.getMarkersOfType(entityMarker.fields.markers, HasManyRelationMarker, hasManyRelation.field)\n\t\tconst markerParams = possibleMarkers.map(it => PlaceholderParametersGenerator.createHasManyRelationParameters(it.parameters))\n\n\t\tconst relationParams = PlaceholderParametersGenerator.createHasManyRelationParameters(hasManyRelation)\n\n\t\tthis.raiseUndefinedRelationError(hasManyRelation.field, entity.environment, relationParams, markerParams)\n\t}\n\n\tprivate raiseUndefinedRelationError(field: string, environment: Environment, relationParams: any, otherMarkersParams: any[]): never {\n\t\tconst hint = this.createHintMessage(otherMarkersParams)\n\t\tthrow new BindingError(''\n\t\t\t+ `EntityAccessor: cannot access relation `\n\t\t\t+ `'${field}' on ${TreeNodeUtils.describeLocation(environment)}.\\n`\n\t\t\t+ 'The cause of the error is that this relation has not been registered during the static rendering process. As a result, it lacks a required marker and accessor.\\n\\n'\n\t\t\t+ 'Provided parameters:\\n'\n\t\t\t+ JSON.stringify(relationParams)\n\t\t\t+ hint,\n\t\t)\n\t}\n\n\tprivate createHintMessage(params: any[]): string {\n\t\tif (params.length === 0) {\n\t\t\treturn ''\n\t\t}\n\n\t\tconst serializedParams = params.map(it => JSON.stringify(it)).join('\\n')\n\t\tconst message = params.length === 1\n\t\t\t? 'However, there is existing marker for the same field, but it have different parameters:'\n\t\t\t: 'However, there are existing markers for the same field, but they have different parameters:'\n\n\t\treturn `\\n\\n${message}\\n${serializedParams}`\n\t}\n\n\tprivate getMarkersOfType<T extends { new(...args: any[]): HasManyRelationMarker | HasOneRelationMarker }>(\n\t\tmarkers: EntityFieldMarkers,\n\t\tmarkerConstructor: T,\n\t\tfieldName: string,\n\t): InstanceType<T>[] {\n\t\treturn Array.from(markers.values())\n\t\t\t.filter((it): it is InstanceType<T> => (it instanceof markerConstructor) && it.parameters.field === fieldName)\n\t}\n\n\tpublic getParent(): EntityAccessor | EntityListAccessor | undefined {\n\t\tconst blueprint = this.state.blueprint\n\t\tif (blueprint.type === 'subTree') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprint.parent.getAccessor()\n\t}\n\n\tpublic getMarker() {\n\t\treturn getEntityMarker(this.state)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor<any>\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;;;;;AAkCA,MAAM,eAAoC;AAAA,EAClC,YACW,OACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACD,SAAA,MAAA;AACA,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,iBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EAEjB;AAAA,EAEA,IAAW,aAAmC;AAC7C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEA,IAAW,iBAA0B;AACpC,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA;AAAA,EAIO,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAChF;AAAA,EAEO,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EACpE;AAAA,EAEO,aAAa,gBAA0D;AAC7E,SAAK,WAAW,aAAa,KAAK,OAAO,cAAc;AAAA,EACxD;AAAA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G,UAAU,CAAC;AAEtH,UAAA,iBAAiB,+BAA+B,gCAAgC,eAAe;AAErG,SAAK,4BAA4B,gBAAgB,OAAO,OAAO,aAAa,gBAAgB,YAAY;AAAA,EACzG;AAAA,EAEQ,4BAA4B,OAAe,aAA0B,gBAAqB,oBAAkC;AAC7H,UAAA,OAAO,KAAK,kBAAkB,kBAAkB;AACtD,UAAM,IAAI;AAAA,MAAa,2CAEhB,aAAa,cAAc,iBAAiB,WAAW;AAAA;AAAA;AAAA;AAAA,IAG3D,KAAK,UAAU,cAAc,IAC7B;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEQ,kBAAkB,QAAuB;AAC5C,QAAA,OAAO,WAAW,GAAG;AACjB,aAAA;AAAA,IACR;AAEM,UAAA,mBAAmB,OAAO,IAAI,CAAM,OAAA,KAAK,UAAU,EAAE,CAAC,EAAE,KAAK,IAAI;AACvE,UAAM,UAAU,OAAO,WAAW,IAC/B,4FACA;AAEI,WAAA;AAAA;AAAA,EAAO;AAAA,EAAY;AAAA,EAC3B;AAAA,EAEQ,iBACP,SACA,mBACA,WACoB;AACpB,WAAO,MAAM,KAAK,QAAQ,OAAQ,CAAA,EAChC,OAAO,CAAC,OAA+B,cAAc,qBAAsB,GAAG,WAAW,UAAU,SAAS;AAAA,EAC/G;AAAA,EAEO,YAA6D;AAC7D,UAAA,YAAY,KAAK,MAAM;AACzB,QAAA,UAAU,SAAS,WAAW;AAC1B,aAAA;AAAA,IACR;AACO,WAAA,UAAU,OAAO;EACzB;AAAA,EAEO,YAAY;AACX,WAAA,gBAAgB,KAAK,KAAK;AAAA,EAClC;AACD;"}
|
|
1
|
+
{"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { EntityFieldMarkers, HasManyRelationMarker, HasOneRelationMarker, PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tHasManyRelation,\n\tHasOneRelation,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\nimport { getEntityMarker } from '../core/state'\nimport { TreeNodeUtils } from '../utils/TreeNodeUtils'\nimport { PlaceholderParametersGenerator } from '../markers/PlaceholderParametersGenerator'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly state: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {\n\t}\n\n\tpublic get idOnServer(): EntityId | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.state, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.state, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.state, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.state)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\tconst entity = this.getRelativeSingleEntity(field)\n\t\tconst fieldPlaceholder = PlaceholderGenerator.getFieldPlaceholder(field.field)\n\t\tconst accessor = entity.fieldData.get(fieldPlaceholder)\n\t\tif (accessor) {\n\t\t\treturn accessor.getAccessor() as FieldAccessor<Value>\n\t\t}\n\n\t\tTreeNodeUtils.resolveColumn(entity.environment, field.field)\n\n\t\tthrow new BindingError(''\n\t\t\t+ 'EntityAccessor: cannot access field '\n\t\t\t+ `'${field.field}' on ${TreeNodeUtils.describeLocation(entity.environment)}.\\n`\n\t\t\t+ 'The cause of the error is that this relation has not been registered during the static rendering process. As a result, it lacks a required marker and accessor.',\n\t\t)\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\tconst fieldPlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation)\n\t\t\tconst accessor = relativeTo.fieldData.get(fieldPlaceholder)\n\t\t\tif (!accessor) {\n\t\t\t\treturn this.raiseInvalidHasOneRelationError(relativeTo, hasOneRelation)\n\t\t\t}\n\n\t\t\trelativeTo = accessor.getAccessor() as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\tconst entity = this.getRelativeSingleEntity(entityList)\n\t\tconst fieldPlaceholder = PlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation)\n\t\tconst accessor = entity.fieldData.get(fieldPlaceholder)\n\t\tif (!accessor) {\n\t\t\treturn this.raiseInvalidHasManyRelationError(entity, entityList.hasManyRelation)\n\t\t}\n\n\t\treturn accessor.getAccessor() as EntityListAccessor\n\t}\n\n\tprivate raiseInvalidHasOneRelationError(relativeTo: EntityAccessor, hasOneRelation: HasOneRelation): never {\n\t\tTreeNodeUtils.resolveHasOneRelation(relativeTo.environment, hasOneRelation.field, !!hasOneRelation.reducedBy)\n\n\t\tconst entityMarker = relativeTo.getMarker()\n\t\tconst possibleMarkers = this.getMarkersOfType(entityMarker.fields.markers, HasOneRelationMarker, hasOneRelation.field)\n\t\tconst markerParams = possibleMarkers.map(it => PlaceholderParametersGenerator.createHasOneRelationParameters(it.parameters))\n\n\t\tconst relationParams = PlaceholderParametersGenerator.createHasOneRelationParameters(hasOneRelation)\n\n\t\tthis.raiseUndefinedRelationError(hasOneRelation.field, relativeTo.environment, relationParams, markerParams)\n\t}\n\n\tprivate raiseInvalidHasManyRelationError(entity: EntityAccessor, hasManyRelation: HasManyRelation): never {\n\t\tTreeNodeUtils.resolveHasManyRelation(entity.environment, hasManyRelation.field)\n\n\t\tconst entityMarker = entity.getMarker()\n\t\tconst possibleMarkers = this.getMarkersOfType(entityMarker.fields.markers, HasManyRelationMarker, hasManyRelation.field)\n\t\tconst markerParams = possibleMarkers.map(it => PlaceholderParametersGenerator.createHasManyRelationParameters(it.parameters))\n\n\t\tconst relationParams = PlaceholderParametersGenerator.createHasManyRelationParameters(hasManyRelation)\n\n\t\tthis.raiseUndefinedRelationError(hasManyRelation.field, entity.environment, relationParams, markerParams)\n\t}\n\n\tprivate raiseUndefinedRelationError(field: string, environment: Environment, relationParams: any, otherMarkersParams: any[]): never {\n\t\tconst hint = this.createHintMessage(otherMarkersParams)\n\t\tthrow new BindingError(''\n\t\t\t+ `EntityAccessor: cannot access relation `\n\t\t\t+ `'${field}' on ${TreeNodeUtils.describeLocation(environment)}.\\n`\n\t\t\t+ 'The cause of the error is that this relation has not been registered during the static rendering process. As a result, it lacks a required marker and accessor.\\n\\n'\n\t\t\t+ 'Provided parameters:\\n'\n\t\t\t+ JSON.stringify(relationParams)\n\t\t\t+ hint,\n\t\t)\n\t}\n\n\tprivate createHintMessage(params: any[]): string {\n\t\tif (params.length === 0) {\n\t\t\treturn ''\n\t\t}\n\n\t\tconst serializedParams = params.map(it => JSON.stringify(it)).join('\\n')\n\t\tconst message = params.length === 1\n\t\t\t? 'However, there is existing marker for the same field, but it have different parameters:'\n\t\t\t: 'However, there are existing markers for the same field, but they have different parameters:'\n\n\t\treturn `\\n\\n${message}\\n${serializedParams}`\n\t}\n\n\tprivate getMarkersOfType<T extends { new(...args: any[]): HasManyRelationMarker | HasOneRelationMarker }>(\n\t\tmarkers: EntityFieldMarkers,\n\t\tmarkerConstructor: T,\n\t\tfieldName: string,\n\t): InstanceType<T>[] {\n\t\treturn Array.from(markers.values())\n\t\t\t.filter((it): it is InstanceType<T> => (it instanceof markerConstructor) && it.parameters.field === fieldName)\n\t}\n\n\tpublic getParent(): EntityAccessor | EntityListAccessor | undefined {\n\t\tconst blueprint = this.state.blueprint\n\t\tif (blueprint.type === 'subTree') {\n\t\t\treturn undefined\n\t\t}\n\t\treturn blueprint.parent.getAccessor()\n\t}\n\n\tpublic getMarker() {\n\t\treturn getEntityMarker(this.state)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor<any>\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | BeforePersistHandler | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | PersistSuccessHandler | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;;;;;AAkCA,MAAM,eAAoC;AAAA,EAClC,YACW,OACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACA,SAAA,YAAA;AACD,SAAA,MAAA;AACA,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,iBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAAA,EAEjB;AAAA,EAEA,IAAW,aAAmC;AAC7C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKA,IAAW,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA,EACvB;AAAA,EAEA,IAAW,iBAA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A,UAAU,SAAS,WAAW;AAC1B,aAAA;AAAA,IACR;AACO,WAAA,UAAU,OAAO;EACzB;AAAA,EAEO,YAAY;AACX,WAAA,gBAAgB,KAAK,KAAK;AAAA,EAClC;AACD;"}
|
|
@@ -13,7 +13,7 @@ const getEntityMarker = require("./state/getEntityMarker.cjs");
|
|
|
13
13
|
class AccessorErrorManager {
|
|
14
14
|
constructor(eventManager, treeStore) {
|
|
15
15
|
__publicField(this, "errorsByState", /* @__PURE__ */ new Map());
|
|
16
|
-
__publicField(this, "getNewErrorId", (() => {
|
|
16
|
+
__publicField(this, "getNewErrorId", /* @__PURE__ */ (() => {
|
|
17
17
|
let errorId = 1;
|
|
18
18
|
return () => errorId++;
|
|
19
19
|
})());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessorErrorManager.cjs","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { DataBindingTransactionResult } from './DataBinding'\nimport { MutationError, ValidationError } from '@contember/client'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: DataBindingTransactionResult, operations: SubMutationOperation[]) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data, operations)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (typeof childKey !== 'string') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\t// unwrap for reduced has many\n\t\t\t\t\t\tif (child.nodeType === 'iNode' && child.children.has(fieldState.entity.id.value)) {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child.children.get(fieldState.entity.id.value)!)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: DataBindingTransactionResult) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data.data) {\n\t\t\tconst treeDatum = data.data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<MutationError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: MutationError | ValidationError) => {\n\t\t\t\tconst path = 'paths' in error ? (error.paths[0] ?? []) : error.path\n\t\t\t\treturn {\n\t\t\t\t\tpath: path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif ('field' in pathPart) {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["EventManager","ErrorsPrepr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gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"AccessorErrorManager.cjs","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { DataBindingTransactionResult } from './DataBinding'\nimport { MutationError, ValidationError } from '@contember/client'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: DataBindingTransactionResult, operations: SubMutationOperation[]) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data, operations)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (typeof childKey !== 'string') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\t// unwrap for reduced has many\n\t\t\t\t\t\tif (child.nodeType === 'iNode' && child.children.has(fieldState.entity.id.value)) {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child.children.get(fieldState.entity.id.value)!)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: DataBindingTransactionResult) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data.data) {\n\t\t\tconst treeDatum = data.data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<MutationError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: MutationError | ValidationError) => {\n\t\t\t\tconst path = 'paths' in error ? (error.paths[0] ?? []) : error.path\n\t\t\t\treturn {\n\t\t\t\t\tpath: path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif ('field' in pathPart) {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["EventManager","ErrorsPreprocessor","ErrorAccessor","errorsById","getEntityMarker"],"mappings":";;;;;;;;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,yCAAuB,uBAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA;AAGsB,SAAA,eAAA;AAA6C,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEjG,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAC7B;AAAA,EAEO,YAAmC;AACzC,WAAO,MAAM,KAAK,KA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AQ;AAAA,MACzC;AAEI,UAAA,WAAW,aAAa,SAAS;AAC/B,aAAA,qBAAqB,YAAgC,UAAU;AAAA,MACrE;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,cAAc,MAAoC;AAE9C,eAAA,sBAAsB,KAAK,MAAM;AACrC,YAAA,YAAY,KAAK,KAAK,kBAAkB;AAC9C,YAAM,kBAA0D,UAAU;AACpE,YAAA,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,MAAM,IAClD;AACH,YAAM,mBAAmB,UAAU,IAAI,CAAC,UAA2C;AAC5E,cAAA,OAAO,WAAW,QAAS,MAAM,MAAM,CAAC,KAAK,CAAA,IAAM,MAAM;AACxD,eAAA;AAAA,UACN,MAAM,KACJ,IAAI,CAAY,aAAA;AAChB,gBAAI,WAAW,UAAU;AACxB,qBAAO,SAAS;AAAA,YACjB;AACA,gBAAI,SAAS,OAAO;AACnB,qBAAO,IAAI,SAAS,KAAK,IAAI,SAAS,KAAK;AAAA,YAC5C;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;;"}
|
|
@@ -11,7 +11,7 @@ import { getEntityMarker } from "./state/getEntityMarker.js";
|
|
|
11
11
|
class AccessorErrorManager {
|
|
12
12
|
constructor(eventManager, treeStore) {
|
|
13
13
|
__publicField(this, "errorsByState", /* @__PURE__ */ new Map());
|
|
14
|
-
__publicField(this, "getNewErrorId", (() => {
|
|
14
|
+
__publicField(this, "getNewErrorId", /* @__PURE__ */ (() => {
|
|
15
15
|
let errorId = 1;
|
|
16
16
|
return () => errorId++;
|
|
17
17
|
})());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { DataBindingTransactionResult } from './DataBinding'\nimport { MutationError, ValidationError } from '@contember/client'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: DataBindingTransactionResult, operations: SubMutationOperation[]) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data, operations)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (typeof childKey !== 'string') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\t// unwrap for reduced has many\n\t\t\t\t\t\tif (child.nodeType === 'iNode' && child.children.has(fieldState.entity.id.value)) {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child.children.get(fieldState.entity.id.value)!)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: DataBindingTransactionResult) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data.data) {\n\t\t\tconst treeDatum = data.data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<MutationError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: MutationError | ValidationError) => {\n\t\t\t\tconst path = 'paths' in error ? (error.paths[0] ?? []) : error.path\n\t\t\t\treturn {\n\t\t\t\t\tpath: path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif ('field' in pathPart) {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["errorsById"],"mappings":";;;;;;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,0CAAiB,MAAM;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA;AAGsB,SAAA,eAAA;AAA6C,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEjG,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAC7B;AAAA,EAEO,YAAmC;AACzC,WAAO,MAAM,KAAK,KAAK,cAAc,OAAU,GAAA,CAAA,OAAM,MAAM,KAAK,GAAG,OAAQ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A,EACD;AAAA,EAEQ,cAAc,MAAoC;AAE9C,eAAA,sBAAsB,KAAK,MAAM;AACrC,YAAA,YAAY,KAAK,KAAK,kBAAkB;AAC9C,YAAM,kBAA0D,UAAU;AACpE,YAAA,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,MAAM,IAClD;AACH,YAAM,mBAAmB,UAAU,IAAI,CAAC,UAA2C;AAC5E,cAAA,OAAO,WAAW,QAAS,MAAM,MAAM,CAAC,KAAK,CAAA,IAAM,MAAM;AACxD,eAAA;AAAA,UACN,MAAM,KACJ,IAAI,CAAY,aAAA;AAChB,gBAAI,WAAW,UAAU;AACxB,qBAAO,SAAS;AAAA,YACjB;AACA,gBAAI,SAAS,OAAO;AACZ,qBAAA,IAAI,SAAS,SAAS,SAAS;AAAA,YACvC;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { DataBindingTransactionResult } from './DataBinding'\nimport { MutationError, ValidationError } from '@contember/client'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: DataBindingTransactionResult, operations: SubMutationOperation[]) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data, operations)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\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\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (typeof childKey !== 'string') {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\t// unwrap for reduced has many\n\t\t\t\t\t\tif (child.nodeType === 'iNode' && child.children.has(fieldState.entity.id.value)) {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child.children.get(fieldState.entity.id.value)!)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: DataBindingTransactionResult) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data.data) {\n\t\t\tconst treeDatum = data.data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<MutationError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: MutationError | ValidationError) => {\n\t\t\t\tconst path = 'paths' in error ? (error.paths[0] ?? []) : error.path\n\t\t\t\treturn {\n\t\t\t\t\tpath: path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif ('field' in pathPart) {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["errorsById"],"mappings":";;;;;;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAR/F,6DAA8D;AAE9D,yCAAuB,uBAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA;AAGsB,SAAA,eAAA;AAA6C,SAAA,YAAA;AAAA,EAAuB;AAAA,EAEjG,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAC7B;AAAA,EAEO,YAAmC;AACzC,WAAO,MAAM,KAAK,KAAK,cAAc,OAAU,GAAA,CAAA,OAAM,MAAM,KAAK,GAAG,OAAQ,CAAA,CAAC,EAAE,KAAK;AAAA,EACpF;AAAA,EAEO,cAAc;AACf,SAAA,aAAa,cAAc,MAAM;AACrC,iBAAW,CAAC,SAAS,KAAK,KAAK,eAAe;AAC7C,kBAAU,SAAS;AACnB,aAAK,aAAa,oBAAoB,WAAW,aAAa,qBAAqB;AAAA,MACpF;AACA,WAAK,cAAc;IAAM,CACzB;AAAA,EACF;AAAA,EAEO,mBAAmB,OAAwB;AAC1C,WAAA,KAAK,aAAa,cAAc,MAAM;AAC5C,UAAI,CAAC,KAAK,cAAc,IAAI,KAAK,GAAG;AACnC;AAAA,MACD;AACK,WAAA,cAAc,OAAO,KAAK;AAC/B,YAAM,SAAS;AACf,WAAK,aAAa,oBAAoB,OAAO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AO;AACnB,qBAAO,IAAI,SAAS,KAAK,IAAI,SAAS,KAAK;AAAA,YAC5C;AACA,mBAAO,SAAS;AAAA,UAAA,CAChB,EACA,KAAK,GAAG;AAAA,UACV,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA,QAAA;AAAA,MAC7E,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AACzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AACA,UAAI,UAAU,cAAc;AACnB,gBAAA,MAAM,UAAU,YAAY;AAAA,MACrC;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
return value;
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
9
|
-
const _Config = class {
|
|
9
|
+
const _Config = class _Config {
|
|
10
10
|
constructor(config = {}) {
|
|
11
11
|
__publicField(this, "config");
|
|
12
12
|
this.config = {
|
|
@@ -22,11 +22,11 @@ const _Config = class {
|
|
|
22
22
|
return this;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
__publicField(Config, "defaultConfig", {
|
|
25
|
+
__publicField(_Config, "defaultConfig", {
|
|
27
26
|
beforePersistSettleLimit: 20,
|
|
28
27
|
beforeUpdateSettleLimit: 20,
|
|
29
28
|
persistSuccessSettleLimit: 20
|
|
30
29
|
});
|
|
30
|
+
let Config = _Config;
|
|
31
31
|
exports.Config = Config;
|
|
32
32
|
//# sourceMappingURL=Config.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.cjs","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAEO,MAAM,UAAN,
|
|
1
|
+
{"version":3,"file":"Config.cjs","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;AAEO,MAAM,UAAN,MAAM,QAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAC3E,WAAA,KAAK,OAAO,IAAI;AAAA,EACxB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC1F,SAAA,OAAO,IAAI,IAAI;AACb,WAAA;AAAA,EACR;AACD;AAvBC,cADY,SACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA;AAJtB,IAAM,SAAN;;"}
|
|
@@ -4,7 +4,7 @@ var __publicField = (obj, key, value) => {
|
|
|
4
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
|
-
const _Config = class {
|
|
7
|
+
const _Config = class _Config {
|
|
8
8
|
constructor(config = {}) {
|
|
9
9
|
__publicField(this, "config");
|
|
10
10
|
this.config = {
|
|
@@ -20,12 +20,12 @@ const _Config = class {
|
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
__publicField(Config, "defaultConfig", {
|
|
23
|
+
__publicField(_Config, "defaultConfig", {
|
|
25
24
|
beforePersistSettleLimit: 20,
|
|
26
25
|
beforeUpdateSettleLimit: 20,
|
|
27
26
|
persistSuccessSettleLimit: 20
|
|
28
27
|
});
|
|
28
|
+
let Config = _Config;
|
|
29
29
|
export {
|
|
30
30
|
Config
|
|
31
31
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,MAAM,UAAN,
|
|
1
|
+
{"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,MAAM,UAAN,MAAM,QAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAC3E,WAAA,KAAK,OAAO,IAAI;AAAA,EACxB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC1F,SAAA,OAAO,IAAI,IAAI;AACb,WAAA;AAAA,EACR;AACD;AAvBC,cADY,SACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA;AAJtB,IAAM,SAAN;"}
|
|
@@ -24,7 +24,7 @@ const getCombinedSignal = require("./utils/getCombinedSignal.cjs");
|
|
|
24
24
|
const StateIterator = require("./state/StateIterator.cjs");
|
|
25
25
|
const assertNever = require("../utils/assertNever.cjs");
|
|
26
26
|
const generateEnumerabilityPreventingEntropy = require("../utils/generateEnumerabilityPreventingEntropy.cjs");
|
|
27
|
-
const _DataBinding = class {
|
|
27
|
+
const _DataBinding = class _DataBinding {
|
|
28
28
|
// private treeRootListeners: {
|
|
29
29
|
// eventListeners: {}
|
|
30
30
|
// } = {
|
|
@@ -341,11 +341,11 @@ const _DataBinding = class {
|
|
|
341
341
|
return this.treeStore.markerTrees.size === 0 ? void 0 : `${generateEnumerabilityPreventingEntropy.generateEnumerabilityPreventingEntropy()}-${_DataBinding.getNextTreeRootIdSeed()}`;
|
|
342
342
|
}
|
|
343
343
|
};
|
|
344
|
-
|
|
345
|
-
__publicField(DataBinding, "getNextTreeRootIdSeed", (() => {
|
|
344
|
+
__publicField(_DataBinding, "getNextTreeRootIdSeed", /* @__PURE__ */ (() => {
|
|
346
345
|
let seed = 1;
|
|
347
346
|
return () => seed++;
|
|
348
347
|
})());
|
|
348
|
+
let DataBinding = _DataBinding;
|
|
349
349
|
const DataBindingExtendAborted = Symbol("aborted");
|
|
350
350
|
exports.DataBinding = DataBinding;
|
|
351
351
|
exports.DataBindingExtendAborted = DataBindingExtendAborted;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.cjs","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import {\n\tContentClient,\n\tContentQueryBuilder,\n\tGraphQlClient,\n\tGraphQlClientError,\n\tMutationResult,\n\tTransactionResult,\n\tTreeFilter,\n} from '@contember/client'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport { ErrorPersistResult, ReceivedDataTree, ReceivedEntityData, SuccessfulPersistResult } from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from './utils/createQueryBuilder'\n\nexport type DataBindingTransactionResult = TransactionResult<Record<string, MutationResult<ReceivedEntityData>>>\n\nexport class DataBinding<Node> {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations<Node>\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly queryBuilder: ContentQueryBuilder\n\tprivate readonly contentClient: ContentClient\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly createMarkerTree: (node: Node, environment: Environment) => MarkerTreeRoot,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor<Node>, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onError: (error: GraphQlClientError, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding<Node>) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t\tthis.batchedUpdates,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations<Node>>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t\tthis.queryBuilder = createQueryBuilder(this.environment.getSchema())\n\t\tthis.contentClient = new ContentClient(contentApiClient)\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore, this.queryBuilder)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { mutations, operations } = mutationResult\n\n\t\t\tlet response: DataBindingTransactionResult\n\t\t\ttry {\n\t\t\t\tresponse = await this.contentClient.mutate(this.queryBuilder.transaction(mutations, {\n\t\t\t\t\tdeferForeignKeyConstraints: true,\n\t\t\t\t}), {\n\t\t\t\t\tsignal,\n\t\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t\tthis.persistFail({\n\t\t\t\t\t\terrors: [e],\n\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (Object.values(response.data).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(response, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (response.errorMessage) {\n\t\t\t\t\tconsole.error(response.errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(response, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: DataBindingTransactionResult, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData.data).map(it => it.node?.id).filter((id): id is EntityId => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData.data).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor<Node>(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: Node\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: Node, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = this.createMarkerTree(newFragment, options.environment ?? this.environment)\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\ttry {\n\t\t\treturn await this.contentClient.query(query, {\n\t\t\t\tsignal,\n\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t},\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\tif (e.type === 'aborted') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.onError(e, this)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["TreeRootAccessor","Config","createBatchUpdatesOptions","DirtinessTracker","EventManager","AccessorErrorManager","StateInitializer","TreeAugmenter","TreeFilterGenerator","options","createQueryBuilder","ContentClient","MutationGenerator","GraphQlClientError","MarkerMerger","getCombinedSignal","QueryGenerator","query","StateIterator","assertNever","generateEnumerabilityPreventingEntropy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,eAAN,MAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAhCe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAIA,iBAAA,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQ/G;AAAA;AAAA;AAAA;AAAA,iEAOC;AA9MS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,YAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AACA,SAAA,UAAA;AAIZ,SAAA,SAAS,IAAIC,OAAAA;AAClB,SAAK,sBAAsBC,0BAAA,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2B;AAAA,MAC/B,GAAG,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA,IAAA;AAEV,SAAA,mBAA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SAAS,GAAG;AACxE,mBAAW,SAASA,cAAAA,cAAc,mBAAmB,SAAS,GAAG;AAChE,kBAAQ,MAAM,MAAM;AAAA,YACnB,KAAK,SAAS;AACb,kBAAI,MAAM,yBAAyB,MAAM,UAAU,MAAM;AACxD,sBAAM,UAAU;AAChB,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAOd,aAAA,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA,KAAK;AACJ,kBAAI,MAAM,0BAA0B,KAAK,MAAM,iBAAiB,MAAM;AACrE,sBAAM,0BAA0B;AAChC,sBAAM,iBAAiB;AACvB,qBAAK,aAAa,oBAAoB,OAAOA,aAAA,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD,KAAK,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAOA,aAAA,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA;AACCe,0BAAAA,YAAiB;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAGC,uCAAAA,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AAhYO,IAAM,cAAN;AAoXN,cApXY,aAoXG,0BAAyB,MAAM;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;;;"}
|
|
1
|
+
{"version":3,"file":"DataBinding.cjs","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import {\n\tContentClient,\n\tContentQueryBuilder,\n\tGraphQlClient,\n\tGraphQlClientError,\n\tMutationResult,\n\tTransactionResult,\n\tTreeFilter,\n} from '@contember/client'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport { ErrorPersistResult, ReceivedDataTree, ReceivedEntityData, SuccessfulPersistResult } from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from './utils/createQueryBuilder'\n\nexport type DataBindingTransactionResult = TransactionResult<Record<string, MutationResult<ReceivedEntityData>>>\n\nexport class DataBinding<Node> {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations<Node>\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly queryBuilder: ContentQueryBuilder\n\tprivate readonly contentClient: ContentClient\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly createMarkerTree: (node: Node, environment: Environment) => MarkerTreeRoot,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor<Node>, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onError: (error: GraphQlClientError, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding<Node>) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t\tthis.batchedUpdates,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations<Node>>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t\tthis.queryBuilder = createQueryBuilder(this.environment.getSchema())\n\t\tthis.contentClient = new ContentClient(contentApiClient)\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore, this.queryBuilder)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { mutations, operations } = mutationResult\n\n\t\t\tlet response: DataBindingTransactionResult\n\t\t\ttry {\n\t\t\t\tresponse = await this.contentClient.mutate(this.queryBuilder.transaction(mutations, {\n\t\t\t\t\tdeferForeignKeyConstraints: true,\n\t\t\t\t}), {\n\t\t\t\t\tsignal,\n\t\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t\tthis.persistFail({\n\t\t\t\t\t\terrors: [e],\n\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (Object.values(response.data).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(response, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (response.errorMessage) {\n\t\t\t\t\tconsole.error(response.errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(response, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: DataBindingTransactionResult, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData.data).map(it => it.node?.id).filter((id): id is EntityId => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData.data).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor<Node>(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: Node\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: Node, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = this.createMarkerTree(newFragment, options.environment ?? this.environment)\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\ttry {\n\t\t\treturn await this.contentClient.query(query, {\n\t\t\t\tsignal,\n\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t},\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\tif (e.type === 'aborted') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.onError(e, this)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["TreeRootAccessor","Config","createBatchUpdatesOptions","DirtinessTracker","EventManager","AccessorErrorManager","StateInitializer","TreeAugmenter","TreeFilterGenerator","options","createQueryBuilder","ContentClient","MutationGenerator","GraphQlClientError","MarkerMerger","getCombinedSignal","QueryGenerator","query","StateIterator","assertNever","generateEnumerabilityPreventingEntropy"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,eAAN,MAAM,aAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAhCe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAIA,iBAAA,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQ/G;AAAA;AAAA;AAAA;AAAA,iEAOC;AA9MS,SAAA,mBAAA;AACA,SAAA,kBAAA;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AGC,uCAAAA,uCAAwC,CAAA,IAAI,aAAY,sBAAA,CAAuB;AAAA,EACtF;AACD;AAZC,cApXY,cAoXG,yBAA+B,uBAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAtXR,IAAM,cAAN;AAkYM,MAAA,2BAA2B,OAAO,SAAS;;;"}
|
|
@@ -22,7 +22,7 @@ import { getCombinedSignal } from "./utils/getCombinedSignal.js";
|
|
|
22
22
|
import { StateIterator } from "./state/StateIterator.js";
|
|
23
23
|
import { assertNever } from "../utils/assertNever.js";
|
|
24
24
|
import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
|
|
25
|
-
const _DataBinding = class {
|
|
25
|
+
const _DataBinding = class _DataBinding {
|
|
26
26
|
// private treeRootListeners: {
|
|
27
27
|
// eventListeners: {}
|
|
28
28
|
// } = {
|
|
@@ -339,11 +339,11 @@ const _DataBinding = class {
|
|
|
339
339
|
return this.treeStore.markerTrees.size === 0 ? void 0 : `${generateEnumerabilityPreventingEntropy()}-${_DataBinding.getNextTreeRootIdSeed()}`;
|
|
340
340
|
}
|
|
341
341
|
};
|
|
342
|
-
|
|
343
|
-
__publicField(DataBinding, "getNextTreeRootIdSeed", (() => {
|
|
342
|
+
__publicField(_DataBinding, "getNextTreeRootIdSeed", /* @__PURE__ */ (() => {
|
|
344
343
|
let seed = 1;
|
|
345
344
|
return () => seed++;
|
|
346
345
|
})());
|
|
346
|
+
let DataBinding = _DataBinding;
|
|
347
347
|
const DataBindingExtendAborted = Symbol("aborted");
|
|
348
348
|
export {
|
|
349
349
|
DataBinding,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import {\n\tContentClient,\n\tContentQueryBuilder,\n\tGraphQlClient,\n\tGraphQlClientError,\n\tMutationResult,\n\tTransactionResult,\n\tTreeFilter,\n} from '@contember/client'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport { ErrorPersistResult, ReceivedDataTree, ReceivedEntityData, SuccessfulPersistResult } from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from './utils/createQueryBuilder'\n\nexport type DataBindingTransactionResult = TransactionResult<Record<string, MutationResult<ReceivedEntityData>>>\n\nexport class DataBinding<Node> {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations<Node>\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly queryBuilder: ContentQueryBuilder\n\tprivate readonly contentClient: ContentClient\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly createMarkerTree: (node: Node, environment: Environment) => MarkerTreeRoot,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor<Node>, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onError: (error: GraphQlClientError, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding<Node>) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t\tthis.batchedUpdates,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations<Node>>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t\tthis.queryBuilder = createQueryBuilder(this.environment.getSchema())\n\t\tthis.contentClient = new ContentClient(contentApiClient)\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore, this.queryBuilder)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { mutations, operations } = mutationResult\n\n\t\t\tlet response: DataBindingTransactionResult\n\t\t\ttry {\n\t\t\t\tresponse = await this.contentClient.mutate(this.queryBuilder.transaction(mutations, {\n\t\t\t\t\tdeferForeignKeyConstraints: true,\n\t\t\t\t}), {\n\t\t\t\t\tsignal,\n\t\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t\tthis.persistFail({\n\t\t\t\t\t\terrors: [e],\n\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (Object.values(response.data).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(response, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (response.errorMessage) {\n\t\t\t\t\tconsole.error(response.errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(response, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: DataBindingTransactionResult, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData.data).map(it => it.node?.id).filter((id): id is EntityId => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData.data).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor<Node>(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: Node\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: Node, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = this.createMarkerTree(newFragment, options.environment ?? this.environment)\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\ttry {\n\t\t\treturn await this.contentClient.query(query, {\n\t\t\t\tsignal,\n\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t},\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\tif (e.type === 'aborted') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.onError(e, this)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["options","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,eAAN,MAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAhCe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQ/G;AAAA;AAAA;AAAA;AAAA,iEAOC;AA9MS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,YAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AACA,SAAA,UAAA;AAIZ,SAAA,SAAS,IAAI;AAClB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AACh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cAAc,KAAK,SAAS,GAAG;AACxE,mBAAW,SAAS,cAAc,mBAAmB,SAAS,GAAG;AAChE,kBAAQ,MAAM,MAAM;AAAA,YACnB,KAAK,SAAS;AACb,kBAAI,MAAM,yBAAyB,MAAM,UAAU,MAAM;AACxD,sBAAM,UAAU;AAChB,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA,KAAK;AACJ,kBAAI,MAAM,0BAA0B,KAAK,MAAM,iBAAiB,MAAM;AACrE,sBAAM,0BAA0B;AAChC,sBAAM,iBAAiB;AACvB,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD,KAAK,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB;AAC9B,qBAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA,YACA;AACC,0BAAiB;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AAhYO,IAAM,cAAN;AAoXN,cApXY,aAoXG,0BAAyB,MAAM;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;"}
|
|
1
|
+
{"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import {\n\tContentClient,\n\tContentQueryBuilder,\n\tGraphQlClient,\n\tGraphQlClientError,\n\tMutationResult,\n\tTransactionResult,\n\tTreeFilter,\n} from '@contember/client'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport { ErrorPersistResult, ReceivedDataTree, ReceivedEntityData, SuccessfulPersistResult } from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from './utils/createQueryBuilder'\n\nexport type DataBindingTransactionResult = TransactionResult<Record<string, MutationResult<ReceivedEntityData>>>\n\nexport class DataBinding<Node> {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations<Node>\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\tprivate readonly queryBuilder: ContentQueryBuilder\n\tprivate readonly contentClient: ContentClient\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly createMarkerTree: (node: Node, environment: Environment) => MarkerTreeRoot,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor<Node>, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onError: (error: GraphQlClientError, binding: DataBinding<Node>) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding<Node>) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t\tthis.batchedUpdates,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations<Node>>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t\tthis.queryBuilder = createQueryBuilder(this.environment.getSchema())\n\t\tthis.contentClient = new ContentClient(contentApiClient)\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore, this.queryBuilder)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { mutations, operations } = mutationResult\n\n\t\t\tlet response: DataBindingTransactionResult\n\t\t\ttry {\n\t\t\t\tresponse = await this.contentClient.mutate(this.queryBuilder.transaction(mutations, {\n\t\t\t\t\tdeferForeignKeyConstraints: true,\n\t\t\t\t}), {\n\t\t\t\t\tsignal,\n\t\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t\tthis.persistFail({\n\t\t\t\t\t\terrors: [e],\n\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (Object.values(response.data).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(response, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (response.errorMessage) {\n\t\t\t\t\tconsole.error(response.errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(response, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: DataBindingTransactionResult, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData.data).map(it => it.node?.id).filter((id): id is EntityId => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData.data).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor<Node>(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: Node\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: Node, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = this.createMarkerTree(newFragment, options.environment ?? this.environment)\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted || aggregatePersistedData === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\ttry {\n\t\t\treturn await this.contentClient.query(query, {\n\t\t\t\tsignal,\n\t\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t\tconsole.debug(query, variables)\n\t\t\t\t},\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tif (e instanceof GraphQlClientError) {\n\t\t\t\tif (e.type === 'aborted') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tthis.onError(e, this)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["options","query"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0CO,MAAM,eAAN,MAAM,aAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAhCe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS,IAAI,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA;AAQ/G;AAAA;AAAA;AAAA;AAAA,iEAOC;AA9MS,SAAA,mBAAA;AACA,SAAA,kBAAA;AACA,SAAA,kBAAA;AACA,SAAA,YAAA;AACA,SAAA,cAAA;AACA,SAAA,mBAAA;AACA,SAAA,iBAAA;AACA,SAAA,WAAA;AACA,SAAA,UAAA;AACA,SAAA,mBAAA;AACA,SAAA,UAAA;AAIZ,SAAA,SAAS,IAAI;AAClB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2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