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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +1 -1
  2. package/dist/binding.d.ts +45 -7
  3. package/dist/development/accessorPropagation/useHasEntity.js +9 -0
  4. package/dist/development/accessorPropagation/useHasEntity.js.map +1 -0
  5. package/dist/development/accessors/EntityListAccessor.js +3 -3
  6. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  7. package/dist/development/core/DataBinding.js +1 -1
  8. package/dist/development/core/DataBinding.js.map +1 -1
  9. package/dist/development/core/MarkerTreeGenerator.js +2 -2
  10. package/dist/development/core/MarkerTreeGenerator.js.map +1 -1
  11. package/dist/development/core/StateInitializer.js +63 -20
  12. package/dist/development/core/StateInitializer.js.map +1 -1
  13. package/dist/development/core/operations/ListOperations.js +7 -4
  14. package/dist/development/core/operations/ListOperations.js.map +1 -1
  15. package/dist/development/core/requestAliases/MutationAlias.js +1 -1
  16. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  17. package/dist/development/helperComponents/SugaredField.js.map +1 -1
  18. package/dist/development/index.js +2 -0
  19. package/dist/development/index.js.map +1 -1
  20. package/dist/development/queryLanguage/CacheStore.js +2 -1
  21. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  22. package/dist/development/queryLanguage/Parser.js +60 -0
  23. package/dist/development/queryLanguage/Parser.js.map +1 -1
  24. package/dist/development/queryLanguage/QueryLanguage.js +1 -0
  25. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  26. package/dist/development/queryLanguage/tokenList.js +5 -0
  27. package/dist/development/queryLanguage/tokenList.js.map +1 -1
  28. package/dist/production/accessorPropagation/useHasEntity.js +7 -0
  29. package/dist/production/accessorPropagation/useHasEntity.js.map +1 -0
  30. package/dist/production/accessors/EntityListAccessor.js +3 -3
  31. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  32. package/dist/production/core/DataBinding.js +1 -1
  33. package/dist/production/core/DataBinding.js.map +1 -1
  34. package/dist/production/core/MarkerTreeGenerator.js +2 -2
  35. package/dist/production/core/MarkerTreeGenerator.js.map +1 -1
  36. package/dist/production/core/StateInitializer.js +63 -20
  37. package/dist/production/core/StateInitializer.js.map +1 -1
  38. package/dist/production/core/operations/ListOperations.js +7 -4
  39. package/dist/production/core/operations/ListOperations.js.map +1 -1
  40. package/dist/production/core/requestAliases/MutationAlias.js +1 -1
  41. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  42. package/dist/production/helperComponents/SugaredField.js.map +1 -1
  43. package/dist/production/index.js +2 -0
  44. package/dist/production/index.js.map +1 -1
  45. package/dist/production/queryLanguage/CacheStore.js +2 -1
  46. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  47. package/dist/production/queryLanguage/Parser.js +60 -0
  48. package/dist/production/queryLanguage/Parser.js.map +1 -1
  49. package/dist/production/queryLanguage/QueryLanguage.js +1 -0
  50. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  51. package/dist/production/queryLanguage/tokenList.js +5 -0
  52. package/dist/production/queryLanguage/tokenList.js.map +1 -1
  53. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerGeneratedUuid, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tScalar,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { Config } from './Config'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\nimport { EventListenersStore } from '../treeParameters'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(this.accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.listOperations = new ListOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<string> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst stub: EntityRealmStateStub = {\n\t\t\ttype: 'entityRealmStub',\n\n\t\t\tblueprint,\n\t\t\tentity,\n\t\t\trealmKey,\n\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t}\n\t\tthis.registerEntityRealm(stub)\n\n\t\treturn stub\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.value),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.value)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.value\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerGeneratedUuid,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<string>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<string | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerGeneratedUuid(entityId) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: Scalar | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: false,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tfieldDatum: EntityFieldPersistedData | undefined,\n\t) {\n\t\tif (fieldDatum instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (fieldDatum instanceof ServerGeneratedUuid) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, fieldDatum),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<string>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field)\n\n\t\tif (targetField?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError() // This should have been validated elsewhere.\n\t\t}\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;uBAwC8B;AAAA,EAKtB,YACW,sBACA,qBACA,QACA,cACA,WAChB;AAVe;AACA;AACA;;;;;;SASX,kBAAkB,IAAI,gBAAgB,KAAK,sBAAsB,KAAK,cAAc,MAAM,KAAK;SAC/F,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;SAED,iBAAiB,IAAI,eACzB,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;AAAA;AAAA,EAIA,kBAAkB,MAAoE;QACxF;UACE,oBAAoB,KAAK,UAAU,qBAAqB,IAAI,KAAK;QAEnE,gBAAgB,yBAAyB;YACtC,qBAAkC,6BAA6B,MAAM,oBAAoB,IAAI;qBACpF,KAAK,0BACnB,EAAE,QAAQ,MAAM,QAAQ,UACxB,KAAK,YACL;AAAA,WAEK;qBACS,KAAK,uBACnB,KAAK,sBACJ,6BAA6B,sBAAsB,oBAAoB,IAAI,4BAC3E,KAAK,YACL;AAAA,QACC,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA;AAAA;WAML;AAAA;AAAA,EAGD,sBACN,IACA,YACA,WAC0C;UAKpC,SAAS,KAAK,sBAAsB,IAAI;UACxC,WAAW,kBAAkB,YAAY,IAAI;UAE7C,WAAW,KAAK,UAAU,iBAAiB,IAAI;QACjD,aAAa,QAAW;aACpB;AAAA;UAGF,OAA6B;AAAA,MAClC,MAAM;AAAA,MAEN;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa,MAAM,KAA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oBH,oCACP,QACA,OACA,oBACC;WACM,SAAS,IACf,MAAM,iBACN,KAAK,0BACJ,EAAE,QAAQ,OAAO,UACjB,KAAK,4BAA4B,QAAQ,QACzC;AAAA;AAAA,EAsBK,4BACP,aACA,OACa;UACP,cAAc,KAAK,UAAU,OAAO,eAAe,YAAY,OAAO,YAAY,MAAM,WAAW;QAErG,aAAa,eAAe,aAAa;YACtC,IAAI;AAAA;WAEJ,YAAY;AAAA;AAAA,EAGb,+BACN,OACA,YACC;QACG,eAAe,QAAW;;;UAGxB,cAAc,KAAK,uBAAuB;UAE1C,cAAc,aAAa;UAE3B,sBAAsB,KAAK,aAAa,kBAAkB,aAAa,EAAE,MAAM;QACjF,wBAAwB,UAAa,oBAAoB,SAAS,GAAG;YAClE,OAAO,kBAAkB;AAAA;AAAA;AAAA,EAI1B,mCAAmC,WAAuE;QAC5G,UAAU,SAAS,cAAc;YAC9B,sBAAqB,UAAU,OAAO,UAAU,OAAO,WAAW;YAClE,kBAAkB,qBAAoB,IAAI,EAAE,MAAM;YAClD,QAAkC,IAAI,oBAAoB,MAAM,UAAU,OAAO;UAEnF,oBAAoB,QAAW;cAC5B,IAAI,EAAE,MAAM,gBAAgB;AAAA;aAE5B;AAAA;UAGF,qBAAqB,UAAU,OAAO,WAAW;QACnD,uBAAuB,QAAW;aAC9B;AAAA;WAED,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,uCACP,WAC2C;UACrC,qBAAqB,UAAU,OAAO,WAAW;QAEnD,uBAAuB,QAAW;aAC9B;AAAA;WAED,oBAAoB,8BAA8B;AAAA;AAAA,EAGlD,4CACP,WACuC;UACjC,qBAAqB,UAAU,OAAO,WAAW;QAEnD,uBAAuB,QAAW;aAC9B;AAAA;WAED,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,kCAAkC,QAA0D;WAE5F;AAAA;AAAA;;"}
1
+ {"version":3,"file":"StateInitializer.js","sources":["../../../src/core/StateInitializer.ts"],"sourcesContent":["import { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, FieldAccessor } from '../accessors'\nimport { EntityFieldPersistedData, RuntimeId, ServerGeneratedUuid, UnpersistedEntityDummyId } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport {\n\tEntityListSubTreeMarker,\n\tEntitySubTreeMarker,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '../markers'\nimport { BijectiveIndexedMap } from '../structures'\nimport type {\n\tEntityEventListenerStore,\n\tEntityListEventListenerStore,\n\tEntityName,\n\tFieldEventListenerStore,\n\tFieldName,\n\tScalar,\n} from '../treeParameters'\nimport { assertNever } from '../utils'\nimport type { AccessorErrorManager } from './AccessorErrorManager'\nimport type { Config } from './Config'\nimport type { EventManager } from './EventManager'\nimport { EntityOperations, FieldOperations, ListOperations } from './operations'\nimport { RealmKeyGenerator } from './RealmKeyGenerator'\nimport {\n\tEntityListBlueprint,\n\tEntityListState,\n\tEntityRealmBlueprint,\n\tEntityRealmState,\n\tEntityRealmStateStub,\n\tEntityState,\n\tFieldState,\n\tgetEntityMarker,\n\tRootStateNode,\n} from './state'\nimport { TreeParameterMerger } from './TreeParameterMerger'\nimport type { TreeStore } from './TreeStore'\nimport { EventListenersStore } from '../treeParameters'\n\nexport class StateInitializer {\n\tprivate readonly fieldOperations: FieldOperations\n\tprivate readonly entityOperations: EntityOperations\n\tprivate readonly listOperations: ListOperations\n\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly config: Config,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {\n\t\tthis.fieldOperations = new FieldOperations(this.accessorErrorManager, this.eventManager, this, this.treeStore)\n\t\tthis.entityOperations = new EntityOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.listOperations = new ListOperations(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis,\n\t\t\tthis.treeStore,\n\t\t)\n\t}\n\n\tpublic initializeSubTree(tree: EntitySubTreeMarker | EntityListSubTreeMarker): RootStateNode {\n\t\tlet subTreeState: RootStateNode\n\t\tconst persistedRootData = this.treeStore.subTreePersistedData.get(tree.placeholderName)\n\n\t\tif (tree instanceof EntityListSubTreeMarker) {\n\t\t\tconst persistedEntityIds: Set<string> = persistedRootData instanceof Set ? persistedRootData : new Set()\n\t\t\tsubTreeState = this.initializeEntityListState(\n\t\t\t\t{ marker: tree, parent: undefined },\n\t\t\t\ttree.entityName,\n\t\t\t\tpersistedEntityIds,\n\t\t\t)\n\t\t} else {\n\t\t\tsubTreeState = this.materializeEntityRealm(\n\t\t\t\tthis.initializeEntityRealm(\n\t\t\t\t\tpersistedRootData instanceof ServerGeneratedUuid ? persistedRootData : new UnpersistedEntityDummyId(),\n\t\t\t\t\ttree.entityName,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: 'subTree',\n\t\t\t\t\t\tmarker: tree,\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t)\n\t\t}\n\n\t\treturn subTreeState\n\t}\n\n\tpublic initializeEntityRealm(\n\t\tid: RuntimeId,\n\t\tentityName: EntityName,\n\t\tblueprint: EntityRealmBlueprint,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t): EntityRealmState | EntityRealmStateStub {\n\t\t// This is counter-intuitive a bit. The method can also return an EntityRealmState, not just a stub.\n\t\t// The reason is so that each call-site can just default to trying to initialize a stub without having to keep\n\t\t// in mind that the realm might have already been initialized.\n\n\t\tconst entity = this.initializeEntityState(id, entityName)\n\t\tconst realmKey = RealmKeyGenerator.getRealmKey(id, blueprint)\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tif (!copyFrom || copyFrom.type !== 'entityRealm') {\n\t\t\tconst stub: EntityRealmStateStub = {\n\t\t\t\ttype: 'entityRealmStub',\n\n\t\t\t\tblueprint,\n\t\t\t\tentity,\n\t\t\t\trealmKey,\n\t\t\t\tgetAccessor: () => this.materializeEntityRealm(stub).getAccessor(),\n\t\t\t}\n\t\t\tthis.registerEntityRealm(stub)\n\n\t\t\treturn stub\n\t\t}\n\t\tconst realm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(realm)\n\n\t\tconst marker = getEntityMarker(realm)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(realm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\tif (!value || value.type !== 'field') {\n\t\t\t\t\tthrow new BindingError()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromFieldMarker(realm, field, value.value)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// todo: get from copyFrom\n\t\t\t\tthis.initializeFromHasManyRelationMarker(realm, field, new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tlet subCopyFrom: EntityRealmState | undefined = undefined\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\tconst value = copyFrom.children.get(placeholderName)\n\t\t\t\t\tif (!value || (value.type !== 'entityRealm' && value.type !== 'entityRealmStub')) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tif (value.type === 'entityRealm') {\n\t\t\t\t\t\tsubCopyFrom = value\n\t\t\t\t\t\truntimeId = value.entity.id\n\t\t\t\t\t} else {\n\t\t\t\t\t\truntimeId = new UnpersistedEntityDummyId()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(realm, field, runtimeId, subCopyFrom)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(realm)\n\t\treturn realm\n\t}\n\n\tprivate createEntityRealm(blueprint: EntityRealmBlueprint, realmKey: string, entity: EntityState): EntityRealmState {\n\t\tconst entityRealm: EntityRealmState = {\n\t\t\ttype: 'entityRealm',\n\n\t\t\tblueprint,\n\t\t\trealmKey,\n\t\t\tentity,\n\n\t\t\taccessor: undefined,\n\t\t\tchildren: new Map(),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\terrors: undefined,\n\t\t\teventListeners: this.initializeEntityEventListenerStore(blueprint),\n\t\t\tfieldsWithPendingConnectionUpdates: undefined,\n\t\t\tplannedHasOneDeletions: undefined,\n\t\t\tunpersistedChangesCount: 0,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityRealm.accessor === undefined) {\n\t\t\t\t\tconst entity = entityRealm.entity\n\t\t\t\t\tentityRealm.accessor = new EntityAccessor(\n\t\t\t\t\t\tentityRealm,\n\t\t\t\t\t\tthis.entityOperations,\n\t\t\t\t\t\tentity.id,\n\t\t\t\t\t\tentityRealm.realmKey,\n\t\t\t\t\t\tentity.entityName,\n\n\t\t\t\t\t\t// We're technically exposing more info in runtime than we'd like but that way we don't have to allocate and\n\t\t\t\t\t\t// keep in sync two copies of the same data. TS hides the extra info anyway.\n\t\t\t\t\t\tentityRealm.children,\n\t\t\t\t\t\tthis.treeStore.persistedEntityData.get(entity.id.value),\n\t\t\t\t\t\tentityRealm.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityRealm.errors,\n\t\t\t\t\t\tgetEntityMarker(entityRealm).environment,\n\t\t\t\t\t\tentityRealm.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityRealm.accessor\n\t\t\t},\n\t\t}\n\t\treturn entityRealm\n\t}\n\n\tprivate materializeEntityRealm(state: EntityRealmState | EntityRealmStateStub): EntityRealmState {\n\t\tif (state.type === 'entityRealm') {\n\t\t\treturn state\n\t\t}\n\t\tconst { realmKey, entity, blueprint } = state\n\n\t\tconst existing = this.treeStore.entityRealmStore.get(realmKey)\n\t\tif (existing !== undefined && existing.type === 'entityRealm') {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityRealm = this.createEntityRealm(blueprint, realmKey, entity)\n\n\t\tthis.registerEntityRealm(entityRealm)\n\n\t\t// if (blueprint.creationParameters.forceCreation && !entity.id.existsOnServer) {\n\t\t// \tentityRealm.unpersistedChangesCount += 1\n\t\t// }\n\n\t\tconst persistedData = this.treeStore.persistedEntityData.get(entity.id.value)\n\n\t\tconst marker = getEntityMarker(state)\n\t\tconst pathBack = this.treeStore.getPathBackToParent(entityRealm)\n\n\t\tfor (const [placeholderName, field] of marker.fields.markers) {\n\t\t\tconst fieldDatum = persistedData?.get(placeholderName)\n\n\t\t\tif (field instanceof FieldMarker) {\n\t\t\t\tthis.initializeFromFieldMarker(entityRealm, field, fieldDatum)\n\t\t\t} else if (field instanceof HasManyRelationMarker) {\n\t\t\t\t// if (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t// \t// TODO this is probably wrong?\n\t\t\t\t// \tconst ids = pathBack.parent.children.get(field.placeholderName)\n\t\t\t\t// \tconst newData = this.treeStore.persistedEntityData.get(pathBack.parent.entity.id.value)\n\t\t\t\t// \tconsole.log('many?', pathBack, field, entityRealm, fieldDatum, ids)\n\t\t\t\t// }\n\t\t\t\tthis.initializeFromHasManyRelationMarker(entityRealm, field, fieldDatum instanceof Set ? fieldDatum : new Set())\n\t\t\t} else if (field instanceof HasOneRelationMarker) {\n\t\t\t\tlet runtimeId: RuntimeId\n\t\t\t\tif (pathBack?.fieldBackToParent === field.parameters.field) {\n\t\t\t\t\truntimeId = pathBack.parent.entity.id\n\t\t\t\t} else {\n\t\t\t\t\truntimeId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t\t\t}\n\t\t\t\tthis.initializeFromHasOneRelationMarker(entityRealm, field, runtimeId)\n\t\t\t} else {\n\t\t\t\tassertNever(field)\n\t\t\t}\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityRealm)\n\n\t\treturn entityRealm\n\t}\n\n\tprivate registerEntityRealm(entityRealm: EntityRealmState | EntityRealmStateStub) {\n\t\tconst { realmKey, blueprint, entity } = entityRealm\n\n\t\tthis.treeStore.entityRealmStore.set(entityRealm.realmKey, entityRealm)\n\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tblueprint.parent.children.set(entity.id.value, entityRealm)\n\t\t} else if (blueprint.type === 'hasOne') {\n\t\t\tblueprint.parent.children.set(blueprint.marker.placeholderName, entityRealm)\n\t\t}\n\t\tentity.realms.set(realmKey, entityRealm)\n\t}\n\n\tpublic initializeEntityState(id: RuntimeId, entityName: EntityName): EntityState {\n\t\tconst entityId = id.value\n\n\t\tconst existing = this.treeStore.entityStore.get(entityId)\n\t\tif (existing !== undefined) {\n\t\t\treturn existing\n\t\t}\n\n\t\tconst entityState: EntityState = {\n\t\t\tentityName,\n\t\t\thasIdSetInStone: id instanceof ServerGeneratedUuid,\n\t\t\tid,\n\t\t\tisScheduledForDeletion: false,\n\t\t\tmaidenId: id instanceof UnpersistedEntityDummyId ? id : undefined,\n\t\t\trealms: new Map(),\n\t\t}\n\t\tthis.treeStore.entityStore.set(entityId, entityState)\n\n\t\treturn entityState\n\t}\n\n\tprivate initializeEntityListState(\n\t\tblueprint: EntityListBlueprint,\n\t\tentityName: EntityName,\n\t\tinitialEntityIds: Set<string>,\n\t): EntityListState {\n\t\tconst entityListState: EntityListState = {\n\t\t\ttype: 'entityList',\n\t\t\taccessor: undefined,\n\t\t\tblueprint,\n\t\t\tchildren: new BijectiveIndexedMap(realm => realm.entity.id.value),\n\t\t\tchildrenWithPendingUpdates: undefined,\n\t\t\tentityName,\n\t\t\teventListeners: this.initializeEntityListEventListenerStore(blueprint),\n\t\t\tchildEventListeners: this.initializeEntityListChildEventListenerStore(blueprint),\n\t\t\terrors: undefined,\n\t\t\tplannedRemovals: undefined,\n\t\t\tunpersistedChangesCount: 0, // TODO force creation?\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (entityListState.accessor === undefined) {\n\t\t\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(entityListState)\n\t\t\t\t\tentityListState.accessor = new EntityListAccessor(\n\t\t\t\t\t\tentityListState,\n\t\t\t\t\t\tthis.listOperations,\n\t\t\t\t\t\tentityListState.children,\n\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\tentityListState.unpersistedChangesCount !== 0,\n\t\t\t\t\t\tentityListState.errors,\n\t\t\t\t\t\tentityListState.blueprint.marker.environment,\n\t\t\t\t\t\tentityListState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn entityListState.accessor\n\t\t\t},\n\t\t}\n\n\t\tconst initialData: Iterable<string | undefined> =\n\t\t\tinitialEntityIds.size === 0\n\t\t\t\t? Array.from({ length: blueprint.marker.parameters.initialEntityCount })\n\t\t\t\t: initialEntityIds\n\t\tfor (const entityId of initialData) {\n\t\t\tthis.initializeEntityRealm(\n\t\t\t\tentityId ? new ServerGeneratedUuid(entityId) : new UnpersistedEntityDummyId(),\n\t\t\t\tentityListState.entityName,\n\t\t\t\t{\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: entityListState,\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(entityListState)\n\n\t\treturn entityListState\n\t}\n\n\tprivate initializeFieldState(\n\t\tparent: EntityRealmState,\n\t\tplaceholderName: FieldName,\n\t\tfieldMarker: FieldMarker,\n\t\tpersistedValue: Scalar | undefined,\n\t): FieldState {\n\t\tconst resolvedFieldValue = persistedValue ?? fieldMarker.defaultValue ?? null\n\n\t\tconst fieldState: FieldState = {\n\t\t\ttype: 'field',\n\t\t\taccessor: undefined,\n\t\t\tfieldMarker,\n\t\t\tplaceholderName,\n\t\t\tpersistedValue,\n\t\t\tparent,\n\t\t\tvalue: resolvedFieldValue,\n\t\t\teventListeners: this.initializeFieldEventListenerStore(fieldMarker),\n\t\t\terrors: undefined,\n\t\t\ttouchLog: undefined,\n\t\t\thasUnpersistedChanges: false,\n\t\t\tgetAccessor: () => {\n\t\t\t\tif (fieldState.accessor === undefined) {\n\t\t\t\t\tfieldState.accessor = new FieldAccessor(\n\t\t\t\t\t\tfieldState,\n\t\t\t\t\t\tthis.fieldOperations,\n\t\t\t\t\t\tfieldState.placeholderName,\n\t\t\t\t\t\tfieldState.value,\n\t\t\t\t\t\tfieldState.persistedValue === undefined ? null : fieldState.persistedValue,\n\t\t\t\t\t\tfieldState.fieldMarker.defaultValue,\n\t\t\t\t\t\tfieldState.errors,\n\t\t\t\t\t\tfieldState.hasUnpersistedChanges,\n\t\t\t\t\t\tfieldState.touchLog,\n\t\t\t\t\t\tfieldState.getAccessor,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\treturn fieldState.accessor\n\t\t\t},\n\t\t}\n\n\t\tthis.eventManager.registerNewlyInitialized(fieldState)\n\t\treturn fieldState\n\t}\n\n\tprivate initializeFromFieldMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: FieldMarker,\n\t\tfieldDatum: EntityFieldPersistedData | undefined,\n\t) {\n\t\tif (fieldDatum instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a collection of referenced entities where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t\t)\n\t\t}\n\t\tif (fieldDatum instanceof ServerGeneratedUuid) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`Received a referenced entity where a single '${field.fieldName}' field was expected. ` +\n\t\t\t\t\t`Perhaps you wanted to use <HasOne />?`,\n\t\t\t)\n\t\t}\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeFieldState(parent, field.placeholderName, field, fieldDatum),\n\t\t)\n\t}\n\n\tprivate initializeFromHasOneRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasOneRelationMarker,\n\t\tentityId: RuntimeId,\n\t\tcopyFrom?: EntityRealmState | EntityRealmStateStub,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityRealm(entityId, this.getRelationTargetEntityName(parent, field), {\n\t\t\t\ttype: 'hasOne',\n\t\t\t\tparent,\n\t\t\t\tmarker: field,\n\t\t\t}, copyFrom),\n\t\t)\n\t\t// if (fieldDatum instanceof ServerGeneratedUuid || fieldDatum === null || fieldDatum === undefined) {\n\t\t// \tconst entityId = fieldDatum instanceof ServerGeneratedUuid ? fieldDatum : new UnpersistedEntityDummyId()\n\t\t//\n\t\t//\n\t\t// } else if (fieldDatum instanceof Set) {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a collection of entities for field '${relation.field}' where a single entity was expected. ` +\n\t\t// \t\t\t`Perhaps you wanted to use a <Repeater />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a single entity was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate initializeFromHasManyRelationMarker(\n\t\tparent: EntityRealmState,\n\t\tfield: HasManyRelationMarker,\n\t\tpersistedEntityIds: Set<string>,\n\t) {\n\t\tparent.children.set(\n\t\t\tfield.placeholderName,\n\t\t\tthis.initializeEntityListState(\n\t\t\t\t{ marker: field, parent },\n\t\t\t\tthis.getRelationTargetEntityName(parent, field),\n\t\t\t\tpersistedEntityIds,\n\t\t\t),\n\t\t)\n\t\t// const relation = field.parameters\n\t\t//\n\t\t// if (fieldDatum === undefined || fieldDatum instanceof Set) {\n\t\t//\n\t\t// } else if (typeof fieldDatum === 'object') {\n\t\t// \t// Intentionally allowing `fieldDatum === null` here as well since this should only happen when a *hasOne\n\t\t// \t// relation is unlinked, e.g. a Person does not have a linked Nationality.\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a referenced entity for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you wanted to use a <HasOne />?`,\n\t\t// \t)\n\t\t// } else {\n\t\t// \tthrow new BindingError(\n\t\t// \t\t`Received a scalar value for field '${relation.field}' where a collection of entities was expected.` +\n\t\t// \t\t\t`Perhaps you meant to use a variant of <Field />?`,\n\t\t// \t)\n\t\t// }\n\t}\n\n\tprivate getRelationTargetEntityName(\n\t\tentityRealm: EntityRealmState,\n\t\tfield: HasOneRelationMarker | HasManyRelationMarker,\n\t): EntityName {\n\t\tconst targetField = this.treeStore.schema.getEntityField(entityRealm.entity.entityName, field.parameters.field)\n\n\t\tif (targetField?.__typename !== '_Relation') {\n\t\t\tthrow new BindingError() // This should have been validated elsewhere.\n\t\t}\n\t\treturn targetField.targetEntity\n\t}\n\n\tpublic runImmediateUserInitialization(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tinitialize: EntityAccessor.BatchUpdatesHandler | undefined,\n\t) {\n\t\tif (initialize === undefined) {\n\t\t\treturn\n\t\t}\n\t\tconst entityRealm = this.materializeEntityRealm(realm)\n\n\t\trealm.getAccessor().batchUpdates(initialize)\n\n\t\tconst initializeListeners = this.eventManager.getEventListeners(entityRealm, { type: 'initialize' })\n\t\tif (initializeListeners === undefined || initializeListeners.size === 0) {\n\t\t\trealm.entity.hasIdSetInStone = true\n\t\t}\n\t}\n\n\tpublic initializeEntityEventListenerStore(blueprint: EntityRealmBlueprint): EntityEventListenerStore | undefined {\n\t\tif (blueprint.type === 'listEntity') {\n\t\t\tconst blueprintListeners = blueprint.parent.blueprint.marker.parameters.childEventListeners\n\t\t\tconst childInitialize = blueprintListeners?.get({ type: 'initialize' })\n\t\t\tconst store: EntityEventListenerStore = new EventListenersStore(() => blueprint.parent.childEventListeners)\n\n\t\t\tif (childInitialize !== undefined) {\n\t\t\t\tstore.set({ type: 'initialize' }, childInitialize)\n\t\t\t}\n\t\t\treturn store\n\t\t}\n\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityListEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.eventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneEntityListEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeEntityListChildEventListenerStore(\n\t\tblueprint: EntityListBlueprint,\n\t): EntityEventListenerStore | undefined {\n\t\tconst blueprintListeners = blueprint.marker.parameters.childEventListeners\n\n\t\tif (blueprintListeners === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn TreeParameterMerger.cloneSingleEntityEventListeners(blueprintListeners)\n\t}\n\n\tprivate initializeFieldEventListenerStore(marker: FieldMarker): FieldEventListenerStore | undefined {\n\t\t// TODO !!!\n\t\treturn undefined\n\t}\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;uBAwC8B;AAAA,EAKtB,YACW,sBACA,qBACA,QACA,cACA,WAChB;AAVe;AACA;AACA;;;;;;SASX,kBAAkB,IAAI,gBAAgB,KAAK,sBAAsB,KAAK,cAAc,MAAM,KAAK;SAC/F,mBAAmB,IAAI,iBAC3B,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;SAED,iBAAiB,IAAI,eACzB,KAAK,sBACL,KAAK,qBACL,KAAK,cACL,MACA,KAAK;AAAA;AAAA,EAIA,kBAAkB,MAAoE;QACxF;UACE,oBAAoB,KAAK,UA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oB,8BAA8B;AAAA;AAAA,EAGlD,4CACP,WACuC;UACjC,qBAAqB,UAAU,OAAO,WAAW;QAEnD,uBAAuB,QAAW;aAC9B;AAAA;WAED,oBAAoB,gCAAgC;AAAA;AAAA,EAGpD,kCAAkC,QAA0D;WAE5F;AAAA;AAAA;;"}
@@ -69,7 +69,7 @@ ${error.message}
69
69
  this.stateInitializer.initializeEntityRealm(idToConnect, state.entityName, {
70
70
  type: "listEntity",
71
71
  parent: state
72
- });
72
+ }, stateToConnect);
73
73
  state.plannedRemovals?.delete(idToConnect.value);
74
74
  let changesDelta = 0;
75
75
  if (persistedEntityIds.has(idToConnect.value)) {
@@ -84,7 +84,7 @@ ${error.message}
84
84
  }
85
85
  });
86
86
  }
87
- disconnectEntity(listState, childEntity) {
87
+ disconnectEntity(listState, childEntity, options) {
88
88
  this.eventManager.syncOperation(() => {
89
89
  const persistedEntityIds = this.treeStore.getEntityListPersistedIds(listState);
90
90
  for (const state of StateIterator.eachSiblingRealmChild(this.treeStore, listState)) {
@@ -101,7 +101,9 @@ ${error.message}
101
101
  if (state.plannedRemovals === void 0) {
102
102
  state.plannedRemovals = new Map();
103
103
  }
104
- state.plannedRemovals.set(disconnectedChildIdValue, "disconnect");
104
+ if (!options.noPersist) {
105
+ state.plannedRemovals.set(disconnectedChildIdValue, "disconnect");
106
+ }
105
107
  } else if (disconnectedChildRealm.entity.id.existsOnServer) {
106
108
  changesDelta--;
107
109
  }
@@ -113,7 +115,7 @@ ${error.message}
113
115
  });
114
116
  }
115
117
  createNewEntity(outerState, initialize) {
116
- this.eventManager.syncOperation(() => {
118
+ return this.eventManager.syncOperation(() => {
117
119
  const id = new UnpersistedEntityDummyId();
118
120
  for (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {
119
121
  const newEntity = this.stateInitializer.initializeEntityRealm(id, state.entityName, {
@@ -123,6 +125,7 @@ ${error.message}
123
125
  this.stateInitializer.runImmediateUserInitialization(newEntity, initialize);
124
126
  this.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE);
125
127
  }
128
+ return id;
126
129
  });
127
130
  }
128
131
  getChildEntityById(state, id) {
@@ -1 +1 @@
1
- {"version":3,"file":"ListOperations.js","sources":["../../../../src/core/operations/ListOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, ErrorAccessor } from '../../accessors'\nimport { UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport { EntityListState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class ListOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(listState: EntityListState, error: ErrorAccessor.SugaredValidationError): () => void {\n\t\treturn this.accessorErrorManager.addError(listState, { type: 'validation', error })\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.childEventListeners === undefined) {\n\t\t\tstate.childEventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.childEventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityListState, performUpdates: EntityListAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntity(outerState: EntityListState, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(outerState)\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst idToConnect = stateToConnect.entity.id\n\n\t\t\t// TODO disable this at the top-level.\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tif (state.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`EntityListAccessor.connectEntity: Attempting to connect at an entity of type ` +\n\t\t\t\t\t\t\t`'${stateToConnect.entity.entityName}' but '${state.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(\n\t\t\t\t\t\tstate.blueprint.marker.fields,\n\t\t\t\t\t\tgetEntityMarker(stateToConnect).fields,\n\t\t\t\t\t)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Entity list: cannot connect entity with key '${entityToConnect.key}' because its fields are ` +\n\t\t\t\t\t\t\t\t`incompatible with entities found on this list. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t`Entity list located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\n\t\t\t\tif (state.children.has(idToConnect.value)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tthis.stateInitializer.initializeEntityRealm(idToConnect, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t})\n\n\t\t\t\tstate.plannedRemovals?.delete(idToConnect.value)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(idToConnect.value)) {\n\t\t\t\t\t// It was removed from the list but now we're adding it back.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t} else {\n\t\t\t\t\tchangesDelta++\n\t\t\t\t}\n\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntity(listState: EntityListState, childEntity: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\t// TODO disable this at the top-level.\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(listState)\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, listState)) {\n\t\t\t\tconst disconnectedChildIdValue = childEntity.id\n\t\t\t\tconst disconnectedChildRealm = state.children.get(disconnectedChildIdValue)\n\n\t\t\t\tif (disconnectedChildRealm === undefined) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Entity list doesn't include an entity with id '${disconnectedChildIdValue}' and so it cannot remove it.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(disconnectedChildRealm)\n\t\t\t\tlistState.children.delete(disconnectedChildIdValue)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(disconnectedChildIdValue)) {\n\t\t\t\t\tchangesDelta++\n\n\t\t\t\t\tif (state.plannedRemovals === undefined) {\n\t\t\t\t\t\tstate.plannedRemovals = new Map()\n\t\t\t\t\t}\n\t\t\t\t\tstate.plannedRemovals.set(disconnectedChildIdValue, 'disconnect')\n\t\t\t\t} else if (disconnectedChildRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// Disconnecting unpersisted entities doesn't constitute a change.\n\n\t\t\t\t\t// It wasn't on the list, then it was, and now we're removing it again.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t}\n\n\t\t\t\tif (disconnectedChildRealm.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever changes this child had caused.\n\t\t\t\t\tchangesDelta -= disconnectedChildRealm.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic createNewEntity(outerState: EntityListState, initialize: EntityAccessor.BatchUpdatesHandler | undefined) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\t// All siblings need to have the same id.\n\t\t\tconst id = new UnpersistedEntityDummyId()\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(id, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t})\n\n\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initialize)\n\n\t\t\t\t// The act of creating the entity doesn't constitute a change unless there's something inside to persist.\n\t\t\t\t// TODO forceCreate\n\t\t\t\t// TODO defaultValue\n\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic getChildEntityById(state: EntityListState, id: string) {\n\t\tconst realm = state.children.get(id)\n\t\tif (realm === undefined) {\n\t\t\tconst isRuntimeId = uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)\n\t\t\tif (isRuntimeId) {\n\t\t\t\tthrow new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`)\n\t\t\t}\n\t\t\tconst looksLikeKey = this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id)\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` +\n\t\t\t\t\t(looksLikeKey\n\t\t\t\t\t\t? `\\nThe supplied value appears to be an entity *key*, not an *id*. List accessors are indexed by ids ` +\n\t\t\t\t\t\t `and you can use \\`EntityAccessor.id\\` to obtain one. Keys, on the other hand, are globally unique and ` +\n\t\t\t\t\t\t `you can use \\`getEntityByKey\\` to get its EntityAccessor.`\n\t\t\t\t\t\t: ''),\n\t\t\t)\n\t\t}\n\t\treturn realm.getAccessor()\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;;;qBAe4B;AAAA,EACpB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;;;;;;;EAEK,SAAS,WAA4B,OAAyD;WAC7F,KAAK,qBAAqB,SAAS,WAAW,EAAE,MAAM,cAAc;AAAA;AAAA,EAGrE,iBACN,OACA,OACA,UACC;QACG,MAAM,mBAAmB,QAAW;YACjC,iBAAiB,IAAI;AAAA;WAErB,MAAM,eAAe,IAAI,OAAO;AAAA;AAAA,EAGjC,sBACN,OACA,OACA,UACC;QACG,MAAM,wBAAwB,QAAW;YACtC,sBAAsB,IAAI;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;cACvC,yBAAyB,MAAM,SAAS,IAAI;YAE9C,2BAA2B,QAAW;gBACnC,IAAI,aACT,kDAAkD;AAAA;aAI/C,UAAU,eAAe;kBACpB,SAAS,OAAO;YAEtB,eAAe;YAEf,mBAAmB,IAAI,2BAA2B;;cAGjD,MAAM,oBAAoB,QAAW;kBAClC,kBAAkB,IAAI;AAAA;gBAEvB,gBAAgB,IAAI,0BAA0B;AAAA,mBAC1C,uBAAuB,OAAO,GAAG,gBAAgB;;;YAOxD,uBAAuB,SAAS,eAAe;0BAElC,uBAAuB;AAAA;aAGnC,aAAa,oBAAoB,OAAO;AAAA;AAAA;AAAA;AAAA,EAKzC,gBAAgB,YAA6B,YAA4D;SAC1G,aAAa,cAAc,MAAM;YAE/B,KAAK,IAAI;iBAEJ,SAAS,cAAc,sBAAsB,KAAK,WAAW,aAAa;cAC9E,YAAY,KAAK,iBAAiB,sBAAsB,IAAI,MAAM,YAAY;AAAA,UACnF,MAAM;AAAA,UACN,QAAQ;AAAA;aAGJ,iBAAiB,+BAA+B,WAAW;aAK3D,aAAa,oBAAoB,OAAO,aAAa;AAAA;AAAA;AAAA;AAAA,EAKtD,mBAAmB,OAAwB,IAAY;UACvD,QAAQ,MAAM,SAAS,IAAI;QAC7B,UAAU,QAAW;YAClB,cAAcA,SAAa,OAAO,yBAAyB,eAAe;UAC5E,aAAa;cACV,IAAI,aAAa,kDAAkD;AAAA;YAEpE,eAAe,KAAK,UAAU,iBAAiB,IAAI,OAAO,kBAAkB,uBAAuB;YACnG,IAAI,aACT,kDAAkD,qDAE9C;AAAA,oQAGA;AAAA;WAGC,MAAM;AAAA;AAAA;;"}
1
+ {"version":3,"file":"ListOperations.js","sources":["../../../../src/core/operations/ListOperations.ts"],"sourcesContent":["import { validate as uuidValidate } from 'uuid'\nimport type { BatchUpdatesOptions, EntityAccessor, EntityListAccessor, ErrorAccessor } from '../../accessors'\nimport { RuntimeId, UnpersistedEntityDummyId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { AccessorErrorManager } from '../AccessorErrorManager'\nimport { EventManager } from '../EventManager'\nimport { ErrorLocator, LocalizedBindingError } from '../exceptions'\nimport { MarkerComparator } from '../MarkerComparator'\nimport { RealmKeyGenerator } from '../RealmKeyGenerator'\nimport { EntityListState, getEntityMarker, StateIterator } from '../state'\nimport type { StateInitializer } from '../StateInitializer'\nimport type { TreeStore } from '../TreeStore'\nimport { OperationsHelpers } from './OperationsHelpers'\nimport { EventListenersStore } from '../../treeParameters'\n\nexport class ListOperations {\n\tpublic constructor(\n\t\tprivate readonly accessorErrorManager: AccessorErrorManager,\n\t\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions,\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic addError(listState: EntityListState, error: ErrorAccessor.SugaredValidationError): () => void {\n\t\treturn this.accessorErrorManager.addError(listState, { type: 'validation', error })\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\tif (state.eventListeners === undefined) {\n\t\t\tstate.eventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.eventListeners.add(event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\tif (state.childEventListeners === undefined) {\n\t\t\tstate.childEventListeners = new EventListenersStore()\n\t\t}\n\t\treturn state.childEventListeners.add(event, listener)\n\t}\n\n\tpublic batchUpdates(state: EntityListState, performUpdates: EntityListAccessor.BatchUpdatesHandler) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tperformUpdates(state.getAccessor, this.batchUpdatesOptions)\n\t\t})\n\t}\n\n\tpublic connectEntity(outerState: EntityListState, entityToConnect: EntityAccessor) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(outerState)\n\t\t\tconst stateToConnect = OperationsHelpers.resolveAndPrepareEntityToConnect(this.treeStore, entityToConnect)\n\t\t\tconst idToConnect = stateToConnect.entity.id\n\n\t\t\t// TODO disable this at the top-level.\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tif (state.entityName !== stateToConnect.entity.entityName) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`EntityListAccessor.connectEntity: Attempting to connect at an entity of type ` +\n\t\t\t\t\t\t\t`'${stateToConnect.entity.entityName}' but '${state.entityName}' is expected.\\n\\n` +\n\t\t\t\t\t\t\t`Entity located at: ${ErrorLocator.locateInternalState(outerState)}.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tMarkerComparator.assertEntityMarkersSubsetOf(\n\t\t\t\t\t\tstate.blueprint.marker.fields,\n\t\t\t\t\t\tgetEntityMarker(stateToConnect).fields,\n\t\t\t\t\t)\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (error instanceof LocalizedBindingError) {\n\t\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t\t`Entity list: cannot connect entity with key '${entityToConnect.key}' because its fields are ` +\n\t\t\t\t\t\t\t\t`incompatible with entities found on this list. Make sure both trees are equivalent.\\n\\n` +\n\t\t\t\t\t\t\t\t`${error.message}\\n\\n` +\n\t\t\t\t\t\t\t\t(error.markerPath.length > 1\n\t\t\t\t\t\t\t\t\t? `Incompatibility found at: ${ErrorLocator.locateMarkerPath(error.markerPath)}.\\n\\n`\n\t\t\t\t\t\t\t\t\t: '') +\n\t\t\t\t\t\t\t\t`Entity list located at: ${ErrorLocator.locateInternalState(state)}.`,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t\tthrow error\n\t\t\t\t}\n\n\t\t\t\tif (state.children.has(idToConnect.value)) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tthis.stateInitializer.initializeEntityRealm(idToConnect, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t}, stateToConnect)\n\n\t\t\t\tstate.plannedRemovals?.delete(idToConnect.value)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(idToConnect.value)) {\n\t\t\t\t\t// It was removed from the list but now we're adding it back.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t} else {\n\t\t\t\t\tchangesDelta++\n\t\t\t\t}\n\t\t\t\tif (stateToConnect.type === 'entityRealm') {\n\t\t\t\t\tchangesDelta += stateToConnect.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectEntity(listState: EntityListState, childEntity: EntityAccessor, options: {noPersist?: boolean}) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\t// TODO disable this at the top-level.\n\t\t\tconst persistedEntityIds = this.treeStore.getEntityListPersistedIds(listState)\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, listState)) {\n\t\t\t\tconst disconnectedChildIdValue = childEntity.id\n\t\t\t\tconst disconnectedChildRealm = state.children.get(disconnectedChildIdValue)\n\n\t\t\t\tif (disconnectedChildRealm === undefined) {\n\t\t\t\t\tthrow new BindingError(\n\t\t\t\t\t\t`Entity list doesn't include an entity with id '${disconnectedChildIdValue}' and so it cannot remove it.`,\n\t\t\t\t\t)\n\t\t\t\t}\n\n\t\t\t\tthis.treeStore.disposeOfRealm(disconnectedChildRealm)\n\t\t\t\tlistState.children.delete(disconnectedChildIdValue)\n\n\t\t\t\tlet changesDelta = 0\n\n\t\t\t\tif (persistedEntityIds.has(disconnectedChildIdValue)) {\n\t\t\t\t\tchangesDelta++\n\n\t\t\t\t\tif (state.plannedRemovals === undefined) {\n\t\t\t\t\t\tstate.plannedRemovals = new Map()\n\t\t\t\t\t}\n\t\t\t\t\tif (!options.noPersist) {\n\t\t\t\t\t\tstate.plannedRemovals.set(disconnectedChildIdValue, 'disconnect')\n\t\t\t\t\t}\n\t\t\t\t} else if (disconnectedChildRealm.entity.id.existsOnServer) {\n\t\t\t\t\t// Disconnecting unpersisted entities doesn't constitute a change.\n\n\t\t\t\t\t// It wasn't on the list, then it was, and now we're removing it again.\n\t\t\t\t\tchangesDelta--\n\t\t\t\t}\n\n\t\t\t\tif (disconnectedChildRealm.type === 'entityRealm') {\n\t\t\t\t\t// Undoing whatever changes this child had caused.\n\t\t\t\t\tchangesDelta -= disconnectedChildRealm.unpersistedChangesCount\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.registerJustUpdated(state, changesDelta)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic createNewEntity(outerState: EntityListState, initialize: EntityAccessor.BatchUpdatesHandler | undefined): RuntimeId {\n\t\treturn this.eventManager.syncOperation((): RuntimeId => {\n\t\t\t// All siblings need to have the same id.\n\t\t\tconst id = new UnpersistedEntityDummyId()\n\n\t\t\tfor (const state of StateIterator.eachSiblingRealmChild(this.treeStore, outerState)) {\n\t\t\t\tconst newEntity = this.stateInitializer.initializeEntityRealm(id, state.entityName, {\n\t\t\t\t\ttype: 'listEntity',\n\t\t\t\t\tparent: state,\n\t\t\t\t})\n\n\t\t\t\tthis.stateInitializer.runImmediateUserInitialization(newEntity, initialize)\n\n\t\t\t\t// The act of creating the entity doesn't constitute a change unless there's something inside to persist.\n\t\t\t\t// TODO forceCreate\n\t\t\t\t// TODO defaultValue\n\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\treturn id\n\t\t})\n\t}\n\n\tpublic getChildEntityById(state: EntityListState, id: string) {\n\t\tconst realm = state.children.get(id)\n\t\tif (realm === undefined) {\n\t\t\tconst isRuntimeId = uuidValidate(id) || UnpersistedEntityDummyId.matchesDummyId(id)\n\t\t\tif (isRuntimeId) {\n\t\t\t\tthrow new BindingError(`EntityList: cannot retrieve an entity with id '${id}' as it is not on the list.`)\n\t\t\t}\n\t\t\tconst looksLikeKey = this.treeStore.entityRealmStore.has(id) || RealmKeyGenerator.vaguelyAppearsToBeAKey(id)\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityList: cannot retrieve an entity with id '${id}' because it's not a valid id.` +\n\t\t\t\t\t(looksLikeKey\n\t\t\t\t\t\t? `\\nThe supplied value appears to be an entity *key*, not an *id*. List accessors are indexed by ids ` +\n\t\t\t\t\t\t `and you can use \\`EntityAccessor.id\\` to obtain one. Keys, on the other hand, are globally unique and ` +\n\t\t\t\t\t\t `you can use \\`getEntityByKey\\` to get its EntityAccessor.`\n\t\t\t\t\t\t: ''),\n\t\t\t)\n\t\t}\n\t\treturn realm.getAccessor()\n\t}\n}\n"],"names":["uuidValidate"],"mappings":";;;;;;;;;;;;qBAe4B;AAAA,EACpB,YACW,sBACA,qBACA,cACA,kBACA,WAChB;;;;;;;EAEK,SAAS,WAA4B,OAAyD;WAC7F,KAAK,qBAAqB,SAAS,WAAW,EAAE,MAAM,cAAc;AAAA;AAAA,EAGrE,iBACN,OACA,OACA,UACC;QACG,MAAM,mBAAmB,QAAW;YACjC,iBAAiB,IAAI;AAAA;WAErB,MAAM,eAAe,IAAI,OAAO;AAAA;AAAA,EAGjC,sBACN,OACA,OACA,UACC;QACG,MAAM,wBAAwB,QAAW;YACtC,sBAAsB,IAAI;AAAA;WAE1B,MAAM,oBAAoB,IAAI,OAAO;AAAA;AAAA,EAGtC,aAAa,OAAwB,gBAAwD;SAC9F,aAAa,cAAc,MAAM;qBACtB,MAAM,aAAa,KAAK;AAAA;AAAA;AAAA,EAIlC,cAAc,YAA6B,iBAAiC;SAC7E,aAAa,cAAc,MAAM;YAC/B,qBAAq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kBAAkB,IAAI;AAAA;cAEzB,CAAC,QAAQ,WAAW;kBACjB,gBAAgB,IAAI,0BAA0B;AAAA;AAAA,mBAE3C,uBAAuB,OAAO,GAAG,gBAAgB;;;YAOxD,uBAAuB,SAAS,eAAe;0BAElC,uBAAuB;AAAA;aAGnC,aAAa,oBAAoB,OAAO;AAAA;AAAA;AAAA;AAAA,EAKzC,gBAAgB,YAA6B,YAAuE;WACnH,KAAK,aAAa,cAAc,MAAiB;YAEjD,KAAK,IAAI;iBAEJ,SAAS,cAAc,sBAAsB,KAAK,WAAW,aAAa;cAC9E,YAAY,KAAK,iBAAiB,sBAAsB,IAAI,MAAM,YAAY;AAAA,UACnF,MAAM;AAAA,UACN,QAAQ;AAAA;aAGJ,iBAAiB,+BAA+B,WAAW;aAK3D,aAAa,oBAAoB,OAAO,aAAa;AAAA;aAEpD;AAAA;AAAA;AAAA,EAIF,mBAAmB,OAAwB,IAAY;UACvD,QAAQ,MAAM,SAAS,IAAI;QAC7B,UAAU,QAAW;YAClB,cAAcA,SAAa,OAAO,yBAAyB,eAAe;UAC5E,aAAa;cACV,IAAI,aAAa,kDAAkD;AAAA;YAEpE,eAAe,KAAK,UAAU,iBAAiB,IAAI,OAAO,kBAAkB,uBAAuB;YACnG,IAAI,aACT,kDAAkD,qDAE9C;AAAA,oQAGA;AAAA;WAGC,MAAM;AAAA;AAAA;;"}
@@ -7,7 +7,7 @@ const aliasToUuidReplacement = "-";
7
7
  const standaloneUuidPrefix = uuidToAliasReplacement;
8
8
  class MutationAlias {
9
9
  static encodeTopLevel(operation) {
10
- const treeRootId = operation.treeRootId === void 0 ? "u" : `t${operation.treeRootId}t`;
10
+ const treeRootId = operation.treeRootId === void 0 ? "u" : `t${operation.treeRootId.replace("-", "_")}t`;
11
11
  const entityId = operation.entityId.replace(uuidToAliasRegex, uuidToAliasReplacement);
12
12
  const alias = `${treeRootId}${operation.subTreePlaceholder}__${operation.type}${operation.subTreeType}${entityId}`;
13
13
  return alias;
@@ -1 +1 @@
1
- {"version":3,"file":"MutationAlias.js","sources":["../../../../src/core/requestAliases/MutationAlias.ts"],"sourcesContent":["import type { RuntimeId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { PlaceholderName, TreeRootId } from '../../treeParameters'\nimport { mutationOperationSubTreeType } from './mutationOperationSubTreeType'\nimport type { mutationOperationType } from './mutationOperationType'\nimport type { TopLevelMutationOperation } from './TopLevelMutationOperation'\n\nconst mutationAliasRegex = /^(?:(u)|(t)([^t]+)t)(.+)__([cud])([sl])(.+)$/\n\nconst uuidToAliasRegex = /-/g\nconst uuidToAliasReplacement = '_'\n\nconst aliasToUuidRegex = /_/g\nconst aliasToUuidReplacement = '-'\n\n// This is just a random character we use to make sure the alias doesn't start with a number as UUIDs often do.\nconst standaloneUuidPrefix = uuidToAliasReplacement\n\nexport class MutationAlias {\n\tpublic static encodeTopLevel(operation: TopLevelMutationOperation): string {\n\t\tconst treeRootId = operation.treeRootId === undefined ? 'u' : `t${operation.treeRootId}t`\n\t\tconst entityId = operation.entityId.replace(uuidToAliasRegex, uuidToAliasReplacement)\n\n\t\tconst alias = `${treeRootId}${operation.subTreePlaceholder}__${operation.type}${operation.subTreeType}${entityId}`\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst matches = alias.match(mutationAliasRegex)\n\n\t\t\tif (!matches) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\n\t\treturn alias\n\t}\n\n\tpublic static decodeTopLevel(alias: string): TopLevelMutationOperation | undefined {\n\t\tconst matches = alias.match(mutationAliasRegex)\n\n\t\tif (!matches) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst treeRootId: TreeRootId | undefined = matches[1] === 'u' ? undefined : matches[3]\n\t\tconst subTreePlaceholder: PlaceholderName = matches[4]\n\t\tconst type = matches[5] as typeof mutationOperationType[keyof typeof mutationOperationType]\n\t\tconst subTreeType =\n\t\t\tmatches[6] === 's' ? mutationOperationSubTreeType.singleEntity : mutationOperationSubTreeType.entityList\n\t\tconst entityId = matches[7].replace(aliasToUuidRegex, aliasToUuidReplacement)\n\n\t\treturn {\n\t\t\ttreeRootId,\n\t\t\tsubTreePlaceholder,\n\t\t\ttype,\n\t\t\tsubTreeType,\n\t\t\tentityId,\n\t\t}\n\t}\n\n\tpublic static encodeEntityId(entityId: RuntimeId): string {\n\t\treturn `${standaloneUuidPrefix}${entityId.value.replace(uuidToAliasRegex, uuidToAliasReplacement)}`\n\t}\n\n\tpublic static decodeEntityId(alias: string): RuntimeId['value'] {\n\t\treturn `${alias.substring(standaloneUuidPrefix.length).replace(aliasToUuidRegex, aliasToUuidReplacement)}`\n\t}\n}\n"],"names":[],"mappings":";AAOA,MAAM,qBAAqB;AAE3B,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAE/B,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAG/B,MAAM,uBAAuB;oBAEF;AAAA,SACZ,eAAe,WAA8C;UACpE,aAAa,UAAU,eAAe,SAAY,MAAM,IAAI,UAAU;UACtE,WAAW,UAAU,SAAS,QAAQ,kBAAkB;UAExD,QAAQ,GAAG,aAAa,UAAU,uBAAuB,UAAU,OAAO,UAAU,cAAc;WAUjG;AAAA;AAAA,SAGM,eAAe,OAAsD;UAC5E,UAAU,MAAM,MAAM;QAExB,CAAC,SAAS;aACN;AAAA;UAEF,aAAqC,QAAQ,OAAO,MAAM,SAAY,QAAQ;UAC9E,qBAAsC,QAAQ;UAC9C,OAAO,QAAQ;UACf,cACL,QAAQ,OAAO,MAAM,6BAA6B,eAAe,6BAA6B;UACzF,WAAW,QAAQ,GAAG,QAAQ,kBAAkB;WAE/C;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA;AAAA,SAIY,eAAe,UAA6B;WAClD,GAAG,uBAAuB,SAAS,MAAM,QAAQ,kBAAkB;AAAA;AAAA,SAG7D,eAAe,OAAmC;WACxD,GAAG,MAAM,UAAU,qBAAqB,QAAQ,QAAQ,kBAAkB;AAAA;AAAA;;"}
1
+ {"version":3,"file":"MutationAlias.js","sources":["../../../../src/core/requestAliases/MutationAlias.ts"],"sourcesContent":["import type { RuntimeId } from '../../accessorTree'\nimport { BindingError } from '../../BindingError'\nimport type { PlaceholderName, TreeRootId } from '../../treeParameters'\nimport { mutationOperationSubTreeType } from './mutationOperationSubTreeType'\nimport type { mutationOperationType } from './mutationOperationType'\nimport type { TopLevelMutationOperation } from './TopLevelMutationOperation'\n\nconst mutationAliasRegex = /^(?:(u)|(t)([^t]+)t)(.+)__([cud])([sl])(.+)$/\n\nconst uuidToAliasRegex = /-/g\nconst uuidToAliasReplacement = '_'\n\nconst aliasToUuidRegex = /_/g\nconst aliasToUuidReplacement = '-'\n\n// This is just a random character we use to make sure the alias doesn't start with a number as UUIDs often do.\nconst standaloneUuidPrefix = uuidToAliasReplacement\n\nexport class MutationAlias {\n\tpublic static encodeTopLevel(operation: TopLevelMutationOperation): string {\n\t\tconst treeRootId = operation.treeRootId === undefined ? 'u' : `t${operation.treeRootId.replace('-', '_')}t`\n\t\tconst entityId = operation.entityId.replace(uuidToAliasRegex, uuidToAliasReplacement)\n\n\t\tconst alias = `${treeRootId}${operation.subTreePlaceholder}__${operation.type}${operation.subTreeType}${entityId}`\n\n\t\tif (import.meta.env.DEV) {\n\t\t\tconst matches = alias.match(mutationAliasRegex)\n\n\t\t\tif (!matches) {\n\t\t\t\tthrow new BindingError()\n\t\t\t}\n\t\t}\n\n\t\treturn alias\n\t}\n\n\tpublic static decodeTopLevel(alias: string): TopLevelMutationOperation | undefined {\n\t\tconst matches = alias.match(mutationAliasRegex)\n\n\t\tif (!matches) {\n\t\t\treturn undefined\n\t\t}\n\t\tconst treeRootId: TreeRootId | undefined = matches[1] === 'u' ? undefined : matches[3]\n\t\tconst subTreePlaceholder: PlaceholderName = matches[4]\n\t\tconst type = matches[5] as typeof mutationOperationType[keyof typeof mutationOperationType]\n\t\tconst subTreeType =\n\t\t\tmatches[6] === 's' ? mutationOperationSubTreeType.singleEntity : mutationOperationSubTreeType.entityList\n\t\tconst entityId = matches[7].replace(aliasToUuidRegex, aliasToUuidReplacement)\n\n\t\treturn {\n\t\t\ttreeRootId,\n\t\t\tsubTreePlaceholder,\n\t\t\ttype,\n\t\t\tsubTreeType,\n\t\t\tentityId,\n\t\t}\n\t}\n\n\tpublic static encodeEntityId(entityId: RuntimeId): string {\n\t\treturn `${standaloneUuidPrefix}${entityId.value.replace(uuidToAliasRegex, uuidToAliasReplacement)}`\n\t}\n\n\tpublic static decodeEntityId(alias: string): RuntimeId['value'] {\n\t\treturn `${alias.substring(standaloneUuidPrefix.length).replace(aliasToUuidRegex, aliasToUuidReplacement)}`\n\t}\n}\n"],"names":[],"mappings":";AAOA,MAAM,qBAAqB;AAE3B,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAE/B,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;AAG/B,MAAM,uBAAuB;oBAEF;AAAA,SACZ,eAAe,WAA8C;UACpE,aAAa,UAAU,eAAe,SAAY,MAAM,IAAI,UAAU,WAAW,QAAQ,KAAK;UAC9F,WAAW,UAAU,SAAS,QAAQ,kBAAkB;UAExD,QAAQ,GAAG,aAAa,UAAU,uBAAuB,UAAU,OAAO,UAAU,cAAc;WAUjG;AAAA;AAAA,SAGM,eAAe,OAAsD;UAC5E,UAAU,MAAM,MAAM;QAExB,CAAC,SAAS;aACN;AAAA;UAEF,aAAqC,QAAQ,OAAO,MAAM,SAAY,QAAQ;UAC9E,qBAAsC,QAAQ;UAC9C,OAAO,QAAQ;UACf,cACL,QAAQ,OAAO,MAAM,6BAA6B,eAAe,6BAA6B;UACzF,WAAW,QAAQ,GAAG,QAAQ,kBAAkB;WAE/C;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA;AAAA,SAIY,eAAe,UAA6B;WAClD,GAAG,uBAAuB,SAAS,MAAM,QAAQ,kBAAkB;AAAA;AAAA,SAG7D,eAAe,OAAmC;WACxD,GAAG,MAAM,UAAU,qBAAqB,QAAQ,QAAQ,kBAAkB;AAAA;AAAA;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"SugaredField.js","sources":["../../../src/helperComponents/SugaredField.tsx"],"sourcesContent":["import { Component, Field, FieldProps } from '../coreComponents'\nimport type { SugaredRelativeSingleField } from '../treeParameters'\n\nexport interface SugaredFieldProps extends Omit<FieldProps, 'field'> {\n\tfield: string | SugaredRelativeSingleField\n}\n\nexport const SugaredField = Component<SugaredFieldProps>(props => {\n\tif (typeof props.field === 'string') {\n\t\treturn <Field {...props} field={props.field} />\n\t}\n\treturn <Field {...props} {...props.field} />\n}, 'SugaredField')\n"],"names":[],"mappings":";;;MAOa,eAAe,UAA6B,WAAS;MAC7D,OAAO,MAAM,UAAU,UAAU;yCAC5B,OAAD;AAAA,SAAW;AAAA,MAAO,OAAO,MAAM;AAAA;AAAA;uCAE/B,OAAD;AAAA,OAAW;AAAA,OAAW,MAAM;AAAA;AAAA,GACjC;;"}
1
+ {"version":3,"file":"SugaredField.js","sources":["../../../src/helperComponents/SugaredField.tsx"],"sourcesContent":["import { Component, Field, FieldProps } from '../coreComponents'\nimport type { SugaredRelativeSingleField } from '../treeParameters'\nimport { FieldValue } from '../treeParameters'\nimport { ReactElement } from 'react'\n\nexport interface SugaredFieldProps<Persisted extends FieldValue = FieldValue> extends Omit<FieldProps<Persisted>, 'field'> {\n\tfield: string | SugaredRelativeSingleField\n}\n\nexport const SugaredField = Component(<Persisted extends FieldValue = FieldValue>(props: SugaredFieldProps<Persisted>) => {\n\tif (typeof props.field === 'string') {\n\t\treturn <Field {...props} field={props.field} />\n\t}\n\treturn <Field {...props} {...props.field} />\n}, 'SugaredField') as <Persisted extends FieldValue = FieldValue>(props: SugaredFieldProps<Persisted>) => ReactElement\n"],"names":[],"mappings":";;;MASa,eAAe,UAAU,CAA4C,UAAwC;MACrH,OAAO,MAAM,UAAU,UAAU;yCAC5B,OAAD;AAAA,SAAW;AAAA,MAAO,OAAO,MAAM;AAAA;AAAA;uCAE/B,OAAD;AAAA,OAAW;AAAA,OAAW,MAAM;AAAA;AAAA,GACjC;;"}
@@ -1,5 +1,6 @@
1
1
  export { NIL_UUID, PRIMARY_KEY_NAME, TYPENAME_KEY_NAME } from "./bindingTypes.js";
2
2
  export { BindingError, throwBindingError } from "./BindingError.js";
3
+ export { v4 as generateUuid } from "uuid";
3
4
  export { AccessorProvider } from "./accessorPropagation/AccessorProvider.js";
4
5
  export { BindingOperationsProvider } from "./accessorPropagation/BindingOperationsProvider.js";
5
6
  export { EntityKeyProvider } from "./accessorPropagation/EntityKeyProvider.js";
@@ -12,6 +13,7 @@ export { useDesugaredRelativeSingleEntity } from "./accessorPropagation/useDesug
12
13
  export { useDesugaredRelativeSingleField } from "./accessorPropagation/useDesugaredRelativeSingleField.js";
13
14
  export { useEntity } from "./accessorPropagation/useEntity.js";
14
15
  export { useEntityKey } from "./accessorPropagation/useEntityKey.js";
16
+ export { useHasEntity } from "./accessorPropagation/useHasEntity.js";
15
17
  export { useEntityList } from "./accessorPropagation/useEntityList.js";
16
18
  export { useEntityListSubTree } from "./accessorPropagation/useEntityListSubTree.js";
17
19
  export { useEntityListSubTreeParameters } from "./accessorPropagation/useEntityListSubTreeParameters.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -35,7 +35,8 @@ class CacheStore {
35
35
  relativeEntityList: new LRUCache(500),
36
36
  uniqueWhere: new LRUCache(100),
37
37
  filter: new LRUCache(100),
38
- orderBy: new LRUCache(50)
38
+ orderBy: new LRUCache(50),
39
+ taggedMap: new LRUCache(50)
39
40
  };
40
41
  }
41
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CacheStore.js","sources":["../../../src/queryLanguage/CacheStore.ts"],"sourcesContent":["import type { Environment } from '../dao'\nimport { LRUCache } from '../structures'\nimport type { Parser } from './Parser'\n\ntype CacheByEntryPoint = {\n\t[Entry in Parser.EntryPoint]: LRUCache<string, Parser.ParserResult[Entry]>\n}\n\nexport class CacheStore {\n\tprivate cacheStore: WeakMap<Environment, CacheByEntryPoint> = new WeakMap()\n\n\tpublic get<Entry extends Parser.EntryPoint>(\n\t\tenvironment: Environment,\n\t\tentry: Entry,\n\t\texpression: string,\n\t): Parser.ParserResult[Entry] | undefined {\n\t\tlet caches = this.cacheStore.get(environment)\n\n\t\tif (caches === undefined) {\n\t\t\tthis.cacheStore.set(environment, (caches = this.createEntryPointCache()))\n\t\t}\n\t\treturn caches[entry].get(expression) as Parser.ParserResult[Entry] | undefined\n\t}\n\n\tpublic set<Entry extends Parser.EntryPoint>(\n\t\tenvironment: Environment,\n\t\tentry: Entry,\n\t\texpression: string,\n\t\tvalue: Parser.ParserResult[Entry],\n\t) {\n\t\tlet caches = this.cacheStore.get(environment)\n\n\t\tif (caches === undefined) {\n\t\t\tthis.cacheStore.set(environment, (caches = this.createEntryPointCache()))\n\t\t}\n\t\t(caches[entry] as LRUCache<string, Parser.ParserResult[Entry]>).set(expression, value)\n\t}\n\n\tprivate createEntryPointCache(): CacheByEntryPoint {\n\t\t// TODO configurable limits\n\t\treturn {\n\t\t\tqualifiedEntityList: new LRUCache(50),\n\t\t\tqualifiedFieldList: new LRUCache(50),\n\t\t\tqualifiedSingleEntity: new LRUCache(50),\n\t\t\tunconstrainedQualifiedEntityList: new LRUCache(10),\n\t\t\tunconstrainedQualifiedSingleEntity: new LRUCache(10),\n\t\t\trelativeSingleField: new LRUCache(1000),\n\t\t\trelativeSingleEntity: new LRUCache(500),\n\t\t\trelativeEntityList: new LRUCache(500),\n\t\t\tuniqueWhere: new LRUCache(100),\n\t\t\tfilter: new LRUCache(100),\n\t\t\torderBy: new LRUCache(50),\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;iBAQwB;AAAA;AACf,sCAAsD,IAAI;AAAA;AAAA,EAE3D,IACN,aACA,OACA,YACyC;QACrC,SAAS,KAAK,WAAW,IAAI;QAE7B,WAAW,QAAW;WACpB,WAAW,IAAI,aAAc,SAAS,KAAK;AAAA;WAE1C,OAAO,OAAO,IAAI;AAAA;AAAA,EAGnB,IACN,aACA,OACA,YACA,OACC;QACG,SAAS,KAAK,WAAW,IAAI;QAE7B,WAAW,QAAW;WACpB,WAAW,IAAI,aAAc,SAAS,KAAK;AAAA;AAEhD,WAAO,OAAwD,IAAI,YAAY;AAAA;AAAA,EAGzE,wBAA2C;WAE3C;AAAA,MACN,qBAAqB,IAAI,SAAS;AAAA,MAClC,oBAAoB,IAAI,SAAS;AAAA,MACjC,uBAAuB,IAAI,SAAS;AAAA,MACpC,kCAAkC,IAAI,SAAS;AAAA,MAC/C,oCAAoC,IAAI,SAAS;AAAA,MACjD,qBAAqB,IAAI,SAAS;AAAA,MAClC,sBAAsB,IAAI,SAAS;AAAA,MACnC,oBAAoB,IAAI,SAAS;AAAA,MACjC,aAAa,IAAI,SAAS;AAAA,MAC1B,QAAQ,IAAI,SAAS;AAAA,MACrB,SAAS,IAAI,SAAS;AAAA;AAAA;AAAA;;"}
1
+ {"version":3,"file":"CacheStore.js","sources":["../../../src/queryLanguage/CacheStore.ts"],"sourcesContent":["import type { Environment } from '../dao'\nimport { LRUCache } from '../structures'\nimport type { Parser } from './Parser'\n\ntype CacheByEntryPoint = {\n\t[Entry in Parser.EntryPoint]: LRUCache<string, Parser.ParserResult[Entry]>\n}\n\nexport class CacheStore {\n\tprivate cacheStore: WeakMap<Environment, CacheByEntryPoint> = new WeakMap()\n\n\tpublic get<Entry extends Parser.EntryPoint>(\n\t\tenvironment: Environment,\n\t\tentry: Entry,\n\t\texpression: string,\n\t): Parser.ParserResult[Entry] | undefined {\n\t\tlet caches = this.cacheStore.get(environment)\n\n\t\tif (caches === undefined) {\n\t\t\tthis.cacheStore.set(environment, (caches = this.createEntryPointCache()))\n\t\t}\n\t\treturn caches[entry].get(expression) as Parser.ParserResult[Entry] | undefined\n\t}\n\n\tpublic set<Entry extends Parser.EntryPoint>(\n\t\tenvironment: Environment,\n\t\tentry: Entry,\n\t\texpression: string,\n\t\tvalue: Parser.ParserResult[Entry],\n\t) {\n\t\tlet caches = this.cacheStore.get(environment)\n\n\t\tif (caches === undefined) {\n\t\t\tthis.cacheStore.set(environment, (caches = this.createEntryPointCache()))\n\t\t}\n\t\t(caches[entry] as LRUCache<string, Parser.ParserResult[Entry]>).set(expression, value)\n\t}\n\n\tprivate createEntryPointCache(): CacheByEntryPoint {\n\t\t// TODO configurable limits\n\t\treturn {\n\t\t\tqualifiedEntityList: new LRUCache(50),\n\t\t\tqualifiedFieldList: new LRUCache(50),\n\t\t\tqualifiedSingleEntity: new LRUCache(50),\n\t\t\tunconstrainedQualifiedEntityList: new LRUCache(10),\n\t\t\tunconstrainedQualifiedSingleEntity: new LRUCache(10),\n\t\t\trelativeSingleField: new LRUCache(1000),\n\t\t\trelativeSingleEntity: new LRUCache(500),\n\t\t\trelativeEntityList: new LRUCache(500),\n\t\t\tuniqueWhere: new LRUCache(100),\n\t\t\tfilter: new LRUCache(100),\n\t\t\torderBy: new LRUCache(50),\n\t\t\ttaggedMap: new LRUCache(50),\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;;;iBAQwB;AAAA;AACf,sCAAsD,IAAI;AAAA;AAAA,EAE3D,IACN,aACA,OACA,YACyC;QACrC,SAAS,KAAK,WAAW,IAAI;QAE7B,WAAW,QAAW;WACpB,WAAW,IAAI,aAAc,SAAS,KAAK;AAAA;WAE1C,OAAO,OAAO,IAAI;AAAA;AAAA,EAGnB,IACN,aACA,OACA,YACA,OACC;QACG,SAAS,KAAK,WAAW,IAAI;QAE7B,WAAW,QAAW;WACpB,WAAW,IAAI,aAAc,SAAS,KAAK;AAAA;AAEhD,WAAO,OAAwD,IAAI,YAAY;AAAA;AAAA,EAGzE,wBAA2C;WAE3C;AAAA,MACN,qBAAqB,IAAI,SAAS;AAAA,MAClC,oBAAoB,IAAI,SAAS;AAAA,MACjC,uBAAuB,IAAI,SAAS;AAAA,MACpC,kCAAkC,IAAI,SAAS;AAAA,MAC/C,oCAAoC,IAAI,SAAS;AAAA,MACjD,qBAAqB,IAAI,SAAS;AAAA,MAClC,sBAAsB,IAAI,SAAS;AAAA,MACnC,oBAAoB,IAAI,SAAS;AAAA,MACjC,aAAa,IAAI,SAAS;AAAA,MAC1B,QAAQ,IAAI,SAAS;AAAA,MACrB,SAAS,IAAI,SAAS;AAAA,MACtB,WAAW,IAAI,SAAS;AAAA;AAAA;AAAA;;"}
@@ -408,6 +408,63 @@ const _Parser = class extends EmbeddedActionsParser {
408
408
  });
409
409
  return order;
410
410
  }));
411
+ __publicField(this, "taggedMap", this.RULE("taggedMap", () => {
412
+ const name = this.SUBRULE(this.identifier);
413
+ return {
414
+ name,
415
+ entries: this.OPTION(() => this.SUBRULE(this.taggedMapEntries)) ?? []
416
+ };
417
+ }));
418
+ __publicField(this, "taggedMapEntries", this.RULE("taggedMapEntries", () => {
419
+ this.CONSUME(tokens.LeftParenthesis);
420
+ const entries = [];
421
+ this.AT_LEAST_ONE_SEP({
422
+ SEP: tokens.Comma,
423
+ DEF: () => entries.push(this.SUBRULE(this.taggedMapEntry))
424
+ });
425
+ this.CONSUME(tokens.RightParenthesis);
426
+ return entries;
427
+ }));
428
+ __publicField(this, "taggedMapEntry", this.RULE("taggedMapEntry", () => {
429
+ const variableName = this.CONSUME(tokens.Identifier).image;
430
+ this.CONSUME1(tokens.Colon);
431
+ const value = this.OR([
432
+ {
433
+ ALT: () => this.SUBRULE(this.taggedMapLiteralValue)
434
+ },
435
+ {
436
+ ALT: () => this.SUBRULE(this.taggedMapVariableValue)
437
+ }
438
+ ]);
439
+ return {
440
+ key: variableName,
441
+ value
442
+ };
443
+ }));
444
+ __publicField(this, "taggedMapLiteralValue", this.RULE("taggedMapLiteralValue", () => {
445
+ const value = this.OR([
446
+ {
447
+ ALT: () => this.SUBRULE(this.string)
448
+ },
449
+ {
450
+ ALT: () => this.SUBRULE(this.number)
451
+ }
452
+ ]);
453
+ return {
454
+ type: "literal",
455
+ value
456
+ };
457
+ }));
458
+ __publicField(this, "taggedMapVariableValue", this.RULE("taggedMapVariableValue", () => {
459
+ const start = this.CONSUME(tokens.DollarSign);
460
+ this.SUBRULE(this.relativeSingleField);
461
+ const end = this.LA(0);
462
+ const field = this.input.slice(this.input.indexOf(start) + 1, this.input.indexOf(end) + 1).map((it) => it.image).join("");
463
+ return {
464
+ type: "variable",
465
+ value: field
466
+ };
467
+ }));
411
468
  __publicField(this, "fieldName", this.RULE("fieldName", () => {
412
469
  return this.OR([
413
470
  {
@@ -548,6 +605,9 @@ ${lexingResult.errors.map((i) => i.message).join("\n")}`);
548
605
  case "orderBy":
549
606
  expression = _Parser.parser.orderBy();
550
607
  break;
608
+ case "taggedMap":
609
+ expression = _Parser.parser.taggedMap();
610
+ break;
551
611
  default:
552
612
  throw new QueryLanguageError(`Not implemented entry point '${entry}'`);
553
613
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.js","sources":["../../../src/queryLanguage/Parser.ts"],"sourcesContent":["import { CrudQueryBuilder, GraphQlBuilder, GraphQlLiteral, Input } from '@contember/client'\nimport { EmbeddedActionsParser, Lexer } from 'chevrotain'\nimport { Environment } from '../dao'\nimport type {\n\tEntityName,\n\tFieldName,\n\tFilter,\n\tOrderBy,\n\tUniqueWhere,\n} from '../treeParameters'\nimport type {\n\tParsedHasManyRelation,\n\tParsedHasOneRelation,\n\tParsedQualifiedEntityList,\n\tParsedQualifiedFieldList,\n\tParsedQualifiedSingleEntity,\n\tParsedRelativeEntityList,\n\tParsedRelativeSingleEntity,\n\tParsedRelativeSingleField,\n\tParsedUnconstrainedQualifiedEntityList,\n\tParsedUnconstrainedQualifiedSingleEntity,\n} from './ParserResults'\nimport { CacheStore } from './CacheStore'\nimport { QueryLanguageError } from './QueryLanguageError'\nimport { tokenList, TokenRegExps, tokens } from './tokenList'\n\n/**\n * TODO:\n * \t- double quoted strings\n * \t- collections (objects & lists)\n * \t- collection operators (e.g. 'in', 'notIn', etc.)\n * \t- filtering toOne\n */\nclass Parser extends EmbeddedActionsParser {\n\tprivate static rawInput: string = ''\n\tprivate static lexer = new Lexer(tokenList)\n\tprivate static parser = new Parser()\n\tprivate static environment: Environment = new Environment()\n\tprivate static cacheStore: CacheStore = new CacheStore()\n\n\tprivate qualifiedEntityList = this.RULE<ParsedQualifiedEntityList>('qualifiedEntityList', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\n\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t})\n\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate qualifiedFieldList = this.RULE<ParsedQualifiedFieldList>('qualifiedFieldList', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\n\t\tthis.CONSUME(tokens.Dot)\n\n\t\tconst { hasOneRelationPath, field } = this.SUBRULE(this.relativeSingleField)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\tfield,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate qualifiedSingleEntity = this.RULE<ParsedQualifiedSingleEntity>('qualifiedSingleEntity', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\n\t\t// TODO this will probably go away once we support singleton entities\n\t\tconst where = this.SUBRULE(this.uniqueWhere)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t})\n\n\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\twhere,\n\t\t\thasOneRelationPath,\n\t\t\tfilter,\n\t\t}\n\t})\n\n\tprivate unconstrainedQualifiedEntityList = this.RULE<ParsedUnconstrainedQualifiedEntityList>(\n\t\t'unconstrainedQualifiedEntityList',\n\t\t() => {\n\t\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\t\tconst relativeSingleEntity = this.OPTION(() => {\n\t\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t\t})\n\n\t\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t\t)\n\n\t\t\treturn {\n\t\t\t\tentityName,\n\t\t\t\thasOneRelationPath,\n\t\t\t}\n\t\t},\n\t)\n\n\tprivate unconstrainedQualifiedSingleEntity = this.RULE<ParsedUnconstrainedQualifiedSingleEntity>(\n\t\t'unconstrainedQualifiedSingleEntity',\n\t\t() => {\n\t\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t\t})\n\n\t\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t\t)\n\n\t\t\treturn {\n\t\t\t\tentityName,\n\t\t\t\thasOneRelationPath,\n\t\t\t}\n\t\t},\n\t)\n\n\tprivate relativeSingleField = this.RULE<ParsedRelativeSingleField>('relativeSingleField', () => {\n\t\tlet { hasOneRelationPath } = this.SUBRULE(this.relativeSingleEntity)\n\n\t\tconst last = this.ACTION(() => hasOneRelationPath.pop()!)\n\n\t\tthis.ACTION(() => {\n\t\t\tif (last.reducedBy !== undefined || last.filter !== undefined) {\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`Cannot parse '${Parser.rawInput}': the last field '${last.field}' is being reduced or filtered, which, grammatically, makes it a relation but a single field is expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t})\n\n\t\tconst field = this.ACTION(() => last.field)\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t\tfield,\n\t\t}\n\t})\n\n\tprivate relativeSingleEntity = this.RULE<ParsedRelativeSingleEntity>('relativeSingleEntity', () => {\n\t\tconst hasOneRelationPath: ParsedHasOneRelation[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Dot,\n\t\t\tDEF: () => {\n\t\t\t\thasOneRelationPath.push(this.SUBRULE(this.hasOneRelation))\n\t\t\t},\n\t\t})\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate relativeEntityList = this.RULE<ParsedRelativeEntityList>('relativeEntityList', () => {\n\t\tlet { hasOneRelationPath } = this.SUBRULE(this.relativeSingleEntity)\n\n\t\tconst last = this.ACTION(() => hasOneRelationPath.pop()!)\n\n\t\tthis.ACTION(() => {\n\t\t\tif (last.reducedBy !== undefined) {\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`Cannot parse '${Parser.rawInput}': the last field '${last.field}' is being reduced, which, grammatically, makes it a has-one relation but a has-many relation is expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t})\n\n\t\tconst hasManyRelation = this.ACTION(\n\t\t\t(): ParsedHasManyRelation => ({\n\t\t\t\tfield: last.field,\n\t\t\t\tfilter: last.filter,\n\t\t\t}),\n\t\t)\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t\thasManyRelation,\n\t\t}\n\t})\n\n\tprivate hasOneRelation = this.RULE<ParsedHasOneRelation>('hasOneRelation', () => {\n\t\tconst fieldName = this.SUBRULE(this.fieldName)\n\t\tconst reducedBy = this.OPTION(() => this.SUBRULE(this.uniqueWhere))\n\t\tconst filter = this.OPTION1(() => this.SUBRULE(this.nonUniqueWhere))\n\t\tconst hasOneRelation: ParsedHasOneRelation = {\n\t\t\tfield: fieldName,\n\t\t\tfilter,\n\t\t\treducedBy,\n\t\t}\n\n\t\treturn hasOneRelation\n\t})\n\n\tprivate nonUniqueWhere: () => Filter = this.RULE('nonUniqueWhere', () => {\n\t\tconst cnfWhere: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE(() => {\n\t\t\tthis.CONSUME(tokens.LeftBracket)\n\n\t\t\tcnfWhere.push(this.SUBRULE(this.disjunction))\n\n\t\t\tthis.CONSUME(tokens.RightBracket)\n\t\t})\n\t\tif (cnfWhere.length === 1) {\n\t\t\treturn cnfWhere[0]\n\t\t}\n\t\treturn {\n\t\t\tand: cnfWhere,\n\t\t}\n\t})\n\n\tprivate disjunction: () => Filter = this.RULE('disjunction', () => {\n\t\tconst conjunctions: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Or,\n\t\t\tDEF: () => {\n\t\t\t\tconjunctions.push(this.SUBRULE(this.conjunction))\n\t\t\t},\n\t\t})\n\t\tif (conjunctions.length === 1) {\n\t\t\treturn conjunctions[0]\n\t\t}\n\t\treturn {\n\t\t\tor: conjunctions,\n\t\t}\n\t})\n\n\tprivate conjunction: () => Filter = this.RULE('conjunction', () => {\n\t\tconst negations: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.And,\n\t\t\tDEF: () => {\n\t\t\t\tnegations.push(this.SUBRULE(this.negation))\n\t\t\t},\n\t\t})\n\t\tif (negations.length === 1) {\n\t\t\treturn negations[0]\n\t\t}\n\t\treturn {\n\t\t\tand: negations,\n\t\t}\n\t})\n\n\t// TODO this is to naïve and needs rewriting\n\tprivate negation: () => Filter = this.RULE('negation', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.Not)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnot: this.SUBRULE(this.filterGroup),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\treturn this.SUBRULE1(this.filterGroup)\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate filterGroup: () => Filter = this.RULE('filterGroup', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.LeftParenthesis)\n\t\t\t\t\tconst subFilter = this.SUBRULE(this.disjunction)\n\t\t\t\t\tthis.CONSUME1(tokens.RightParenthesis)\n\t\t\t\t\treturn subFilter\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE1(this.filterAtom),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate filterAtom: () => Filter = this.RULE('filterAtom', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (typeof variable !== 'object' || variable instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`Invalid filter value '${JSON.stringify(variable)}'`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn variable\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE1(this.fieldWhere),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate fieldWhere: () => Parser.AST.FieldWhere = this.RULE('fieldWhere', () => {\n\t\tconst fields: FieldName[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Dot,\n\t\t\tDEF: () => {\n\t\t\t\tfields.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t},\n\t\t})\n\n\t\tconst condition = this.SUBRULE(this.condition)\n\n\t\tlet i = fields.length - 1\n\t\tlet where: Parser.AST.FieldWhere = {\n\t\t\t[fields[i--]]: condition,\n\t\t}\n\n\t\twhile (i >= 0) {\n\t\t\twhere = {\n\t\t\t\t[fields[i--]]: where,\n\t\t\t}\n\t\t}\n\n\t\treturn where\n\t})\n\n\tprivate condition: () => Parser.AST.Condition = this.RULE('condition', () => {\n\t\tconst operator = this.SUBRULE(this.conditionOperator)\n\t\tconst columnValue = this.SUBRULE(this.columnValue)\n\t\tconst condition: Parser.AST.Condition = {}\n\n\t\treturn this.ACTION(() => {\n\t\t\tif (columnValue === null) {\n\t\t\t\tif (operator === 'eq') {\n\t\t\t\t\tcondition.null = true\n\t\t\t\t} else if (operator === 'notEq') {\n\t\t\t\t\tcondition.null = false\n\t\t\t\t} else {\n\t\t\t\t\tthrow new QueryLanguageError(`The null keyword as a right hand operand can only be tested for (in)equality.`)\n\t\t\t\t}\n\t\t\t\treturn condition\n\t\t\t}\n\t\t\tcondition[operator] = columnValue\n\n\t\t\treturn condition\n\t\t})\n\t})\n\n\tprivate conditionOperator: () => Parser.AST.ConditionOperator = this.RULE<Parser.AST.ConditionOperator>(\n\t\t'conditionOperator',\n\t\t() => {\n\t\t\treturn this.OR([\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.Equals)\n\t\t\t\t\t\treturn 'eq'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.NotEquals)\n\t\t\t\t\t\treturn 'notEq'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.LowerThan)\n\t\t\t\t\t\treturn 'lt'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.LowerEqual)\n\t\t\t\t\t\treturn 'lte'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.GreaterThan)\n\t\t\t\t\t\treturn 'gt'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.GreaterEqual)\n\t\t\t\t\t\treturn 'gte'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t])\n\t\t},\n\t)\n\n\tprivate columnValue: () => Parser.AST.ColumnValue = this.RULE<Parser.AST.ColumnValue>('columnValue', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.Null)\n\t\t\t\t\treturn null\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.True)\n\t\t\t\t\treturn true\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.False)\n\t\t\t\t\treturn false\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.primaryValue),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate uniqueWhere = this.RULE('uniqueWhere', () => {\n\t\tconst where: UniqueWhere = {}\n\n\t\tthis.CONSUME(tokens.LeftParenthesis)\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Comma,\n\t\t\tDEF: () => {\n\t\t\t\tconst nestedFields: string[] = []\n\t\t\t\tthis.AT_LEAST_ONE_SEP1({\n\t\t\t\t\tSEP: tokens.Dot,\n\t\t\t\t\tDEF: () => {\n\t\t\t\t\t\tnestedFields.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tthis.CONSUME(tokens.Equals)\n\t\t\t\tconst primaryValue = this.SUBRULE<Input.PrimaryValue<GraphQlBuilder.GraphQlLiteral>>(this.primaryValue)\n\n\t\t\t\tthis.ACTION(() => {\n\t\t\t\t\tlet nestedWhere = where\n\t\t\t\t\tfor (let i = 0, len = nestedFields.length; i < len; i++) {\n\t\t\t\t\t\tconst nestedField = nestedFields[i]\n\n\t\t\t\t\t\tconst isLast = len - 1 === i\n\n\t\t\t\t\t\tif (isLast) {\n\t\t\t\t\t\t\tif (nestedField in nestedWhere) {\n\t\t\t\t\t\t\t\tthrow new QueryLanguageError(`Duplicate '${nestedFields.slice(0, i + 1).join('.')}' field`)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tnestedWhere[nestedField] = primaryValue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (nestedField in nestedWhere) {\n\t\t\t\t\t\t\t\tconst existingWhere = nestedWhere[nestedField]\n\n\t\t\t\t\t\t\t\tif (typeof existingWhere === 'object' && !(existingWhere instanceof GraphQlBuilder.GraphQlLiteral)) {\n\t\t\t\t\t\t\t\t\tnestedWhere = existingWhere\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t\t\t\t\t\t`Malformed expression: cannot simultaneously treat the '${nestedFields\n\t\t\t\t\t\t\t\t\t\t\t.slice(0, i + 1)\n\t\t\t\t\t\t\t\t\t\t\t.join('.')}' ` + `field as a scalar as well as a relation.`,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst newWhere = {}\n\t\t\t\t\t\t\t\tnestedWhere[nestedField] = newWhere\n\t\t\t\t\t\t\t\tnestedWhere = newWhere\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})\n\t\t\t},\n\t\t})\n\t\tthis.CONSUME(tokens.RightParenthesis)\n\n\t\treturn where\n\t})\n\n\tprivate orderBy: () => Input.OrderBy<CrudQueryBuilder.OrderDirection>[] = this.RULE<\n\t\tInput.OrderBy<CrudQueryBuilder.OrderDirection>[]\n\t>('orderBy', () => {\n\t\tconst order: Input.OrderBy<CrudQueryBuilder.OrderDirection>[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Comma,\n\t\t\tDEF: () => {\n\t\t\t\tconst fieldNames: FieldName[] = []\n\t\t\t\tthis.AT_LEAST_ONE_SEP1({\n\t\t\t\t\tSEP: tokens.Dot,\n\t\t\t\t\tDEF: () => {\n\t\t\t\t\t\tfieldNames.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tlet literal = this.OPTION(() => this.SUBRULE1(this.graphQlLiteral)) as\n\t\t\t\t\t| CrudQueryBuilder.OrderDirection\n\t\t\t\t\t| undefined\n\n\t\t\t\tthis.ACTION(() => {\n\t\t\t\t\tif (literal) {\n\t\t\t\t\t\tif (literal.value !== 'asc' && literal.value !== 'desc') {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`The only valid order directions are \\`asc\\` and \\`desc\\`.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tliteral = new GraphQlBuilder.GraphQlLiteral('asc')\n\t\t\t\t\t}\n\t\t\t\t\tlet orderBy: Input.FieldOrderBy<CrudQueryBuilder.OrderDirection> = literal\n\n\t\t\t\t\tfor (let i = fieldNames.length - 1; i >= 0; i--) {\n\t\t\t\t\t\torderBy = { [fieldNames[i]]: orderBy }\n\t\t\t\t\t}\n\t\t\t\t\torder.push(orderBy as Input.OrderBy<CrudQueryBuilder.OrderDirection>)\n\t\t\t\t})\n\t\t\t},\n\t\t})\n\n\t\treturn order\n\t})\n\n\tprivate fieldName: () => FieldName = this.RULE<FieldName>('fieldName', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.fieldIdentifier),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate primaryValue = this.RULE<Input.PrimaryValue<GraphQlBuilder.GraphQlLiteral>>('primaryValue', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.string),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.number),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.graphQlLiteral),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variableValue = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof variableValue === 'string' ||\n\t\t\t\t\t\t\ttypeof variableValue === 'number' ||\n\t\t\t\t\t\t\tvariableValue instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn variableValue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t\t\t`A variable can resolve to a literal, string or a number, not ${typeof variableValue}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate fieldIdentifier: () => FieldName = this.RULE('fieldIdentifier', () => {\n\t\treturn this.SUBRULE(this.identifier)\n\t\t// return this.OR([\n\t\t// \t{\n\t\t// \t\tALT: () => this.SUBRULE(this.identifier),\n\t\t// \t},\n\t\t// \t{\n\t\t// \t\tALT: () => {\n\t\t// \t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t// \t\t\treturn this.ACTION(() => {\n\t\t// \t\t\t\tif (!(typeof variable === 'string') || !TokenRegExps.identifier.test(variable)) {\n\t\t// \t\t\t\t\tthrow new QueryLanguageError(`The value \\$${variable} is not a valid field identifier.`)\n\t\t// \t\t\t\t}\n\t\t// \t\t\t\treturn variable\n\t\t// \t\t\t})\n\t\t// \t\t},\n\t\t// \t},\n\t\t// ])\n\t})\n\n\tprivate identifier: () => string = this.RULE('identifier', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.CONSUME(tokens.Identifier).image,\n\t\t\t},\n\t\t\t{\n\t\t\t\t// TODO this is a temporary hack to allow for literals that start with an uppercase letter… 🙈\n\t\t\t\tALT: () => this.CONSUME(tokens.EntityIdentifier).image,\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate entityIdentifier: () => EntityName = this.RULE('entityIdentifier', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.CONSUME(tokens.EntityIdentifier).image,\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (!(typeof variable === 'string') || !TokenRegExps.entityIdentifier.test(variable)) {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`The value of the variable \\$${variable} is not a valid entity identifier.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn variable\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate string = this.RULE('string', () => {\n\t\tconst image = this.CONSUME(tokens.StringLiteral).image\n\t\treturn image\n\t\t\t.substring(1, image.length - 1)\n\t\t\t.replace(\"\\\\'\", \"'\")\n\t\t\t.replace('\\\\b', '\\b')\n\t\t\t.replace('\\\\f', '\\f')\n\t\t\t.replace('\\\\n', '\\n')\n\t\t\t.replace('\\\\r', '\\r')\n\t\t\t.replace('\\\\t', '\\t')\n\t\t\t.replace('\\\\v', '\\v')\n\t})\n\n\tprivate number = this.RULE('number', () => {\n\t\treturn parseFloat(this.CONSUME(tokens.NumberLiteral).image)\n\t})\n\n\tprivate graphQlLiteral: () => GraphQlBuilder.GraphQlLiteral = this.RULE('graphQlLiteral', () => {\n\t\tconst image = this.SUBRULE(this.identifier)\n\n\t\treturn new GraphQlBuilder.GraphQlLiteral(image)\n\t})\n\n\tprivate variable = this.RULE<string | number | GraphQlLiteral | Filter | UniqueWhere>('variable', () => {\n\t\tthis.CONSUME(tokens.DollarSign)\n\t\tconst variableName = this.CONSUME(tokens.Identifier).image\n\n\t\treturn this.ACTION(() => {\n\t\t\tif (Parser.environment.hasName(variableName)) {\n\t\t\t\treturn Parser.environment.getValue(variableName)\n\t\t\t}\n\t\t\tif (Parser.environment.hasDimension(variableName)) {\n\t\t\t\tconst dimensionValue = Parser.environment.getDimension(variableName)\n\n\t\t\t\tif (dimensionValue.length === 1) {\n\t\t\t\t\treturn dimensionValue[0]\n\t\t\t\t}\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`The variable \\$${variableName} resolved to a dimension which exists but contains ${dimensionValue.length} values. It has to contain exactly one. ` +\n\t\t\t\t\t\t`Perhaps you forgot to set the 'maxItems' prop of your DimensionsSwitcher?`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new QueryLanguageError(`Undefined variable \\$${variableName}.`)\n\t\t})\n\t})\n\n\tprivate constructor() {\n\t\tsuper(tokenList, { outputCst: false, maxLookahead: 1 })\n\t\tthis.performSelfAnalysis()\n\t}\n\n\tpublic static parseQueryLanguageExpression<E extends Parser.EntryPoint>(\n\t\tinput: string,\n\t\tentry: E,\n\t\tenvironment: Environment,\n\t): Parser.ParserResult[E] {\n\t\tconst cached = this.cacheStore.get(environment, entry, input)\n\n\t\tif (cached !== undefined) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst lexingResult = Parser.lexer.tokenize((Parser.rawInput = input))\n\n\t\tif (lexingResult.errors.length !== 0) {\n\t\t\tthrow new QueryLanguageError(\n\t\t\t\t`Failed to tokenize '${input}'.\\n\\n${lexingResult.errors.map(i => i.message).join('\\n')}`,\n\t\t\t)\n\t\t}\n\n\t\tParser.environment = environment\n\t\tParser.parser.input = lexingResult.tokens\n\n\t\tlet expression: Parser.ParserResult[keyof Parser.ParserResult]\n\n\t\tswitch (entry) {\n\t\t\tcase 'relativeSingleField':\n\t\t\t\texpression = Parser.parser.relativeSingleField()\n\t\t\t\tbreak\n\t\t\tcase 'relativeSingleEntity':\n\t\t\t\texpression = Parser.parser.relativeSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'relativeEntityList':\n\t\t\t\texpression = Parser.parser.relativeEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedEntityList':\n\t\t\t\texpression = Parser.parser.qualifiedEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedFieldList':\n\t\t\t\texpression = Parser.parser.qualifiedFieldList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedSingleEntity':\n\t\t\t\texpression = Parser.parser.qualifiedSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'unconstrainedQualifiedEntityList':\n\t\t\t\texpression = Parser.parser.unconstrainedQualifiedEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'unconstrainedQualifiedSingleEntity':\n\t\t\t\texpression = Parser.parser.unconstrainedQualifiedSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'uniqueWhere':\n\t\t\t\texpression = Parser.parser.uniqueWhere()\n\t\t\t\tbreak\n\t\t\tcase 'filter':\n\t\t\t\texpression = Parser.parser.nonUniqueWhere()\n\t\t\t\tbreak\n\t\t\tcase 'orderBy':\n\t\t\t\texpression = Parser.parser.orderBy()\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tthrow new QueryLanguageError(`Not implemented entry point '${entry}'`)\n\t\t}\n\n\t\tif (Parser.parser.errors.length !== 0) {\n\t\t\tthrow new QueryLanguageError(\n\t\t\t\t`Failed to parse '${input}'.\\n\\n${Parser.parser.errors.map(i => i.message).join('\\n')}`,\n\t\t\t)\n\t\t}\n\n\t\tthis.cacheStore.set(environment, entry, input, expression as Parser.ParserResult[E])\n\n\t\treturn expression as Parser.ParserResult[E]\n\t}\n}\n\nnamespace Parser {\n\texport namespace AST {\n\t\texport type FieldWhere = Input.FieldWhere<Condition>\n\n\t\texport type ColumnValue = Input.ColumnValue<GraphQlBuilder.GraphQlLiteral>\n\n\t\texport type Condition = Input.Condition<ColumnValue>\n\n\t\texport type ConditionOperator = keyof Pick<Condition, 'eq' | 'notEq' | 'lt' | 'lte' | 'gt' | 'gte'>\n\t}\n\n\texport interface ParserResult {\n\t\tqualifiedEntityList: ParsedQualifiedEntityList // E.g. Author[age < 123].son.sisters(name = 'Jane')\n\t\tqualifiedFieldList: ParsedQualifiedFieldList // E.g. Author[age < 123].son.sister.name\n\t\tqualifiedSingleEntity: ParsedQualifiedSingleEntity // E.g. Author(id = 123).son.sister\n\t\tunconstrainedQualifiedEntityList: ParsedUnconstrainedQualifiedEntityList // E.g. Author.son.sister\n\t\tunconstrainedQualifiedSingleEntity: ParsedUnconstrainedQualifiedSingleEntity // E.g. Author.son.sister\n\t\trelativeSingleField: ParsedRelativeSingleField // E.g. authors(id = 123).person.name\n\t\trelativeSingleEntity: ParsedRelativeSingleEntity // E.g. localesByLocale(locale.slug = en)\n\t\trelativeEntityList: ParsedRelativeEntityList // E.g. genres(slug = 'sciFi').authors[age < 123]\n\t\tuniqueWhere: UniqueWhere // E.g. (author.mother.id = 123)\n\t\tfilter: Filter // E.g. [author.son.age < 123]\n\t\torderBy: OrderBy // E.g. items.order asc, items.content.name asc\n\t}\n\n\texport type EntryPoint = keyof ParserResult\n}\n\nexport { Parser }\n"],"names":[],"mappings":";;;;;;;;;;;;AAiCA,8BAAqB,sBAAs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G3D,QAAO,OAAO,OAAO,WAAW,GAAG;YAChC,IAAI,mBACT,oBAAoB;AAAA;AAAA,EAAc,QAAO,OAAO,OAAO,IAAI,OAAK,EAAE,SAAS,KAAK;AAAA;SAI7E,WAAW,IAAI,aAAa,OAAO,OAAO;WAExC;AAAA;AAAA;AAzsBT;AACgB,cADhB,QACgB,YAAmB;AACnB,cAFhB,QAEgB,SAAQ,IAAI,MAAM;AAClB,cAHhB,QAGgB,UAAS,IAAI;AACb,cAJhB,QAIgB,eAA2B,IAAI;AAC/B,cALhB,QAKgB,cAAyB,IAAI;;"}
1
+ {"version":3,"file":"Parser.js","sources":["../../../src/queryLanguage/Parser.ts"],"sourcesContent":["import { CrudQueryBuilder, GraphQlBuilder, GraphQlLiteral, Input } from '@contember/client'\nimport { EmbeddedActionsParser, Lexer } from 'chevrotain'\nimport { Environment } from '../dao'\nimport type { EntityName, FieldName, Filter, OrderBy, UniqueWhere } from '../treeParameters'\nimport type {\n\tParsedTaggedMap,\n\tParsedTaggedMapVariableValue,\n\tParsedTaggedMapLiteralValue,\n\tParsedTaggedMapEntry,\n\tParsedHasManyRelation,\n\tParsedHasOneRelation,\n\tParsedQualifiedEntityList,\n\tParsedQualifiedFieldList,\n\tParsedQualifiedSingleEntity,\n\tParsedRelativeEntityList,\n\tParsedRelativeSingleEntity,\n\tParsedRelativeSingleField,\n\tParsedUnconstrainedQualifiedEntityList,\n\tParsedUnconstrainedQualifiedSingleEntity,\n} from './ParserResults'\nimport { CacheStore } from './CacheStore'\nimport { QueryLanguageError } from './QueryLanguageError'\nimport { tokenList, TokenRegExps, tokens } from './tokenList'\n\n/**\n * TODO:\n * \t- double quoted strings\n * \t- collections (objects & lists)\n * \t- collection operators (e.g. 'in', 'notIn', etc.)\n * \t- filtering toOne\n */\nclass Parser extends EmbeddedActionsParser {\n\tprivate static rawInput: string = ''\n\tprivate static lexer = new Lexer(tokenList)\n\tprivate static parser = new Parser()\n\tprivate static environment: Environment = new Environment()\n\tprivate static cacheStore: CacheStore = new CacheStore()\n\n\tprivate qualifiedEntityList = this.RULE<ParsedQualifiedEntityList>('qualifiedEntityList', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\n\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t})\n\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate qualifiedFieldList = this.RULE<ParsedQualifiedFieldList>('qualifiedFieldList', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\n\t\tthis.CONSUME(tokens.Dot)\n\n\t\tconst { hasOneRelationPath, field } = this.SUBRULE(this.relativeSingleField)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\tfield,\n\t\t\tfilter,\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate qualifiedSingleEntity = this.RULE<ParsedQualifiedSingleEntity>('qualifiedSingleEntity', () => {\n\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\n\t\t// TODO this will probably go away once we support singleton entities\n\t\tconst where = this.SUBRULE(this.uniqueWhere)\n\t\tconst filter = this.OPTION(() => this.SUBRULE(this.nonUniqueWhere))\n\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t})\n\n\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t)\n\n\t\treturn {\n\t\t\tentityName,\n\t\t\twhere,\n\t\t\thasOneRelationPath,\n\t\t\tfilter,\n\t\t}\n\t})\n\n\tprivate unconstrainedQualifiedEntityList = this.RULE<ParsedUnconstrainedQualifiedEntityList>(\n\t\t'unconstrainedQualifiedEntityList',\n\t\t() => {\n\t\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\t\tconst relativeSingleEntity = this.OPTION(() => {\n\t\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t\t})\n\n\t\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t\t)\n\n\t\t\treturn {\n\t\t\t\tentityName,\n\t\t\t\thasOneRelationPath,\n\t\t\t}\n\t\t},\n\t)\n\n\tprivate unconstrainedQualifiedSingleEntity = this.RULE<ParsedUnconstrainedQualifiedSingleEntity>(\n\t\t'unconstrainedQualifiedSingleEntity',\n\t\t() => {\n\t\t\tconst entityName = this.SUBRULE(this.entityIdentifier)\n\t\t\tconst relativeSingleEntity = this.OPTION1(() => {\n\t\t\t\tthis.CONSUME(tokens.Dot)\n\t\t\t\treturn this.SUBRULE(this.relativeSingleEntity)\n\t\t\t})\n\n\t\t\tconst hasOneRelationPath = this.ACTION(() =>\n\t\t\t\trelativeSingleEntity === undefined ? [] : relativeSingleEntity.hasOneRelationPath,\n\t\t\t)\n\n\t\t\treturn {\n\t\t\t\tentityName,\n\t\t\t\thasOneRelationPath,\n\t\t\t}\n\t\t},\n\t)\n\n\tprivate relativeSingleField = this.RULE<ParsedRelativeSingleField>('relativeSingleField', () => {\n\t\tlet { hasOneRelationPath } = this.SUBRULE(this.relativeSingleEntity)\n\n\t\tconst last = this.ACTION(() => hasOneRelationPath.pop()!)\n\n\t\tthis.ACTION(() => {\n\t\t\tif (last.reducedBy !== undefined || last.filter !== undefined) {\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`Cannot parse '${Parser.rawInput}': the last field '${last.field}' is being reduced or filtered, which, grammatically, makes it a relation but a single field is expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t})\n\n\t\tconst field = this.ACTION(() => last.field)\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t\tfield,\n\t\t}\n\t})\n\n\tprivate relativeSingleEntity = this.RULE<ParsedRelativeSingleEntity>('relativeSingleEntity', () => {\n\t\tconst hasOneRelationPath: ParsedHasOneRelation[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Dot,\n\t\t\tDEF: () => {\n\t\t\t\thasOneRelationPath.push(this.SUBRULE(this.hasOneRelation))\n\t\t\t},\n\t\t})\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t}\n\t})\n\n\tprivate relativeEntityList = this.RULE<ParsedRelativeEntityList>('relativeEntityList', () => {\n\t\tlet { hasOneRelationPath } = this.SUBRULE(this.relativeSingleEntity)\n\n\t\tconst last = this.ACTION(() => hasOneRelationPath.pop()!)\n\n\t\tthis.ACTION(() => {\n\t\t\tif (last.reducedBy !== undefined) {\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`Cannot parse '${Parser.rawInput}': the last field '${last.field}' is being reduced, which, grammatically, makes it a has-one relation but a has-many relation is expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t})\n\n\t\tconst hasManyRelation = this.ACTION(\n\t\t\t(): ParsedHasManyRelation => ({\n\t\t\t\tfield: last.field,\n\t\t\t\tfilter: last.filter,\n\t\t\t}),\n\t\t)\n\n\t\treturn {\n\t\t\thasOneRelationPath,\n\t\t\thasManyRelation,\n\t\t}\n\t})\n\n\tprivate hasOneRelation = this.RULE<ParsedHasOneRelation>('hasOneRelation', () => {\n\t\tconst fieldName = this.SUBRULE(this.fieldName)\n\t\tconst reducedBy = this.OPTION(() => this.SUBRULE(this.uniqueWhere))\n\t\tconst filter = this.OPTION1(() => this.SUBRULE(this.nonUniqueWhere))\n\t\tconst hasOneRelation: ParsedHasOneRelation = {\n\t\t\tfield: fieldName,\n\t\t\tfilter,\n\t\t\treducedBy,\n\t\t}\n\n\t\treturn hasOneRelation\n\t})\n\n\tprivate nonUniqueWhere: () => Filter = this.RULE('nonUniqueWhere', () => {\n\t\tconst cnfWhere: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE(() => {\n\t\t\tthis.CONSUME(tokens.LeftBracket)\n\n\t\t\tcnfWhere.push(this.SUBRULE(this.disjunction))\n\n\t\t\tthis.CONSUME(tokens.RightBracket)\n\t\t})\n\t\tif (cnfWhere.length === 1) {\n\t\t\treturn cnfWhere[0]\n\t\t}\n\t\treturn {\n\t\t\tand: cnfWhere,\n\t\t}\n\t})\n\n\tprivate disjunction: () => Filter = this.RULE('disjunction', () => {\n\t\tconst conjunctions: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Or,\n\t\t\tDEF: () => {\n\t\t\t\tconjunctions.push(this.SUBRULE(this.conjunction))\n\t\t\t},\n\t\t})\n\t\tif (conjunctions.length === 1) {\n\t\t\treturn conjunctions[0]\n\t\t}\n\t\treturn {\n\t\t\tor: conjunctions,\n\t\t}\n\t})\n\n\tprivate conjunction: () => Filter = this.RULE('conjunction', () => {\n\t\tconst negations: Filter[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.And,\n\t\t\tDEF: () => {\n\t\t\t\tnegations.push(this.SUBRULE(this.negation))\n\t\t\t},\n\t\t})\n\t\tif (negations.length === 1) {\n\t\t\treturn negations[0]\n\t\t}\n\t\treturn {\n\t\t\tand: negations,\n\t\t}\n\t})\n\n\t// TODO this is to naïve and needs rewriting\n\tprivate negation: () => Filter = this.RULE('negation', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.Not)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tnot: this.SUBRULE(this.filterGroup),\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\treturn this.SUBRULE1(this.filterGroup)\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate filterGroup: () => Filter = this.RULE('filterGroup', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.LeftParenthesis)\n\t\t\t\t\tconst subFilter = this.SUBRULE(this.disjunction)\n\t\t\t\t\tthis.CONSUME1(tokens.RightParenthesis)\n\t\t\t\t\treturn subFilter\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE1(this.filterAtom),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate filterAtom: () => Filter = this.RULE('filterAtom', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (typeof variable !== 'object' || variable instanceof GraphQlBuilder.GraphQlLiteral) {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`Invalid filter value '${JSON.stringify(variable)}'`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn variable\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE1(this.fieldWhere),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate fieldWhere: () => Parser.AST.FieldWhere = this.RULE('fieldWhere', () => {\n\t\tconst fields: FieldName[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Dot,\n\t\t\tDEF: () => {\n\t\t\t\tfields.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t},\n\t\t})\n\n\t\tconst condition = this.SUBRULE(this.condition)\n\n\t\tlet i = fields.length - 1\n\t\tlet where: Parser.AST.FieldWhere = {\n\t\t\t[fields[i--]]: condition,\n\t\t}\n\n\t\twhile (i >= 0) {\n\t\t\twhere = {\n\t\t\t\t[fields[i--]]: where,\n\t\t\t}\n\t\t}\n\n\t\treturn where\n\t})\n\n\tprivate condition: () => Parser.AST.Condition = this.RULE('condition', () => {\n\t\tconst operator = this.SUBRULE(this.conditionOperator)\n\t\tconst columnValue = this.SUBRULE(this.columnValue)\n\t\tconst condition: Parser.AST.Condition = {}\n\n\t\treturn this.ACTION(() => {\n\t\t\tif (columnValue === null) {\n\t\t\t\tif (operator === 'eq') {\n\t\t\t\t\tcondition.null = true\n\t\t\t\t} else if (operator === 'notEq') {\n\t\t\t\t\tcondition.null = false\n\t\t\t\t} else {\n\t\t\t\t\tthrow new QueryLanguageError(`The null keyword as a right hand operand can only be tested for (in)equality.`)\n\t\t\t\t}\n\t\t\t\treturn condition\n\t\t\t}\n\t\t\tcondition[operator] = columnValue\n\n\t\t\treturn condition\n\t\t})\n\t})\n\n\tprivate conditionOperator: () => Parser.AST.ConditionOperator = this.RULE<Parser.AST.ConditionOperator>(\n\t\t'conditionOperator',\n\t\t() => {\n\t\t\treturn this.OR([\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.Equals)\n\t\t\t\t\t\treturn 'eq'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.NotEquals)\n\t\t\t\t\t\treturn 'notEq'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.LowerThan)\n\t\t\t\t\t\treturn 'lt'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.LowerEqual)\n\t\t\t\t\t\treturn 'lte'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.GreaterThan)\n\t\t\t\t\t\treturn 'gt'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tALT: () => {\n\t\t\t\t\t\tthis.CONSUME(tokens.GreaterEqual)\n\t\t\t\t\t\treturn 'gte'\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t])\n\t\t},\n\t)\n\n\tprivate columnValue: () => Parser.AST.ColumnValue = this.RULE<Parser.AST.ColumnValue>('columnValue', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.Null)\n\t\t\t\t\treturn null\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.True)\n\t\t\t\t\treturn true\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tthis.CONSUME(tokens.False)\n\t\t\t\t\treturn false\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.primaryValue),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate uniqueWhere = this.RULE('uniqueWhere', () => {\n\t\tconst where: UniqueWhere = {}\n\n\t\tthis.CONSUME(tokens.LeftParenthesis)\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Comma,\n\t\t\tDEF: () => {\n\t\t\t\tconst nestedFields: string[] = []\n\t\t\t\tthis.AT_LEAST_ONE_SEP1({\n\t\t\t\t\tSEP: tokens.Dot,\n\t\t\t\t\tDEF: () => {\n\t\t\t\t\t\tnestedFields.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tthis.CONSUME(tokens.Equals)\n\t\t\t\tconst primaryValue = this.SUBRULE<Input.PrimaryValue<GraphQlBuilder.GraphQlLiteral>>(this.primaryValue)\n\n\t\t\t\tthis.ACTION(() => {\n\t\t\t\t\tlet nestedWhere = where\n\t\t\t\t\tfor (let i = 0, len = nestedFields.length; i < len; i++) {\n\t\t\t\t\t\tconst nestedField = nestedFields[i]\n\n\t\t\t\t\t\tconst isLast = len - 1 === i\n\n\t\t\t\t\t\tif (isLast) {\n\t\t\t\t\t\t\tif (nestedField in nestedWhere) {\n\t\t\t\t\t\t\t\tthrow new QueryLanguageError(`Duplicate '${nestedFields.slice(0, i + 1).join('.')}' field`)\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tnestedWhere[nestedField] = primaryValue\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (nestedField in nestedWhere) {\n\t\t\t\t\t\t\t\tconst existingWhere = nestedWhere[nestedField]\n\n\t\t\t\t\t\t\t\tif (typeof existingWhere === 'object' && !(existingWhere instanceof GraphQlBuilder.GraphQlLiteral)) {\n\t\t\t\t\t\t\t\t\tnestedWhere = existingWhere\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t\t\t\t\t\t`Malformed expression: cannot simultaneously treat the '${nestedFields\n\t\t\t\t\t\t\t\t\t\t\t.slice(0, i + 1)\n\t\t\t\t\t\t\t\t\t\t\t.join('.')}' ` + `field as a scalar as well as a relation.`,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tconst newWhere = {}\n\t\t\t\t\t\t\t\tnestedWhere[nestedField] = newWhere\n\t\t\t\t\t\t\t\tnestedWhere = newWhere\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})\n\t\t\t},\n\t\t})\n\t\tthis.CONSUME(tokens.RightParenthesis)\n\n\t\treturn where\n\t})\n\n\tprivate orderBy: () => Input.OrderBy<CrudQueryBuilder.OrderDirection>[] = this.RULE<\n\t\tInput.OrderBy<CrudQueryBuilder.OrderDirection>[]\n\t>('orderBy', () => {\n\t\tconst order: Input.OrderBy<CrudQueryBuilder.OrderDirection>[] = []\n\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Comma,\n\t\t\tDEF: () => {\n\t\t\t\tconst fieldNames: FieldName[] = []\n\t\t\t\tthis.AT_LEAST_ONE_SEP1({\n\t\t\t\t\tSEP: tokens.Dot,\n\t\t\t\t\tDEF: () => {\n\t\t\t\t\t\tfieldNames.push(this.SUBRULE(this.fieldIdentifier))\n\t\t\t\t\t},\n\t\t\t\t})\n\t\t\t\tlet literal = this.OPTION(() => this.SUBRULE1(this.graphQlLiteral)) as\n\t\t\t\t\t| CrudQueryBuilder.OrderDirection\n\t\t\t\t\t| undefined\n\n\t\t\t\tthis.ACTION(() => {\n\t\t\t\t\tif (literal) {\n\t\t\t\t\t\tif (literal.value !== 'asc' && literal.value !== 'desc') {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`The only valid order directions are \\`asc\\` and \\`desc\\`.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tliteral = new GraphQlBuilder.GraphQlLiteral('asc')\n\t\t\t\t\t}\n\t\t\t\t\tlet orderBy: Input.FieldOrderBy<CrudQueryBuilder.OrderDirection> = literal\n\n\t\t\t\t\tfor (let i = fieldNames.length - 1; i >= 0; i--) {\n\t\t\t\t\t\torderBy = { [fieldNames[i]]: orderBy }\n\t\t\t\t\t}\n\t\t\t\t\torder.push(orderBy as Input.OrderBy<CrudQueryBuilder.OrderDirection>)\n\t\t\t\t})\n\t\t\t},\n\t\t})\n\n\t\treturn order\n\t})\n\n\tprivate taggedMap: () => ParsedTaggedMap = this.RULE<ParsedTaggedMap>('taggedMap', () => {\n\t\tconst name = this.SUBRULE(this.identifier)\n\t\treturn {\n\t\t\tname,\n\t\t\tentries: this.OPTION(() => this.SUBRULE(this.taggedMapEntries)) ?? [],\n\t\t}\n\t})\n\n\tprivate taggedMapEntries: () => ParsedTaggedMapEntry[] = this.RULE<ParsedTaggedMapEntry[]>('taggedMapEntries', () => {\n\t\tthis.CONSUME(tokens.LeftParenthesis)\n\t\tconst entries: ParsedTaggedMapEntry[] = []\n\t\tthis.AT_LEAST_ONE_SEP({\n\t\t\tSEP: tokens.Comma,\n\t\t\tDEF: () => entries.push(this.SUBRULE(this.taggedMapEntry)),\n\t\t})\n\t\tthis.CONSUME(tokens.RightParenthesis)\n\n\t\treturn entries\n\t})\n\n\tprivate taggedMapEntry: () => ParsedTaggedMapEntry = this.RULE<ParsedTaggedMapEntry>('taggedMapEntry', () => {\n\t\tconst variableName = this.CONSUME(tokens.Identifier).image\n\t\tthis.CONSUME1(tokens.Colon)\n\t\tconst value = this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.taggedMapLiteralValue),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.taggedMapVariableValue),\n\t\t\t},\n\t\t])\n\n\t\treturn {\n\t\t\tkey: variableName,\n\t\t\tvalue,\n\t\t}\n\t})\n\n\tprivate taggedMapLiteralValue: () => ParsedTaggedMapLiteralValue = this.RULE<ParsedTaggedMapLiteralValue>('taggedMapLiteralValue', () => {\n\t\tconst value = this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.string),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.number),\n\t\t\t},\n\t\t])\n\n\t\treturn {\n\t\t\ttype: 'literal',\n\t\t\tvalue,\n\t\t}\n\t})\n\n\tprivate taggedMapVariableValue: () => ParsedTaggedMapVariableValue = this.RULE<ParsedTaggedMapVariableValue>('taggedMapVariableValue', () => {\n\t\tconst start = this.CONSUME(tokens.DollarSign)\n\t\tthis.SUBRULE(this.relativeSingleField)\n\t\tconst end = this.LA(0)\n\t\tconst field = this.input.slice(this.input.indexOf(start) + 1, this.input.indexOf(end) + 1).map(it => it.image).join('')\n\n\t\treturn {\n\t\t\ttype: 'variable',\n\t\t\tvalue: field,\n\t\t}\n\t})\n\n\n\tprivate fieldName: () => FieldName = this.RULE<FieldName>('fieldName', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.fieldIdentifier),\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate primaryValue = this.RULE<Input.PrimaryValue<GraphQlBuilder.GraphQlLiteral>>('primaryValue', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.string),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.number),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => this.SUBRULE(this.graphQlLiteral),\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variableValue = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof variableValue === 'string' ||\n\t\t\t\t\t\t\ttypeof variableValue === 'number' ||\n\t\t\t\t\t\t\tvariableValue instanceof GraphQlBuilder.GraphQlLiteral\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn variableValue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t\t\t`A variable can resolve to a literal, string or a number, not ${typeof variableValue}`,\n\t\t\t\t\t\t)\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate fieldIdentifier: () => FieldName = this.RULE('fieldIdentifier', () => {\n\t\treturn this.SUBRULE(this.identifier)\n\t\t// return this.OR([\n\t\t// \t{\n\t\t// \t\tALT: () => this.SUBRULE(this.identifier),\n\t\t// \t},\n\t\t// \t{\n\t\t// \t\tALT: () => {\n\t\t// \t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t// \t\t\treturn this.ACTION(() => {\n\t\t// \t\t\t\tif (!(typeof variable === 'string') || !TokenRegExps.identifier.test(variable)) {\n\t\t// \t\t\t\t\tthrow new QueryLanguageError(`The value \\$${variable} is not a valid field identifier.`)\n\t\t// \t\t\t\t}\n\t\t// \t\t\t\treturn variable\n\t\t// \t\t\t})\n\t\t// \t\t},\n\t\t// \t},\n\t\t// ])\n\t})\n\n\tprivate identifier: () => string = this.RULE('identifier', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.CONSUME(tokens.Identifier).image,\n\t\t\t},\n\t\t\t{\n\t\t\t\t// TODO this is a temporary hack to allow for literals that start with an uppercase letter… 🙈\n\t\t\t\tALT: () => this.CONSUME(tokens.EntityIdentifier).image,\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate entityIdentifier: () => EntityName = this.RULE('entityIdentifier', () => {\n\t\treturn this.OR([\n\t\t\t{\n\t\t\t\tALT: () => this.CONSUME(tokens.EntityIdentifier).image,\n\t\t\t},\n\t\t\t{\n\t\t\t\tALT: () => {\n\t\t\t\t\tconst variable = this.SUBRULE(this.variable)\n\t\t\t\t\treturn this.ACTION(() => {\n\t\t\t\t\t\tif (!(typeof variable === 'string') || !TokenRegExps.entityIdentifier.test(variable)) {\n\t\t\t\t\t\t\tthrow new QueryLanguageError(`The value of the variable \\$${variable} is not a valid entity identifier.`)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn variable\n\t\t\t\t\t})\n\t\t\t\t},\n\t\t\t},\n\t\t])\n\t})\n\n\tprivate string = this.RULE('string', () => {\n\t\tconst image = this.CONSUME(tokens.StringLiteral).image\n\t\treturn image\n\t\t\t.substring(1, image.length - 1)\n\t\t\t.replace(\"\\\\'\", \"'\")\n\t\t\t.replace('\\\\b', '\\b')\n\t\t\t.replace('\\\\f', '\\f')\n\t\t\t.replace('\\\\n', '\\n')\n\t\t\t.replace('\\\\r', '\\r')\n\t\t\t.replace('\\\\t', '\\t')\n\t\t\t.replace('\\\\v', '\\v')\n\t})\n\n\tprivate number = this.RULE('number', () => {\n\t\treturn parseFloat(this.CONSUME(tokens.NumberLiteral).image)\n\t})\n\n\tprivate graphQlLiteral: () => GraphQlBuilder.GraphQlLiteral = this.RULE('graphQlLiteral', () => {\n\t\tconst image = this.SUBRULE(this.identifier)\n\n\t\treturn new GraphQlBuilder.GraphQlLiteral(image)\n\t})\n\n\tprivate variable = this.RULE<string | number | GraphQlLiteral | Filter | UniqueWhere>('variable', () => {\n\t\tthis.CONSUME(tokens.DollarSign)\n\t\tconst variableName = this.CONSUME(tokens.Identifier).image\n\n\t\treturn this.ACTION(() => {\n\t\t\tif (Parser.environment.hasName(variableName)) {\n\t\t\t\treturn Parser.environment.getValue(variableName)\n\t\t\t}\n\t\t\tif (Parser.environment.hasDimension(variableName)) {\n\t\t\t\tconst dimensionValue = Parser.environment.getDimension(variableName)\n\n\t\t\t\tif (dimensionValue.length === 1) {\n\t\t\t\t\treturn dimensionValue[0]\n\t\t\t\t}\n\t\t\t\tthrow new QueryLanguageError(\n\t\t\t\t\t`The variable \\$${variableName} resolved to a dimension which exists but contains ${dimensionValue.length} values. It has to contain exactly one. ` +\n\t\t\t\t\t\t`Perhaps you forgot to set the 'maxItems' prop of your DimensionsSwitcher?`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tthrow new QueryLanguageError(`Undefined variable \\$${variableName}.`)\n\t\t})\n\t})\n\n\tprivate constructor() {\n\t\tsuper(tokenList, { outputCst: false, maxLookahead: 1 })\n\t\tthis.performSelfAnalysis()\n\t}\n\n\tpublic static parseQueryLanguageExpression<E extends Parser.EntryPoint>(\n\t\tinput: string,\n\t\tentry: E,\n\t\tenvironment: Environment,\n\t): Parser.ParserResult[E] {\n\t\tconst cached = this.cacheStore.get(environment, entry, input)\n\n\t\tif (cached !== undefined) {\n\t\t\treturn cached\n\t\t}\n\n\t\tconst lexingResult = Parser.lexer.tokenize((Parser.rawInput = input))\n\n\t\tif (lexingResult.errors.length !== 0) {\n\t\t\tthrow new QueryLanguageError(\n\t\t\t\t`Failed to tokenize '${input}'.\\n\\n${lexingResult.errors.map(i => i.message).join('\\n')}`,\n\t\t\t)\n\t\t}\n\n\t\tParser.environment = environment\n\t\tParser.parser.input = lexingResult.tokens\n\n\t\tlet expression: Parser.ParserResult[keyof Parser.ParserResult]\n\n\t\tswitch (entry) {\n\t\t\tcase 'relativeSingleField':\n\t\t\t\texpression = Parser.parser.relativeSingleField()\n\t\t\t\tbreak\n\t\t\tcase 'relativeSingleEntity':\n\t\t\t\texpression = Parser.parser.relativeSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'relativeEntityList':\n\t\t\t\texpression = Parser.parser.relativeEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedEntityList':\n\t\t\t\texpression = Parser.parser.qualifiedEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedFieldList':\n\t\t\t\texpression = Parser.parser.qualifiedFieldList()\n\t\t\t\tbreak\n\t\t\tcase 'qualifiedSingleEntity':\n\t\t\t\texpression = Parser.parser.qualifiedSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'unconstrainedQualifiedEntityList':\n\t\t\t\texpression = Parser.parser.unconstrainedQualifiedEntityList()\n\t\t\t\tbreak\n\t\t\tcase 'unconstrainedQualifiedSingleEntity':\n\t\t\t\texpression = Parser.parser.unconstrainedQualifiedSingleEntity()\n\t\t\t\tbreak\n\t\t\tcase 'uniqueWhere':\n\t\t\t\texpression = Parser.parser.uniqueWhere()\n\t\t\t\tbreak\n\t\t\tcase 'filter':\n\t\t\t\texpression = Parser.parser.nonUniqueWhere()\n\t\t\t\tbreak\n\t\t\tcase 'orderBy':\n\t\t\t\texpression = Parser.parser.orderBy()\n\t\t\t\tbreak\n\t\t\tcase 'taggedMap':\n\t\t\t\texpression = Parser.parser.taggedMap()\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tthrow new QueryLanguageError(`Not implemented entry point '${entry}'`)\n\t\t}\n\n\t\tif (Parser.parser.errors.length !== 0) {\n\t\t\tthrow new QueryLanguageError(\n\t\t\t\t`Failed to parse '${input}'.\\n\\n${Parser.parser.errors.map(i => i.message).join('\\n')}`,\n\t\t\t)\n\t\t}\n\n\t\tthis.cacheStore.set(environment, entry, input, expression as Parser.ParserResult[E])\n\n\t\treturn expression as Parser.ParserResult[E]\n\t}\n}\n\nnamespace Parser {\n\texport namespace AST {\n\t\texport type FieldWhere = Input.FieldWhere<Condition>\n\n\t\texport type ColumnValue = Input.ColumnValue<GraphQlBuilder.GraphQlLiteral>\n\n\t\texport type Condition = Input.Condition<ColumnValue>\n\n\t\texport type ConditionOperator = keyof Pick<Condition, 'eq' | 'notEq' | 'lt' | 'lte' | 'gt' | 'gte'>\n\t}\n\n\texport interface ParserResult {\n\t\tqualifiedEntityList: ParsedQualifiedEntityList // E.g. Author[age < 123].son.sisters(name = 'Jane')\n\t\tqualifiedFieldList: ParsedQualifiedFieldList // E.g. Author[age < 123].son.sister.name\n\t\tqualifiedSingleEntity: ParsedQualifiedSingleEntity // E.g. Author(id = 123).son.sister\n\t\tunconstrainedQualifiedEntityList: ParsedUnconstrainedQualifiedEntityList // E.g. Author.son.sister\n\t\tunconstrainedQualifiedSingleEntity: ParsedUnconstrainedQualifiedSingleEntity // E.g. Author.son.sister\n\t\trelativeSingleField: ParsedRelativeSingleField // E.g. authors(id = 123).person.name\n\t\trelativeSingleEntity: ParsedRelativeSingleEntity // E.g. localesByLocale(locale.slug = en)\n\t\trelativeEntityList: ParsedRelativeEntityList // E.g. genres(slug = 'sciFi').authors[age < 123]\n\t\tuniqueWhere: UniqueWhere // E.g. (author.mother.id = 123)\n\t\tfilter: Filter // E.g. [author.son.age < 123]\n\t\torderBy: OrderBy // E.g. items.order asc, items.content.name asc\n\t\ttaggedMap: ParsedTaggedMap // E.g editUser(id: $entity.id, foo: 'bar')\n\t}\n\n\texport type EntryPoint = keyof ParserResult\n}\n\nexport { Parser }\n"],"names":[],"mappings":";;;;;;;;;;;;AA+BA,8BAAqB,sBAAsB;AAAA,EAisBlC,cAAc;UACf,WAAW,EAAE,WAAW,OAAO,cAAc;AA3rB5C,+CA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EAAc,QAAO,OAAO,OAAO,IAAI,OAAK,EAAE,SAAS,KAAK;AAAA;SAI7E,WAAW,IAAI,aAAa,OAAO,OAAO;WAExC;AAAA;AAAA;AA/wBT;AACgB,cADhB,QACgB,YAAmB;AACnB,cAFhB,QAEgB,SAAQ,IAAI,MAAM;AAClB,cAHhB,QAGgB,UAAS,IAAI;AACb,cAJhB,QAIgB,eAA2B,IAAI;AAC/B,cALhB,QAKgB,cAAyB,IAAI;;"}
@@ -446,5 +446,6 @@ __publicField(QueryLanguage, "parseRelativeSingleField", _QueryLanguage.prepareP
446
446
  __publicField(QueryLanguage, "desugarUniqueWhere", _QueryLanguage.preparePrimitiveEntryPointWithFallback("uniqueWhere"));
447
447
  __publicField(QueryLanguage, "desugarFilter", _QueryLanguage.preparePrimitiveEntryPointWithFallback("filter"));
448
448
  __publicField(QueryLanguage, "desugarOrderBy", _QueryLanguage.preparePrimitiveEntryPointWithFallback("orderBy"));
449
+ __publicField(QueryLanguage, "desugarTaggedMap", _QueryLanguage.preparePrimitiveEntryPointWithFallback("taggedMap"));
449
450
  export { QueryLanguage };
450
451
  //# sourceMappingURL=QueryLanguage.js.map