@contember/binding 1.1.0-alpha.0 → 1.1.0-alpha.3

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 (271) hide show
  1. package/dist/development/accessorPropagation/useEntityListSubTree.js +4 -2
  2. package/dist/development/accessorPropagation/useEntityListSubTree.js.map +1 -1
  3. package/dist/development/accessorPropagation/useEntitySubTree.js +4 -2
  4. package/dist/development/accessorPropagation/useEntitySubTree.js.map +1 -1
  5. package/dist/development/accessorPropagation/useExtendTree.js +27 -0
  6. package/dist/development/accessorPropagation/useExtendTree.js.map +1 -0
  7. package/dist/development/accessorTree/AccessorTree.js +9 -4
  8. package/dist/development/accessorTree/AccessorTree.js.map +1 -1
  9. package/dist/development/accessorTree/AccessorTreeStateContext.js +6 -0
  10. package/dist/development/accessorTree/AccessorTreeStateContext.js.map +1 -0
  11. package/dist/development/accessorTree/NormalizedPersistedData.js.map +1 -1
  12. package/dist/development/accessorTree/RuntimeId.js +17 -4
  13. package/dist/development/accessorTree/RuntimeId.js.map +1 -1
  14. package/dist/development/accessorTree/useAccessorTreeState.js +5 -0
  15. package/dist/development/accessorTree/useAccessorTreeState.js.map +1 -0
  16. package/dist/development/accessors/EntityAccessor.js +0 -32
  17. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  18. package/dist/development/accessors/EntityListAccessor.js +1 -1
  19. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  20. package/dist/development/core/AccessorErrorManager.js +3 -0
  21. package/dist/development/core/AccessorErrorManager.js.map +1 -1
  22. package/dist/development/core/DataBinding.js +7 -6
  23. package/dist/development/core/DataBinding.js.map +1 -1
  24. package/dist/development/core/DirtinessTracker.js +4 -13
  25. package/dist/development/core/DirtinessTracker.js.map +1 -1
  26. package/dist/development/core/ErrorsPreprocessor.js.map +1 -1
  27. package/dist/development/core/EventManager.js +12 -7
  28. package/dist/development/core/EventManager.js.map +1 -1
  29. package/dist/development/core/MutationGenerator.js +100 -94
  30. package/dist/development/core/MutationGenerator.js.map +1 -1
  31. package/dist/development/core/RequestResponseNormalizer.js +27 -31
  32. package/dist/development/core/RequestResponseNormalizer.js.map +1 -1
  33. package/dist/development/core/StateInitializer.js +23 -26
  34. package/dist/development/core/StateInitializer.js.map +1 -1
  35. package/dist/development/core/TreeAugmenter.js +10 -10
  36. package/dist/development/core/TreeAugmenter.js.map +1 -1
  37. package/dist/development/core/TreeFilterGenerator.js +2 -2
  38. package/dist/development/core/TreeFilterGenerator.js.map +1 -1
  39. package/dist/development/core/TreeStore.js +5 -5
  40. package/dist/development/core/TreeStore.js.map +1 -1
  41. package/dist/development/core/operations/EntityOperations.js +12 -11
  42. package/dist/development/core/operations/EntityOperations.js.map +1 -1
  43. package/dist/development/core/operations/FieldOperations.js +2 -2
  44. package/dist/development/core/operations/FieldOperations.js.map +1 -1
  45. package/dist/development/core/operations/ListOperations.js +3 -3
  46. package/dist/development/core/operations/ListOperations.js.map +1 -1
  47. package/dist/development/core/operations/OperationsHelpers.js +2 -2
  48. package/dist/development/core/operations/OperationsHelpers.js.map +1 -1
  49. package/dist/development/core/requestAliases/MutationAlias.js +5 -3
  50. package/dist/development/core/requestAliases/MutationAlias.js.map +1 -1
  51. package/dist/development/core/schema/SchemaPreprocessor.js +1 -1
  52. package/dist/development/core/schema/SchemaPreprocessor.js.map +1 -1
  53. package/dist/development/dao/Environment.js +12 -2
  54. package/dist/development/dao/Environment.js.map +1 -1
  55. package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -2
  56. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  57. package/dist/development/helperComponents/DeferredSubTrees.js +4 -2
  58. package/dist/development/helperComponents/DeferredSubTrees.js.map +1 -1
  59. package/dist/development/helperComponents/If.js +39 -0
  60. package/dist/development/helperComponents/If.js.map +1 -0
  61. package/dist/development/helperComponents/SugaredField.js +1 -1
  62. package/dist/development/helperComponents/helpers/FilterEvaluator.js +38 -0
  63. package/dist/development/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  64. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js +41 -0
  65. package/dist/development/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  66. package/dist/development/helperComponents/helpers/evaluateCondition.js +46 -0
  67. package/dist/development/helperComponents/helpers/evaluateCondition.js.map +1 -0
  68. package/dist/development/index.js +4 -1
  69. package/dist/development/index.js.map +1 -1
  70. package/dist/development/markers/EntityListSubTreeMarker.js +1 -1
  71. package/dist/development/markers/EntityListSubTreeMarker.js.map +1 -1
  72. package/dist/development/markers/EntitySubTreeMarker.js +1 -1
  73. package/dist/development/markers/EntitySubTreeMarker.js.map +1 -1
  74. package/dist/development/markers/PlaceholderGenerator.js +4 -4
  75. package/dist/development/markers/PlaceholderGenerator.js.map +1 -1
  76. package/dist/development/utils/Hashing.js +21 -6
  77. package/dist/development/utils/Hashing.js.map +1 -1
  78. package/dist/production/accessorPropagation/useEntityListSubTree.js +4 -2
  79. package/dist/production/accessorPropagation/useEntityListSubTree.js.map +1 -1
  80. package/dist/production/accessorPropagation/useEntitySubTree.js +4 -2
  81. package/dist/production/accessorPropagation/useEntitySubTree.js.map +1 -1
  82. package/dist/production/accessorPropagation/useExtendTree.js +27 -0
  83. package/dist/production/accessorPropagation/useExtendTree.js.map +1 -0
  84. package/dist/production/accessorTree/AccessorTree.js +9 -4
  85. package/dist/production/accessorTree/AccessorTree.js.map +1 -1
  86. package/dist/production/accessorTree/AccessorTreeStateContext.js +6 -0
  87. package/dist/production/accessorTree/AccessorTreeStateContext.js.map +1 -0
  88. package/dist/production/accessorTree/NormalizedPersistedData.js.map +1 -1
  89. package/dist/production/accessorTree/RuntimeId.js +17 -4
  90. package/dist/production/accessorTree/RuntimeId.js.map +1 -1
  91. package/dist/production/accessorTree/useAccessorTreeState.js +5 -0
  92. package/dist/production/accessorTree/useAccessorTreeState.js.map +1 -0
  93. package/dist/production/accessors/EntityAccessor.js +0 -32
  94. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  95. package/dist/production/accessors/EntityListAccessor.js +1 -1
  96. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  97. package/dist/production/core/AccessorErrorManager.js +3 -0
  98. package/dist/production/core/AccessorErrorManager.js.map +1 -1
  99. package/dist/production/core/DataBinding.js +7 -6
  100. package/dist/production/core/DataBinding.js.map +1 -1
  101. package/dist/production/core/DirtinessTracker.js +4 -13
  102. package/dist/production/core/DirtinessTracker.js.map +1 -1
  103. package/dist/production/core/ErrorsPreprocessor.js.map +1 -1
  104. package/dist/production/core/EventManager.js +11 -6
  105. package/dist/production/core/EventManager.js.map +1 -1
  106. package/dist/production/core/MutationGenerator.js +100 -94
  107. package/dist/production/core/MutationGenerator.js.map +1 -1
  108. package/dist/production/core/RequestResponseNormalizer.js +27 -31
  109. package/dist/production/core/RequestResponseNormalizer.js.map +1 -1
  110. package/dist/production/core/StateInitializer.js +23 -26
  111. package/dist/production/core/StateInitializer.js.map +1 -1
  112. package/dist/production/core/TreeAugmenter.js +10 -10
  113. package/dist/production/core/TreeAugmenter.js.map +1 -1
  114. package/dist/production/core/TreeFilterGenerator.js +2 -2
  115. package/dist/production/core/TreeFilterGenerator.js.map +1 -1
  116. package/dist/production/core/TreeStore.js +5 -5
  117. package/dist/production/core/TreeStore.js.map +1 -1
  118. package/dist/production/core/operations/EntityOperations.js +12 -11
  119. package/dist/production/core/operations/EntityOperations.js.map +1 -1
  120. package/dist/production/core/operations/FieldOperations.js.map +1 -1
  121. package/dist/production/core/operations/ListOperations.js +3 -3
  122. package/dist/production/core/operations/ListOperations.js.map +1 -1
  123. package/dist/production/core/operations/OperationsHelpers.js +2 -2
  124. package/dist/production/core/operations/OperationsHelpers.js.map +1 -1
  125. package/dist/production/core/requestAliases/MutationAlias.js +5 -3
  126. package/dist/production/core/requestAliases/MutationAlias.js.map +1 -1
  127. package/dist/production/core/schema/SchemaPreprocessor.js +1 -1
  128. package/dist/production/core/schema/SchemaPreprocessor.js.map +1 -1
  129. package/dist/production/dao/Environment.js +12 -2
  130. package/dist/production/dao/Environment.js.map +1 -1
  131. package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -2
  132. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  133. package/dist/production/helperComponents/DeferredSubTrees.js +4 -2
  134. package/dist/production/helperComponents/DeferredSubTrees.js.map +1 -1
  135. package/dist/production/helperComponents/If.js +39 -0
  136. package/dist/production/helperComponents/If.js.map +1 -0
  137. package/dist/production/helperComponents/SugaredField.js +1 -1
  138. package/dist/production/helperComponents/helpers/FilterEvaluator.js +38 -0
  139. package/dist/production/helperComponents/helpers/FilterEvaluator.js.map +1 -0
  140. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js +41 -0
  141. package/dist/production/helperComponents/helpers/FilterFieldsCollector.js.map +1 -0
  142. package/dist/production/helperComponents/helpers/evaluateCondition.js +46 -0
  143. package/dist/production/helperComponents/helpers/evaluateCondition.js.map +1 -0
  144. package/dist/production/index.js +4 -1
  145. package/dist/production/index.js.map +1 -1
  146. package/dist/production/markers/EntityListSubTreeMarker.js +1 -1
  147. package/dist/production/markers/EntityListSubTreeMarker.js.map +1 -1
  148. package/dist/production/markers/EntitySubTreeMarker.js +1 -1
  149. package/dist/production/markers/EntitySubTreeMarker.js.map +1 -1
  150. package/dist/production/markers/PlaceholderGenerator.js +4 -4
  151. package/dist/production/markers/PlaceholderGenerator.js.map +1 -1
  152. package/dist/production/utils/Hashing.js +21 -6
  153. package/dist/production/utils/Hashing.js.map +1 -1
  154. package/dist/types/accessorPropagation/index.d.ts +1 -0
  155. package/dist/types/accessorPropagation/index.d.ts.map +1 -1
  156. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
  157. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
  158. package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
  159. package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
  160. package/dist/types/accessorPropagation/useExtendTree.d.ts +5 -0
  161. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -0
  162. package/dist/types/accessorTree/AccessorTree.d.ts.map +1 -1
  163. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts +4 -0
  164. package/dist/types/accessorTree/AccessorTreeStateContext.d.ts.map +1 -0
  165. package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -1
  166. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  167. package/dist/types/accessorTree/NormalizedPersistedData.d.ts +4 -4
  168. package/dist/types/accessorTree/NormalizedPersistedData.d.ts.map +1 -1
  169. package/dist/types/accessorTree/PersistResult.d.ts +2 -1
  170. package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
  171. package/dist/types/accessorTree/QueryRequestResponse.d.ts +11 -10
  172. package/dist/types/accessorTree/QueryRequestResponse.d.ts.map +1 -1
  173. package/dist/types/accessorTree/RuntimeId.d.ts +16 -6
  174. package/dist/types/accessorTree/RuntimeId.d.ts.map +1 -1
  175. package/dist/types/accessorTree/index.d.ts +1 -0
  176. package/dist/types/accessorTree/index.d.ts.map +1 -1
  177. package/dist/types/accessorTree/useAccessorTreeState.d.ts +2 -0
  178. package/dist/types/accessorTree/useAccessorTreeState.d.ts.map +1 -0
  179. package/dist/types/accessors/EntityAccessor.d.ts +1 -3
  180. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  181. package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
  182. package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
  183. package/dist/types/core/AccessorErrorManager.d.ts.map +1 -1
  184. package/dist/types/core/DataBinding.d.ts.map +1 -1
  185. package/dist/types/core/DirtinessTracker.d.ts +2 -5
  186. package/dist/types/core/DirtinessTracker.d.ts.map +1 -1
  187. package/dist/types/core/ErrorsPreprocessor.d.ts +2 -2
  188. package/dist/types/core/ErrorsPreprocessor.d.ts.map +1 -1
  189. package/dist/types/core/EventManager.d.ts +1 -1
  190. package/dist/types/core/EventManager.d.ts.map +1 -1
  191. package/dist/types/core/MutationGenerator.d.ts.map +1 -1
  192. package/dist/types/core/RequestResponseNormalizer.d.ts.map +1 -1
  193. package/dist/types/core/StateInitializer.d.ts +1 -5
  194. package/dist/types/core/StateInitializer.d.ts.map +1 -1
  195. package/dist/types/core/TreeStore.d.ts +3 -3
  196. package/dist/types/core/TreeStore.d.ts.map +1 -1
  197. package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
  198. package/dist/types/core/operations/ListOperations.d.ts +2 -1
  199. package/dist/types/core/operations/ListOperations.d.ts.map +1 -1
  200. package/dist/types/core/requestAliases/MutationAlias.d.ts.map +1 -1
  201. package/dist/types/core/schema/RawSchemaEntity.d.ts +3 -2
  202. package/dist/types/core/schema/RawSchemaEntity.d.ts.map +1 -1
  203. package/dist/types/core/schema/SchemaEntity.d.ts +1 -1
  204. package/dist/types/core/schema/SchemaEntity.d.ts.map +1 -1
  205. package/dist/types/dao/Environment.d.ts +7 -5
  206. package/dist/types/dao/Environment.d.ts.map +1 -1
  207. package/dist/types/helperComponents/If.d.ts +14 -0
  208. package/dist/types/helperComponents/If.d.ts.map +1 -0
  209. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts +9 -0
  210. package/dist/types/helperComponents/helpers/FilterEvaluator.d.ts.map +1 -0
  211. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts +10 -0
  212. package/dist/types/helperComponents/helpers/FilterFieldsCollector.d.ts.map +1 -0
  213. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts +4 -0
  214. package/dist/types/helperComponents/helpers/evaluateCondition.d.ts.map +1 -0
  215. package/dist/types/helperComponents/index.d.ts +1 -0
  216. package/dist/types/helperComponents/index.d.ts.map +1 -1
  217. package/dist/types/markers/PlaceholderGenerator.d.ts +3 -2
  218. package/dist/types/markers/PlaceholderGenerator.d.ts.map +1 -1
  219. package/dist/types/treeParameters/primitives/EntityId.d.ts +1 -1
  220. package/dist/types/treeParameters/primitives/EntityId.d.ts.map +1 -1
  221. package/dist/types/tsconfig.tsbuildinfo +1 -1
  222. package/dist/types/utils/Hashing.d.ts +3 -2
  223. package/dist/types/utils/Hashing.d.ts.map +1 -1
  224. package/package.json +7 -5
  225. package/src/accessorPropagation/index.ts +1 -0
  226. package/src/accessorPropagation/useEntityListSubTree.ts +8 -1
  227. package/src/accessorPropagation/useEntitySubTree.ts +8 -1
  228. package/src/accessorPropagation/useExtendTree.ts +30 -0
  229. package/src/accessorTree/AccessorTree.tsx +18 -12
  230. package/src/accessorTree/AccessorTreeStateContext.ts +6 -0
  231. package/src/accessorTree/MutationRequestResponse.ts +3 -1
  232. package/src/accessorTree/NormalizedPersistedData.ts +4 -4
  233. package/src/accessorTree/PersistResult.ts +2 -1
  234. package/src/accessorTree/QueryRequestResponse.ts +17 -14
  235. package/src/accessorTree/RuntimeId.ts +27 -6
  236. package/src/accessorTree/index.ts +1 -0
  237. package/src/accessorTree/useAccessorTreeState.ts +4 -0
  238. package/src/accessors/EntityAccessor.ts +2 -51
  239. package/src/accessors/EntityListAccessor.ts +3 -3
  240. package/src/core/AccessorErrorManager.ts +3 -0
  241. package/src/core/DataBinding.ts +6 -7
  242. package/src/core/DirtinessTracker.ts +4 -16
  243. package/src/core/ErrorsPreprocessor.ts +2 -2
  244. package/src/core/EventManager.ts +14 -8
  245. package/src/core/MutationGenerator.ts +137 -130
  246. package/src/core/RequestResponseNormalizer.ts +37 -38
  247. package/src/core/StateInitializer.ts +35 -42
  248. package/src/core/TreeAugmenter.ts +11 -11
  249. package/src/core/TreeFilterGenerator.ts +5 -5
  250. package/src/core/TreeStore.ts +14 -6
  251. package/src/core/operations/EntityOperations.ts +12 -13
  252. package/src/core/operations/FieldOperations.ts +2 -2
  253. package/src/core/operations/ListOperations.ts +6 -5
  254. package/src/core/operations/OperationsHelpers.ts +2 -2
  255. package/src/core/requestAliases/MutationAlias.ts +5 -3
  256. package/src/core/schema/RawSchemaEntity.ts +1 -2
  257. package/src/core/schema/SchemaEntity.ts +1 -1
  258. package/src/core/schema/SchemaPreprocessor.ts +1 -1
  259. package/src/dao/Environment.ts +18 -7
  260. package/src/dao/TreeNodeEnvironmentFactory.ts +2 -2
  261. package/src/helperComponents/DeferredSubTrees.tsx +4 -4
  262. package/src/helperComponents/If.tsx +71 -0
  263. package/src/helperComponents/helpers/FilterEvaluator.ts +48 -0
  264. package/src/helperComponents/helpers/FilterFieldsCollector.ts +49 -0
  265. package/src/helperComponents/helpers/evaluateCondition.ts +52 -0
  266. package/src/helperComponents/index.ts +1 -0
  267. package/src/markers/EntityListSubTreeMarker.ts +1 -1
  268. package/src/markers/EntitySubTreeMarker.ts +1 -1
  269. package/src/markers/PlaceholderGenerator.ts +5 -2
  270. package/src/treeParameters/primitives/EntityId.ts +1 -1
  271. package/src/utils/Hashing.ts +23 -8
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/binding",
3
3
  "license": "Apache-2.0",
4
- "version": "1.1.0-alpha.0",
4
+ "version": "1.1.0-alpha.3",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/production/index.js",
@@ -19,10 +19,10 @@
19
19
  ],
20
20
  "typings": "./dist/types/index.d.ts",
21
21
  "dependencies": {
22
- "@contember/client": "1.1.0-alpha.0",
23
- "@contember/react-client": "1.1.0-alpha.0",
24
- "@contember/react-multipass-rendering": "1.1.0-alpha.0",
25
- "@contember/react-utils": "1.1.0-alpha.0",
22
+ "@contember/client": "1.1.0-alpha.3",
23
+ "@contember/react-client": "1.1.0-alpha.3",
24
+ "@contember/react-multipass-rendering": "1.1.0-alpha.3",
25
+ "@contember/react-utils": "1.1.0-alpha.3",
26
26
  "chevrotain": "6.5.0",
27
27
  "fast-deep-equal": "^3.1.3",
28
28
  "js-levenshtein": "1.1.6",
@@ -42,6 +42,8 @@
42
42
  "build": "pnpm run build:js:dev && pnpm run build:js:prod",
43
43
  "build:js:dev": "vite build --mode development",
44
44
  "build:js:prod": "vite build --mode production",
45
+ "ae:build": "api-extractor run --local",
46
+ "ae:test": "api-extractor run",
45
47
  "test": "vitest"
46
48
  }
47
49
  }
@@ -20,6 +20,7 @@ export * from './useEntityListSubTreeParameters'
20
20
  export * from './useEntitySubTree'
21
21
  export * from './useEntitySubTreeParameters'
22
22
  export * from './useEnvironment'
23
+ export * from './useExtendTree'
23
24
  export * from './useField'
24
25
  export * from './useGetEntityByKey'
25
26
  export * from './useGetEntityListSubTree'
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEn
4
4
  import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
5
5
  import { useEntityListSubTreeParameters } from './useEntityListSubTreeParameters'
6
6
  import { useGetEntityListSubTree } from './useGetEntityListSubTree'
7
+ import { TreeRootId } from '../treeParameters'
7
8
 
8
9
  export const useEntityListSubTree = (
9
10
  qualifiedEntityList: Alias | SugaredQualifiedEntityList | SugaredUnconstrainedQualifiedEntityList,
11
+ ...treeId: [TreeRootId | undefined] | []
10
12
  ): EntityListAccessor => {
11
13
  const getSubTree = useGetEntityListSubTree()
12
14
  const parameters = useEntityListSubTreeParameters(qualifiedEntityList)
13
- const getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters])
15
+ const hasTreeId = treeId.length > 0
16
+ const treeIdVal = treeId[0]
17
+ const getAccessor = useCallback(
18
+ () => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
19
+ [getSubTree, hasTreeId, parameters, treeIdVal],
20
+ )
14
21
 
15
22
  // if (typeof parameters !== 'string' && parameters.value.hasOneRelationPath.length) {
16
23
  // throw new BindingError(`useEntityListSubTree: cannot use hasOneRelationPath!`)
@@ -4,13 +4,20 @@ import type { Alias, SugaredQualifiedSingleEntity, SugaredUnconstrainedQualified
4
4
  import { useAccessorUpdateSubscription } from './useAccessorUpdateSubscription'
5
5
  import { useEntitySubTreeParameters } from './useEntitySubTreeParameters'
6
6
  import { useGetEntitySubTree } from './useGetEntitySubTree'
7
+ import { TreeRootId } from '../treeParameters'
7
8
 
8
9
  export const useEntitySubTree = (
9
10
  qualifiedSingleEntity: Alias | SugaredQualifiedSingleEntity | SugaredUnconstrainedQualifiedSingleEntity,
11
+ ...treeId: [TreeRootId | undefined] | []
10
12
  ): EntityAccessor => {
11
13
  const getSubTree = useGetEntitySubTree()
12
14
  const parameters = useEntitySubTreeParameters(qualifiedSingleEntity)
13
- const getAccessor = useCallback(() => getSubTree(parameters), [getSubTree, parameters])
15
+ const hasTreeId = treeId.length > 0
16
+ const treeIdVal = treeId[0]
17
+ const getAccessor = useCallback(
18
+ () => getSubTree(parameters, ...(hasTreeId ? [treeIdVal] : [])),
19
+ [getSubTree, hasTreeId, parameters, treeIdVal],
20
+ )
14
21
 
15
22
  // if (typeof parameters !== 'string' && parameters.hasOneRelationPath.length) {
16
23
  // throw new BindingError(`useEntitySubTree: cannot use hasOneRelationPath!`)
@@ -0,0 +1,30 @@
1
+ import { ReactNode, useCallback } from 'react'
2
+ import { useAbortController, useIsMounted } from '@contember/react-utils'
3
+ import { useBindingOperations } from './useBindingOperations'
4
+ import { TreeRootId } from '../treeParameters'
5
+ import { ExtendTreeOptions } from '../accessors'
6
+ import { DataBindingExtendAborted } from '../core'
7
+ import { useEnvironment } from './useEnvironment'
8
+
9
+ export const useExtendTree = () => {
10
+ const abort = useAbortController()
11
+ const { extendTree } = useBindingOperations()
12
+ const isMountedRef = useIsMounted()
13
+ const environment = useEnvironment()
14
+ return useCallback(async (newFragment: ReactNode, options?: Omit<ExtendTreeOptions, 'signal'>): Promise<TreeRootId | undefined> => {
15
+ try {
16
+ const newTreeRootId = await extendTree(newFragment,
17
+ { environment, ...options, signal: abort() },
18
+ )
19
+ if (!isMountedRef.current) {
20
+ return
21
+ }
22
+ return newTreeRootId
23
+ } catch (e) {
24
+ if (e === DataBindingExtendAborted) {
25
+ return
26
+ }
27
+ throw e
28
+ }
29
+ }, [abort, environment, extendTree, isMountedRef])
30
+ }
@@ -1,6 +1,7 @@
1
1
  import type { ReactNode } from 'react'
2
2
  import { BindingOperationsProvider } from '../accessorPropagation'
3
3
  import type { AccessorTreeState } from './AccessorTreeState'
4
+ import { AccessorTreeStateContext } from './AccessorTreeStateContext'
4
5
  import { DirtinessContext } from './DirtinessContext'
5
6
  import { MutationStateContext } from './MutationStateContext'
6
7
 
@@ -14,21 +15,26 @@ export function AccessorTree({ state, children }: AccessorTreeProps) {
14
15
  // remounts.
15
16
  if (state.name === 'initialized') {
16
17
  return (
17
- <DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>
18
- <MutationStateContext.Provider value={state.data.isMutating}>
19
- <BindingOperationsProvider bindingOperations={state.data.bindingOperations}>
20
- {children}
21
- </BindingOperationsProvider>
22
- </MutationStateContext.Provider>
23
- </DirtinessContext.Provider>
18
+ <AccessorTreeStateContext.Provider value={state}>
19
+ <DirtinessContext.Provider value={state.data.hasUnpersistedChanges}>
20
+ <MutationStateContext.Provider value={state.data.isMutating}>
21
+ <BindingOperationsProvider bindingOperations={state.data.bindingOperations}>
22
+ {children}
23
+ </BindingOperationsProvider>
24
+ </MutationStateContext.Provider>
25
+ </DirtinessContext.Provider>
26
+ </AccessorTreeStateContext.Provider>
24
27
  )
25
28
  }
26
29
  return (
27
- <DirtinessContext.Provider value={false}>
28
- <MutationStateContext.Provider value={false}>
29
- <BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>
30
- </MutationStateContext.Provider>
31
- </DirtinessContext.Provider>
30
+ <AccessorTreeStateContext.Provider value={state}>
31
+ <DirtinessContext.Provider value={false}>
32
+ <MutationStateContext.Provider value={false}>
33
+ <BindingOperationsProvider bindingOperations={undefined}>{children}</BindingOperationsProvider>
34
+ </MutationStateContext.Provider>
35
+ </DirtinessContext.Provider>
36
+ </AccessorTreeStateContext.Provider>
32
37
  )
33
38
  }
39
+
34
40
  AccessorTree.displayName = 'AccessorTree'
@@ -0,0 +1,6 @@
1
+ import { createContext } from 'react'
2
+ import { AccessorTreeState } from './AccessorTreeState'
3
+
4
+ export const AccessorTreeStateContext = createContext<AccessorTreeState>({
5
+ name: 'initializing',
6
+ })
@@ -1,6 +1,8 @@
1
1
  import type { Result } from '@contember/client'
2
2
  import type { ReceivedEntityData } from './QueryRequestResponse'
3
3
 
4
+ type WithType<V, Type extends string> = V & { __typename: Type }
5
+
4
6
  export interface FieldPathErrorFragment {
5
7
  __typename: '_FieldPathFragment'
6
8
  field: string
@@ -47,7 +49,7 @@ export interface MutationDataResponse {
47
49
  }
48
50
 
49
51
  export interface MutationTransactionResponse {
50
- transaction: MutationDataResponse | null
52
+ transaction: WithType<MutationDataResponse, 'MutationTransaction'> | null
51
53
  }
52
54
 
53
55
  export interface MutationRequestResponse {
@@ -1,19 +1,19 @@
1
1
  import type { EntityId, PlaceholderName, Scalar } from '../treeParameters'
2
- import type { ServerGeneratedUuid } from './RuntimeId'
2
+ import type { ServerId, UniqueEntityId } from './RuntimeId'
3
3
 
4
4
  // HasMany relations are encoded as sets of entity ids.
5
5
  // HasOne relations are encoded as BoxedSingleEntityId just to make them different from actual strings.
6
6
  // Not sure whether that is a reasonable precaution or just pure overhead.
7
- export type EntityFieldPersistedData = Scalar | ServerGeneratedUuid | EntityListPersistedData
7
+ export type EntityFieldPersistedData = Scalar | ServerId | EntityListPersistedData
8
8
 
9
9
  export type SingleEntityPersistedData = Map<PlaceholderName, EntityFieldPersistedData>
10
10
 
11
11
  export type EntityListPersistedData = Set<EntityId>
12
12
 
13
- export type PersistedEntityDataStore = Map<EntityId, SingleEntityPersistedData>
13
+ export type PersistedEntityDataStore = Map<UniqueEntityId, SingleEntityPersistedData>
14
14
 
15
15
  // The key is the subTree placeholder name
16
- export type SubTreeDataStore = Map<PlaceholderName, ServerGeneratedUuid | EntityListPersistedData>
16
+ export type SubTreeDataStore = Map<PlaceholderName, ServerId | EntityListPersistedData>
17
17
 
18
18
  export class NormalizedPersistedData {
19
19
  public constructor(
@@ -1,5 +1,6 @@
1
1
  import type { RequestError } from './RequestError'
2
2
  import { ErrorAccessor } from '../accessors'
3
+ import { EntityId } from '../treeParameters'
3
4
 
4
5
  export interface NothingToPersistPersistResult {
5
6
  type: 'nothingToPersist'
@@ -7,7 +8,7 @@ export interface NothingToPersistPersistResult {
7
8
 
8
9
  export interface JustSuccessPersistResult {
9
10
  type: 'justSuccess'
10
- persistedEntityIds: string[]
11
+ persistedEntityIds: EntityId[]
11
12
  afterPersistError?: any
12
13
  }
13
14
 
@@ -1,20 +1,23 @@
1
- import type { Scalar } from '../treeParameters'
1
+ import type { EntityId, Scalar } from '../treeParameters'
2
2
 
3
- export type ReceivedFieldData<A = never> = Scalar | ReceivedEntityData<A> | Array<ReceivedEntityData<A> | A>
4
- export type ReceivedEntityData<A = never> =
5
- | A
6
- | {
7
- id: string
8
- __typename: string
9
- [fieldName: string]: ReceivedFieldData<A>
10
- }
11
- export type ReceivedData<A = never> = A | ReceivedEntityData<A> | ReceivedEntityData<A>[]
3
+ export type ReceivedFieldData = Scalar | ReceivedEntityData | Array<ReceivedEntityData>
12
4
 
13
- export interface ReceivedDataTree<A = never> {
14
- [treeId: string]: ReceivedData<A> | null
5
+ export type ReceivedEntityData =
6
+ & {
7
+ __typename: string
8
+ id: EntityId
9
+ }
10
+ & {
11
+ [fieldName: string]: ReceivedFieldData
12
+ }
13
+
14
+ export type ReceivedData = ReceivedEntityData | ReceivedEntityData[]
15
+
16
+ export interface ReceivedDataTree {
17
+ [treeId: string]: ReceivedData | null
15
18
  }
16
19
 
17
- export interface QueryRequestResponse<A = never> {
18
- data: ReceivedDataTree<A>
20
+ export interface QueryRequestResponse {
21
+ data: ReceivedDataTree
19
22
  errors?: { message: string, path?: string[] }[]
20
23
  }
@@ -1,15 +1,28 @@
1
1
  import { generateEnumerabilityPreventingEntropy } from '../utils'
2
+ import { EntityId } from '../treeParameters'
3
+
4
+ export type UniqueEntityId = string & { __type: 'UniqueEntityId' }
2
5
 
3
6
  export interface RuntimeIdSpec {
4
7
  existsOnServer: boolean
5
- value: string
8
+ value: EntityId
9
+ uniqueValue: UniqueEntityId
6
10
  }
7
11
 
8
- export class ServerGeneratedUuid implements RuntimeIdSpec {
12
+ export class ServerId implements RuntimeIdSpec {
9
13
  public get existsOnServer(): true {
10
14
  return true
11
15
  }
12
- public constructor(public readonly value: string) {}
16
+ public constructor(public readonly value: EntityId, public readonly entityName: string) {
17
+ }
18
+
19
+ get uniqueValue() {
20
+ return ServerId.formatUniqueValue(this.value, this.entityName)
21
+ }
22
+
23
+ static formatUniqueValue(id: EntityId, entityName: string): UniqueEntityId {
24
+ return `${entityName}_${id}` as UniqueEntityId
25
+ }
13
26
  }
14
27
 
15
28
  export class ClientGeneratedUuid implements RuntimeIdSpec {
@@ -17,6 +30,10 @@ export class ClientGeneratedUuid implements RuntimeIdSpec {
17
30
  return false
18
31
  }
19
32
  public constructor(public readonly value: string) {}
33
+
34
+ get uniqueValue() {
35
+ return this.value as UniqueEntityId
36
+ }
20
37
  }
21
38
 
22
39
  export class UnpersistedEntityDummyId implements RuntimeIdSpec {
@@ -41,9 +58,13 @@ export class UnpersistedEntityDummyId implements RuntimeIdSpec {
41
58
 
42
59
  private static entropyLength = 5
43
60
  private static dummyIdRegex = new RegExp(`^adminOnlyDummyId-\\d{${UnpersistedEntityDummyId.entropyLength}}-\\d+$`)
44
- public static matchesDummyId(candidate: string): boolean {
45
- return UnpersistedEntityDummyId.dummyIdRegex.test(candidate)
61
+ public static matchesDummyId(candidate: EntityId): boolean {
62
+ return typeof candidate === 'string' && UnpersistedEntityDummyId.dummyIdRegex.test(candidate)
63
+ }
64
+
65
+ get uniqueValue() {
66
+ return this.value as UniqueEntityId
46
67
  }
47
68
  }
48
69
 
49
- export type RuntimeId = ServerGeneratedUuid | ClientGeneratedUuid | UnpersistedEntityDummyId
70
+ export type RuntimeId = ServerId | ClientGeneratedUuid | UnpersistedEntityDummyId
@@ -13,6 +13,7 @@ export * from './PersistResult'
13
13
  export * from './QueryRequestResponse'
14
14
  export * from './RequestError'
15
15
  export * from './RuntimeId'
16
+ export * from './useAccessorTreeState'
16
17
  export * from './useDataBinding'
17
18
  export * from './useDirtinessState'
18
19
  export * from './useMutationState'
@@ -0,0 +1,4 @@
1
+ import { useContext } from 'react'
2
+ import { AccessorTreeStateContext } from './AccessorTreeStateContext'
3
+
4
+ export const useAccessorTreeState = () => useContext(AccessorTreeStateContext)
@@ -1,4 +1,4 @@
1
- import { RuntimeId, ServerGeneratedUuid, SingleEntityPersistedData } from '../accessorTree'
1
+ import { RuntimeId, SingleEntityPersistedData } from '../accessorTree'
2
2
  import { BindingError } from '../BindingError'
3
3
  import type { EntityOperations } from '../core/operations'
4
4
  import type { Environment } from '../dao'
@@ -42,7 +42,7 @@ class EntityAccessor implements Errorable {
42
42
  public readonly getAccessor: EntityAccessor.GetEntityAccessor,
43
43
  ) {}
44
44
 
45
- public get idOnServer(): string | undefined {
45
+ public get idOnServer(): EntityId | undefined {
46
46
  return this.runtimeId.existsOnServer ? this.runtimeId.value : undefined
47
47
  }
48
48
 
@@ -116,21 +116,6 @@ class EntityAccessor implements Errorable {
116
116
  return this.getRelativeEntityList(QueryLanguage.desugarRelativeEntityList(entityList, this.environment))
117
117
  }
118
118
 
119
- public getKeyConnectedOnServer(entity: SugaredRelativeSingleEntity | string): string | null {
120
- const desugared = QueryLanguage.desugarRelativeSingleEntity(entity, this.environment)
121
- const lastHasOne = desugared.hasOneRelationPath[desugared.hasOneRelationPath.length - 1]
122
- const lastHasOnePlaceholder = PlaceholderGenerator.getHasOneRelationPlaceholder(lastHasOne)
123
-
124
- let containingAccessor: EntityAccessor = this
125
-
126
- if (desugared.hasOneRelationPath.length > 1) {
127
- containingAccessor = this.getRelativeSingleEntity({
128
- hasOneRelationPath: desugared.hasOneRelationPath.slice(0, -1),
129
- })
130
- }
131
- return containingAccessor.getPersistedKeyByPlaceholder(lastHasOnePlaceholder)
132
- }
133
-
134
119
  //
135
120
 
136
121
  /**
@@ -173,40 +158,6 @@ class EntityAccessor implements Errorable {
173
158
  }
174
159
  return record.getAccessor()
175
160
  }
176
-
177
- private getPersistedKeyByPlaceholder(placeholderName: string): string | null {
178
- if (this.dataFromServer === undefined) {
179
- return null
180
- }
181
- const key = this.dataFromServer.get(placeholderName)
182
-
183
- if (key instanceof ServerGeneratedUuid) {
184
- return key.value
185
- }
186
- if (key === null) {
187
- // TODO this also returns null and fails to throw when placeholderName points to a regular scalar field that
188
- // happens to be also null.
189
- return null
190
- }
191
-
192
- // From now on, we're past the happy path, way into error land.
193
- if (key === undefined) {
194
- throw new BindingError(
195
- `EntityAccessor.getKeyConnectedOnServer: unknown placeholder '${placeholderName}'. Unless this is just ` +
196
- `a typo, this typically happens when a has-one relation hasn't been registered during static render.`,
197
- )
198
- }
199
- if (key instanceof Set) {
200
- throw new BindingError(
201
- `EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a has-many relation, ` +
202
- `not a has-one. This method is meant exclusively for has-one relations.`,
203
- )
204
- }
205
- throw new BindingError(
206
- `EntityAccessor.getKeyConnectedOnServer: the placeholder '${placeholderName}' refers to a scalar field, not a` +
207
- `has-one relation. This method is meant exclusively for has-one relations.`,
208
- )
209
- }
210
161
  }
211
162
 
212
163
  namespace EntityAccessor {
@@ -16,7 +16,7 @@ class EntityListAccessor implements Errorable {
16
16
  private readonly stateKey: EntityListState,
17
17
  private readonly operations: ListOperations,
18
18
  private readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,
19
- private readonly _idsPersistedOnServer: ReadonlySet<string>,
19
+ private readonly _idsPersistedOnServer: ReadonlySet<EntityId>,
20
20
  public readonly hasUnpersistedChanges: boolean,
21
21
  public readonly errors: ErrorAccessor | undefined,
22
22
  public readonly environment: Environment,
@@ -42,7 +42,7 @@ class EntityListAccessor implements Errorable {
42
42
  * This will only contain the ids that the server knows about. Not necessarily the ids that have been added on
43
43
  * the list since the last server query.
44
44
  */
45
- public get idsPersistedOnServer(): Set<string> {
45
+ public get idsPersistedOnServer(): Set<EntityId> {
46
46
  return new Set(this._idsPersistedOnServer)
47
47
  }
48
48
 
@@ -65,7 +65,7 @@ class EntityListAccessor implements Errorable {
65
65
  }
66
66
 
67
67
  public hasEntityOnServer(entityOrItsId: EntityAccessor | EntityId): boolean {
68
- if (typeof entityOrItsId === 'string') {
68
+ if (typeof entityOrItsId === 'string' || typeof entityOrItsId === 'number') {
69
69
  return this.idsPersistedOnServer.has(entityOrItsId)
70
70
  }
71
71
  const idOnServer = entityOrItsId.idOnServer
@@ -134,6 +134,9 @@ export class AccessorErrorManager {
134
134
  }
135
135
 
136
136
  for (const [childKey, child] of errors.children) {
137
+ if (typeof childKey !== 'string') {
138
+ continue
139
+ }
137
140
  if (child.nodeType === 'leaf') {
138
141
  const fieldState = state.children.get(childKey)
139
142
 
@@ -89,7 +89,6 @@ export class DataBinding {
89
89
  this.stateInitializer = new StateInitializer(
90
90
  this.accessorErrorManager,
91
91
  this.batchUpdatesOptions,
92
- this.config,
93
92
  this.eventManager,
94
93
  this.treeStore,
95
94
  )
@@ -171,15 +170,15 @@ export class DataBinding {
171
170
  errors: mutationResponse.errors,
172
171
  })
173
172
  }
174
-
175
- const mutationData = mutationResponse.data?.transaction ?? {}
176
- const aliases = Object.keys(mutationData)
177
- if (!mutationResponse.data) {
173
+ if (!mutationResponse.data?.transaction) {
178
174
  throw {
179
- errors: mutationData.errors,
175
+ errors: [],
180
176
  type: 'invalidResponse',
181
177
  }
182
- } else if (aliases.every(item => mutationData[item].ok)) {
178
+ }
179
+ const { __typename, ...mutationData } = mutationResponse.data.transaction
180
+ const aliases = Object.keys(mutationData)
181
+ if (aliases.every(item => mutationData[item].ok)) {
183
182
  const persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)
184
183
  const result: SuccessfulPersistResult = {
185
184
  type: 'justSuccess',
@@ -1,13 +1,9 @@
1
1
  export class DirtinessTracker {
2
2
  private changesCount = 0
3
- private totalChangesCount = 0
3
+ private touchedCount = 0
4
4
 
5
- public getChangesCount() {
6
- return this.changesCount
7
- }
8
-
9
- public getTotalChangesCount() {
10
- return this.totalChangesCount
5
+ public getTotalTouchCount() {
6
+ return this.touchedCount
11
7
  }
12
8
 
13
9
  public hasChanges() {
@@ -18,16 +14,8 @@ export class DirtinessTracker {
18
14
  this.changesCount = 0
19
15
  }
20
16
 
21
- public increment() {
22
- this.totalChangesCount++
23
- this.changesCount++
24
- }
25
-
26
- public decrement() {
27
- this.changesCount--
28
- }
29
-
30
17
  public increaseBy(delta: number) {
31
18
  this.changesCount += delta
19
+ this.touchedCount++
32
20
  }
33
21
  }
@@ -1,6 +1,6 @@
1
1
  import type { ErrorAccessor } from '../accessors'
2
2
  import type { ExecutionError, MutationDataResponse, MutationResponse, ValidationError } from '../accessorTree'
3
- import type { PlaceholderName } from '../treeParameters'
3
+ import type { EntityId, FieldName, PlaceholderName } from '../treeParameters'
4
4
  import { assertNever } from '../utils'
5
5
  import { MutationAlias, mutationOperationSubTreeType } from './requestAliases'
6
6
 
@@ -227,7 +227,7 @@ namespace ErrorsPreprocessor {
227
227
 
228
228
  export interface ErrorINode extends BaseErrorNode {
229
229
  nodeType: 'iNode'
230
- children: Map<string, ErrorNode>
230
+ children: Map<FieldName | EntityId, ErrorNode>
231
231
  }
232
232
 
233
233
  export type ErrorNode = ErrorINode | LeafErrorNode
@@ -346,9 +346,12 @@ export class EventManager {
346
346
 
347
347
  for (const [state, callback] of callbackQueue) {
348
348
  correspondingStates.push(state)
349
+ const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
350
+ let validateChanges = false
349
351
  try {
350
352
  const result = callback(state.getAccessor as any, options as any) // TS can't quite handle this but this is sound.
351
353
  if (result instanceof Promise) {
354
+ validateChanges = true
352
355
  promiseReturns.push(result)
353
356
  } else {
354
357
  promiseReturns.push(Promise.resolve(result))
@@ -356,10 +359,15 @@ export class EventManager {
356
359
  } catch (e) {
357
360
  promiseReturns.push(Promise.reject(e))
358
361
  }
362
+ if (validateChanges) {
363
+ this.validateWithoutChanges(changesCountBefore, eventType)
364
+ }
359
365
  }
360
366
  // TODO timeout
361
367
 
362
- const newCallbacks = await this.executeWithoutChanges(eventType, () => Promise.allSettled(promiseReturns))
368
+ const changesCountBefore = this.dirtinessTracker.getTotalTouchCount()
369
+ const newCallbacks = await Promise.allSettled(promiseReturns)
370
+ this.validateWithoutChanges(changesCountBefore, eventType)
363
371
 
364
372
  callbackQueue.length = 0 // Empties the queue
365
373
 
@@ -561,20 +569,18 @@ export class EventManager {
561
569
  }
562
570
  }
563
571
 
564
- private async executeWithoutChanges<T>(eventType: string, cb: () => Promise<T>): Promise<T> {
565
- const changesCountBefore = this.dirtinessTracker.getTotalChangesCount()
566
- const result = await cb()
567
- const changesCountAfter = this.dirtinessTracker.getTotalChangesCount()
572
+
573
+ private validateWithoutChanges(initialCount: number, eventType: string): void {
574
+ const changesCountAfter = this.dirtinessTracker.getTotalTouchCount()
568
575
  if (import.meta.env.DEV) {
569
- if (changesCountBefore !== changesCountAfter) {
576
+ if (initialCount !== changesCountAfter) {
570
577
  // This isn't bulletproof. They could e.g. undo a change and make another one which would
571
578
  // slip through this detection. But for most cases, it should be good enough and not too expensive.
572
579
  throw new BindingError(
573
580
  `A ${eventType} event handler cannot be asynchronous and alter the accessor tree at the same time. ` +
574
- `To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,
581
+ `To achieve this, prepare your data asynchronously but only touch the tree from a returned callback.`,
575
582
  )
576
583
  }
577
584
  }
578
- return result
579
585
  }
580
586
  }