@contember/binding 0.7.0-beta.5 → 0.8.0-alpha.10

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.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/dist/binding.d.ts +45 -7
  3. package/dist/development/accessorPropagation/useHasEntity.js +9 -0
  4. package/dist/development/accessorPropagation/useHasEntity.js.map +1 -0
  5. package/dist/development/accessors/EntityListAccessor.js +3 -3
  6. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  7. package/dist/development/core/DataBinding.js +1 -1
  8. package/dist/development/core/DataBinding.js.map +1 -1
  9. package/dist/development/core/MarkerTreeGenerator.js +2 -2
  10. package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
  11. package/dist/development/core/StateInitializer.js +63 -20
  12. package/dist/development/core/StateInitializer.js.map +1 -1
  13. package/dist/development/core/operations/ListOperations.js +7 -4
  14. package/dist/development/core/operations/ListOperations.js.map +1 -1
  15. package/dist/development/core/requestAliases/MutationAlias.js +1 -1
  16. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  17. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  18. package/dist/development/index.js +2 -0
  19. package/dist/development/index.js.map +1 -1
  20. package/dist/development/queryLanguage/CacheStore.js +2 -1
  21. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  22. package/dist/development/queryLanguage/Parser.js +60 -0
  23. package/dist/development/queryLanguage/Parser.js.map +1 -1
  24. package/dist/development/queryLanguage/QueryLanguage.js +1 -0
  25. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  26. package/dist/development/queryLanguage/tokenList.js +5 -0
  27. package/dist/development/queryLanguage/tokenList.js.map +1 -1
  28. package/dist/production/accessorPropagation/useHasEntity.js +7 -0
  29. package/dist/production/accessorPropagation/useHasEntity.js.map +1 -0
  30. package/dist/production/accessors/EntityListAccessor.js +3 -3
  31. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  32. package/dist/production/core/DataBinding.js +1 -1
  33. package/dist/production/core/DataBinding.js.map +1 -1
  34. package/dist/production/core/MarkerTreeGenerator.js +2 -2
  35. package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
  36. package/dist/production/core/StateInitializer.js +63 -20
  37. package/dist/production/core/StateInitializer.js.map +1 -1
  38. package/dist/production/core/operations/ListOperations.js +7 -4
  39. package/dist/production/core/operations/ListOperations.js.map +1 -1
  40. package/dist/production/core/requestAliases/MutationAlias.js +1 -1
  41. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  42. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  43. package/dist/production/index.js +2 -0
  44. package/dist/production/index.js.map +1 -1
  45. package/dist/production/queryLanguage/CacheStore.js +2 -1
  46. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  47. package/dist/production/queryLanguage/Parser.js +60 -0
  48. package/dist/production/queryLanguage/Parser.js.map +1 -1
  49. package/dist/production/queryLanguage/QueryLanguage.js +1 -0
  50. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  51. package/dist/production/queryLanguage/tokenList.js +5 -0
  52. package/dist/production/queryLanguage/tokenList.js.map +1 -1
  53. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"QueryLanguage.js","sources":["../../../src/queryLanguage/QueryLanguage.ts"],"sourcesContent":["import { emptyObject } from '@contember/react-utils'\nimport { TreeParameterMerger, VariableInputTransformer } from '../core'\nimport type { Environment } from '../dao'\nimport {\n\tAlias,\n\tEntityCreationParametersDefaults,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityListParameters,\n\tEntityListPreferencesDefaults,\n\tEntityName,\n\tEventListenersStore,\n\tFieldEventListenerStore,\n\tFieldName,\n\tFilter,\n\tHasManyRelation,\n\tHasOneRelation,\n\tLeafFieldDefaults,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedEntityParametersDefaults,\n\tQualifiedFieldList,\n\tQualifiedSingleEntity,\n\tRelationDefaults,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugarableEntityListParameters,\n\tSugarableHasManyRelation,\n\tSugarableHasOneRelation,\n\tSugaredFilter,\n\tSugaredParentEntityParameters,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedFieldList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n\tSugaredSetOnCreate,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n\tUnsugarableEntityListEventListeners,\n\tUnsugarableEntityListParameters,\n\tUnsugarableFieldEventListeners,\n\tUnsugarableHasManyRelation,\n\tUnsugarableHasOneRelation,\n\tUnsugarableSingleEntityEventListeners,\n} from '../treeParameters'\nimport { Parser } from './Parser'\nimport { GraphQlLiteral } from '@contember/client'\nimport { ParsedHasManyRelation, ParsedHasOneRelation } from './ParserResults'\n\nexport class QueryLanguage {\n\n\tprivate static preparePrimitiveEntryPoint<Entry extends Parser.EntryPoint>(entryPoint: Entry) {\n\t\treturn (input: string, environment: Environment): Parser.ParserResult[Entry] =>\n\t\t\tParser.parseQueryLanguageExpression(input, entryPoint, environment)\n\t}\n\n\tprivate static preparePrimitiveEntryPointWithFallback<Entry extends Parser.EntryPoint>(entryPoint: Entry) {\n\t\treturn (input: string | Parser.ParserResult[Entry], environment: Environment): Parser.ParserResult[Entry] => {\n\t\t\tif (typeof input === 'string') {\n\t\t\t\treturn Parser.parseQueryLanguageExpression(input, entryPoint, environment)\n\t\t\t}\n\t\t\treturn input\n\t\t}\n\t}\n\n\tprivate static parseUnconstrainedQualifiedEntityList = QueryLanguage.preparePrimitiveEntryPoint('unconstrainedQualifiedEntityList')\n\tprivate static parseUnconstrainedQualifiedSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('unconstrainedQualifiedEntityList')\n\tprivate static parseQualifiedEntityList = QueryLanguage.preparePrimitiveEntryPoint('qualifiedEntityList')\n\tprivate static parseQualifiedFieldList = QueryLanguage.preparePrimitiveEntryPoint('qualifiedFieldList')\n\tprivate static parseQualifiedSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('qualifiedSingleEntity')\n\tprivate static parseRelativeEntityList = QueryLanguage.preparePrimitiveEntryPoint('relativeEntityList')\n\tprivate static parseRelativeSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('relativeSingleEntity')\n\tprivate static parseRelativeSingleField = QueryLanguage.preparePrimitiveEntryPoint('relativeSingleField')\n\n\tpublic static desugarUniqueWhere = QueryLanguage.preparePrimitiveEntryPointWithFallback('uniqueWhere')\n\tpublic static desugarFilter = QueryLanguage.preparePrimitiveEntryPointWithFallback('filter')\n\tpublic static desugarOrderBy = QueryLanguage.preparePrimitiveEntryPointWithFallback('orderBy')\n\n\n\tprivate static desugarEntityListParameters(\n\t\tsugarablePart: SugarableEntityListParameters,\n\t\tunsugarablePart: UnsugarableEntityListParameters,\n\t\tenvironment: Environment,\n\t): EntityListParameters {\n\t\treturn {\n\t\t\tfilter: sugarablePart.filter ? this.desugarFilter(sugarablePart.filter, environment) : undefined,\n\t\t\tlimit: unsugarablePart.limit,\n\t\t\toffset: unsugarablePart.offset,\n\t\t\torderBy: unsugarablePart.orderBy ? this.desugarOrderBy(unsugarablePart.orderBy, environment) : undefined,\n\t\t\tinitialEntityCount: unsugarablePart.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t}\n\t}\n\n\tpublic static desugarSetOnCreate(setOnCreate: SugaredSetOnCreate, environment: Environment): UniqueWhere {\n\t\tif (Array.isArray(setOnCreate)) {\n\t\t\tconst whereList = setOnCreate.map(connection => this.desugarUniqueWhere(connection, environment))\n\t\t\treturn whereList.reduce(\n\t\t\t\t(accumulator, uniqueWhere) => TreeParameterMerger.mergeSetOnCreate(accumulator, uniqueWhere)!,\n\t\t\t)\n\t\t}\n\t\tif (typeof setOnCreate === 'string') {\n\t\t\treturn this.desugarUniqueWhere(setOnCreate, environment)\n\t\t}\n\t\treturn setOnCreate\n\t}\n\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F>): Set<F>\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F> | undefined): Set<F> | undefined\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F> | undefined): Set<F> | undefined {\n\t\tif (typeof listener === 'function') {\n\t\t\treturn new Set([listener])\n\t\t}\n\t\treturn listener\n\t}\n\n\tprivate static desugarSingleEntityEventListeners(\n\t\tunsugarable: UnsugarableSingleEntityEventListeners,\n\t): EntityEventListenerStore | undefined {\n\t\tif (\n\t\t\tunsugarable.onBeforePersist === undefined &&\n\t\t\tunsugarable.onBeforeUpdate === undefined &&\n\t\t\tunsugarable.onInitialize === undefined &&\n\t\t\tunsugarable.onPersistError === undefined &&\n\t\t\tunsugarable.onPersistSuccess === undefined &&\n\t\t\tunsugarable.onUpdate === undefined\n\t\t) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst store: EntityEventListenerStore = new EventListenersStore()\n\n\t\tif (unsugarable.onConnectionUpdate) {\n\t\t\tfor (const fieldName in unsugarable.onConnectionUpdate) {\n\t\t\t\tconst listener = this.desugarEventListener(unsugarable.onConnectionUpdate[fieldName])\n\t\t\t\tstore.set({ type: 'connectionUpdate', key: fieldName }, listener)\n\t\t\t}\n\t\t}\n\n\t\tconst beforePersist = this.desugarEventListener(unsugarable.onBeforePersist)\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst initialize = this.desugarEventListener(unsugarable.onInitialize)\n\t\tconst persistError = this.desugarEventListener(unsugarable.onPersistError)\n\t\tconst persistSuccess = this.desugarEventListener(unsugarable.onPersistSuccess)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforePersist) {\n\t\t\tstore.set({ type: 'beforePersist' }, beforePersist)\n\t\t}\n\t\tif (beforeUpdate) {\n\t\t\tstore.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (initialize) {\n\t\t\tstore.set({ type: 'initialize' }, initialize)\n\t\t}\n\t\tif (persistError) {\n\t\t\tstore.set({ type: 'persistError' }, persistError)\n\t\t}\n\t\tif (persistSuccess) {\n\t\t\tstore.set({ type: 'persistSuccess' }, persistSuccess)\n\t\t}\n\t\tif (update) {\n\t\t\tstore.set({ type: 'update' }, update)\n\t\t}\n\n\t\treturn store\n\t}\n\n\tprivate static desugarEntityListEventListeners(unsugarable: UnsugarableEntityListEventListeners):\n\t\t| {\n\t\t\t\teventListeners: EntityListEventListenerStore | undefined\n\t\t\t\tchildEventListeners: EntityEventListenerStore | undefined\n\t\t }\n\t\t| undefined {\n\t\tif (\n\t\t\tunsugarable.onBeforePersist === undefined &&\n\t\t\tunsugarable.onBeforeUpdate === undefined &&\n\t\t\tunsugarable.onChildBeforeUpdate === undefined &&\n\t\t\tunsugarable.onChildInitialize === undefined &&\n\t\t\tunsugarable.onChildUpdate === undefined &&\n\t\t\tunsugarable.onInitialize === undefined &&\n\t\t\tunsugarable.onPersistError === undefined &&\n\t\t\tunsugarable.onPersistSuccess === undefined &&\n\t\t\tunsugarable.onUpdate === undefined\n\t\t) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst eventListeners: EntityListEventListenerStore = new EventListenersStore()\n\n\t\tconst beforePersist = this.desugarEventListener(unsugarable.onBeforePersist)\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst initialize = this.desugarEventListener(unsugarable.onInitialize)\n\t\tconst persistError = this.desugarEventListener(unsugarable.onPersistError)\n\t\tconst persistSuccess = this.desugarEventListener(unsugarable.onPersistSuccess)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforePersist) {\n\t\t\teventListeners.set({ type: 'beforePersist' }, beforePersist)\n\t\t}\n\t\tif (beforeUpdate) {\n\t\t\teventListeners.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (initialize) {\n\t\t\teventListeners.set({ type: 'initialize' }, initialize)\n\t\t}\n\t\tif (persistError) {\n\t\t\teventListeners.set({ type: 'persistError' }, persistError)\n\t\t}\n\t\tif (persistSuccess) {\n\t\t\teventListeners.set({ type: 'persistSuccess' }, persistSuccess)\n\t\t}\n\t\tif (update) {\n\t\t\teventListeners.set({ type: 'update' }, update)\n\t\t}\n\n\t\tconst childEventListeners: EntityEventListenerStore = new EventListenersStore()\n\n\t\tconst childBeforeUpdate = this.desugarEventListener(unsugarable.onChildBeforeUpdate)\n\t\tconst childInitialize = this.desugarEventListener(unsugarable.onChildInitialize)\n\t\tconst childUpdate = this.desugarEventListener(unsugarable.onChildUpdate)\n\n\t\tif (childBeforeUpdate) {\n\t\t\tchildEventListeners.set({ type: 'beforeUpdate' }, childBeforeUpdate)\n\t\t}\n\t\tif (childInitialize) {\n\t\t\tchildEventListeners.set({ type: 'initialize' }, childInitialize)\n\t\t}\n\t\tif (childUpdate) {\n\t\t\tchildEventListeners.set({ type: 'update' }, childUpdate)\n\t\t}\n\n\t\treturn {\n\t\t\teventListeners,\n\t\t\tchildEventListeners,\n\t\t}\n\t}\n\n\tprivate static desugarFieldEventListeners(\n\t\tunsugarable: UnsugarableFieldEventListeners,\n\t): FieldEventListenerStore | undefined {\n\t\tif (unsugarable.onBeforeUpdate === undefined && unsugarable.onUpdate === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst store: FieldEventListenerStore = new EventListenersStore()\n\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforeUpdate) {\n\t\t\tstore.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (update) {\n\t\t\tstore.set({ type: 'update' }, update)\n\t\t}\n\n\t\treturn store\n\t}\n\n\tprivate static desugarSubTreeAlias(alias: Alias | Set<Alias> | undefined): Set<Alias> | undefined {\n\t\tif (alias === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (alias instanceof Set) {\n\t\t\treturn alias\n\t\t}\n\t\treturn new Set<Alias>().add(alias)\n\t}\n\n\tprivate static desugarHasOneRelation(\n\t\tsugarable: SugarableHasOneRelation,\n\t\tunsugarable: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\tfield: sugarable.field,\n\t\t\tfilter: sugarable.filter ? this.desugarFilter(sugarable.filter, environment) : undefined,\n\t\t\texpectedMutation: unsugarable.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\treducedBy: sugarable.reducedBy ? this.desugarUniqueWhere(sugarable.reducedBy, environment) : undefined,\n\t\t\tsetOnCreate: unsugarable.setOnCreate ? this.desugarSetOnCreate(unsugarable.setOnCreate, environment) : undefined,\n\t\t\tisNonbearing: unsugarable.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarable.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(unsugarable),\n\t\t}\n\t}\n\n\tprivate static augmentDesugaredHasOneRelationPath(\n\t\tpath: ParsedHasOneRelation[],\n\t\tunsugarable: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation[] {\n\t\treturn path.map((desugaredHasOneRelation, i) =>\n\t\t\t// Unsugarable applies to the last\n\t\t\tthis.desugarHasOneRelation(desugaredHasOneRelation, i === path.length - 1 ? unsugarable : {}, environment),\n\t\t)\n\t}\n\n\tprivate static augmentDesugaredHasManyRelation(\n\t\trelation: ParsedHasManyRelation,\n\t\tunsugarable: UnsugarableHasManyRelation,\n\t\tenvironment: Environment,\n\t): HasManyRelation {\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarable)\n\t\treturn {\n\t\t\tfield: relation.field,\n\t\t\tfilter: relation.filter,\n\t\t\texpectedMutation: unsugarable.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\tisNonbearing: unsugarable.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarable.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tinitialEntityCount: unsugarable.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t\tsetOnCreate: unsugarable.setOnCreate ? this.desugarSetOnCreate(unsugarable.setOnCreate, environment) : undefined,\n\t\t\torderBy: unsugarable.orderBy ? this.desugarOrderBy(unsugarable.orderBy, environment) : undefined,\n\t\t\toffset: unsugarable.offset,\n\t\t\tlimit: unsugarable.limit,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tprivate static desugarHasOneRelationPath(\n\t\tinput: SugarableHasOneRelation[] | SugarableHasOneRelation | undefined,\n\t\tlastRelation: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation[] {\n\t\tif (input === undefined) {\n\t\t\tinput = []\n\t\t} else if (!Array.isArray(input)) {\n\t\t\tinput = [input]\n\t\t}\n\n\t\tconst relationPath: HasOneRelation[] = []\n\n\t\tconst cappedLength = input.length - 1\n\t\tlet i = 0\n\t\tfor (; i < cappedLength; i++) {\n\t\t\t// Deliberately leaving out the last element\n\t\t\tconst pathNode = input[i]\n\n\t\t\trelationPath.push(this.desugarHasOneRelation(pathNode, {}, environment))\n\t\t}\n\t\tif (i in input) {\n\t\t\trelationPath.push(this.desugarHasOneRelation(input[i], lastRelation, environment))\n\t\t}\n\n\t\treturn relationPath\n\t}\n\n\tprivate static desugarHasManyRelation(\n\t\tsugarablePart: SugarableHasManyRelation,\n\t\tunsugarablePart: UnsugarableHasManyRelation,\n\t\tenvironment: Environment,\n\t): HasManyRelation {\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarablePart)\n\t\treturn {\n\t\t\t...this.desugarEntityListParameters(sugarablePart, unsugarablePart, environment),\n\t\t\texpectedMutation: unsugarablePart.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\tsetOnCreate: unsugarablePart.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarablePart.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\tfield: sugarablePart.field,\n\t\t\tisNonbearing: unsugarablePart.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarablePart.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tpublic static desugarUnconstrainedQualifiedEntityList(\n\t\t{ entities, ...unsugarableEntityList }: SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): UnconstrainedQualifiedEntityList {\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet entityName: EntityName\n\n\t\tif (typeof entities === 'string') {\n\t\t\tconst parsed = this.parseUnconstrainedQualifiedEntityList(entities, environment)\n\t\t\tentityName = parsed.entityName\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entities.entityName\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(entities.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarableEntityList)\n\n\t\treturn {\n\t\t\tisCreating: true,\n\t\t\tisNonbearing: unsugarableEntityList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableEntityList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableEntityList.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableEntityList.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableEntityList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t\tinitialEntityCount: unsugarableEntityList.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t\talias: this.desugarSubTreeAlias(unsugarableEntityList.alias),\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarUnconstrainedQualifiedSingleEntity(\n\t\t{ entity, ...unsugarableSingleEntity }: SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): UnconstrainedQualifiedSingleEntity {\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet entityName: EntityName\n\n\t\tif (typeof entity === 'string') {\n\t\t\tconst parsed = this.parseUnconstrainedQualifiedSingleEntity(entity, environment)\n\t\t\tentityName = parsed.entityName\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entity.entityName\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(\n\t\t\t\tentity.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\tisCreating: true,\n\t\t\tisNonbearing: unsugarableSingleEntity.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableSingleEntity.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableSingleEntity.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableSingleEntity.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableSingleEntity.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(unsugarableSingleEntity),\n\t\t\talias: this.desugarSubTreeAlias(unsugarableSingleEntity.alias),\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedEntityList(\n\t\t{ entities, ...unsugarableEntityList }: SugaredQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): QualifiedEntityList {\n\t\tlet entityName: EntityName\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tlet filter: SugaredFilter | undefined\n\n\t\tif (typeof entities === 'string') {\n\t\t\tconst parsed = this.parseQualifiedEntityList(entities, environment)\n\n\t\t\tentityName = parsed.entityName\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entities.entityName\n\t\t\tfilter = entities.filter\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(entities.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarableEntityList)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t\t...this.desugarEntityListParameters(\n\t\t\t\t{\n\t\t\t\t\tfilter,\n\t\t\t\t},\n\t\t\t\tunsugarableEntityList,\n\t\t\t\tenvironment,\n\t\t\t),\n\t\t\talias: this.desugarSubTreeAlias(unsugarableEntityList.alias),\n\t\t\tisCreating: false,\n\t\t\tisNonbearing: unsugarableEntityList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableEntityList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableEntityList.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableEntityList.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableEntityList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedFieldList(\n\t\t{ fields, ...unsugarableFieldList }: SugaredQualifiedFieldList,\n\t\tenvironment: Environment,\n\t): QualifiedFieldList {\n\t\tlet field: FieldName\n\t\tlet entityName: EntityName\n\t\tlet filter: SugaredFilter | undefined\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tif (typeof fields === 'string') {\n\t\t\tconst parsed = this.parseQualifiedFieldList(fields, environment)\n\n\t\t\tfield = parsed.field\n\t\t\tentityName = parsed.entityName\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tfield = fields.field\n\t\t\tentityName = fields.entityName\n\t\t\tfilter = fields.filter\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(fields.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\treturn {\n\t\t\tfield,\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t\talias: this.desugarSubTreeAlias(unsugarableFieldList.alias),\n\t\t\tisNonbearing: unsugarableFieldList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableFieldList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tdefaultValue:\n\t\t\t\tunsugarableFieldList.defaultValue !== undefined\n\t\t\t\t\t? VariableInputTransformer.transformValue(unsugarableFieldList.defaultValue, environment)\n\t\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableFieldList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\teventListeners: this.desugarFieldEventListeners(unsugarableFieldList),\n\t\t\t...this.desugarEntityListParameters({ filter }, unsugarableFieldList, environment),\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedSingleEntity(\n\t\t{ entity, ...unsugarableSingleEntity }: SugaredQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t\toptions: { missingSetOnCreate?: 'fill' | 'fillAndWarn' } = {},\n\t): QualifiedSingleEntity {\n\t\tlet entityName: EntityName\n\t\tlet where: UniqueWhere\n\t\tlet filter: Filter | undefined\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tif (typeof entity === 'string') {\n\t\t\tconst parsed = this.parseQualifiedSingleEntity(entity, environment)\n\n\t\t\tentityName = parsed.entityName\n\t\t\twhere = parsed.where\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entity.entityName\n\t\t\twhere = this.desugarUniqueWhere(entity.where, environment)\n\t\t\tfilter = entity.filter ? this.desugarFilter(entity.filter, environment) : undefined\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(\n\t\t\t\tentity.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\t// const forceCreation: boolean =\n\t\t// \tunsugarableSingleEntity.forceCreation !== undefined\n\t\t// \t\t? unsugarableSingleEntity.forceCreation !== undefined\n\t\t// \t\t: EntityCreationParametersDefaults.forceCreation\n\t\tlet setOnCreate: UniqueWhere | undefined =\n\t\t\tunsugarableSingleEntity.setOnCreate !== undefined\n\t\t\t\t? this.desugarSetOnCreate(unsugarableSingleEntity.setOnCreate, environment)\n\t\t\t\t: undefined\n\n\t\t// todo: remove deprecated code\n\t\tif (!setOnCreate && options.missingSetOnCreate) {\n\t\t\tconst whereValues = Object.values(where)\n\t\t\tif (whereValues.length === 1 && whereValues[0] instanceof GraphQlLiteral) {\n\t\t\t\tsetOnCreate = where\n\t\t\t\tif (import.meta.env.DEV && options.missingSetOnCreate === 'fillAndWarn') {\n\t\t\t\t\tconsole.warn('Automatic creation of singleton entities in EditPage is deprecated. Please use setOnCreate prop.')\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst isNonbearing: boolean =\n\t\t\tunsugarableSingleEntity.isNonbearing !== undefined\n\t\t\t\t? unsugarableSingleEntity.isNonbearing\n\t\t\t\t: EntityCreationParametersDefaults.isNonbearing\n\t\tconst eventListeners = this.desugarSingleEntityEventListeners(unsugarableSingleEntity)\n\t\tconst expectedMutation =\n\t\t\tunsugarableSingleEntity.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation\n\t\tconst alias = this.desugarSubTreeAlias(unsugarableSingleEntity.alias)\n\n\t\treturn {\n\t\t\talias,\n\t\t\tentityName,\n\t\t\tisCreating: false,\n\t\t\twhere,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t\t// forceCreation,\n\t\t\tsetOnCreate,\n\t\t\tisNonbearing,\n\t\t\teventListeners,\n\t\t\texpectedMutation,\n\t\t}\n\t}\n\n\tpublic static desugarParentEntityParameters(\n\t\tparentEntity: SugaredParentEntityParameters,\n\t\tenvironment: Environment,\n\t): ParentEntityParameters {\n\t\treturn {\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(parentEntity),\n\t\t}\n\t}\n\n\tpublic static desugarRelativeSingleEntity(\n\t\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity,\n\t\tenvironment: Environment,\n\t): RelativeSingleEntity {\n\t\tif (typeof sugaredRelativeSingleEntity === 'string') {\n\t\t\treturn this.desugarRelativeSingleEntity({ field: sugaredRelativeSingleEntity }, environment)\n\t\t}\n\n\t\tconst { field, ...unsugarableEntity } = sugaredRelativeSingleEntity\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeSingleEntity(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field, unsugarableEntity, environment)\n\t\t}\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarRelativeSingleField(\n\t\tsugaredRelativeSingleField: string | SugaredRelativeSingleField,\n\t\tenvironment: Environment,\n\t): RelativeSingleField {\n\t\tif (typeof sugaredRelativeSingleField === 'string') {\n\t\t\treturn this.desugarRelativeSingleField({ field: sugaredRelativeSingleField }, environment)\n\t\t}\n\n\t\tconst { field, ...unsugarableField } = sugaredRelativeSingleField\n\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet fieldName: FieldName\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeSingleField(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(parsed.hasOneRelationPath, {}, environment)\n\t\t\tfieldName = parsed.field\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field.hasOneRelationPath, {}, environment)\n\t\t\tfieldName = field.field\n\t\t}\n\n\t\treturn {\n\t\t\teventListeners: this.desugarFieldEventListeners(unsugarableField),\n\t\t\thasOneRelationPath,\n\t\t\tfield: fieldName,\n\t\t\tisNonbearing: unsugarableField.isNonbearing ?? LeafFieldDefaults.isNonbearing,\n\t\t\tdefaultValue:\n\t\t\t\tunsugarableField.defaultValue !== undefined\n\t\t\t\t\t? VariableInputTransformer.transformValue(unsugarableField.defaultValue, environment)\n\t\t\t\t\t: undefined,\n\t\t}\n\t}\n\n\tpublic static desugarRelativeEntityList(\n\t\tsugaredRelativeEntityList: string | SugaredRelativeEntityList,\n\t\tenvironment: Environment,\n\t): RelativeEntityList {\n\t\tif (typeof sugaredRelativeEntityList === 'string') {\n\t\t\treturn this.desugarRelativeEntityList(\n\t\t\t\t{\n\t\t\t\t\tfield: sugaredRelativeEntityList,\n\t\t\t\t},\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\tconst { field, ...unsugarableEntityList } = sugaredRelativeEntityList\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet hasManyRelation: HasManyRelation\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeEntityList(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t\thasManyRelation = this.augmentDesugaredHasManyRelation(\n\t\t\t\tparsed.hasManyRelation,\n\t\t\t\tunsugarableEntityList,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field.hasOneRelationPath || [], emptyObject, environment)\n\t\t\thasManyRelation = this.desugarHasManyRelation(field.hasManyRelation, unsugarableEntityList, environment)\n\t\t}\n\n\t\treturn {\n\t\t\thasManyRelation,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;oBAuD2B;AAAA,SAEX,2BAA4D,YAAmB;AAC7F,WAAO,CAAC,OAAe,gBACtB,OAAO,6BAA6B,OAAO,YAAY;AAAA;AAAA,SAG1C,uCAAwE,YAAmB;AACzG,WAAO,CAAC,OAA4C,gBAAyD;AAC5G,UAAI,OAAO,UAAU,UAAU;AAC9B,eAAO,OAAO,6BAA6B,OAAO,YAAY;AAAA;AAE/D,aAAO;AAAA;AAAA;AAAA,SAIM,wCAAwC,cAAc,2BAA2B;AAAA,SACjF,0CAA0C,cAAc,2BAA2B;AAAA,SACnF,2BAA2B,cAAc,2BAA2B;AAAA,SACpE,0BAA0B,cAAc,2BAA2B;AAAA,SACnE,6BAA6B,cAAc,2BAA2B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B,UAAU;AACnD,aAAO,KAAK,2BAA2B,EAAE,OAAO,8BAA8B;AAAA;AAG/E,UAAM,EAAE,UAAU,qBAAqB;AAEvC,QAAI;AACJ,QAAI;AACJ,QAAI,OAAO,UAAU,UAAU;AAC9B,YAAM,SAAS,KAAK,yBAAyB,OAAO;AACpD,2BAAqB,KAAK,mCAAmC,OAAO,oBAAoB,IAAI;AAC5F,kBAAY,OAAO;AAAA,WACb;AACN,2BAAqB,KAAK,0BAA0B,MAAM,oBAAoB,IAAI;AAClF,kBAAY,MAAM;AAAA;AAGnB,WAAO;AAAA,MACN,gBAAgB,KAAK,2BAA2B;AAAA,MAChD;AAAA,MACA,OAAO;AAAA,MACP,cAAc,iBAAiB,gBAAgB,kBAAkB;AAAA,MACjE,cACC,iBAAiB,iBAAiB,SAC/B,yBAAyB,eAAe,iBAAiB,cAAc,eACvE;AAAA;AAAA;AAAA,SAIQ,0BACb,2BACA,aACqB;AACrB,QAAI,OAAO,8BAA8B,UAAU;AAClD,aAAO,KAAK,0BACX;AAAA,QACC,OAAO;AAAA,SAER;AAAA;AAIF,UAAM,EAAE,UAAU,0BAA0B;AAC5C,QAAI;AACJ,QAAI;AACJ,QAAI,OAAO,UAAU,UAAU;AAC9B,YAAM,SAAS,KAAK,wBAAwB,OAAO;AACnD,2BAAqB,KAAK,mCACzB,OAAO,oBACP,aACA;AAED,wBAAkB,KAAK,gCACtB,OAAO,iBACP,uBACA;AAAA,WAEK;AACN,2BAAqB,KAAK,0BAA0B,MAAM,sBAAsB,IAAI,aAAa;AACjG,wBAAkB,KAAK,uBAAuB,MAAM,iBAAiB,uBAAuB;AAAA;AAG7F,WAAO;AAAA,MACN;AAAA,MACA;AAAA;AAAA;AAAA;;;;"}
1
+ {"version":3,"file":"QueryLanguage.js","sources":["../../../src/queryLanguage/QueryLanguage.ts"],"sourcesContent":["import { emptyObject } from '@contember/react-utils'\nimport { TreeParameterMerger, VariableInputTransformer } from '../core'\nimport type { Environment } from '../dao'\nimport {\n\tAlias,\n\tEntityCreationParametersDefaults,\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityListParameters,\n\tEntityListPreferencesDefaults,\n\tEntityName,\n\tEventListenersStore,\n\tFieldEventListenerStore,\n\tFieldName,\n\tFilter,\n\tHasManyRelation,\n\tHasOneRelation,\n\tLeafFieldDefaults,\n\tParentEntityParameters,\n\tQualifiedEntityList,\n\tQualifiedEntityParametersDefaults,\n\tQualifiedFieldList,\n\tQualifiedSingleEntity,\n\tRelationDefaults,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugarableEntityListParameters,\n\tSugarableHasManyRelation,\n\tSugarableHasOneRelation,\n\tSugaredFilter,\n\tSugaredParentEntityParameters,\n\tSugaredQualifiedEntityList,\n\tSugaredQualifiedFieldList,\n\tSugaredQualifiedSingleEntity,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n\tSugaredSetOnCreate,\n\tSugaredUnconstrainedQualifiedEntityList,\n\tSugaredUnconstrainedQualifiedSingleEntity,\n\tUnconstrainedQualifiedEntityList,\n\tUnconstrainedQualifiedSingleEntity,\n\tUniqueWhere,\n\tUnsugarableEntityListEventListeners,\n\tUnsugarableEntityListParameters,\n\tUnsugarableFieldEventListeners,\n\tUnsugarableHasManyRelation,\n\tUnsugarableHasOneRelation,\n\tUnsugarableSingleEntityEventListeners,\n} from '../treeParameters'\nimport { Parser } from './Parser'\nimport { GraphQlLiteral } from '@contember/client'\nimport { ParsedHasManyRelation, ParsedHasOneRelation } from './ParserResults'\n\nexport class QueryLanguage {\n\n\tprivate static preparePrimitiveEntryPoint<Entry extends Parser.EntryPoint>(entryPoint: Entry) {\n\t\treturn (input: string, environment: Environment): Parser.ParserResult[Entry] =>\n\t\t\tParser.parseQueryLanguageExpression(input, entryPoint, environment)\n\t}\n\n\tprivate static preparePrimitiveEntryPointWithFallback<Entry extends Parser.EntryPoint>(entryPoint: Entry) {\n\t\treturn (input: string | Parser.ParserResult[Entry], environment: Environment): Parser.ParserResult[Entry] => {\n\t\t\tif (typeof input === 'string') {\n\t\t\t\treturn Parser.parseQueryLanguageExpression(input, entryPoint, environment)\n\t\t\t}\n\t\t\treturn input\n\t\t}\n\t}\n\n\tprivate static parseUnconstrainedQualifiedEntityList = QueryLanguage.preparePrimitiveEntryPoint('unconstrainedQualifiedEntityList')\n\tprivate static parseUnconstrainedQualifiedSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('unconstrainedQualifiedEntityList')\n\tprivate static parseQualifiedEntityList = QueryLanguage.preparePrimitiveEntryPoint('qualifiedEntityList')\n\tprivate static parseQualifiedFieldList = QueryLanguage.preparePrimitiveEntryPoint('qualifiedFieldList')\n\tprivate static parseQualifiedSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('qualifiedSingleEntity')\n\tprivate static parseRelativeEntityList = QueryLanguage.preparePrimitiveEntryPoint('relativeEntityList')\n\tprivate static parseRelativeSingleEntity = QueryLanguage.preparePrimitiveEntryPoint('relativeSingleEntity')\n\tprivate static parseRelativeSingleField = QueryLanguage.preparePrimitiveEntryPoint('relativeSingleField')\n\n\tpublic static desugarUniqueWhere = QueryLanguage.preparePrimitiveEntryPointWithFallback('uniqueWhere')\n\tpublic static desugarFilter = QueryLanguage.preparePrimitiveEntryPointWithFallback('filter')\n\tpublic static desugarOrderBy = QueryLanguage.preparePrimitiveEntryPointWithFallback('orderBy')\n\tpublic static desugarTaggedMap = QueryLanguage.preparePrimitiveEntryPointWithFallback('taggedMap')\n\n\n\tprivate static desugarEntityListParameters(\n\t\tsugarablePart: SugarableEntityListParameters,\n\t\tunsugarablePart: UnsugarableEntityListParameters,\n\t\tenvironment: Environment,\n\t): EntityListParameters {\n\t\treturn {\n\t\t\tfilter: sugarablePart.filter ? this.desugarFilter(sugarablePart.filter, environment) : undefined,\n\t\t\tlimit: unsugarablePart.limit,\n\t\t\toffset: unsugarablePart.offset,\n\t\t\torderBy: unsugarablePart.orderBy ? this.desugarOrderBy(unsugarablePart.orderBy, environment) : undefined,\n\t\t\tinitialEntityCount: unsugarablePart.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t}\n\t}\n\n\tpublic static desugarSetOnCreate(setOnCreate: SugaredSetOnCreate, environment: Environment): UniqueWhere {\n\t\tif (Array.isArray(setOnCreate)) {\n\t\t\tconst whereList = setOnCreate.map(connection => this.desugarUniqueWhere(connection, environment))\n\t\t\treturn whereList.reduce(\n\t\t\t\t(accumulator, uniqueWhere) => TreeParameterMerger.mergeSetOnCreate(accumulator, uniqueWhere)!,\n\t\t\t)\n\t\t}\n\t\tif (typeof setOnCreate === 'string') {\n\t\t\treturn this.desugarUniqueWhere(setOnCreate, environment)\n\t\t}\n\t\treturn setOnCreate\n\t}\n\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F>): Set<F>\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F> | undefined): Set<F> | undefined\n\tpublic static desugarEventListener<F extends Function>(listener: F | Set<F> | undefined): Set<F> | undefined {\n\t\tif (typeof listener === 'function') {\n\t\t\treturn new Set([listener])\n\t\t}\n\t\treturn listener\n\t}\n\n\tprivate static desugarSingleEntityEventListeners(\n\t\tunsugarable: UnsugarableSingleEntityEventListeners,\n\t): EntityEventListenerStore | undefined {\n\t\tif (\n\t\t\tunsugarable.onBeforePersist === undefined &&\n\t\t\tunsugarable.onBeforeUpdate === undefined &&\n\t\t\tunsugarable.onInitialize === undefined &&\n\t\t\tunsugarable.onPersistError === undefined &&\n\t\t\tunsugarable.onPersistSuccess === undefined &&\n\t\t\tunsugarable.onUpdate === undefined\n\t\t) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst store: EntityEventListenerStore = new EventListenersStore()\n\n\t\tif (unsugarable.onConnectionUpdate) {\n\t\t\tfor (const fieldName in unsugarable.onConnectionUpdate) {\n\t\t\t\tconst listener = this.desugarEventListener(unsugarable.onConnectionUpdate[fieldName])\n\t\t\t\tstore.set({ type: 'connectionUpdate', key: fieldName }, listener)\n\t\t\t}\n\t\t}\n\n\t\tconst beforePersist = this.desugarEventListener(unsugarable.onBeforePersist)\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst initialize = this.desugarEventListener(unsugarable.onInitialize)\n\t\tconst persistError = this.desugarEventListener(unsugarable.onPersistError)\n\t\tconst persistSuccess = this.desugarEventListener(unsugarable.onPersistSuccess)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforePersist) {\n\t\t\tstore.set({ type: 'beforePersist' }, beforePersist)\n\t\t}\n\t\tif (beforeUpdate) {\n\t\t\tstore.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (initialize) {\n\t\t\tstore.set({ type: 'initialize' }, initialize)\n\t\t}\n\t\tif (persistError) {\n\t\t\tstore.set({ type: 'persistError' }, persistError)\n\t\t}\n\t\tif (persistSuccess) {\n\t\t\tstore.set({ type: 'persistSuccess' }, persistSuccess)\n\t\t}\n\t\tif (update) {\n\t\t\tstore.set({ type: 'update' }, update)\n\t\t}\n\n\t\treturn store\n\t}\n\n\tprivate static desugarEntityListEventListeners(unsugarable: UnsugarableEntityListEventListeners):\n\t\t| {\n\t\t\t\teventListeners: EntityListEventListenerStore | undefined\n\t\t\t\tchildEventListeners: EntityEventListenerStore | undefined\n\t\t }\n\t\t| undefined {\n\t\tif (\n\t\t\tunsugarable.onBeforePersist === undefined &&\n\t\t\tunsugarable.onBeforeUpdate === undefined &&\n\t\t\tunsugarable.onChildBeforeUpdate === undefined &&\n\t\t\tunsugarable.onChildInitialize === undefined &&\n\t\t\tunsugarable.onChildUpdate === undefined &&\n\t\t\tunsugarable.onInitialize === undefined &&\n\t\t\tunsugarable.onPersistError === undefined &&\n\t\t\tunsugarable.onPersistSuccess === undefined &&\n\t\t\tunsugarable.onUpdate === undefined\n\t\t) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst eventListeners: EntityListEventListenerStore = new EventListenersStore()\n\n\t\tconst beforePersist = this.desugarEventListener(unsugarable.onBeforePersist)\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst initialize = this.desugarEventListener(unsugarable.onInitialize)\n\t\tconst persistError = this.desugarEventListener(unsugarable.onPersistError)\n\t\tconst persistSuccess = this.desugarEventListener(unsugarable.onPersistSuccess)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforePersist) {\n\t\t\teventListeners.set({ type: 'beforePersist' }, beforePersist)\n\t\t}\n\t\tif (beforeUpdate) {\n\t\t\teventListeners.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (initialize) {\n\t\t\teventListeners.set({ type: 'initialize' }, initialize)\n\t\t}\n\t\tif (persistError) {\n\t\t\teventListeners.set({ type: 'persistError' }, persistError)\n\t\t}\n\t\tif (persistSuccess) {\n\t\t\teventListeners.set({ type: 'persistSuccess' }, persistSuccess)\n\t\t}\n\t\tif (update) {\n\t\t\teventListeners.set({ type: 'update' }, update)\n\t\t}\n\n\t\tconst childEventListeners: EntityEventListenerStore = new EventListenersStore()\n\n\t\tconst childBeforeUpdate = this.desugarEventListener(unsugarable.onChildBeforeUpdate)\n\t\tconst childInitialize = this.desugarEventListener(unsugarable.onChildInitialize)\n\t\tconst childUpdate = this.desugarEventListener(unsugarable.onChildUpdate)\n\n\t\tif (childBeforeUpdate) {\n\t\t\tchildEventListeners.set({ type: 'beforeUpdate' }, childBeforeUpdate)\n\t\t}\n\t\tif (childInitialize) {\n\t\t\tchildEventListeners.set({ type: 'initialize' }, childInitialize)\n\t\t}\n\t\tif (childUpdate) {\n\t\t\tchildEventListeners.set({ type: 'update' }, childUpdate)\n\t\t}\n\n\t\treturn {\n\t\t\teventListeners,\n\t\t\tchildEventListeners,\n\t\t}\n\t}\n\n\tprivate static desugarFieldEventListeners(\n\t\tunsugarable: UnsugarableFieldEventListeners,\n\t): FieldEventListenerStore | undefined {\n\t\tif (unsugarable.onBeforeUpdate === undefined && unsugarable.onUpdate === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst store: FieldEventListenerStore = new EventListenersStore()\n\n\t\tconst beforeUpdate = this.desugarEventListener(unsugarable.onBeforeUpdate)\n\t\tconst update = this.desugarEventListener(unsugarable.onUpdate)\n\n\t\tif (beforeUpdate) {\n\t\t\tstore.set({ type: 'beforeUpdate' }, beforeUpdate)\n\t\t}\n\t\tif (update) {\n\t\t\tstore.set({ type: 'update' }, update)\n\t\t}\n\n\t\treturn store\n\t}\n\n\tprivate static desugarSubTreeAlias(alias: Alias | Set<Alias> | undefined): Set<Alias> | undefined {\n\t\tif (alias === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\tif (alias instanceof Set) {\n\t\t\treturn alias\n\t\t}\n\t\treturn new Set<Alias>().add(alias)\n\t}\n\n\tprivate static desugarHasOneRelation(\n\t\tsugarable: SugarableHasOneRelation,\n\t\tunsugarable: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation {\n\t\treturn {\n\t\t\tfield: sugarable.field,\n\t\t\tfilter: sugarable.filter ? this.desugarFilter(sugarable.filter, environment) : undefined,\n\t\t\texpectedMutation: unsugarable.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\treducedBy: sugarable.reducedBy ? this.desugarUniqueWhere(sugarable.reducedBy, environment) : undefined,\n\t\t\tsetOnCreate: unsugarable.setOnCreate ? this.desugarSetOnCreate(unsugarable.setOnCreate, environment) : undefined,\n\t\t\tisNonbearing: unsugarable.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarable.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(unsugarable),\n\t\t}\n\t}\n\n\tprivate static augmentDesugaredHasOneRelationPath(\n\t\tpath: ParsedHasOneRelation[],\n\t\tunsugarable: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation[] {\n\t\treturn path.map((desugaredHasOneRelation, i) =>\n\t\t\t// Unsugarable applies to the last\n\t\t\tthis.desugarHasOneRelation(desugaredHasOneRelation, i === path.length - 1 ? unsugarable : {}, environment),\n\t\t)\n\t}\n\n\tprivate static augmentDesugaredHasManyRelation(\n\t\trelation: ParsedHasManyRelation,\n\t\tunsugarable: UnsugarableHasManyRelation,\n\t\tenvironment: Environment,\n\t): HasManyRelation {\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarable)\n\t\treturn {\n\t\t\tfield: relation.field,\n\t\t\tfilter: relation.filter,\n\t\t\texpectedMutation: unsugarable.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\tisNonbearing: unsugarable.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarable.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tinitialEntityCount: unsugarable.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t\tsetOnCreate: unsugarable.setOnCreate ? this.desugarSetOnCreate(unsugarable.setOnCreate, environment) : undefined,\n\t\t\torderBy: unsugarable.orderBy ? this.desugarOrderBy(unsugarable.orderBy, environment) : undefined,\n\t\t\toffset: unsugarable.offset,\n\t\t\tlimit: unsugarable.limit,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tprivate static desugarHasOneRelationPath(\n\t\tinput: SugarableHasOneRelation[] | SugarableHasOneRelation | undefined,\n\t\tlastRelation: UnsugarableHasOneRelation,\n\t\tenvironment: Environment,\n\t): HasOneRelation[] {\n\t\tif (input === undefined) {\n\t\t\tinput = []\n\t\t} else if (!Array.isArray(input)) {\n\t\t\tinput = [input]\n\t\t}\n\n\t\tconst relationPath: HasOneRelation[] = []\n\n\t\tconst cappedLength = input.length - 1\n\t\tlet i = 0\n\t\tfor (; i < cappedLength; i++) {\n\t\t\t// Deliberately leaving out the last element\n\t\t\tconst pathNode = input[i]\n\n\t\t\trelationPath.push(this.desugarHasOneRelation(pathNode, {}, environment))\n\t\t}\n\t\tif (i in input) {\n\t\t\trelationPath.push(this.desugarHasOneRelation(input[i], lastRelation, environment))\n\t\t}\n\n\t\treturn relationPath\n\t}\n\n\tprivate static desugarHasManyRelation(\n\t\tsugarablePart: SugarableHasManyRelation,\n\t\tunsugarablePart: UnsugarableHasManyRelation,\n\t\tenvironment: Environment,\n\t): HasManyRelation {\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarablePart)\n\t\treturn {\n\t\t\t...this.desugarEntityListParameters(sugarablePart, unsugarablePart, environment),\n\t\t\texpectedMutation: unsugarablePart.expectedMutation ?? RelationDefaults.expectedMutation,\n\t\t\tsetOnCreate: unsugarablePart.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarablePart.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\tfield: sugarablePart.field,\n\t\t\tisNonbearing: unsugarablePart.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarablePart.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tpublic static desugarUnconstrainedQualifiedEntityList(\n\t\t{ entities, ...unsugarableEntityList }: SugaredUnconstrainedQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): UnconstrainedQualifiedEntityList {\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet entityName: EntityName\n\n\t\tif (typeof entities === 'string') {\n\t\t\tconst parsed = this.parseUnconstrainedQualifiedEntityList(entities, environment)\n\t\t\tentityName = parsed.entityName\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entities.entityName\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(entities.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarableEntityList)\n\n\t\treturn {\n\t\t\tisCreating: true,\n\t\t\tisNonbearing: unsugarableEntityList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableEntityList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableEntityList.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableEntityList.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableEntityList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t\tinitialEntityCount: unsugarableEntityList.initialEntityCount ?? EntityListPreferencesDefaults.initialEntityCount,\n\t\t\talias: this.desugarSubTreeAlias(unsugarableEntityList.alias),\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarUnconstrainedQualifiedSingleEntity(\n\t\t{ entity, ...unsugarableSingleEntity }: SugaredUnconstrainedQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t): UnconstrainedQualifiedSingleEntity {\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet entityName: EntityName\n\n\t\tif (typeof entity === 'string') {\n\t\t\tconst parsed = this.parseUnconstrainedQualifiedSingleEntity(entity, environment)\n\t\t\tentityName = parsed.entityName\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entity.entityName\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(\n\t\t\t\tentity.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\treturn {\n\t\t\tisCreating: true,\n\t\t\tisNonbearing: unsugarableSingleEntity.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableSingleEntity.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableSingleEntity.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableSingleEntity.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableSingleEntity.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(unsugarableSingleEntity),\n\t\t\talias: this.desugarSubTreeAlias(unsugarableSingleEntity.alias),\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedEntityList(\n\t\t{ entities, ...unsugarableEntityList }: SugaredQualifiedEntityList,\n\t\tenvironment: Environment,\n\t): QualifiedEntityList {\n\t\tlet entityName: EntityName\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tlet filter: SugaredFilter | undefined\n\n\t\tif (typeof entities === 'string') {\n\t\t\tconst parsed = this.parseQualifiedEntityList(entities, environment)\n\n\t\t\tentityName = parsed.entityName\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entities.entityName\n\t\t\tfilter = entities.filter\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(entities.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\tconst eventListeners = this.desugarEntityListEventListeners(unsugarableEntityList)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t\t...this.desugarEntityListParameters(\n\t\t\t\t{\n\t\t\t\t\tfilter,\n\t\t\t\t},\n\t\t\t\tunsugarableEntityList,\n\t\t\t\tenvironment,\n\t\t\t),\n\t\t\talias: this.desugarSubTreeAlias(unsugarableEntityList.alias),\n\t\t\tisCreating: false,\n\t\t\tisNonbearing: unsugarableEntityList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableEntityList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tsetOnCreate: unsugarableEntityList.setOnCreate\n\t\t\t\t? this.desugarSetOnCreate(unsugarableEntityList.setOnCreate, environment)\n\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableEntityList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\tchildEventListeners: eventListeners?.childEventListeners,\n\t\t\teventListeners: eventListeners?.eventListeners,\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedFieldList(\n\t\t{ fields, ...unsugarableFieldList }: SugaredQualifiedFieldList,\n\t\tenvironment: Environment,\n\t): QualifiedFieldList {\n\t\tlet field: FieldName\n\t\tlet entityName: EntityName\n\t\tlet filter: SugaredFilter | undefined\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tif (typeof fields === 'string') {\n\t\t\tconst parsed = this.parseQualifiedFieldList(fields, environment)\n\n\t\t\tfield = parsed.field\n\t\t\tentityName = parsed.entityName\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tfield = fields.field\n\t\t\tentityName = fields.entityName\n\t\t\tfilter = fields.filter\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(fields.hasOneRelationPath, emptyObject, environment)\n\t\t}\n\n\t\treturn {\n\t\t\tfield,\n\t\t\tentityName,\n\t\t\thasOneRelationPath,\n\t\t\talias: this.desugarSubTreeAlias(unsugarableFieldList.alias),\n\t\t\tisNonbearing: unsugarableFieldList.isNonbearing ?? EntityCreationParametersDefaults.isNonbearing,\n\t\t\t// forceCreation: unsugarableFieldList.forceCreation ?? EntityCreationParametersDefaults.forceCreation,\n\t\t\tdefaultValue:\n\t\t\t\tunsugarableFieldList.defaultValue !== undefined\n\t\t\t\t\t? VariableInputTransformer.transformValue(unsugarableFieldList.defaultValue, environment)\n\t\t\t\t\t: undefined,\n\t\t\texpectedMutation: unsugarableFieldList.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation,\n\t\t\teventListeners: this.desugarFieldEventListeners(unsugarableFieldList),\n\t\t\t...this.desugarEntityListParameters({ filter }, unsugarableFieldList, environment),\n\t\t}\n\t}\n\n\tpublic static desugarQualifiedSingleEntity(\n\t\t{ entity, ...unsugarableSingleEntity }: SugaredQualifiedSingleEntity,\n\t\tenvironment: Environment,\n\t\toptions: { missingSetOnCreate?: 'fill' | 'fillAndWarn' } = {},\n\t): QualifiedSingleEntity {\n\t\tlet entityName: EntityName\n\t\tlet where: UniqueWhere\n\t\tlet filter: Filter | undefined\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\n\t\tif (typeof entity === 'string') {\n\t\t\tconst parsed = this.parseQualifiedSingleEntity(entity, environment)\n\n\t\t\tentityName = parsed.entityName\n\t\t\twhere = parsed.where\n\t\t\tfilter = parsed.filter\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\tentityName = entity.entityName\n\t\t\twhere = this.desugarUniqueWhere(entity.where, environment)\n\t\t\tfilter = entity.filter ? this.desugarFilter(entity.filter, environment) : undefined\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(\n\t\t\t\tentity.hasOneRelationPath,\n\t\t\t\tunsugarableSingleEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\t// const forceCreation: boolean =\n\t\t// \tunsugarableSingleEntity.forceCreation !== undefined\n\t\t// \t\t? unsugarableSingleEntity.forceCreation !== undefined\n\t\t// \t\t: EntityCreationParametersDefaults.forceCreation\n\t\tlet setOnCreate: UniqueWhere | undefined =\n\t\t\tunsugarableSingleEntity.setOnCreate !== undefined\n\t\t\t\t? this.desugarSetOnCreate(unsugarableSingleEntity.setOnCreate, environment)\n\t\t\t\t: undefined\n\n\t\t// todo: remove deprecated code\n\t\tif (!setOnCreate && options.missingSetOnCreate) {\n\t\t\tconst whereValues = Object.values(where)\n\t\t\tif (whereValues.length === 1 && whereValues[0] instanceof GraphQlLiteral) {\n\t\t\t\tsetOnCreate = where\n\t\t\t\tif (import.meta.env.DEV && options.missingSetOnCreate === 'fillAndWarn') {\n\t\t\t\t\tconsole.warn('Automatic creation of singleton entities in EditPage is deprecated. Please use setOnCreate prop.')\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst isNonbearing: boolean =\n\t\t\tunsugarableSingleEntity.isNonbearing !== undefined\n\t\t\t\t? unsugarableSingleEntity.isNonbearing\n\t\t\t\t: EntityCreationParametersDefaults.isNonbearing\n\t\tconst eventListeners = this.desugarSingleEntityEventListeners(unsugarableSingleEntity)\n\t\tconst expectedMutation =\n\t\t\tunsugarableSingleEntity.expectedMutation ?? QualifiedEntityParametersDefaults.expectedMutation\n\t\tconst alias = this.desugarSubTreeAlias(unsugarableSingleEntity.alias)\n\n\t\treturn {\n\t\t\talias,\n\t\t\tentityName,\n\t\t\tisCreating: false,\n\t\t\twhere,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t\t// forceCreation,\n\t\t\tsetOnCreate,\n\t\t\tisNonbearing,\n\t\t\teventListeners,\n\t\t\texpectedMutation,\n\t\t}\n\t}\n\n\tpublic static desugarParentEntityParameters(\n\t\tparentEntity: SugaredParentEntityParameters,\n\t\tenvironment: Environment,\n\t): ParentEntityParameters {\n\t\treturn {\n\t\t\teventListeners: this.desugarSingleEntityEventListeners(parentEntity),\n\t\t}\n\t}\n\n\tpublic static desugarRelativeSingleEntity(\n\t\tsugaredRelativeSingleEntity: string | SugaredRelativeSingleEntity,\n\t\tenvironment: Environment,\n\t): RelativeSingleEntity {\n\t\tif (typeof sugaredRelativeSingleEntity === 'string') {\n\t\t\treturn this.desugarRelativeSingleEntity({ field: sugaredRelativeSingleEntity }, environment)\n\t\t}\n\n\t\tconst { field, ...unsugarableEntity } = sugaredRelativeSingleEntity\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeSingleEntity(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\tunsugarableEntity,\n\t\t\t\tenvironment,\n\t\t\t)\n\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field, unsugarableEntity, environment)\n\t\t}\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n\n\tpublic static desugarRelativeSingleField(\n\t\tsugaredRelativeSingleField: string | SugaredRelativeSingleField,\n\t\tenvironment: Environment,\n\t): RelativeSingleField {\n\t\tif (typeof sugaredRelativeSingleField === 'string') {\n\t\t\treturn this.desugarRelativeSingleField({ field: sugaredRelativeSingleField }, environment)\n\t\t}\n\n\t\tconst { field, ...unsugarableField } = sugaredRelativeSingleField\n\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet fieldName: FieldName\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeSingleField(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(parsed.hasOneRelationPath, {}, environment)\n\t\t\tfieldName = parsed.field\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field.hasOneRelationPath, {}, environment)\n\t\t\tfieldName = field.field\n\t\t}\n\n\t\treturn {\n\t\t\teventListeners: this.desugarFieldEventListeners(unsugarableField),\n\t\t\thasOneRelationPath,\n\t\t\tfield: fieldName,\n\t\t\tisNonbearing: unsugarableField.isNonbearing ?? LeafFieldDefaults.isNonbearing,\n\t\t\tdefaultValue:\n\t\t\t\tunsugarableField.defaultValue !== undefined\n\t\t\t\t\t? VariableInputTransformer.transformValue(unsugarableField.defaultValue, environment)\n\t\t\t\t\t: undefined,\n\t\t}\n\t}\n\n\tpublic static desugarRelativeEntityList(\n\t\tsugaredRelativeEntityList: string | SugaredRelativeEntityList,\n\t\tenvironment: Environment,\n\t): RelativeEntityList {\n\t\tif (typeof sugaredRelativeEntityList === 'string') {\n\t\t\treturn this.desugarRelativeEntityList(\n\t\t\t\t{\n\t\t\t\t\tfield: sugaredRelativeEntityList,\n\t\t\t\t},\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t}\n\n\t\tconst { field, ...unsugarableEntityList } = sugaredRelativeEntityList\n\t\tlet hasOneRelationPath: HasOneRelation[]\n\t\tlet hasManyRelation: HasManyRelation\n\t\tif (typeof field === 'string') {\n\t\t\tconst parsed = this.parseRelativeEntityList(field, environment)\n\t\t\thasOneRelationPath = this.augmentDesugaredHasOneRelationPath(\n\t\t\t\tparsed.hasOneRelationPath,\n\t\t\t\temptyObject,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t\thasManyRelation = this.augmentDesugaredHasManyRelation(\n\t\t\t\tparsed.hasManyRelation,\n\t\t\t\tunsugarableEntityList,\n\t\t\t\tenvironment,\n\t\t\t)\n\t\t} else {\n\t\t\thasOneRelationPath = this.desugarHasOneRelationPath(field.hasOneRelationPath || [], emptyObject, environment)\n\t\t\thasManyRelation = this.desugarHasManyRelation(field.hasManyRelation, unsugarableEntityList, environment)\n\t\t}\n\n\t\treturn {\n\t\t\thasManyRelation,\n\t\t\thasOneRelationPath,\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;oBAuD2B;AAAA,SAEX,2BAA4D,YAAmB;AAC7F,WAAO,CAAC,OAAe,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mCACzB,OAAO,oBACP,aACA;AAED,wBAAkB,KAAK,gCACtB,OAAO,iBACP,uBACA;AAAA,WAEK;AACN,2BAAqB,KAAK,0BAA0B,MAAM,sBAAsB,IAAI,aAAa;AACjG,wBAAkB,KAAK,uBAAuB,MAAM,iBAAiB,uBAAuB;AAAA;AAG7F,WAAO;AAAA,MACN;AAAA,MACA;AAAA;AAAA;AAAA;;;;"}
@@ -32,6 +32,10 @@ const tokens = {
32
32
  name: "Comma",
33
33
  pattern: /,/
34
34
  }),
35
+ Colon: createToken({
36
+ name: "Colon",
37
+ pattern: /:/
38
+ }),
35
39
  NumberLiteral: createToken({
36
40
  name: "NumberLiteral",
37
41
  pattern: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/
@@ -118,6 +122,7 @@ const tokenList = [
118
122
  tokens.DollarSign,
119
123
  tokens.Dot,
120
124
  tokens.Comma,
125
+ tokens.Colon,
121
126
  tokens.StringLiteral,
122
127
  tokens.NumberLiteral,
123
128
  tokens.LeftParenthesis,
@@ -1 +1 @@
1
- {"version":3,"file":"tokenList.js","sources":["../../../src/queryLanguage/tokenList.ts"],"sourcesContent":["import { createToken, Lexer } from 'chevrotain'\n\nexport namespace TokenRegExps {\n\texport const entityIdentifier = /[A-Z_]\\w*/\n\texport const identifier = /[a-zA-Z_]\\w*/\n}\n\nconst identifier = createToken({\n\tname: 'Identifier',\n\tpattern: TokenRegExps.identifier,\n})\n\nexport const tokens = {\n\tWhiteSpace: createToken({\n\t\tname: 'WhiteSpace',\n\t\tpattern: /\\s+/,\n\t\tgroup: Lexer.SKIPPED,\n\t}),\n\n\tEntityIdentifier: createToken({\n\t\tname: 'EntityIdentifier',\n\t\tpattern: TokenRegExps.entityIdentifier,\n\t}),\n\n\tIdentifier: identifier,\n\n\tDollarSign: createToken({\n\t\tname: 'DollarSign',\n\t\tpattern: /\\$/,\n\t}),\n\n\tDot: createToken({\n\t\tname: 'Dot',\n\t\tpattern: /\\./,\n\t}),\n\n\tComma: createToken({\n\t\tname: 'Comma',\n\t\tpattern: /,/,\n\t}),\n\n\tNumberLiteral: createToken({\n\t\tname: 'NumberLiteral',\n\t\tpattern: /-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?/,\n\t}),\n\n\tStringLiteral: createToken({\n\t\tname: 'StringLiteral',\n\t\tpattern: /'(:?[^\\\\']|\\\\(:?[bfnrtv'\\\\/]|u[0-9a-fA-F]{4}))*'/,\n\t}),\n\n\tLeftParenthesis: createToken({\n\t\tname: 'LeftParenthesis',\n\t\tpattern: /\\(/,\n\t}),\n\n\tRightParenthesis: createToken({\n\t\tname: 'RightParenthesis',\n\t\tpattern: /\\)/,\n\t}),\n\n\tLeftBracket: createToken({\n\t\tname: 'LeftBracket',\n\t\tpattern: /\\[/,\n\t}),\n\n\tRightBracket: createToken({\n\t\tname: 'RightBracket',\n\t\tpattern: /]/,\n\t}),\n\n\tNotEquals: createToken({\n\t\tname: 'NotEquals',\n\t\tpattern: /!=/,\n\t}),\n\n\tTrue: createToken({\n\t\tname: 'True',\n\t\tpattern: /true/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tFalse: createToken({\n\t\tname: 'False',\n\t\tpattern: /false/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tNull: createToken({\n\t\tname: 'Null',\n\t\tpattern: /null/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tEquals: createToken({\n\t\tname: 'Equals',\n\t\tpattern: /=/,\n\t}),\n\n\tNot: createToken({\n\t\tname: 'Not',\n\t\tpattern: /!/,\n\t}),\n\n\tAnd: createToken({\n\t\tname: 'And',\n\t\tpattern: /&&/,\n\t}),\n\n\tOr: createToken({\n\t\tname: 'Or',\n\t\tpattern: /\\|\\|/,\n\t}),\n\n\tLowerEqual: createToken({\n\t\tname: 'LowerEqual',\n\t\tpattern: /<=/,\n\t}),\n\n\tGreaterEqual: createToken({\n\t\tname: 'GreaterEqual',\n\t\tpattern: />=/,\n\t}),\n\n\tLowerThan: createToken({\n\t\tname: 'LowerThan',\n\t\tpattern: /</,\n\t}),\n\n\tGreaterThan: createToken({\n\t\tname: 'GreaterThan',\n\t\tpattern: />/,\n\t}),\n}\n\nconst tokenList = [\n\ttokens.WhiteSpace,\n\ttokens.True,\n\ttokens.False,\n\ttokens.Null,\n\ttokens.EntityIdentifier,\n\ttokens.Identifier,\n\ttokens.DollarSign,\n\ttokens.Dot,\n\ttokens.Comma,\n\ttokens.StringLiteral,\n\ttokens.NumberLiteral,\n\ttokens.LeftParenthesis,\n\ttokens.RightParenthesis,\n\ttokens.LeftBracket,\n\ttokens.RightBracket,\n\ttokens.NotEquals,\n\ttokens.Equals,\n\ttokens.Not,\n\ttokens.GreaterEqual,\n\ttokens.GreaterThan,\n\ttokens.LowerEqual,\n\ttokens.LowerThan,\n\ttokens.And,\n\ttokens.Or,\n]\n\nexport { tokenList }\n"],"names":[],"mappings":";;IAEiB;AAAV,UAAU,eAAV;AACC,EAAM,iCAAmB;AACzB,EAAM,2BAAa;AAAA,GAFV;AAKjB,MAAM,aAAa,YAAY;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS,aAAa;AAAA;MAGV,SAAS;AAAA,EACrB,YAAY,YAAY;AAAA,IACvB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO,MAAM;AAAA;AAAA,EAGd,kBAAkB,YAAY;AAAA,IAC7B,MAAM;AAAA,IACN,SAAS,aAAa;AAAA;AAAA,EAGvB,YAAY;AAAA,EAEZ,YAAY,YAAY;AAAA,IACvB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,KAAK,YAAY;AAAA,IAChB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,OAAO,YAAY;AAAA,IAClB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,eAAe,YAAY;AAAA,IAC1B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,eAAe,YAAY;AAAA,IAC1B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,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A,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA;;;;"}
1
+ {"version":3,"file":"tokenList.js","sources":["../../../src/queryLanguage/tokenList.ts"],"sourcesContent":["import { createToken, Lexer } from 'chevrotain'\n\nexport namespace TokenRegExps {\n\texport const entityIdentifier = /[A-Z_]\\w*/\n\texport const identifier = /[a-zA-Z_]\\w*/\n}\n\nconst identifier = createToken({\n\tname: 'Identifier',\n\tpattern: TokenRegExps.identifier,\n})\n\nexport const tokens = {\n\tWhiteSpace: createToken({\n\t\tname: 'WhiteSpace',\n\t\tpattern: /\\s+/,\n\t\tgroup: Lexer.SKIPPED,\n\t}),\n\n\tEntityIdentifier: createToken({\n\t\tname: 'EntityIdentifier',\n\t\tpattern: TokenRegExps.entityIdentifier,\n\t}),\n\n\tIdentifier: identifier,\n\n\tDollarSign: createToken({\n\t\tname: 'DollarSign',\n\t\tpattern: /\\$/,\n\t}),\n\n\tDot: createToken({\n\t\tname: 'Dot',\n\t\tpattern: /\\./,\n\t}),\n\n\tComma: createToken({\n\t\tname: 'Comma',\n\t\tpattern: /,/,\n\t}),\n\n\tColon: createToken({\n\t\tname: 'Colon',\n\t\tpattern: /:/,\n\t}),\n\n\tNumberLiteral: createToken({\n\t\tname: 'NumberLiteral',\n\t\tpattern: /-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?/,\n\t}),\n\n\tStringLiteral: createToken({\n\t\tname: 'StringLiteral',\n\t\tpattern: /'(:?[^\\\\']|\\\\(:?[bfnrtv'\\\\/]|u[0-9a-fA-F]{4}))*'/,\n\t}),\n\n\tLeftParenthesis: createToken({\n\t\tname: 'LeftParenthesis',\n\t\tpattern: /\\(/,\n\t}),\n\n\tRightParenthesis: createToken({\n\t\tname: 'RightParenthesis',\n\t\tpattern: /\\)/,\n\t}),\n\n\tLeftBracket: createToken({\n\t\tname: 'LeftBracket',\n\t\tpattern: /\\[/,\n\t}),\n\n\tRightBracket: createToken({\n\t\tname: 'RightBracket',\n\t\tpattern: /]/,\n\t}),\n\n\tNotEquals: createToken({\n\t\tname: 'NotEquals',\n\t\tpattern: /!=/,\n\t}),\n\n\tTrue: createToken({\n\t\tname: 'True',\n\t\tpattern: /true/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tFalse: createToken({\n\t\tname: 'False',\n\t\tpattern: /false/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tNull: createToken({\n\t\tname: 'Null',\n\t\tpattern: /null/,\n\t\tlonger_alt: identifier,\n\t}),\n\n\tEquals: createToken({\n\t\tname: 'Equals',\n\t\tpattern: /=/,\n\t}),\n\n\tNot: createToken({\n\t\tname: 'Not',\n\t\tpattern: /!/,\n\t}),\n\n\tAnd: createToken({\n\t\tname: 'And',\n\t\tpattern: /&&/,\n\t}),\n\n\tOr: createToken({\n\t\tname: 'Or',\n\t\tpattern: /\\|\\|/,\n\t}),\n\n\tLowerEqual: createToken({\n\t\tname: 'LowerEqual',\n\t\tpattern: /<=/,\n\t}),\n\n\tGreaterEqual: createToken({\n\t\tname: 'GreaterEqual',\n\t\tpattern: />=/,\n\t}),\n\n\tLowerThan: createToken({\n\t\tname: 'LowerThan',\n\t\tpattern: /</,\n\t}),\n\n\tGreaterThan: createToken({\n\t\tname: 'GreaterThan',\n\t\tpattern: />/,\n\t}),\n}\n\nconst tokenList = [\n\ttokens.WhiteSpace,\n\ttokens.True,\n\ttokens.False,\n\ttokens.Null,\n\ttokens.EntityIdentifier,\n\ttokens.Identifier,\n\ttokens.DollarSign,\n\ttokens.Dot,\n\ttokens.Comma,\n\ttokens.Colon,\n\ttokens.StringLiteral,\n\ttokens.NumberLiteral,\n\ttokens.LeftParenthesis,\n\ttokens.RightParenthesis,\n\ttokens.LeftBracket,\n\ttokens.RightBracket,\n\ttokens.NotEquals,\n\ttokens.Equals,\n\ttokens.Not,\n\ttokens.GreaterEqual,\n\ttokens.GreaterThan,\n\ttokens.LowerEqual,\n\ttokens.LowerThan,\n\ttokens.And,\n\ttokens.Or,\n]\n\nexport { tokenList }\n"],"names":[],"mappings":";;IAEiB;AAAV,UAAU,eAAV;AACC,EAAM,iCAAmB;AACzB,EAAM,2BAAa;AAAA,GAFV;AAKjB,MAAM,aAAa,YAAY;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS,aAAa;AAAA;MAGV,SAAS;AAAA,EACrB,YAAY,YAAY;AAAA,IACvB,MAAM;AAAA,IACN,SAAS;AAAA,IACT,OAAO,MAAM;AAAA;AAAA,EAGd,kBAAkB,YAAY;AAAA,IAC7B,MAAM;AAAA,IACN,SAAS,aAAa;AAAA;AAAA,EAGvB,YAAY;AAAA,EAEZ,YAAY,YAAY;AAAA,IACvB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,KAAK,YAAY;AAAA,IAChB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,OAAO,YAAY;AAAA,IAClB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,OAAO,YAAY;AAAA,IAClB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,eAAe,YAAY;AAAA,IAC1B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,eAAe,YAAY;AAAA,IAC1B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,iBAAiB,YAAY;AAAA,IAC5B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,kBAAkB,YAAY;AAAA,IAC7B,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,aAAa,YAAY;AAAA,IACxB,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,EAGV,cAAc,YA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AAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA;;;;"}
@@ -0,0 +1,7 @@
1
+ import { useContext } from "react";
2
+ import { EntityKeyContext } from "./EntityKeyContext.js";
3
+ const useHasEntity = () => {
4
+ return useContext(EntityKeyContext) !== void 0;
5
+ };
6
+ export { useHasEntity };
7
+ //# sourceMappingURL=useHasEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasEntity.js","sources":["../../../src/accessorPropagation/useHasEntity.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { EntityKeyContext } from './EntityKeyContext'\n\nexport const useHasEntity = (): boolean => {\n\treturn useContext(EntityKeyContext) !== undefined\n}\n"],"names":[],"mappings":";;MAGa,eAAe,MAAe;SACnC,WAAW,sBAAsB;AAAA;;"}
@@ -76,10 +76,10 @@ class EntityListAccessor {
76
76
  this.operations.connectEntity(this.stateKey, entityToConnect);
77
77
  }
78
78
  createNewEntity(initialize) {
79
- this.operations.createNewEntity(this.stateKey, initialize);
79
+ return this.operations.createNewEntity(this.stateKey, initialize);
80
80
  }
81
- disconnectEntity(childEntity) {
82
- this.operations.disconnectEntity(this.stateKey, childEntity);
81
+ disconnectEntity(childEntity, options = {}) {
82
+ this.operations.disconnectEntity(this.stateKey, childEntity, options);
83
83
  }
84
84
  getChildEntityById(id) {
85
85
  return this.operations.getChildEntityById(this.stateKey, id);
@@ -1 +1 @@
1
- {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport type { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\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\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<string> {\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') {\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.SugaredValidationError): () => void {\n\t\treturn this.operations.addError(this.stateKey, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":"AAYA,yBAA8C;AAAA,EACtC,YACW,UACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;;;;;;;;;;GAOM,OAAyC;eACrC,YAAY,MAAM;YACtB,SAAS;AAAA;AAAA;AAAA,GAIT,MAAkC;WAClC,KAAK,UAAU;AAAA;AAAA,MAOZ,uBAAoC;WACvC,IAAI,IAAI,KAAK;AAAA;AAAA,IAGZ,OAAO,YAA8C;eAClD,EAAE,iBAAiB,KAAK,UAAU,UAAU;YAChD;AAAA;AAAA;AAAA,EAID,YAAY,IAAuB;WAClC,KAAK,UAAU,IAAI;AAAA;AAAA,EAGpB,UAAmB;WAClB,KAAK,WAAW;AAAA;AAAA,MAGb,SAAiB;WACpB,KAAK,UAAU;AAAA;AAAA,EAGhB,kBAAkB,eAAmD;QACvE,OAAO,kBAAkB,UAAU;aAC/B,KAAK,qBAAqB,IAAI;AAAA;UAEhC,aAAa,cAAc;QAC7B,eAAe,QAAW;aACtB;AAAA;WAED,KAAK,qBAAqB,IAAI;AAAA;AAAA,EAG/B,YAAkB;SACnB,aAAa,iBAAe;YAC1B,OAAO;iBACF,UAAU,MAAM;eACnB;AAAA;AAAA;AAAA;AAAA,EAKH,gBAAsB;SACvB,aAAa,iBAAe;YAC1B,OAAO;iBACF,UAAU,MAAM;aACrB,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKlB,SAAS,OAAyD;WACjE,KAAK,WAAW,SAAS,KAAK,UAAU;AAAA;AAAA,EAGzC,iBACN,OACA,UACC;WACM,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO;AAAA;AAAA,EAGxD,sBACN,OACA,OACA,UACC;WACM,KAAK,WAAW,sBAAsB,KAAK,UAAU,OAAO;AAAA;AAAA,EAG7D,aAAa,gBAA8D;SAC5E,WAAW,aAAa,KAAK,UAAU;AAAA;AAAA,EAGtC,cAAc,iBAAuC;SACtD,WAAW,cAAc,KAAK,UAAU;AAAA;AAAA,EAGvC,gBAAgB,YAAuD;SACxE,WAAW,gBAAgB,KAAK,UAAU;AAAA;AAAA,EAEzC,iBAAiB,aAAmC;SACrD,WAAW,iBAAiB,KAAK,UAAU;AAAA;AAAA,EAE1C,mBAAmB,IAA8B;WAChD,KAAK,WAAW,mBAAmB,KAAK,UAAU;AAAA;AAAA;;"}
1
+ {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport type { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\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\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<string> {\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') {\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.SugaredValidationError): () => void {\n\t\treturn this.operations.addError(this.stateKey, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":"AA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gBAAgB,KAAK,UAAU;AAAA;AAAA,EAEhD,iBAAiB,aAA6B,UAAmC,IAAU;SAC5F,WAAW,iBAAiB,KAAK,UAAU,aAAa;AAAA;AAAA,EAEvD,mBAAmB,IAA8B;WAChD,KAAK,WAAW,mBAAmB,KAAK,UAAU;AAAA;AAAA;;"}
@@ -120,7 +120,7 @@ const _DataBinding = class {
120
120
  const aliases = Object.keys(mutationData);
121
121
  const allSubMutationsOk = aliases.every((item) => mutationData[item].ok);
122
122
  if (allSubMutationsOk) {
123
- const persistedEntityIds = aliases.map((alias) => mutationData[alias].node.id);
123
+ const persistedEntityIds = aliases.map((alias) => mutationData[alias].node?.id).filter((id) => id !== void 0);
124
124
  const result = {
125
125
  type: "justSuccess",
126
126
  persistedEntityIds
@@ -1 +1 @@
1
- {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader, SchemaValidator } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\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 treeStore: TreeStore\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 environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\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)\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.config,\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)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tconst allSubMutationsOk = aliases.every(item => mutationData[item].ok)\n\n\t\t\t\t\t\tif (allSubMutationsOk) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node.id)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\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: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject()\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\tconst schema = await this.getOrLoadSchema()\n\t\t\tthis.treeStore.setSchema(schema)\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t// For most trees, checking this against the schema should be unnecessary since if we already effectively\n\t\t\t\t// have this tree root, then assuming everything we already have is valid, this should match the schema as well.\n\t\t\t\t// However, we might be dealing with an isCreating tree root which is completely new. Also, we can just lean\n\t\t\t\t// towards the safe side since developer machines can generally handle the potentially unnecessary check anyway.\n\t\t\t\tSchemaValidator.assertTreeValid(schema, markerTreeRoot)\n\t\t\t}\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject,\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\t// Even if we don't have a schema yet, we'll still optimistically fire the request so as to prevent a waterfall\n\t\t// in the most likely case that things will go fine and the query does match the schema. If it doesn't, then we\n\t\t// just get a \"400 Bad Request\" but that's not enough to make us delay the happy path.\n\t\tconst [aggregatePersistedData, schema] = await Promise.all([\n\t\t\tthis.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),\n\t\t\tthis.getOrLoadSchema(),\n\t\t])\n\t\tthis.treeStore.setSchema(schema)\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tSchemaValidator.assertTreeValid(schema, extension.markerTreeRoot)\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\t\treturn queryResponse\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 getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;2BAwCyB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwLT,4CAAmB,CAAC,EAAE,iBAAiC;WACzD,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,cAAc,YAAY,KAAK;AAAA;AAQjF,6CAOH,IAAI;;;;;;;;SAvLH,SAAS,IAAI;SACb,YAAY,IAAI;SAChB,sBAAsB,0BAA0B,aAAa,KAAK;SAClE,2BAA2B;AAAA,SAC5B,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA;SAEV,mBAAmB,IAAI;SACvB,eAAe,IAAI,aACvB,KAAK,0BACL,KAAK,qBACL,KAAK,QACL,KAAK,kBACL,KAAK,kBACL,KAAK;SAED,uBAAuB,IAAI,qBAAqB,KAAK,cAAc,KAAK;SACxE,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,QACL,KAAK,cACL,KAAK;SAED,gBAAgB,IAAI,cAAc,KAAK,cAAc,KAAK,kBAAkB,KAAK;SAGjF,oBAAoB,OAAO,OAA0B;AAAA,SACtD,KAAK;AAAA,MACR,gBAAgB,MAAoB;cAC7B,YAAY,IAAI,oBAAoB,KAAK;eACxC,UAAU;AAAA;AAAA,MAElB,sBAAsB,oBAAkB;aAClC,aAAa,gBAA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AM,UAAU,MAAM;sBAClD,UAAU;sBACV,wBAAwB;qBACzB,aAAa,oBAAoB,OAAO,aAAa;AAAA;;;iBAIvD;kBACA,MAAM,0BAA0B,KAAK,MAAM,iBAAiB,MAAM;sBAC/D,0BAA0B;sBAC1B,iBAAiB;qBAClB,aAAa,oBAAoB,OAAO,aAAa;AAAA;;iBAGvD,eAAe;kBACf,MAAM,0BAA0B,KAAK,MAAM,wBAAwB,MAAM;sBACtE,0BAA0B;sBAC1B,wBAAwB;qBACzB,aAAa,oBAAoB,OAAO,aAAa;AAAA;;;;;;;;;;EAYzD,kBAA4C;UAC7C,WAAW,aAAY,gBAAgB,IAAI,KAAK,iBAAiB;QACnE,aAAa,QAAW;aACpB;AAAA;UAGF,gBAAgB,aAAa,WAAW,KAAK,kBAAkB,KAAK,OAAO,SAAS;kBAC5E,KAAK,YAAU;mBAChB,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;AAAA;iBAEnD,gBAAgB,IAAI,KAAK,iBAAiB,QAAQ;WACvD;AAAA;AAAA,EAQA,mBAAmB;WAGnB,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,4CAA4C,aAAY;AAAA;AAAA;;AArZvC,2BAAA,mBAAyD,IAAI;AA2YtE,2BAAA,gCAA+B;MACzC,OAAO;SACJ,MAAM;AAAA;;"}
1
+ {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { Schema, SchemaLoader, SchemaValidator } from './schema'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate static readonly schemaLoadCache: Map<string, Schema | Promise<Schema>> = new Map()\n\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\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 treeStore: TreeStore\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 environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor) => void,\n\t\tprivate readonly onError: (error: RequestError) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.treeStore = new TreeStore()\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)\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.config,\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)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutation = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(mutation, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\t\t\t\t\t\tconst mutationData = mutationResponse.data?.transaction ?? {}\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tconst allSubMutationsOk = aliases.every(item => mutationData[item].ok)\n\n\t\t\t\t\t\tif (allSubMutationsOk) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations))\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: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject()\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\tconst schema = await this.getOrLoadSchema()\n\t\t\tthis.treeStore.setSchema(schema)\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t// For most trees, checking this against the schema should be unnecessary since if we already effectively\n\t\t\t\t// have this tree root, then assuming everything we already have is valid, this should match the schema as well.\n\t\t\t\t// However, we might be dealing with an isCreating tree root which is completely new. Also, we can just lean\n\t\t\t\t// towards the safe side since developer machines can generally handle the potentially unnecessary check anyway.\n\t\t\t\tSchemaValidator.assertTreeValid(schema, markerTreeRoot)\n\t\t\t}\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject,\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\t// Even if we don't have a schema yet, we'll still optimistically fire the request so as to prevent a waterfall\n\t\t// in the most likely case that things will go fine and the query does match the schema. If it doesn't, then we\n\t\t// just get a \"400 Bad Request\" but that's not enough to make us delay the happy path.\n\t\tconst [aggregatePersistedData, schema] = await Promise.all([\n\t\t\tthis.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal),\n\t\t\tthis.getOrLoadSchema(),\n\t\t])\n\t\tthis.treeStore.setSchema(schema)\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tSchemaValidator.assertTreeValid(schema, extension.markerTreeRoot)\n\t\t\t}\n\t\t}\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {})\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (metadata.name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata))\n\t\t}\n\t\treturn queryResponse\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 getOrLoadSchema(): Schema | Promise<Schema> {\n\t\tconst existing = DataBinding.schemaLoadCache.get(this.contentApiClient.apiUrl)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst schemaPromise = SchemaLoader.loadSchema(this.contentApiClient, this.config.getValue('maxSchemaLoadAttempts'))\n\t\tschemaPromise.then(schema => {\n\t\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schema)\n\t\t})\n\t\tDataBinding.schemaLoadCache.set(this.contentApiClient.apiUrl, schemaPromise)\n\t\treturn schemaPromise\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":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;2BAwCyB;AAAA,EAoBjB,YACW,kBACA,iBACA,iBACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwLT,4CAAmB,CAAC,EAAE,iBAAiC;WACzD,SAAS,IAAI,iBAAiB,KAAK,iBAAiB,cAAc,YAAY,KAAK;AAAA;AAQjF,6CAOH,IAAI;;;;;;;;SAvLH,SAAS,IAAI;SACb,YAAY,IAAI;SAChB,sBAAsB,0BAA0B,aAAa,KAAK;SAClE,2BAA2B;AAAA,SAC5B,KAAK;AAAA,MACR,eAAe;AAAA,MACf,cAAc;AAAA,MACd,cAAc;AAAA;SAEV,mBAAmB,IAAI;SACvB,eAAe,IAAI,aACvB,KAAK,0BACL,KAAK,qBACL,KAAK,QACL,KAAK,kBACL,KAAK,kBACL,KAAK;SAED,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, ChildrenAnalyzer } from "@contember/react-multipass-r
8
8
  import { BindingError } from "../BindingError.js";
9
9
  import { IncrementalMarkerBuilder } from "./IncrementalMarkerBuilder.js";
10
10
  import { Environment } from "../dao/Environment.js";
11
- import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
12
11
  import { MarkerTreeRoot } from "../markers/MarkerTreeRoot.js";
12
+ import { EntityFieldMarkersContainer } from "../markers/EntityFieldMarkersContainer.js";
13
13
  const _MarkerTreeGenerator = class {
14
14
  constructor(sourceTree, environment = Environment.create()) {
15
15
  this.sourceTree = sourceTree;
@@ -18,7 +18,7 @@ const _MarkerTreeGenerator = class {
18
18
  generate() {
19
19
  const processed = _MarkerTreeGenerator.childrenAnalyzer.processChildren(this.sourceTree, this.environment);
20
20
  if (processed.length === 0) {
21
- throw new BindingError("Empty data binding tree discovered. Try adding some fields\u2026");
21
+ return new MarkerTreeRoot(new Map(), new Map());
22
22
  }
23
23
  const collectedMarkers = _MarkerTreeGenerator.mapNodeResultToEntityFields(processed);
24
24
  if (collectedMarkers instanceof EntityFieldMarkersContainer) {
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerTreeGenerator.js","sources":["../../../src/core/MarkerTreeGenerator.ts"],"sourcesContent":["import { BranchNode, ChildrenAnalyzer, Leaf, RawNodeRepresentation } from '@contember/react-multipass-rendering'\nimport type { ReactNode } from 'react'\nimport { BindingError } from '../BindingError'\nimport { Environment } from '../dao'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport type { Alias } from '../treeParameters'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Fragment = EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker\ntype Terminals = FieldMarker | HasOneRelationMarker | Fragment\ntype Nonterminals = HasOneRelationMarker | HasManyRelationMarker | Fragment\n\nexport class MarkerTreeGenerator {\n\tprivate static childrenAnalyzer = MarkerTreeGenerator.initializeChildrenAnalyzer()\n\n\tpublic constructor(private sourceTree: ReactNode, private environment: Environment = Environment.create()) {}\n\n\tpublic generate(): MarkerTreeRoot {\n\t\tconst processed = MarkerTreeGenerator.childrenAnalyzer.processChildren(this.sourceTree, this.environment)\n\n\t\tif (processed.length === 0) {\n\t\t\tthrow new BindingError('Empty data binding tree discovered. Try adding some fields…')\n\t\t}\n\n\t\tconst collectedMarkers = MarkerTreeGenerator.mapNodeResultToEntityFields(processed)\n\n\t\tif (collectedMarkers instanceof EntityFieldMarkersContainer) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.fields.markers.size) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.parentReference !== undefined) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.subTrees === undefined) {\n\t\t\tthrow new BindingError()\n\t\t}\n\n\t\tconst subTrees = collectedMarkers.subTrees\n\n\t\treturn new MarkerTreeRoot(subTrees, this.generatePlaceholdersByAliases(subTrees))\n\t}\n\n\tprivate generatePlaceholdersByAliases(\n\t\thoistedSubTrees: Map<string, EntitySubTreeMarker | EntityListSubTreeMarker>,\n\t): Map<Alias, string> {\n\t\tconst placeholders = new Map<Alias, string>()\n\n\t\tfor (const [placeholderName, subTree] of hoistedSubTrees) {\n\t\t\tconst aliases = subTree.parameters.alias\n\t\t\tif (aliases === undefined || aliases.size === 0) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const alias of aliases) {\n\t\t\t\tconst existingPlaceholder = placeholders.get(alias)\n\t\t\t\tif (existingPlaceholder !== undefined) {\n\t\t\t\t\tif (existingPlaceholder === placeholderName) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Detected the same sub-tree alias '${alias}' referring to sub-trees with different parameters!`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tplaceholders.set(alias, placeholderName)\n\t\t\t}\n\t\t}\n\n\t\treturn placeholders\n\t}\n\n\tprivate static mapNodeResultToEntityFields(\n\t\tresult: RawNodeRepresentation<Terminals, Nonterminals>,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer {\n\t\tconst builder = new IncrementalMarkerBuilder()\n\n\t\tif (!result) {\n\t\t\treturn builder.getFinalMarker()\n\t\t}\n\n\t\tif (!Array.isArray(result)) {\n\t\t\tbuilder.mutateIn(result)\n\t\t\treturn builder.getFinalMarker()\n\t\t}\n\n\t\tfor (const marker of result) {\n\t\t\tbuilder.mutateIn(marker)\n\t\t}\n\n\t\treturn builder.getFinalMarker()\n\t}\n\n\tprivate static initializeChildrenAnalyzer(): ChildrenAnalyzer<Terminals, Nonterminals, Environment> {\n\t\tconst fieldMarkerLeaf = new Leaf<any, Environment>('generateLeafMarker')\n\n\t\tconst branchMarkerBranchNode = new BranchNode<any, Environment>(\n\t\t\t'generateBranchMarker',\n\t\t\tthis.mapNodeResultToEntityFields,\n\t\t\t{ childrenAreOptional: true },\n\t\t)\n\n\t\treturn new ChildrenAnalyzer([fieldMarkerLeaf], [branchMarkerBranchNode], {\n\t\t\tstaticRenderFactoryName: 'staticRender',\n\t\t\trenderPropsErrorMessage:\n\t\t\t\t`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`,\n\t\t\tignoreRenderProps: false,\n\t\t\tstaticContextFactoryName: 'generateEnvironment',\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;mCAqBiC;AAAA,EAGzB,YAAoB,YAA+B,cAA2B,YAAY,UAAU;;;;EAEpG,WAA2B;UAC3B,YAAY,qBAAoB,iBAAiB,gBAAgB,KAAK,YAAY,KAAK;QAEzF,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nalyzer, Leaf, RawNodeRepresentation } from '@contember/react-multipass-rendering'\nimport type { ReactNode } from 'react'\nimport { BindingError } from '../BindingError'\nimport { Environment } from '../dao'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '../markers'\nimport type { Alias } from '../treeParameters'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Fragment = EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker\ntype Terminals = FieldMarker | HasOneRelationMarker | Fragment\ntype Nonterminals = HasOneRelationMarker | HasManyRelationMarker | Fragment\n\nexport class MarkerTreeGenerator {\n\tprivate static childrenAnalyzer = MarkerTreeGenerator.initializeChildrenAnalyzer()\n\n\tpublic constructor(private sourceTree: ReactNode, private environment: Environment = Environment.create()) {}\n\n\tpublic generate(): MarkerTreeRoot {\n\t\tconst processed = MarkerTreeGenerator.childrenAnalyzer.processChildren(this.sourceTree, this.environment)\n\n\t\tif (processed.length === 0) {\n\t\t\treturn new MarkerTreeRoot(new Map(), new Map())\n\t\t}\n\n\t\tconst collectedMarkers = MarkerTreeGenerator.mapNodeResultToEntityFields(processed)\n\n\t\tif (collectedMarkers instanceof EntityFieldMarkersContainer) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.fields.markers.size) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.parentReference !== undefined) {\n\t\t\tthrow new BindingError()\n\t\t}\n\t\tif (collectedMarkers.subTrees === undefined) {\n\t\t\tthrow new BindingError()\n\t\t}\n\n\t\tconst subTrees = collectedMarkers.subTrees\n\n\t\treturn new MarkerTreeRoot(subTrees, this.generatePlaceholdersByAliases(subTrees))\n\t}\n\n\tprivate generatePlaceholdersByAliases(\n\t\thoistedSubTrees: Map<string, EntitySubTreeMarker | EntityListSubTreeMarker>,\n\t): Map<Alias, string> {\n\t\tconst placeholders = new Map<Alias, string>()\n\n\t\tfor (const [placeholderName, subTree] of hoistedSubTrees) {\n\t\t\tconst aliases = subTree.parameters.alias\n\t\t\tif (aliases === undefined || aliases.size === 0) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tfor (const alias of aliases) {\n\t\t\t\tconst existingPlaceholder = placeholders.get(alias)\n\t\t\t\tif (existingPlaceholder !== undefined) {\n\t\t\t\t\tif (existingPlaceholder === placeholderName) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Detected the same sub-tree alias '${alias}' referring to sub-trees with different parameters!`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tplaceholders.set(alias, placeholderName)\n\t\t\t}\n\t\t}\n\n\t\treturn placeholders\n\t}\n\n\tprivate static mapNodeResultToEntityFields(\n\t\tresult: RawNodeRepresentation<Terminals, Nonterminals>,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer {\n\t\tconst builder = new IncrementalMarkerBuilder()\n\n\t\tif (!result) {\n\t\t\treturn builder.getFinalMarker()\n\t\t}\n\n\t\tif (!Array.isArray(result)) {\n\t\t\tbuilder.mutateIn(result)\n\t\t\treturn builder.getFinalMarker()\n\t\t}\n\n\t\tfor (const marker of result) {\n\t\t\tbuilder.mutateIn(marker)\n\t\t}\n\n\t\treturn builder.getFinalMarker()\n\t}\n\n\tprivate static initializeChildrenAnalyzer(): ChildrenAnalyzer<Terminals, Nonterminals, Environment> {\n\t\tconst fieldMarkerLeaf = new Leaf<any, Environment>('generateLeafMarker')\n\n\t\tconst branchMarkerBranchNode = new BranchNode<any, Environment>(\n\t\t\t'generateBranchMarker',\n\t\t\tthis.mapNodeResultToEntityFields,\n\t\t\t{ childrenAreOptional: true },\n\t\t)\n\n\t\treturn new ChildrenAnalyzer([fieldMarkerLeaf], [branchMarkerBranchNode], {\n\t\t\tstaticRenderFactoryName: 'staticRender',\n\t\t\trenderPropsErrorMessage:\n\t\t\t\t`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`,\n\t\t\tignoreRenderProps: false,\n\t\t\tstaticContextFactoryName: 'generateEnvironment',\n\t\t})\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;mCAqBiC;AAAA,EAGzB,YAAoB,YAA+B,cAA2B,YAAY,UAAU;;;;EAEpG,WAA2B;UAC3B,YAAY,qBAAoB,iBAAiB,gBAAgB,KAAK,YAAY,KAAK;QAEzF,UAAU,WAAW,GAAG;aACpB,IAAI,eAAe,IAAI,OAAO,IAAI;AAAA;UAGpC,mBAAmB,qBAAoB,4BAA4B;QAErE,4BAA4B,6BAA6B;YACtD,IAAI;AAAA;QAEP,iBAAiB,OAAO,QAAQ,MAAM;YACnC,IAAI;AAAA;QAEP,iBAAiB,oBAAoB,QAAW;YAC7C,IAAI;AAAA;QAEP,iBAAiB,aAAa,QAAW;YACtC,IAAI;AAAA;UAGL,WAAW,iBAAiB;WAE3B,IAAI,eAAe,UAAU,KAAK,8BAA8B;AAAA;AAAA,EAGhE,8BACP,iBACqB;UACf,eAAe,IAAI;eAEd,CAAC,iBAAiB,YAAY,iBAAiB;YACnD,UAAU,QAAQ,WAAW;UAC/B,YAAY,UAAa,QAAQ,SAAS,GAAG;;;iBAGtC,SAAS,SAAS;cACtB,sBAAsB,aAAa,IAAI;YACzC,wBAAwB,QAAW;cAClC,wBAAwB,iBAAiB;;;gBAGvC,IAAI,aACT,qCAAqC;AAAA;qBAG1B,IAAI,OAAO;AAAA;AAAA;WAInB;AAAA;AAAA,SAGO,4BACd,QACiE;UAC3D,UAAU,IAAI;QAEhB,CAAC,QAAQ;aACL,QAAQ;AAAA;QAGZ,CAAC,MAAM,QAAQ,SAAS;cACnB,SAAS;aACV,QAAQ;AAAA;eAGL,UAAU,QAAQ;cACpB,SAAS;AAAA;WAGX,QAAQ;AAAA;AAAA,SAGD,6BAAqF;UAC7F,kBAAkB,IAAI,KAAuB;UAE7C,yBAAyB,IAAI,WAClC,wBACA,KAAK,6BACL,EAAE,qBAAqB;WAGjB,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,yBAAyB;AAAA,MACxE,yBAAyB;AAAA,MACzB,yBACC;AAAA,MAGD,mBAAmB;AAAA,MACnB,0BAA0B;AAAA;AAAA;AAAA;;AA/Fb,mCAAA,oBAAmB,qBAAoB;;"}
@@ -51,32 +51,63 @@ class StateInitializer {
51
51
  }
52
52
  return subTreeState;
53
53
  }
54
- initializeEntityRealm(id, entityName, blueprint) {
54
+ initializeEntityRealm(id, entityName, blueprint, copyFrom) {
55
55
  const entity = this.initializeEntityState(id, entityName);
56
56
  const realmKey = RealmKeyGenerator.getRealmKey(id, blueprint);
57
57
  const existing = this.treeStore.entityRealmStore.get(realmKey);
58
58
  if (existing !== void 0) {
59
59
  return existing;
60
60
  }
61
- const stub = {
62
- type: "entityRealmStub",
63
- blueprint,
64
- entity,
65
- realmKey,
66
- getAccessor: () => this.materializeEntityRealm(stub).getAccessor()
67
- };
68
- this.registerEntityRealm(stub);
69
- return stub;
70
- }
71
- materializeEntityRealm(state) {
72
- if (state.type === "entityRealm") {
73
- return state;
61
+ if (!copyFrom || copyFrom.type !== "entityRealm") {
62
+ const stub = {
63
+ type: "entityRealmStub",
64
+ blueprint,
65
+ entity,
66
+ realmKey,
67
+ getAccessor: () => this.materializeEntityRealm(stub).getAccessor()
68
+ };
69
+ this.registerEntityRealm(stub);
70
+ return stub;
74
71
  }
75
- const { realmKey, entity, blueprint } = state;
76
- const existing = this.treeStore.entityRealmStore.get(realmKey);
77
- if (existing !== void 0 && existing.type === "entityRealm") {
78
- return existing;
72
+ const realm = this.createEntityRealm(blueprint, realmKey, entity);
73
+ this.registerEntityRealm(realm);
74
+ const marker = getEntityMarker(realm);
75
+ const pathBack = this.treeStore.getPathBackToParent(realm);
76
+ for (const [placeholderName, field] of marker.fields.markers) {
77
+ if (field instanceof FieldMarker) {
78
+ const value = copyFrom.children.get(placeholderName);
79
+ if (!value || value.type !== "field") {
80
+ throw new BindingError();
81
+ }
82
+ this.initializeFromFieldMarker(realm, field, value.value);
83
+ } else if (field instanceof HasManyRelationMarker) {
84
+ this.initializeFromHasManyRelationMarker(realm, field, new Set());
85
+ } else if (field instanceof HasOneRelationMarker) {
86
+ let runtimeId;
87
+ let subCopyFrom = void 0;
88
+ if (pathBack?.fieldBackToParent === field.parameters.field) {
89
+ runtimeId = pathBack.parent.entity.id;
90
+ } else {
91
+ const value = copyFrom.children.get(placeholderName);
92
+ if (!value || value.type !== "entityRealm" && value.type !== "entityRealmStub") {
93
+ throw new BindingError();
94
+ }
95
+ if (value.type === "entityRealm") {
96
+ subCopyFrom = value;
97
+ runtimeId = value.entity.id;
98
+ } else {
99
+ runtimeId = new UnpersistedEntityDummyId();
100
+ }
101
+ }
102
+ this.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom);
103
+ } else {
104
+ assertNever();
105
+ }
79
106
  }
107
+ this.eventManager.registerNewlyInitialized(realm);
108
+ return realm;
109
+ }
110
+ createEntityRealm(blueprint, realmKey, entity) {
80
111
  const entityRealm = {
81
112
  type: "entityRealm",
82
113
  blueprint,
@@ -98,6 +129,18 @@ class StateInitializer {
98
129
  return entityRealm.accessor;
99
130
  }
100
131
  };
132
+ return entityRealm;
133
+ }
134
+ materializeEntityRealm(state) {
135
+ if (state.type === "entityRealm") {
136
+ return state;
137
+ }
138
+ const { realmKey, entity, blueprint } = state;
139
+ const existing = this.treeStore.entityRealmStore.get(realmKey);
140
+ if (existing !== void 0 && existing.type === "entityRealm") {
141
+ return existing;
142
+ }
143
+ const entityRealm = this.createEntityRealm(blueprint, realmKey, entity);
101
144
  this.registerEntityRealm(entityRealm);
102
145
  const persistedData = this.treeStore.persistedEntityData.get(entity.id.value);
103
146
  const marker = getEntityMarker(state);
@@ -214,12 +257,12 @@ class StateInitializer {
214
257
  }
215
258
  parent.children.set(field.placeholderName, this.initializeFieldState(parent, field.placeholderName, field, fieldDatum));
216
259
  }
217
- initializeFromHasOneRelationMarker(parent, field, entityId) {
260
+ initializeFromHasOneRelationMarker(parent, field, entityId, copyFrom) {
218
261
  parent.children.set(field.placeholderName, this.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {
219
262
  type: "hasOne",
220
263
  parent,
221
264
  marker: field
222
- }));
265
+ }, copyFrom));
223
266
  }
224
267
  initializeFromHasManyRelationMarker(parent, field, persistedEntityIds) {
225
268
  parent.children.set(field.placeholderName, this.initializeEntityListState({ marker: field, parent }, this.getRelationTargetEntityName(parent, field), persistedEntityIds));