@contember/binding 0.8.0-alpha.7 → 1.0.0-alpha.2

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 (70) hide show
  1. package/dist/binding.d.ts +50 -32
  2. package/dist/development/accessorPropagation/useHasEntity.js +9 -0
  3. package/dist/development/accessorPropagation/useHasEntity.js.map +1 -0
  4. package/dist/development/accessors/EntityAccessor.js +2 -1
  5. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  6. package/dist/development/accessors/EntityListAccessor.js +3 -1
  7. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  8. package/dist/development/accessors/ErrorAccessor.js +7 -21
  9. package/dist/development/accessors/ErrorAccessor.js.map +1 -1
  10. package/dist/development/accessors/FieldAccessor.js +2 -1
  11. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  12. package/dist/development/core/AccessorErrorManager.js +7 -4
  13. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  14. package/dist/development/core/DataBinding.js +2 -0
  15. package/dist/development/core/DataBinding.js.map +1 -1
  16. package/dist/development/core/ErrorsPreprocessor.js +11 -16
  17. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  18. package/dist/development/core/MutationGenerator.js +1 -1
  19. package/dist/development/core/MutationGenerator.js.map +1 -1
  20. package/dist/development/core/operations/EntityOperations.js +1 -1
  21. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  22. package/dist/development/core/operations/FieldOperations.js +1 -1
  23. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  24. package/dist/development/core/operations/ListOperations.js +1 -1
  25. package/dist/development/core/operations/ListOperations.js.map +1 -1
  26. package/dist/development/index.js +1 -0
  27. package/dist/development/index.js.map +1 -1
  28. package/dist/development/queryLanguage/CacheStore.js +2 -1
  29. package/dist/development/queryLanguage/CacheStore.js.map +1 -1
  30. package/dist/development/queryLanguage/Parser.js +60 -0
  31. package/dist/development/queryLanguage/Parser.js.map +1 -1
  32. package/dist/development/queryLanguage/QueryLanguage.js +1 -0
  33. package/dist/development/queryLanguage/QueryLanguage.js.map +1 -1
  34. package/dist/development/queryLanguage/tokenList.js +5 -0
  35. package/dist/development/queryLanguage/tokenList.js.map +1 -1
  36. package/dist/production/accessorPropagation/useHasEntity.js +7 -0
  37. package/dist/production/accessorPropagation/useHasEntity.js.map +1 -0
  38. package/dist/production/accessors/EntityAccessor.js +2 -1
  39. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  40. package/dist/production/accessors/EntityListAccessor.js +2 -1
  41. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  42. package/dist/production/accessors/ErrorAccessor.js +7 -27
  43. package/dist/production/accessors/ErrorAccessor.js.map +1 -1
  44. package/dist/production/accessors/FieldAccessor.js +2 -1
  45. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  46. package/dist/production/core/AccessorErrorManager.js +7 -4
  47. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  48. package/dist/production/core/DataBinding.js +2 -0
  49. package/dist/production/core/DataBinding.js.map +1 -1
  50. package/dist/production/core/ErrorsPreprocessor.js +11 -16
  51. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  52. package/dist/production/core/MutationGenerator.js +1 -1
  53. package/dist/production/core/MutationGenerator.js.map +1 -1
  54. package/dist/production/core/operations/EntityOperations.js +1 -1
  55. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  56. package/dist/production/core/operations/FieldOperations.js +1 -1
  57. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  58. package/dist/production/core/operations/ListOperations.js +1 -1
  59. package/dist/production/core/operations/ListOperations.js.map +1 -1
  60. package/dist/production/index.js +1 -0
  61. package/dist/production/index.js.map +1 -1
  62. package/dist/production/queryLanguage/CacheStore.js +2 -1
  63. package/dist/production/queryLanguage/CacheStore.js.map +1 -1
  64. package/dist/production/queryLanguage/Parser.js +60 -0
  65. package/dist/production/queryLanguage/Parser.js.map +1 -1
  66. package/dist/production/queryLanguage/QueryLanguage.js +1 -0
  67. package/dist/production/queryLanguage/QueryLanguage.js.map +1 -1
  68. package/dist/production/queryLanguage/tokenList.js +5 -0
  69. package/dist/production/queryLanguage/tokenList.js.map +1 -1
  70. package/package.json +5 -5
package/dist/binding.d.ts CHANGED
@@ -25,10 +25,11 @@ declare class AccessorErrorManager {
25
25
  private getNewErrorId;
26
26
  constructor(eventManager: EventManager, treeStore: TreeStore);
27
27
  hasErrors(): boolean;
28
+ getErrors(): ErrorAccessor.Error[];
28
29
  clearErrors(): void;
29
30
  clearErrorsByState(state: StateNode): void;
30
31
  replaceErrors(data: MutationDataResponse): void;
31
- addError(state: StateNode, error: ErrorAccessor.BoxedError): () => void;
32
+ addError(state: StateNode, error: ErrorAccessor.Error): () => void;
32
33
  private addSeveralErrors;
33
34
  private setRootStateErrors;
34
35
  private setEntityStateErrors;
@@ -271,7 +272,7 @@ export declare class EntityAccessor implements Errorable {
271
272
  */
272
273
  get id(): EntityId;
273
274
  get existsOnServer(): boolean;
274
- addError(error: ErrorAccessor.SugaredValidationError): () => void;
275
+ addError(error: ErrorAccessor.Error | string): () => void;
275
276
  addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(event: {
276
277
  type: Type;
277
278
  key?: string;
@@ -411,7 +412,7 @@ export declare class EntityListAccessor implements Errorable {
411
412
  hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean;
412
413
  deleteAll(): void;
413
414
  disconnectAll(): void;
414
- addError(error: ErrorAccessor.SugaredValidationError): () => void;
415
+ addError(error: ErrorAccessor.Error | string): () => void;
415
416
  addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(event: {
416
417
  type: Type;
417
418
  key?: string;
@@ -545,7 +546,7 @@ declare class EntityOperations {
545
546
  private readonly stateInitializer;
546
547
  private readonly treeStore;
547
548
  constructor(accessorErrorManager: AccessorErrorManager, batchUpdatesOptions: BatchUpdatesOptions, eventManager: EventManager, stateInitializer: StateInitializer, treeStore: TreeStore);
548
- addError(entityRealm: EntityRealmState, error: ErrorAccessor.SugaredValidationError): () => void;
549
+ addError(entityRealm: EntityRealmState, error: ErrorAccessor.Error): () => void;
549
550
  addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(state: EntityRealmState, event: {
550
551
  type: Type;
551
552
  key?: string;
@@ -700,42 +701,28 @@ export declare interface Errorable {
700
701
  }
701
702
 
702
703
  export declare class ErrorAccessor {
703
- private readonly errors;
704
- readonly validation: ErrorAccessor.ValidationErrors | undefined;
705
- readonly execution: ErrorAccessor.ExecutionErrors | undefined;
706
- constructor(errors: ErrorAccessor.ErrorsById);
704
+ readonly errors: ErrorAccessor.Error[];
705
+ constructor(errors: ErrorAccessor.Error[]);
707
706
  }
708
707
 
709
708
  export declare namespace ErrorAccessor {
710
709
  export type ErrorId = number;
711
- export type BoxedError = BoxedExecutionError | BoxedValidationError;
712
- export type ErrorsById = Map<ErrorId, BoxedError>;
713
- export type ExecutionErrors = [ExecutionError, ...ExecutionError[]];
714
- export interface BoxedExecutionError {
715
- type: 'execution';
716
- error: SugaredExecutionError;
717
- }
718
- export type SugaredExecutionError = Result.ExecutionErrorType | Omit<ExecutionError, 'key'>;
710
+ export type Error = ExecutionError | ValidationError;
711
+ export type ErrorsById = Map<ErrorId, Error>;
712
+ export type ExecutionErrors = ExecutionError[];
719
713
  export interface ExecutionError {
720
- key: ErrorId;
721
- type: Result.ExecutionErrorType;
714
+ type: 'execution';
715
+ code: Result.ExecutionErrorType;
722
716
  developerMessage: string | null;
723
717
  }
724
- export type ValidationErrors = [ValidationError, ...ValidationError[]];
725
- export interface BoxedValidationError {
726
- type: 'validation';
727
- error: SugaredValidationError;
728
- }
729
- export type SugaredValidationError = string | {
730
- message: string;
731
- code?: string;
732
- };
718
+ export type ValidationErrors = ValidationError[];
733
719
  export interface ValidationError {
734
- key: ErrorId;
735
- message: string;
720
+ type: 'validation';
736
721
  code: WellKnownErrorCode | string | undefined;
722
+ message: string;
737
723
  }
738
724
  export type WellKnownErrorCode = 'fieldRequired';
725
+ const normalizeError: (error: Error | string) => Error;
739
726
  }
740
727
 
741
728
  export declare interface ErrorAccessorTreeState {
@@ -861,7 +848,7 @@ export declare class FieldAccessor<Value extends FieldValue = FieldValue> implem
861
848
  private readonly touchLog;
862
849
  readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>;
863
850
  constructor(stateKey: FieldState<Value>, operations: FieldOperations, fieldName: FieldName, value: Value | null, valueOnServer: Value | null, defaultValue: Value | undefined, errors: ErrorAccessor | undefined, hasUnpersistedChanges: boolean, touchLog: ReadonlySet<string> | undefined, getAccessor: FieldAccessor.GetFieldAccessor<Value>);
864
- addError(error: ErrorAccessor.SugaredValidationError): () => void;
851
+ addError(error: ErrorAccessor.Error | string): () => void;
865
852
  clearErrors(): void;
866
853
  addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(event: {
867
854
  type: Type;
@@ -930,7 +917,7 @@ declare class FieldOperations {
930
917
  private readonly stateInitializer;
931
918
  private readonly treeStore;
932
919
  constructor(accessorErrorManager: AccessorErrorManager, eventManager: EventManager, stateInitializer: StateInitializer, treeStore: TreeStore);
933
- addError(fieldState: FieldState<any>, error: ErrorAccessor.SugaredValidationError): () => void;
920
+ addError(fieldState: FieldState<any>, error: ErrorAccessor.Error): () => void;
934
921
  clearErrors(fieldState: FieldState<any>): void;
935
922
  addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap, Value extends FieldValue = FieldValue>(state: FieldState<Value>, event: {
936
923
  type: Type;
@@ -1099,6 +1086,7 @@ export declare interface InitializingAccessorTreeState {
1099
1086
 
1100
1087
  export declare interface InvalidInputPersistResult {
1101
1088
  type: 'invalidInput';
1089
+ errors: ErrorAccessor.Error[];
1102
1090
  }
1103
1091
 
1104
1092
  declare interface InverseRelation extends BaseRelation {
@@ -1140,7 +1128,7 @@ declare class ListOperations {
1140
1128
  private readonly stateInitializer;
1141
1129
  private readonly treeStore;
1142
1130
  constructor(accessorErrorManager: AccessorErrorManager, batchUpdatesOptions: BatchUpdatesOptions, eventManager: EventManager, stateInitializer: StateInitializer, treeStore: TreeStore);
1143
- addError(listState: EntityListState, error: ErrorAccessor.SugaredValidationError): () => void;
1131
+ addError(listState: EntityListState, error: ErrorAccessor.Error): () => void;
1144
1132
  addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(state: EntityListState, event: {
1145
1133
  type: Type;
1146
1134
  key?: string;
@@ -1338,6 +1326,26 @@ declare interface ParsedRelativeSingleField {
1338
1326
  field: FieldName;
1339
1327
  }
1340
1328
 
1329
+ declare interface ParsedTaggedMap {
1330
+ name: string;
1331
+ entries: ParsedTaggedMapEntry[];
1332
+ }
1333
+
1334
+ declare interface ParsedTaggedMapEntry {
1335
+ key: string;
1336
+ value: ParsedTaggedMapLiteralValue | ParsedTaggedMapVariableValue;
1337
+ }
1338
+
1339
+ declare interface ParsedTaggedMapLiteralValue {
1340
+ type: 'literal';
1341
+ value: string | number;
1342
+ }
1343
+
1344
+ declare interface ParsedTaggedMapVariableValue {
1345
+ type: 'variable';
1346
+ value: string;
1347
+ }
1348
+
1341
1349
  declare interface ParsedUnconstrainedQualifiedEntityList {
1342
1350
  entityName: EntityName;
1343
1351
  hasOneRelationPath: ParsedHasOneRelation[];
@@ -1382,6 +1390,11 @@ export declare class Parser extends EmbeddedActionsParser {
1382
1390
  private columnValue;
1383
1391
  private uniqueWhere;
1384
1392
  private orderBy;
1393
+ private taggedMap;
1394
+ private taggedMapEntries;
1395
+ private taggedMapEntry;
1396
+ private taggedMapLiteralValue;
1397
+ private taggedMapVariableValue;
1385
1398
  private fieldName;
1386
1399
  private primaryValue;
1387
1400
  private fieldIdentifier;
@@ -1414,6 +1427,7 @@ export declare namespace Parser {
1414
1427
  uniqueWhere: UniqueWhere;
1415
1428
  filter: Filter;
1416
1429
  orderBy: OrderBy;
1430
+ taggedMap: ParsedTaggedMap;
1417
1431
  }
1418
1432
  export type EntryPoint = keyof ParserResult;
1419
1433
  }
@@ -1491,6 +1505,7 @@ export declare class QueryLanguage {
1491
1505
  static desugarUniqueWhere: (input: string | UniqueWhere<GraphQlLiteral<string>>, environment: Environment) => UniqueWhere<GraphQlLiteral<string>>;
1492
1506
  static desugarFilter: (input: string | Filter<GraphQlLiteral<string>>, environment: Environment) => Filter<GraphQlLiteral<string>>;
1493
1507
  static desugarOrderBy: (input: string | OrderBy, environment: Environment) => OrderBy;
1508
+ static desugarTaggedMap: (input: string | ParsedTaggedMap, environment: Environment) => ParsedTaggedMap;
1494
1509
  private static desugarEntityListParameters;
1495
1510
  static desugarSetOnCreate(setOnCreate: SugaredSetOnCreate, environment: Environment): UniqueWhere;
1496
1511
  static desugarEventListener<F extends Function>(listener: F | Set<F>): Set<F>;
@@ -1873,6 +1888,7 @@ export declare const tokens: {
1873
1888
  DollarSign: TokenType;
1874
1889
  Dot: TokenType;
1875
1890
  Comma: TokenType;
1891
+ Colon: TokenType;
1876
1892
  NumberLiteral: TokenType;
1877
1893
  StringLiteral: TokenType;
1878
1894
  LeftParenthesis: TokenType;
@@ -2202,6 +2218,8 @@ export declare const useGetEntitySubTree: () => (parametersOrAlias: Alias | Suga
2202
2218
 
2203
2219
  export declare const useGetTreeFilters: () => (() => TreeFilter[]);
2204
2220
 
2221
+ export declare const useHasEntity: () => boolean;
2222
+
2205
2223
  export declare const useMutationState: () => boolean;
2206
2224
 
2207
2225
  export declare const useOnConnectionUpdate: (fieldName: FieldName, listener: EntityAccessor.EntityEventListenerMap['connectionUpdate']) => void;
@@ -0,0 +1,9 @@
1
+ import { useContext } from 'react';
2
+ import { EntityKeyContext } from './EntityKeyContext.js';
3
+
4
+ const useHasEntity = () => {
5
+ return useContext(EntityKeyContext) !== void 0;
6
+ };
7
+
8
+ export { useHasEntity };
9
+ //# sourceMappingURL=useHasEntity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHasEntity.js","sources":["../../../src/accessorPropagation/useHasEntity.ts"],"sourcesContent":["import { useContext } from 'react'\nimport { EntityKeyContext } from './EntityKeyContext'\n\nexport const useHasEntity = (): boolean => {\n\treturn useContext(EntityKeyContext) !== undefined\n}\n"],"names":[],"mappings":";;;MAGa,eAAe,MAAe;AAC1C,SAAO,WAAW,sBAAsB;AAAA;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { BindingError } from '../BindingError.js';
2
+ import { ErrorAccessor } from './ErrorAccessor.js';
2
3
  import { QueryLanguage } from '../queryLanguage/QueryLanguage.js';
3
4
  import { PlaceholderGenerator } from '../markers/PlaceholderGenerator.js';
4
5
  import { ServerGeneratedUuid } from '../accessorTree/RuntimeId.js';
@@ -27,7 +28,7 @@ class EntityAccessor {
27
28
  return this.runtimeId.existsOnServer;
28
29
  }
29
30
  addError(error) {
30
- return this.operations.addError(this.stateKey, error);
31
+ return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error));
31
32
  }
32
33
  addEventListener(event, listener) {
33
34
  return this.operations.addEventListener(this.stateKey, event, listener);
@@ -1 +1 @@
1
- {"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, ServerGeneratedUuid, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport type { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): string | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.SugaredValidationError): () => void {\n\t\treturn this.operations.addError(this.stateKey, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.stateKey, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.stateKey)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\tpublic getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {\n\t\tconst desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)\n\t\tconst lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]\n\t\tconst lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)\n\n\t\tlet containingAccessor: EntityAccessor = this\n\n\t\tif (desugared.hasOneRelationPath.length > 1) {\n\t\t\tcontainingAccessor = this.getRelativeSingleEntity({\n\t\t\t\thasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),\n\t\t\t})\n\t\t}\n\t\treturn containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n\n\tprivate getPersistedKeyByPlaceholder(placeholderName: string): string | null {\n\t\tif (this.dataFromServer === undefined) {\n\t\t\treturn null\n\t\t}\n\t\tconst key = this.dataFromServer.get(placeholderName)\n\n\t\tif (key instanceof ServerGeneratedUuid) {\n\t\t\treturn key.value\n\t\t}\n\t\tif (key === null) {\n\t\t\t// TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that\n\t\t\t// \thappens to be also null.\n\t\t\treturn null\n\t\t}\n\n\t\t// From now on, we're past the happy path, way into error land.\n\t\tif (key === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +\n\t\t\t\t\t`a typo, this typically happens when a has-one relation hasn't been registered during static render.`,\n\t\t\t)\n\t\t}\n\t\tif (key instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +\n\t\t\t\t\t`not a has-one. This method is meant exclusively for has-one relations.`,\n\t\t\t)\n\t\t}\n\t\tthrow new BindingError(\n\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +\n\t\t\t\t`has-one relation. This method is meant exclusively for has-one relations.`,\n\t\t)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;AA6BA,qBAA0C;AAAA,EAClC,YACW,UACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB;AACA;AACA;AACD;AACA;AACC;AACA;AACD;AACA;AACA;AACA;AAAA;AAAA,MAGN,aAAiC;AAC3C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA;AAAA,MAMpD,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA;AAAA,MAGZ,iBAA0B;AACpC,WAAO,KAAK,UAAU;AAAA;AAAA,EAKhB,SAAS,OAAyD;AACxE,WAAO,KAAK,WAAW,SAAS,KAAK,UAAU;AAAA;AAAA,EAGzC,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO;AAAA;AAAA,EAGxD,aAAa,gBAA0D;AAC7E,SAAK,WAAW,aAAa,KAAK,UAAU;AAAA;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ACrE,mBAAa,WAAW,yBACvB,qBAAqB,6BAA6B;AAAA;AAGpD,WAAO;AAAA;AAAA,EAGD,sBAAsB,YAAoD;AAChF,WAAO,KAAK,wBAAwB,YAAY,yBAC/C,qBAAqB,8BAA8B,WAAW;AAAA;AAAA,EAIxD,yBAAyB,iBAA2D;AAC3F,UAAM,SAAS,KAAK,UAAU,IAAI;AAClC,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,aACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3E,WAAO,OAAO;AAAA;AAAA,EAGP,6BAA6B,iBAAwC;AAC5E,QAAI,KAAK,mBAAmB,QAAW;AACtC,aAAO;AAAA;AAER,UAAM,MAAM,KAAK,eAAe,IAAI;AAEpC,QAAI,eAAe,qBAAqB;AACvC,aAAO,IAAI;AAAA;AAEZ,QAAI,QAAQ,MAAM;AAGjB,aAAO;AAAA;AAIR,QAAI,QAAQ,QAAW;AACtB,YAAM,IAAI,aACT,gEAAgE;AAAA;AAIlE,QAAI,eAAe,KAAK;AACvB,YAAM,IAAI,aACT,4DAA4D;AAAA;AAI9D,UAAM,IAAI,aACT,4DAA4D;AAAA;AAAA;;;;"}
1
+ {"version":3,"file":"EntityAccessor.js","sources":["../../../src/accessors/EntityAccessor.ts"],"sourcesContent":["import { RuntimeId, ServerGeneratedUuid, SingleEntityPersistedData } from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { EntityOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport { PlaceholderGenerator } from '../markers'\nimport { QueryLanguage } from '../queryLanguage'\nimport type {\n\tEntityId,\n\tEntityName,\n\tEntityRealmKey,\n\tFieldName,\n\tFieldValue,\n\tRelativeEntityList,\n\tRelativeSingleEntity,\n\tRelativeSingleField,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tSugaredRelativeSingleField,\n} from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityListAccessor } from './EntityListAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldAccessor } from './FieldAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityRealmState } from '../core/state'\n\nclass EntityAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityRealmState,\n\t\tprivate readonly operations: EntityOperations,\n\t\tprivate readonly runtimeId: RuntimeId,\n\t\tpublic readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️\n\t\tpublic readonly name: EntityName,\n\t\tprivate readonly fieldData: EntityAccessor.FieldData,\n\t\tprivate readonly dataFromServer: SingleEntityPersistedData | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityAccessor.GetEntityAccessor,\n\t) {}\n\n\tpublic get idOnServer(): string | undefined {\n\t\treturn this.runtimeId.existsOnServer ? this.runtimeId.value : undefined\n\t}\n\n\t/**\n\t * Note that for entities that don't yet exist on server this will return a dummy id.\n\t */\n\tpublic get id(): EntityId {\n\t\treturn this.runtimeId.value\n\t}\n\n\tpublic get existsOnServer(): boolean {\n\t\treturn this.runtimeId.existsOnServer\n\t}\n\n\t//\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntityAtField(this.stateKey, field, entityToConnect)\n\t}\n\n\tpublic disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)\n\t}\n\n\tpublic deleteEntity(): void {\n\t\tthis.operations.deleteEntity(this.stateKey)\n\t}\n\n\t//\n\n\tpublic updateValues(fieldValuePairs: EntityAccessor.FieldValuePairs): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst entries = Array.isArray(fieldValuePairs) ? fieldValuePairs : Object.entries(fieldValuePairs)\n\n\t\t\tfor (const [field, value] of entries) {\n\t\t\t\tgetAccessor().getField(field).updateValue(value)\n\t\t\t}\n\t\t})\n\t}\n\n\t/**\n\t * Please keep in mind that this method signature is literally impossible to implement safely. The generic parameter\n\t * is really just a way to succinctly write a type cast. Nothing more, really.\n\t */\n\tpublic getField<Value extends FieldValue = FieldValue>(\n\t\tfield: SugaredRelativeSingleField | string,\n\t): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleField<Value>(QueryLanguage.desugarRelativeSingleField(field, this.environment))\n\t}\n\n\tpublic getEntity(entity: SugaredRelativeSingleEntity | string): EntityAccessor {\n\t\treturn this.getRelativeSingleEntity(QueryLanguage.desugarRelativeSingleEntity(entity, this.environment))\n\t}\n\n\tpublic getEntityList(entityList: SugaredRelativeEntityList | string): EntityListAccessor {\n\t\treturn this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))\n\t}\n\n\tpublic getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {\n\t\tconst desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)\n\t\tconst lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]\n\t\tconst lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)\n\n\t\tlet containingAccessor: EntityAccessor = this\n\n\t\tif (desugared.hasOneRelationPath.length > 1) {\n\t\t\tcontainingAccessor = this.getRelativeSingleEntity({\n\t\t\t\thasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),\n\t\t\t})\n\t\t}\n\t\treturn containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)\n\t}\n\n\t//\n\n\t/**\n\t * @see EntityAccessor.getField\n\t */\n\tpublic getRelativeSingleField<Value extends FieldValue = FieldValue>(field: RelativeSingleField): FieldAccessor<Value> {\n\t\treturn this.getRelativeSingleEntity(field).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getFieldPlaceholder(field.field),\n\t\t) as unknown as FieldAccessor<Value>\n\t}\n\n\tpublic getRelativeSingleEntity(relativeSingleEntity: RelativeSingleEntity): EntityAccessor {\n\t\tlet relativeTo: EntityAccessor = this\n\n\t\tfor (const hasOneRelation of relativeSingleEntity.hasOneRelationPath) {\n\t\t\trelativeTo = relativeTo.getAccessorByPlaceholder(\n\t\t\t\tPlaceholderGenerator.getHasOneRelationPlaceholder(hasOneRelation),\n\t\t\t) as EntityAccessor\n\t\t}\n\t\treturn relativeTo\n\t}\n\n\tpublic getRelativeEntityList(entityList: RelativeEntityList): EntityListAccessor {\n\t\treturn this.getRelativeSingleEntity(entityList).getAccessorByPlaceholder(\n\t\t\tPlaceholderGenerator.getHasManyRelationPlaceholder(entityList.hasManyRelation),\n\t\t) as EntityListAccessor\n\t}\n\n\tprivate getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {\n\t\tconst record = this.fieldData.get(placeholderName)\n\t\tif (record === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor: unknown field placeholder '${placeholderName} on ${this.name}'. Unless this is just a typo, this is ` +\n\t\t\t\t\t`typically caused by one of the following:\\n` +\n\t\t\t\t\t`\\t• Trying to access a field that has not been registered during static render, and thus lacks a marker and an accessor.\\n` +\n\t\t\t\t\t`\\t• Misusing an EntityAccessor getter. If you used one of the getRelative[…] family, please make sure all ` +\n\t\t\t\t\t`parameters match the marker tree exactly.` +\n\t\t\t\t\t`\\n\\nFor more information, please consult the documentation.\\n\\n`,\n\t\t\t)\n\t\t}\n\t\treturn record.getAccessor()\n\t}\n\n\tprivate getPersistedKeyByPlaceholder(placeholderName: string): string | null {\n\t\tif (this.dataFromServer === undefined) {\n\t\t\treturn null\n\t\t}\n\t\tconst key = this.dataFromServer.get(placeholderName)\n\n\t\tif (key instanceof ServerGeneratedUuid) {\n\t\t\treturn key.value\n\t\t}\n\t\tif (key === null) {\n\t\t\t// TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that\n\t\t\t// \thappens to be also null.\n\t\t\treturn null\n\t\t}\n\n\t\t// From now on, we're past the happy path, way into error land.\n\t\tif (key === undefined) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +\n\t\t\t\t\t`a typo, this typically happens when a has-one relation hasn't been registered during static render.`,\n\t\t\t)\n\t\t}\n\t\tif (key instanceof Set) {\n\t\t\tthrow new BindingError(\n\t\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +\n\t\t\t\t\t`not a has-one. This method is meant exclusively for has-one relations.`,\n\t\t\t)\n\t\t}\n\t\tthrow new BindingError(\n\t\t\t`EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +\n\t\t\t\t`has-one relation. This method is meant exclusively for has-one relations.`,\n\t\t)\n\t}\n}\n\nnamespace EntityAccessor {\n\texport interface FieldDatum {\n\t\tgetAccessor(): NestedAccessor\n\t}\n\texport type NestedAccessor = EntityAccessor | EntityListAccessor | FieldAccessor\n\n\texport type FieldValuePairs =\n\t\t| {\n\t\t\t\t[field: string]: FieldValue\n\t\t }\n\t\t| Iterable<[SugaredRelativeSingleField | string, FieldValue]>\n\n\texport type FieldData = Map<FieldName, FieldDatum>\n\n\texport type GetEntityAccessor = () => EntityAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityAccessor, options: BatchUpdatesOptions) => void\n\texport type UpdateListener = (accessor: EntityAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport interface RuntimeEntityEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tconnectionUpdate: UpdateListener\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityEventListenerMap extends RuntimeEntityEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityEventType = keyof EntityEventListenerMap\n}\n\nexport { EntityAccessor }\n"],"names":[],"mappings":";;;;;;AA6BA,qBAA0C;AAAA,EAClC,YACW,UACA,YACA,WACD,KACA,MACC,WACA,gBACD,uBACA,QACA,aACA,aACf;AAXgB;AACA;AACA;AACD;AACA;AACC;AACA;AACD;AACA;AACA;AACA;AAAA;AAAA,MAGN,aAAiC;AAC3C,WAAO,KAAK,UAAU,iBAAiB,KAAK,UAAU,QAAQ;AAAA;AAAA,MAMpD,KAAe;AACzB,WAAO,KAAK,UAAU;AAAA;AAAA,MAGZ,iBAA0B;AACpC,WAAO,KAAK,UAAU;AAAA;AAAA,EAKhB,SAAS,OAAiD;AAChE,WAAO,KAAK,WAAW,SAA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AAA,EAQjD,uBAA8D,OAAkD;AACtH,WAAO,KAAK,wBAAwB,OAAO,yBAC1C,qBAAqB,oBAAoB,MAAM;AAAA;AAAA,EAI1C,wBAAwB,sBAA4D;AAC1F,QAAI,aAA6B;AAEjC,eAAW,kBAAkB,qBAAqB,oBAAoB;AACrE,mBAAa,WAAW,yBACvB,qBAAqB,6BAA6B;AAAA;AAGpD,WAAO;AAAA;AAAA,EAGD,sBAAsB,YAAoD;AAChF,WAAO,KAAK,wBAAwB,YAAY,yBAC/C,qBAAqB,8BAA8B,WAAW;AAAA;AAAA,EAIxD,yBAAyB,iBAA2D;AAC3F,UAAM,SAAS,KAAK,UAAU,IAAI;AAClC,QAAI,WAAW,QAAW;AACzB,YAAM,IAAI,aACT,8CAA8C,sBAAsB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3E,WAAO,OAAO;AAAA;AAAA,EAGP,6BAA6B,iBAAwC;AAC5E,QAAI,KAAK,mBAAmB,QAAW;AACtC,aAAO;AAAA;AAER,UAAM,MAAM,KAAK,eAAe,IAAI;AAEpC,QAAI,eAAe,qBAAqB;AACvC,aAAO,IAAI;AAAA;AAEZ,QAAI,QAAQ,MAAM;AAGjB,aAAO;AAAA;AAIR,QAAI,QAAQ,QAAW;AACtB,YAAM,IAAI,aACT,gEAAgE;AAAA;AAIlE,QAAI,eAAe,KAAK;AACvB,YAAM,IAAI,aACT,4DAA4D;AAAA;AAI9D,UAAM,IAAI,aACT,4DAA4D;AAAA;AAAA;;;;"}
@@ -1,3 +1,5 @@
1
+ import { ErrorAccessor } from './ErrorAccessor.js';
2
+
1
3
  class EntityListAccessor {
2
4
  constructor(stateKey, operations, _children, _idsPersistedOnServer, hasUnpersistedChanges, errors, environment, getAccessor) {
3
5
  this.stateKey = stateKey;
@@ -61,7 +63,7 @@ class EntityListAccessor {
61
63
  });
62
64
  }
63
65
  addError(error) {
64
- return this.operations.addError(this.stateKey, error);
66
+ return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error));
65
67
  }
66
68
  addEventListener(event, listener) {
67
69
  return this.operations.addEventListener(this.stateKey, event, listener);
@@ -1 +1 @@
1
- {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport type { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic *keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key\n\t\t}\n\t}\n\n\tpublic *ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<string> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic addError(error: ErrorAccessor.SugaredValidationError): () => void {\n\t\treturn this.operations.addError(this.stateKey, error)\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":"AAaA,yBAA8C;AAAA,EACtC,YACW,UACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;AARgB;AACA;AACA;AACA;AACD;AACA;AACA;AACA;AAAA;AAAA,GAQT,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA;AAAA;AAAA,GAIT,MAAkC;AACzC,WAAO,KAAK,UAAU;AAAA;AAAA,MAOZ,uBAAoC;AAC9C,WAAO,IAAI,IAAI,KAAK;AAAA;AAAA,IAGZ,OAAO,YAA8C;AAC7D,eAAW,EAAE,iBAAiB,KAAK,UAAU,UAAU;AACtD,YAAM;AAAA;AAAA;AAAA,EAID,YAAY,IAAuB;AACzC,WAAO,KAAK,UAAU,IAAI;AAAA;AAAA,EAGpB,UAAmB;AACzB,WAAO,KAAK,WAAW;AAAA;AAAA,MAGb,SAAiB;AAC3B,WAAO,KAAK,UAAU;AAAA;AAAA,EAGhB,kBAAkB,eAAmD;AAC3E,QAAI,OAAO,kBAAkB,UAAU;AACtC,aAAO,KAAK,qBAAqB,IAAI;AAAA;AAEtC,UAAM,aAAa,cAAc;AACjC,QAAI,eAAe,QAAW;AAC7B,aAAO;AAAA;AAER,WAAO,KAAK,qBAAqB,IAAI;AAAA;AAAA,EAG/B,YAAkB;AACxB,SAAK,aAAa,iBAAe;AAChC,YAAM,OAAO;AACb,iBAAW,UAAU,MAAM;AAC1B,eAAO;AAAA;AAAA;AAAA;AAAA,EAKH,gBAAsB;AAC5B,SAAK,aAAa,iBAAe;AAChC,YAAM,OAAO;AACb,iBAAW,UAAU,MAAM;AAC1B,aAAK,iBAAiB;AAAA;AAAA;AAAA;AAAA,EAKlB,SAAS,OAAyD;AACxE,WAAO,KAAK,WAAW,SAAS,KAAK,UAAU;AAAA;AAAA,EAGzC,iBACN,OACA,UACC;AACD,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO;AAAA;AAAA,EAGxD,sBACN,OACA,OACA,UACC;AACD,WAAO,KAAK,WAAW,sBAAsB,KAAK,UAAU,OAAO;AAAA;AAAA,EAG7D,aAAa,gBAA8D;AACjF,SAAK,WAAW,aAAa,KAAK,UAAU;AAAA;AAAA,EAGtC,cAAc,iBAAuC;AAC3D,SAAK,WAAW,cAAc,KAAK,UAAU;AAAA;AAAA,EAGvC,gBAAgB,YAA4D;AAClF,WAAO,KAAK,WAAW,gBAAgB,KAAK,UAAU;AAAA;AAAA,EAEhD,iBAAiB,aAA6B,UAAmC,IAAU;AACjG,SAAK,WAAW,iBAAiB,KAAK,UAAU,aAAa;AAAA;AAAA,EAEvD,mBAAmB,IAA8B;AACvD,WAAO,KAAK,WAAW,mBAAmB,KAAK,UAAU;AAAA;AAAA;;;;"}
1
+ {"version":3,"file":"EntityListAccessor.js","sources":["../../../src/accessors/EntityListAccessor.ts"],"sourcesContent":["import type { ListOperations } from '../core/operations'\nimport type { Environment } from '../dao'\nimport type { EntityId, EntityRealmKey } from '../treeParameters'\nimport type { AsyncBatchUpdatesOptions } from './AsyncBatchUpdatesOptions'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { EntityAccessor } from './EntityAccessor'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { PersistErrorOptions } from './PersistErrorOptions'\nimport type { PersistSuccessOptions } from './PersistSuccessOptions'\nimport type { EntityListState } from '../core/state'\nimport { RuntimeId } from '../accessorTree'\n\nclass EntityListAccessor implements Errorable {\n\tpublic constructor(\n\t\tprivate readonly stateKey: EntityListState,\n\t\tprivate readonly operations: ListOperations,\n\t\tprivate readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,\n\t\tprivate readonly _idsPersistedOnServer: ReadonlySet<string>,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly environment: Environment,\n\t\tpublic readonly getAccessor: EntityListAccessor.GetEntityListAccessor,\n\t) {}\n\n\t/**\n\t * Returns all entity keys that are on the list.\n\t * **KEYS ARE NOT IDS!**\n\t * @see EntityAccessor.key\n\t */\n\tpublic *keys(): IterableIterator<EntityRealmKey> {\n\t\tfor (const accessor of this) {\n\t\t\tyield accessor.key\n\t\t}\n\t}\n\n\tpublic *ids(): IterableIterator<EntityId> {\n\t\treturn this._children.keys()\n\t}\n\n\t/**\n\t * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on\n\t * the list since the last server query.\n\t */\n\tpublic get idsPersistedOnServer(): Set<string> {\n\t\treturn new Set(this._idsPersistedOnServer)\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<EntityAccessor> {\n\t\tfor (const { getAccessor } of this._children.values()) {\n\t\t\tyield getAccessor()\n\t\t}\n\t}\n\n\tpublic hasEntityId(id: EntityId): boolean {\n\t\treturn this._children.has(id)\n\t}\n\n\tpublic isEmpty(): boolean {\n\t\treturn this.length === 0\n\t}\n\n\tpublic get length(): number {\n\t\treturn this._children.size\n\t}\n\n\tpublic hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {\n\t\tif (typeof entityOrItsId === 'string') {\n\t\t\treturn this.idsPersistedOnServer.has(entityOrItsId)\n\t\t}\n\t\tconst idOnServer = entityOrItsId.idOnServer\n\t\tif (idOnServer === undefined) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.idsPersistedOnServer.has(idOnServer)\n\t}\n\n\tpublic deleteAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tentity.deleteEntity()\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic disconnectAll(): void {\n\t\tthis.batchUpdates(getAccessor => {\n\t\t\tconst list = getAccessor()\n\t\t\tfor (const entity of list) {\n\t\t\t\tlist.disconnectEntity(entity)\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(\n\t\tstate: EntityListState,\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: EntityAccessor.EntityEventListenerMap[Type],\n\t) {\n\t\treturn this.operations.addChildEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {\n\t\tthis.operations.batchUpdates(this.stateKey, performUpdates)\n\t}\n\n\tpublic connectEntity(entityToConnect: EntityAccessor): void {\n\t\tthis.operations.connectEntity(this.stateKey, entityToConnect)\n\t}\n\n\tpublic createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {\n\t\treturn this.operations.createNewEntity(this.stateKey, initialize)\n\t}\n\tpublic disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {\n\t\tthis.operations.disconnectEntity(this.stateKey, childEntity, options)\n\t}\n\tpublic getChildEntityById(id: EntityId): EntityAccessor {\n\t\treturn this.operations.getChildEntityById(this.stateKey, id)\n\t}\n}\n\nnamespace EntityListAccessor {\n\texport type GetEntityListAccessor = () => EntityListAccessor\n\texport type BatchUpdatesHandler = (getAccessor: GetEntityListAccessor, options: BatchUpdatesOptions) => void\n\n\texport type UpdateListener = (accessor: EntityListAccessor) => void\n\n\texport type BeforePersistHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: AsyncBatchUpdatesOptions,\n\t) => void | Promise<void | BeforePersistHandler>\n\n\texport type PersistErrorHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistErrorOptions,\n\t) => void | Promise<void>\n\n\texport type PersistSuccessHandler = (\n\t\tgetAccessor: GetEntityListAccessor,\n\t\toptions: PersistSuccessOptions,\n\t) => void | Promise<void | PersistSuccessHandler>\n\n\texport type ChildEventListenerMap = {\n\t\t[EventType in keyof Pick<EntityAccessor.EntityEventListenerMap, 'beforeUpdate' | 'initialize' | 'update'> &\n\t\t\tstring as `child${Capitalize<EventType>}`]: EntityAccessor.EntityEventListenerMap[EventType]\n\t}\n\n\texport interface RuntimeEntityListEventListenerMap {\n\t\tbeforePersist: BeforePersistHandler\n\t\tbeforeUpdate: BatchUpdatesHandler\n\t\tpersistError: PersistErrorHandler\n\t\tpersistSuccess: PersistSuccessHandler\n\t\tupdate: UpdateListener\n\t}\n\texport interface EntityListEventListenerMap extends RuntimeEntityListEventListenerMap {\n\t\tinitialize: BatchUpdatesHandler\n\t}\n\texport type EntityListEventType = keyof EntityListEventListenerMap\n}\n\nexport { EntityListAccessor }\n"],"names":[],"mappings":";;AAaA,yBAA8C;AAAA,EACtC,YACW,UACA,YACA,WACA,uBACD,uBACA,QACA,aACA,aACf;AARgB;AACA;AACA;AACA;AACD;AACA;AACA;AACA;AAAA;AAAA,GAQT,OAAyC;AAChD,eAAW,YAAY,MAAM;AAC5B,YAAM,SAAS;AAAA;AAAA;AAAA,GAIT,MAAkC;AACzC,WAAO,KAAK,UAAU;AAAA;AAAA,MAOZ,uBAAoC;AAC9C,WAAO,IAAI,IAAI,KAAK;AAAA;AAAA,IAGZ,OAAO,YAA8C;AAC7D,eAAW,EAAE,iBAAiB,KAAK,UAAU,UAAU;AACtD,YAAM;AAAA;AAAA;AAAA,EAID,YAAY,IAAuB;AACzC,WAAO,KAAK,UAAU,IAAI;AAAA;AAAA,EAGpB,UAAmB;AACz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or {
2
2
  constructor(errors) {
3
3
  this.errors = errors;
4
- const validation = [];
5
- const execution = [];
6
- for (const [key, boxed] of errors) {
7
- if (boxed.type === "validation") {
8
- validation.push({
9
- key,
10
- message: typeof boxed.error === "string" ? boxed.error : boxed.error.message,
11
- code: typeof boxed.error === "string" ? void 0 : boxed.error.code
12
- });
13
- } else {
14
- execution.push({
15
- key,
16
- type: typeof boxed.error === "string" ? boxed.error : boxed.error.type,
17
- developerMessage: typeof boxed.error === "string" ? null : boxed.error.developerMessage
18
- });
19
- }
20
- }
21
- this.validation = validation.length ? validation : void 0;
22
- this.execution = execution.length ? execution : void 0;
23
4
  }
24
- validation;
25
- execution;
26
5
  }
6
+ (function(ErrorAccessor2) {
7
+ ErrorAccessor2.normalizeError = (error) => typeof error === "string" ? {
8
+ type: "validation",
9
+ message: error,
10
+ code: void 0
11
+ } : error;
12
+ })(ErrorAccessor || (ErrorAccessor = {}));
27
13
 
28
14
  export { ErrorAccessor };
29
15
  //# sourceMappingURL=ErrorAccessor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorAccessor.js","sources":["../../../src/accessors/ErrorAccessor.ts"],"sourcesContent":["import type { Result } from '@contember/client'\n\nclass ErrorAccessor {\n\tpublic readonly validation: ErrorAccessor.ValidationErrors | undefined\n\tpublic readonly execution: ErrorAccessor.ExecutionErrors | undefined\n\n\tpublic constructor(private readonly errors: ErrorAccessor.ErrorsById) {\n\t\tconst validation: ErrorAccessor.ValidationError[] = []\n\t\tconst execution: ErrorAccessor.ExecutionError[] = []\n\n\t\tfor (const [key, boxed] of errors) {\n\t\t\tif (boxed.type === 'validation') {\n\t\t\t\tvalidation.push({\n\t\t\t\t\tkey,\n\t\t\t\t\tmessage: typeof boxed.error === 'string' ? boxed.error : boxed.error.message,\n\t\t\t\t\tcode: typeof boxed.error === 'string' ? undefined : boxed.error.code,\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\texecution.push({\n\t\t\t\t\tkey,\n\t\t\t\t\ttype: typeof boxed.error === 'string' ? boxed.error : boxed.error.type,\n\t\t\t\t\tdeveloperMessage: typeof boxed.error === 'string' ? null : boxed.error.developerMessage,\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tthis.validation = validation.length ? (validation as ErrorAccessor.ValidationErrors) : undefined\n\t\tthis.execution = execution.length ? (execution as ErrorAccessor.ExecutionErrors) : undefined\n\t}\n}\nnamespace ErrorAccessor {\n\texport type ErrorId = number\n\texport type BoxedError = BoxedExecutionError | BoxedValidationError\n\texport type ErrorsById = Map<ErrorId, BoxedError>\n\n\texport type ExecutionErrors = [ExecutionError, ...ExecutionError[]]\n\texport interface BoxedExecutionError {\n\t\ttype: 'execution'\n\t\terror: SugaredExecutionError\n\t}\n\texport type SugaredExecutionError = Result.ExecutionErrorType | Omit<ExecutionError, 'key'>\n\texport interface ExecutionError {\n\t\tkey: ErrorId\n\t\ttype: Result.ExecutionErrorType\n\t\tdeveloperMessage: string | null\n\t}\n\n\texport type ValidationErrors = [ValidationError, ...ValidationError[]]\n\texport interface BoxedValidationError {\n\t\ttype: 'validation'\n\t\terror: SugaredValidationError\n\t}\n\texport type SugaredValidationError =\n\t\t| string\n\t\t| {\n\t\t\t\tmessage: string\n\t\t\t\tcode?: string\n\t\t }\n\texport interface ValidationError {\n\t\tkey: ErrorId\n\t\tmessage: string\n\t\tcode: WellKnownErrorCode | string | undefined\n\t}\n\n\texport type WellKnownErrorCode = 'fieldRequired'\n}\nexport { ErrorAccessor }\n"],"names":[],"mappings":"AAEA,oBAAoB;AAAA,EAIZ,YAA6B,QAAkC;AAAlC;AACnC,UAAM,aAA8C;AACpD,UAAM,YAA4C;AAElD,eAAW,CAAC,KAAK,UAAU,QAAQ;AAClC,UAAI,MAAM,SAAS,cAAc;AAChC,mBAAW,KAAK;AAAA,UACf;AAAA,UACA,SAAS,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ,MAAM,MAAM;AAAA,UACrE,MAAM,OAAO,MAAM,UAAU,WAAW,SAAY,MAAM,MAAM;AAAA;AAAA,aAE3D;AACN,kBAAU,KAAK;AAAA,UACd;AAAA,UACA,MAAM,OAAO,MAAM,UAAU,WAAW,MAAM,QAAQ,MAAM,MAAM;AAAA,UAClE,kBAAkB,OAAO,MAAM,UAAU,WAAW,OAAO,MAAM,MAAM;AAAA;AAAA;AAAA;AAI1E,SAAK,aAAa,WAAW,SAAU,aAAgD;AACvF,SAAK,YAAY,UAAU,SAAU,YAA8C;AAAA;AAAA,EAvBpE;AAAA,EACA;AAAA;;;;"}
1
+ {"version":3,"file":"ErrorAccessor.js","sources":["../../../src/accessors/ErrorAccessor.ts"],"sourcesContent":["import type { Result } from '@contember/client'\n\nclass ErrorAccessor {\n\tpublic constructor(\n\t\tpublic readonly errors: ErrorAccessor.Error[],\n\t) {\n\t}\n}\n\nnamespace ErrorAccessor {\n\texport type ErrorId = number\n\texport type Error = ExecutionError | ValidationError\n\texport type ErrorsById = Map<ErrorId, Error>\n\n\texport type ExecutionErrors = ExecutionError[]\n\n\texport interface ExecutionError {\n\t\ttype: 'execution'\n\t\tcode: Result.ExecutionErrorType\n\t\tdeveloperMessage: string | null\n\t}\n\n\texport type ValidationErrors = ValidationError[]\n\n\texport interface ValidationError {\n\t\ttype: 'validation'\n\t\tcode: WellKnownErrorCode | string | undefined\n\t\tmessage: string\n\t}\n\n\texport type WellKnownErrorCode = 'fieldRequired'\n\n\texport const normalizeError = (error: Error | string): Error => typeof error === 'string' ? {\n\t\ttype: 'validation',\n\t\tmessage: error,\n\t\tcode: undefined,\n\t} : error\n}\nexport { ErrorAccessor }\n"],"names":[],"mappings":"AAEA,oBAAoB;AAAA,EACZ,YACU,QACf;AADe;AAAA;AAAA;AAKlB,UAAU,gBAAV;AAuBQ,EAAM,gCAAiB,CAAC,UAAiC,OAAO,UAAU,WAAW;AAAA,IAC3F,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM;AAAA,MACH;AAAA,GA3BK;;;;"}
@@ -1,3 +1,4 @@
1
+ import { ErrorAccessor } from './ErrorAccessor.js';
1
2
  import { TemporalFieldHelper } from '../fieldHelpers/helpers/TemporalFieldHelper.js';
2
3
  import { UuidFieldHelper } from '../fieldHelpers/helpers/UuidFieldHelper.js';
3
4
 
@@ -15,7 +16,7 @@ class FieldAccessor {
15
16
  this.getAccessor = getAccessor;
16
17
  }
17
18
  addError(error) {
18
- return this.operations.addError(this.stateKey, error);
19
+ return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error));
19
20
  }
20
21
  clearErrors() {
21
22
  this.operations.clearErrors(this.stateKey);
@@ -1 +1 @@
1
- {"version":3,"file":"FieldAccessor.js","sources":["../../../src/accessors/FieldAccessor.ts"],"sourcesContent":["import type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport type { FieldName, FieldValue } from '../treeParameters'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { Errorable } from './Errorable'\nimport type { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldState } from '../core/state'\n\nclass FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable {\n\tconstructor(\n\t\tprivate readonly stateKey: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t) {}\n\n\tpublic addError(error: ErrorAccessor.SugaredValidationError): () => void {\n\t\treturn this.operations.addError(this.stateKey, error)\n\t}\n\n\tpublic clearErrors(): void {\n\t\tthis.operations.clearErrors(this.stateKey)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.stateKey, newValue, options)\n\t}\n\n\tpublic hasValue(candidate: this['value']): boolean {\n\t\treturn this.value === candidate\n\t}\n\n\tpublic isTouchedBy(agent: string) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy(FieldAccessor.userAgent)\n\t}\n\n\tpublic get resolvedValue() {\n\t\tif (this.defaultValue === undefined) {\n\t\t\treturn this.value\n\t\t}\n\t\treturn this.value === null ? this.defaultValue : this.value\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n}\nnamespace FieldAccessor {\n\texport const userAgent = 'user'\n\n\texport interface UpdateOptions {\n\t\tagent?: string\n\t}\n\n\texport type GetFieldAccessor<Value extends FieldValue = FieldValue> = () => FieldAccessor<Value>\n\n\texport type BeforeUpdateListener<Value extends FieldValue = FieldValue> = (\n\t\tupdatedAccessor: FieldAccessor<Value>,\n\t) => void\n\texport type InitializeListener<Value extends FieldValue = FieldValue> = (\n\t\tgetAccessor: GetFieldAccessor<Value>,\n\t\toptions: BatchUpdatesOptions,\n\t) => void\n\texport type UpdateListener<Value extends FieldValue = FieldValue> = (accessor: FieldAccessor<Value>) => void\n\n\texport interface RuntimeFieldEventListenerMap<Value extends FieldValue = FieldValue> {\n\t\tbeforeUpdate: BeforeUpdateListener<Value>\n\t\tupdate: UpdateListener<Value>\n\t}\n\texport interface FieldEventListenerMap<Value extends FieldValue = FieldValue>\n\t\textends RuntimeFieldEventListenerMap<Value> {\n\t\tinitialize: InitializeListener<Value>\n\t}\n\texport type FieldEventType = keyof FieldEventListenerMap\n}\n\nexport { FieldAccessor }\n"],"names":[],"mappings":";;;AAQA,oBAAgF;AAAA,EAC/E,YACkB,UACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACf;AAVgB;AACA;AACD;AACA;AACA;AACA;AACA;AACA;AACC;AACD;AAAA;AAAA,EAGV,SAAS,OAAyD;AACxE,WAAO,KAAK,WAAW,SAAS,KAAK,UAAU;AAAA;AAAA,EAGzC,cAAoB;AAC1B,SAAK,WAAW,YAAY,KAAK;AAAA;AAAA,EAG3B,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO;AAAA;AAAA,EAGxD,YAAY,UAAwB,SAA6C;AACvF,SAAK,WAAW,YAAY,KAAK,UAAU,UAAU;AAAA;AAAA,EAG/C,SAAS,WAAmC;AAClD,WAAO,KAAK,UAAU;AAAA;AAAA,EAGhB,YAAY,OAAe;AACjC,WAAO,KAAK,UAAU,IAAI,UAAU;AAAA;AAAA,MAG1B,YAAY;AACtB,WAAO,KAAK,YAAY,cAAc;AAAA;AAAA,MAG5B,gBAAgB;AAC1B,QAAI,KAAK,iBAAiB,QAAW;AACpC,aAAO,KAAK;AAAA;AAEb,WAAO,KAAK,UAAU,OAAO,KAAK,eAAe,KAAK;AAAA;AAAA,MAK5C,aAAkC;AAC5C,WAAO,IAAI,oBAAoB,KAAK;AAAA;AAAA,MAG1B,SAA0B;AACpC,WAAO,IAAI,gBAAgB,KAAK;AAAA;AAAA;AAGlC,UAAU,gBAAV;AACQ,EAAM,2BAAY;AAAA,GADhB;;;;"}
1
+ {"version":3,"file":"FieldAccessor.js","sources":["../../../src/accessors/FieldAccessor.ts"],"sourcesContent":["import type { FieldOperations } from '../core/operations'\nimport { TemporalFieldHelper, UuidFieldHelper } from '../fieldHelpers'\nimport type { FieldName, FieldValue } from '../treeParameters'\nimport type { BatchUpdatesOptions } from './BatchUpdatesOptions'\nimport type { Errorable } from './Errorable'\nimport { ErrorAccessor } from './ErrorAccessor'\nimport type { FieldState } from '../core/state'\n\nclass FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable {\n\tconstructor(\n\t\tprivate readonly stateKey: FieldState<Value>,\n\t\tprivate readonly operations: FieldOperations,\n\t\tpublic readonly fieldName: FieldName,\n\t\tpublic readonly value: Value | null,\n\t\tpublic readonly valueOnServer: Value | null,\n\t\tpublic readonly defaultValue: Value | undefined,\n\t\tpublic readonly errors: ErrorAccessor | undefined,\n\t\tpublic readonly hasUnpersistedChanges: boolean,\n\t\tprivate readonly touchLog: ReadonlySet<string> | undefined,\n\t\tpublic readonly getAccessor: FieldAccessor.GetFieldAccessor<Value>,\n\t) {}\n\n\tpublic addError(error: ErrorAccessor.Error | string): () => void {\n\t\treturn this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))\n\t}\n\n\tpublic clearErrors(): void {\n\t\tthis.operations.clearErrors(this.stateKey)\n\t}\n\n\tpublic addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(\n\t\tevent: { type: Type; key?: string },\n\t\tlistener: FieldAccessor.FieldEventListenerMap<Value>[Type],\n\t): () => void {\n\t\treturn this.operations.addEventListener(this.stateKey, event, listener)\n\t}\n\n\tpublic updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {\n\t\tthis.operations.updateValue(this.stateKey, newValue, options)\n\t}\n\n\tpublic hasValue(candidate: this['value']): boolean {\n\t\treturn this.value === candidate\n\t}\n\n\tpublic isTouchedBy(agent: string) {\n\t\treturn this.touchLog?.has(agent) ?? false\n\t}\n\n\tpublic get isTouched() {\n\t\treturn this.isTouchedBy(FieldAccessor.userAgent)\n\t}\n\n\tpublic get resolvedValue() {\n\t\tif (this.defaultValue === undefined) {\n\t\t\treturn this.value\n\t\t}\n\t\treturn this.value === null ? this.defaultValue : this.value\n\t}\n\n\t// helpers\n\n\tpublic get asTemporal(): TemporalFieldHelper {\n\t\treturn new TemporalFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n\n\tpublic get asUuid(): UuidFieldHelper {\n\t\treturn new UuidFieldHelper(this.getAccessor as FieldAccessor.GetFieldAccessor<any>)\n\t}\n}\nnamespace FieldAccessor {\n\texport const userAgent = 'user'\n\n\texport interface UpdateOptions {\n\t\tagent?: string\n\t}\n\n\texport type GetFieldAccessor<Value extends FieldValue = FieldValue> = () => FieldAccessor<Value>\n\n\texport type BeforeUpdateListener<Value extends FieldValue = FieldValue> = (\n\t\tupdatedAccessor: FieldAccessor<Value>,\n\t) => void\n\texport type InitializeListener<Value extends FieldValue = FieldValue> = (\n\t\tgetAccessor: GetFieldAccessor<Value>,\n\t\toptions: BatchUpdatesOptions,\n\t) => void\n\texport type UpdateListener<Value extends FieldValue = FieldValue> = (accessor: FieldAccessor<Value>) => void\n\n\texport interface RuntimeFieldEventListenerMap<Value extends FieldValue = FieldValue> {\n\t\tbeforeUpdate: BeforeUpdateListener<Value>\n\t\tupdate: UpdateListener<Value>\n\t}\n\texport interface FieldEventListenerMap<Value extends FieldValue = FieldValue>\n\t\textends RuntimeFieldEventListenerMap<Value> {\n\t\tinitialize: InitializeListener<Value>\n\t}\n\texport type FieldEventType = keyof FieldEventListenerMap\n}\n\nexport { FieldAccessor }\n"],"names":[],"mappings":";;;;AAQA,oBAAgF;AAAA,EAC/E,YACkB,UACA,YACD,WACA,OACA,eACA,cACA,QACA,uBACC,UACD,aACf;AAVgB;AACA;AACD;AACA;AACA;AACA;AACA;AACA;AACC;AACD;AAAA;AAAA,EAGV,SAAS,OAAiD;AAChE,WAAO,KAAK,WAAW,SAAS,KAAK,UAAU,cAAc,eAAe;AAAA;AAAA,EAGtE,cAAoB;AAC1B,SAAK,WAAW,YAAY,KAAK;AAAA;AAAA,EAG3B,iBACN,OACA,UACa;AACb,WAAO,KAAK,WAAW,iBAAiB,KAAK,UAAU,OAAO;AAAA;AAAA,EAGxD,YAAY,UAAwB,SAA6C;AACvF,SAAK,WAAW,YAAY,KAAK,UAAU,UAAU;AAAA;AAAA,EAG/C,SAAS,WAAmC;AAClD,WAAO,KAAK,UAAU;AAAA;AAAA,EAGhB,YAAY,OAAe;AACjC,WAAO,KAAK,UAAU,IAAI,UAAU;AAAA;AAAA,MAG1B,YAAY;AACtB,WAAO,KAAK,YAAY,cAAc;AAAA;AAAA,MAG5B,gBAAgB;AAC1B,QAAI,KAAK,iBAAiB,QAAW;AACpC,aAAO,KAAK;AAAA;AAEb,WAAO,KAAK,UAAU,OAAO,KAAK,eAAe,KAAK;AAAA;AAAA,MAK5C,aAAkC;AAC5C,WAAO,IAAI,oBAAoB,KAAK;AAAA;AAAA,MAG1B,SAA0B;AACpC,WAAO,IAAI,gBAAgB,KAAK;AAAA;AAAA;AAGlC,UAAU,gBAAV;AACQ,EAAM,2BAAY;AAAA,GADhB;;;;"}
@@ -16,6 +16,9 @@ class AccessorErrorManager {
16
16
  hasErrors() {
17
17
  return !!this.errorsByState.size;
18
18
  }
19
+ getErrors() {
20
+ return Array.from(this.errorsByState.values(), (it) => Array.from(it.values())).flat();
21
+ }
19
22
  clearErrors() {
20
23
  this.eventManager.syncOperation(() => {
21
24
  for (const [stateNode] of this.errorsByState) {
@@ -52,7 +55,7 @@ class AccessorErrorManager {
52
55
  this.errorsByState.set(state, errorsById = new Map());
53
56
  }
54
57
  errorsById.set(errorId, error);
55
- state.errors = new ErrorAccessor(errorsById);
58
+ state.errors = new ErrorAccessor(Array.from(errorsById.values()));
56
59
  this.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE);
57
60
  return () => this.eventManager.syncOperation(() => {
58
61
  const errorsById2 = this.errorsByState.get(state);
@@ -61,7 +64,7 @@ class AccessorErrorManager {
61
64
  }
62
65
  errorsById2.delete(errorId);
63
66
  if (errorsById2.size) {
64
- state.errors = new ErrorAccessor(errorsById2);
67
+ state.errors = new ErrorAccessor(Array.from(errorsById2.values()));
65
68
  } else {
66
69
  state.errors = void 0;
67
70
  this.errorsByState.delete(state);
@@ -73,12 +76,12 @@ class AccessorErrorManager {
73
76
  addSeveralErrors(state, errors) {
74
77
  if (errors.validation) {
75
78
  for (const error of errors.validation) {
76
- this.addError(state, { type: "validation", error });
79
+ this.addError(state, error);
77
80
  }
78
81
  }
79
82
  if (errors.execution) {
80
83
  for (const error of errors.execution) {
81
- this.addError(state, { type: "execution", error });
84
+ this.addError(state, error);
82
85
  }
83
86
  }
84
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.BoxedError): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(errorsById)\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(errorsById)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, { type: 'validation', error })\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, { type: 'execution', error })\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;2BAOkC;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE;AAA6C;AAAA;AAAA,EARzE,gBAA0D,IAAI;AAAA,EAE9D,gBAAiB,OAAM;AAC9B,QAAI,UAAU;AAEd,WAAO,MAAM;AAAA;AAAA,EAKP,YAAY;AAClB,WAAO,CAAC,CAAC,KAAK,cAAc;AAAA;AAAA,EAGtB,cAAc;AACpB,SAAK,aAAa,cAAc,MAAM;AACrC,iBAAW,CAAC,cAAc,KAAK,eAAe;AAC7C,kBAAU,SAAS;AACnB,aAAK,aAAa,oBAAoB,WAAW,aAAa;AAAA;AAE/D,WAAK,cAAc;AAAA;AAAA;AAAA,EAId,mBAAmB,OAAwB;AACjD,WAAO,KAAK,aAAa,cAAc,MAAM;AAC5C,UAAI,CAAC,KAAK,cAAc,IAAI,QAAQ;AACnC;AAAA;AAED,WAAK,cAAc,OAAO;AAC1B,YAAM,SAAS;AACf,WAAK,aAAa,oBAAoB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YAAgC;AAAA;AAAA;AAAA;AAAA,EAKrD,cAAc,MAA4B;AAEjD,eAAW,sBAAsB,MAAM;AACtC,YAAM,YAAY,KAAK;AACvB,YAAM,kBAA2D,UAAU;AAC3E,YAAM,YAAY,WAAW,YAAY,SACtC,gBAAgB,OAAO,UAAU,WAAW,UAC5C;AACH,YAAM,mBAAmB,UAAU,IAAI,CAAC,UAA4C;AACnF,eAAO;AAAA,UACN,MAAM,MAAM,KACV,IAAI,cAAY;AAChB,gBAAI,SAAS,eAAe,sBAAsB;AACjD,qBAAO,SAAS;AAAA;AAEjB,gBAAI,SAAS,OAAO;AACnB,qBAAO,IAAI,SAAS,SAAS,SAAS;AAAA;AAEvC,mBAAO,SAAS;AAAA,aAEhB,KAAK;AAAA,UACP,MAAM,UAAU,QAAQ,MAAM,OAAO;AAAA,UACrC,SAAS,OAAO,MAAM,YAAY,WAAW,MAAM,UAAU,MAAM,SAAS;AAAA;AAAA;AAG9E,UAAI,OAAO,KAAK,kBAAkB,QAAQ;AACzC,gBAAQ,MAAM;AAAA;AAEf,UAAI,UAAU,cAAc;AAC3B,gBAAQ,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;;;;"}
1
+ {"version":3,"file":"AccessorErrorManager.js","sources":["../../../src/core/AccessorErrorManager.ts"],"sourcesContent":["import { ErrorAccessor } from '../accessors'\nimport type { ExecutionError, MutationDataResponse, ValidationError } from '../accessorTree'\nimport { ErrorsPreprocessor } from './ErrorsPreprocessor'\nimport { EventManager } from './EventManager'\nimport { EntityListState, EntityRealmState, getEntityMarker, StateNode } from './state'\nimport type { TreeStore } from './TreeStore'\n\nexport class AccessorErrorManager {\n\tprivate errorsByState: Map<StateNode, ErrorAccessor.ErrorsById> = new Map()\n\n\tprivate getNewErrorId = (() => {\n\t\tlet errorId = 1\n\n\t\treturn () => errorId++\n\t})()\n\n\tpublic constructor(private readonly eventManager: EventManager, private readonly treeStore: TreeStore) {}\n\n\tpublic hasErrors() {\n\t\treturn !!this.errorsByState.size\n\t}\n\n\tpublic getErrors(): ErrorAccessor.Error[] {\n\t\treturn Array.from(this.errorsByState.values(), it => Array.from(it.values())).flat()\n\t}\n\n\tpublic clearErrors() {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tfor (const [stateNode] of this.errorsByState) {\n\t\t\t\tstateNode.errors = undefined\n\t\t\t\tthis.eventManager.registerJustUpdated(stateNode, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t}\n\t\t\tthis.errorsByState.clear()\n\t\t})\n\t}\n\n\tpublic clearErrorsByState(state: StateNode): void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tif (!this.errorsByState.has(state)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.errorsByState.delete(state)\n\t\t\tstate.errors = undefined\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t})\n\t}\n\n\tpublic replaceErrors(data: MutationDataResponse) {\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.clearErrors()\n\n\t\t\tconst preprocessor = new ErrorsPreprocessor(data)\n\t\t\tconst errorTreeRoot = preprocessor.preprocess()\n\n\t\t\tthis.setRootStateErrors(errorTreeRoot)\n\n\t\t\tthis.dumpErrorData(data)\n\t\t})\n\t}\n\n\tpublic addError(state: StateNode, error: ErrorAccessor.Error): () => void {\n\t\treturn this.eventManager.syncOperation(() => {\n\t\t\tconst errorId = this.getNewErrorId()\n\n\t\t\tlet errorsById: ErrorAccessor.ErrorsById | undefined = this.errorsByState.get(state)\n\t\t\tif (errorsById === undefined) {\n\t\t\t\tthis.errorsByState.set(state, (errorsById = new Map()))\n\t\t\t}\n\t\t\terrorsById.set(errorId, error)\n\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\n\t\t\treturn () =>\n\t\t\t\tthis.eventManager.syncOperation(() => {\n\t\t\t\t\tconst errorsById = this.errorsByState.get(state)\n\t\t\t\t\tif (errorsById === undefined) {\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\terrorsById.delete(errorId)\n\t\t\t\t\tif (errorsById.size) {\n\t\t\t\t\t\tstate.errors = new ErrorAccessor(Array.from(errorsById.values()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstate.errors = undefined\n\t\t\t\t\t\tthis.errorsByState.delete(state)\n\t\t\t\t\t}\n\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t})\n\t\t})\n\t}\n\n\tprivate addSeveralErrors(state: StateNode, errors: ErrorsPreprocessor.BaseErrorNode) {\n\t\tif (errors.validation) {\n\t\t\tfor (const error of errors.validation) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t\tif (errors.execution) {\n\t\t\tfor (const error of errors.execution) {\n\t\t\t\tthis.addError(state, error)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setRootStateErrors(errorTreeRoot: ErrorsPreprocessor.ErrorTreeRoot) {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [subTreePlaceholder, rootError] of errorTreeRoot) {\n\t\t\t\tconst rootState = rootStates.get(subTreePlaceholder)\n\n\t\t\t\tif (!rootState) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (rootState.type) {\n\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\tthis.setEntityStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'entityList': {\n\t\t\t\t\t\tthis.setEntityListStateErrors(rootState, rootError)\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityStateErrors(\n\t\tstate: EntityRealmState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, child] of errors.children) {\n\t\t\tif (child.nodeType === 'leaf') {\n\t\t\t\tconst fieldState = state.children.get(childKey)\n\n\t\t\t\tif (fieldState?.type === 'field') {\n\t\t\t\t\tthis.addSeveralErrors(fieldState, child)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Deliberately letting flow get here as well. Leaf errors *CAN* refer to relations as well.\n\n\t\t\tconst fields = getEntityMarker(state).fields\n\t\t\tconst placeholders = fields.placeholders.get(childKey)\n\t\t\tif (placeholders === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tconst normalizedPlaceholders = typeof placeholders === 'string' ? new Set([placeholders]) : placeholders\n\n\t\t\tfor (const normalizedPlaceholder of normalizedPlaceholders) {\n\t\t\t\tconst fieldState = state.children.get(normalizedPlaceholder)\n\t\t\t\tif (fieldState === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tswitch (fieldState.type) {\n\t\t\t\t\tcase 'entityRealm':\n\t\t\t\t\t\tthis.setEntityStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\tthis.setEntityListStateErrors(fieldState, child)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate setEntityListStateErrors(\n\t\tstate: EntityListState,\n\t\terrors: ErrorsPreprocessor.ErrorINode | ErrorsPreprocessor.LeafErrorNode,\n\t) {\n\t\tthis.addSeveralErrors(state, errors)\n\n\t\tif (errors.nodeType !== 'iNode') {\n\t\t\treturn\n\t\t}\n\n\t\tfor (const [childKey, childError] of errors.children) {\n\t\t\tlet childState = state.children.get(childKey)\n\n\t\t\tif (childState === undefined) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif (childState.type === 'entityRealmStub') {\n\t\t\t\tchildState.getAccessor() // Force init\n\t\t\t\tchildState = state.children.get(childKey)!\n\t\t\t}\n\n\t\t\tif (childError.nodeType === 'iNode') {\n\t\t\t\tthis.setEntityStateErrors(childState as EntityRealmState, childError)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate dumpErrorData(data: MutationDataResponse) {\n\t\t// TODO this is just temporary\n\t\tfor (const subTreePlaceholder in data) {\n\t\t\tconst treeDatum = data[subTreePlaceholder]\n\t\t\tconst executionErrors: Array<ExecutionError | ValidationError> = treeDatum.errors\n\t\t\tconst allErrors = treeDatum?.validation?.errors\n\t\t\t\t? executionErrors.concat(treeDatum.validation.errors)\n\t\t\t\t: executionErrors\n\t\t\tconst normalizedErrors = allErrors.map((error: ExecutionError | ValidationError) => {\n\t\t\t\treturn {\n\t\t\t\t\tpath: error.path\n\t\t\t\t\t\t.map(pathPart => {\n\t\t\t\t\t\t\tif (pathPart.__typename === '_FieldPathFragment') {\n\t\t\t\t\t\t\t\treturn pathPart.field\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (pathPart.alias) {\n\t\t\t\t\t\t\t\treturn `#${pathPart.index}(${pathPart.alias})`\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pathPart.index\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('.'),\n\t\t\t\t\ttype: 'type' in error ? error.type : undefined,\n\t\t\t\t\tmessage: typeof error.message === 'string' ? error.message : error.message?.text,\n\t\t\t\t}\n\t\t\t})\n\t\t\tif (Object.keys(normalizedErrors).length) {\n\t\t\t\tconsole.table(normalizedErrors)\n\t\t\t}\n\t\t\tif (treeDatum.errorMessage) {\n\t\t\t\tconsole.error(treeDatum.errorMessage)\n\t\t\t}\n\t\t}\n\t}\n}\n"],"names":[],"mappings":";;;;;2BAOkC;AAAA,EAS1B,YAA6B,cAA6C,WAAsB;AAAnE;AAA6C;AAAA;AAAA,EARzE,gBAA0D,IAAI;AAAA,EAE9D,gBAAi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Ef,UAAI,UAAU,cAAc;AAC3B,gBAAQ,MAAM,UAAU;AAAA;AAAA;AAAA;AAAA;;;;"}
@@ -78,6 +78,7 @@ class DataBinding {
78
78
  continue;
79
79
  }
80
80
  throw {
81
+ errors: this.accessorErrorManager.getErrors(),
81
82
  type: "invalidInput"
82
83
  };
83
84
  }
@@ -145,6 +146,7 @@ class DataBinding {
145
146
  continue;
146
147
  }
147
148
  throw {
149
+ errors: this.accessorErrorManager.getErrors(),
148
150
  type: "invalidInput"
149
151
  };
150
152
  }