@contember/binding 1.3.0-alpha.6 → 1.3.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/dist/development/accessorTree/RuntimeId.cjs +5 -5
  2. package/dist/development/accessorTree/RuntimeId.cjs.map +1 -1
  3. package/dist/development/accessorTree/RuntimeId.js +5 -5
  4. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  5. package/dist/development/accessors/EntityAccessor.cjs.map +1 -1
  6. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  7. package/dist/development/core/AccessorErrorManager.cjs +1 -1
  8. package/dist/development/core/AccessorErrorManager.cjs.map +1 -1
  9. package/dist/development/core/AccessorErrorManager.js +1 -1
  10. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  11. package/dist/development/core/Config.cjs +3 -3
  12. package/dist/development/core/Config.cjs.map +1 -1
  13. package/dist/development/core/Config.js +3 -3
  14. package/dist/development/core/Config.js.map +1 -1
  15. package/dist/development/core/DataBinding.cjs +3 -3
  16. package/dist/development/core/DataBinding.cjs.map +1 -1
  17. package/dist/development/core/DataBinding.js +3 -3
  18. package/dist/development/core/DataBinding.js.map +1 -1
  19. package/dist/development/core/ErrorsPreprocessor.cjs.map +1 -1
  20. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  21. package/dist/development/core/EventManager.cjs.map +1 -1
  22. package/dist/development/core/EventManager.js.map +1 -1
  23. package/dist/development/core/MarkerComparator.cjs.map +1 -1
  24. package/dist/development/core/MarkerComparator.js.map +1 -1
  25. package/dist/development/core/MarkerMerger.cjs.map +1 -1
  26. package/dist/development/core/MarkerMerger.js.map +1 -1
  27. package/dist/development/core/MutationGenerator.cjs.map +1 -1
  28. package/dist/development/core/MutationGenerator.js.map +1 -1
  29. package/dist/development/core/QueryGenerator.cjs.map +1 -1
  30. package/dist/development/core/QueryGenerator.js.map +1 -1
  31. package/dist/development/core/RealmKeyGenerator.cjs.map +1 -1
  32. package/dist/development/core/RealmKeyGenerator.js.map +1 -1
  33. package/dist/development/core/StateInitializer.cjs.map +1 -1
  34. package/dist/development/core/StateInitializer.js.map +1 -1
  35. package/dist/development/core/TreeParameterMerger.cjs.map +1 -1
  36. package/dist/development/core/TreeParameterMerger.js.map +1 -1
  37. package/dist/development/core/TreeStore.cjs.map +1 -1
  38. package/dist/development/core/TreeStore.js.map +1 -1
  39. package/dist/development/core/VariableInputTransformer.cjs.map +1 -1
  40. package/dist/development/core/VariableInputTransformer.js.map +1 -1
  41. package/dist/development/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
  42. package/dist/development/core/exceptions/TreeParameterSugarer.js.map +1 -1
  43. package/dist/development/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
  44. package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
  45. package/dist/development/core/operations/EntityOperations.cjs.map +1 -1
  46. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  47. package/dist/development/core/operations/FieldOperations.cjs.map +1 -1
  48. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  49. package/dist/development/core/operations/ListOperations.cjs.map +1 -1
  50. package/dist/development/core/operations/ListOperations.js.map +1 -1
  51. package/dist/development/core/operations/OperationsHelpers.cjs.map +1 -1
  52. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  53. package/dist/development/core/requestAliases/MutationAlias.cjs.map +1 -1
  54. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  55. package/dist/development/core/schema/Schema.cjs.map +1 -1
  56. package/dist/development/core/schema/Schema.js.map +1 -1
  57. package/dist/development/dao/Environment.cjs.map +1 -1
  58. package/dist/development/dao/Environment.js.map +1 -1
  59. package/dist/development/markers/PlaceholderGenerator.cjs.map +1 -1
  60. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  61. package/dist/development/queryLanguage/Parser.cjs +6 -6
  62. package/dist/development/queryLanguage/Parser.cjs.map +1 -1
  63. package/dist/development/queryLanguage/Parser.js +6 -6
  64. package/dist/development/queryLanguage/Parser.js.map +1 -1
  65. package/dist/development/queryLanguage/QueryLanguage.cjs +13 -13
  66. package/dist/development/queryLanguage/QueryLanguage.cjs.map +1 -1
  67. package/dist/development/queryLanguage/QueryLanguage.js +13 -13
  68. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  69. package/dist/development/treeParameters/EventListenersStore.cjs.map +1 -1
  70. package/dist/development/treeParameters/EventListenersStore.js.map +1 -1
  71. package/dist/development/utils/TreeNodeUtils.cjs.map +1 -1
  72. package/dist/development/utils/TreeNodeUtils.js.map +1 -1
  73. package/dist/development/utils/assert.cjs.map +1 -1
  74. package/dist/development/utils/assert.js.map +1 -1
  75. package/dist/development/utils/ucfirst.cjs.map +1 -1
  76. package/dist/development/utils/ucfirst.js.map +1 -1
  77. package/dist/production/accessorTree/RuntimeId.cjs +5 -5
  78. package/dist/production/accessorTree/RuntimeId.cjs.map +1 -1
  79. package/dist/production/accessorTree/RuntimeId.js +5 -5
  80. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  81. package/dist/production/accessors/EntityAccessor.cjs.map +1 -1
  82. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  83. package/dist/production/core/AccessorErrorManager.cjs +1 -1
  84. package/dist/production/core/AccessorErrorManager.cjs.map +1 -1
  85. package/dist/production/core/AccessorErrorManager.js +1 -1
  86. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  87. package/dist/production/core/Config.cjs +3 -3
  88. package/dist/production/core/Config.cjs.map +1 -1
  89. package/dist/production/core/Config.js +3 -3
  90. package/dist/production/core/Config.js.map +1 -1
  91. package/dist/production/core/DataBinding.cjs +3 -3
  92. package/dist/production/core/DataBinding.cjs.map +1 -1
  93. package/dist/production/core/DataBinding.js +3 -3
  94. package/dist/production/core/DataBinding.js.map +1 -1
  95. package/dist/production/core/ErrorsPreprocessor.cjs.map +1 -1
  96. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  97. package/dist/production/core/EventManager.cjs.map +1 -1
  98. package/dist/production/core/EventManager.js.map +1 -1
  99. package/dist/production/core/MarkerComparator.cjs.map +1 -1
  100. package/dist/production/core/MarkerComparator.js.map +1 -1
  101. package/dist/production/core/MarkerMerger.cjs.map +1 -1
  102. package/dist/production/core/MarkerMerger.js.map +1 -1
  103. package/dist/production/core/MutationGenerator.cjs.map +1 -1
  104. package/dist/production/core/MutationGenerator.js.map +1 -1
  105. package/dist/production/core/QueryGenerator.cjs.map +1 -1
  106. package/dist/production/core/QueryGenerator.js.map +1 -1
  107. package/dist/production/core/RealmKeyGenerator.cjs.map +1 -1
  108. package/dist/production/core/RealmKeyGenerator.js.map +1 -1
  109. package/dist/production/core/StateInitializer.cjs.map +1 -1
  110. package/dist/production/core/StateInitializer.js.map +1 -1
  111. package/dist/production/core/TreeParameterMerger.cjs.map +1 -1
  112. package/dist/production/core/TreeParameterMerger.js.map +1 -1
  113. package/dist/production/core/TreeStore.cjs.map +1 -1
  114. package/dist/production/core/TreeStore.js.map +1 -1
  115. package/dist/production/core/VariableInputTransformer.cjs.map +1 -1
  116. package/dist/production/core/VariableInputTransformer.js.map +1 -1
  117. package/dist/production/core/exceptions/TreeParameterSugarer.cjs.map +1 -1
  118. package/dist/production/core/exceptions/TreeParameterSugarer.js.map +1 -1
  119. package/dist/production/core/factories/createBatchUpdatesOptions.cjs.map +1 -1
  120. package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
  121. package/dist/production/core/operations/EntityOperations.cjs.map +1 -1
  122. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  123. package/dist/production/core/operations/ListOperations.cjs.map +1 -1
  124. package/dist/production/core/operations/ListOperations.js.map +1 -1
  125. package/dist/production/core/operations/OperationsHelpers.cjs.map +1 -1
  126. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  127. package/dist/production/core/requestAliases/MutationAlias.cjs.map +1 -1
  128. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  129. package/dist/production/core/schema/Schema.cjs.map +1 -1
  130. package/dist/production/core/schema/Schema.js.map +1 -1
  131. package/dist/production/dao/Environment.cjs.map +1 -1
  132. package/dist/production/dao/Environment.js.map +1 -1
  133. package/dist/production/markers/PlaceholderGenerator.cjs.map +1 -1
  134. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  135. package/dist/production/queryLanguage/Parser.cjs +6 -6
  136. package/dist/production/queryLanguage/Parser.cjs.map +1 -1
  137. package/dist/production/queryLanguage/Parser.js +6 -6
  138. package/dist/production/queryLanguage/Parser.js.map +1 -1
  139. package/dist/production/queryLanguage/QueryLanguage.cjs +13 -13
  140. package/dist/production/queryLanguage/QueryLanguage.cjs.map +1 -1
  141. package/dist/production/queryLanguage/QueryLanguage.js +13 -13
  142. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  143. package/dist/production/treeParameters/EventListenersStore.cjs.map +1 -1
  144. package/dist/production/treeParameters/EventListenersStore.js.map +1 -1
  145. package/dist/production/utils/TreeNodeUtils.cjs.map +1 -1
  146. package/dist/production/utils/TreeNodeUtils.js.map +1 -1
  147. package/dist/production/utils/assert.cjs.map +1 -1
  148. package/dist/production/utils/assert.js.map +1 -1
  149. package/dist/production/utils/ucfirst.cjs.map +1 -1
  150. package/dist/production/utils/ucfirst.js.map +1 -1
  151. package/dist/types/accessors/EntityAccessor.d.ts +2 -2
  152. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  153. package/dist/types/treeParameters/EventListenersStore.d.ts +2 -1
  154. package/dist/types/treeParameters/EventListenersStore.d.ts.map +1 -1
  155. package/dist/types/tsconfig.tsbuildinfo +1 -1
  156. package/package.json +5 -5
  157. package/src/accessors/EntityAccessor.ts +2 -2
  158. package/src/treeParameters/EventListenersStore.ts +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\n\t\t\t\t\tif (!(justUpdated.blueprint.type === 'subTree' && justUpdated.blueprint.marker.parameters.isCreating && justUpdated.blueprint.marker.parameters.isUnpersisted)) {\n\t\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\t\tlet validateChanges = false\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tvalidateChanges = true\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t\tif (validateChanges) {\n\t\t\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\tconst newCallbacks = await Promise.allSettled(promiseReturns)\n\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\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\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\n\tprivate validateWithoutChanges(initialCount: number, eventType: string): void {\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalTouchCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (initialCount !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["changesCountBefore"],"mappings":";;;;;;;;;;AA6BO,MAAM,aAAa;AAAA,EAiBlB,YACW,0BACA,qBACA,QACA,kBACA,UACA,WACA,gBAChB;AAtBM,4CAAmB;AACnB,iDAAwB;AAIxB;AAAA;AAAA,sCAAsB;AACtB;AAEA;AAEA,6EAA0F;AAC1F,uEAA8C;AAC9C,uEAAkD;AAGxC,SAAA,2BAAA;AACA,SAAA,sBAAA;AACA,SAAA,SAAA;AACA,SAAA,m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AAiB,mBAAmB;AAGvC,cAAM,IAAI;AAAA,UACT,KAAK;AAAA,QAAA;AAAA,MAGP;AAAA,IACD;AAAA,EACD;AACD;AA9iBC,cADY,cACW,yBAAwB;"}
1
+ {"version":3,"file":"EventManager.js","sources":["../../../src/core/EventManager.ts"],"sourcesContent":["import type {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tEntityAccessor,\n\tEntityListAccessor,\n\tFieldAccessor,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n} from '../accessors'\nimport type { SuccessfulPersistResult } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { Config } from './Config'\nimport type { DirtinessTracker } from './DirtinessTracker'\nimport {\n\tEntityListState,\n\tEntityRealmState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n\tStateINode,\n\tStateIterator,\n\tStateNode,\n} from './state'\nimport type { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport type { EventListenersStore } from '../treeParameters'\n\nexport class EventManager {\n\tpublic static readonly NO_CHANGES_DIFFERENCE = 0\n\n\tprivate transactionDepth = 0\n\tprivate isFrozenWhileUpdating = false\n\n\t// This should ideally not exists as it should be synonymous to `this.ongoingPersistOperation !== undefined`\n\t// but it makes persist-related promise juggling significantly more straightforward.\n\tprivate isMutating: boolean = false\n\tprivate ongoingPersistOperation: Promise<SuccessfulPersistResult> | undefined = undefined\n\n\tprivate previousMetadata: UpdateMetadata | undefined = undefined\n\n\tprivate newlyInitializedWithListeners: Set<EntityListState | EntityRealmState | FieldState> = new Set()\n\tprivate pendingWithBeforeUpdate: Set<StateNode> = new Set()\n\tprivate rootsWithPendingUpdates: Set<RootStateNode> = new Set()\n\n\tpublic constructor(\n\t\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly dirtinessTracker: DirtinessTracker,\n\t\tprivate readonly onUpdate: (metadata: UpdateMetadata) => void,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly batchedUpdates: (callback: () => any) => void,\n\t) {}\n\n\tpublic async persistOperation(operation: () => Promise<SuccessfulPersistResult>): Promise<SuccessfulPersistResult> {\n\t\tif (this.transactionDepth > 0) {\n\t\t\tthrow new BindingError(`Cannot trigger a persist whilst batching updates!`)\n\t\t}\n\t\tconst ongoingOperation = this.ongoingPersistOperation\n\t\tif (ongoingOperation !== undefined) {\n\t\t\treturn await ongoingOperation\n\t\t}\n\t\treturn await (this.ongoingPersistOperation = new Promise<SuccessfulPersistResult>(async (resolve, reject) => {\n\t\t\tthis.isMutating = true\n\t\t\tthis.flushUpdates() // Let the world know that we're mutating\n\n\t\t\ttry {\n\t\t\t\tresolve(await this.asyncOperation(operation))\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error('PersistError', e)\n\t\t\t\treject(e)\n\t\t\t} finally {\n\t\t\t\tthis.ongoingPersistOperation = undefined\n\t\t\t\tthis.isMutating = false\n\t\t\t\tthis.flushUpdates()\n\t\t\t}\n\t\t}))\n\t}\n\n\tpublic syncTransaction<T>(transaction: () => T) {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic syncOperation<T>(operation: () => T) {\n\t\tconst result = this.syncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tpublic async asyncTransaction<T>(transaction: () => Promise<T>): Promise<T> {\n\t\ttry {\n\t\t\tthis.transactionDepth++\n\t\t\treturn await transaction()\n\t\t} finally {\n\t\t\tthis.transactionDepth--\n\t\t}\n\t}\n\tpublic async asyncOperation<T>(operation: () => Promise<T>): Promise<T> {\n\t\tconst result = await this.asyncTransaction(operation)\n\t\tthis.flushUpdates()\n\t\treturn result\n\t}\n\n\tprivate flushUpdates() {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn\n\t\t}\n\n\t\tif (this.isFrozenWhileUpdating) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Trying to perform an update while the whole accessor tree is already updating. This is most likely caused ` +\n\t\t\t\t\t`by updating the accessor tree while rendering or from within the 'update' event handler, which is a no-op. ` +\n\t\t\t\t\t`If you wish to mutate the tree in reaction to other changes, use the 'beforeUpdate' event.`,\n\t\t\t)\n\t\t}\n\n\t\tconst newMetadata = this.getNewUpdateMetadata()\n\n\t\tif (!this.shouldFlushUpdates(newMetadata)) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.batchedUpdates(() => {\n\t\t\tthis.isFrozenWhileUpdating = true\n\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\tthis.onUpdate(newMetadata)\n\t\t\tthis.flushPendingAccessorUpdates(Array.from(this.rootsWithPendingUpdates))\n\n\t\t\tthis.rootsWithPendingUpdates.clear()\n\t\t\tthis.isFrozenWhileUpdating = false\n\t\t\tthis.previousMetadata = newMetadata\n\t\t})\n\t}\n\n\tprivate getNewUpdateMetadata(): UpdateMetadata {\n\t\treturn {\n\t\t\tisMutating: this.isMutating,\n\t\t}\n\t}\n\n\tprivate shouldFlushUpdates(newMetadata: UpdateMetadata): boolean {\n\t\tif (this.transactionDepth > 0) {\n\t\t\treturn false\n\t\t}\n\t\tif (this.previousMetadata === undefined) {\n\t\t\treturn true\n\t\t}\n\t\tif (this.rootsWithPendingUpdates.size) {\n\t\t\treturn true\n\t\t}\n\t\tfor (const key in newMetadata) {\n\t\t\tconst fromPrevious = this.previousMetadata[key as keyof UpdateMetadata]\n\t\t\tconst fromNew = newMetadata[key as keyof UpdateMetadata]\n\n\t\t\tif (!Object.is(fromPrevious, fromNew)) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t}\n\t\treturn false\n\t}\n\n\tpublic registerNewlyInitialized(newlyInitialized: StateNode) {\n\t\tconst initializeListeners = this.getEventListeners(newlyInitialized, { type: 'initialize' })\n\n\t\tif (initializeListeners === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.newlyInitializedWithListeners.add(newlyInitialized)\n\n\t\tif (this.transactionDepth === 0) {\n\t\t\tthis.triggerOnInitialize()\n\t\t}\n\t}\n\n\tpublic registerUpdatedConnection(parentState: EntityRealmState, placeholderName: PlaceholderName) {\n\t\tif (parentState.fieldsWithPendingConnectionUpdates === undefined) {\n\t\t\tparentState.fieldsWithPendingConnectionUpdates = new Set()\n\t\t}\n\n\t\tconst marker = getEntityMarker(parentState)\n\t\tplaceholders: for (const [fieldName, placeholdersByField] of marker.fields.placeholders) {\n\t\t\tif (typeof placeholdersByField === 'string') {\n\t\t\t\tif (placeholdersByField === placeholderName) {\n\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const placeholderByFieldName of placeholdersByField) {\n\t\t\t\t\tif (placeholderByFieldName === placeholderName) {\n\t\t\t\t\t\tparentState.fieldsWithPendingConnectionUpdates.add(fieldName)\n\t\t\t\t\t\tcontinue placeholders\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic registerJustUpdated(justUpdated: StateNode, changesDelta: number) {\n\t\tconst beforeUpdateListeners = this.getEventListeners(justUpdated, { type: 'beforeUpdate' })\n\t\tif (beforeUpdateListeners !== undefined) {\n\t\t\tthis.pendingWithBeforeUpdate.add(justUpdated)\n\t\t}\n\t\tjustUpdated.accessor = undefined\n\n\t\tswitch (justUpdated.type) {\n\t\t\tcase 'entityRealm':\n\t\t\tcase 'entityList': {\n\t\t\t\tjustUpdated.unpersistedChangesCount += changesDelta\n\n\t\t\t\tif (import.meta.env.DEV) {\n\t\t\t\t\tif (justUpdated.unpersistedChangesCount < 0) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`We have *JUST* reached a completely invalid state. From now on, anything can (and likely will) ` +\n\t\t\t\t\t\t\t\t`go wrong. This is definitely a bug. Please try to report whatever led to this situation.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst parent = justUpdated.blueprint.parent\n\n\t\t\t\tif (parent === undefined) {\n\t\t\t\t\tthis.rootsWithPendingUpdates.add(justUpdated)\n\n\t\t\t\t\tif (!(justUpdated.blueprint.type === 'subTree' && justUpdated.blueprint.marker.parameters.isCreating && justUpdated.blueprint.marker.parameters.isUnpersisted)) {\n\t\t\t\t\t\tthis.dirtinessTracker.increaseBy(changesDelta)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t\t}\n\t\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\t\tthis.registerJustUpdated(parent, changesDelta)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'field': {\n\t\t\t\tconst parent = justUpdated.parent\n\t\t\t\tif (!parent.childrenWithPendingUpdates) {\n\t\t\t\t\tparent.childrenWithPendingUpdates = new Set()\n\t\t\t\t}\n\t\t\t\tparent.childrenWithPendingUpdates.add(justUpdated as any)\n\t\t\t\tthis.registerJustUpdated(justUpdated.parent, changesDelta)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate flushPendingAccessorUpdates(rootStates: Array<StateINode>) {\n\t\t// It is *CRUCIAL* that this is a BFS so that we update the components in top-down order.\n\t\tconst agenda: StateNode[] = rootStates\n\n\t\tfor (const state of agenda) {\n\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\tconst updateListeners =\n\t\t\t\tstate.type === 'field'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t? this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\t\t\t\t\t: this.getEventDispatchers(state, { type: 'update' }, [state.getAccessor()])\n\n\t\t\tif (updateListeners !== undefined) {\n\t\t\t\tfor (const handler of updateListeners) {\n\t\t\t\t\t// TS can't quite handle the polymorphism here but this is fine.\n\t\t\t\t\thandler()\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (state.type === 'entityRealm' && state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\tfor (const updatedField of state.fieldsWithPendingConnectionUpdates) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'connectionUpdate', key: updatedField })\n\t\t\t\t\tif (!listeners) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener(state.getAccessor())\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tswitch (state.type) {\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (state.childrenWithPendingUpdates !== undefined) {\n\t\t\t\t\t\tfor (const childState of state.childrenWithPendingUpdates) {\n\t\t\t\t\t\t\tagenda.push(childState)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tstate.childrenWithPendingUpdates.clear()\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'field':\n\t\t\t\t\t// Do nothing\n\t\t\t\t\tbreak\n\t\t\t\tdefault:\n\t\t\t\t\tassertNever(state)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async triggerAsyncMutatingEvent(eventType: 'beforePersist', options: AsyncBatchUpdatesOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(eventType: 'persistSuccess', options: PersistSuccessOptions): Promise<void>\n\tprivate async triggerAsyncMutatingEvent(\n\t\teventType: 'beforePersist' | 'persistSuccess',\n\t\toptions: AsyncBatchUpdatesOptions | PersistSuccessOptions,\n\t): Promise<void> {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\t// TODO if an entity from here (or its parent) gets deleted, we need to remove stale handlers from here.\n\t\t\tconst callbackQueue: Array<\n\t\t\t\t[\n\t\t\t\t\t// The typings could be nicer but TS…\n\t\t\t\t\tStateINode,\n\t\t\t\t\t(\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\tconst listeners = this.getEventListeners(iNode, { type: eventType }) ?? []\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tcallbackQueue.push([iNode, listener])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (\n\t\t\t\tlet waterfallDepth = 0;\n\t\t\t\twaterfallDepth < this.config.getValue(`${eventType}SettleLimit` as const);\n\t\t\t\twaterfallDepth++\n\t\t\t) {\n\t\t\t\tconst promiseReturns: Array<\n\t\t\t\t\tPromise<\n\t\t\t\t\t\t| void\n\t\t\t\t\t\t| EntityAccessor.EntityEventListenerMap[typeof eventType]\n\t\t\t\t\t\t| EntityListAccessor.EntityListEventListenerMap[typeof eventType]\n\t\t\t\t\t>\n\t\t\t\t> = []\n\t\t\t\tconst correspondingStates: Array<StateINode> = []\n\n\t\t\t\tif (callbackQueue.length === 0) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\n\t\t\t\tfor (const [state, callback] of callbackQueue) {\n\t\t\t\t\tcorrespondingStates.push(state)\n\t\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\t\tlet validateChanges = false\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.\n\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\tvalidateChanges = true\n\t\t\t\t\t\t\tpromiseReturns.push(result)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tpromiseReturns.push(Promise.resolve(result))\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tpromiseReturns.push(Promise.reject(e))\n\t\t\t\t\t}\n\t\t\t\t\tif (validateChanges) {\n\t\t\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// TODO timeout\n\n\t\t\t\tconst changesCountBefore = this.dirtinessTracker.getTotalTouchCount()\n\t\t\t\tconst newCallbacks = await Promise.allSettled(promiseReturns)\n\t\t\t\tthis.validateWithoutChanges(changesCountBefore, eventType)\n\n\t\t\t\tcallbackQueue.length = 0 // Empties the queue\n\n\t\t\t\t// TODO we're drifting away from the original depth-first order. Let's see if that's ever even an issue.\n\t\t\t\tfor (const newlyInitialized of this.newlyInitializedWithListeners) {\n\t\t\t\t\tif (newlyInitialized.type === 'field') {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst beforePersistHandlers = this.getEventListeners(newlyInitialized, { type: eventType })\n\t\t\t\t\tif (beforePersistHandlers) {\n\t\t\t\t\t\tfor (const listener of beforePersistHandlers) {\n\t\t\t\t\t\t\tcallbackQueue.push([newlyInitialized, listener])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerBeforeFlushEvents()\n\t\t\t\tthis.handleRejections(eventType, newCallbacks)\n\n\t\t\t\tfor (let i = 0; i < newCallbacks.length; i++) {\n\t\t\t\t\tconst result = newCallbacks[i]\n\t\t\t\t\tconst correspondingState = correspondingStates[i]\n\n\t\t\t\t\tif (result.status === 'fulfilled') {\n\t\t\t\t\t\tif (typeof result.value === 'function') {\n\t\t\t\t\t\t\tcallbackQueue.push([correspondingState, result.value])\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Otherwise do nothing. This is just a handler that albeit async, doesn't appear to\n\t\t\t\t\t\t// interact with data binding.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (import.meta.env.DEV) {\n\t\t\t\tif (callbackQueue.length) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Exceeded the ${eventType} settle limit. Your code likely contains a deadlock. ` +\n\t\t\t\t\t\t\t`If that's not the case, raise the settle limit from DataBindingProvider.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate triggerBeforeFlushEvents() {\n\t\tthis.syncTransaction(() => {\n\t\t\tconst settleLimit = this.config.getValue('beforeUpdateSettleLimit')\n\n\t\t\tfor (let attemptNumber = 0; attemptNumber < settleLimit; attemptNumber++) {\n\t\t\t\tif (!this.pendingWithBeforeUpdate.size) {\n\t\t\t\t\tthis.triggerOnInitialize()\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tconst withBeforeUpdate = this.pendingWithBeforeUpdate\n\t\t\t\tthis.pendingWithBeforeUpdate = new Set()\n\n\t\t\t\tfor (const state of withBeforeUpdate) {\n\t\t\t\t\tconst listeners = this.getEventListeners(state, { type: 'beforeUpdate' })\n\t\t\t\t\tif (listeners === undefined) {\n\t\t\t\t\t\t// This can happen if the listener has unsubscribed since we added it to the set.\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\t(listener as FieldAccessor.BeforeUpdateListener)(state.getAccessor())\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\tcase 'entityList':\n\t\t\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\t\t\tstate.getAccessor().batchUpdates(listener as any)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn assertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.triggerOnInitialize()\n\t\t\t}\n\t\t\tthrow new BindingError(\n\t\t\t\t`Maximum stabilization limit of updates caused by 'beforeUpdate' exceeded. ` +\n\t\t\t\t\t`This likely means there is an infinite feedback loop in your code.`,\n\t\t\t)\n\t\t})\n\t}\n\n\tprivate triggerOnInitialize() {\n\t\tthis.syncTransaction(() => {\n\t\t\tfor (const state of this.newlyInitializedWithListeners) {\n\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\tconst listeners =\n\t\t\t\t\tstate.type === 'field'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: state.type === 'entityRealm'\n\t\t\t\t\t\t? this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\t\t\t\t\t\t: this.getEventDispatchers(state, { type: 'initialize' }, [state.getAccessor, this.batchUpdatesOptions])\n\n\t\t\t\tif (listeners) {\n\t\t\t\t\tfor (const listener of listeners) {\n\t\t\t\t\t\tlistener()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (state.type === 'entityRealm') {\n\t\t\t\t\tstate.entity.hasIdSetInStone = true\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.newlyInitializedWithListeners.clear()\n\t\t})\n\t}\n\n\tpublic async triggerOnPersistError(options: PersistErrorOptions) {\n\t\tawait this.asyncTransaction(async () => {\n\t\t\tconst handlerPromises: Array<Promise<void>> = []\n\n\t\t\tfor (const [, subTreeState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const iNode of StateIterator.depthFirstINodes(subTreeState)) {\n\t\t\t\t\t// yes, the calls are same, but this way we can avoid type casting\n\t\t\t\t\tconst dispatchers =\n\t\t\t\t\t\tiNode.type === 'entityRealm'\n\t\t\t\t\t\t\t? this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\t\t\t: this.getEventDispatchers(iNode, { type: 'persistError' }, [iNode.getAccessor, options])\n\t\t\t\t\tif (dispatchers === undefined) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const listener of dispatchers ?? []) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst result = listener()\n\t\t\t\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\t\t\t\thandlerPromises.push(result)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\thandlerPromises.push(Promise.resolve(result))\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\thandlerPromises.push(Promise.reject(e))\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// TODO timeout\n\t\t\tconst handlerResults = await Promise.allSettled(handlerPromises)\n\t\t\tthis.handleRejections('persistError', handlerResults)\n\t\t})\n\t}\n\n\tpublic async triggerOnBeforePersist() {\n\t\treturn this.triggerAsyncMutatingEvent('beforePersist', this.asyncBatchUpdatesOptions)\n\t}\n\n\tpublic async triggerOnPersistSuccess(options: PersistSuccessOptions) {\n\t\treturn this.triggerAsyncMutatingEvent('persistSuccess', options)\n\t}\n\n\tpublic getEventListeners<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(state: State, event: { type: EventType; key?: string }): Set<Exclude<EventListenerTypes[1][EventType], undefined>> | undefined {\n\t\tif (!state.eventListeners) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn (state.eventListeners as EventListenersStore<EventType, EventListenerTypes[1]>).get(event) as Set<\n\t\t\tExclude<EventListenerTypes[1][EventType], undefined>\n\t\t>\n\t}\n\n\tpublic getEventDispatchers<\n\t\tState extends StateNode,\n\t\tEventListenerTypes extends\n\t\t\tExclude<State['eventListeners'], undefined> extends EventListenersStore<infer Keys, infer Map> ? [Keys, Map] : never,\n\t\tEventType extends EventListenerTypes[0],\n\t>(\n\t\tstate: State,\n\t\tevent: { type: EventType; key?: string },\n\t\tlistenerArgs: Parameters<Exclude<EventListenerTypes[1][EventType], undefined>>,\n\t): Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>> | undefined {\n\t\tconst eventListeners = this.getEventListeners(state, event)\n\t\tif (eventListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn Array.from(eventListeners.values(), listener => {\n\t\t\treturn () => listener(...listenerArgs)\n\t\t}) as Array<() => ReturnType<Exclude<EventListenerTypes[1][EventType], undefined>>>\n\t}\n\n\tprivate handleRejections(handler: string, promises: PromiseSettledResult<any>[]) {\n\t\tconst rejections = promises.filter((it): it is PromiseRejectedResult => it.status === 'rejected')\n\t\tif (rejections.length === 0) {\n\t\t\treturn\n\t\t}\n\t\trejections.forEach(it => console.error(it.reason))\n\t\tif (import.meta.env.DEV) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`A ${handler} handler returned a promise that rejected. ` +\n\t\t\t\t\t`This is a no-op that will fail silently in production.`,\n\t\t\t)\n\t\t}\n\t}\n\n\n\tprivate validateWithoutChanges(initialCount: number, eventType: string): void {\n\t\tconst changesCountAfter = this.dirtinessTracker.getTotalTouchCount()\n\t\tif (import.meta.env.DEV) {\n\t\t\tif (initialCount !== changesCountAfter) {\n\t\t\t\t// This isn't bulletproof. They could e.g. undo a change and make another one which would\n\t\t\t\t// slip through this detection. But for most cases, it should be good enough and not too expensive.\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t`A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +\n\t\t\t\t\t`To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":["changesCountBefore"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C,GAAG,WAAW,UAAU;AAC5F,QAAA,WAAW,WAAW,GAAG;AAC5B;AAAA,IACD;AACA,eAAW,QAAQ,CAAM,OAAA,QAAQ,MAAM,GAAG,MAAM,CAAC;AACxB;AACxB,YAAM,IAAI;AAAA,QACT,KAAK,OAAO;AAAA,MAAA;AAAA,IAGd;AAAA,EACD;AAAA,EAGQ,uBAAuB,cAAsB,WAAyB;AACvE,UAAA,oBAAoB,KAAK,iBAAiB,mBAAmB;AAC1C;AACxB,UAAI,iBAAiB,mBAAmB;AAGvC,cAAM,IAAI;AAAA,UACT,KAAK,SAAS;AAAA,QAAA;AAAA,MAGhB;AAAA,IACD;AAAA,EACD;AACD;AA9iBC,cADY,cACW,yBAAwB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerComparator.cjs","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":["FieldMarker","PRIMARY_KEY_NAME","TYPENAME_KEY_NAME","LocalizedBindingError","HasOneRelationMarker","HasManyRelationMarker","assertNever"],"mappings":";;;;;;;;AAYO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,kBACb,WACA,UACU;AACN,QAAA,UAAU,oBAAoB,SAAS,iBAAiB;AACpD,aAAA;AAAA,IACR;AACA,WAAO,KAAK,WAAW,UAAU,QAAQ,SAAS,MAAM;AAAA,EACzD;AAAA,EAEA,OAAc,4BACb,WACA,UACC;AACI,SAAA,eAAe,WAAW,QAAQ;AAAA,EACxC;AAAA,EAEA,OAAe,eAAe,WAAwC,UAAuC;AAC5G,eAAW,CAAC,iBAAiB,eAAe,KAAK,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YAAI,2BAA2BA,YAAAA,aAAa;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I,UAAA,2BAA2BF,YAAAA,eAAe,wBAAwBA,yBAAa;AAClF;AAAA,MACD;AACA,UAAI,CAAC,KAAK,WAAW,gBAAgB,QAAQ,aAAa,MAAM,GAAG;AAC3D,eAAA;AAAA,MACR;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA;AAGD;;"}
1
+ {"version":3,"file":"MarkerComparator.cjs","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":["FieldMarker","PRIMARY_KEY_NAME","TYPENAME_KEY_NAME","LocalizedBindingError","HasOneRelationMarker","HasManyRelationMarker","assertNever"],"mappings":";;;;;;;;AAYO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,kBACb,WACA,UACU;AACN,QAAA,UAAU,oBAAoB,SAAS,iBAAiB;AACpD,aAAA;AAAA,IACR;AACA,WAAO,KAAK,WAAW,UAAU,QAAQ,SAAS,MAAM;AAAA,EACzD;AAAA,EAEA,OAAc,4BACb,WACA,UACC;AACI,SAAA,eAAe,WAAW,QAAQ;AAAA,EACxC;AAAA,EAEA,OAAe,eAAe,WAAwC,UAAuC;AAC5G,eAAW,CAAC,iBAAiB,eAAe,KAAK,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YAAI,2BAA2BA,YAAAA,aAAa;AAC3C,cAAI,gBAAgB,cAAcC,aAAAA,oBAAoB,gBAAgB,cAAcC,aAAAA,mBAAmB;AACtG;AAAA,UACD;AACM,gBAAA,IAAIC,sBAAAA,sBAAsB,cAAc,gBAAgB,SAAS,iBAAiB,CAAC,eAAe,CAAC;AAAA,QAC1G;AACI,YAAA,2BAA2BC,qBAAAA,wBAAwB,2BAA2BC,6CAAuB;AACxG,gBAAM,wBAAwB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js","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,kBACb,WACA,UACU;AACN,QAAA,UAAU,oBAAoB,SAAS,iBAAiB;AACpD,aAAA;AAAA,IACR;AACA,WAAO,KAAK,WAAW,UAAU,QAAQ,SAAS,MAAM;AAAA,EACzD;AAAA,EAEA,OAAc,4BACb,WACA,UACC;AACI,SAAA,eAAe,WAAW,QAAQ;AAAA,EACxC;AAAA,EAEA,OAAe,eAAe,WAAwC,UAAuC;AAC5G,eAAW,CAAC,iBAAiB,eAAe,KAAK,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YAAI,2BAA2B,aAAa;AAC3C,cAAI,gBAAgB,cAAc,oBAAoB,gBAAgB,cAAc,mBAAmB;AACtG;AAAA,UACD;AACA,gBAAM,IAAI,sBAAsB,cAAc,gBAAgB,0BAA0B,CAAC,eAAe,CAAC;AAAA,QAC1G;AACI,YAAA,2BAA2B,wBAAwB,2BAA2B,uBAAuB;AACxG,gBAAM,wBAAwB,SAAS,aAAa,IAAI,gBAAgB,WAAW,KAAK;AAExF,cAAI,0BAA0B,QAAW;AACxC,kBAAM,IAAI,sBAAsB,iBAAiB,gBAAgB,WAAW,sBAAsB;AAAA,cACjG;AAAA,YAAA,CACA;AAAA,UACF;AAEA,gBAAM,IAAI;AAAA,YACT,iBAAiB,gBAAgB,WAAW;AAAA,YAE5C,CAAC,eAAe;AAAA,UAAA;AAAA,QAElB;AACA,oBAA2B;AAAA,MAC5B;AACA,UAAI,2BAA2B,aAAa;AAC3C;AAAA,MACD;AACI,UAAA;AACH,YACE,2BAA2B,wBAAwB,wBAAwB,wBAC3E,2BAA2B,yBAAyB,wBAAwB,uBAC5E;AACD,eAAK,eAAe,gBAAgB,QAAQ,aAAa,MAAM;AAAA,QAChE;AAAA,eACQ;AACR,YAAI,aAAa,uBAAuB;AACjC,gBAAA,EAAE,SAAS,eAAe;AAAA,QACjC;AACM,cAAA;AAAA,MACP;AAAA,IACD;AAAA,EACD;AAAA,EAEA,OAAe,WAAW,WAAwC,UAAgD;AACjH,eAAW,CAAC,iBAAiB,eAAe,KAAK,UAAU,SAAS;AACnE,YAAM,eAAe,SAAS,QAAQ,IAAI,eAAe;AAEzD,UAAI,iBAAiB,QAAW;AAC/B,YACC,2BAA2B,gBAC1B,gBAAgB,cAAc,oBAAoB,gBAAgB,cAAc,oBAChF;AACD;AAAA,QACD;AACO,eAAA;AAAA,MACR;AACI,UAAA,2BAA2B,eAAe,wBAAwB,aAAa;AAClF;AAAA,MACD;AACA,UAAI,CAAC,KAAK,WAAW,gBAAgB,QAAQ,aAAa,MAAM,GAAG;AAC3D,eAAA;AAAA,MACR;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA;AAGD;"}
1
+ {"version":3,"file":"MarkerComparator.js","sources":["../../../src/core/MarkerComparator.ts"],"sourcesContent":["import { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { assertNever } from '../utils'\nimport { LocalizedBindingError } from './exceptions'\n\nexport class MarkerComparator {\n\tpublic static isSubTreeSubsetOf(\n\t\tcandidate: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t\tsuperset: EntitySubTreeMarker | EntityListSubTreeMarker,\n\t): boolean {\n\t\tif (candidate.placeholderName !== superset.placeholderName) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.isSubsetOf(candidate.fields, superset.fields)\n\t}\n\n\tpublic static assertEntityMarkersSubsetOf(\n\t\tcandidate: EntityFieldMarkersContainer,\n\t\tsuperset: EntityFieldMarkersContainer,\n\t) {\n\t\tthis.assertSubsetOf(candidate, superset)\n\t}\n\n\tprivate static assertSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer) {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\t\tif (candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tthrow new LocalizedBindingError(`The field '${candidateMarker.fieldName}' is missing.`, [candidateMarker])\n\t\t\t\t}\n\t\t\t\tif (candidateMarker instanceof HasOneRelationMarker || candidateMarker instanceof HasManyRelationMarker) {\n\t\t\t\t\tconst differentPlaceholders = superset.placeholders.get(candidateMarker.parameters.field)\n\n\t\t\t\t\tif (differentPlaceholders === undefined) {\n\t\t\t\t\t\tthrow new LocalizedBindingError(`The relation '${candidateMarker.parameters.field}' is missing.`, [\n\t\t\t\t\t\t\tcandidateMarker,\n\t\t\t\t\t\t])\n\t\t\t\t\t}\n\t\t\t\t\t// TODO be more specific\n\t\t\t\t\tthrow new LocalizedBindingError(\n\t\t\t\t\t\t`The relation '${candidateMarker.parameters.field}' exists but its parameters don't match exactly. ` +\n\t\t\t\t\t\t\t`Check that all relation parameters are the same.`,\n\t\t\t\t\t\t[candidateMarker],\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tassertNever(candidateMarker)\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tif (\n\t\t\t\t\t(candidateMarker instanceof HasOneRelationMarker && fromSuperset instanceof HasOneRelationMarker) ||\n\t\t\t\t\t(candidateMarker instanceof HasManyRelationMarker && fromSuperset instanceof HasManyRelationMarker)\n\t\t\t\t) {\n\t\t\t\t\tthis.assertSubsetOf(candidateMarker.fields, fromSuperset.fields)\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\tif (e instanceof LocalizedBindingError) {\n\t\t\t\t\tthrow e.nestedIn(candidateMarker)\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static isSubsetOf(candidate: EntityFieldMarkersContainer, superset: EntityFieldMarkersContainer): boolean {\n\t\tfor (const [placeholderName, candidateMarker] of candidate.markers) {\n\t\t\tconst fromSuperset = superset.markers.get(placeholderName)\n\n\t\t\tif (fromSuperset === undefined) {\n\t\t\t\tif (\n\t\t\t\t\tcandidateMarker instanceof FieldMarker &&\n\t\t\t\t\t(candidateMarker.fieldName === PRIMARY_KEY_NAME || candidateMarker.fieldName === TYPENAME_KEY_NAME)\n\t\t\t\t) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\treturn false\n\t\t\t}\n\t\t\tif (candidateMarker instanceof FieldMarker || fromSuperset instanceof FieldMarker) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (!this.isSubsetOf(candidateMarker.fields, fromSuperset.fields)) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t}\n\t\treturn true\n\t}\n\n\t//private static assertAreMarkersSubsetOf(): {}\n}\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,iBAAiB;AAAA,EAC7B,OAAc,kBACb,WACA,UACU;AACN,QAAA,UAAU,oBAAoB,SAAS,iBAAiB;AACpD,aAAA;AAAA,IACR;AACA,WAAO,KAAK,WAAW,UAAU,QAAQ,SAAS,MAAM;AAAA,EACzD;AAAA,EAEA,OAAc,4BACb,WACA,UACC;AACI,SAAA,eAAe,WAAW,QAAQ;AAAA,EACxC;AAAA,EAEA,OAAe,eAAe,WAAwC,UAAuC;AAC5G,eAAW,CAAC,iBAA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AAA;AAAA,MACR;AACI,UAAA,2BAA2B,eAAe,wBAAwB,aAAa;AAClF;AAAA,MACD;AACA,UAAI,CAAC,KAAK,WAAW,gBAAgB,QAAQ,aAAa,MAAM,GAAG;AAC3D,eAAA;AAAA,MACR;AAAA,IACD;AACO,WAAA;AAAA,EACR;AAAA;AAGD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerMerger.cjs","sources":["../../../src/core/MarkerMerger.ts"],"sourcesContent":["import { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport type { Environment } from '../dao'\nimport {\n\tEntityFieldMarkers,\n\tEntityFieldMarkersContainer,\n\tEntityFieldPlaceholders,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tMeaningfulMarker,\n\tSubTreeMarkers,\n} from '../markers'\nimport type { Alias, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class MarkerMerger {\n\t// This method assumes their placeholder names are the same\n\tpublic static mergeMarkers(original: MeaningfulMarker, fresh: MeaningfulMarker): MeaningfulMarker {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original instanceof FieldMarker) {\n\t\t\tif (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.mergeFieldMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker || fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.fieldName)\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('Merging fields and sub trees is an undefined operation.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasOneRelationMarker) {\n\t\t\tif (fresh instanceof HasOneRelationMarker) {\n\t\t\t\treturn this.mergeHasOneRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasManyRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasManyRelationMarker) {\n\t\t\tif (fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.mergeHasManyRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof EntitySubTreeMarker) {\n\t\t\tif (fresh instanceof EntitySubTreeMarker) {\n\t\t\t\treturn this.mergeEntitySubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntitySubTreeMarker can only be merged with other entity sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (original instanceof EntityListSubTreeMarker) {\n\t\t\tif (fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\treturn this.mergeEntityListSubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntityListSubTreeMarker can only be merged with other list sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tassertNever(original)\n\t}\n\n\tpublic static mergeMarkerTreeRoots(original: MarkerTreeRoot, fresh: MarkerTreeRoot): MarkerTreeRoot {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new MarkerTreeRoot(\n\t\t\tthis.mergeEntityFields(original.subTrees, fresh.subTrees),\n\t\t\tthis.mergeSubTreePlaceholdersByAliases(original.placeholdersByAliases, fresh.placeholdersByAliases),\n\t\t)\n\t}\n\n\tpublic static mergeSubTreeMarkers(\n\t\toriginal: SubTreeMarkers | undefined,\n\t\tfresh: SubTreeMarkers | undefined,\n\t): SubTreeMarkers | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal = new Map(original)\n\n\t\tfor (const [placeholderName, fromFresh] of fresh) {\n\t\t\tconst fromOriginal = newOriginal.get(placeholderName)\n\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tfromOriginal === undefined\n\t\t\t\t\t? fromFresh\n\t\t\t\t\t: fromOriginal instanceof EntityListSubTreeMarker\n\t\t\t\t\t? MarkerMerger.mergeEntityListSubTreeMarkers(fromOriginal, fromFresh as EntityListSubTreeMarker)\n\t\t\t\t\t: MarkerMerger.mergeEntitySubTreeMarkers(fromOriginal, fromFresh as EntitySubTreeMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeSubTreePlaceholdersByAliases(\n\t\toriginal: Map<Alias, PlaceholderName>,\n\t\tfresh: Map<Alias, PlaceholderName>,\n\t) {\n\t\tconst newOriginalAliases = new Map(original)\n\t\tfor (const [alias, placeholder] of fresh) {\n\t\t\tconst fromOriginal = newOriginalAliases.get(alias)\n\t\t\tif (fromOriginal === undefined) {\n\t\t\t\tnewOriginalAliases.set(alias, placeholder)\n\t\t\t} else if (fromOriginal === placeholder) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(`Illegal subTree alias '${alias}' points to distinct subTrees.`)\n\t\t\t}\n\t\t}\n\t\treturn newOriginalAliases\n\t}\n\n\tpublic static mergeEntityFields(original: SubTreeMarkers, fresh: SubTreeMarkers): SubTreeMarkers\n\tpublic static mergeEntityFields(original: EntityFieldMarkers, fresh: EntityFieldMarkers): EntityFieldMarkers\n\tpublic static mergeEntityFields(\n\t\toriginal: Map<PlaceholderName, MeaningfulMarker>,\n\t\tfresh: Map<PlaceholderName, MeaningfulMarker>,\n\t): Map<PlaceholderName, MeaningfulMarker> {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: Map<PlaceholderName, MeaningfulMarker> = new Map(original)\n\t\tfor (const [placeholderName, freshMarker] of fresh) {\n\t\t\tconst markerFromOriginal = newOriginal.get(placeholderName)\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tmarkerFromOriginal === undefined ? freshMarker : this.mergeMarkers(markerFromOriginal, freshMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldPlaceholders(\n\t\toriginal: EntityFieldPlaceholders,\n\t\tfresh: EntityFieldPlaceholders,\n\t): EntityFieldPlaceholders {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: EntityFieldPlaceholders = new Map(original)\n\t\tfor (const [fieldName, freshPlaceholders] of fresh) {\n\t\t\tconst placeholderFromOriginal = newOriginal.get(fieldName)\n\n\t\t\tif (placeholderFromOriginal === undefined) {\n\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t} else if (placeholderFromOriginal instanceof Set) {\n\t\t\t\tconst combinedSet = new Set(placeholderFromOriginal)\n\t\t\t\tif (freshPlaceholders instanceof Set) {\n\t\t\t\t\tfor (const freshPlaceholder of freshPlaceholders) {\n\t\t\t\t\t\tcombinedSet.add(freshPlaceholder)\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tcombinedSet.add(freshPlaceholders)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t} else if (typeof placeholderFromOriginal === 'string') {\n\t\t\t\tif (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tif (placeholderFromOriginal === freshPlaceholders) {\n\t\t\t\t\t\t// Do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewOriginal.set(fieldName, new Set([placeholderFromOriginal, freshPlaceholders]))\n\t\t\t\t\t}\n\t\t\t\t} else if (freshPlaceholders instanceof Set) {\n\t\t\t\t\tif (freshPlaceholders.has(placeholderFromOriginal)) {\n\t\t\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst combinedSet = new Set(freshPlaceholders)\n\t\t\t\t\t\tcombinedSet.add(placeholderFromOriginal)\n\t\t\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(placeholderFromOriginal)\n\t\t\t}\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldsContainers(\n\t\toriginal: EntityFieldMarkersContainer,\n\t\tfresh: EntityFieldMarkersContainer,\n\t): EntityFieldMarkersContainer {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityFieldMarkersContainer(\n\t\t\toriginal.hasAtLeastOneBearingField || fresh.hasAtLeastOneBearingField,\n\t\t\tthis.mergeEntityFields(original.markers, fresh.markers),\n\t\t\tthis.mergeEntityFieldPlaceholders(original.placeholders, fresh.placeholders),\n\t\t)\n\t}\n\n\tpublic static mergeHasOneRelationMarkers(original: HasOneRelationMarker, fresh: HasOneRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasOneRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasOneRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeHasManyRelationMarkers(original: HasManyRelationMarker, fresh: HasManyRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasManyRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasManyRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntitySubTreeMarkers(original: EntitySubTreeMarker, fresh: EntitySubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntitySubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntitySubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntityListSubTreeMarkers(original: EntityListSubTreeMarker, fresh: EntityListSubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityListSubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntityListSubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeFieldMarkers(original: FieldMarker, fresh: FieldMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original.defaultValue !== undefined && fresh.defaultValue !== undefined && original.defaultValue !== fresh.defaultValue) {\n\t\t\tthrow new BindingError(`MarkerTreeGenerator merging: multiple fields \"${original.fieldName}\" with different defaultValue found: ${JSON.stringify([original.defaultValue, fresh.defaultValue])}, `)\n\t\t}\n\t\treturn new FieldMarker(\n\t\t\toriginal.fieldName,\n\t\t\toriginal.defaultValue ?? fresh.defaultValue,\n\t\t\toriginal.isNonbearing && fresh.isNonbearing,\n\t\t)\n\t}\n\n\tpublic static mergeInSystemFields(original: EntityFieldMarkersContainer | undefined): EntityFieldMarkersContainer {\n\t\tconst primaryKey = new FieldMarker(PRIMARY_KEY_NAME, undefined, true)\n\t\t// We could potentially share this instance for all fields. Maybe sometime later.\n\t\tconst freshFields = new EntityFieldMarkersContainer(\n\t\t\tfalse,\n\t\t\tnew Map([[primaryKey.placeholderName, primaryKey]]),\n\t\t\tnew Map([[PRIMARY_KEY_NAME, primaryKey.placeholderName]]),\n\t\t)\n\t\treturn original ? this.mergeEntityFieldsContainers(original, freshFields) : freshFields\n\t}\n\n\tpublic static mergeEnvironments(original: Environment, fresh: Environment): Environment {\n\t\treturn original.merge(fresh)\n\t}\n\n\tprivate static rejectRelationScalarCombo(fieldName: FieldName): never {\n\t\tthrow new BindingError(`Cannot combine a relation with a scalar field '${fieldName}'.`)\n\t}\n}\n"],"names":["FieldMarker","HasOneRelationMarker","HasManyRelationMarker","EntitySubTreeMarker","EntityListSubTreeMarker","BindingError","assertNever","MarkerTreeRoot","EntityFieldMarkersContainer","TreeParameterMerger","PRIMARY_KEY_NAME"],"mappings":";;;;;;;;;;;;;AAoBO,MAAM,aAAa;AAAA;AAAA,EAEzB,OAAc,aAAa,UAA4B,OAA2C;AACjG,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,oBAAoBA,YAAAA,aAAa;AACpC,UAAI,iBAAiBA,YAAAA,aAAa;AAC1B,eAAA,KAAK,kBAAkB,UAAU,KAAK;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IAAI,CAAC,CAACE,aAAAA,kBAAkB,WAAW,eAAe,CAAC,CAAC;AAAA,IAAA;AAEzD,WAAO,WAAW,KAAK,4BAA4B,UAAU,WAAW,IAAI;AAAA,EAC7E;AAAA,EAEA,OAAc,kBAAkB,UAAuB,OAAiC;AAChF,WAAA,SAAS,MAAM,KAAK;AAAA,EAC5B;AAAA,EAEA,OAAe,0BAA0B,WAA6B;AAC/D,UAAA,IAAIL,aAAa,aAAA,kDAAkD,aAAa;AAAA,EACvF;AACD;;"}
1
+ {"version":3,"file":"MarkerMerger.cjs","sources":["../../../src/core/MarkerMerger.ts"],"sourcesContent":["import { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport type { Environment } from '../dao'\nimport {\n\tEntityFieldMarkers,\n\tEntityFieldMarkersContainer,\n\tEntityFieldPlaceholders,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tMeaningfulMarker,\n\tSubTreeMarkers,\n} from '../markers'\nimport type { Alias, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class MarkerMerger {\n\t// This method assumes their placeholder names are the same\n\tpublic static mergeMarkers(original: MeaningfulMarker, fresh: MeaningfulMarker): MeaningfulMarker {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original instanceof FieldMarker) {\n\t\t\tif (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.mergeFieldMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker || fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.fieldName)\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('Merging fields and sub trees is an undefined operation.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasOneRelationMarker) {\n\t\t\tif (fresh instanceof HasOneRelationMarker) {\n\t\t\t\treturn this.mergeHasOneRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasManyRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasManyRelationMarker) {\n\t\t\tif (fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.mergeHasManyRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof EntitySubTreeMarker) {\n\t\t\tif (fresh instanceof EntitySubTreeMarker) {\n\t\t\t\treturn this.mergeEntitySubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntitySubTreeMarker can only be merged with other entity sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (original instanceof EntityListSubTreeMarker) {\n\t\t\tif (fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\treturn this.mergeEntityListSubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntityListSubTreeMarker can only be merged with other list sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tassertNever(original)\n\t}\n\n\tpublic static mergeMarkerTreeRoots(original: MarkerTreeRoot, fresh: MarkerTreeRoot): MarkerTreeRoot {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new MarkerTreeRoot(\n\t\t\tthis.mergeEntityFields(original.subTrees, fresh.subTrees),\n\t\t\tthis.mergeSubTreePlaceholdersByAliases(original.placeholdersByAliases, fresh.placeholdersByAliases),\n\t\t)\n\t}\n\n\tpublic static mergeSubTreeMarkers(\n\t\toriginal: SubTreeMarkers | undefined,\n\t\tfresh: SubTreeMarkers | undefined,\n\t): SubTreeMarkers | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal = new Map(original)\n\n\t\tfor (const [placeholderName, fromFresh] of fresh) {\n\t\t\tconst fromOriginal = newOriginal.get(placeholderName)\n\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tfromOriginal === undefined\n\t\t\t\t\t? fromFresh\n\t\t\t\t\t: fromOriginal instanceof EntityListSubTreeMarker\n\t\t\t\t\t? MarkerMerger.mergeEntityListSubTreeMarkers(fromOriginal, fromFresh as EntityListSubTreeMarker)\n\t\t\t\t\t: MarkerMerger.mergeEntitySubTreeMarkers(fromOriginal, fromFresh as EntitySubTreeMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeSubTreePlaceholdersByAliases(\n\t\toriginal: Map<Alias, PlaceholderName>,\n\t\tfresh: Map<Alias, PlaceholderName>,\n\t) {\n\t\tconst newOriginalAliases = new Map(original)\n\t\tfor (const [alias, placeholder] of fresh) {\n\t\t\tconst fromOriginal = newOriginalAliases.get(alias)\n\t\t\tif (fromOriginal === undefined) {\n\t\t\t\tnewOriginalAliases.set(alias, placeholder)\n\t\t\t} else if (fromOriginal === placeholder) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(`Illegal subTree alias '${alias}' points to distinct subTrees.`)\n\t\t\t}\n\t\t}\n\t\treturn newOriginalAliases\n\t}\n\n\tpublic static mergeEntityFields(original: SubTreeMarkers, fresh: SubTreeMarkers): SubTreeMarkers\n\tpublic static mergeEntityFields(original: EntityFieldMarkers, fresh: EntityFieldMarkers): EntityFieldMarkers\n\tpublic static mergeEntityFields(\n\t\toriginal: Map<PlaceholderName, MeaningfulMarker>,\n\t\tfresh: Map<PlaceholderName, MeaningfulMarker>,\n\t): Map<PlaceholderName, MeaningfulMarker> {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: Map<PlaceholderName, MeaningfulMarker> = new Map(original)\n\t\tfor (const [placeholderName, freshMarker] of fresh) {\n\t\t\tconst markerFromOriginal = newOriginal.get(placeholderName)\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tmarkerFromOriginal === undefined ? freshMarker : this.mergeMarkers(markerFromOriginal, freshMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldPlaceholders(\n\t\toriginal: EntityFieldPlaceholders,\n\t\tfresh: EntityFieldPlaceholders,\n\t): EntityFieldPlaceholders {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: EntityFieldPlaceholders = new Map(original)\n\t\tfor (const [fieldName, freshPlaceholders] of fresh) {\n\t\t\tconst placeholderFromOriginal = newOriginal.get(fieldName)\n\n\t\t\tif (placeholderFromOriginal === undefined) {\n\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t} else if (placeholderFromOriginal instanceof Set) {\n\t\t\t\tconst combinedSet = new Set(placeholderFromOriginal)\n\t\t\t\tif (freshPlaceholders instanceof Set) {\n\t\t\t\t\tfor (const freshPlaceholder of freshPlaceholders) {\n\t\t\t\t\t\tcombinedSet.add(freshPlaceholder)\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tcombinedSet.add(freshPlaceholders)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t} else if (typeof placeholderFromOriginal === 'string') {\n\t\t\t\tif (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tif (placeholderFromOriginal === freshPlaceholders) {\n\t\t\t\t\t\t// Do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewOriginal.set(fieldName, new Set([placeholderFromOriginal, freshPlaceholders]))\n\t\t\t\t\t}\n\t\t\t\t} else if (freshPlaceholders instanceof Set) {\n\t\t\t\t\tif (freshPlaceholders.has(placeholderFromOriginal)) {\n\t\t\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst combinedSet = new Set(freshPlaceholders)\n\t\t\t\t\t\tcombinedSet.add(placeholderFromOriginal)\n\t\t\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(placeholderFromOriginal)\n\t\t\t}\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldsContainers(\n\t\toriginal: EntityFieldMarkersContainer,\n\t\tfresh: EntityFieldMarkersContainer,\n\t): EntityFieldMarkersContainer {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityFieldMarkersContainer(\n\t\t\toriginal.hasAtLeastOneBearingField || fresh.hasAtLeastOneBearingField,\n\t\t\tthis.mergeEntityFields(original.markers, fresh.markers),\n\t\t\tthis.mergeEntityFieldPlaceholders(original.placeholders, fresh.placeholders),\n\t\t)\n\t}\n\n\tpublic static mergeHasOneRelationMarkers(original: HasOneRelationMarker, fresh: HasOneRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasOneRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasOneRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeHasManyRelationMarkers(original: HasManyRelationMarker, fresh: HasManyRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasManyRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasManyRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntitySubTreeMarkers(original: EntitySubTreeMarker, fresh: EntitySubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntitySubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntitySubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntityListSubTreeMarkers(original: EntityListSubTreeMarker, fresh: EntityListSubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityListSubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntityListSubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeFieldMarkers(original: FieldMarker, fresh: FieldMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original.defaultValue !== undefined && fresh.defaultValue !== undefined && original.defaultValue !== fresh.defaultValue) {\n\t\t\tthrow new BindingError(`MarkerTreeGenerator merging: multiple fields \"${original.fieldName}\" with different defaultValue found: ${JSON.stringify([original.defaultValue, fresh.defaultValue])}, `)\n\t\t}\n\t\treturn new FieldMarker(\n\t\t\toriginal.fieldName,\n\t\t\toriginal.defaultValue ?? fresh.defaultValue,\n\t\t\toriginal.isNonbearing && fresh.isNonbearing,\n\t\t)\n\t}\n\n\tpublic static mergeInSystemFields(original: EntityFieldMarkersContainer | undefined): EntityFieldMarkersContainer {\n\t\tconst primaryKey = new FieldMarker(PRIMARY_KEY_NAME, undefined, true)\n\t\t// We could potentially share this instance for all fields. Maybe sometime later.\n\t\tconst freshFields = new EntityFieldMarkersContainer(\n\t\t\tfalse,\n\t\t\tnew Map([[primaryKey.placeholderName, primaryKey]]),\n\t\t\tnew Map([[PRIMARY_KEY_NAME, primaryKey.placeholderName]]),\n\t\t)\n\t\treturn original ? this.mergeEntityFieldsContainers(original, freshFields) : freshFields\n\t}\n\n\tpublic static mergeEnvironments(original: Environment, fresh: Environment): Environment {\n\t\treturn original.merge(fresh)\n\t}\n\n\tprivate static rejectRelationScalarCombo(fieldName: FieldName): never {\n\t\tthrow new BindingError(`Cannot combine a relation with a scalar field '${fieldName}'.`)\n\t}\n}\n"],"names":["FieldMarker","HasOneRelationMarker","HasManyRelationMarker","EntitySubTreeMarker","EntityListSubTreeMarker","BindingError","assertNever","MarkerTreeRoot","EntityFieldMarkersContainer","TreeParameterMerger","PRIMARY_KEY_NAME"],"mappings":";;;;;;;;;;;;;AAoBO,MAAM,aAAa;AAAA;AAAA,EAEzB,OAAc,aAAa,UAA4B,OAA2C;AACjG,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QA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AAc,IAAIF,4BAAA;AAAA,MACvB;AAAA,MACA,oBAAI,IAAI,CAAC,CAAC,WAAW,iBAAiB,UAAU,CAAC,CAAC;AAAA,MAClD,oBAAI,IAAI,CAAC,CAACE,aAAAA,kBAAkB,WAAW,eAAe,CAAC,CAAC;AAAA,IAAA;AAEzD,WAAO,WAAW,KAAK,4BAA4B,UAAU,WAAW,IAAI;AAAA,EAC7E;AAAA,EAEA,OAAc,kBAAkB,UAAuB,OAAiC;AAChF,WAAA,SAAS,MAAM,KAAK;AAAA,EAC5B;AAAA,EAEA,OAAe,0BAA0B,WAA6B;AACrE,UAAM,IAAIL,aAAA,aAAa,kDAAkD,SAAS,IAAI;AAAA,EACvF;AACD;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MarkerMerger.js","sources":["../../../src/core/MarkerMerger.ts"],"sourcesContent":["import { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport type { Environment } from '../dao'\nimport {\n\tEntityFieldMarkers,\n\tEntityFieldMarkersContainer,\n\tEntityFieldPlaceholders,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tMeaningfulMarker,\n\tSubTreeMarkers,\n} from '../markers'\nimport type { Alias, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class MarkerMerger {\n\t// This method assumes their placeholder names are the same\n\tpublic static mergeMarkers(original: MeaningfulMarker, fresh: MeaningfulMarker): MeaningfulMarker {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original instanceof FieldMarker) {\n\t\t\tif (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.mergeFieldMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker || fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.fieldName)\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('Merging fields and sub trees is an undefined operation.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasOneRelationMarker) {\n\t\t\tif (fresh instanceof HasOneRelationMarker) {\n\t\t\t\treturn this.mergeHasOneRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasManyRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasManyRelationMarker) {\n\t\t\tif (fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.mergeHasManyRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof EntitySubTreeMarker) {\n\t\t\tif (fresh instanceof EntitySubTreeMarker) {\n\t\t\t\treturn this.mergeEntitySubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntitySubTreeMarker can only be merged with other entity sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (original instanceof EntityListSubTreeMarker) {\n\t\t\tif (fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\treturn this.mergeEntityListSubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntityListSubTreeMarker can only be merged with other list sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tassertNever(original)\n\t}\n\n\tpublic static mergeMarkerTreeRoots(original: MarkerTreeRoot, fresh: MarkerTreeRoot): MarkerTreeRoot {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new MarkerTreeRoot(\n\t\t\tthis.mergeEntityFields(original.subTrees, fresh.subTrees),\n\t\t\tthis.mergeSubTreePlaceholdersByAliases(original.placeholdersByAliases, fresh.placeholdersByAliases),\n\t\t)\n\t}\n\n\tpublic static mergeSubTreeMarkers(\n\t\toriginal: SubTreeMarkers | undefined,\n\t\tfresh: SubTreeMarkers | undefined,\n\t): SubTreeMarkers | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal = new Map(original)\n\n\t\tfor (const [placeholderName, fromFresh] of fresh) {\n\t\t\tconst fromOriginal = newOriginal.get(placeholderName)\n\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tfromOriginal === undefined\n\t\t\t\t\t? fromFresh\n\t\t\t\t\t: fromOriginal instanceof EntityListSubTreeMarker\n\t\t\t\t\t? MarkerMerger.mergeEntityListSubTreeMarkers(fromOriginal, fromFresh as EntityListSubTreeMarker)\n\t\t\t\t\t: MarkerMerger.mergeEntitySubTreeMarkers(fromOriginal, fromFresh as EntitySubTreeMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeSubTreePlaceholdersByAliases(\n\t\toriginal: Map<Alias, PlaceholderName>,\n\t\tfresh: Map<Alias, PlaceholderName>,\n\t) {\n\t\tconst newOriginalAliases = new Map(original)\n\t\tfor (const [alias, placeholder] of fresh) {\n\t\t\tconst fromOriginal = newOriginalAliases.get(alias)\n\t\t\tif (fromOriginal === undefined) {\n\t\t\t\tnewOriginalAliases.set(alias, placeholder)\n\t\t\t} else if (fromOriginal === placeholder) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(`Illegal subTree alias '${alias}' points to distinct subTrees.`)\n\t\t\t}\n\t\t}\n\t\treturn newOriginalAliases\n\t}\n\n\tpublic static mergeEntityFields(original: SubTreeMarkers, fresh: SubTreeMarkers): SubTreeMarkers\n\tpublic static mergeEntityFields(original: EntityFieldMarkers, fresh: EntityFieldMarkers): EntityFieldMarkers\n\tpublic static mergeEntityFields(\n\t\toriginal: Map<PlaceholderName, MeaningfulMarker>,\n\t\tfresh: Map<PlaceholderName, MeaningfulMarker>,\n\t): Map<PlaceholderName, MeaningfulMarker> {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: Map<PlaceholderName, MeaningfulMarker> = new Map(original)\n\t\tfor (const [placeholderName, freshMarker] of fresh) {\n\t\t\tconst markerFromOriginal = newOriginal.get(placeholderName)\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tmarkerFromOriginal === undefined ? freshMarker : this.mergeMarkers(markerFromOriginal, freshMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldPlaceholders(\n\t\toriginal: EntityFieldPlaceholders,\n\t\tfresh: EntityFieldPlaceholders,\n\t): EntityFieldPlaceholders {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: EntityFieldPlaceholders = new Map(original)\n\t\tfor (const [fieldName, freshPlaceholders] of fresh) {\n\t\t\tconst placeholderFromOriginal = newOriginal.get(fieldName)\n\n\t\t\tif (placeholderFromOriginal === undefined) {\n\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t} else if (placeholderFromOriginal instanceof Set) {\n\t\t\t\tconst combinedSet = new Set(placeholderFromOriginal)\n\t\t\t\tif (freshPlaceholders instanceof Set) {\n\t\t\t\t\tfor (const freshPlaceholder of freshPlaceholders) {\n\t\t\t\t\t\tcombinedSet.add(freshPlaceholder)\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tcombinedSet.add(freshPlaceholders)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t} else if (typeof placeholderFromOriginal === 'string') {\n\t\t\t\tif (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tif (placeholderFromOriginal === freshPlaceholders) {\n\t\t\t\t\t\t// Do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewOriginal.set(fieldName, new Set([placeholderFromOriginal, freshPlaceholders]))\n\t\t\t\t\t}\n\t\t\t\t} else if (freshPlaceholders instanceof Set) {\n\t\t\t\t\tif (freshPlaceholders.has(placeholderFromOriginal)) {\n\t\t\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst combinedSet = new Set(freshPlaceholders)\n\t\t\t\t\t\tcombinedSet.add(placeholderFromOriginal)\n\t\t\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(placeholderFromOriginal)\n\t\t\t}\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldsContainers(\n\t\toriginal: EntityFieldMarkersContainer,\n\t\tfresh: EntityFieldMarkersContainer,\n\t): EntityFieldMarkersContainer {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityFieldMarkersContainer(\n\t\t\toriginal.hasAtLeastOneBearingField || fresh.hasAtLeastOneBearingField,\n\t\t\tthis.mergeEntityFields(original.markers, fresh.markers),\n\t\t\tthis.mergeEntityFieldPlaceholders(original.placeholders, fresh.placeholders),\n\t\t)\n\t}\n\n\tpublic static mergeHasOneRelationMarkers(original: HasOneRelationMarker, fresh: HasOneRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasOneRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasOneRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeHasManyRelationMarkers(original: HasManyRelationMarker, fresh: HasManyRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasManyRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasManyRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntitySubTreeMarkers(original: EntitySubTreeMarker, fresh: EntitySubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntitySubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntitySubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntityListSubTreeMarkers(original: EntityListSubTreeMarker, fresh: EntityListSubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityListSubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntityListSubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeFieldMarkers(original: FieldMarker, fresh: FieldMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original.defaultValue !== undefined && fresh.defaultValue !== undefined && original.defaultValue !== fresh.defaultValue) {\n\t\t\tthrow new BindingError(`MarkerTreeGenerator merging: multiple fields \"${original.fieldName}\" with different defaultValue found: ${JSON.stringify([original.defaultValue, fresh.defaultValue])}, `)\n\t\t}\n\t\treturn new FieldMarker(\n\t\t\toriginal.fieldName,\n\t\t\toriginal.defaultValue ?? fresh.defaultValue,\n\t\t\toriginal.isNonbearing && fresh.isNonbearing,\n\t\t)\n\t}\n\n\tpublic static mergeInSystemFields(original: EntityFieldMarkersContainer | undefined): EntityFieldMarkersContainer {\n\t\tconst primaryKey = new FieldMarker(PRIMARY_KEY_NAME, undefined, true)\n\t\t// We could potentially share this instance for all fields. Maybe sometime later.\n\t\tconst freshFields = new EntityFieldMarkersContainer(\n\t\t\tfalse,\n\t\t\tnew Map([[primaryKey.placeholderName, primaryKey]]),\n\t\t\tnew Map([[PRIMARY_KEY_NAME, primaryKey.placeholderName]]),\n\t\t)\n\t\treturn original ? this.mergeEntityFieldsContainers(original, freshFields) : freshFields\n\t}\n\n\tpublic static mergeEnvironments(original: Environment, fresh: Environment): Environment {\n\t\treturn original.merge(fresh)\n\t}\n\n\tprivate static rejectRelationScalarCombo(fieldName: FieldName): never {\n\t\tthrow new BindingError(`Cannot combine a relation with a scalar field '${fieldName}'.`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAoBO,MAAM,aAAa;AAAA;AAAA,EAEzB,OAAc,aAAa,UAA4B,OAA2C;AACjG,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,o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kDAAkD,aAAa;AAAA,EACvF;AACD;"}
1
+ {"version":3,"file":"MarkerMerger.js","sources":["../../../src/core/MarkerMerger.ts"],"sourcesContent":["import { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME } from '../bindingTypes'\nimport type { Environment } from '../dao'\nimport {\n\tEntityFieldMarkers,\n\tEntityFieldMarkersContainer,\n\tEntityFieldPlaceholders,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tMeaningfulMarker,\n\tSubTreeMarkers,\n} from '../markers'\nimport type { Alias, FieldName, PlaceholderName } from '../treeParameters'\nimport { assertNever } from '../utils'\nimport { TreeParameterMerger } from './TreeParameterMerger'\n\nexport class MarkerMerger {\n\t// This method assumes their placeholder names are the same\n\tpublic static mergeMarkers(original: MeaningfulMarker, fresh: MeaningfulMarker): MeaningfulMarker {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original instanceof FieldMarker) {\n\t\t\tif (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.mergeFieldMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker || fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.fieldName)\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('Merging fields and sub trees is an undefined operation.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasOneRelationMarker) {\n\t\t\tif (fresh instanceof HasOneRelationMarker) {\n\t\t\t\treturn this.mergeHasOneRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasManyRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof HasManyRelationMarker) {\n\t\t\tif (fresh instanceof HasManyRelationMarker) {\n\t\t\t\treturn this.mergeHasManyRelationMarkers(original, fresh)\n\t\t\t} else if (fresh instanceof FieldMarker) {\n\t\t\t\treturn this.rejectRelationScalarCombo(original.parameters.field)\n\t\t\t} else if (fresh instanceof HasOneRelationMarker) {\n\t\t\t\tthrow new BindingError() // TODO not implemented\n\t\t\t} else if (fresh instanceof EntitySubTreeMarker || fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\tthrow new BindingError('MarkerTreeGenerator merging: SubTreeMarkers can only be merged with other sub trees.')\n\t\t\t}\n\t\t\tassertNever(fresh)\n\t\t} else if (original instanceof EntitySubTreeMarker) {\n\t\t\tif (fresh instanceof EntitySubTreeMarker) {\n\t\t\t\treturn this.mergeEntitySubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntitySubTreeMarker can only be merged with other entity sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t} else if (original instanceof EntityListSubTreeMarker) {\n\t\t\tif (fresh instanceof EntityListSubTreeMarker) {\n\t\t\t\treturn this.mergeEntityListSubTreeMarkers(original, fresh)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(\n\t\t\t\t\t'MarkerTreeGenerator merging: EntityListSubTreeMarker can only be merged with other list sub trees.',\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\t\tassertNever(original)\n\t}\n\n\tpublic static mergeMarkerTreeRoots(original: MarkerTreeRoot, fresh: MarkerTreeRoot): MarkerTreeRoot {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new MarkerTreeRoot(\n\t\t\tthis.mergeEntityFields(original.subTrees, fresh.subTrees),\n\t\t\tthis.mergeSubTreePlaceholdersByAliases(original.placeholdersByAliases, fresh.placeholdersByAliases),\n\t\t)\n\t}\n\n\tpublic static mergeSubTreeMarkers(\n\t\toriginal: SubTreeMarkers | undefined,\n\t\tfresh: SubTreeMarkers | undefined,\n\t): SubTreeMarkers | undefined {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original === undefined) {\n\t\t\treturn fresh\n\t\t}\n\t\tif (fresh === undefined) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal = new Map(original)\n\n\t\tfor (const [placeholderName, fromFresh] of fresh) {\n\t\t\tconst fromOriginal = newOriginal.get(placeholderName)\n\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tfromOriginal === undefined\n\t\t\t\t\t? fromFresh\n\t\t\t\t\t: fromOriginal instanceof EntityListSubTreeMarker\n\t\t\t\t\t? MarkerMerger.mergeEntityListSubTreeMarkers(fromOriginal, fromFresh as EntityListSubTreeMarker)\n\t\t\t\t\t: MarkerMerger.mergeEntitySubTreeMarkers(fromOriginal, fromFresh as EntitySubTreeMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeSubTreePlaceholdersByAliases(\n\t\toriginal: Map<Alias, PlaceholderName>,\n\t\tfresh: Map<Alias, PlaceholderName>,\n\t) {\n\t\tconst newOriginalAliases = new Map(original)\n\t\tfor (const [alias, placeholder] of fresh) {\n\t\t\tconst fromOriginal = newOriginalAliases.get(alias)\n\t\t\tif (fromOriginal === undefined) {\n\t\t\t\tnewOriginalAliases.set(alias, placeholder)\n\t\t\t} else if (fromOriginal === placeholder) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\tthrow new BindingError(`Illegal subTree alias '${alias}' points to distinct subTrees.`)\n\t\t\t}\n\t\t}\n\t\treturn newOriginalAliases\n\t}\n\n\tpublic static mergeEntityFields(original: SubTreeMarkers, fresh: SubTreeMarkers): SubTreeMarkers\n\tpublic static mergeEntityFields(original: EntityFieldMarkers, fresh: EntityFieldMarkers): EntityFieldMarkers\n\tpublic static mergeEntityFields(\n\t\toriginal: Map<PlaceholderName, MeaningfulMarker>,\n\t\tfresh: Map<PlaceholderName, MeaningfulMarker>,\n\t): Map<PlaceholderName, MeaningfulMarker> {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: Map<PlaceholderName, MeaningfulMarker> = new Map(original)\n\t\tfor (const [placeholderName, freshMarker] of fresh) {\n\t\t\tconst markerFromOriginal = newOriginal.get(placeholderName)\n\t\t\tnewOriginal.set(\n\t\t\t\tplaceholderName,\n\t\t\t\tmarkerFromOriginal === undefined ? freshMarker : this.mergeMarkers(markerFromOriginal, freshMarker),\n\t\t\t)\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldPlaceholders(\n\t\toriginal: EntityFieldPlaceholders,\n\t\tfresh: EntityFieldPlaceholders,\n\t): EntityFieldPlaceholders {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tconst newOriginal: EntityFieldPlaceholders = new Map(original)\n\t\tfor (const [fieldName, freshPlaceholders] of fresh) {\n\t\t\tconst placeholderFromOriginal = newOriginal.get(fieldName)\n\n\t\t\tif (placeholderFromOriginal === undefined) {\n\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t} else if (placeholderFromOriginal instanceof Set) {\n\t\t\t\tconst combinedSet = new Set(placeholderFromOriginal)\n\t\t\t\tif (freshPlaceholders instanceof Set) {\n\t\t\t\t\tfor (const freshPlaceholder of freshPlaceholders) {\n\t\t\t\t\t\tcombinedSet.add(freshPlaceholder)\n\t\t\t\t\t}\n\t\t\t\t} else if (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tcombinedSet.add(freshPlaceholders)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t} else if (typeof placeholderFromOriginal === 'string') {\n\t\t\t\tif (typeof freshPlaceholders === 'string') {\n\t\t\t\t\tif (placeholderFromOriginal === freshPlaceholders) {\n\t\t\t\t\t\t// Do nothing\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnewOriginal.set(fieldName, new Set([placeholderFromOriginal, freshPlaceholders]))\n\t\t\t\t\t}\n\t\t\t\t} else if (freshPlaceholders instanceof Set) {\n\t\t\t\t\tif (freshPlaceholders.has(placeholderFromOriginal)) {\n\t\t\t\t\t\tnewOriginal.set(fieldName, freshPlaceholders)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst combinedSet = new Set(freshPlaceholders)\n\t\t\t\t\t\tcombinedSet.add(placeholderFromOriginal)\n\t\t\t\t\t\tnewOriginal.set(fieldName, combinedSet)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(freshPlaceholders)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tassertNever(placeholderFromOriginal)\n\t\t\t}\n\t\t}\n\t\treturn newOriginal\n\t}\n\n\tpublic static mergeEntityFieldsContainers(\n\t\toriginal: EntityFieldMarkersContainer,\n\t\tfresh: EntityFieldMarkersContainer,\n\t): EntityFieldMarkersContainer {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityFieldMarkersContainer(\n\t\t\toriginal.hasAtLeastOneBearingField || fresh.hasAtLeastOneBearingField,\n\t\t\tthis.mergeEntityFields(original.markers, fresh.markers),\n\t\t\tthis.mergeEntityFieldPlaceholders(original.placeholders, fresh.placeholders),\n\t\t)\n\t}\n\n\tpublic static mergeHasOneRelationMarkers(original: HasOneRelationMarker, fresh: HasOneRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasOneRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasOneRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeHasManyRelationMarkers(original: HasManyRelationMarker, fresh: HasManyRelationMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new HasManyRelationMarker(\n\t\t\tTreeParameterMerger.mergeHasManyRelationsWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntitySubTreeMarkers(original: EntitySubTreeMarker, fresh: EntitySubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntitySubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntitySubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeEntityListSubTreeMarkers(original: EntityListSubTreeMarker, fresh: EntityListSubTreeMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\treturn new EntityListSubTreeMarker(\n\t\t\tTreeParameterMerger.mergeEntityListSubTreeParametersWithSamePlaceholders(original.parameters, fresh.parameters),\n\t\t\tthis.mergeEntityFieldsContainers(original.fields, fresh.fields),\n\t\t\tthis.mergeEnvironments(original.environment, fresh.environment),\n\t\t)\n\t}\n\n\tpublic static mergeFieldMarkers(original: FieldMarker, fresh: FieldMarker) {\n\t\tif (original === fresh) {\n\t\t\treturn original\n\t\t}\n\t\tif (original.defaultValue !== undefined && fresh.defaultValue !== undefined && original.defaultValue !== fresh.defaultValue) {\n\t\t\tthrow new BindingError(`MarkerTreeGenerator merging: multiple fields \"${original.fieldName}\" with different defaultValue found: ${JSON.stringify([original.defaultValue, fresh.defaultValue])}, `)\n\t\t}\n\t\treturn new FieldMarker(\n\t\t\toriginal.fieldName,\n\t\t\toriginal.defaultValue ?? fresh.defaultValue,\n\t\t\toriginal.isNonbearing && fresh.isNonbearing,\n\t\t)\n\t}\n\n\tpublic static mergeInSystemFields(original: EntityFieldMarkersContainer | undefined): EntityFieldMarkersContainer {\n\t\tconst primaryKey = new FieldMarker(PRIMARY_KEY_NAME, undefined, true)\n\t\t// We could potentially share this instance for all fields. Maybe sometime later.\n\t\tconst freshFields = new EntityFieldMarkersContainer(\n\t\t\tfalse,\n\t\t\tnew Map([[primaryKey.placeholderName, primaryKey]]),\n\t\t\tnew Map([[PRIMARY_KEY_NAME, primaryKey.placeholderName]]),\n\t\t)\n\t\treturn original ? this.mergeEntityFieldsContainers(original, freshFields) : freshFields\n\t}\n\n\tpublic static mergeEnvironments(original: Environment, fresh: Environment): Environment {\n\t\treturn original.merge(fresh)\n\t}\n\n\tprivate static rejectRelationScalarCombo(fieldName: FieldName): never {\n\t\tthrow new BindingError(`Cannot combine a relation with a scalar field '${fieldName}'.`)\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAoBO,MAAM,aAAa;AAAA;AAAA,EAEzB,OAAc,aAAa,UAA4B,OAA2C;AACjG,QAAI,aAAa,OAAO;AAChB,aAAA;AAAA,IACR;AACA,QAAI,oBAAoB,aAAa;AACpC,UAAI,iBAAiB,aAAa;AAC1B,eAAA,KAAK,kBAAkB,UAAU,KAAK;AAAA,MACnC,WAAA,iBAAiB,wBAAwB,iBAAiB,uBAAuB;AACpF,eAAA,KAAK,0BAA0B,SAAS,SAAS;AAAA,MAC9C,WAAA,iBAAiB,uBAAuB,iBAAiB,yBAAyB;AACtF,cAAA,IAAI,aAAa,yDAAyD;AAAA,MACjF;AACA,kBAAiB;AAAA,IAAA,WACP,oBAAoB,sBAAsB;AACpD,UAAI,iBAAiB,sBAAsB;AACnC,eAAA,KAAK,2BAA2B,UAAU,KAAK;AAAA,MAAA,WAC5C,iBAAiB,aAAa;AACxC,eA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,aAAA;AAAA,IACR;AACI,QAAA,SAAS,iBAAiB,UAAa,MAAM,iBAAiB,UAAa,SAAS,iBAAiB,MAAM,cAAc;AAC5H,YAAM,IAAI,aAAa,iDAAiD,SAAS,SAAS,wCAAwC,KAAK,UAAU,CAAC,SAAS,cAAc,MAAM,YAAY,CAAC,CAAC,IAAI;AAAA,IAClM;AACA,WAAO,IAAI;AAAA,MACV,SAAS;AAAA,MACT,SAAS,gBAAgB,MAAM;AAAA,MAC/B,SAAS,gBAAgB,MAAM;AAAA,IAAA;AAAA,EAEjC;AAAA,EAEA,OAAc,oBAAoB,UAAgF;AACjH,UAAM,aAAa,IAAI,YAAY,kBAAkB,QAAW,IAAI;AAEpE,UAAM,cAAc,IAAI;AAAA,MACvB;AAAA,MACA,oBAAI,IAAI,CAAC,CAAC,WAAW,iBAAiB,UAAU,CAAC,CAAC;AAAA,MAClD,oBAAI,IAAI,CAAC,CAAC,kBAAkB,WAAW,eAAe,CAAC,CAAC;AAAA,IAAA;AAEzD,WAAO,WAAW,KAAK,4BAA4B,UAAU,WAAW,IAAI;AAAA,EAC7E;AAAA,EAEA,OAAc,kBAAkB,UAAuB,OAAiC;AAChF,WAAA,SAAS,MAAM,KAAK;AAAA,EAC5B;AAAA,EAEA,OAAe,0BAA0B,WAA6B;AACrE,UAAM,IAAI,aAAa,kDAAkD,SAAS,IAAI;AAAA,EACvF;AACD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"MutationGenerator.cjs","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, GraphQlLiteral, Input, replaceGraphQlLiteral } from '@contember/client'\nimport { ClientGeneratedUuid, EntityFieldPersistedData, ReceivedEntityData, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\t\tconst processedDeletes = new Set<string>()\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating && subTreeState.blueprint.marker.parameters.isUnpersisted) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating && subTreeState.blueprint.marker.parameters.isUnpersisted) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (processedDeletes.has(key)) {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tprocessedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.createCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(processedPlaceholdersByEntity, entityRealm)\n\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\tentityRealm,\n\t\t)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst value = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(processedPlaceholdersByEntity, fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst input = this.getCreateManyRelationInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tconst value = field.fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\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 'hasMany': {\n\t\t\t\t\t\t\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\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(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && !isEmptyObject(result)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field instanceof GraphQlLiteral ? field.value : field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: replaceGraphQlLiteral(field) }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\tif (reducedBy === undefined) {\n\n\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t}\n\n\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName, reducedBy)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity)\n\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined// …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t): Input.UpdateManyRelationInput | undefined {\n\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(processedPlaceholdersByEntity, childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\n\t\t\t\t\t\t\t\t},\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} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(processedPlaceholdersByEntity, childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["assertNever","getEntityMarker","builder","PRIMARY_KEY_NAME","QueryGenerator","StateIterator","placeholderName","TYPENAME_KEY_NAME","ClientGeneratedUuid","HasOneRelationMarker","BindingError","HasManyRelationMarker","isEmptyObject","GraphQlLiteral","replaceGraphQlLiteral","createData","MutationAlias","ServerId"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCO,MAAM,kBAAkB;AAAA,EAIvB,YACW,WACA,IAChB;AALM,wCAAe;AAGL,SAAA,YAAA;AACA,SAAA,KAAA;AAAA,EAElB;AAAA,EA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M;AAAA,gBACP;AAAA,cAAA,CACA;AAAA,YACF;AAAA,UACD;AAAA,QAAA,OACM;AACN,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,SAAS,EAAE,CAACA,6BAAgB,GAAG,UAAU,MAAM;AAAA,UAAA,CAC/C;AAAA,QACF;AAAA,MAAA,OACM;AACN,cAAM,YAAY,KAAK,mBAAmB,+BAA+B,UAAU;AACnF,YAAI,cAAc,QAAW;AAC5B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ;AAAA,UAAA,CACR;AAAA,QACF;AAAA,MACD;AAAA,IACD;AACA,QAAI,WAAW,iBAAiB;AAC/B,iBAAW,CAAC,WAAW,WAAW,KAAK,WAAW,iBAAiB;AAC5D,cAAA,QAAQa,4BAAc,eAAe,IAAIC,mBAAS,WAAW,WAAW,UAAU,CAAC;AACzF,YAAI,gBAAgB,UAAU;AAE7B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ,EAAE,CAACd,aAAgB,gBAAA,GAAG,UAAU;AAAA,UAAA,CACxC;AAAA,QAAA,WAES,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAACA,aAAgB,gBAAA,GAAG,UAAU;AAAA,UAAA,CAC5C;AAAA,QAAA,OACK;AACNH,sBAAAA,YAAuB;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAEO,WAAA,MAAM,WAAW,IAAI,SAAY;AAAA,EACzC;AAAA,EAGQ,cAAsB;AAC7B,WAAO,MAAM,KAAK;AAAA,EACnB;AACD;;"}
1
+ {"version":3,"file":"MutationGenerator.cjs","sources":["../../../src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, GraphQlLiteral, Input, replaceGraphQlLiteral } from '@contember/client'\nimport { ClientGeneratedUuid, EntityFieldPersistedData, ReceivedEntityData, ServerId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '../bindingTypes'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '../markers'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '../treeParameters'\nimport { assertNever, isEmptyObject } from '../utils'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\n\n\ntype ProcessedPlaceholdersByEntity = Map<EntityState, Set<PlaceholderName>>\n\nexport type SubMutationOperation =\n\t& {\n\t\talias: string,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single'\n\t}\n\t& (\n\t\t| { type: 'delete', id: EntityId }\n\t\t| { type: 'update', markers: EntityFieldMarkers, id: EntityId }\n\t\t| { type: 'create', markers: EntityFieldMarkers, id: EntityId }\n\t)\n\nexport type PersistMutationResult = {\n\tmutations: Record<string, ContentMutation<ReceivedEntityData>>\n\toperations: SubMutationOperation[]\n}\n\n// TODO enforce correct expected mutations in dev mode.\nexport class MutationGenerator {\n\n\tprivate aliasCounter = 1\n\n\tpublic constructor(\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly qb: ContentQueryBuilder,\n\t) {\n\t}\n\n\tpublic getPersistMutation(): PersistMutationResult | undefined {\n\t\tconst mutations: Record<string, ContentMutation<any>> = {}\n\t\tconst operations: SubMutationOperation[] = []\n\t\tconst processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()\n\t\tconst processedDeletes = new Set<string>()\n\n\t\tfor (const [treeRootId, rootStates] of this.treeStore.subTreeStatesByRoot.entries()) {\n\t\t\tfor (const [placeholderName, subTreeState] of Array.from(rootStates.entries()).reverse()) {\n\t\t\t\tif (subTreeState.unpersistedChangesCount <= 0) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif (subTreeState.type === 'entityRealm') {\n\t\t\t\t\tif (subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating && subTreeState.blueprint.marker.parameters.isUnpersisted) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t'single',\n\t\t\t\t\t\tsubTreeState.entity.id.value,\n\t\t\t\t\t\tsubTreeState,\n\t\t\t\t\t)\n\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t}\n\t\t\t\t} else if (subTreeState.type === 'entityList') {\n\t\t\t\t\tif (subTreeState.blueprint.type === 'subTree' && subTreeState.blueprint.marker.parameters.isCreating && subTreeState.blueprint.marker.parameters.isUnpersisted) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tfor (const childState of subTreeState.children.values()) {\n\t\t\t\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\t\t\t\t// TODO there can be a forceCreate somewhere in there that we're hereby ignoring.\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst subMutation = this.createMutation(\n\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t'list',\n\t\t\t\t\t\t\tchildState.entity.id.value,\n\t\t\t\t\t\t\tchildState,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tif (subMutation) {\n\t\t\t\t\t\t\tmutations[subMutation[1].alias] = subMutation[0]\n\t\t\t\t\t\t\toperations.push(subMutation[1])\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (subTreeState.plannedRemovals) {\n\t\t\t\t\t\tfor (const [removedId, removalType] of subTreeState.plannedRemovals) {\n\t\t\t\t\t\t\tif (removalType === 'disconnect') {\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (removalType === 'delete') {\n\t\t\t\t\t\t\t\tconst key = `${subTreeState.entityName}#${removedId}`\n\t\t\t\t\t\t\t\tif (processedDeletes.has(key)) {\n\t\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tprocessedDeletes.add(key)\n\t\t\t\t\t\t\t\tconst alias = this.createAlias()\n\t\t\t\t\t\t\t\tmutations[alias] = this.createDeleteMutation(\n\t\t\t\t\t\t\t\t\tsubTreeState.entityName,\n\t\t\t\t\t\t\t\t\tremovedId,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\toperations.push({ alias, subTreePlaceholder: placeholderName, subTreeType: 'list', type: 'delete', id: removedId })\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tassertNever(removalType)\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} else {\n\t\t\t\t\tassertNever(subTreeState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { mutations, operations }\n\t}\n\n\tprivate createMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tsubTreePlaceholder: PlaceholderName,\n\t\tsubTreeType: 'list' | 'single',\n\t\tentityId: EntityId,\n\t\trealmState: EntityRealmState,\n\t): [ContentMutation<any>, SubMutationOperation] | undefined {\n\t\tif (realmState.unpersistedChangesCount === 0) {\n\t\t\t// Bail out early\n\t\t\treturn undefined\n\t\t}\n\t\tconst fieldMarkers = getEntityMarker(realmState).fields.markers\n\n\t\tconst alias = this.createAlias()\n\n\t\tif (realmState.entity.isScheduledForDeletion) {\n\t\t\tconst mutation = this.createDeleteMutation(\n\t\t\t\trealmState.entity.entityName,\n\t\t\t\tentityId,\n\t\t\t)\n\t\t\treturn [\n\t\t\t\tmutation,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'delete',\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n\t\t\t]\n\t\t} else if (!realmState.entity.id.existsOnServer) {\n\t\t\tconst builder = this.createCreateMutation(\n\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\trealmState,\n\t\t\t\tfieldMarkers,\n\t\t\t)\n\t\t\tif (!builder) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [\n\t\t\t\tbuilder,\n\t\t\t\t{\n\t\t\t\t\talias,\n\t\t\t\t\tsubTreePlaceholder,\n\t\t\t\t\tsubTreeType,\n\t\t\t\t\ttype: 'create',\n\t\t\t\t\tmarkers: fieldMarkers,\n\t\t\t\t\tid: entityId,\n\t\t\t\t},\n]\n\t\t}\n\t\tconst builder = this.createUpdateMutation(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\trealmState,\n\t\t\tfieldMarkers,\n\t\t)\n\t\tif (!builder) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [\n\t\t\tbuilder,\n\t\t\t{\n\t\t\t\talias,\n\t\t\t\tsubTreePlaceholder,\n\t\t\t\tsubTreeType,\n\t\t\t\ttype: 'update',\n\t\t\t\tid: entityId,\n\t\t\t\tmarkers: fieldMarkers,\n\t\t\t},\n\t\t]\n\t}\n\n\tprivate createDeleteMutation(\n\t\tentityName: EntityName,\n\t\tdeletedId: EntityId,\n\t): ContentMutation<any> {\n\t\treturn this.qb.delete(entityName, {\n\t\t\tby: { [PRIMARY_KEY_NAME]: deletedId },\n\t\t}, it => it.$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createUpdateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getUpdateDataInput(processedPlaceholdersByEntity, entityRealm)\n\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst runtimeId = entityRealm.entity.id\n\n\t\tif (!runtimeId.existsOnServer) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.update(entityRealm.entity.entityName, {\n\t\t\tby: {\n\t\t\t\t[PRIMARY_KEY_NAME]: runtimeId.value,\n\t\t\t},\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate createCreateMutation(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tentityRealm: EntityRealmState,\n\t\tfieldMarkers: EntityFieldMarkers,\n\t): ContentMutation<any> | undefined {\n\t\tconst input = this.getCreateDataInput(\n\t\t\tprocessedPlaceholdersByEntity,\n\t\t\tentityRealm,\n\t\t)\n\t\tif (input === undefined) {\n\t\t\treturn undefined\n\t\t}\n\n\t\treturn this.qb.create(entityRealm.entity.entityName, {\n\t\t\tdata: input,\n\t\t}, it => QueryGenerator.registerQueryPart(fieldMarkers, it).$(PRIMARY_KEY_NAME).$('__typename'))\n\t}\n\n\tprivate getCreateDataInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): Input.CreateDataInput | undefined {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tif (currentState.type === 'entityRealmStub') {\n\t\t\t// TODO If there's a forceCreate, this is wrong.\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst result: Input.CreateDataInput = {}\n\t\tfor (const siblingState of StateIterator.eachSiblingRealm(currentState)) {\n\n\t\t\tconst pathBack = this.treeStore.getPathBackToParent(siblingState)\n\n\t\t\tconst nonbearingFields: Array<| { type: 'field'; marker: FieldMarker; fieldState: FieldState }\n\t\t\t\t| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\t\t\t\t| { type: 'hasMany'; marker: HasManyRelationMarker; fieldState: EntityListState }> = []\n\n\t\t\tfor (const [placeholderName, fieldState] of siblingState.children) {\n\t\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\tconst marker = fieldState.fieldMarker\n\t\t\t\t\t\tconst placeholderName = marker.placeholderName\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tplaceholderName === TYPENAME_KEY_NAME ||\n\t\t\t\t\t\t\t(placeholderName === PRIMARY_KEY_NAME && !(siblingState.entity.id instanceof ClientGeneratedUuid))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'field',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst value = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (value !== undefined && value !== null) {\n\t\t\t\t\t\t\tresult[marker.fieldName] = value\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityRealmStub':\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasOne',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(processedPlaceholdersByEntity, fieldState, marker)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (marker.parameters.isNonbearing) {\n\t\t\t\t\t\t\tnonbearingFields.push({\n\t\t\t\t\t\t\t\ttype: 'hasMany',\n\t\t\t\t\t\t\t\tmarker,\n\t\t\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst input = this.getCreateManyRelationInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((!isEmptyObject(result)) || !getEntityMarker(siblingState).fields.hasAtLeastOneBearingField) {\n\t\t\t\tfor (const field of nonbearingFields) {\n\t\t\t\t\tswitch (field.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tconst value = field.fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\t\tif (value !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.fieldName] = value\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 'hasOne': {\n\t\t\t\t\t\t\tconst input = this.getCreateOneRelationInput(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t\tfield.marker,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\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 'hasMany': {\n\t\t\t\t\t\t\tconst input = this.getCreateManyRelationInput(\n\t\t\t\t\t\t\t\tprocessedPlaceholdersByEntity,\n\t\t\t\t\t\t\t\tfield.fieldState,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tif (input !== undefined) {\n\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\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(field)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst setOnCreate = getEntityMarker(siblingState).parameters.setOnCreate\n\t\t\tif (setOnCreate && !isEmptyObject(result)) {\n\t\t\t\tfor (const key in setOnCreate) {\n\t\t\t\t\tconst field = setOnCreate[key]\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof field === 'string' ||\n\t\t\t\t\t\ttypeof field === 'number' ||\n\t\t\t\t\t\tfield === null ||\n\t\t\t\t\t\tfield instanceof GraphQlLiteral\n\t\t\t\t\t) {\n\t\t\t\t\t\tresult[key] = field instanceof GraphQlLiteral ? field.value : field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: replaceGraphQlLiteral(field) }\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getCreateOneRelationInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tmarker: HasOneRelationMarker,\n\t): Input.CreateOneRelationInput | Input.CreateManyRelationInput | undefined {\n\t\tconst reducedBy = marker.parameters.reducedBy\n\t\tconst runtimeId = fieldState.entity.id\n\n\t\tif (reducedBy === undefined) {\n\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t\treturn { connect: { [PRIMARY_KEY_NAME]: runtimeId.value } }\n\t\t\t}\n\n\t\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createData === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn { create: createData }\n\t\t}\n\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, fieldState)) {\n\t\t\t// TODO also potentially update\n\t\t\treturn [{ connect: { [PRIMARY_KEY_NAME]: runtimeId.value }, alias }]\n\t\t}\n\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\tif (createData === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn [{ create: createData, alias }]\n\t}\n\n\tprivate getCreateManyRelationInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tfieldState: EntityListState,\n\t): Input.CreateManyRelationInput | undefined {\n\t\tconst result: Input.CreateManyRelationInput = []\n\t\tfor (const entityRealm of fieldState.children.values()) {\n\t\t\tconst runtimeId = entityRealm.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\t\t\tif (this.shouldConnectInsteadOfCreate(processedPlaceholdersByEntity, entityRealm)) {\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\tconst createData = this.getCreateDataInput(processedPlaceholdersByEntity, entityRealm)\n\t\t\t\tif (createData === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tresult.push({\n\t\t\t\t\talias,\n\t\t\t\t\tcreate: createData,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn result.length === 0 ? undefined : result\n\t}\n\n\tprivate shouldConnectInsteadOfCreate(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState | EntityRealmStateStub,\n\t): boolean {\n\t\tconst runtimeId = currentState.entity.id\n\t\tconst processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\treturn runtimeId.existsOnServer || (runtimeId instanceof ClientGeneratedUuid && (processedPlaceholders?.has(PRIMARY_KEY_NAME) ?? false))\n\t}\n\n\tprivate getUpdateDataInput(\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tcurrentState: EntityRealmState,\n\t): Input.UpdateDataInput | undefined {\n\t\tlet processedPlaceholders = processedPlaceholdersByEntity.get(currentState.entity)\n\n\t\tif (processedPlaceholders === undefined) {\n\t\t\tprocessedPlaceholdersByEntity.set(currentState.entity, (processedPlaceholders = new Set()))\n\t\t}\n\n\t\tconst pathBack = this.treeStore.getPathBackToParent(currentState)\n\t\tconst entityData = this.treeStore.persistedEntityData.get(currentState.entity.id.uniqueValue)\n\n\t\tconst result: Input.UpdateDataInput = {}\n\n\t\tfor (const [placeholderName, fieldState] of currentState.children) {\n\t\t\tif (placeholderName === PRIMARY_KEY_NAME || placeholderName === TYPENAME_KEY_NAME) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (processedPlaceholders.has(placeholderName)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tprocessedPlaceholders.add(placeholderName)\n\n\t\t\tswitch (fieldState.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (fieldState.persistedValue !== undefined) {\n\t\t\t\t\t\tconst resolvedValue = fieldState.getAccessor().resolvedValue\n\t\t\t\t\t\tif (fieldState.persistedValue !== resolvedValue) {\n\t\t\t\t\t\t\tresult[placeholderName] = resolvedValue\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealmStub':\n\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\tconst marker = getEntityMarker(fieldState)\n\t\t\t\t\tif (!(marker instanceof HasOneRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst reducedBy = marker.parameters.reducedBy\n\n\t\t\t\t\tconst persistedValue = entityData?.get?.(placeholderName)\n\t\t\t\t\tif (reducedBy === undefined) {\n\n\t\t\t\t\t\tconst relationData = this.getUpdateOneRelationInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t}\n\n\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName, reducedBy)\n\t\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tconst marker = fieldState.blueprint.marker\n\t\t\t\t\tif (!(marker instanceof HasManyRelationMarker)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (pathBack?.fieldBackToParent === marker.parameters.field) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst persistedEntityIds = entityData?.get?.(placeholderName) ?? new Set()\n\n\t\t\t\t\tif (!(persistedEntityIds instanceof Set)) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity)\n\t\t\t\t\tif (relationData !== undefined) {\n\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn assertNever(fieldState)\n\t\t\t}\n\t\t}\n\n\t\treturn isEmptyObject(result) ? undefined : result\n\t}\n\n\tprivate getUpdateOneRelationInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tplaceholderName: PlaceholderName,\n\t): Input.UpdateOneRelationInput | undefined {\n\t\tconst runtimeId = fieldState.entity.id\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\t// The persisted and currently referenced ids match, and so this is an update.\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined// …unless we're dealing with a stub. There cannot be any updates there.\n\t\t\t\t}\n\t\t\t\tconst input = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\tif (input === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tupdate: input,\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// There was a referenced entity but currently, there is a different one. Let's investigate:\n\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t// It's planned for deletion.\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn {\n\t\t\t\t\tdelete: true,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// This isn't the persisted entity but it does exist on the server. Thus this is a connect.\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn {\n\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t}\n\n\t\t\t}\n\t\t\t// The currently present entity doesn't exist on the server. Try if creating yields anything…\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createInput !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tcreate: createInput,\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// …but if it doesn't, we just disconnect.\n\t\t\t\treturn {\n\t\t\t\t\tdisconnect: true,\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\t// There isn't a linked entity on the server but we're seeing one that exists there.\n\t\t\t// Thus this is a connect.\n\t\t\t// TODO also potentially update\n\t\t\treturn {\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}\n\t\t} else {\n\t\t\tconst input = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (input === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tcreate: input,\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationForReducedInput(\n\t\tcurrentState: EntityRealmState,\n\t\tfieldState: EntityRealmState | EntityRealmStateStub,\n\t\tpersistedValue: EntityFieldPersistedData | undefined,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t\tplaceholderName: PlaceholderName,\n\t\treducedBy: UniqueWhere,\n\t): Input.UpdateManyRelationInput | undefined {\n\n\t\tconst runtimeId = fieldState.entity.id\n\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\tif (persistedValue instanceof ServerId) {\n\t\t\tif (persistedValue.value === runtimeId.value) {\n\t\t\t\tif (fieldState.type === 'entityRealmStub') {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\tconst updateData = this.getUpdateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\t\tif (updateData === undefined) {\n\t\t\t\t\treturn undefined\n\t\t\t\t}\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\tby: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t\t\tdata: updateData,\n\t\t\t\t\t},\n\t\t\t\t}]\n\t\t\t}\n\t\t\tconst plannedDeletion = currentState.plannedHasOneDeletions?.get(placeholderName)\n\t\t\tif (plannedDeletion !== undefined) {\n\t\t\t\t// TODO also potentially do something about the current entity\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdelete: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t}]\n\t\t\t}\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\t// TODO will re-using the alias like this work?\n\t\t\t\t// TODO also potentially update\n\t\t\t\treturn [\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t}\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn [{\n\t\t\t\t\talias,\n\t\t\t\t\tdisconnect: replaceGraphQlLiteral(reducedBy),\n\t\t\t\t}]\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t} else if (runtimeId.existsOnServer) {\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t}]\n\t\t} else {\n\t\t\tconst createInput = this.getCreateDataInput(processedPlaceholdersByEntity, fieldState)\n\t\t\tif (createInput === undefined) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\treturn [{\n\t\t\t\talias,\n\t\t\t\tcreate: createInput,\n\t\t\t}]\n\t\t}\n\t}\n\n\tprivate getUpdateManyRelationInput(\n\t\tfieldState: EntityListState,\n\t\tpersistedEntityIds: Set<EntityId>,\n\t\tprocessedPlaceholdersByEntity: ProcessedPlaceholdersByEntity,\n\t): Input.UpdateManyRelationInput | undefined {\n\n\t\tconst input: Input.UpdateManyRelationInput = []\n\t\tfor (const childState of fieldState.children.values()) {\n\t\t\tconst runtimeId = childState.entity.id\n\t\t\tconst alias = MutationAlias.encodeEntityId(runtimeId)\n\n\t\t\tif (runtimeId.existsOnServer) {\n\t\t\t\tif (persistedEntityIds.has(runtimeId.value)) {\n\t\t\t\t\tif (childState.type !== 'entityRealmStub') {\n\t\t\t\t\t\tconst dataInput = this.getUpdateDataInput(processedPlaceholdersByEntity, childState)\n\n\t\t\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\t\t\tinput.push({\n\t\t\t\t\t\t\t\talias,\n\t\t\t\t\t\t\t\tupdate: {\n\t\t\t\t\t\t\t\t\tby: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t\t\t\t\tdata: dataInput,\n\t\t\t\t\t\t\t\t},\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} else {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tconnect: { [PRIMARY_KEY_NAME]: runtimeId.value },\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst dataInput = this.getCreateDataInput(processedPlaceholdersByEntity, childState)\n\t\t\t\tif (dataInput !== undefined) {\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tcreate: dataInput,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (fieldState.plannedRemovals) {\n\t\t\tfor (const [removedId, removalType] of fieldState.plannedRemovals) {\n\t\t\t\tconst alias = MutationAlias.encodeEntityId(new ServerId(removedId, fieldState.entityName))\n\t\t\t\tif (removalType === 'delete') {\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdelete: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\n\t\t\t\t} else if (removalType === 'disconnect') {\n\t\t\t\t\t// TODO also potentially update\n\n\t\t\t\t\tinput.push({\n\t\t\t\t\t\talias,\n\t\t\t\t\t\tdisconnect: { [PRIMARY_KEY_NAME]: removedId },\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(removalType)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn input.length === 0 ? undefined : input\n\t}\n\n\n\tprivate createAlias(): string {\n\t\treturn `op_${this.aliasCounter++}`\n\t}\n}\n"],"names":["assertNever","getEntityMarker","builder","PRIMARY_KEY_NAME","QueryGenerator","StateIterator","placeholderName","TYPENAME_KEY_NAME","ClientGeneratedUuid","HasOneRelationMarker","BindingError","HasManyRelationMarker","isEmptyObject","GraphQlLiteral","replaceGraphQlLiteral","createData","MutationAlias","ServerId"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCO,MAAM,kBAAkB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