@contember/binding 1.1.0-alpha.14 → 1.1.0-alpha.16

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 (48) hide show
  1. package/dist/development/accessorTree/useDataBinding.js +9 -6
  2. package/dist/development/accessorTree/useDataBinding.js.map +1 -1
  3. package/dist/development/core/Config.js +1 -2
  4. package/dist/development/core/Config.js.map +1 -1
  5. package/dist/development/core/DataBinding.js +114 -129
  6. package/dist/development/core/DataBinding.js.map +1 -1
  7. package/dist/development/core/TreeAugmenter.js +5 -1
  8. package/dist/development/core/TreeAugmenter.js.map +1 -1
  9. package/dist/development/coreComponents/DataBindingProvider.js +2 -5
  10. package/dist/development/coreComponents/DataBindingProvider.js.map +1 -1
  11. package/dist/production/accessorTree/useDataBinding.js +9 -6
  12. package/dist/production/accessorTree/useDataBinding.js.map +1 -1
  13. package/dist/production/core/Config.js +1 -2
  14. package/dist/production/core/Config.js.map +1 -1
  15. package/dist/production/core/DataBinding.js +114 -129
  16. package/dist/production/core/DataBinding.js.map +1 -1
  17. package/dist/production/core/TreeAugmenter.js +5 -1
  18. package/dist/production/core/TreeAugmenter.js.map +1 -1
  19. package/dist/production/coreComponents/DataBindingProvider.js +1 -4
  20. package/dist/production/coreComponents/DataBindingProvider.js.map +1 -1
  21. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts +2 -1
  22. package/dist/types/accessorTree/AccessorTreeStateOptions.d.ts.map +1 -1
  23. package/dist/types/accessorTree/PersistResult.d.ts +1 -4
  24. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  25. package/dist/types/accessorTree/useDataBinding.d.ts +1 -1
  26. package/dist/types/accessorTree/useDataBinding.d.ts.map +1 -1
  27. package/dist/types/accessors/BindingConfig.d.ts +0 -1
  28. package/dist/types/accessors/BindingConfig.d.ts.map +1 -1
  29. package/dist/types/accessors/PersistErrorOptions.d.ts +0 -2
  30. package/dist/types/accessors/PersistErrorOptions.d.ts.map +1 -1
  31. package/dist/types/core/Config.d.ts.map +1 -1
  32. package/dist/types/core/DataBinding.d.ts +9 -1
  33. package/dist/types/core/DataBinding.d.ts.map +1 -1
  34. package/dist/types/core/TreeAugmenter.d.ts +2 -1
  35. package/dist/types/core/TreeAugmenter.d.ts.map +1 -1
  36. package/dist/types/coreComponents/DataBindingProvider.d.ts +2 -5
  37. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +5 -5
  40. package/src/accessorTree/AccessorTreeStateOptions.ts +2 -1
  41. package/src/accessorTree/PersistResult.ts +1 -5
  42. package/src/accessorTree/useDataBinding.ts +9 -6
  43. package/src/accessors/BindingConfig.ts +0 -1
  44. package/src/accessors/PersistErrorOptions.ts +0 -2
  45. package/src/core/Config.ts +0 -1
  46. package/src/core/DataBinding.ts +131 -140
  47. package/src/core/TreeAugmenter.ts +4 -1
  48. package/src/coreComponents/DataBindingProvider.tsx +4 -9
@@ -7,8 +7,9 @@ import { useEnvironment } from "../accessorPropagation/useEnvironment.js";
7
7
  import { DataBinding } from "../core/DataBinding.js";
8
8
  import { SchemaLoader } from "../core/schema/SchemaLoader.js";
9
9
  const useDataBinding = ({
10
- nodeTree,
11
- refreshOnPersist = false
10
+ children,
11
+ refreshOnPersist,
12
+ skipStateUpdateAfterPersist
12
13
  }) => {
13
14
  const contentClient = useCurrentContentGraphQlClient();
14
15
  const systemClient = useCurrentSystemGraphQlClient();
@@ -36,9 +37,11 @@ const useDataBinding = ({
36
37
  if (currentTreeStore.current === void 0 || newStore) {
37
38
  currentTreeStore.current = new TreeStore(environment2.getSchema());
38
39
  }
39
- const binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment2, onUpdate, onError, onPersistSuccess);
40
+ const binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment2, onUpdate, onError, onPersistSuccess, {
41
+ skipStateUpdateAfterPersist: skipStateUpdateAfterPersist ?? false
42
+ });
40
43
  dispatch({ type: "reset", binding, environment: environment2 });
41
- }, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist]);
44
+ }, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist, skipStateUpdateAfterPersist]);
42
45
  const [state, dispatch] = useReducer(accessorTreeStateReducer, {
43
46
  name: "initializing",
44
47
  environment
@@ -54,8 +57,8 @@ const useDataBinding = ({
54
57
  }
55
58
  }, [resetDataBinding, schema, environment]);
56
59
  useEffect(() => {
57
- state.binding?.extendTree(nodeTree);
58
- }, [nodeTree, state.binding]);
60
+ state.binding?.extendTree(children);
61
+ }, [children, state.binding]);
59
62
  return state;
60
63
  };
61
64
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"useDataBinding.js","sources":["../../../src/accessorTree/useDataBinding.ts"],"sourcesContent":["import {\n\tuseCurrentContentGraphQlClient,\n\tuseCurrentSystemGraphQlClient,\n\tuseTenantGraphQlClient,\n} from '@contember/react-client'\nimport { useCallback, useEffect, useReducer, useRef, useState } from 'react'\nimport { useEnvironment } from '../accessorPropagation'\nimport type { TreeRootAccessor } from '../accessors'\nimport { DataBinding } from '../core'\nimport type { AccessorTreeState } from './AccessorTreeState'\nimport type { AccessorTreeStateOptions } from './AccessorTreeStateOptions'\nimport { accessorTreeStateReducer } from './accessorTreeStateReducer'\nimport type { RequestError } from './RequestError'\nimport { Environment } from '../dao'\nimport { Schema, SchemaLoader } from '../core/schema'\nimport { TreeStore } from '../core/TreeStore'\nimport { useIsMounted } from '@contember/react-utils'\n\nexport const useDataBinding = ({\n\tnodeTree,\n\trefreshOnPersist = false,\n}: AccessorTreeStateOptions): AccessorTreeState => {\n\tconst contentClient = useCurrentContentGraphQlClient()\n\tconst systemClient = useCurrentSystemGraphQlClient()\n\tconst tenantClient = useTenantGraphQlClient()\n\tconst environment = useEnvironment()\n\tconst currentTreeStore = useRef<TreeStore>()\n\tconst isMountedRef = useIsMounted()\n\tconst [schema, setSchema] = useState<Schema>()\n\n\tconst resetDataBinding = useCallback((environment: Environment, newStore: boolean) => {\n\t\tconst onUpdate = (data: TreeRootAccessor, binding: DataBinding) => {\n\t\t\tif (isMountedRef.current) {\n\t\t\t\tdispatch({ type: 'setData', data, binding })\n\t\t\t}\n\t\t}\n\n\t\tconst onError = (error: RequestError, binding: DataBinding) => {\n\t\t\tif (isMountedRef.current) {\n\t\t\t\tdispatch({ type: 'failWithError', error, binding })\n\t\t\t}\n\t\t}\n\n\t\tconst onPersistSuccess = () => {\n\t\t\tif (isMountedRef.current && refreshOnPersist) {\n\t\t\t\tresetDataBinding(environment, true)\n\t\t\t}\n\t\t}\n\n\t\tif (currentTreeStore.current === undefined || newStore) {\n\t\t\tcurrentTreeStore.current = new TreeStore(environment.getSchema())\n\t\t}\n\n\t\tconst binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment, onUpdate, onError, onPersistSuccess)\n\t\tdispatch({ type: 'reset', binding, environment })\n\t}, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist])\n\n\tconst [state, dispatch] = useReducer(accessorTreeStateReducer, {\n\t\tname: 'initializing',\n\t\tenvironment,\n\t})\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tsetSchema(await SchemaLoader.loadSchema(contentClient))\n\t\t})()\n\t}, [contentClient])\n\n\tuseEffect(() => {\n\t\tif (schema) {\n\t\t\tresetDataBinding(environment.withSchema(schema), false)\n\t\t}\n\t}, [resetDataBinding, schema, environment])\n\n\tuseEffect(() => {\n\t\tstate.binding?.extendTree(nodeTree)\n\t}, [nodeTree, state.binding])\n\n\treturn state\n}\n"],"names":["environment","binding"],"mappings":";;;;;;;;AAkBO,MAAM,iBAAiB,CAAC;AAAA,EAC9B;AAAA,EACA,mBAAmB;AACpB,MAAmD;AAClD,QAAM,gBAAgB;AACtB,QAAM,eAAe;AACrB,QAAM,eAAe;AACrB,QAAM,cAAc;AACpB,QAAM,mBAAmB;AACzB,QAAM,eAAe;AACrB,QAAM,CAAC,QAAQ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B,SAAA;AACR;"}
1
+ {"version":3,"file":"useDataBinding.js","sources":["../../../src/accessorTree/useDataBinding.ts"],"sourcesContent":["import {\n\tuseCurrentContentGraphQlClient,\n\tuseCurrentSystemGraphQlClient,\n\tuseTenantGraphQlClient,\n} from '@contember/react-client'\nimport { useCallback, useEffect, useReducer, useRef, useState } from 'react'\nimport { useEnvironment } from '../accessorPropagation'\nimport type { TreeRootAccessor } from '../accessors'\nimport { DataBinding } from '../core'\nimport type { AccessorTreeState } from './AccessorTreeState'\nimport type { AccessorTreeStateOptions } from './AccessorTreeStateOptions'\nimport { accessorTreeStateReducer } from './accessorTreeStateReducer'\nimport type { RequestError } from './RequestError'\nimport { Environment } from '../dao'\nimport { Schema, SchemaLoader } from '../core/schema'\nimport { TreeStore } from '../core/TreeStore'\nimport { useIsMounted } from '@contember/react-utils'\n\nexport const useDataBinding = ({\n\tchildren,\n\trefreshOnPersist,\n\tskipStateUpdateAfterPersist,\n}: AccessorTreeStateOptions): AccessorTreeState => {\n\tconst contentClient = useCurrentContentGraphQlClient()\n\tconst systemClient = useCurrentSystemGraphQlClient()\n\tconst tenantClient = useTenantGraphQlClient()\n\tconst environment = useEnvironment()\n\tconst currentTreeStore = useRef<TreeStore>()\n\tconst isMountedRef = useIsMounted()\n\tconst [schema, setSchema] = useState<Schema>()\n\n\tconst resetDataBinding = useCallback((environment: Environment, newStore: boolean) => {\n\t\tconst onUpdate = (data: TreeRootAccessor, binding: DataBinding) => {\n\t\t\tif (isMountedRef.current) {\n\t\t\t\tdispatch({ type: 'setData', data, binding })\n\t\t\t}\n\t\t}\n\n\t\tconst onError = (error: RequestError, binding: DataBinding) => {\n\t\t\tif (isMountedRef.current) {\n\t\t\t\tdispatch({ type: 'failWithError', error, binding })\n\t\t\t}\n\t\t}\n\n\t\tconst onPersistSuccess = () => {\n\t\t\tif (isMountedRef.current && refreshOnPersist) {\n\t\t\t\tresetDataBinding(environment, true)\n\t\t\t}\n\t\t}\n\n\t\tif (currentTreeStore.current === undefined || newStore) {\n\t\t\tcurrentTreeStore.current = new TreeStore(environment.getSchema())\n\t\t}\n\n\t\tconst binding = new DataBinding(contentClient, systemClient, tenantClient, currentTreeStore.current, environment, onUpdate, onError, onPersistSuccess, {\n\t\t\tskipStateUpdateAfterPersist: skipStateUpdateAfterPersist ?? false,\n\t\t})\n\t\tdispatch({ type: 'reset', binding, environment })\n\t}, [contentClient, systemClient, tenantClient, isMountedRef, refreshOnPersist, skipStateUpdateAfterPersist])\n\n\tconst [state, dispatch] = useReducer(accessorTreeStateReducer, {\n\t\tname: 'initializing',\n\t\tenvironment,\n\t})\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tsetSchema(await SchemaLoader.loadSchema(contentClient))\n\t\t})()\n\t}, [contentClient])\n\n\tuseEffect(() => {\n\t\tif (schema) {\n\t\t\tresetDataBinding(environment.withSchema(schema), false)\n\t\t}\n\t}, [resetDataBinding, schema, environment])\n\n\tuseEffect(() => {\n\t\tstate.binding?.extendTree(children)\n\t}, [children, state.binding])\n\n\treturn state\n}\n"],"names":["environment","binding"],"mappings":";;;;;;;;AAkBO,MAAM,iBAAiB,CAAC;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACD,MAAmD;AAClD,QAAM,gBAAgB;AACtB,QAAM,eAAe;AACrB,QAAM,eAAe;AACrB,QAAM,cAAc;AACpB,QAAM,mBAAmB;AACzB,QAAM,eAAe;AACrB,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAiB;AAE7C,QAAM,mBAAmB,YAAY,CAACA,cAA0B,aAAsB;AAC/E,UAAA,WAAW,CAAC,MAAwBC,aAAyB;AAClE,UAAI,aAAa,SAAS;AACzB,iBAAS,EAAE,MAAM,WAAW,MAAM,SAAAA,UAAS;AAAA,MAC5C;AAAA,IAAA;AAGK,UAAA,UAAU,CAAC,OAAqBA,aAAyB;AAC9D,UAAI,aAAa,SAAS;AACzB,iBAAS,EAAE,MAAM,iBAAiB,OAAO,SAAAA,UAAS;AAAA,MACnD;AAAA,IAAA;AAGD,UAAM,mBAAmB,MAAM;AAC1B,UAAA,aAAa,WAAW,kBAAkB;AAC7C,yBAAiBD,cAAa,IAAI;AAAA,MACnC;AAAA,IAAA;AAGG,QAAA,iBAAiB,YAAY,UAAa,UAAU;AACvD,uBAAiB,UAAU,IAAI,UAAUA,aAAY,UAAW,CAAA;AAAA,IACjE;AAEM,UAAA,UAAU,IAAI,YAAY,eAAe,cAAc,cAAc,iBAAiB,SAASA,cAAa,UAAU,SAAS,kBAAkB;AAAA,MACtJ,6BAA6B,+BAA+B;AAAA,IAAA,CAC5D;AACD,aAAS,EAAE,MAAM,SAAS,SAAS,aAAAA,cAAa;AAAA,EAAA,GAC9C,CAAC,eAAe,cAAc,cAAc,cAAc,kBAAkB,2BAA2B,CAAC;AAE3G,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,0BAA0B;AAAA,IAC9D,MAAM;AAAA,IACN;AAAA,EAAA,CACA;AAED,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,gBAAU,MAAM,aAAa,WAAW,aAAa,CAAC;AAAA,IAAA;EACpD,GACD,CAAC,aAAa,CAAC;AAElB,YAAU,MAAM;AACf,QAAI,QAAQ;AACX,uBAAiB,YAAY,WAAW,MAAM,GAAG,KAAK;AAAA,IACvD;AAAA,EACE,GAAA,CAAC,kBAAkB,QAAQ,WAAW,CAAC;AAE1C,YAAU,MAAM;AACT,UAAA,SAAS,WAAW,QAAQ;AAAA,EAChC,GAAA,CAAC,UAAU,MAAM,OAAO,CAAC;AAErB,SAAA;AACR;"}
@@ -24,8 +24,7 @@ let Config = _Config;
24
24
  __publicField(Config, "defaultConfig", {
25
25
  beforePersistSettleLimit: 20,
26
26
  beforeUpdateSettleLimit: 20,
27
- persistSuccessSettleLimit: 20,
28
- maxPersistAttempts: 5
27
+ persistSuccessSettleLimit: 20
29
28
  });
30
29
  export {
31
30
  Config
@@ -1 +1 @@
1
- {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t\tmaxPersistAttempts: 5,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,MAAM,UAAN,MAAa;AAAA,EAUZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAClF,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC/F,SAAK,OAAO,QAAQ;AACb,WAAA;AAAA,EACR;AACD;AAzBO,IAAM,SAAN;AACN,cADY,QACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA,EAC3B,oBAAoB;AAAA;"}
1
+ {"version":3,"file":"Config.js","sources":["../../../src/core/Config.ts"],"sourcesContent":["import type { BindingConfig } from '../accessors'\n\nexport class Config {\n\tprivate static defaultConfig: BindingConfig = {\n\t\tbeforePersistSettleLimit: 20,\n\t\tbeforeUpdateSettleLimit: 20,\n\t\tpersistSuccessSettleLimit: 20,\n\t}\n\n\tprivate readonly config: BindingConfig\n\n\tpublic constructor(config: Partial<BindingConfig> = {}) {\n\t\tthis.config = {\n\t\t\t...Config.defaultConfig,\n\t\t\t...config,\n\t\t}\n\t}\n\n\tpublic getValue<Name extends keyof BindingConfig>(name: Name): BindingConfig[Name] {\n\t\treturn this.config[name]\n\t}\n\n\tpublic setValue<Name extends keyof BindingConfig>(name: Name, value: BindingConfig[Name]): this {\n\t\tthis.config[name] = value\n\t\treturn this\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAEO,MAAM,UAAN,MAAa;AAAA,EASZ,YAAY,SAAiC,IAAI;AAFvC;AAGhB,SAAK,SAAS;AAAA,MACb,GAAG,QAAO;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEL;AAAA,EAEO,SAA2C,MAAiC;AAClF,WAAO,KAAK,OAAO;AAAA,EACpB;AAAA,EAEO,SAA2C,MAAY,OAAkC;AAC/F,SAAK,OAAO,QAAQ;AACb,WAAA;AAAA,EACR;AACD;AAxBO,IAAM,SAAN;AACN,cADY,QACG,iBAA+B;AAAA,EAC7C,0BAA0B;AAAA,EAC1B,yBAAyB;AAAA,EACzB,2BAA2B;AAAA;"}
@@ -23,7 +23,7 @@ import { StateIterator } from "./state/StateIterator.js";
23
23
  import { assertNever } from "../utils/assertNever.js";
24
24
  import { generateEnumerabilityPreventingEntropy } from "../utils/generateEnumerabilityPreventingEntropy.js";
25
25
  const _DataBinding = class {
26
- constructor(contentApiClient, systemApiClient, tenantApiClient, treeStore, environment, onUpdate, onError, onPersistSuccess) {
26
+ constructor(contentApiClient, systemApiClient, tenantApiClient, treeStore, environment, onUpdate, onError, onPersistSuccess, options) {
27
27
  __publicField(this, "accessorErrorManager");
28
28
  __publicField(this, "batchUpdatesOptions");
29
29
  __publicField(this, "asyncBatchUpdatesOptions");
@@ -45,6 +45,7 @@ const _DataBinding = class {
45
45
  this.onUpdate = onUpdate;
46
46
  this.onError = onError;
47
47
  this.onPersistSuccess = onPersistSuccess;
48
+ this.options = options;
48
49
  this.config = new Config();
49
50
  this.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore);
50
51
  this.asyncBatchUpdatesOptions = {
@@ -69,7 +70,7 @@ const _DataBinding = class {
69
70
  this.eventManager,
70
71
  this.treeStore
71
72
  );
72
- this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore);
73
+ this.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist);
73
74
  this.bindingOperations = Object.freeze({
74
75
  ...this.asyncBatchUpdatesOptions,
75
76
  getTreeFilters: () => {
@@ -80,136 +81,120 @@ const _DataBinding = class {
80
81
  this.eventManager.syncTransaction(() => performUpdates(this.bindingOperations));
81
82
  },
82
83
  extendTree: async (...args) => await this.extendTree(...args),
83
- persist: async ({ signal, onPersistSuccess: onPersistSuccess2, onPersistError } = {}) => await this.eventManager.persistOperation(async () => {
84
- for (let attemptNumber = 1; attemptNumber <= this.config.getValue("maxPersistAttempts"); attemptNumber++) {
85
- this.eventManager.syncTransaction(() => {
86
- this.accessorErrorManager.clearErrors();
87
- });
88
- await this.eventManager.triggerOnBeforePersist();
89
- let shouldTryAgain = false;
90
- const proposedBackOffs = [];
91
- const persistErrorOptions = {
92
- ...this.bindingOperations,
93
- tryAgain: (options) => {
94
- shouldTryAgain = true;
95
- if (options?.proposedBackoff !== void 0 && options.proposedBackoff > 0) {
96
- proposedBackOffs.push(options.proposedBackoff);
97
- }
98
- },
99
- attemptNumber
100
- };
101
- if (this.accessorErrorManager.hasErrors()) {
102
- await this.eventManager.triggerOnPersistError(persistErrorOptions);
103
- await onPersistError?.(persistErrorOptions);
104
- if (shouldTryAgain) {
105
- continue;
106
- }
107
- throw {
108
- errors: this.accessorErrorManager.getErrors(),
109
- type: "invalidInput"
110
- };
111
- }
112
- const generator = new MutationGenerator(this.treeStore);
113
- const mutationResult = generator.getPersistMutation();
114
- if (mutationResult === void 0) {
115
- this.dirtinessTracker.reset();
116
- const persistSuccessOptions = {
117
- ...this.bindingOperations,
118
- successType: "nothingToPersist"
119
- };
120
- await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions);
121
- await onPersistSuccess2?.(persistSuccessOptions);
122
- return {
123
- type: "nothingToPersist"
124
- };
125
- }
126
- const { query, operations } = mutationResult;
127
- const mutationResponse = await this.contentApiClient.sendRequest(query, {
128
- signal
129
- });
130
- if (mutationResponse.errors !== void 0 && mutationResponse.errors.length > 0) {
131
- this.onError({
132
- type: "gqlError",
133
- query,
134
- errors: mutationResponse.errors
135
- }, this);
136
- }
137
- if (!mutationResponse.data?.transaction) {
138
- throw {
139
- errors: [],
140
- type: "invalidResponse"
141
- };
142
- }
143
- const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction;
144
- const aliases = Object.keys(mutationData);
145
- if (aliases.every((item) => mutationData[item].ok)) {
146
- const persistedEntityIds = aliases.map((alias) => mutationData[alias].node?.id).filter((id) => id !== void 0);
147
- const result = {
148
- type: "justSuccess",
149
- persistedEntityIds
150
- };
151
- try {
152
- await this.eventManager.asyncTransaction(async () => {
153
- this.resetTreeAfterSuccessfulPersist();
154
- this.treeAugmenter.updatePersistedData(
155
- Object.fromEntries(
156
- Object.entries(mutationData).map(([placeholderName, subTreeResponse]) => [
157
- placeholderName,
158
- subTreeResponse.node
159
- ])
160
- ),
161
- operations
162
- );
163
- const persistSuccessOptions = {
164
- ...this.bindingOperations,
165
- successType: result.type
166
- };
167
- await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions);
168
- await onPersistSuccess2?.(persistSuccessOptions);
169
- this.treeAugmenter.resetCreatingSubTrees();
170
- });
171
- } catch (e) {
172
- console.error(e);
173
- const resultWithError = {
174
- ...result,
175
- afterPersistError: e
176
- };
177
- this.onPersistSuccess(resultWithError, this);
178
- return resultWithError;
179
- }
180
- this.onPersistSuccess(result, this);
181
- return result;
182
- } else {
183
- if (errorMessage) {
184
- console.error(errorMessage);
185
- }
186
- this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations));
187
- await this.eventManager.triggerOnPersistError(persistErrorOptions);
188
- await onPersistError?.(persistErrorOptions);
189
- if (shouldTryAgain) {
190
- if (proposedBackOffs.length) {
191
- const geometricMean = Math.round(
192
- Math.pow(
193
- proposedBackOffs.reduce((a, b) => a * b, 1),
194
- 1 / proposedBackOffs.length
195
- )
196
- );
197
- await new Promise((resolve) => setTimeout(resolve, geometricMean));
198
- }
199
- continue;
200
- }
201
- throw {
202
- errors: this.accessorErrorManager.getErrors(),
203
- type: "invalidInput"
204
- };
205
- }
206
- }
207
- throw {
208
- type: "givenUp"
84
+ persist: async (options2) => await this.persist(options2)
85
+ });
86
+ }
87
+ async persist({ onPersistError, onPersistSuccess, signal } = {}) {
88
+ return await this.eventManager.persistOperation(async () => {
89
+ this.eventManager.syncTransaction(() => {
90
+ this.accessorErrorManager.clearErrors();
91
+ });
92
+ await this.eventManager.triggerOnBeforePersist();
93
+ await this.checkErrorsBeforePersist(onPersistError);
94
+ const generator = new MutationGenerator(this.treeStore);
95
+ const mutationResult = generator.getPersistMutation();
96
+ if (mutationResult === void 0) {
97
+ await this.processEmptyPersistMutation(onPersistSuccess);
98
+ return {
99
+ type: "nothingToPersist"
209
100
  };
210
- })
101
+ }
102
+ const { query, operations } = mutationResult;
103
+ const mutationResponse = await this.contentApiClient.sendRequest(query, {
104
+ signal
105
+ });
106
+ if (mutationResponse.errors !== void 0 && mutationResponse.errors.length > 0) {
107
+ this.onError({
108
+ type: "gqlError",
109
+ query,
110
+ errors: mutationResponse.errors
111
+ }, this);
112
+ }
113
+ if (!mutationResponse.data?.transaction) {
114
+ this.persistFail({
115
+ errors: [],
116
+ type: "invalidResponse"
117
+ });
118
+ }
119
+ const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction;
120
+ if (Object.values(mutationData).every((it) => it.ok)) {
121
+ return await this.processSuccessfulPersistResult(mutationData, operations, onPersistSuccess);
122
+ } else {
123
+ if (errorMessage) {
124
+ console.error(errorMessage);
125
+ }
126
+ this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations));
127
+ await this.eventManager.triggerOnPersistError(this.bindingOperations);
128
+ await onPersistError?.(this.bindingOperations);
129
+ this.persistFail({
130
+ errors: this.accessorErrorManager.getErrors(),
131
+ type: "invalidInput"
132
+ });
133
+ }
211
134
  });
212
135
  }
136
+ async checkErrorsBeforePersist(onPersistError) {
137
+ if (this.accessorErrorManager.hasErrors()) {
138
+ await this.eventManager.triggerOnPersistError(this.bindingOperations);
139
+ await onPersistError?.(this.bindingOperations);
140
+ this.persistFail(
141
+ {
142
+ errors: this.accessorErrorManager.getErrors(),
143
+ type: "invalidInput"
144
+ }
145
+ );
146
+ }
147
+ }
148
+ async processEmptyPersistMutation(onPersistSuccess) {
149
+ this.dirtinessTracker.reset();
150
+ const persistSuccessOptions = {
151
+ ...this.bindingOperations,
152
+ successType: "nothingToPersist"
153
+ };
154
+ await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions);
155
+ await onPersistSuccess?.(persistSuccessOptions);
156
+ }
157
+ async processSuccessfulPersistResult(mutationData, operations, onPersistSuccess) {
158
+ const persistedEntityIds = Object.values(mutationData).map((it) => it.node?.id).filter((id) => id !== void 0);
159
+ const result = {
160
+ type: "justSuccess",
161
+ persistedEntityIds
162
+ };
163
+ try {
164
+ await this.eventManager.asyncTransaction(async () => {
165
+ this.resetTreeAfterSuccessfulPersist();
166
+ this.treeAugmenter.updatePersistedData(
167
+ Object.fromEntries(
168
+ Object.entries(mutationData).map(([placeholderName, subTreeResponse]) => [
169
+ placeholderName,
170
+ subTreeResponse.node
171
+ ])
172
+ ),
173
+ operations
174
+ );
175
+ const persistSuccessOptions = {
176
+ ...this.bindingOperations,
177
+ successType: result.type
178
+ };
179
+ await this.eventManager.triggerOnPersistSuccess(persistSuccessOptions);
180
+ await onPersistSuccess?.(persistSuccessOptions);
181
+ this.treeAugmenter.resetCreatingSubTrees();
182
+ });
183
+ } catch (e) {
184
+ console.error(e);
185
+ const resultWithError = {
186
+ ...result,
187
+ afterPersistError: e
188
+ };
189
+ this.onPersistSuccess(resultWithError, this);
190
+ return resultWithError;
191
+ }
192
+ this.onPersistSuccess(result, this);
193
+ return result;
194
+ }
195
+ persistFail(error) {
196
+ throw error;
197
+ }
213
198
  async extendTree(newFragment, options = {}) {
214
199
  if (options.signal?.aborted) {
215
200
  return Promise.reject(DataBindingExtendAborted);
@@ -1 +1 @@
1
- {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tmetadataToRequestError,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,\n\t\tprivate readonly onError: (error: RequestError, binding: DataBinding) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async ({ signal, onPersistSuccess, onPersistError } = {}) =>\n\t\t\t\tawait this.eventManager.persistOperation(async () => {\n\t\t\t\t\tfor (let attemptNumber = 1; attemptNumber <= this.config.getValue('maxPersistAttempts'); attemptNumber++) {\n\t\t\t\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\t\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t\t\t\t})\n\t\t\t\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\t\t\t\tlet shouldTryAgain = false\n\t\t\t\t\t\tconst proposedBackOffs: number[] = []\n\t\t\t\t\t\tconst persistErrorOptions: PersistErrorOptions = {\n\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\ttryAgain: options => {\n\t\t\t\t\t\t\t\tshouldTryAgain = true\n\t\t\t\t\t\t\t\tif (options?.proposedBackoff !== undefined && options.proposedBackoff > 0) {\n\t\t\t\t\t\t\t\t\tproposedBackOffs.push(options.proposedBackoff)\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tattemptNumber,\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tcontinue // Trying again immediately\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\t\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\t\t\t\tif (mutationResult === undefined) {\n\t\t\t\t\t\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\tsuccessType: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { query, operations } = mutationResult\n\n\t\t\t\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t})\n\n\t\t\t\t\t\tif (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {\n\t\t\t\t\t\t\tthis.onError({\n\t\t\t\t\t\t\t\ttype: 'gqlError',\n\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\terrors: mutationResponse.errors,\n\t\t\t\t\t\t\t}, this)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!mutationResponse.data?.transaction) {\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: [],\n\t\t\t\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction\n\t\t\t\t\t\tconst aliases = Object.keys(mutationData)\n\t\t\t\t\t\tif (aliases.every(item => mutationData[item].ok)) {\n\t\t\t\t\t\t\tconst persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)\n\t\t\t\t\t\t\tconst result: SuccessfulPersistResult = {\n\t\t\t\t\t\t\t\ttype: 'justSuccess',\n\t\t\t\t\t\t\t\tpersistedEntityIds,\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\t\t\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t\t\t\t\t\t]),\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\toperations,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\t\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\t\t\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\t\t\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tconsole.error(e)\n\t\t\t\t\t\t\t\tconst resultWithError = {\n\t\t\t\t\t\t\t\t\t...result,\n\t\t\t\t\t\t\t\t\tafterPersistError: e,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\t\t\t\t\t\treturn resultWithError\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.onPersistSuccess(result, this)\n\t\t\t\t\t\t\treturn result\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (errorMessage) {\n\t\t\t\t\t\t\t\tconsole.error(errorMessage)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))\n\t\t\t\t\t\t\tawait this.eventManager.triggerOnPersistError(persistErrorOptions)\n\t\t\t\t\t\t\tawait onPersistError?.(persistErrorOptions)\n\t\t\t\t\t\t\tif (shouldTryAgain) {\n\t\t\t\t\t\t\t\tif (proposedBackOffs.length) {\n\t\t\t\t\t\t\t\t\tconst geometricMean = Math.round(\n\t\t\t\t\t\t\t\t\t\tMath.pow(\n\t\t\t\t\t\t\t\t\t\t\tproposedBackOffs.reduce((a, b) => a * b, 1),\n\t\t\t\t\t\t\t\t\t\t\t1 / proposedBackOffs.length,\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, geometricMean))\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow {\n\t\t\t\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Max attempts exceeded\n\t\t\t\t\t// TODO fire persist error\n\t\t\t\t\tthrow {\n\t\t\t\t\t\ttype: 'givenUp',\n\t\t\t\t\t}\n\t\t\t\t}),\n\t\t})\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {}, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (typeof metadata === 'object' && metadata !== null && (metadata as { name?: unknown }).name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)\n\t\t}\n\n\t\tif (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {\n\t\t\tthis.onError({\n\t\t\t\ttype: 'gqlError',\n\t\t\t\tquery: query ?? 'unknown query',\n\t\t\t\terrors: queryResponse.errors,\n\t\t\t}, this)\n\t\t}\n\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["onPersistSuccess"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuCO,MAAM,eAAN,MAAkB;AAAA,EAiBjB,YACW,kBACA,iBACA,iBACA,WACA,aACA,UACA,SACA,kBAChB;AAzBe;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA0MT,4CA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AAa,oBAAoB,OAAO,aAAa,qBAAqB;AAAA,cAChF;AACA;AAAA,YACD;AAAA;AAEC,0BAAiB;AAAA;AAAA,QAEpB;AAAA,MACD;AAAA,IAAA,CACA;AAAA,EACF;AAAA,EAOQ,mBAAmB;AAGnB,WAAA,KAAK,UAAU,YAAY,SAAS,IACxC,SACA,GAAG,uCAA4C,KAAA,aAAY,sBAAsB;AAAA,EACrF;AACD;AA3YO,IAAM,cAAN;AA+XN,cA/XY,aA+XG,0BAAyB,MAAM;AAC7C,MAAI,OAAO;AACX,SAAO,MAAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;"}
1
+ {"version":3,"file":"DataBinding.js","sources":["../../../src/core/DataBinding.ts"],"sourcesContent":["import type { GraphQlClient, GraphQlClientFailedRequestMetadata, TreeFilter } from '@contember/client'\nimport type { ReactNode } from 'react'\nimport {\n\tAsyncBatchUpdatesOptions,\n\tBatchUpdatesOptions,\n\tBindingOperations,\n\tExtendTreeOptions,\n\tPersistErrorOptions, PersistOptions,\n\tPersistSuccessOptions,\n\tTreeRootAccessor,\n} from '../accessors'\nimport {\n\tErrorPersistResult,\n\tmetadataToRequestError, MutationDataResponse,\n\tMutationRequestResponse,\n\tQueryRequestResponse,\n\tRequestError,\n\tSuccessfulPersistResult,\n} from '../accessorTree'\nimport type { Environment } from '../dao'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { TreeRootId } from '../treeParameters'\nimport { assertNever, generateEnumerabilityPreventingEntropy } from '../utils'\nimport { AccessorErrorManager } from './AccessorErrorManager'\nimport { Config } from './Config'\nimport { DirtinessTracker } from './DirtinessTracker'\nimport { EventManager } from './EventManager'\nimport { createBatchUpdatesOptions } from './factories'\nimport { MarkerMerger } from './MarkerMerger'\nimport { MarkerTreeGenerator } from './MarkerTreeGenerator'\nimport { MutationGenerator, SubMutationOperation } from './MutationGenerator'\nimport { QueryGenerator } from './QueryGenerator'\nimport { StateIterator } from './state'\nimport { StateInitializer } from './StateInitializer'\nimport { TreeAugmenter } from './TreeAugmenter'\nimport { TreeFilterGenerator } from './TreeFilterGenerator'\nimport { TreeStore } from './TreeStore'\nimport type { UpdateMetadata } from './UpdateMetadata'\nimport { getCombinedSignal } from './utils'\n\nexport class DataBinding {\n\tprivate readonly accessorErrorManager: AccessorErrorManager\n\tprivate readonly batchUpdatesOptions: BatchUpdatesOptions\n\tprivate readonly asyncBatchUpdatesOptions: AsyncBatchUpdatesOptions\n\tprivate readonly bindingOperations: BindingOperations\n\tprivate readonly config: Config\n\tprivate readonly dirtinessTracker: DirtinessTracker\n\tprivate readonly eventManager: EventManager\n\tprivate readonly stateInitializer: StateInitializer\n\tprivate readonly treeAugmenter: TreeAugmenter\n\n\t// private treeRootListeners: {\n\t// \teventListeners: {}\n\t// } = {\n\t// \teventListeners: {},\n\t// }\n\n\tpublic constructor(\n\t\tprivate readonly contentApiClient: GraphQlClient,\n\t\tprivate readonly systemApiClient: GraphQlClient,\n\t\tprivate readonly tenantApiClient: GraphQlClient,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly environment: Environment,\n\t\tprivate readonly onUpdate: (newData: TreeRootAccessor, binding: DataBinding) => void,\n\t\tprivate readonly onError: (error: RequestError, binding: DataBinding) => void,\n\t\tprivate readonly onPersistSuccess: (result: SuccessfulPersistResult, binding: DataBinding) => void,\n\t\tprivate readonly options: {\n\t\t\tskipStateUpdateAfterPersist: boolean\n\t\t},\n\t) {\n\t\tthis.config = new Config()\n\t\tthis.batchUpdatesOptions = createBatchUpdatesOptions(environment, this.treeStore)\n\t\tthis.asyncBatchUpdatesOptions = {\n\t\t\t...this.batchUpdatesOptions,\n\t\t\tcontentClient: contentApiClient,\n\t\t\tsystemClient: systemApiClient,\n\t\t\ttenantClient: tenantApiClient,\n\t\t}\n\t\tthis.dirtinessTracker = new DirtinessTracker()\n\t\tthis.eventManager = new EventManager(\n\t\t\tthis.asyncBatchUpdatesOptions,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.config,\n\t\t\tthis.dirtinessTracker,\n\t\t\tthis.resolvedOnUpdate,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.accessorErrorManager = new AccessorErrorManager(this.eventManager, this.treeStore)\n\t\tthis.stateInitializer = new StateInitializer(\n\t\t\tthis.accessorErrorManager,\n\t\t\tthis.batchUpdatesOptions,\n\t\t\tthis.eventManager,\n\t\t\tthis.treeStore,\n\t\t)\n\t\tthis.treeAugmenter = new TreeAugmenter(this.eventManager, this.stateInitializer, this.treeStore, options.skipStateUpdateAfterPersist)\n\n\t\t// TODO move this elsewhere\n\t\tthis.bindingOperations = Object.freeze<BindingOperations>({\n\t\t\t...this.asyncBatchUpdatesOptions,\n\t\t\tgetTreeFilters: (): TreeFilter[] => {\n\t\t\t\tconst generator = new TreeFilterGenerator(this.treeStore)\n\t\t\t\treturn generator.generateTreeFilter()\n\t\t\t},\n\t\t\tbatchDeferredUpdates: performUpdates => {\n\t\t\t\tthis.eventManager.syncTransaction(() => performUpdates(this.bindingOperations))\n\t\t\t},\n\t\t\textendTree: async (...args) => await this.extendTree(...args),\n\t\t\tpersist: async options => await this.persist(options),\n\t\t})\n\t}\n\n\tprivate async persist({ onPersistError, onPersistSuccess, signal }: PersistOptions = {}) {\n\t\treturn await this.eventManager.persistOperation(async () => {\n\t\t\t// TODO if the tree is in an inconsistent state, wait for lock releases\n\n\t\t\tthis.eventManager.syncTransaction(() => {\n\t\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\t})\n\t\t\tawait this.eventManager.triggerOnBeforePersist()\n\n\t\t\tawait this.checkErrorsBeforePersist(onPersistError)\n\n\t\t\tconst generator = new MutationGenerator(this.treeStore)\n\t\t\tconst mutationResult = generator.getPersistMutation()\n\n\t\t\tif (mutationResult === undefined) {\n\t\t\t\tawait this.processEmptyPersistMutation(onPersistSuccess)\n\t\t\t\treturn {\n\t\t\t\t\ttype: 'nothingToPersist',\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst { query, operations } = mutationResult\n\n\t\t\tconst mutationResponse: MutationRequestResponse = await this.contentApiClient.sendRequest(query, {\n\t\t\t\tsignal,\n\t\t\t})\n\n\t\t\tif (mutationResponse.errors !== undefined && mutationResponse.errors.length > 0) {\n\t\t\t\tthis.onError({\n\t\t\t\t\ttype: 'gqlError',\n\t\t\t\t\tquery,\n\t\t\t\t\terrors: mutationResponse.errors,\n\t\t\t\t}, this)\n\t\t\t}\n\n\t\t\tif (!mutationResponse.data?.transaction) {\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: [],\n\t\t\t\t\ttype: 'invalidResponse',\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tconst { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction\n\t\t\tif (Object.values(mutationData).every(it => it.ok)) {\n\t\t\t\treturn await this.processSuccessfulPersistResult(mutationData, operations, onPersistSuccess)\n\t\t\t} else {\n\t\t\t\tif (errorMessage) {\n\t\t\t\t\tconsole.error(errorMessage)\n\t\t\t\t}\n\n\t\t\t\tthis.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))\n\n\t\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t})\n\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async checkErrorsBeforePersist(onPersistError: PersistOptions['onPersistError']) {\n\t\tif (this.accessorErrorManager.hasErrors()) {\n\t\t\tawait this.eventManager.triggerOnPersistError(this.bindingOperations)\n\t\t\tawait onPersistError?.(this.bindingOperations)\n\t\t\tthis.persistFail({\n\t\t\t\t\terrors: this.accessorErrorManager.getErrors(),\n\t\t\t\t\ttype: 'invalidInput',\n\t\t\t\t},\n\t\t\t)\n\t\t}\n\t}\n\n\tprivate async processEmptyPersistMutation(onPersistSuccess: PersistOptions['onPersistSuccess']): Promise<void> {\n\t\tthis.dirtinessTracker.reset() // TODO This ideally shouldn't be necessary but given the current limitations, this makes for better UX.\n\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t...this.bindingOperations,\n\t\t\tsuccessType: 'nothingToPersist',\n\t\t}\n\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\t}\n\n\tprivate async processSuccessfulPersistResult(mutationData: MutationDataResponse, operations: SubMutationOperation[], onPersistSuccess: PersistOptions['onPersistSuccess']) {\n\t\tconst persistedEntityIds = Object.values(mutationData).map(it => it.node?.id).filter(id => id !== undefined)\n\t\tconst result: SuccessfulPersistResult = {\n\t\t\ttype: 'justSuccess',\n\t\t\tpersistedEntityIds,\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.eventManager.asyncTransaction(async () => {\n\t\t\t\tthis.resetTreeAfterSuccessfulPersist()\n\t\t\t\tthis.treeAugmenter.updatePersistedData(\n\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\tObject.entries(mutationData).map(([placeholderName, subTreeResponse]) => [\n\t\t\t\t\t\t\tplaceholderName,\n\t\t\t\t\t\t\tsubTreeResponse.node,\n\t\t\t\t\t\t]),\n\t\t\t\t\t),\n\t\t\t\t\toperations,\n\t\t\t\t)\n\t\t\t\tconst persistSuccessOptions: PersistSuccessOptions = {\n\t\t\t\t\t...this.bindingOperations,\n\t\t\t\t\tsuccessType: result.type,\n\t\t\t\t}\n\t\t\t\tawait this.eventManager.triggerOnPersistSuccess(persistSuccessOptions)\n\t\t\t\tawait onPersistSuccess?.(persistSuccessOptions)\n\n\t\t\t\tthis.treeAugmenter.resetCreatingSubTrees()\n\t\t\t})\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t\tconst resultWithError = {\n\t\t\t\t...result,\n\t\t\t\tafterPersistError: e,\n\t\t\t}\n\t\t\tthis.onPersistSuccess(resultWithError, this)\n\t\t\treturn resultWithError\n\t\t}\n\t\tthis.onPersistSuccess(result, this)\n\t\treturn result\n\t}\n\n\tprivate persistFail(error: ErrorPersistResult): never {\n\t\tthrow error\n\t}\n\n\tprivate resolvedOnUpdate = ({ isMutating }: UpdateMetadata) => {\n\t\tthis.onUpdate(new TreeRootAccessor(this.dirtinessTracker.hasChanges(), isMutating, this.bindingOperations), this)\n\t}\n\n\t// This is currently useless but potentially future-compatible\n\t// private readonly addTreeRootEventListener: TreeRootAccessor.AddTreeRootEventListener = this.getAddEventListener(\n\t// \tthis.treeRootListeners,\n\t// )\n\n\tprivate pendingExtensions: Set<{\n\t\tmarkerTreeRoot: MarkerTreeRoot\n\t\tnewFragment: ReactNode\n\t\tnewTreeRootId: TreeRootId | undefined\n\t\toptions: ExtendTreeOptions\n\t\treject: () => void\n\t\tresolve: (newRootId: TreeRootId | undefined) => void\n\t}> = new Set()\n\n\tpublic async extendTree(newFragment: ReactNode, options: ExtendTreeOptions = {}): Promise<TreeRootId | undefined> {\n\t\tif (options.signal?.aborted) {\n\t\t\treturn Promise.reject(DataBindingExtendAborted)\n\t\t}\n\t\tconst markerTreeRoot = new MarkerTreeGenerator(newFragment, options.environment ?? this.environment).generate()\n\n\t\tif (this.treeStore.effectivelyHasTreeRoot(markerTreeRoot)) {\n\t\t\t// This isn't perfectly accurate as theoretically, we could already have all the data necessary but this\n\t\t\t// could still be false.\n\n\t\t\treturn this.eventManager.syncOperation(() => {\n\t\t\t\tconst newTreeRootId = this.getNewTreeRootId()\n\t\t\t\tthis.treeAugmenter.extendTreeStates(newTreeRootId, markerTreeRoot)\n\t\t\t\treturn newTreeRootId\n\t\t\t})\n\t\t}\n\n\t\treturn await new Promise((resolve, reject) => {\n\t\t\tthis.pendingExtensions.add({\n\t\t\t\tmarkerTreeRoot,\n\t\t\t\tnewFragment,\n\t\t\t\tnewTreeRootId: this.getNewTreeRootId(),\n\t\t\t\toptions,\n\t\t\t\treject: () => reject(DataBindingExtendAborted),\n\t\t\t\tresolve,\n\t\t\t})\n\t\t\tconst pendingExtensionsCount = this.pendingExtensions.size\n\n\t\t\tPromise.resolve().then(() => {\n\t\t\t\tif (pendingExtensionsCount < this.pendingExtensions.size) {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tthis.flushBatchedTreeExtensions()\n\t\t\t})\n\t\t})\n\t}\n\n\tprivate async flushBatchedTreeExtensions() {\n\t\t// This is an async operation so we just take whatever pendingExtensions there are now and let any new ones\n\t\t// accumulate in an empty set.\n\t\tconst pendingExtensions = Array.from(this.pendingExtensions).filter(extension => {\n\t\t\tif (extension.options.signal?.aborted) {\n\t\t\t\textension.reject()\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn true\n\t\t})\n\t\tthis.pendingExtensions.clear()\n\n\t\tconst aggregateMarkerTreeRoot = pendingExtensions.reduce<MarkerTreeRoot | undefined>(\n\t\t\t(previousValue, currentValue) => {\n\t\t\t\tif (previousValue === undefined) {\n\t\t\t\t\treturn currentValue.markerTreeRoot\n\t\t\t\t}\n\t\t\t\treturn MarkerMerger.mergeMarkerTreeRoots(previousValue, currentValue.markerTreeRoot)\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\n\t\tif (aggregateMarkerTreeRoot === undefined) {\n\t\t\treturn\n\t\t}\n\n\t\tconst aggregateSignal = getCombinedSignal(pendingExtensions.map(extension => extension.options.signal))\n\n\t\tconst aggregatePersistedData = await this.fetchPersistedData(aggregateMarkerTreeRoot, aggregateSignal)\n\n\t\tif (aggregateSignal?.aborted) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.eventManager.syncOperation(() => {\n\t\t\tthis.treeAugmenter.extendPersistedData(aggregatePersistedData?.data ?? {}, aggregateMarkerTreeRoot)\n\n\t\t\tfor (const extension of pendingExtensions) {\n\t\t\t\tthis.treeAugmenter.extendTreeStates(extension.newTreeRootId, extension.markerTreeRoot)\n\t\t\t\textension.resolve(extension.newTreeRootId)\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate async fetchPersistedData(\n\t\ttree: MarkerTreeRoot,\n\t\tsignal?: AbortSignal,\n\t): Promise<QueryRequestResponse | undefined> {\n\t\tconst queryGenerator = new QueryGenerator(tree)\n\t\tconst query = queryGenerator.getReadQuery()\n\n\t\tlet queryResponse: QueryRequestResponse | undefined = undefined\n\n\t\ttry {\n\t\t\tqueryResponse =\n\t\t\t\tquery === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: await this.contentApiClient.sendRequest(query, {\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t })\n\t\t} catch (metadata) {\n\t\t\tif (typeof metadata === 'object' && metadata !== null && (metadata as { name?: unknown }).name === 'AbortError') {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tthis.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)\n\t\t}\n\n\t\tif (queryResponse && queryResponse.errors !== undefined && queryResponse.errors.length > 0) {\n\t\t\tthis.onError({\n\t\t\t\ttype: 'gqlError',\n\t\t\t\tquery: query ?? 'unknown query',\n\t\t\t\terrors: queryResponse.errors,\n\t\t\t}, this)\n\t\t}\n\n\t\treturn queryResponse\n\t}\n\n\tprivate resetTreeAfterSuccessfulPersist() {\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tthis.accessorErrorManager.clearErrors()\n\t\t\tthis.dirtinessTracker.reset()\n\n\t\t\tfor (const [, rootState] of StateIterator.eachRootState(this.treeStore)) {\n\t\t\t\tfor (const state of StateIterator.depthFirstAllNodes(rootState)) {\n\t\t\t\t\tswitch (state.type) {\n\t\t\t\t\t\tcase 'field': {\n\t\t\t\t\t\t\tif (state.hasUnpersistedChanges || state.touchLog?.size) {\n\t\t\t\t\t\t\t\tstate.touchLog?.clear()\n\t\t\t\t\t\t\t\tstate.hasUnpersistedChanges = false\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcase 'entityList':\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedRemovals?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedRemovals?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase 'entityRealm': {\n\t\t\t\t\t\t\tif (state.unpersistedChangesCount > 0 || state.plannedHasOneDeletions?.size) {\n\t\t\t\t\t\t\t\tstate.unpersistedChangesCount = 0\n\t\t\t\t\t\t\t\tstate.plannedHasOneDeletions?.clear()\n\t\t\t\t\t\t\t\tthis.eventManager.registerJustUpdated(state, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tassertNever(state)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tprivate static getNextTreeRootIdSeed = (() => {\n\t\tlet seed = 1\n\t\treturn () => seed++\n\t})()\n\n\tprivate getNewTreeRootId() {\n\t\t// TODO this is an awful, awful hack.\n\t\t// TODO the particular shape of the alias is relied on in MutationAlias. If you change this, change it there too.\n\t\treturn this.treeStore.markerTrees.size === 0\n\t\t\t? undefined\n\t\t\t: `${generateEnumerabilityPreventingEntropy()}-${DataBinding.getNextTreeRootIdSeed()}`\n\t}\n}\n\nexport const DataBindingExtendAborted = Symbol('aborted')\n"],"names":["options"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAwCO,MAAM,eAAN,MAAkB;AAAA,EAiBjB,YACW,kBACA,iBACA,iBACA,WACA,aACA,UACA,SACA,kBACA,SAGhB;AA5Be;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAgMT,4CAAmB,CAAC,EAAE,iBAAiC;AACzD,WAAA,SAAS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AAM;AAAA;AAYF,MAAA,2BAA2B,OAAO,SAAS;"}
@@ -5,10 +5,11 @@ import { assert } from "../utils/assert.js";
5
5
  import { ServerId, UnpersistedEntityDummyId, ClientGeneratedUuid } from "../accessorTree/RuntimeId.js";
6
6
  import { assertNever } from "../utils/assertNever.js";
7
7
  class TreeAugmenter {
8
- constructor(eventManager, stateInitializer, treeStore) {
8
+ constructor(eventManager, stateInitializer, treeStore, skipStateUpdateAfterPersist = false) {
9
9
  this.eventManager = eventManager;
10
10
  this.stateInitializer = stateInitializer;
11
11
  this.treeStore = treeStore;
12
+ this.skipStateUpdateAfterPersist = skipStateUpdateAfterPersist;
12
13
  }
13
14
  extendPersistedData(newPersistedData, markerTree) {
14
15
  this.treeStore.mergeInQueryResponse(newPersistedData, markerTree);
@@ -24,6 +25,9 @@ class TreeAugmenter {
24
25
  }
25
26
  updatePersistedData(response, operations) {
26
27
  this.treeStore.mergeInMutationResponse(response, operations);
28
+ if (this.skipStateUpdateAfterPersist) {
29
+ return;
30
+ }
27
31
  this.eventManager.syncTransaction(() => {
28
32
  for (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {
29
33
  for (const [rootPlaceholder, rootState] of rootStates) {
@@ -1 +1 @@
1
- {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.children.changeKeyOrder(newPersistedIds)\n\t}\n}\n"],"names":[],"mappings":";;;;;;AAmBO,MAAM,cAAc;AAAA,EACnB,YACW,cACA,kBACA,WAChB;AAHgB,SAAA,eAAA;AACA,SAAA,mBAAA;AACA,SAAA,YAAA;AAAA,EACf;AAAA,EAEI,oBAAoB,kBAAoC,YAA4B;AAErF,SAAA,UAAU,qBAAqB,kBAAkB,UAAU;AAAA,EACjE;AAAA,EAEO,iBAAiB,WAAmC,eAAqC;AACzF,UAAA,oCAAyD;AAE/D,SAAK,UAAU,YAAY,IAAI,WAAW,aAAa;AACvD,SAAK,UAAU,oBAAoB,IAAI,WAAW,aAAa;AAE/D,eAAW,CAAC,iBAAiB,gBAAgB,KAAK,cAAc,UAAU;AACzE,YAAM,WAAW,KAAK,iBAAiB,kBAAkB,gBAAgB;AAC3D,oBAAA,IAAI,iBAAiB,QAAQ;AAAA,IAC5C;AAAA,EACD;AAAA,EAEO,oBAAoB,UAA4B,YAAoC;AACrF,SAAA,UAAU,wBAAwB,UAAU,UAAU;AAEtD,SAAA,aAAa,gBAAgB,MAAM;AACvC,iBAAW,cAAc,KAAK,UAAU,oBAAoB,UAAU;AAUrE,mBAAW,CAAC,iBAAiB,SAAS,KAAK,YAAY;AACtD,gBAAM,WAAW,KAAK,UAAU,qBAAqB,IAAI,eAAe;AAEpE,cAAA,UAAU,SAAS,cAAc;AAChC,gBAAA,EAAE,oBAAoB,MAAM;AAC/B;AAAA,YACD;AACK,iBAAA,8BAA8B,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S,eAAe,OAAO,MAAM,OAAO,UAAU;AAAA,QAAA;AAAA,MAE5D;AACI,UAAA,MAAM,SAAS,eAAe;AACjC,aAAK,+BAA+B,KAAK;AAAA,MAC1C;AAAA,IACD;AACA,eAAW,wBAAwB,uBAAuB;AACpD,WAAA,iBAAiB,sBAAsB,IAAI,SAAS,sBAAsB,MAAM,UAAU,GAAG,MAAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
1
+ {"version":3,"file":"TreeAugmenter.js","sources":["../../../src/core/TreeAugmenter.ts"],"sourcesContent":["import {\n\tClientGeneratedUuid,\n\tEntityListPersistedData,\n\tReceivedDataTree,\n\tRuntimeId,\n\tServerId,\n\tUnpersistedEntityDummyId,\n} from '../accessorTree'\nimport { BindingError } from '../BindingError'\nimport type { MarkerTreeRoot } from '../markers'\nimport type { EntityId, PlaceholderName, TreeRootId } from '../treeParameters'\nimport { assert, assertNever } from '../utils'\nimport { EventManager } from './EventManager'\nimport { OperationsHelpers } from './operations/OperationsHelpers'\nimport type { EntityListState, EntityRealmState, EntityRealmStateStub, RootStateNode } from './state'\nimport type { StateInitializer } from './StateInitializer'\nimport type { TreeStore } from './TreeStore'\nimport { SubMutationOperation } from './MutationGenerator'\n\nexport class TreeAugmenter {\n\tpublic constructor(\n\t\tprivate readonly eventManager: EventManager,\n\t\tprivate readonly stateInitializer: StateInitializer,\n\t\tprivate readonly treeStore: TreeStore,\n\t\tprivate readonly skipStateUpdateAfterPersist: boolean = false,\n\t) {}\n\n\tpublic extendPersistedData(newPersistedData: ReceivedDataTree, markerTree: MarkerTreeRoot) {\n\t\t// TODO this doesn't yet handle updates for entities whose persisted data just gets magically changed without notice.\n\t\tthis.treeStore.mergeInQueryResponse(newPersistedData, markerTree)\n\t}\n\n\tpublic extendTreeStates(newTreeId: TreeRootId | undefined, newMarkerTree: MarkerTreeRoot): void {\n\t\tconst subTreeStates: Map<PlaceholderName, RootStateNode> = new Map()\n\n\t\tthis.treeStore.markerTrees.set(newTreeId, newMarkerTree)\n\t\tthis.treeStore.subTreeStatesByRoot.set(newTreeId, subTreeStates)\n\n\t\tfor (const [placeholderName, newSubTreeMarker] of newMarkerTree.subTrees) {\n\t\t\tconst newState = this.stateInitializer.initializeSubTree(newSubTreeMarker)\n\t\t\tsubTreeStates.set(placeholderName, newState)\n\t\t}\n\t}\n\n\tpublic updatePersistedData(response: ReceivedDataTree, operations: SubMutationOperation[]) {\n\t\tthis.treeStore.mergeInMutationResponse(response, operations)\n\t\tif (this.skipStateUpdateAfterPersist) {\n\t\t\treturn\n\t\t}\n\t\tthis.eventManager.syncTransaction(() => {\n\t\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\t\t// for (const rootPlaceholder in response) {\n\t\t\t\t// \tconst rootState = rootStates.get(rootPlaceholder)\n\t\t\t\t//\n\t\t\t\t// \tif (rootState === undefined) {\n\t\t\t\t// \t\tcontinue\n\t\t\t\t// \t}\n\t\t\t\t// TODO the above would be better, only refreshing roots which participated in the mutation. However, due to\n\t\t\t\t// \thow mutations are currently generated, we cannot assume that only roots present in the response need\n\t\t\t\t// \trefreshed. So we just refresh all.\n\t\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\t\tconst rootData = this.treeStore.subTreePersistedData.get(rootPlaceholder)\n\n\t\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\t\tif (!(rootData instanceof Set)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateEntityListPersistedData(rootState, rootData)\n\t\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\t\tif (rootData !== undefined && !(rootData instanceof ServerId)) {\n\t\t\t\t\t\t\tcontinue // This should never happen.\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.updateRealmIdIfNecessary(rootState, rootData)\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(rootState)\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn assertNever(rootState)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\tpublic resetCreatingSubTrees() {\n\t\tfor (const rootStates of this.treeStore.subTreeStatesByRoot.values()) {\n\t\t\tfor (const [rootPlaceholder, rootState] of rootStates) {\n\t\t\t\tif (rootState.type === 'entityList') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst changesCount = rootState.unpersistedChangesCount\n\n\t\t\t\t\t// Just emptying the list. But the list itself can stay.\n\t\t\t\t\tfor (const childState of rootState.children.values()) {\n\t\t\t\t\t\tthis.treeStore.disposeOfRealm(childState)\n\t\t\t\t\t}\n\t\t\t\t\trootState.accessor = undefined\n\t\t\t\t\trootState.children.clear()\n\t\t\t\t\trootState.childrenWithPendingUpdates?.clear()\n\t\t\t\t\trootState.errors = undefined\n\t\t\t\t\trootState.plannedRemovals?.clear()\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(\n\t\t\t\t\t\trootState,\n\t\t\t\t\t\tchangesCount ? -1 * changesCount : EventManager.NO_CHANGES_DIFFERENCE,\n\t\t\t\t\t)\n\t\t\t\t} else if (rootState.type === 'entityRealm') {\n\t\t\t\t\tassert(rootState.blueprint.parent === undefined)\n\t\t\t\t\tif (!rootState.blueprint.marker.parameters.isCreating) {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tconst presentListeners = rootState.eventListeners\n\t\t\t\t\tthis.treeStore.disposeOfRealm(rootState)\n\n\t\t\t\t\t// It's crucial to delete the persisted data before we re-initialize so that we get a fresh, new entity.\n\t\t\t\t\tthis.treeStore.subTreePersistedData.delete(rootPlaceholder)\n\t\t\t\t\tconst newRootState = this.stateInitializer.initializeSubTree(rootState.blueprint.marker)\n\n\t\t\t\t\t// We preserve the previous listeners but purge some of them.\n\t\t\t\t\tnewRootState.eventListeners = presentListeners\n\t\t\t\t\tOperationsHelpers.purgeStaleListenersAfterIdChange(newRootState as EntityRealmState)\n\n\t\t\t\t\trootStates.set(rootPlaceholder, newRootState)\n\n\t\t\t\t\tthis.eventManager.registerJustUpdated(newRootState, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t} else {\n\t\t\t\t\tassertNever(rootState)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateRealmIdIfNecessary(\n\t\trealm: EntityRealmState | EntityRealmStateStub,\n\t\tnewId: ServerId | undefined | null,\n\t) {\n\t\tconst currentId = realm.entity.id\n\t\tlet idToChangeTo: RuntimeId | undefined = undefined\n\n\t\tif (currentId instanceof ServerId) {\n\t\t\tif (newId === undefined || newId === null) {\n\t\t\t\tidToChangeTo = new UnpersistedEntityDummyId()\n\t\t\t} else if (currentId.value !== newId.value) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else if (currentId instanceof ClientGeneratedUuid) {\n\t\t\tidToChangeTo = newId ?? new UnpersistedEntityDummyId()\n\t\t} else if (currentId instanceof UnpersistedEntityDummyId) {\n\t\t\tif (newId) {\n\t\t\t\tidToChangeTo = newId\n\t\t\t}\n\t\t} else {\n\t\t\treturn assertNever(currentId)\n\t\t}\n\t\tif (idToChangeTo) {\n\t\t\tOperationsHelpers.changeRealmId(this.treeStore, this.eventManager, this.stateInitializer, realm, idToChangeTo)\n\t\t}\n\t}\n\n\tprivate updateEntityRealmPersistedData(realm: EntityRealmState) {\n\t\tconst realmId = realm.entity.id\n\t\tconst persistedData = realmId.existsOnServer ? this.treeStore.persistedEntityData.get(realmId.uniqueValue) : undefined\n\n\t\tfor (const [placeholderName, child] of realm.children) {\n\t\t\tconst childData = persistedData?.get(placeholderName)\n\n\t\t\tswitch (child.type) {\n\t\t\t\tcase 'field': {\n\t\t\t\t\tif (childData instanceof ServerId || childData instanceof Set) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\n\t\t\t\t\tif (child.persistedValue !== childData) {\n\t\t\t\t\t\tconst shouldChangeBothValues = child.persistedValue === child.value\n\n\t\t\t\t\t\tchild.persistedValue = childData\n\t\t\t\t\t\tif (shouldChangeBothValues) {\n\t\t\t\t\t\t\tchild.value = childData ?? null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.eventManager.registerJustUpdated(child, EventManager.NO_CHANGES_DIFFERENCE)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityRealm':\n\t\t\t\tcase 'entityRealmStub': {\n\t\t\t\t\tif (!(childData instanceof ServerId) && childData !== undefined && childData !== null) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateRealmIdIfNecessary(child, childData)\n\t\t\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t\t\t}\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'entityList': {\n\t\t\t\t\tif (childData !== undefined && !(childData instanceof Set)) {\n\t\t\t\t\t\tthrow new BindingError()\n\t\t\t\t\t}\n\t\t\t\t\tthis.updateEntityListPersistedData(child, childData ?? new Set()) // TODO!!\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn assertNever(child)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate updateEntityListPersistedData(state: EntityListState, newPersistedIds: EntityListPersistedData) {\n\t\tconst persistedWithoutState: EntityId[] = []\n\n\t\t// TODO This isn't particularly efficient. We should probably use something like diff-sequence here.\n\n\t\tfor (const persistedId of newPersistedIds) {\n\t\t\tif (!state.children.has(persistedId)) {\n\t\t\t\tpersistedWithoutState.push(persistedId)\n\t\t\t}\n\t\t}\n\t\tfor (const [stateId, child] of state.children) {\n\t\t\tconst childRuntimeId = child.entity.id\n\t\t\tif (!newPersistedIds.has(stateId)) {\n\t\t\t\tif (\n\t\t\t\t\t// It's a uuid but it's not among the persisted so either it got deleted/disconnected or the client-side\n\t\t\t\t\t// id generation didn't quite pan out.\n\t\t\t\t\tchildRuntimeId instanceof ServerId ||\n\t\t\t\t\tchildRuntimeId instanceof ClientGeneratedUuid ||\n\t\t\t\t\t// No persisted entity id to allocate to this so that's a goodbye.\n\t\t\t\t\tpersistedWithoutState.length === 0\n\t\t\t\t) {\n\t\t\t\t\tstate.getAccessor().disconnectEntity(child.getAccessor())\n\t\t\t\t\tcontinue\n\t\t\t\t} else {\n\t\t\t\t\tconst drawnId = persistedWithoutState.shift()!\n\t\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\t\tthis.treeStore,\n\t\t\t\t\t\tthis.eventManager,\n\t\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\t\tchild,\n\t\t\t\t\t\tnew ServerId(drawnId, child.entity.entityName),\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t} else if (childRuntimeId instanceof ClientGeneratedUuid) {\n\t\t\t\tOperationsHelpers.changeRealmId(\n\t\t\t\t\tthis.treeStore,\n\t\t\t\t\tthis.eventManager,\n\t\t\t\t\tthis.stateInitializer,\n\t\t\t\t\tchild,\n\t\t\t\t\tnew ServerId(childRuntimeId.value, child.entity.entityName),\n\t\t\t\t)\n\t\t\t}\n\t\t\tif (child.type === 'entityRealm') {\n\t\t\t\tthis.updateEntityRealmPersistedData(child)\n\t\t\t}\n\t\t}\n\t\tfor (const unclaimedPersistedId of persistedWithoutState) {\n\t\t\tthis.stateInitializer.initializeEntityRealm(new ServerId(unclaimedPersistedId, state.entityName), state.entityName, {\n\t\t\t\ttype: 'listEntity',\n\t\t\t\tparent: state,\n\t\t\t})\n\t\t}\n\t\t// All that remains now is the order.\n\t\tstate.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AAM,YAAY;AAAA,QACnH,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA,CACR;AAAA,IACF;AAEM,UAAA,SAAS,eAAe,eAAe;AAAA,EAC9C;AACD;"}
@@ -4,10 +4,7 @@ import { useDataBinding } from "../accessorTree/useDataBinding.js";
4
4
  import { AccessorTree } from "../accessorTree/AccessorTree.js";
5
5
  var _jsxFileName = "/__w/admin/admin/packages/binding/src/coreComponents/DataBindingProvider.tsx";
6
6
  const DataBindingProvider = memo(function DataBindingProvider2(props) {
7
- const accessorTreeState = useDataBinding({
8
- nodeTree: props.children,
9
- refreshOnPersist: props.refreshOnPersist ?? false
10
- });
7
+ const accessorTreeState = useDataBinding(props);
11
8
  const children = "stateComponent" in props && props.stateComponent ? createElement(props.stateComponent, {
12
9
  ...props.stateProps,
13
10
  accessorTreeState
@@ -17,7 +14,7 @@ const DataBindingProvider = memo(function DataBindingProvider2(props) {
17
14
  children
18
15
  }, void 0, false, {
19
16
  fileName: _jsxFileName,
20
- lineNumber: 42,
17
+ lineNumber: 37,
21
18
  columnNumber: 9
22
19
  }, this);
23
20
  });
@@ -1 +1 @@
1
- {"version":3,"file":"DataBindingProvider.js","sources":["../../../src/coreComponents/DataBindingProvider.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode } from 'react'\nimport { AccessorTree, AccessorTreeState, useDataBinding } from '../accessorTree'\n\nexport interface DataBindingProviderBaseProps {\n\tchildren?: ReactNode\n\trefreshOnPersist?: boolean\n}\n\nexport interface DataBindingStateComponentProps {\n\taccessorTreeState: AccessorTreeState\n\tchildren?: ReactNode\n}\n\nexport type DataBindingProviderProps<StateProps> = DataBindingProviderBaseProps &\n\t(\n\t\t| {}\n\t\t| {\n\t\t\t\tstateComponent: ComponentType<StateProps & DataBindingStateComponentProps>\n\t\t\t\tstateProps?: StateProps\n\t\t }\n\t)\n\nexport const DataBindingProvider = memo(function DataBindingProvider<StateProps extends DataBindingStateComponentProps>(\n\tprops: DataBindingProviderProps<StateProps>,\n) {\n\tconst accessorTreeState = useDataBinding({\n\t\tnodeTree: props.children,\n\t\trefreshOnPersist: props.refreshOnPersist ?? false,\n\t})\n\n\tconst children =\n\t\t'stateComponent' in props && props.stateComponent\n\t\t\t? createElement(\n\t\t\t\t\tprops.stateComponent,\n\t\t\t\t\t{\n\t\t\t\t\t\t...props.stateProps!,\n\t\t\t\t\t\taccessorTreeState: accessorTreeState,\n\t\t\t\t\t},\n\t\t\t\t\tprops.children,\n\t\t\t )\n\t\t\t: props.children\n\treturn <AccessorTree state={accessorTreeState}>{children}</AccessorTree>\n}) as <StateProps>(props: DataBindingProviderProps<StateProps>) => ReactElement\n"],"names":["DataBindingProvider","memo","props","accessorTreeState","useDataBinding","nodeTree","children","refreshOnPersist","stateComponent","createElement","stateProps"],"mappings":";;;;;AAsBO,MAAMA,sBAAsBC,KAAK,SAASD,qBAChDE,OACC;AACD,QAAMC,oBAAoBC,eAAe;AAAA,IACxCC,UAAUH,MAAMI;AAAAA,IAChBC,kBAAkBL,MAAMK,oBAAoB;AAAA,EAAA,CAFL;AAKxC,QAAMD,WACL,oBAAoBJ,SAASA,MAAMM,iBAChCC,cACAP,MAAMM,gBACN;AAAA,IACC,GAAGN,MAAMQ;AAAAA,IACTP;AAAAA,EAEDD,GAAAA,MAAMI,QANO,IAQbJ,MAAMI;AACV,gCAAQ,cAAD;AAAA,IAAc,OAAOH;AAAAA,IAArB;AAAA,EAAA,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,KAAP,IAAA;AACA,CApBsC;"}
1
+ {"version":3,"file":"DataBindingProvider.js","sources":["../../../src/coreComponents/DataBindingProvider.tsx"],"sourcesContent":["import { ComponentType, createElement, memo, ReactElement, ReactNode } from 'react'\nimport { AccessorTree, AccessorTreeState, AccessorTreeStateOptions, useDataBinding } from '../accessorTree'\n\nexport type DataBindingProviderBaseProps =\n\t& AccessorTreeStateOptions\n\nexport interface DataBindingStateComponentProps {\n\taccessorTreeState: AccessorTreeState\n\tchildren?: ReactNode\n}\n\nexport type DataBindingProviderProps<StateProps> = DataBindingProviderBaseProps &\n\t(\n\t\t| {}\n\t\t| {\n\t\t\t\tstateComponent: ComponentType<StateProps & DataBindingStateComponentProps>\n\t\t\t\tstateProps?: StateProps\n\t\t }\n\t)\n\nexport const DataBindingProvider = memo(function DataBindingProvider<StateProps extends DataBindingStateComponentProps>(\n\tprops: DataBindingProviderProps<StateProps>,\n) {\n\tconst accessorTreeState = useDataBinding(props)\n\n\tconst children =\n\t\t'stateComponent' in props && props.stateComponent\n\t\t\t? createElement(\n\t\t\t\t\tprops.stateComponent,\n\t\t\t\t\t{\n\t\t\t\t\t\t...props.stateProps!,\n\t\t\t\t\t\taccessorTreeState: accessorTreeState,\n\t\t\t\t\t},\n\t\t\t\t\tprops.children,\n\t\t\t )\n\t\t\t: props.children\n\treturn <AccessorTree state={accessorTreeState}>{children}</AccessorTree>\n}) as <StateProps>(props: DataBindingProviderProps<StateProps>) => ReactElement\n"],"names":["DataBindingProvider","memo","props","accessorTreeState","useDataBinding","children","stateComponent","createElement","stateProps"],"mappings":";;;;;AAoBO,MAAMA,sBAAsBC,KAAK,SAASD,qBAChDE,OACC;AACKC,QAAAA,oBAAoBC,eAAeF,KAAD;AAExC,QAAMG,WACL,oBAAoBH,SAASA,MAAMI,iBAChCC,cACAL,MAAMI,gBACN;AAAA,IACC,GAAGJ,MAAMM;AAAAA,IACTL;AAAAA,EAEDD,GAAAA,MAAMG,QANO,IAQbH,MAAMG;AACV,gCAAQ,cAAD;AAAA,IAAc,OAAOF;AAAAA,IAArB;AAAA,EAAA,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,KAAP,IAAA;AACA,CAjBsC;"}