@contember/binding-legacy 2.0.0-alpha.32 → 2.0.0-alpha.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/development/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/development/src/core/Config.cjs.map +1 -1
- package/dist/development/src/core/Config.js.map +1 -1
- package/dist/development/src/core/DataBinding.cjs.map +1 -1
- package/dist/development/src/core/DataBinding.js.map +1 -1
- package/dist/development/src/core/DirtinessTracker.cjs.map +1 -1
- package/dist/development/src/core/DirtinessTracker.js.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/development/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/development/src/core/EventManager.cjs.map +1 -1
- package/dist/development/src/core/EventManager.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/development/src/core/QueryGenerator.js.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/development/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/src/core/StateInitializer.cjs.map +1 -1
- package/dist/development/src/core/StateInitializer.js.map +1 -1
- package/dist/development/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/development/src/core/TreeAugmenter.js.map +1 -1
- package/dist/development/src/core/TreeStore.cjs.map +1 -1
- package/dist/development/src/core/TreeStore.js.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/development/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/development/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/development/src/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/development/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/development/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/development/src/core/operations/ListOperations.js.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/development/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/development/src/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/development/src/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/development/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/development/src/core/state/StateIterator.js.map +1 -1
- package/dist/development/src/core/utils/getCombinedSignal.cjs.map +1 -1
- package/dist/development/src/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/development/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/development/src/utils/isEmptyObject.cjs.map +1 -1
- package/dist/development/src/utils/isEmptyObject.js.map +1 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityListAccessorImpl.js.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/FieldAccessorImpl.js.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.cjs.map +1 -1
- package/dist/production/src/core/AccessorErrorManager.js.map +1 -1
- package/dist/production/src/core/Config.cjs.map +1 -1
- package/dist/production/src/core/Config.js.map +1 -1
- package/dist/production/src/core/DataBinding.cjs.map +1 -1
- package/dist/production/src/core/DataBinding.js.map +1 -1
- package/dist/production/src/core/DirtinessTracker.cjs.map +1 -1
- package/dist/production/src/core/DirtinessTracker.js.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.cjs.map +1 -1
- package/dist/production/src/core/ErrorsPreprocessor.js.map +1 -1
- package/dist/production/src/core/EventManager.cjs.map +1 -1
- package/dist/production/src/core/EventManager.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/production/src/core/QueryGenerator.js.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.cjs.map +1 -1
- package/dist/production/src/core/RealmKeyGenerator.js.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/src/core/StateInitializer.cjs.map +1 -1
- package/dist/production/src/core/StateInitializer.js.map +1 -1
- package/dist/production/src/core/TreeAugmenter.cjs.map +1 -1
- package/dist/production/src/core/TreeAugmenter.js.map +1 -1
- package/dist/production/src/core/TreeStore.cjs.map +1 -1
- package/dist/production/src/core/TreeStore.js.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.cjs.map +1 -1
- package/dist/production/src/core/exceptions/ErrorLocator.js.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.cjs.map +1 -1
- package/dist/production/src/core/exceptions/MarkerSugarer.js.map +1 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
- package/dist/production/src/core/exceptions/TreeParameterSugarer.js.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
- package/dist/production/src/core/factories/createBatchUpdatesOptions.js.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/FieldOperations.js.map +1 -1
- package/dist/production/src/core/operations/ListOperations.cjs.map +1 -1
- package/dist/production/src/core/operations/ListOperations.js.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.cjs.map +1 -1
- package/dist/production/src/core/operations/OperationsHelpers.js.map +1 -1
- package/dist/production/src/core/requestAliases/MutationAlias.cjs.map +1 -1
- package/dist/production/src/core/requestAliases/MutationAlias.js.map +1 -1
- package/dist/production/src/core/state/StateIterator.cjs.map +1 -1
- package/dist/production/src/core/state/StateIterator.js.map +1 -1
- package/dist/production/src/core/utils/getCombinedSignal.cjs.map +1 -1
- package/dist/production/src/core/utils/getCombinedSignal.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/FieldHelper.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/TemporalFieldHelper.js.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.cjs.map +1 -1
- package/dist/production/src/fieldHelpers/helpers/UuidFieldHelper.js.map +1 -1
- package/dist/production/src/utils/isEmptyObject.cjs.map +1 -1
- package/dist/production/src/utils/isEmptyObject.js.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/tests/example.test.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityListAccessorImpl.cjs","sources":["../../../../../packages/binding-legacy/src/accessors/EntityListAccessorImpl.ts"],"sourcesContent":["import type { EntityListState } from '../core/state'\nimport type { ListOperations } from '../core/operations'\nimport { EntityAccessor, EntityId, EntityListSubTreeMarker, EntityName, EntityRealmKey, Environment, ErrorAccessor,\n\tHasManyRelationMarker, RuntimeId } from '@contember/binding-common'\nimport { EntityListAccessor } from '@contember/binding-common'\n\nexport class EntityListAccessorImpl implements EntityListAccessor {\n\tpublic readonly __type = 'EntityListAccessor' as const\n\n\tpublic constructor(\n\t\tprivate readonly state: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<EntityId>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {\n\t}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic* keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key!\n\t\t}\n\t}\n\n\tpublic* ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<EntityId> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic* [Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\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 EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.EntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.state, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.state, initialize)\n\t}\n\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.state, childEntity, options)\n\t}\n\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.state, id)\n\t}\n\n\tpublic getParent(): EntityAccessor | undefined {\n\t\treturn this.state.blueprint.parent?.getAccessor()\n\t}\n\n\tpublic getMarker(): EntityListSubTreeMarker | HasManyRelationMarker {\n\t\treturn this.state.blueprint.marker\n\t}\n}\n"],"names":["ErrorAccessor"],"mappings":";;;;;;AAMO,MAAM,uBAAqD;AAAA,EAG1D,YACW,OACA,YACD,MACC,WACA,uBACD,uBACA,QACA,aACA,aACf;AATgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAXjB,kBAAA,MAAiB,UAAS,oBAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"EntityListAccessorImpl.cjs","sources":["../../../../../packages/binding-legacy/src/accessors/EntityListAccessorImpl.ts"],"sourcesContent":["import type { EntityListState } from '../core/state'\nimport type { ListOperations } from '../core/operations'\nimport { EntityAccessor, EntityId, EntityListSubTreeMarker, EntityName, EntityRealmKey, Environment, ErrorAccessor,\n\tHasManyRelationMarker, RuntimeId } from '@contember/binding-common'\nimport { EntityListAccessor } from '@contember/binding-common'\n\nexport class EntityListAccessorImpl implements EntityListAccessor {\n\tpublic readonly __type = 'EntityListAccessor' as const\n\n\tpublic constructor(\n\t\tprivate readonly state: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<EntityId>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {\n\t}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic* keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key!\n\t\t}\n\t}\n\n\tpublic* ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<EntityId> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic* [Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\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 EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.EntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.state, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.state, initialize)\n\t}\n\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.state, childEntity, options)\n\t}\n\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.state, id)\n\t}\n\n\tpublic getParent(): EntityAccessor | undefined {\n\t\treturn this.state.blueprint.parent?.getAccessor()\n\t}\n\n\tpublic getMarker(): EntityListSubTreeMarker | HasManyRelationMarker {\n\t\treturn this.state.blueprint.marker\n\t}\n}\n"],"names":["ErrorAccessor"],"mappings":";;;;;;AAMO,MAAM,uBAAqD;AAAA,EAG1D,YACW,OACA,YACD,MACC,WACA,uBACD,uBACA,QACA,aACA,aACf;AATgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAXjB,kBAAA,MAAiB,UAAS,oBAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,CAAQ,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA,IAAA;AAAA,EAChB;AAAA,EAGD,CAAQ,MAAkC;AAClC,WAAA,KAAK,UAAU,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5B,IAAW,uBAAsC;AACzC,WAAA,IAAI,IAAI,KAAK,qBAAqB;AAAA,EAAA;AAAA,EAG1C,EAAS,OAAO,QAAQ,IAAsC;AAC7D,eAAW,EAAE,YAAY,KAAK,KAAK,UAAU,UAAU;AACtD,YAAM,YAAY;AAAA,IAAA;AAAA,EACnB;AAAA,EAGM,YAAY,IAAuB;AAClC,WAAA,KAAK,UAAU,IAAI,EAAE;AAAA,EAAA;AAAA,EAGtB,UAAm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AO,UAAU;AAAA,EAAA;AAAA,EAGvD,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,OAAO,aAAa,OAAO;AAAA,EAAA;AAAA,EAG3D,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,OAAO,EAAE;AAAA,EAAA;AAAA,EAGlD,YAAwC;AAC9C,WAAO,KAAK,MAAM,UAAU,QAAQ,YAAY;AAAA,EAAA;AAAA,EAG1C,YAA6D;AAC5D,WAAA,KAAK,MAAM,UAAU;AAAA,EAAA;AAE9B;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityListAccessorImpl.js","sources":["../../../../../packages/binding-legacy/src/accessors/EntityListAccessorImpl.ts"],"sourcesContent":["import type { EntityListState } from '../core/state'\nimport type { ListOperations } from '../core/operations'\nimport { EntityAccessor, EntityId, EntityListSubTreeMarker, EntityName, EntityRealmKey, Environment, ErrorAccessor,\n\tHasManyRelationMarker, RuntimeId } from '@contember/binding-common'\nimport { EntityListAccessor } from '@contember/binding-common'\n\nexport class EntityListAccessorImpl implements EntityListAccessor {\n\tpublic readonly __type = 'EntityListAccessor' as const\n\n\tpublic constructor(\n\t\tprivate readonly state: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<EntityId>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {\n\t}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic* keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key!\n\t\t}\n\t}\n\n\tpublic* ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<EntityId> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic* [Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\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 EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.EntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.state, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.state, initialize)\n\t}\n\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.state, childEntity, options)\n\t}\n\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.state, id)\n\t}\n\n\tpublic getParent(): EntityAccessor | undefined {\n\t\treturn this.state.blueprint.parent?.getAccessor()\n\t}\n\n\tpublic getMarker(): EntityListSubTreeMarker | HasManyRelationMarker {\n\t\treturn this.state.blueprint.marker\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,uBAAqD;AAAA,EAG1D,YACW,OACA,YACD,MACC,WACA,uBACD,uBACA,QACA,aACA,aACf;AATgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAXjB,kBAAA,MAAiB,UAAS,oBAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"EntityListAccessorImpl.js","sources":["../../../../../packages/binding-legacy/src/accessors/EntityListAccessorImpl.ts"],"sourcesContent":["import type { EntityListState } from '../core/state'\nimport type { ListOperations } from '../core/operations'\nimport { EntityAccessor, EntityId, EntityListSubTreeMarker, EntityName, EntityRealmKey, Environment, ErrorAccessor,\n\tHasManyRelationMarker, RuntimeId } from '@contember/binding-common'\nimport { EntityListAccessor } from '@contember/binding-common'\n\nexport class EntityListAccessorImpl implements EntityListAccessor {\n\tpublic readonly __type = 'EntityListAccessor' as const\n\n\tpublic constructor(\n\t\tprivate readonly state: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<EntityId>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {\n\t}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic* keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key!\n\t\t}\n\t}\n\n\tpublic* ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<EntityId> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic* [Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\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 EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.EntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.state, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.state, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.state, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.state, initialize)\n\t}\n\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.state, childEntity, options)\n\t}\n\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.state, id)\n\t}\n\n\tpublic getParent(): EntityAccessor | undefined {\n\t\treturn this.state.blueprint.parent?.getAccessor()\n\t}\n\n\tpublic getMarker(): EntityListSubTreeMarker | HasManyRelationMarker {\n\t\treturn this.state.blueprint.marker\n\t}\n}\n"],"names":[],"mappings":";;;;AAMO,MAAM,uBAAqD;AAAA,EAG1D,YACW,OACA,YACD,MACC,WACA,uBACD,uBACA,QACA,aACA,aACf;AATgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,OAAA;AACC,SAAA,YAAA;AACA,SAAA,wBAAA;AACD,SAAA,wBAAA;AACA,SAAA,SAAA;AACA,SAAA,cAAA;AACA,SAAA,cAAA;AAXjB,kBAAA,MAAiB,UAAS,oBAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAoB1B,CAAQ,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA,IAAA;AAAA,EAChB;AAAA,EAGD,CAAQ,MAAkC;AAClC,WAAA,KAAK,UAAU,KAAK;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO5B,IAAW,uBAAsC;AACzC,WAAA,IAAI,IAAI,KAAK,qBAAqB;AAAA,EAAA;AAAA,EAG1C,EAAS,OAAO,QAAQ,IAAsC;AAC7D,eAAW,EAAE,YAAY,KAAK,KAAK,UAAU,UAAU;AACtD,YAAM,YAAY;AAAA,IAAA;AAAA,EACnB;AAAA,EAGM,YAAY,IAAuB;AAClC,WAAA,KAAK,UAAU,IAAI,EAAE;AAAA,EAAA;AAAA,EAGtB,UAAmB;AACzB,WAAO,KAAK,WAAW;AAAA,EAAA;AAAA,EAGxB,I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AU;AACjG,SAAK,WAAW,iBAAiB,KAAK,OAAO,aAAa,OAAO;AAAA,EAAA;AAAA,EAG3D,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,OAAO,EAAE;AAAA,EAAA;AAAA,EAGlD,YAAwC;AAC9C,WAAO,KAAK,MAAM,UAAU,QAAQ,YAAY;AAAA,EAAA;AAAA,EAG1C,YAA6D;AAC5D,WAAA,KAAK,MAAM,UAAU;AAAA,EAAA;AAE9B;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldAccessorImpl.cjs","sources":["../../../../../packages/binding-legacy/src/accessors/FieldAccessorImpl.ts"],"sourcesContent":["import type { FieldState } from '../core/state'\nimport type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport { EntityAccessor, ErrorAccessor, FieldAccessor, FieldName, FieldValue, SchemaColumn } from '@contember/binding-common'\n\nexport class FieldAccessorImpl<Value extends FieldValue = FieldValue> implements FieldAccessor {\n\tpublic readonly __type = 'FieldAccessor' as const\n\n\tconstructor(\n\t\tprivate readonly state: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {\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 clearErrors(): void {\n\t\tthis.operations.clearErrors(this.state)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.state, newValue, options)\n\t}\n\n\tpublic isTouchedBy(agent: 'user' | (string & {})) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy('user')\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic getParent(): EntityAccessor {\n\t\treturn this.state.parent.getAccessor()\n\t}\n}\n"],"names":["ErrorAccessor","TemporalFieldHelper","UuidFieldHelper"],"mappings":";;;;;;;;AAKO,MAAM,kBAAkF;AAAA,EAG9F,YACkB,OACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACA,QACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,YAAA;AACA,SAAA,QAAA;AACA,SAAA,gBAAA;AACA,SAAA,eAAA;AACA,SAAA,SAAA;AACA,SAAA,wBAAA;AACC,SAAA,WAAA;AACD,SAAA,cAAA;AACA,SAAA,SAAA;AAbjB,kBAAA,MAAgB,UAAS,eAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"FieldAccessorImpl.cjs","sources":["../../../../../packages/binding-legacy/src/accessors/FieldAccessorImpl.ts"],"sourcesContent":["import type { FieldState } from '../core/state'\nimport type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport { EntityAccessor, ErrorAccessor, FieldAccessor, FieldName, FieldValue, SchemaColumn } from '@contember/binding-common'\n\nexport class FieldAccessorImpl<Value extends FieldValue = FieldValue> implements FieldAccessor {\n\tpublic readonly __type = 'FieldAccessor' as const\n\n\tconstructor(\n\t\tprivate readonly state: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {\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 clearErrors(): void {\n\t\tthis.operations.clearErrors(this.state)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.state, newValue, options)\n\t}\n\n\tpublic isTouchedBy(agent: 'user' | (string & {})) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy('user')\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic getParent(): EntityAccessor {\n\t\treturn this.state.parent.getAccessor()\n\t}\n}\n"],"names":["ErrorAccessor","TemporalFieldHelper","UuidFieldHelper"],"mappings":";;;;;;;;AAKO,MAAM,kBAAkF;AAAA,EAG9F,YACkB,OACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACA,QACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,YAAA;AACA,SAAA,QAAA;AACA,SAAA,gBAAA;AACA,SAAA,eAAA;AACA,SAAA,SAAA;AACA,SAAA,wBAAA;AACC,SAAA,WAAA;AACD,SAAA,cAAA;AACA,SAAA,SAAA;AAbjB,kBAAA,MAAgB,UAAS,eAAA;AAAA,EAAA;AAAA,EAiBlB,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAOA,cAAc,cAAA,eAAe,KAAK,CAAC;AAAA,EAAA;AAAA,EAGzE,cAAoB;AACrB,SAAA,WAAW,YAAY,KAAK,KAAK;AAAA,EAAA;AAAA,EAGhC,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EAAA;AAAA,EAG7D,YAAY,UAAwB,SAA6C;AACvF,SAAK,WAAW,YAAY,KAAK,OAAO,UAAU,OAAO;AAAA,EAAA;AAAA,EAGnD,YAAY,OAA+B;AACjD,WAAO,KAAK,UAAU,IAAI,KAAK,KAAK;AAAA,EAAA;AAAA,EAGrC,IAAW,YAAY;AACf,WAAA,KAAK,YAAY,MAAM;AAAA,EAAA;AAAA;AAAA,EAK/B,IAAW,aAAkC;AACrC,WAAA,IAAIC,oBAAAA,oBAAoB,KAAK,WAAkD;AAAA,EAAA;AAAA,EAGvF,IAAW,SAA0B;AAC7B,WAAA,IAAIC,gBAAAA,gBAAgB,KAAK,WAAkD;AAAA,EAAA;AAAA,EAG5E,YAA4B;AAC3B,WAAA,KAAK,MAAM,OAAO,YAAY;AAAA,EAAA;AAEvC;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldAccessorImpl.js","sources":["../../../../../packages/binding-legacy/src/accessors/FieldAccessorImpl.ts"],"sourcesContent":["import type { FieldState } from '../core/state'\nimport type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport { EntityAccessor, ErrorAccessor, FieldAccessor, FieldName, FieldValue, SchemaColumn } from '@contember/binding-common'\n\nexport class FieldAccessorImpl<Value extends FieldValue = FieldValue> implements FieldAccessor {\n\tpublic readonly __type = 'FieldAccessor' as const\n\n\tconstructor(\n\t\tprivate readonly state: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {\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 clearErrors(): void {\n\t\tthis.operations.clearErrors(this.state)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.state, newValue, options)\n\t}\n\n\tpublic isTouchedBy(agent: 'user' | (string & {})) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy('user')\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic getParent(): EntityAccessor {\n\t\treturn this.state.parent.getAccessor()\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAKO,MAAM,kBAAkF;AAAA,EAG9F,YACkB,OACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACA,QACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,YAAA;AACA,SAAA,QAAA;AACA,SAAA,gBAAA;AACA,SAAA,eAAA;AACA,SAAA,SAAA;AACA,SAAA,wBAAA;AACC,SAAA,WAAA;AACD,SAAA,cAAA;AACA,SAAA,SAAA;AAbjB,kBAAA,MAAgB,UAAS,eAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"FieldAccessorImpl.js","sources":["../../../../../packages/binding-legacy/src/accessors/FieldAccessorImpl.ts"],"sourcesContent":["import type { FieldState } from '../core/state'\nimport type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport { EntityAccessor, ErrorAccessor, FieldAccessor, FieldName, FieldValue, SchemaColumn } from '@contember/binding-common'\n\nexport class FieldAccessorImpl<Value extends FieldValue = FieldValue> implements FieldAccessor {\n\tpublic readonly __type = 'FieldAccessor' as const\n\n\tconstructor(\n\t\tprivate readonly state: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t\tpublic readonly schema: SchemaColumn,\n\t) {\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 clearErrors(): void {\n\t\tthis.operations.clearErrors(this.state)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.state, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.state, newValue, options)\n\t}\n\n\tpublic isTouchedBy(agent: 'user' | (string & {})) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy('user')\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic getParent(): EntityAccessor {\n\t\treturn this.state.parent.getAccessor()\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAKO,MAAM,kBAAkF;AAAA,EAG9F,YACkB,OACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACA,QACf;AAXgB,SAAA,QAAA;AACA,SAAA,aAAA;AACD,SAAA,YAAA;AACA,SAAA,QAAA;AACA,SAAA,gBAAA;AACA,SAAA,eAAA;AACA,SAAA,SAAA;AACA,SAAA,wBAAA;AACC,SAAA,WAAA;AACD,SAAA,cAAA;AACA,SAAA,SAAA;AAbjB,kBAAA,MAAgB,UAAS,eAAA;AAAA,EAAA;AAAA,EAiBlB,SAAS,OAAiD;AACzD,WAAA,KAAK,WAAW,SAAS,KAAK,OAAO,cAAc,eAAe,KAAK,CAAC;AAAA,EAAA;AAAA,EAGzE,cAAoB;AACrB,SAAA,WAAW,YAAY,KAAK,KAAK;AAAA,EAAA;AAAA,EAGhC,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,OAAO,OAAO,QAAQ;AAAA,EAAA;AAAA,EAG7D,YAAY,UAAwB,SAA6C;AACvF,SAAK,WAAW,YAAY,KAAK,OAAO,UAAU,OAAO;AAAA,EAAA;AAAA,EAGnD,YAAY,OAA+B;AACjD,WAAO,KAAK,UAAU,IAAI,KAAK,KAAK;AAAA,EAAA;AAAA,EAGrC,IAAW,YAAY;AACf,WAAA,KAAK,YAAY,MAAM;AAAA,EAAA;AAAA;AAAA,EAK/B,IAAW,aAAkC;AACrC,WAAA,IAAI,oBAAoB,KAAK,WAAkD;AAAA,EAAA;AAAA,EAGvF,IAAW,SAA0B;AAC7B,WAAA,IAAI,gBAAgB,KAAK,WAAkD;AAAA,EAAA;AAAA,EAG5E,YAA4B;AAC3B,WAAA,KAAK,MAAM,OAAO,YAAY;AAAA,EAAA;AAEvC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessorErrorManager.cjs","sources":["../../../../../packages/binding-legacy/src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '@contember/binding-common'\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 '@contember/binding-common'\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 = { errors: 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 = { errors: 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\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["EventManager","ErrorsPreprocessor","errorsById","getEntityMarker"],"mappings":";;;;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE,SAAA,eAAA;AAA6C,SAAA,YAAA;AARzE,kBAAA,MAAA,qCAA8D,IAAI,CAAA;AAE1E,kBAAA,MAAQ,iBAAuB,uBAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IACX,GAAA,CAAA;AAAA,EAEqG;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,WAAWA,aAAA,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,OAAOA,aAA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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;AAEzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AAAA,IACD;AAAA,EACD;AACD;;"}
|
|
1
|
+
{"version":3,"file":"AccessorErrorManager.cjs","sources":["../../../../../packages/binding-legacy/src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '@contember/binding-common'\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 '@contember/binding-common'\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 = { errors: 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 = { errors: 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\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["EventManager","ErrorsPreprocessor","errorsById","getEntityMarker"],"mappings":";;;;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE,SAAA,eAAA;AAA6C,S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AAA,EACD;AAEF;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccessorErrorManager.js","sources":["../../../../../packages/binding-legacy/src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '@contember/binding-common'\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 '@contember/binding-common'\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 = { errors: 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 = { errors: 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\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["errorsById"],"mappings":";;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE,SAAA,eAAA;AAA6C,SAAA,YAAA;AARzE,kBAAA,MAAA,qCAA8D,IAAI,CAAA;AAE1E,kBAAA,MAAQ,iBAAuB,uBAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IACX,GAAA,CAAA;AAAA,EAEqG;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,cAA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rC,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;AAEzC,gBAAQ,MAAM,gBAAgB;AAAA,MAC/B;AAAA,IACD;AAAA,EACD;AACD;"}
|
|
1
|
+
{"version":3,"file":"AccessorErrorManager.js","sources":["../../../../../packages/binding-legacy/src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '@contember/binding-common'\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 '@contember/binding-common'\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 = { errors: 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 = { errors: 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\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["errorsById"],"mappings":";;;;;;AASO,MAAM,qBAAqB;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE,SAAA,eAAA;AAA6C,SAAA,YAAA;AARzE,kBAAA,MAAA,qCAA8D,IAAI,CAAA;AAE1E,kBAAA,MAAQ,iBAAuB,uBAAA;AAC9B,UAAI,UAAU;AAEd,aAAO,MAAM;AAAA,IAAA,IACX;AAAA,EAAA;AAAA,EAII,YAAY;AACX,WAAA,CAAC,CAAC,KAAK,cAAc;AAAA,EAAA;AAAA,EAGtB,YAAmC;AACzC,WAAO,MAAM,KAAK,KAAK,cAAc,UAAU,CAAA,OAAM,MAAM,KAAK,GAAG,OAAA,CAAQ,CAAC,EAAE,KAAK;AAAA,EAAA;AAAA,EAG7E,cAAc;AACf,SAAA,aAAa,cAAc,MAAM;AACrC,iBAAW,CAAC,SAAS,KAAK,KAAK,eAAe;AAC7C,kBAAU,SAAS;AACnB,aAAK,aAAa,oBAAoB,WAAW,aAAa,qBAAqB;AAAA,MAAA;AAEpF,WAAK,cAAc,MAAM;AAAA,IAAA,CACzB;AAAA,EAAA;AAAA,EAGK,mBAAmB,OAAwB;AAC1C,WAAA,KAAK,aAAa,cAAc,MAAM;AAC5C,UAAI,CAAC,KAAK,cAAc,IAAI,KAAK,GAAG;AACnC;AAAA,MAAA;AAEI,WAAA,cAAc,OAAO,KAAK;AAC/B,YAAM,SAAS;AACf,WAAK,aAAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,IAAA,CAC/E;AAAA,EAAA;AAAA,EAGK,cAAc,MAAoC,YAAoC;AACvF,SAAA,aAAa,cAAc,MA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E5C,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,QAC7E;AAAA,MAAA,CACA;AACD,UAAI,OAAO,KAAK,gBAAgB,EAAE,QAAQ;AAEzC,gBAAQ,MAAM,gBAAgB;AAAA,MAAA;AAAA,IAC/B;AAAA,EACD;AAEF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.cjs","sources":["../../../../../packages/binding-legacy/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":["_Config"],"mappings":";;;;;AAEO,MAAM,UAAN,MAAMA,SAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC,kBAAA,MAAA,QAAA;AAGhB,SAAK,SAAS;AAAA,MACb,GAAGA,SAAO;AAAA,MACV,GAAG;AAAA,
|
|
1
|
+
{"version":3,"file":"Config.cjs","sources":["../../../../../packages/binding-legacy/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":["_Config"],"mappings":";;;;;AAEO,MAAM,UAAN,MAAMA,SAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC,kBAAA,MAAA,QAAA;AAGhB,SAAK,SAAS;AAAA,MACb,GAAGA,SAAO;AAAA,MACV,GAAG;AAAA,IACJ;AAAA,EAAA;AAAA,EAGM,SAA2C,MAAiC;AAC3E,WAAA,KAAK,OAAO,IAAI;AAAA,EAAA;AAAA,EAGjB,SAA2C,MAAY,OAAkC;AAC1F,SAAA,OAAO,IAAI,IAAI;AACb,WAAA;AAAA,EAAA;AAET;AAvBC,cADY,SACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAC5B,CAAA;AALM,IAAM,SAAN;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sources":["../../../../../packages/binding-legacy/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":["_Config"],"mappings":";;;AAEO,MAAM,UAAN,MAAMA,SAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC,kBAAA,MAAA,QAAA;AAGhB,SAAK,SAAS;AAAA,MACb,GAAGA,SAAO;AAAA,MACV,GAAG;AAAA,
|
|
1
|
+
{"version":3,"file":"Config.js","sources":["../../../../../packages/binding-legacy/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":["_Config"],"mappings":";;;AAEO,MAAM,UAAN,MAAMA,SAAO;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC,kBAAA,MAAA,QAAA;AAGhB,SAAK,SAAS;AAAA,MACb,GAAGA,SAAO;AAAA,MACV,GAAG;AAAA,IACJ;AAAA,EAAA;AAAA,EAGM,SAA2C,MAAiC;AAC3E,WAAA,KAAK,OAAO,IAAI;AAAA,EAAA;AAAA,EAGjB,SAA2C,MAAY,OAAkC;AAC1F,SAAA,OAAO,IAAI,IAAI;AACb,WAAA;AAAA,EAAA;AAET;AAvBC,cADY,SACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAC5B,CAAA;AALM,IAAM,SAAN;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.cjs","sources":["../../../../../packages/binding-legacy/src/core/DataBinding.ts"],"sourcesContent":["import { ContentClient, ContentQueryBuilder, GraphQlClient, GraphQlClientError } from '@contember/client'\nimport type { DataBindingTransactionResult, EntityId, Environment, MarkerTreeRoot, TreeRootId } from '@contember/binding-common'\nimport {\n\tassertNever,\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tErrorPersistResult,\n\tExtendTreeOptions,\n\tMarkerMerger,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tReceivedDataTree,\n\tSuccessfulPersistResult,\n\tTreeRootAccessor,\n} from '@contember/binding-common'\nimport { generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from '@contember/binding-common'\nimport { DataBindingExtendAborted } from '@contember/binding-common'\n\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\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\tfetchData: async (...args) => await this.fetchData(...args),\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.operations.length === 0) {\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\t// eslint-disable-next-line no-console\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 (response.ok && 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\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(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\tresponse,\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\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\ttype: 'invalidInput',\n\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\tonError?: (error: Error) => void\n\t}> = new Set()\n\n\tprivate flushResult: Promise<boolean> | undefined\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 (!options.force && 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(async (resolve, reject) => {\n\t\t\tconst treeRootId = this.getNewTreeRootId()\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: treeRootId,\n\t\t\t\toptions,\n\t\t\t\tonError: options.onError,\n\t\t\t})\n\t\t\tthis.flushResult ??= (async () => {\n\t\t\t\tawait Promise.resolve()\n\t\t\t\tthis.flushResult = undefined\n\t\t\t\treturn await this.flushBatchedTreeExtensions()\n\t\t\t})()\n\n\t\t\tif (!(await this.flushResult) || options.signal?.aborted) {\n\t\t\t\treturn reject(DataBindingExtendAborted)\n\t\t\t}\n\n\t\t\tresolve(treeRootId)\n\t\t})\n\t}\n\n\tpublic async fetchData(fragment: Node, options?: { signal?: AbortSignal; environment?: Environment }): Promise<{\n\t\tdata: ReceivedDataTree\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t}> {\n\t\tconst markerTreeRoot = this.createMarkerTree(fragment, options?.environment ?? this.environment)\n\t\tconst data = await this.fetchPersistedData(markerTreeRoot, options?.signal)\n\n\t\treturn {\n\t\t\tdata: data,\n\t\t\tmarkerTreeRoot,\n\t\t}\n\t}\n\n\tprivate async flushBatchedTreeExtensions(): Promise<boolean> {\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\treturn !extension.options.signal?.aborted\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 false\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tlet aggregatePersistedData: ReceivedDataTree\n\t\ttry {\n\t\t\taggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\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 false\n\t\t\t\t}\n\t\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\t\textension.onError?.(e)\n\t\t\t\t}\n\t\t\t\tif (!pendingExtensions.every(it => !!it.onError)) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t} else {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn false\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}\n\t\t})\n\t\treturn true\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\treturn await this.contentClient.query(query, {\n\t\t\tsignal,\n\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.debug(query, variables)\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"],"names":["_DataBinding","TreeRootAccessor","Config","createBatchUpdatesOptions","DirtinessTracker","EventManager","AccessorErrorManager","StateInitializer","TreeAugmenter","options","createQueryBuilder","ContentClient","MutationGenerator","GraphQlClientError","DataBindingExtendAborted","MarkerMerger","getCombinedSignal","QueryGenerator","query","StateIterator","assertNever","generateEnumerabilityPreventingEntropy"],"mappings":";;;;;;;;;;;;;;;;;;;AAkCO,MAAM,eAAN,MAAMA,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAbgB,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;AA7BD,kBAAA,MAAA,sBAAA;AACA,kBAAA,MAAA,qBAAA;AACA,kBAAA,MAAA,0BAAA;AACA,kBAAA,MAAA,mBAAA;AACA,kBAAA,MAAA,QAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,eAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,eAAA;AAuMjB,kBAAA,MAAQ,oBAAmB,CAAC,EAAE,WAAA,MAAiC;AACzD,WAAA,SAAS,IAAIC,cAAA,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA,CACvH;AAOQ,kBAAA,MAAA,yCAMC,IAAI,CAAA;AAEL,kBAAA,MAAA,aAAA;AAjMF,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,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ACF;AAAA,EAOQ,mBAAmB;AAG1B,WAAO,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAGC,uCAAAA,uCAAwC,CAAA,IAAIrB,cAAY,sBAAA,CAAuB;AAAA,EACtF;AACD;AAZC,cA3YY,cA2YG,yBAA+B,uBAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AACd,GAAG,CAAA;AA9YG,IAAM,cAAN;;"}
|
|
1
|
+
{"version":3,"file":"DataBinding.cjs","sources":["../../../../../packages/binding-legacy/src/core/DataBinding.ts"],"sourcesContent":["import { ContentClient, ContentQueryBuilder, GraphQlClient, GraphQlClientError } from '@contember/client'\nimport type { DataBindingTransactionResult, EntityId, Environment, MarkerTreeRoot, TreeRootId } from '@contember/binding-common'\nimport {\n\tassertNever,\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tErrorPersistResult,\n\tExtendTreeOptions,\n\tMarkerMerger,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tReceivedDataTree,\n\tSuccessfulPersistResult,\n\tTreeRootAccessor,\n} from '@contember/binding-common'\nimport { generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from '@contember/binding-common'\nimport { DataBindingExtendAborted } from '@contember/binding-common'\n\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\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\tfetchData: async (...args) => await this.fetchData(...args),\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.operations.length === 0) {\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\t// eslint-disable-next-line no-console\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 (response.ok && 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\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(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\tresponse,\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\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\ttype: 'invalidInput',\n\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\tonError?: (error: Error) => void\n\t}> = new Set()\n\n\tprivate flushResult: Promise<boolean> | undefined\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 (!options.force && 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(async (resolve, reject) => {\n\t\t\tconst treeRootId = this.getNewTreeRootId()\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: treeRootId,\n\t\t\t\toptions,\n\t\t\t\tonError: options.onError,\n\t\t\t})\n\t\t\tthis.flushResult ??= (async () => {\n\t\t\t\tawait Promise.resolve()\n\t\t\t\tthis.flushResult = undefined\n\t\t\t\treturn await this.flushBatchedTreeExtensions()\n\t\t\t})()\n\n\t\t\tif (!(await this.flushResult) || options.signal?.aborted) {\n\t\t\t\treturn reject(DataBindingExtendAborted)\n\t\t\t}\n\n\t\t\tresolve(treeRootId)\n\t\t})\n\t}\n\n\tpublic async fetchData(fragment: Node, options?: { signal?: AbortSignal; environment?: Environment }): Promise<{\n\t\tdata: ReceivedDataTree\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t}> {\n\t\tconst markerTreeRoot = this.createMarkerTree(fragment, options?.environment ?? this.environment)\n\t\tconst data = await this.fetchPersistedData(markerTreeRoot, options?.signal)\n\n\t\treturn {\n\t\t\tdata: data,\n\t\t\tmarkerTreeRoot,\n\t\t}\n\t}\n\n\tprivate async flushBatchedTreeExtensions(): Promise<boolean> {\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\treturn !extension.options.signal?.aborted\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 false\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tlet aggregatePersistedData: ReceivedDataTree\n\t\ttry {\n\t\t\taggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\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 false\n\t\t\t\t}\n\t\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\t\textension.onError?.(e)\n\t\t\t\t}\n\t\t\t\tif (!pendingExtensions.every(it => !!it.onError)) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t} else {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn false\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}\n\t\t})\n\t\treturn true\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\treturn await this.contentClient.query(query, {\n\t\t\tsignal,\n\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.debug(query, variables)\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"],"names":["_DataBinding","TreeRootAccessor","Config","createBatchUpdatesOptions","DirtinessTracker","EventManager","AccessorErrorManager","StateInitializer","TreeAugmenter","options","createQueryBuilder","ContentClient","MutationGenerator","GraphQlClientError","DataBindingExtendAborted","MarkerMerger","getCombinedSignal","QueryGenerator","query","StateIterator","assertNever","generateEnumerabilityPreventingEntropy"],"mappings":";;;;;;;;;;;;;;;;;;;AAkCO,MAAM,eAAN,MAAMA,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAbgB,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;AA7BD,kBAAA,MAAA,sBAAA;AACA,kBAAA,MAAA,qBAAA;AACA,kBAAA,MAAA,0BAAA;AACA,kBAAA,MAAA,mBAAA;AACA,kBAAA,MAAA,QAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,eAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,eAAA;AAuMjB,kBAAA,MAAQ,oBAAmB,CAAC,EAAE,WAAA,MAAiC;AACzD,WAAA,SAAS,IAAIC,cAAA,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA,CACvH;AAOQ,kBAAA,MAAA,yCAMC,IAAI,CAAA;AAEL,kBAAA,MAAA,aAAA;AAjMF,SAAA,SAAS,IAAIC,cAAO;AACzB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K,eAAe;AACnB,kBAAI,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;AAC5E,sBAAM,0BAA0B;AAChC,sBAAM,wBAAwB,MAAM;AACpC,qBAAK,aAAa,oBAAoB,OAAOA,aAAAA,aAAa,qBAAqB;AAAA,cAAA;AAEhF;AAAA,YAAA;AAAA,YAED;AACCe,4BAAAA,YAAY,KAAK;AAAA,UAAA;AAAA,QACnB;AAAA,MACD;AAAA,IACD,CACA;AAAA,EAAA;AAAA,EAQM,mBAAmB;AAG1B,WAAO,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAGC,uCAAA,uCAAA,CAAwC,IAAIrB,cAAY,sBAAuB,CAAA;AAAA,EAAA;AAEvF;AAZC,cA3YY,cA2YG,yBAA+B,uBAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AACd,IAAG;AA9YG,IAAM,cAAN;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataBinding.js","sources":["../../../../../packages/binding-legacy/src/core/DataBinding.ts"],"sourcesContent":["import { ContentClient, ContentQueryBuilder, GraphQlClient, GraphQlClientError } from '@contember/client'\nimport type { DataBindingTransactionResult, EntityId, Environment, MarkerTreeRoot, TreeRootId } from '@contember/binding-common'\nimport {\n\tassertNever,\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tErrorPersistResult,\n\tExtendTreeOptions,\n\tMarkerMerger,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tReceivedDataTree,\n\tSuccessfulPersistResult,\n\tTreeRootAccessor,\n} from '@contember/binding-common'\nimport { generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from '@contember/binding-common'\nimport { DataBindingExtendAborted } from '@contember/binding-common'\n\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\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\tfetchData: async (...args) => await this.fetchData(...args),\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.operations.length === 0) {\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\t// eslint-disable-next-line no-console\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 (response.ok && 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\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(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\tresponse,\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\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\ttype: 'invalidInput',\n\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\tonError?: (error: Error) => void\n\t}> = new Set()\n\n\tprivate flushResult: Promise<boolean> | undefined\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 (!options.force && 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(async (resolve, reject) => {\n\t\t\tconst treeRootId = this.getNewTreeRootId()\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: treeRootId,\n\t\t\t\toptions,\n\t\t\t\tonError: options.onError,\n\t\t\t})\n\t\t\tthis.flushResult ??= (async () => {\n\t\t\t\tawait Promise.resolve()\n\t\t\t\tthis.flushResult = undefined\n\t\t\t\treturn await this.flushBatchedTreeExtensions()\n\t\t\t})()\n\n\t\t\tif (!(await this.flushResult) || options.signal?.aborted) {\n\t\t\t\treturn reject(DataBindingExtendAborted)\n\t\t\t}\n\n\t\t\tresolve(treeRootId)\n\t\t})\n\t}\n\n\tpublic async fetchData(fragment: Node, options?: { signal?: AbortSignal; environment?: Environment }): Promise<{\n\t\tdata: ReceivedDataTree\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t}> {\n\t\tconst markerTreeRoot = this.createMarkerTree(fragment, options?.environment ?? this.environment)\n\t\tconst data = await this.fetchPersistedData(markerTreeRoot, options?.signal)\n\n\t\treturn {\n\t\t\tdata: data,\n\t\t\tmarkerTreeRoot,\n\t\t}\n\t}\n\n\tprivate async flushBatchedTreeExtensions(): Promise<boolean> {\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\treturn !extension.options.signal?.aborted\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 false\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tlet aggregatePersistedData: ReceivedDataTree\n\t\ttry {\n\t\t\taggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\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 false\n\t\t\t\t}\n\t\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\t\textension.onError?.(e)\n\t\t\t\t}\n\t\t\t\tif (!pendingExtensions.every(it => !!it.onError)) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t} else {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn false\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}\n\t\t})\n\t\treturn true\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\treturn await this.contentClient.query(query, {\n\t\t\tsignal,\n\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.debug(query, variables)\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"],"names":["_DataBinding","options","query"],"mappings":";;;;;;;;;;;;;;;;;AAkCO,MAAM,eAAN,MAAMA,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAbgB,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;AA7BD,kBAAA,MAAA,sBAAA;AACA,kBAAA,MAAA,qBAAA;AACA,kBAAA,MAAA,0BAAA;AACA,kBAAA,MAAA,mBAAA;AACA,kBAAA,MAAA,QAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,eAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,eAAA;AAuMjB,kBAAA,MAAQ,oBAAmB,CAAC,EAAE,WAAA,MAAiC;AACzD,WAAA,SAAS,IAAI,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA,CACvH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ACA;AACC,0BAAY,KAAK;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAG1B,WAAO,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAAwC,CAAA,IAAIF,cAAY,sBAAA,CAAuB;AAAA,EACtF;AACD;AAZC,cA3YY,cA2YG,yBAA+B,uBAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AACd,GAAG,CAAA;AA9YG,IAAM,cAAN;"}
|
|
1
|
+
{"version":3,"file":"DataBinding.js","sources":["../../../../../packages/binding-legacy/src/core/DataBinding.ts"],"sourcesContent":["import { ContentClient, ContentQueryBuilder, GraphQlClient, GraphQlClientError } from '@contember/client'\nimport type { DataBindingTransactionResult, EntityId, Environment, MarkerTreeRoot, TreeRootId } from '@contember/binding-common'\nimport {\n\tassertNever,\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tErrorPersistResult,\n\tExtendTreeOptions,\n\tMarkerMerger,\n\tPersistOptions,\n\tPersistSuccessOptions,\n\tReceivedDataTree,\n\tSuccessfulPersistResult,\n\tTreeRootAccessor,\n} from '@contember/binding-common'\nimport { generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\nimport { createQueryBuilder } from '@contember/binding-common'\nimport { DataBindingExtendAborted } from '@contember/binding-common'\n\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\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\tfetchData: async (...args) => await this.fetchData(...args),\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.operations.length === 0) {\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\t// eslint-disable-next-line no-console\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 (response.ok && 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\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.debug(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\tresponse,\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\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\ttype: 'invalidInput',\n\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\tonError?: (error: Error) => void\n\t}> = new Set()\n\n\tprivate flushResult: Promise<boolean> | undefined\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 (!options.force && 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(async (resolve, reject) => {\n\t\t\tconst treeRootId = this.getNewTreeRootId()\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: treeRootId,\n\t\t\t\toptions,\n\t\t\t\tonError: options.onError,\n\t\t\t})\n\t\t\tthis.flushResult ??= (async () => {\n\t\t\t\tawait Promise.resolve()\n\t\t\t\tthis.flushResult = undefined\n\t\t\t\treturn await this.flushBatchedTreeExtensions()\n\t\t\t})()\n\n\t\t\tif (!(await this.flushResult) || options.signal?.aborted) {\n\t\t\t\treturn reject(DataBindingExtendAborted)\n\t\t\t}\n\n\t\t\tresolve(treeRootId)\n\t\t})\n\t}\n\n\tpublic async fetchData(fragment: Node, options?: { signal?: AbortSignal; environment?: Environment }): Promise<{\n\t\tdata: ReceivedDataTree\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t}> {\n\t\tconst markerTreeRoot = this.createMarkerTree(fragment, options?.environment ?? this.environment)\n\t\tconst data = await this.fetchPersistedData(markerTreeRoot, options?.signal)\n\n\t\treturn {\n\t\t\tdata: data,\n\t\t\tmarkerTreeRoot,\n\t\t}\n\t}\n\n\tprivate async flushBatchedTreeExtensions(): Promise<boolean> {\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\treturn !extension.options.signal?.aborted\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 false\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tlet aggregatePersistedData: ReceivedDataTree\n\t\ttry {\n\t\t\taggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\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 false\n\t\t\t\t}\n\t\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\t\textension.onError?.(e)\n\t\t\t\t}\n\t\t\t\tif (!pendingExtensions.every(it => !!it.onError)) {\n\t\t\t\t\tthis.onError(e, this)\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t} else {\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn false\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}\n\t\t})\n\t\treturn true\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<ReceivedDataTree> {\n\t\tconst queryGenerator = new QueryGenerator(tree, this.queryBuilder)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\treturn await this.contentClient.query(query, {\n\t\t\tsignal,\n\t\t\tonBeforeRequest: ({ query, variables }) => {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.debug(query, variables)\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"],"names":["_DataBinding","options","query"],"mappings":";;;;;;;;;;;;;;;;;AAkCO,MAAM,eAAN,MAAMA,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBvB,YACW,kBACA,iBACA,iBACA,WACA,aACA,kBACA,gBACA,UACA,SACA,kBACA,SAGhB;AAbgB,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;AA7BD,kBAAA,MAAA,sBAAA;AACA,kBAAA,MAAA,qBAAA;AACA,kBAAA,MAAA,0BAAA;AACA,kBAAA,MAAA,mBAAA;AACA,kBAAA,MAAA,QAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,kBAAA;AACA,kBAAA,MAAA,eAAA;AACA,kBAAA,MAAA,cAAA;AACA,kBAAA,MAAA,eAAA;AAuMjB,kBAAA,MAAQ,oBAAmB,CAAC,EAAE,WAAA,MAAiC;AACzD,WAAA,SAAS,IAAI,iBAAuB,KAAK,iBAAiB,WAAW,GAAG,YAAY,KAAK,iBAAiB,GAAG,IAAI;AAAA,IAAA,CACvH;AAOQ,kBAAA,MAAA,yCAMC,IAAI,CAAA;AAEL,kBAAA,MAAA,aAAA;AAjMF,SAAA,SAAS,IAAI,OAAO;AACzB,SAAK,sBAAsB,0BAA0B,aAAa,KAAK,SAAS;AAChF,SAAK,2BAA2B;AAAA,MAC/B,GAAG,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA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;AAAA,EAQM,mBAAmB;AAG1B,WAAO,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAAA,CAAwC,IAAIF,cAAY,sBAAuB,CAAA;AAAA,EAAA;AAEvF;AAZC,cA3YY,cA2YG,yBAA+B,uBAAA;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AACd,IAAG;AA9YG,IAAM,cAAN;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirtinessTracker.cjs","sources":["../../../../../packages/binding-legacy/src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate touchedCount = 0\n\n\tpublic getTotalTouchCount() {\n\t\treturn this.touchedCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t\tthis.touchedCount++\n\t}\n}\n"],"names":[],"mappings":";;;;;AAAO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAEhB,qBAAqB;AAC3B,WAAO,KAAK;AAAA,
|
|
1
|
+
{"version":3,"file":"DirtinessTracker.cjs","sources":["../../../../../packages/binding-legacy/src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate touchedCount = 0\n\n\tpublic getTotalTouchCount() {\n\t\treturn this.touchedCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t\tthis.touchedCount++\n\t}\n}\n"],"names":[],"mappings":";;;;;AAAO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAEhB,qBAAqB;AAC3B,WAAO,KAAK;AAAA,EAAA;AAAA,EAGN,aAAa;AACnB,WAAO,KAAK,eAAe;AAAA,EAAA;AAAA,EAGrB,QAAQ;AACd,SAAK,eAAe;AAAA,EAAA;AAAA,EAGd,WAAW,OAAe;AAChC,SAAK,gBAAgB;AAChB,SAAA;AAAA,EAAA;AAEP;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirtinessTracker.js","sources":["../../../../../packages/binding-legacy/src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate touchedCount = 0\n\n\tpublic getTotalTouchCount() {\n\t\treturn this.touchedCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t\tthis.touchedCount++\n\t}\n}\n"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAEhB,qBAAqB;AAC3B,WAAO,KAAK;AAAA,
|
|
1
|
+
{"version":3,"file":"DirtinessTracker.js","sources":["../../../../../packages/binding-legacy/src/core/DirtinessTracker.ts"],"sourcesContent":["export class DirtinessTracker {\n\tprivate changesCount = 0\n\tprivate touchedCount = 0\n\n\tpublic getTotalTouchCount() {\n\t\treturn this.touchedCount\n\t}\n\n\tpublic hasChanges() {\n\t\treturn this.changesCount > 0\n\t}\n\n\tpublic reset() {\n\t\tthis.changesCount = 0\n\t}\n\n\tpublic increaseBy(delta: number) {\n\t\tthis.changesCount += delta\n\t\tthis.touchedCount++\n\t}\n}\n"],"names":[],"mappings":";;;AAAO,MAAM,iBAAiB;AAAA,EAAvB,cAAA;AACN,kBAAA,MAAQ,gBAAe,CAAA;AACvB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAEhB,qBAAqB;AAC3B,WAAO,KAAK;AAAA,EAAA;AAAA,EAGN,aAAa;AACnB,WAAO,KAAK,eAAe;AAAA,EAAA;AAAA,EAGrB,QAAQ;AACd,SAAK,eAAe;AAAA,EAAA;AAAA,EAGd,WAAW,OAAe;AAChC,SAAK,gBAAgB;AAChB,SAAA;AAAA,EAAA;AAEP;"}
|