@contember/binding 1.1.0-alpha.10 → 1.1.0-alpha.13

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 (63) hide show
  1. package/dist/development/accessors/EntityAccessor.js +19 -8
  2. package/dist/development/accessors/EntityAccessor.js.map +1 -1
  3. package/dist/development/accessors/EntityListAccessor.js +10 -10
  4. package/dist/development/accessors/EntityListAccessor.js.map +1 -1
  5. package/dist/development/accessors/FieldAccessor.js +6 -6
  6. package/dist/development/accessors/FieldAccessor.js.map +1 -1
  7. package/dist/development/core/DataBinding.js +5 -2
  8. package/dist/development/core/DataBinding.js.map +1 -1
  9. package/dist/development/core/EventManager.js +1 -1
  10. package/dist/development/core/factories/createBatchUpdatesOptions.js.map +1 -1
  11. package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
  12. package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -3
  13. package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  14. package/dist/production/accessors/EntityAccessor.js +19 -8
  15. package/dist/production/accessors/EntityAccessor.js.map +1 -1
  16. package/dist/production/accessors/EntityListAccessor.js +10 -10
  17. package/dist/production/accessors/EntityListAccessor.js.map +1 -1
  18. package/dist/production/accessors/FieldAccessor.js +6 -6
  19. package/dist/production/accessors/FieldAccessor.js.map +1 -1
  20. package/dist/production/core/DataBinding.js +5 -2
  21. package/dist/production/core/DataBinding.js.map +1 -1
  22. package/dist/production/core/EventManager.js +1 -1
  23. package/dist/production/core/factories/createBatchUpdatesOptions.js.map +1 -1
  24. package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
  25. package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -3
  26. package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
  27. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts +2 -1
  28. package/dist/types/accessorPropagation/useEntityListSubTree.d.ts.map +1 -1
  29. package/dist/types/accessorPropagation/useEntitySubTree.d.ts +2 -1
  30. package/dist/types/accessorPropagation/useEntitySubTree.d.ts.map +1 -1
  31. package/dist/types/accessorPropagation/useExtendTree.d.ts +1 -1
  32. package/dist/types/accessorPropagation/useExtendTree.d.ts.map +1 -1
  33. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +2 -1
  34. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -1
  35. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +2 -1
  36. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -1
  37. package/dist/types/accessorSorting/addEntityAtIndex.d.ts +1 -1
  38. package/dist/types/accessorSorting/addEntityAtIndex.d.ts.map +1 -1
  39. package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -5
  40. package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
  41. package/dist/types/accessors/EntityAccessor.d.ts +4 -2
  42. package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
  43. package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
  44. package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
  45. package/dist/types/accessors/FieldAccessor.d.ts +2 -2
  46. package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
  47. package/dist/types/core/DataBinding.d.ts.map +1 -1
  48. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  49. package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
  50. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts +1 -1
  51. package/dist/types/fieldHelpers/helpers/TemporalFieldHelper.d.ts.map +1 -1
  52. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts +1 -1
  53. package/dist/types/fieldHelpers/helpers/UuidFieldHelper.d.ts.map +1 -1
  54. package/dist/types/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +5 -5
  56. package/src/accessorTree/MutationRequestResponse.ts +9 -3
  57. package/src/accessors/EntityAccessor.ts +20 -7
  58. package/src/accessors/EntityListAccessor.ts +9 -9
  59. package/src/accessors/FieldAccessor.ts +5 -5
  60. package/src/core/DataBinding.ts +5 -2
  61. package/src/core/factories/createBatchUpdatesOptions.ts +1 -1
  62. package/src/coreComponents/EntityListSubTree.tsx +2 -3
  63. package/src/dao/TreeNodeEnvironmentFactory.ts +2 -3
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.10",
4
+ "version": "1.1.0-alpha.13",
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.10",
23
- "@contember/react-client": "1.1.0-alpha.10",
24
- "@contember/react-multipass-rendering": "1.1.0-alpha.10",
25
- "@contember/react-utils": "1.1.0-alpha.10",
22
+ "@contember/client": "1.1.0-alpha.13",
23
+ "@contember/react-client": "1.1.0-alpha.13",
24
+ "@contember/react-multipass-rendering": "1.1.0-alpha.13",
25
+ "@contember/react-utils": "1.1.0-alpha.13",
26
26
  "chevrotain": "6.5.0",
27
27
  "fast-deep-equal": "^3.1.3",
28
28
  "js-levenshtein": "1.1.6",
@@ -1,8 +1,6 @@
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
-
6
4
  export interface FieldPathErrorFragment {
7
5
  __typename: '_FieldPathFragment'
8
6
  field: string
@@ -48,8 +46,16 @@ export interface MutationDataResponse {
48
46
  [alias: string]: MutationResponse
49
47
  }
50
48
 
49
+
51
50
  export interface MutationTransactionResponse {
52
- transaction: WithType<MutationDataResponse, 'MutationTransaction'> | null
51
+ transaction: (
52
+ & MutationDataResponse
53
+ & {
54
+ __type: 'MutationTransaction'
55
+ ok: boolean
56
+ errorMessage: string | null
57
+ }
58
+ )
53
59
  }
54
60
 
55
61
  export interface MutationRequestResponse {
@@ -26,10 +26,11 @@ import type { FieldAccessor } from './FieldAccessor'
26
26
  import type { PersistErrorOptions } from './PersistErrorOptions'
27
27
  import type { PersistSuccessOptions } from './PersistSuccessOptions'
28
28
  import type { EntityRealmState } from '../core/state'
29
+ import { getEntityMarker } from '../core/state'
29
30
 
30
31
  class EntityAccessor implements Errorable {
31
32
  public constructor(
32
- private readonly stateKey: EntityRealmState,
33
+ private readonly state: EntityRealmState,
33
34
  private readonly operations: EntityOperations,
34
35
  private readonly runtimeId: RuntimeId,
35
36
  public readonly key: EntityRealmKey, // ⚠️ This is *NOT* the id! ⚠️
@@ -60,30 +61,30 @@ class EntityAccessor implements Errorable {
60
61
  //
61
62
 
62
63
  public addError(error: ErrorAccessor.Error | string): () => void {
63
- return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))
64
+ return this.operations.addError(this.state, ErrorAccessor.normalizeError(error))
64
65
  }
65
66
 
66
67
  public addEventListener<Type extends keyof EntityAccessor.RuntimeEntityEventListenerMap>(
67
68
  event: { type: Type; key?: string },
68
69
  listener: EntityAccessor.EntityEventListenerMap[Type],
69
70
  ): () => void {
70
- return this.operations.addEventListener(this.stateKey, event, listener)
71
+ return this.operations.addEventListener(this.state, event, listener)
71
72
  }
72
73
 
73
74
  public batchUpdates(performUpdates: EntityAccessor.BatchUpdatesHandler): void {
74
- this.operations.batchUpdates(this.stateKey, performUpdates)
75
+ this.operations.batchUpdates(this.state, performUpdates)
75
76
  }
76
77
 
77
78
  public connectEntityAtField(field: FieldName, entityToConnect: EntityAccessor): void {
78
- this.operations.connectEntityAtField(this.stateKey, field, entityToConnect)
79
+ this.operations.connectEntityAtField(this.state, field, entityToConnect)
79
80
  }
80
81
 
81
82
  public disconnectEntityAtField(field: FieldName, initializeReplacement?: EntityAccessor.BatchUpdatesHandler): void {
82
- this.operations.disconnectEntityAtField(this.stateKey, field, initializeReplacement)
83
+ this.operations.disconnectEntityAtField(this.state, field, initializeReplacement)
83
84
  }
84
85
 
85
86
  public deleteEntity(): void {
86
- this.operations.deleteEntity(this.stateKey)
87
+ this.operations.deleteEntity(this.state)
87
88
  }
88
89
 
89
90
  //
@@ -144,6 +145,18 @@ class EntityAccessor implements Errorable {
144
145
  ) as EntityListAccessor
145
146
  }
146
147
 
148
+ public getParent(): EntityAccessor | EntityListAccessor | undefined {
149
+ const blueprint = this.state.blueprint
150
+ if (blueprint.type === 'subTree') {
151
+ return undefined
152
+ }
153
+ return blueprint.parent.getAccessor()
154
+ }
155
+
156
+ public getMarker() {
157
+ return getEntityMarker(this.state)
158
+ }
159
+
147
160
  private getAccessorByPlaceholder(placeholderName: FieldName): EntityAccessor.NestedAccessor {
148
161
  const record = this.fieldData.get(placeholderName)
149
162
  if (record === undefined) {
@@ -13,7 +13,7 @@ import { RuntimeId } from '../accessorTree'
13
13
 
14
14
  class EntityListAccessor implements Errorable {
15
15
  public constructor(
16
- private readonly stateKey: EntityListState,
16
+ private readonly state: EntityListState,
17
17
  private readonly operations: ListOperations,
18
18
  private readonly _children: ReadonlyMap<EntityId, { getAccessor: EntityAccessor.GetEntityAccessor }>,
19
19
  private readonly _idsPersistedOnServer: ReadonlySet<EntityId>,
@@ -94,14 +94,14 @@ class EntityListAccessor implements Errorable {
94
94
  }
95
95
 
96
96
  public addError(error: ErrorAccessor.Error | string): () => void {
97
- return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))
97
+ return this.operations.addError(this.state, ErrorAccessor.normalizeError(error))
98
98
  }
99
99
 
100
100
  public addEventListener<Type extends keyof EntityListAccessor.RuntimeEntityListEventListenerMap>(
101
101
  event: { type: Type; key?: string },
102
102
  listener: EntityListAccessor.RuntimeEntityListEventListenerMap[Type],
103
103
  ) {
104
- return this.operations.addEventListener(this.stateKey, event, listener)
104
+ return this.operations.addEventListener(this.state, event, listener)
105
105
  }
106
106
 
107
107
  public addChildEventListener<Type extends keyof EntityAccessor.EntityEventListenerMap>(
@@ -109,25 +109,25 @@ class EntityListAccessor implements Errorable {
109
109
  event: { type: Type; key?: string },
110
110
  listener: EntityAccessor.EntityEventListenerMap[Type],
111
111
  ) {
112
- return this.operations.addChildEventListener(this.stateKey, event, listener)
112
+ return this.operations.addChildEventListener(this.state, event, listener)
113
113
  }
114
114
 
115
115
  public batchUpdates(performUpdates: EntityListAccessor.BatchUpdatesHandler): void {
116
- this.operations.batchUpdates(this.stateKey, performUpdates)
116
+ this.operations.batchUpdates(this.state, performUpdates)
117
117
  }
118
118
 
119
119
  public connectEntity(entityToConnect: EntityAccessor): void {
120
- this.operations.connectEntity(this.stateKey, entityToConnect)
120
+ this.operations.connectEntity(this.state, entityToConnect)
121
121
  }
122
122
 
123
123
  public createNewEntity(initialize?: EntityAccessor.BatchUpdatesHandler): RuntimeId {
124
- return this.operations.createNewEntity(this.stateKey, initialize)
124
+ return this.operations.createNewEntity(this.state, initialize)
125
125
  }
126
126
  public disconnectEntity(childEntity: EntityAccessor, options: { noPersist?: boolean } = {}): void {
127
- this.operations.disconnectEntity(this.stateKey, childEntity, options)
127
+ this.operations.disconnectEntity(this.state, childEntity, options)
128
128
  }
129
129
  public getChildEntityById(id: EntityId): EntityAccessor {
130
- return this.operations.getChildEntityById(this.stateKey, id)
130
+ return this.operations.getChildEntityById(this.state, id)
131
131
  }
132
132
  }
133
133
 
@@ -9,7 +9,7 @@ import type { SchemaColumn } from '../core/schema/SchemaColumn'
9
9
 
10
10
  class FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable {
11
11
  constructor(
12
- private readonly stateKey: FieldState<Value>,
12
+ private readonly state: FieldState<Value>,
13
13
  private readonly operations: FieldOperations,
14
14
  public readonly fieldName: FieldName,
15
15
  public readonly value: Value | null,
@@ -23,22 +23,22 @@ class FieldAccessor<Value extends FieldValue = FieldValue> implements Errorable
23
23
  ) {}
24
24
 
25
25
  public addError(error: ErrorAccessor.Error | string): () => void {
26
- return this.operations.addError(this.stateKey, ErrorAccessor.normalizeError(error))
26
+ return this.operations.addError(this.state, ErrorAccessor.normalizeError(error))
27
27
  }
28
28
 
29
29
  public clearErrors(): void {
30
- this.operations.clearErrors(this.stateKey)
30
+ this.operations.clearErrors(this.state)
31
31
  }
32
32
 
33
33
  public addEventListener<Type extends keyof FieldAccessor.FieldEventListenerMap<Value>>(
34
34
  event: { type: Type; key?: string },
35
35
  listener: FieldAccessor.FieldEventListenerMap<Value>[Type],
36
36
  ): () => void {
37
- return this.operations.addEventListener(this.stateKey, event, listener)
37
+ return this.operations.addEventListener(this.state, event, listener)
38
38
  }
39
39
 
40
40
  public updateValue(newValue: Value | null, options?: FieldAccessor.UpdateOptions): void {
41
- this.operations.updateValue(this.stateKey, newValue, options)
41
+ this.operations.updateValue(this.state, newValue, options)
42
42
  }
43
43
 
44
44
  public hasValue(candidate: this['value']): boolean {
@@ -173,7 +173,7 @@ export class DataBinding {
173
173
  type: 'invalidResponse',
174
174
  }
175
175
  }
176
- const { __typename, ...mutationData } = mutationResponse.data.transaction
176
+ const { __typename, ok, errorMessage, ...mutationData } = mutationResponse.data.transaction
177
177
  const aliases = Object.keys(mutationData)
178
178
  if (aliases.every(item => mutationData[item].ok)) {
179
179
  const persistedEntityIds = aliases.map(alias => mutationData[alias].node?.id).filter(id => id !== undefined)
@@ -215,6 +215,9 @@ export class DataBinding {
215
215
  this.onPersistSuccess(result, this)
216
216
  return result
217
217
  } else {
218
+ if (errorMessage) {
219
+ console.error(errorMessage)
220
+ }
218
221
  this.eventManager.syncTransaction(() => this.accessorErrorManager.replaceErrors(mutationData, operations))
219
222
  await this.eventManager.triggerOnPersistError(persistErrorOptions)
220
223
  await onPersistError?.(persistErrorOptions)
@@ -361,7 +364,7 @@ export class DataBinding {
361
364
  signal,
362
365
  })
363
366
  } catch (metadata) {
364
- if (metadata.name === 'AbortError') {
367
+ if (typeof metadata === 'object' && metadata !== null && (metadata as { name?: unknown }).name === 'AbortError') {
365
368
  return
366
369
  }
367
370
  this.onError(metadataToRequestError(metadata as GraphQlClientFailedRequestMetadata), this)
@@ -13,7 +13,7 @@ import type { TreeStore } from '../TreeStore'
13
13
 
14
14
  export const createBatchUpdatesOptions = (rootEnvironment: Environment, treeStore: TreeStore): BatchUpdatesOptions =>
15
15
  Object.freeze({
16
- getEntityByKey: key => {
16
+ getEntityByKey: (key: string) => {
17
17
  const realm = treeStore.entityRealmStore.get(key)
18
18
 
19
19
  if (realm === undefined) {
@@ -1,4 +1,3 @@
1
- import { whereToFilter } from '@contember/client'
2
1
  import { useConstantValueInvariant } from '@contember/react-utils'
3
2
  import { ComponentType, ReactElement, ReactNode, useCallback } from 'react'
4
3
  import {
@@ -6,9 +5,9 @@ import {
6
5
  useEntityListSubTreeParameters,
7
6
  useGetEntityListSubTree,
8
7
  } from '../accessorPropagation'
9
- import { NIL_UUID, PRIMARY_KEY_NAME } from '../bindingTypes'
8
+ import { PRIMARY_KEY_NAME } from '../bindingTypes'
10
9
  import { Environment } from '../dao'
11
- import { MarkerFactory, QueryLanguage } from '../queryLanguage'
10
+ import { MarkerFactory } from '../queryLanguage'
12
11
  import type { SugaredQualifiedEntityList, SugaredUnconstrainedQualifiedEntityList, TreeRootId } from '../treeParameters'
13
12
  import { Component } from './Component'
14
13
  import { EntityList, EntityListBaseProps } from './EntityList'
@@ -11,7 +11,6 @@ import {
11
11
  } from '../treeParameters'
12
12
  import { QueryLanguage } from '../queryLanguage'
13
13
  import { BindingError } from '../BindingError'
14
- import { NIL_UUID } from '../bindingTypes'
15
14
  import { whereToFilter } from '@contember/client'
16
15
  import { BaseRelation, Schema, SchemaColumn, SchemaEntity, SchemaField, SchemaRelation } from '../core/schema'
17
16
  import levenshtein from 'js-levenshtein'
@@ -28,7 +27,7 @@ export class TreeNodeEnvironmentFactory {
28
27
 
29
28
  if (sugaredEntityList.isCreating) {
30
29
  entityList = QueryLanguage.desugarUnconstrainedQualifiedEntityList(sugaredEntityList, environment)
31
- rootWhere = { id: { eq: NIL_UUID } } as const
30
+ rootWhere = {} as const
32
31
  expectedCardinality = 'zero'
33
32
 
34
33
  } else {
@@ -56,7 +55,7 @@ export class TreeNodeEnvironmentFactory {
56
55
  let expectedCardinality: Environment.SubTreeNode['expectedCardinality']
57
56
 
58
57
  if (sugaredEntityList.isCreating) {
59
- rootWhere = { id: { eq: NIL_UUID } } as const
58
+ rootWhere = { } as const
60
59
  expectedCardinality = 'zero'
61
60
  entity = QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(sugaredEntityList, environment)
62
61