@contember/binding 1.3.0-alpha.9 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/accessors/EntityAccessor.cjs +12 -2
- package/dist/development/accessors/EntityAccessor.cjs.map +1 -1
- package/dist/development/accessors/EntityAccessor.js +12 -2
- package/dist/development/accessors/EntityAccessor.js.map +1 -1
- package/dist/development/accessors/EntityListAccessor.cjs +8 -1
- package/dist/development/accessors/EntityListAccessor.cjs.map +1 -1
- package/dist/development/accessors/EntityListAccessor.js +8 -1
- package/dist/development/accessors/EntityListAccessor.js.map +1 -1
- package/dist/development/accessors/ErrorAccessor.cjs.map +1 -1
- package/dist/development/accessors/ErrorAccessor.js.map +1 -1
- package/dist/development/accessors/FieldAccessor.cjs +3 -0
- package/dist/development/accessors/FieldAccessor.cjs.map +1 -1
- package/dist/development/accessors/FieldAccessor.js +3 -0
- package/dist/development/accessors/FieldAccessor.js.map +1 -1
- package/dist/development/core/DataBinding.cjs +4 -3
- package/dist/development/core/DataBinding.cjs.map +1 -1
- package/dist/development/core/DataBinding.js +4 -3
- package/dist/development/core/DataBinding.js.map +1 -1
- package/dist/development/core/MutationGenerator.cjs +36 -6
- package/dist/development/core/MutationGenerator.cjs.map +1 -1
- package/dist/development/core/MutationGenerator.js +36 -6
- package/dist/development/core/MutationGenerator.js.map +1 -1
- package/dist/development/core/StateInitializer.cjs +1 -0
- package/dist/development/core/StateInitializer.cjs.map +1 -1
- package/dist/development/core/StateInitializer.js +1 -0
- package/dist/development/core/StateInitializer.js.map +1 -1
- package/dist/development/core/operations/EntityOperations.cjs +5 -13
- package/dist/development/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/development/core/operations/EntityOperations.js +5 -13
- package/dist/development/core/operations/EntityOperations.js.map +1 -1
- package/dist/development/dao/Environment.cjs.map +1 -1
- package/dist/development/dao/Environment.js.map +1 -1
- package/dist/development/index.cjs +2 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +2 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/queryLanguage/Parser.cjs.map +1 -1
- package/dist/development/queryLanguage/Parser.js.map +1 -1
- package/dist/production/accessors/EntityAccessor.cjs +12 -2
- package/dist/production/accessors/EntityAccessor.cjs.map +1 -1
- package/dist/production/accessors/EntityAccessor.js +12 -2
- package/dist/production/accessors/EntityAccessor.js.map +1 -1
- package/dist/production/accessors/EntityListAccessor.cjs +8 -1
- package/dist/production/accessors/EntityListAccessor.cjs.map +1 -1
- package/dist/production/accessors/EntityListAccessor.js +8 -1
- package/dist/production/accessors/EntityListAccessor.js.map +1 -1
- package/dist/production/accessors/ErrorAccessor.cjs.map +1 -1
- package/dist/production/accessors/ErrorAccessor.js.map +1 -1
- package/dist/production/accessors/FieldAccessor.cjs +3 -0
- package/dist/production/accessors/FieldAccessor.cjs.map +1 -1
- package/dist/production/accessors/FieldAccessor.js +3 -0
- package/dist/production/accessors/FieldAccessor.js.map +1 -1
- package/dist/production/core/DataBinding.cjs +4 -3
- package/dist/production/core/DataBinding.cjs.map +1 -1
- package/dist/production/core/DataBinding.js +4 -3
- package/dist/production/core/DataBinding.js.map +1 -1
- package/dist/production/core/MutationGenerator.cjs +36 -6
- package/dist/production/core/MutationGenerator.cjs.map +1 -1
- package/dist/production/core/MutationGenerator.js +36 -6
- package/dist/production/core/MutationGenerator.js.map +1 -1
- package/dist/production/core/StateInitializer.cjs +1 -0
- package/dist/production/core/StateInitializer.cjs.map +1 -1
- package/dist/production/core/StateInitializer.js +1 -0
- package/dist/production/core/StateInitializer.js.map +1 -1
- package/dist/production/core/operations/EntityOperations.cjs +5 -13
- package/dist/production/core/operations/EntityOperations.cjs.map +1 -1
- package/dist/production/core/operations/EntityOperations.js +5 -13
- package/dist/production/core/operations/EntityOperations.js.map +1 -1
- package/dist/production/dao/Environment.cjs.map +1 -1
- package/dist/production/dao/Environment.js.map +1 -1
- package/dist/production/index.cjs +2 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +2 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/queryLanguage/Parser.cjs.map +1 -1
- package/dist/production/queryLanguage/Parser.js.map +1 -1
- package/dist/types/accessorTree/PersistResult.d.ts +2 -0
- package/dist/types/accessorTree/PersistResult.d.ts.map +1 -1
- package/dist/types/accessors/EntityAccessor.d.ts +2 -2
- package/dist/types/accessors/EntityAccessor.d.ts.map +1 -1
- package/dist/types/accessors/EntityListAccessor.d.ts +6 -2
- package/dist/types/accessors/EntityListAccessor.d.ts.map +1 -1
- package/dist/types/accessors/ErrorAccessor.d.ts +3 -0
- package/dist/types/accessors/ErrorAccessor.d.ts.map +1 -1
- package/dist/types/accessors/FieldAccessor.d.ts +2 -0
- package/dist/types/accessors/FieldAccessor.d.ts.map +1 -1
- package/dist/types/core/DataBinding.d.ts.map +1 -1
- package/dist/types/core/MutationGenerator.d.ts +1 -1
- package/dist/types/core/MutationGenerator.d.ts.map +1 -1
- package/dist/types/core/StateInitializer.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/operations/EntityOperations.d.ts.map +1 -1
- package/dist/types/dao/Environment.d.ts +8 -8
- package/dist/types/dao/Environment.d.ts.map +1 -1
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts +6 -2
- package/dist/types/dao/TreeNodeEnvironmentFactory.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/accessorTree/PersistResult.ts +2 -0
- package/src/accessors/EntityAccessor.ts +15 -7
- package/src/accessors/EntityListAccessor.ts +11 -1
- package/src/accessors/ErrorAccessor.ts +4 -0
- package/src/accessors/FieldAccessor.ts +5 -0
- package/src/core/DataBinding.ts +3 -2
- package/src/core/MutationGenerator.ts +37 -7
- package/src/core/StateInitializer.ts +1 -0
- package/src/core/index.ts +1 -0
- package/src/core/operations/EntityOperations.ts +5 -13
- package/src/dao/Environment.ts +7 -7
- package/src/queryLanguage/Parser.ts +1 -1
|
@@ -41,7 +41,7 @@ export class MutationGenerator {
|
|
|
41
41
|
) {
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
public getPersistMutation(): PersistMutationResult
|
|
44
|
+
public getPersistMutation(): PersistMutationResult {
|
|
45
45
|
const mutations: Record<string, ContentMutation<any>> = {}
|
|
46
46
|
const operations: SubMutationOperation[] = []
|
|
47
47
|
const processedPlaceholdersByEntity: ProcessedPlaceholdersByEntity = new Map()
|
|
@@ -317,7 +317,12 @@ export class MutationGenerator {
|
|
|
317
317
|
}
|
|
318
318
|
const input = this.getCreateOneRelationInput(processedPlaceholdersByEntity, fieldState, marker)
|
|
319
319
|
if (input !== undefined) {
|
|
320
|
-
result[marker.parameters.field]
|
|
320
|
+
const current = result[marker.parameters.field]
|
|
321
|
+
if (Array.isArray(input) && Array.isArray(current)) {
|
|
322
|
+
current.push(...input)
|
|
323
|
+
} else {
|
|
324
|
+
result[marker.parameters.field] = input
|
|
325
|
+
}
|
|
321
326
|
}
|
|
322
327
|
break
|
|
323
328
|
}
|
|
@@ -339,7 +344,12 @@ export class MutationGenerator {
|
|
|
339
344
|
}
|
|
340
345
|
const input = this.getCreateManyRelationInput(processedPlaceholdersByEntity, fieldState)
|
|
341
346
|
if (input !== undefined) {
|
|
342
|
-
result[marker.parameters.field]
|
|
347
|
+
const current = result[marker.parameters.field]
|
|
348
|
+
if (Array.isArray(current)) {
|
|
349
|
+
current.push(...input)
|
|
350
|
+
} else {
|
|
351
|
+
result[marker.parameters.field] = input
|
|
352
|
+
}
|
|
343
353
|
}
|
|
344
354
|
break
|
|
345
355
|
}
|
|
@@ -366,7 +376,12 @@ export class MutationGenerator {
|
|
|
366
376
|
field.marker,
|
|
367
377
|
)
|
|
368
378
|
if (input !== undefined) {
|
|
369
|
-
result[field.marker.parameters.field]
|
|
379
|
+
const current = result[field.marker.parameters.field]
|
|
380
|
+
if (Array.isArray(input) && Array.isArray(current)) {
|
|
381
|
+
current.push(...input)
|
|
382
|
+
} else {
|
|
383
|
+
result[field.marker.parameters.field] = input
|
|
384
|
+
}
|
|
370
385
|
}
|
|
371
386
|
break
|
|
372
387
|
}
|
|
@@ -376,7 +391,12 @@ export class MutationGenerator {
|
|
|
376
391
|
field.fieldState,
|
|
377
392
|
)
|
|
378
393
|
if (input !== undefined) {
|
|
379
|
-
result[field.marker.parameters.field]
|
|
394
|
+
const current = result[field.marker.parameters.field]
|
|
395
|
+
if (Array.isArray(current)) {
|
|
396
|
+
current.push(...input)
|
|
397
|
+
} else {
|
|
398
|
+
result[field.marker.parameters.field] = input
|
|
399
|
+
}
|
|
380
400
|
}
|
|
381
401
|
break
|
|
382
402
|
}
|
|
@@ -534,7 +554,12 @@ export class MutationGenerator {
|
|
|
534
554
|
} else {
|
|
535
555
|
const relationData = this.getUpdateManyRelationForReducedInput(currentState, fieldState, persistedValue, processedPlaceholdersByEntity, placeholderName, reducedBy)
|
|
536
556
|
if (relationData !== undefined) {
|
|
537
|
-
result[marker.parameters.field]
|
|
557
|
+
const current = result[marker.parameters.field]
|
|
558
|
+
if (Array.isArray(current)) {
|
|
559
|
+
current.push(...relationData)
|
|
560
|
+
} else {
|
|
561
|
+
result[marker.parameters.field] = relationData
|
|
562
|
+
}
|
|
538
563
|
}
|
|
539
564
|
|
|
540
565
|
}
|
|
@@ -555,7 +580,12 @@ export class MutationGenerator {
|
|
|
555
580
|
}
|
|
556
581
|
const relationData = this.getUpdateManyRelationInput(fieldState, persistedEntityIds, processedPlaceholdersByEntity)
|
|
557
582
|
if (relationData !== undefined) {
|
|
558
|
-
result[marker.parameters.field]
|
|
583
|
+
const current = result[marker.parameters.field]
|
|
584
|
+
if (Array.isArray(current)) {
|
|
585
|
+
current.push(...relationData)
|
|
586
|
+
} else {
|
|
587
|
+
result[marker.parameters.field] = relationData
|
|
588
|
+
}
|
|
559
589
|
}
|
|
560
590
|
break
|
|
561
591
|
}
|
|
@@ -317,6 +317,7 @@ export class StateInitializer {
|
|
|
317
317
|
entityListState.accessor = new EntityListAccessor(
|
|
318
318
|
entityListState,
|
|
319
319
|
this.listOperations,
|
|
320
|
+
entityListState.entityName,
|
|
320
321
|
entityListState.children,
|
|
321
322
|
persistedEntityIds,
|
|
322
323
|
entityListState.unpersistedChangesCount !== 0,
|
package/src/core/index.ts
CHANGED
|
@@ -67,11 +67,7 @@ export class EntityOperations {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
for (const state of StateIterator.eachSiblingRealm(outerState)) {
|
|
70
|
-
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(
|
|
71
|
-
getEntityMarker(state).fields,
|
|
72
|
-
fieldName,
|
|
73
|
-
`Cannot connect at field '${fieldName}' as it doesn't refer to a has one relation.`,
|
|
74
|
-
)
|
|
70
|
+
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'connect')
|
|
75
71
|
for (const targetHasOneMarker of targetHasOneMarkers) {
|
|
76
72
|
const previouslyConnectedState = state.children.get(targetHasOneMarker.placeholderName)
|
|
77
73
|
|
|
@@ -169,11 +165,7 @@ export class EntityOperations {
|
|
|
169
165
|
const persistedData = this.treeStore.persistedEntityData.get(outerState.entity.id.uniqueValue)
|
|
170
166
|
|
|
171
167
|
for (const state of StateIterator.eachSiblingRealm(outerState)) {
|
|
172
|
-
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(
|
|
173
|
-
getEntityMarker(state).fields,
|
|
174
|
-
fieldName,
|
|
175
|
-
`Cannot disconnect at field '${fieldName}' as it doesn't refer to a has one relation.`,
|
|
176
|
-
)
|
|
168
|
+
const targetHasOneMarkers = this.resolveHasOneRelationMarkers(getEntityMarker(state).fields, fieldName, 'disconnect')
|
|
177
169
|
for (const targetHasOneMarker of targetHasOneMarkers) {
|
|
178
170
|
const stateToDisconnect = state.children.get(targetHasOneMarker.placeholderName)
|
|
179
171
|
|
|
@@ -293,12 +285,12 @@ export class EntityOperations {
|
|
|
293
285
|
private *resolveHasOneRelationMarkers(
|
|
294
286
|
container: EntityFieldMarkersContainer,
|
|
295
287
|
field: FieldName,
|
|
296
|
-
|
|
288
|
+
type: 'connect' | 'disconnect',
|
|
297
289
|
): IterableIterator<HasOneRelationMarker> {
|
|
298
290
|
const placeholders = container.placeholders.get(field)
|
|
299
291
|
|
|
300
292
|
if (placeholders === undefined) {
|
|
301
|
-
|
|
293
|
+
throw new BindingError(`Cannot ${type} at field '${field}' as it wasn't registered during static render.`)
|
|
302
294
|
}
|
|
303
295
|
const normalizedPlaceholders = placeholders instanceof Set ? placeholders : [placeholders]
|
|
304
296
|
|
|
@@ -306,7 +298,7 @@ export class EntityOperations {
|
|
|
306
298
|
const hasOneRelation = container.markers.get(placeholderName)
|
|
307
299
|
|
|
308
300
|
if (!(hasOneRelation instanceof HasOneRelationMarker)) {
|
|
309
|
-
throw new BindingError(
|
|
301
|
+
throw new BindingError(`Cannot ${type} at field '${field}' as it doesn't refer to a has one relation.`)
|
|
310
302
|
}
|
|
311
303
|
yield hasOneRelation
|
|
312
304
|
}
|
package/src/dao/Environment.ts
CHANGED
|
@@ -4,9 +4,9 @@ import equal from 'fast-deep-equal/es6/index.js'
|
|
|
4
4
|
import { Schema, SchemaColumn, SchemaEntity, SchemaRelation } from '../core/schema'
|
|
5
5
|
import { GraphQlLiteral } from '@contember/client'
|
|
6
6
|
|
|
7
|
-
class Environment {
|
|
7
|
+
class Environment<Node extends Environment.AnyNode | undefined = Environment.AnyNode | undefined> {
|
|
8
8
|
private constructor(
|
|
9
|
-
private readonly options: Environment.Options
|
|
9
|
+
private readonly options: Environment.Options<Node>,
|
|
10
10
|
) {
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -29,14 +29,14 @@ class Environment {
|
|
|
29
29
|
throw new BindingError('Not in a SubTree')
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
public getSubTreeNode(): Environment.AnyNode {
|
|
32
|
+
public getSubTreeNode(): Node & Environment.AnyNode {
|
|
33
33
|
if (!this.options.node) {
|
|
34
34
|
throw new BindingError()
|
|
35
35
|
}
|
|
36
36
|
return this.options.node
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
public withSubTree(SubTree:
|
|
39
|
+
public withSubTree<Node extends Environment.SubTreeNode>(SubTree: Node): Environment<Node> {
|
|
40
40
|
const { parent, ...options } = this.options
|
|
41
41
|
return new Environment({
|
|
42
42
|
...options,
|
|
@@ -44,7 +44,7 @@ class Environment {
|
|
|
44
44
|
})
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
public withSubTreeChild(node:
|
|
47
|
+
public withSubTreeChild<Node extends Environment.InnerNode>(node: Node): Environment<Node> {
|
|
48
48
|
if (!this.options.node) {
|
|
49
49
|
throw new BindingError(`Cannot call withSubTreeChild without previous call of withSubTree`)
|
|
50
50
|
}
|
|
@@ -251,8 +251,8 @@ namespace Environment {
|
|
|
251
251
|
|
|
252
252
|
export type ResolvedValue = Value
|
|
253
253
|
|
|
254
|
-
export interface Options {
|
|
255
|
-
node?:
|
|
254
|
+
export interface Options<Node extends AnyNode | undefined> {
|
|
255
|
+
node?: Node
|
|
256
256
|
schema?: Schema
|
|
257
257
|
dimensions: SelectedDimensions
|
|
258
258
|
parameters: Parameters
|