@contember/binding 1.1.0-alpha.10 → 1.1.0-alpha.11
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.
- package/dist/development/accessors/EntityAccessor.js +19 -8
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +10 -10
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +6 -6
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/core/DataBinding.js +4 -1
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/EventManager.js +1 -1
- package/dist/development/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/development/dao/TreeNodeEnvironmentFactory.js +2 -3
- package/dist/development/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.js +19 -8
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +10 -10
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.js +6 -6
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/core/DataBinding.js +4 -1
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/EventManager.js +1 -1
- package/dist/production/coreComponents/EntityListSubTree.js.map +1 -1
- package/dist/production/dao/TreeNodeEnvironmentFactory.js +2 -3
- package/dist/production/dao/TreeNodeEnvironmentFactory.js.map +1 -1
- package/dist/types/accessorTree/MutationRequestResponse.d.ts +5 -5
- package/dist/types/accessorTree/MutationRequestResponse.d.ts.map +1 -1
- package/dist/types/accessors/EntityAccessor.d.ts +4 -2
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessor.d.ts +2 -2
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/accessors/FieldAccessor.d.ts +2 -2
- package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/accessorTree/MutationRequestResponse.ts +9 -3
- package/src/accessors/EntityAccessor.ts +20 -7
- package/src/accessors/EntityListAccessor.ts +9 -9
- package/src/accessors/FieldAccessor.ts +5 -5
- package/src/core/DataBinding.ts +4 -1
- package/src/coreComponents/EntityListSubTree.tsx +2 -3
- 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.
|
|
4
|
+
"version": "1.1.0-alpha.11",
|
|
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.
|
|
23
|
-
"@contember/react-client": "1.1.0-alpha.
|
|
24
|
-
"@contember/react-multipass-rendering": "1.1.0-alpha.
|
|
25
|
-
"@contember/react-utils": "1.1.0-alpha.
|
|
22
|
+
"@contember/client": "1.1.0-alpha.11",
|
|
23
|
+
"@contember/react-client": "1.1.0-alpha.11",
|
|
24
|
+
"@contember/react-multipass-rendering": "1.1.0-alpha.11",
|
|
25
|
+
"@contember/react-utils": "1.1.0-alpha.11",
|
|
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:
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
83
|
+
this.operations.disconnectEntityAtField(this.state, field, initializeReplacement)
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
public deleteEntity(): void {
|
|
86
|
-
this.operations.deleteEntity(this.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
116
|
+
this.operations.batchUpdates(this.state, performUpdates)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
public connectEntity(entityToConnect: EntityAccessor): void {
|
|
120
|
-
this.operations.connectEntity(this.
|
|
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.
|
|
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.
|
|
127
|
+
this.operations.disconnectEntity(this.state, childEntity, options)
|
|
128
128
|
}
|
|
129
129
|
public getChildEntityById(id: EntityId): EntityAccessor {
|
|
130
|
-
return this.operations.getChildEntityById(this.
|
|
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
|
|
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.
|
|
26
|
+
return this.operations.addError(this.state, ErrorAccessor.normalizeError(error))
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
public clearErrors(): void {
|
|
30
|
-
this.operations.clearErrors(this.
|
|
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.
|
|
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.
|
|
41
|
+
this.operations.updateValue(this.state, newValue, options)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
public hasValue(candidate: this['value']): boolean {
|
package/src/core/DataBinding.ts
CHANGED
|
@@ -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)
|
|
@@ -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 {
|
|
8
|
+
import { PRIMARY_KEY_NAME } from '../bindingTypes'
|
|
10
9
|
import { Environment } from '../dao'
|
|
11
|
-
import { MarkerFactory
|
|
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 = {
|
|
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 = {
|
|
58
|
+
rootWhere = { } as const
|
|
60
59
|
expectedCardinality = 'zero'
|
|
61
60
|
entity = QueryLanguage.desugarUnconstrainedQualifiedSingleEntity(sugaredEntityList, environment)
|
|
62
61
|
|