@contember/binding-legacy 2.0.0-beta.4 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/development/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.cjs +7 -0
- package/dist/development/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/development/src/accessors/EntityAccessorImpl.js +7 -0
- package/dist/development/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/development/src/core/MutationGenerator.cjs +1 -1
- package/dist/development/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/src/core/MutationGenerator.js +1 -1
- package/dist/development/src/core/MutationGenerator.js.map +1 -1
- package/dist/development/src/core/QueryGenerator.cjs +7 -0
- package/dist/development/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/development/src/core/QueryGenerator.js +7 -0
- package/dist/development/src/core/QueryGenerator.js.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.cjs +22 -6
- package/dist/development/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/development/src/core/RequestResponseNormalizer.js +22 -6
- package/dist/development/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/development/src/core/StateInitializer.cjs +1 -1
- package/dist/development/src/core/StateInitializer.cjs.map +1 -1
- package/dist/development/src/core/StateInitializer.js +1 -1
- package/dist/development/src/core/StateInitializer.js.map +1 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.cjs.map +1 -1
- package/dist/production/src/accessorTree/NormalizedPersistedData.js.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.cjs +7 -0
- package/dist/production/src/accessors/EntityAccessorImpl.cjs.map +1 -1
- package/dist/production/src/accessors/EntityAccessorImpl.js +7 -0
- package/dist/production/src/accessors/EntityAccessorImpl.js.map +1 -1
- package/dist/production/src/core/MutationGenerator.cjs +1 -1
- package/dist/production/src/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/src/core/MutationGenerator.js +1 -1
- package/dist/production/src/core/MutationGenerator.js.map +1 -1
- package/dist/production/src/core/QueryGenerator.cjs +7 -0
- package/dist/production/src/core/QueryGenerator.cjs.map +1 -1
- package/dist/production/src/core/QueryGenerator.js +7 -0
- package/dist/production/src/core/QueryGenerator.js.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.cjs +22 -6
- package/dist/production/src/core/RequestResponseNormalizer.cjs.map +1 -1
- package/dist/production/src/core/RequestResponseNormalizer.js +22 -6
- package/dist/production/src/core/RequestResponseNormalizer.js.map +1 -1
- package/dist/production/src/core/StateInitializer.cjs +1 -1
- package/dist/production/src/core/StateInitializer.cjs.map +1 -1
- package/dist/production/src/core/StateInitializer.js +1 -1
- package/dist/production/src/core/StateInitializer.js.map +1 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts +6 -1
- package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
- package/dist/types/accessors/EntityAccessorImpl.d.ts +4 -0
- package/dist/types/accessors/EntityAccessorImpl.d.ts.map +1 -1
- package/dist/types/core/QueryGenerator.d.ts +1 -0
- package/dist/types/core/QueryGenerator.d.ts.map +1 -1
- package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/accessorTree/NormalizedPersistedData.ts +7 -1
- package/src/accessors/EntityAccessorImpl.ts +8 -0
- package/src/core/MutationGenerator.ts +1 -1
- package/src/core/QueryGenerator.ts +9 -1
- package/src/core/RequestResponseNormalizer.ts +24 -8
- package/src/core/StateInitializer.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MutationGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { EntityFieldPersistedData } from '../accessorTree'\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 {\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\t\t\t]\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| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\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 accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\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 accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: 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 accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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: 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: 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: 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: 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":["builder","placeholderName","createData"],"mappings":";;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAIvB,YACW,WACA,IAChB;AAFgB,SAAA,YAAA;AACA,SAAA,KAAA;AAJlB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAQhB,qBAA4C;AAClD,UAAM,YAAkD,CAAC;AACzD,UAAM,aAAqC,CAAC;AACtC,UAAA,oDAAmE,IAAI;AACvE,UAAA,uCAAuB,IAAY;AAE9B,eAAA,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACzE,iBAAA,CAAC,iBAAiB,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B,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAAC,gBAAgB,GAAG,UAAU;AAAA,UAAA,CAC5C;AAAA,QAAA,OACK;AACN,sBAAY,WAAW;AAAA,QAAA;AAAA,MACxB;AAAA,IACD;AAGM,WAAA,MAAM,WAAW,IAAI,SAAY;AAAA,EAAA;AAAA,EAIjC,cAAsB;AACtB,WAAA,MAAM,KAAK,cAAc;AAAA,EAAA;AAElC;"}
|
|
1
|
+
{"version":3,"file":"MutationGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/MutationGenerator.ts"],"sourcesContent":["import { ContentMutation, ContentQueryBuilder, Input } from '@contember/client'\nimport { ClientGeneratedUuid, ReceivedEntityData, ServerId } from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from '@contember/binding-common'\nimport { EntityFieldMarkers, FieldMarker, HasManyRelationMarker, HasOneRelationMarker } from '@contember/binding-common'\nimport type { EntityId, EntityName, PlaceholderName, UniqueWhere } from '@contember/binding-common'\nimport { isEmptyObject } from '../utils'\nimport { assertNever } from '@contember/binding-common'\nimport { QueryGenerator } from './QueryGenerator'\nimport { MutationAlias } from './requestAliases'\nimport { EntityListState, EntityRealmState, EntityRealmStateStub, EntityState, FieldState, getEntityMarker, StateIterator } from './state'\nimport type { TreeStore } from './TreeStore'\nimport { EntityFieldPersistedData } from '../accessorTree'\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 {\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\t\t\t]\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| { type: 'hasOne'; marker: HasOneRelationMarker; fieldState: EntityRealmState | EntityRealmStateStub }\n\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 accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = input\n\t\t\t\t\t\t\t}\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 accessor = field.fieldState.getAccessor()\n\t\t\t\t\t\t\tconst value = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(input) && Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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\tconst current = result[field.marker.parameters.field]\n\t\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\t\tcurrent.push(...input)\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tresult[field.marker.parameters.field] = input\n\t\t\t\t\t\t\t\t}\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) {\n\t\t\t\t\t\tresult[key] = field\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresult[key] = { connect: 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 accessor = fieldState.getAccessor()\n\t\t\t\t\t\tconst resolvedValue = accessor.value ?? accessor.defaultValue ?? null\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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\n\t\t\t\t\t\t\t}\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)?.value ?? 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\tconst current = result[marker.parameters.field]\n\t\t\t\t\t\tif (Array.isArray(current)) {\n\t\t\t\t\t\t\tcurrent.push(...relationData)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tresult[marker.parameters.field] = relationData\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\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: 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: 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: 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: 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":["builder","placeholderName","createData"],"mappings":";;;;;;;;;AAmCO,MAAM,kBAAkB;AAAA,EAIvB,YACW,WACA,IAChB;AAFgB,SAAA,YAAA;AACA,SAAA,KAAA;AAJlB,kBAAA,MAAQ,gBAAe,CAAA;AAAA,EAAA;AAAA,EAQhB,qBAA4C;AAClD,UAAM,YAAkD,CAAC;AACzD,UAAM,aAAqC,CAAC;AACtC,UAAA,oDAAmE,IAAI;AACvE,UAAA,uCAAuB,IAAY;AAE9B,eAAA,CAAC,YAAY,UAAU,KAAK,KAAK,UAAU,oBAAoB,WAAW;AACzE,iBAAA,CAAC,iBAAiB,YAAY,KAAK,MAAM,KAAK,WAAW,QAAQ,CAAC,EAAE,WAAW;AACrF,YAAA,aAAa,2BAA2B,GAAG;AAC9C;AAAA,QAAA;AAEG,YAAA,aAAa,SAAS,eAAe;AACxC,cAAI,aAAa,UAAU,SAAS,aAAa,aAAa,UAAU,OAAO,WAAW,cAAc,aAAa,UAAU,OAAO,WAAW,eAAe;AAC/J;AAAA,UAAA;AAED,gBAAM,cAAc,KAAK;AAAA,YACxB;AAAA,YACA;AAAA,YACA;AAAA,YACA,aAAa,OAAO,GAAG;AAAA,YACvB;AAAA,UACD;AACA,cAAI,aAAa;AAChB,sBAAU,YAAY,CAAC,EAAE,KAAK,IAAI,YAAY,CAAC;AACpC,uBAAA,KAAK,YAAY,CAAC,CAAC;AAAA,UAAA;AAAA,QAC/B,WACU,aAAa,SAAS,cAAc;AAC9C,cAAI,aAAa,UAAU,SAAS,aAAa,aAAa,UAAU,OAAO,WAAW,cAAc,aAAa,UAAU,OAAO,WAAW,eAAe;AAC/J;AAAA,UAAA;AAED,qBAAW,cAAc,aAAa,SAAS,OAAA,GAAU;AACpD,gBAAA,WAAW,SAAS,mBAAmB;AAE1C;AAAA,YAAA;AAED,kBAAM,cAAc,KAAK;AAAA,cACxB;AAAA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;AACN,cAAM,YAAY,KAAK,mBAAmB,+BAA+B,UAAU;AACnF,YAAI,cAAc,QAAW;AAC5B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ;AAAA,UAAA,CACR;AAAA,QAAA;AAAA,MACF;AAAA,IACD;AAED,QAAI,WAAW,iBAAiB;AAC/B,iBAAW,CAAC,WAAW,WAAW,KAAK,WAAW,iBAAiB;AAC5D,cAAA,QAAQ,cAAc,eAAe,IAAI,SAAS,WAAW,WAAW,UAAU,CAAC;AACzF,YAAI,gBAAgB,UAAU;AAE7B,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,QAAQ,EAAE,CAAC,gBAAgB,GAAG,UAAU;AAAA,UAAA,CACxC;AAAA,QAAA,WAES,gBAAgB,cAAc;AAGxC,gBAAM,KAAK;AAAA,YACV;AAAA,YACA,YAAY,EAAE,CAAC,gBAAgB,GAAG,UAAU;AAAA,UAAA,CAC5C;AAAA,QAAA,OACK;AACN,sBAAY,WAAW;AAAA,QAAA;AAAA,MACxB;AAAA,IACD;AAGM,WAAA,MAAM,WAAW,IAAI,SAAY;AAAA,EAAA;AAAA,EAIjC,cAAsB;AACtB,WAAA,MAAM,KAAK,cAAc;AAAA,EAAA;AAElC;"}
|
|
@@ -94,9 +94,16 @@ class QueryGenerator {
|
|
|
94
94
|
} else {
|
|
95
95
|
bindingCommon.assertNever(fieldValue);
|
|
96
96
|
}
|
|
97
|
+
selection = QueryGenerator.withMetaField(selection, fieldValue.parameters.field, fieldValue.parameters.meta);
|
|
97
98
|
}
|
|
98
99
|
return selection;
|
|
99
100
|
}
|
|
101
|
+
static withMetaField(selection, fieldName, metaField) {
|
|
102
|
+
if (metaField.length === 0) {
|
|
103
|
+
return selection;
|
|
104
|
+
}
|
|
105
|
+
return selection.meta(fieldName, metaField);
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
const ucfirst = (string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`;
|
|
102
109
|
exports.QueryGenerator = QueryGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/QueryGenerator.ts"],"sourcesContent":["import {\n\tassertNever,\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tPRIMARY_KEY_NAME,\n} from '@contember/binding-common'\nimport { ContentEntitySelection, ContentQuery, ContentQueryBuilder } from '@contember/client'\n\n\nexport class QueryGenerator {\n\tconstructor(\n\t\tprivate tree: MarkerTreeRoot,\n\t\tprivate qb: ContentQueryBuilder,\n\t) {}\n\n\tpublic getReadQuery(): Record<string, ContentQuery<any>> {\n\t\tconst result: Record<string, ContentQuery<any>> = {}\n\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\tif (subTreeMarker.parameters.isCreating) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (subTreeMarker instanceof EntitySubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.addGetQuery(subTreeMarker)\n\t\t\t} else if (subTreeMarker instanceof EntityListSubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.createListQuery(subTreeMarker)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate addGetQuery(subTree: EntitySubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\treturn this.qb.get(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tby: subTree.parameters.where,\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tprivate createListQuery(subTree: EntityListSubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\t\treturn this.qb.list(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t\torderBy: subTree.parameters.orderBy,\n\t\t\t\toffset: subTree.parameters.offset,\n\t\t\t\tlimit: subTree.parameters.limit,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, selection: ContentEntitySelection): ContentEntitySelection {\n\t\tselection = selection.$(PRIMARY_KEY_NAME).$('__typename')\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tselection = selection.$(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tby: relation.reducedBy,\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\n\t\t\t\tselection = selection.$(\n\t\t\t\t\trelation.field,\n\t\t\t\t\t{\n\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\torderBy: relation.orderBy,\n\t\t\t\t\t\toffset: relation.offset,\n\t\t\t\t\t\tlimit: relation.limit,\n\t\t\t\t\t},\n\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t}\n\n\t\treturn selection\n\t}\n}\n\nconst ucfirst = (string: string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`\n"],"names":["EntitySubTreeMarker","EntityListSubTreeMarker","PRIMARY_KEY_NAME","FieldMarker","HasOneRelationMarker","HasManyRelationMarker","assertNever"],"mappings":";;;AAcO,MAAM,eAAe;AAAA,EAC3B,YACS,MACA,IACP;AAFO,SAAA,OAAA;AACA,SAAA,KAAA;AAAA,EAAA;AAAA,EAGF,eAAkD;AACxD,UAAM,SAA4C,CAAC;AACnD,eAAW,CAAA,EAAG,aAAa,KAAK,KAAK,KAAK,UAAU;AAC/C,UAAA,cAAc,WAAW,YAAY;AACxC;AAAA,MAAA;AAED,UAAI,yBAAyBA,cAAAA,qBAAqB;AACjD,eAAO,cAAc,eAAe,IAAI,KAAK,YAAY,aAAa;AAAA,MAAA,WAC5D,yBAAyBC,uCAAyB;AAC5D,eAAO,cAAc,eAAe,IAAI,KAAK,gBAAgB,aAAa;AAAA,MAAA;AAAA,IAC3E;AAEM,WAAA;AAAA,EAAA;AAAA,EAGA,YAAY,SAAiD;AAChE,QAAA,QAAQ,WAAW,YAAY;AAClC,YAAM,IAAI,MAAM;AAAA,IAAA;AAGjB,WAAO,KAAK,GAAG;AAAA,MACd,QAAQ;AAAA,MACR;AAAA,QACC,IAAI,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Q,SAAS;AAAA,cACjB,IAAI,WAAW;AAAA,YAChB;AAAA,YACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,UACrE;AAAA,QAAA;AAAA,MACD,WACU,sBAAsBC,qCAAuB;AACvD,cAAM,WAAW,WAAW;AAG5B,oBAAY,UAAU;AAAA,UACrB,SAAS;AAAA,UACT;AAAA,YACC,IAAI,WAAW;AAAA,YACf,QAAQ,SAAS;AAAA,YACjB,SAAS,SAAS;AAAA,YAClB,QAAQ,SAAS;AAAA,YACjB,OAAO,SAAS;AAAA,UACjB;AAAA,UACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,QACrE;AAAA,MAAA,OACM;AACNC,sBAAAA,YAAY,UAAU;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"QueryGenerator.cjs","sources":["../../../../../packages/binding-legacy/src/core/QueryGenerator.ts"],"sourcesContent":["import {\n\tassertNever,\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker, FieldMeta,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tPRIMARY_KEY_NAME,\n} from '@contember/binding-common'\nimport { ContentEntitySelection, ContentQuery, ContentQueryBuilder } from '@contember/client'\n\n\nexport class QueryGenerator {\n\tconstructor(\n\t\tprivate tree: MarkerTreeRoot,\n\t\tprivate qb: ContentQueryBuilder,\n\t) {}\n\n\tpublic getReadQuery(): Record<string, ContentQuery<any>> {\n\t\tconst result: Record<string, ContentQuery<any>> = {}\n\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\tif (subTreeMarker.parameters.isCreating) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (subTreeMarker instanceof EntitySubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.addGetQuery(subTreeMarker)\n\t\t\t} else if (subTreeMarker instanceof EntityListSubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.createListQuery(subTreeMarker)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate addGetQuery(subTree: EntitySubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\treturn this.qb.get(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tby: subTree.parameters.where,\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tprivate createListQuery(subTree: EntityListSubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\t\treturn this.qb.list(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t\torderBy: subTree.parameters.orderBy,\n\t\t\t\toffset: subTree.parameters.offset,\n\t\t\t\tlimit: subTree.parameters.limit,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, selection: ContentEntitySelection): ContentEntitySelection {\n\t\tselection = selection.$(PRIMARY_KEY_NAME).$('__typename')\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tselection = selection.$(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tby: relation.reducedBy,\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\n\t\t\t\tselection = selection.$(\n\t\t\t\t\trelation.field,\n\t\t\t\t\t{\n\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\torderBy: relation.orderBy,\n\t\t\t\t\t\toffset: relation.offset,\n\t\t\t\t\t\tlimit: relation.limit,\n\t\t\t\t\t},\n\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t\tselection = QueryGenerator.withMetaField(selection, fieldValue.parameters.field, fieldValue.parameters.meta)\n\t\t}\n\n\t\treturn selection\n\t}\n\n\tprivate static withMetaField(selection: ContentEntitySelection, fieldName: string, metaField: FieldMeta): ContentEntitySelection {\n\t\tif (metaField.length === 0) {\n\t\t\treturn selection\n\t\t}\n\t\treturn selection.meta(fieldName, metaField)\n\t}\n}\n\nconst ucfirst = (string: string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`\n"],"names":["EntitySubTreeMarker","EntityListSubTreeMarker","PRIMARY_KEY_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IAAI;AAAA,IAAA;AAGrG,WAAA;AAAA,EAAA;AAAA,EAGR,OAAe,cAAc,WAAmC,WAAmB,WAA8C;AAC5H,QAAA,UAAU,WAAW,GAAG;AACpB,aAAA;AAAA,IAAA;AAED,WAAA,UAAU,KAAK,WAAW,SAAS;AAAA,EAAA;AAE5C;AAEA,MAAM,UAAU,CAAC,WAAmB,GAAG,OAAO,OAAO,CAAC,EAAE,YAAa,CAAA,GAAG,OAAO,UAAU,CAAC,CAAC;;"}
|
|
@@ -92,9 +92,16 @@ class QueryGenerator {
|
|
|
92
92
|
} else {
|
|
93
93
|
assertNever(fieldValue);
|
|
94
94
|
}
|
|
95
|
+
selection = QueryGenerator.withMetaField(selection, fieldValue.parameters.field, fieldValue.parameters.meta);
|
|
95
96
|
}
|
|
96
97
|
return selection;
|
|
97
98
|
}
|
|
99
|
+
static withMetaField(selection, fieldName, metaField) {
|
|
100
|
+
if (metaField.length === 0) {
|
|
101
|
+
return selection;
|
|
102
|
+
}
|
|
103
|
+
return selection.meta(fieldName, metaField);
|
|
104
|
+
}
|
|
98
105
|
}
|
|
99
106
|
const ucfirst = (string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`;
|
|
100
107
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/QueryGenerator.ts"],"sourcesContent":["import {\n\tassertNever,\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tPRIMARY_KEY_NAME,\n} from '@contember/binding-common'\nimport { ContentEntitySelection, ContentQuery, ContentQueryBuilder } from '@contember/client'\n\n\nexport class QueryGenerator {\n\tconstructor(\n\t\tprivate tree: MarkerTreeRoot,\n\t\tprivate qb: ContentQueryBuilder,\n\t) {}\n\n\tpublic getReadQuery(): Record<string, ContentQuery<any>> {\n\t\tconst result: Record<string, ContentQuery<any>> = {}\n\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\tif (subTreeMarker.parameters.isCreating) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (subTreeMarker instanceof EntitySubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.addGetQuery(subTreeMarker)\n\t\t\t} else if (subTreeMarker instanceof EntityListSubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.createListQuery(subTreeMarker)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate addGetQuery(subTree: EntitySubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\treturn this.qb.get(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tby: subTree.parameters.where,\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tprivate createListQuery(subTree: EntityListSubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\t\treturn this.qb.list(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t\torderBy: subTree.parameters.orderBy,\n\t\t\t\toffset: subTree.parameters.offset,\n\t\t\t\tlimit: subTree.parameters.limit,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, selection: ContentEntitySelection): ContentEntitySelection {\n\t\tselection = selection.$(PRIMARY_KEY_NAME).$('__typename')\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tselection = selection.$(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tby: relation.reducedBy,\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\n\t\t\t\tselection = selection.$(\n\t\t\t\t\trelation.field,\n\t\t\t\t\t{\n\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\torderBy: relation.orderBy,\n\t\t\t\t\t\toffset: relation.offset,\n\t\t\t\t\t\tlimit: relation.limit,\n\t\t\t\t\t},\n\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t}\n\n\t\treturn selection\n\t}\n}\n\nconst ucfirst = (string: string) => `${string.charAt(0).toUpperCase()}${string.substring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E,EAAE,YAAY;AAExD,eAAW,CAAA,EAAG,UAAU,KAAK,QAAQ;AACpC,UAAI,sBAAsB,aAAa;AAClC,YAAA,WAAW,cAAc,kBAAkB;AAClC,sBAAA,UAAU,EAAE,WAAW,SAAS;AAAA,QAAA;AAAA,MAC7C,WACU,sBAAsB,sBAAsB;AACtD,cAAM,WAAW,WAAW;AAE5B,YAAI,SAAS,WAAW;AAEvB,gBAAM,gBAAgB,GAAG,SAAS,KAAK,KAAK,QAAQ,OAAO,KAAK,SAAS,SAAS,EAAE,CAAC,CAAC,CAAC;AACvF,sBAAY,UAAU;AAAA,YACrB;AAAA,YACA;AAAA,cACC,IAAI,SAAS;AAAA,cACb,QAAQ,SAAS;AAAA,cACjB,IAAI,WAAW;AAAA,YAChB;AAAA,YACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,UACrE;AAAA,QAAA,OACM;AACN,sBAAY,UAAU;AAAA,YACrB,SAAS;AAAA,YACT;AAAA,cACC,QAAQ,SAAS;AAAA,cACjB,IAAI,WAAW;AAAA,YAChB;AAAA,YACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,UACrE;AAAA,QAAA;AAAA,MACD,WACU,sBAAsB,uBAAuB;AACvD,cAAM,WAAW,WAAW;AAG5B,oBAAY,UAAU;AAAA,UACrB,SAAS;AAAA,UACT;AAAA,YACC,IAAI,WAAW;AAAA,YACf,QAAQ,SAAS;AAAA,YACjB,SAAS,SAAS;AAAA,YAClB,QAAQ,SAAS;AAAA,YACjB,OAAO,SAAS;AAAA,UACjB;AAAA,UACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,QACrE;AAAA,MAAA,OACM;AACN,oBAAY,UAAU;AAAA,MAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"QueryGenerator.js","sources":["../../../../../packages/binding-legacy/src/core/QueryGenerator.ts"],"sourcesContent":["import {\n\tassertNever,\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker, FieldMeta,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n\tPRIMARY_KEY_NAME,\n} from '@contember/binding-common'\nimport { ContentEntitySelection, ContentQuery, ContentQueryBuilder } from '@contember/client'\n\n\nexport class QueryGenerator {\n\tconstructor(\n\t\tprivate tree: MarkerTreeRoot,\n\t\tprivate qb: ContentQueryBuilder,\n\t) {}\n\n\tpublic getReadQuery(): Record<string, ContentQuery<any>> {\n\t\tconst result: Record<string, ContentQuery<any>> = {}\n\t\tfor (const [, subTreeMarker] of this.tree.subTrees) {\n\t\t\tif (subTreeMarker.parameters.isCreating) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (subTreeMarker instanceof EntitySubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.addGetQuery(subTreeMarker)\n\t\t\t} else if (subTreeMarker instanceof EntityListSubTreeMarker) {\n\t\t\t\tresult[subTreeMarker.placeholderName] = this.createListQuery(subTreeMarker)\n\t\t\t}\n\t\t}\n\t\treturn result\n\t}\n\n\tprivate addGetQuery(subTree: EntitySubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\n\t\treturn this.qb.get(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tby: subTree.parameters.where,\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tprivate createListQuery(subTree: EntityListSubTreeMarker): ContentQuery<any> {\n\t\tif (subTree.parameters.isCreating) {\n\t\t\tthrow new Error()\n\t\t}\n\t\treturn this.qb.list(\n\t\t\tsubTree.entityName,\n\t\t\t{\n\t\t\t\tfilter: subTree.parameters.filter,\n\t\t\t\torderBy: subTree.parameters.orderBy,\n\t\t\t\toffset: subTree.parameters.offset,\n\t\t\t\tlimit: subTree.parameters.limit,\n\t\t\t},\n\t\t\tit => QueryGenerator.registerQueryPart(subTree.fields.markers, it),\n\t\t)\n\t}\n\n\tpublic static registerQueryPart(fields: EntityFieldMarkers, selection: ContentEntitySelection): ContentEntitySelection {\n\t\tselection = selection.$(PRIMARY_KEY_NAME).$('__typename')\n\n\t\tfor (const [, fieldValue] of fields) {\n\t\t\tif (fieldValue instanceof FieldMarker) {\n\t\t\t\tif (fieldValue.fieldName !== PRIMARY_KEY_NAME) {\n\t\t\t\t\tselection = selection.$(fieldValue.fieldName)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasOneRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\t\t\t\tif (relation.reducedBy) {\n\t\t\t\t\t// Assuming there's exactly one reducer field as enforced by MarkerTreeGenerator\n\t\t\t\t\tconst relationField = `${relation.field}By${ucfirst(Object.keys(relation.reducedBy)[0])}`\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelationField,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tby: relation.reducedBy,\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t} else {\n\t\t\t\t\tselection = selection.$(\n\t\t\t\t\t\trelation.field,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (fieldValue instanceof HasManyRelationMarker) {\n\t\t\t\tconst relation = fieldValue.parameters\n\n\n\t\t\t\tselection = selection.$(\n\t\t\t\t\trelation.field,\n\t\t\t\t\t{\n\t\t\t\t\t\tas: fieldValue.placeholderName,\n\t\t\t\t\t\tfilter: relation.filter,\n\t\t\t\t\t\torderBy: relation.orderBy,\n\t\t\t\t\t\toffset: relation.offset,\n\t\t\t\t\t\tlimit: relation.limit,\n\t\t\t\t\t},\n\t\t\t\t\tit => QueryGenerator.registerQueryPart(fieldValue.fields.markers, it),\n\t\t\t\t)\n\t\t\t} else {\n\t\t\t\tassertNever(fieldValue)\n\t\t\t}\n\t\t\tselection = QueryGenerator.withMetaField(selection, fieldValue.parameters.field, fieldValue.parameters.meta)\n\t\t}\n\n\t\treturn selection\n\t}\n\n\tprivate static withMetaField(selection: ContentEntitySelection, fieldName: string, metaField: FieldMeta): ContentEntitySelection {\n\t\tif (metaField.length === 0) {\n\t\t\treturn selection\n\t\t}\n\t\treturn selection.meta(fieldName, metaField)\n\t}\n}\n\nconst ucfirst = (string: string) => `${string.charAt(0).toUpperCase()}${string.substring(1)}`\n"],"names":[],"mappings":";AAcO,MAAM,eAAe;AAAA,EAC3B,YACS,MACA,IACP;AAFO,SAAA,OAAA;AACA,SAAA,KAAA;AAAA,EAAA;AAAA,EAGF,eAAkD;AACxD,UAAM,SAA4C,CAAC;AACnD,eAAW,CAAA,EAAG,aAAa,KAAK,KAAK,KAAK,UAAU;AAC/C,UAAA,cAAc,WAAW,YAAY;AACxC;AAAA,MAAA;AAED,UAAI,yBAAyB,qBAAqB;AACjD,eAAO,cAAc,eAAe,IAAI,KAAK,YAAY,aAAa;AAAA,MAAA,WAC5D,yBAAyB,yBAAyB;AAC5D,eAAO,cAAc,eAAe,IAAI,KAAK,gBAAgB,aAAa;AAAA,MAAA;AAAA,IAC3E;AAEM,WAAA;AAAA,EAAA;AAAA,EAGA,YAAY,SAAiD;AAChE,QAAA,QAAQ,WAAW,YAAY;AAClC,YAAM,IAAI,MAAM;AAAA,IAAA;AAGjB,WAAO,KAAK,GAAG;AAAA,MACd,QAAQ;AAAA,MACR;AAAA,QACC,IAAI,QAAQ,WAAW;AAAA,QACvB,QAAQ,QAAQ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QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,UACrE;AAAA,QAAA;AAAA,MACD,WACU,sBAAsB,uBAAuB;AACvD,cAAM,WAAW,WAAW;AAG5B,oBAAY,UAAU;AAAA,UACrB,SAAS;AAAA,UACT;AAAA,YACC,IAAI,WAAW;AAAA,YACf,QAAQ,SAAS;AAAA,YACjB,SAAS,SAAS;AAAA,YAClB,QAAQ,SAAS;AAAA,YACjB,OAAO,SAAS;AAAA,UACjB;AAAA,UACA,QAAM,eAAe,kBAAkB,WAAW,OAAO,SAAS,EAAE;AAAA,QACrE;AAAA,MAAA,OACM;AACN,oBAAY,UAAU;AAAA,MAAA;AAEX,kBAAA,eAAe,cAAc,WAAW,WAAW,WAAW,OAAO,WAAW,WAAW,IAAI;AAAA,IAAA;AAGrG,WAAA;AAAA,EAAA;AAAA,EAGR,OAAe,cAAc,WAAmC,WAAmB,WAA8C;AAC5H,QAAA,UAAU,WAAW,GAAG;AACpB,aAAA;AAAA,IAAA;AAED,WAAA,UAAU,KAAK,WAAW,SAAS;AAAA,EAAA;AAE5C;AAEA,MAAM,UAAU,CAAC,WAAmB,GAAG,OAAO,OAAO,CAAC,EAAE,YAAa,CAAA,GAAG,OAAO,UAAU,CAAC,CAAC;"}
|
|
@@ -16,7 +16,7 @@ class RequestResponseNormalizer {
|
|
|
16
16
|
const id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers);
|
|
17
17
|
subTreeDataStore.set(placeholder, id);
|
|
18
18
|
}
|
|
19
|
-
} else if (bindingCommon.EntityListSubTreeMarker) {
|
|
19
|
+
} else if (marker instanceof bindingCommon.EntityListSubTreeMarker) {
|
|
20
20
|
const subTreeListIds = /* @__PURE__ */ new Set();
|
|
21
21
|
if (!Array.isArray(data)) {
|
|
22
22
|
throw new bindingCommon.BindingError();
|
|
@@ -83,17 +83,33 @@ class RequestResponseNormalizer {
|
|
|
83
83
|
entityMap.set(id.uniqueValue, presentEntityData);
|
|
84
84
|
for (const [placeholder, field] of fields) {
|
|
85
85
|
const value = entityData[placeholder];
|
|
86
|
+
const metaFlags = {
|
|
87
|
+
readable: entityData._meta?.[field.parameters.field]?.readable ?? void 0,
|
|
88
|
+
updatable: entityData._meta?.[field.parameters.field]?.updatable ?? void 0
|
|
89
|
+
};
|
|
86
90
|
if (field instanceof bindingCommon.FieldMarker) {
|
|
87
|
-
presentEntityData.set(placeholder,
|
|
91
|
+
presentEntityData.set(placeholder, {
|
|
92
|
+
value,
|
|
93
|
+
...metaFlags
|
|
94
|
+
});
|
|
88
95
|
} else if (field instanceof bindingCommon.HasOneRelationMarker) {
|
|
89
96
|
if (value === null) {
|
|
90
|
-
presentEntityData.set(placeholder,
|
|
97
|
+
presentEntityData.set(placeholder, {
|
|
98
|
+
value: null,
|
|
99
|
+
...metaFlags
|
|
100
|
+
});
|
|
91
101
|
} else {
|
|
92
|
-
presentEntityData.set(placeholder,
|
|
102
|
+
presentEntityData.set(placeholder, {
|
|
103
|
+
value: this.processEntityData(entityMap, value, field.fields.markers),
|
|
104
|
+
...metaFlags
|
|
105
|
+
});
|
|
93
106
|
}
|
|
94
107
|
} else if (field instanceof bindingCommon.HasManyRelationMarker) {
|
|
95
|
-
const ids = presentEntityData.get(placeholder) ?? /* @__PURE__ */ new Set();
|
|
96
|
-
presentEntityData.set(placeholder,
|
|
108
|
+
const ids = presentEntityData.get(placeholder)?.value ?? /* @__PURE__ */ new Set();
|
|
109
|
+
presentEntityData.set(placeholder, {
|
|
110
|
+
value: ids,
|
|
111
|
+
...metaFlags
|
|
112
|
+
});
|
|
97
113
|
if (!(ids instanceof Set)) {
|
|
98
114
|
throw new bindingCommon.BindingError();
|
|
99
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.cjs","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore } from '../accessorTree'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, value)\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, null)\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers))\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder) ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, ids)\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":["EntitySubTreeMarker","BindingError","EntityListSubTreeMarker","assertNever","FieldMarker","HasOneRelationMarker","HasManyRelationMarker","id","PRIMARY_KEY_NAME","ServerId"],"mappings":";;;AAqBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkBA,cAAAA,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QAAA,OAC7B;AACF,cAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAIC,cAAAA,aAAa;AAAA,UAAA;AAExB,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACtE,2BAAA,IAAI,aAAa,EAAE;AAAA,QAAA;AAAA,iBAE3BC,cAAAA,yBAAyB;AAC7B,cAAA,qCAAqB,IAAc;AACzC,YAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACzB,gBAAM,IAAID,cAAAA,aAAa;AAAA,QAAA;AAExB,mBAAW,OAAO,MAAM;AACvB,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,KAAK,OAAO,OAAO,OAAO;AACvE,yBAAA,IAAI,GAAG,KAAK;AAAA,QAAA;AAEX,yBAAA,IAAI,aAAa,cAAc;AAAA,MAAA,OAC1C;AACN,cAAM,IAAIA,cAAAA,aAAa;AAAA,MAAA;AAAA,IACxB;AAAA,EACD;AA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S,YAAY,WAAW,UAAU;AAAA,EAAA;AAEvD;;"}
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.cjs","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (marker instanceof EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData: SingleEntityPersistedData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":["EntitySubTreeMarker","BindingError","EntityListSubTreeMarker","assertNever","FieldMarker","HasOneRelationMarker","HasManyRelationMarker","id","PRIMARY_KEY_NAME","ServerId"],"mappings":";;;AAqBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkBA,cAAAA,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,O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QAAA,CACH;AAAA,MAAA,WACS,iBAAiBC,oCAAsB;AACjD,YAAI,UAAU,MAAM;AACnB,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO;AAAA,YACP,GAAG;AAAA,UAAA,CACH;AAAA,QAAA,OACK;AACN,4BAAkB,IAAI,aAAa;AAAA,YAClC,OAAO,KAAK,kBAAkB,WAAW,OAA6B,MAAM,OAAO,OAAO;AAAA,YAC1F,GAAG;AAAA,UAAA,CACH;AAAA,QAAA;AAAA,MACF,WACU,iBAAiBC,qCAAuB;AAClD,cAAM,MAAM,kBAAkB,IAAI,WAAW,GAAG,6BAAa,IAAI;AACjE,0BAAkB,IAAI,aAAa;AAAA,UAClC,OAAO;AAAA,UACP,GAAG;AAAA,QAAA,CACH;AACG,YAAA,EAAE,eAAe,MAAM;AAC1B,gBAAM,IAAIL,cAAAA,aAAa;AAAA,QAAA;AAExB,YAAI,MAAM;AACV,mBAAW,OAAO,OAA+B;AAChD,gBAAMM,MAAK,KAAK,kBAAkB,WAAW,KAAK,MAAM,OAAO,OAAO;AAClE,cAAA,IAAIA,IAAG,KAAK;AAAA,QAAA;AAAA,MACjB,OACM;AACN,cAAM,IAAI,MAAM;AAAA,MAAA;AAAA,IACjB;AAGM,WAAA;AAAA,EAAA;AAAA,EAGR,OAAe,UAAU,YAA0C;AAC5D,UAAA,aAAmC,WAAWC,8BAAgB;AAEpE,QAAI,eAAe,QAAW;AACvB,YAAA,IAAIP,cAAAA,aAAa,mEAAmE;AAAA,IAAA;AAG3F,WAAO,IAAIQ,cAAA,SAAS,YAAY,WAAW,UAAU;AAAA,EAAA;AAEvD;;"}
|
|
@@ -14,7 +14,7 @@ class RequestResponseNormalizer {
|
|
|
14
14
|
const id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers);
|
|
15
15
|
subTreeDataStore.set(placeholder, id);
|
|
16
16
|
}
|
|
17
|
-
} else if (EntityListSubTreeMarker) {
|
|
17
|
+
} else if (marker instanceof EntityListSubTreeMarker) {
|
|
18
18
|
const subTreeListIds = /* @__PURE__ */ new Set();
|
|
19
19
|
if (!Array.isArray(data)) {
|
|
20
20
|
throw new BindingError();
|
|
@@ -81,17 +81,33 @@ class RequestResponseNormalizer {
|
|
|
81
81
|
entityMap.set(id.uniqueValue, presentEntityData);
|
|
82
82
|
for (const [placeholder, field] of fields) {
|
|
83
83
|
const value = entityData[placeholder];
|
|
84
|
+
const metaFlags = {
|
|
85
|
+
readable: entityData._meta?.[field.parameters.field]?.readable ?? void 0,
|
|
86
|
+
updatable: entityData._meta?.[field.parameters.field]?.updatable ?? void 0
|
|
87
|
+
};
|
|
84
88
|
if (field instanceof FieldMarker) {
|
|
85
|
-
presentEntityData.set(placeholder,
|
|
89
|
+
presentEntityData.set(placeholder, {
|
|
90
|
+
value,
|
|
91
|
+
...metaFlags
|
|
92
|
+
});
|
|
86
93
|
} else if (field instanceof HasOneRelationMarker) {
|
|
87
94
|
if (value === null) {
|
|
88
|
-
presentEntityData.set(placeholder,
|
|
95
|
+
presentEntityData.set(placeholder, {
|
|
96
|
+
value: null,
|
|
97
|
+
...metaFlags
|
|
98
|
+
});
|
|
89
99
|
} else {
|
|
90
|
-
presentEntityData.set(placeholder,
|
|
100
|
+
presentEntityData.set(placeholder, {
|
|
101
|
+
value: this.processEntityData(entityMap, value, field.fields.markers),
|
|
102
|
+
...metaFlags
|
|
103
|
+
});
|
|
91
104
|
}
|
|
92
105
|
} else if (field instanceof HasManyRelationMarker) {
|
|
93
|
-
const ids = presentEntityData.get(placeholder) ?? /* @__PURE__ */ new Set();
|
|
94
|
-
presentEntityData.set(placeholder,
|
|
106
|
+
const ids = presentEntityData.get(placeholder)?.value ?? /* @__PURE__ */ new Set();
|
|
107
|
+
presentEntityData.set(placeholder, {
|
|
108
|
+
value: ids,
|
|
109
|
+
...metaFlags
|
|
110
|
+
});
|
|
95
111
|
if (!(ids instanceof Set)) {
|
|
96
112
|
throw new BindingError();
|
|
97
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore } from '../accessorTree'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder,
|
|
1
|
+
{"version":3,"file":"RequestResponseNormalizer.js","sources":["../../../../../packages/binding-legacy/src/core/RequestResponseNormalizer.ts"],"sourcesContent":["import {\n\tReceivedDataTree,\n\tReceivedEntityData,\n\tServerId,\n} from '@contember/binding-common'\nimport { BindingError } from '@contember/binding-common'\nimport { PRIMARY_KEY_NAME } from '@contember/binding-common'\nimport { EntityId } from '@contember/binding-common'\nimport {\n\tEntityFieldMarkers,\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n\tMarkerTreeRoot,\n} from '@contember/binding-common'\nimport { SubMutationOperation } from './MutationGenerator'\nimport { assertNever } from '@contember/binding-common'\nimport { NormalizedPersistedData, PersistedEntityDataStore, SingleEntityPersistedData } from '../accessorTree'\n\nexport class RequestResponseNormalizer {\n\tpublic static mergeInQueryResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\tmarkerTree: MarkerTreeRoot,\n\t): void {\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const [placeholder, marker] of markerTree.subTrees) {\n\t\t\tconst data = newPersistedData[placeholder] ?? null\n\t\t\tif (marker instanceof EntitySubTreeMarker) {\n\t\t\t\tif (data === null) {\n\t\t\t\t\tsubTreeDataStore.delete(placeholder)\n\t\t\t\t} else {\n\t\t\t\t\tif (Array.isArray(data)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, data, marker.fields.markers)\n\t\t\t\t\tsubTreeDataStore.set(placeholder, id)\n\t\t\t\t}\n\t\t\t} else if (marker instanceof EntityListSubTreeMarker) {\n\t\t\t\tconst subTreeListIds = new Set<EntityId>()\n\t\t\t\tif (!Array.isArray(data)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tfor (const row of data) {\n\t\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, row, marker.fields.markers)\n\t\t\t\t\tsubTreeListIds.add(id.value)\n\t\t\t\t}\n\t\t\t\tsubTreeDataStore.set(placeholder, subTreeListIds)\n\t\t\t} else {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static mergeInMutationResponse(\n\t\toriginal: NormalizedPersistedData,\n\t\tnewPersistedData: ReceivedDataTree,\n\t\toperations: SubMutationOperation[],\n\t): void {\n\n\t\tconst { subTreeDataStore, persistedEntityDataStore } = original\n\n\t\tfor (const operation of operations) {\n\t\t\tconst { subTreePlaceholder, subTreeType, alias } = operation\n\n\t\t\tconst receivedData = newPersistedData[alias]\n\n\t\t\t// probably multiple operations removing same entity, resulting in no data for some of them\n\t\t\tif (!receivedData) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (Array.isArray(receivedData)) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\n\t\t\tif (operation.type === 'update' || operation.type === 'create') {\n\t\t\t\tconst id = this.processEntityData(persistedEntityDataStore, receivedData, operation.markers)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, id)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (list instanceof Set) {\n\t\t\t\t\t\t// TODO this is somewhat dubious because we're essentially just guessing the order of the entities\n\t\t\t\t\t\t//\t\tand just carelessly put the new one at the end.\n\t\t\t\t\t\tlist.add(id.value)\n\t\t\t\t\t} else if (list === undefined) {\n\t\t\t\t\t\t// That's fine. This is probably just an isCreating sub-tree.\n\t\t\t\t\t\tsubTreeDataStore.set(subTreePlaceholder, new Set([id.value]))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else if (operation.type === 'delete') {\n\t\t\t\tconst id = this.extractId(receivedData)\n\t\t\t\t// TODO there are potentially some references to entityId that this whole process won't quite remove.\n\t\t\t\t//\t\tThat's a memory leak. Probably not particularly severe in most cases but still.\n\t\t\t\tpersistedEntityDataStore.delete(id.uniqueValue)\n\t\t\t\tif (subTreeType === 'single') {\n\t\t\t\t\tsubTreeDataStore.delete(subTreePlaceholder)\n\t\t\t\t} else if (subTreeType === 'list') {\n\t\t\t\t\tconst list = subTreeDataStore.get(subTreePlaceholder)\n\n\t\t\t\t\tif (!(list instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tlist.delete(id.value)\n\t\t\t\t} else {\n\t\t\t\t\treturn assertNever(subTreeType)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn assertNever(operation)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static processEntityData(entityMap: PersistedEntityDataStore, entityData: ReceivedEntityData, fields: EntityFieldMarkers): ServerId {\n\t\tconst id = this.extractId(entityData)\n\t\tconst presentEntityData: SingleEntityPersistedData = entityMap.get(id.uniqueValue) ?? new Map()\n\t\tentityMap.set(id.uniqueValue, presentEntityData)\n\n\t\tfor (const [placeholder, field] of fields) {\n\t\t\tconst value = entityData[placeholder]\n\t\t\tconst metaFlags = {\n\t\t\t\treadable: entityData._meta?.[field.parameters.field]?.readable ?? undefined,\n\t\t\t\tupdatable: entityData._meta?.[field.parameters.field]?.updatable ?? undefined,\n\t\t\t}\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tif (value === null) {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: null,\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t} else {\n\t\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\t\tvalue: this.processEntityData(entityMap, value as ReceivedEntityData, field.fields.markers),\n\t\t\t\t\t\t...metaFlags,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\tconst ids = presentEntityData.get(placeholder)?.value ?? new Set()\n\t\t\t\tpresentEntityData.set(placeholder, {\n\t\t\t\t\tvalue: ids,\n\t\t\t\t\t...metaFlags,\n\t\t\t\t})\n\t\t\t\tif (!(ids instanceof Set)) {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tids.clear()\n\t\t\t\tfor (const row of value as ReceivedEntityData[]) {\n\t\t\t\t\tconst id = this.processEntityData(entityMap, row, field.fields.markers)\n\t\t\t\t\tids.add(id.value)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthrow new Error()\n\t\t\t}\n\t\t}\n\n\t\treturn id\n\t}\n\n\tprivate static extractId(entityData: ReceivedEntityData): ServerId {\n\t\tconst primaryKey: EntityId | undefined = entityData[PRIMARY_KEY_NAME]\n\n\t\tif (primaryKey === undefined) {\n\t\t\tthrow new BindingError(`The server has responded with an entity that lacks a primary key.`)\n\t\t}\n\n\t\treturn new ServerId(primaryKey, entityData.__typename)\n\t}\n}\n"],"names":["id"],"mappings":";AAqBO,MAAM,0BAA0B;AAAA,EACtC,OAAc,qBACb,UACA,kBACA,YACO;AACD,UAAA,EAAE,kBAAkB,yBAAA,IAA6B;AAEvD,eAAW,CAAC,aAAa,MAAM,KAAK,WAAW,UAAU;AAClD,YAAA,OAAO,iBAAiB,WAAW,KAAK;AAC9C,UAAI,kBAAkB,qBAAqB;AAC1C,YAAI,SAAS,MAAM;AAClB,2BAAiB,OAAO,WAAW;AAAA,QAAA,OAC7B;AACF,cAAA,MAAM,QAAQ,IAAI,GAAG;AACxB,kBAAM,IAAI,aAAa;AAAA,UAAA;AAExB,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,MAAM,OAAO,OAAO,OAAO;AACtE,2BAAA,IAAI,aAAa,EAAE;AAAA,QAAA;AAAA,MACrC,WACU,kBAAkB,yBAAyB;AAC/C,cAAA,qCAAqB,IAAc;AACzC,YAAI,CAAC,MAAM,QAAQ,IAAI,GAAG;AACzB,gBAAM,IAAI,aAAa;AAAA,QAAA;AAExB,mBAAW,OAAO,MAAM;AACvB,gBAAM,KAAK,KAAK,kBAAkB,0BAA0B,KAAK,OAAO,OAAO,OAAO;AACvE,yBAAA,IAAI,GAAG,KAAK;AAAA,QAAA;AAEX,yBAAA,IAAI,aAAa,cAAc;AAAA,MAAA,OAC1C;AACN,cAAM,IAAI,aAAa;AAAA,MAAA;AAAA,I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AG,KAAK;AAAA,QAAA;AAAA,MACjB,OACM;AACN,cAAM,IAAI,MAAM;AAAA,MAAA;AAAA,IACjB;AAGM,WAAA;AAAA,EAAA;AAAA,EAGR,OAAe,UAAU,YAA0C;AAC5D,UAAA,aAAmC,WAAW,gBAAgB;AAEpE,QAAI,eAAe,QAAW;AACvB,YAAA,IAAI,aAAa,mEAAmE;AAAA,IAAA;AAG3F,WAAO,IAAI,SAAS,YAAY,WAAW,UAAU;AAAA,EAAA;AAEvD;"}
|
|
@@ -160,7 +160,7 @@ class StateInitializer {
|
|
|
160
160
|
const marker = getEntityMarker.getEntityMarker(state);
|
|
161
161
|
const pathBack = this.treeStore.getPathBackToParent(entityRealm);
|
|
162
162
|
for (const [placeholderName, field] of marker.fields.markers) {
|
|
163
|
-
const fieldDatum = persistedData?.get(placeholderName);
|
|
163
|
+
const fieldDatum = persistedData?.get(placeholderName)?.value;
|
|
164
164
|
if (field instanceof bindingCommon.FieldMarker) {
|
|
165
165
|
this.initializeFromFieldMarker(entityRealm, field, fieldDatum);
|
|
166
166
|
} else if (field instanceof bindingCommon.HasManyRelationMarker) {
|