@contember/client-content 2.1.0-alpha.8 → 2.1.0-beta.1
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/CLAUDE.md +52 -0
- package/dist/development/src/ContentClient.cjs +12 -0
- package/dist/development/src/ContentClient.cjs.map +1 -1
- package/dist/development/src/ContentClient.js +12 -0
- package/dist/development/src/ContentClient.js.map +1 -1
- package/dist/development/src/ContentQueryBuilder.cjs +26 -15
- package/dist/development/src/ContentQueryBuilder.cjs.map +1 -1
- package/dist/development/src/ContentQueryBuilder.js +26 -15
- package/dist/development/src/ContentQueryBuilder.js.map +1 -1
- package/dist/development/src/MutationFailedError.cjs +11 -0
- package/dist/development/src/MutationFailedError.cjs.map +1 -0
- package/dist/development/src/MutationFailedError.js +11 -0
- package/dist/development/src/MutationFailedError.js.map +1 -0
- package/dist/development/src/nodes/ContentEntitySelection.cjs +47 -12
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/development/src/nodes/ContentEntitySelection.js +47 -12
- package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/development/src/nodes/ContentOperation.cjs.map +1 -1
- package/dist/development/src/nodes/ContentOperation.js.map +1 -1
- package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/ContentOperationSet.js.map +1 -1
- package/dist/development/src/utils/createListArgs.cjs.map +1 -1
- package/dist/development/src/utils/createListArgs.js.map +1 -1
- package/dist/development/src/utils/createMutationOperationSet.cjs +8 -6
- package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/createMutationOperationSet.js +8 -6
- package/dist/development/src/utils/createMutationOperationSet.js.map +1 -1
- package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/createQueryOperationSet.js.map +1 -1
- package/dist/development/src/utils/createTypedArgs.cjs.map +1 -1
- package/dist/development/src/utils/createTypedArgs.js.map +1 -1
- package/dist/development/src/utils/mutationFragments.cjs.map +1 -1
- package/dist/development/src/utils/mutationFragments.js.map +1 -1
- package/dist/production/src/ContentClient.cjs +12 -0
- package/dist/production/src/ContentClient.cjs.map +1 -1
- package/dist/production/src/ContentClient.js +12 -0
- package/dist/production/src/ContentClient.js.map +1 -1
- package/dist/production/src/ContentQueryBuilder.cjs +26 -15
- package/dist/production/src/ContentQueryBuilder.cjs.map +1 -1
- package/dist/production/src/ContentQueryBuilder.js +26 -15
- package/dist/production/src/ContentQueryBuilder.js.map +1 -1
- package/dist/production/src/MutationFailedError.cjs +11 -0
- package/dist/production/src/MutationFailedError.cjs.map +1 -0
- package/dist/production/src/MutationFailedError.js +11 -0
- package/dist/production/src/MutationFailedError.js.map +1 -0
- package/dist/production/src/nodes/ContentEntitySelection.cjs +47 -12
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/production/src/nodes/ContentEntitySelection.js +47 -12
- package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/production/src/nodes/ContentOperation.cjs.map +1 -1
- package/dist/production/src/nodes/ContentOperation.js.map +1 -1
- package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/ContentOperationSet.js.map +1 -1
- package/dist/production/src/utils/createListArgs.cjs.map +1 -1
- package/dist/production/src/utils/createListArgs.js.map +1 -1
- package/dist/production/src/utils/createMutationOperationSet.cjs +8 -6
- package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/createMutationOperationSet.js +8 -6
- package/dist/production/src/utils/createMutationOperationSet.js.map +1 -1
- package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/createQueryOperationSet.js.map +1 -1
- package/dist/production/src/utils/createTypedArgs.cjs.map +1 -1
- package/dist/production/src/utils/createTypedArgs.js.map +1 -1
- package/dist/production/src/utils/mutationFragments.cjs.map +1 -1
- package/dist/production/src/utils/mutationFragments.js.map +1 -1
- package/dist/types/ContentClient.d.ts +10 -0
- package/dist/types/ContentClient.d.ts.map +1 -1
- package/dist/types/ContentQueryBuilder.d.ts.map +1 -1
- package/dist/types/MutationFailedError.d.ts +13 -0
- package/dist/types/MutationFailedError.d.ts.map +1 -0
- package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts +4 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
- package/dist/types/nodes/TypedEntitySelection.d.ts +1 -0
- package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/Input.d.ts.map +1 -1
- package/dist/types/types/Result.d.ts +30 -9
- package/dist/types/types/Result.d.ts.map +1 -1
- package/dist/types/utils/createListArgs.d.ts.map +1 -1
- package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -1
- package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/ContentClient.ts +36 -9
- package/src/ContentQueryBuilder.ts +45 -35
- package/src/MutationFailedError.ts +19 -0
- package/src/TypedContentQueryBuilder.ts +0 -4
- package/src/nodes/ContentEntitySelection.ts +67 -23
- package/src/nodes/TypedEntitySelection.ts +96 -48
- package/src/types/Input.ts +1 -9
- package/src/types/Result.ts +41 -9
- package/src/types/Schema.ts +0 -1
- package/src/utils/createListArgs.ts +5 -1
- package/src/utils/createMutationOperationSet.ts +9 -7
- package/src/utils/createQueryOperationSet.ts +0 -1
- package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
- package/tests/cases/unit/__snapshots__/query.test.ts.snap +216 -60
- package/tests/cases/unit/mutation.test.ts +48 -3
- package/tests/cases/unit/query.test.ts +103 -82
- package/tests/cases/unit/types.test.ts +31 -27
- package/tests/client/entities.ts +2 -0
- package/tests/client/enums.ts +5 -0
- package/tests/client/names.ts +129 -117
- package/tests/generate.ts +0 -1
- package/tests/lib.ts +0 -1
- package/tests/schema.ts +1 -2
|
@@ -2,38 +2,49 @@ import { EntityTypeLike, SchemaTypeLike } from '../types'
|
|
|
2
2
|
import { ContentClientInput } from '../types'
|
|
3
3
|
import { ContentEntitySelectionContext } from './ContentEntitySelection'
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
export interface TypedEntitySelection<TSchema extends SchemaTypeLike, TEntityName extends string, TEntity extends EntityTypeLike, TValue> {
|
|
7
|
-
|
|
8
6
|
/** @internal */
|
|
9
7
|
readonly context: ContentEntitySelectionContext<TEntityName>
|
|
10
8
|
|
|
11
|
-
$$(): TypedEntitySelection<
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
$$(): TypedEntitySelection<
|
|
10
|
+
TSchema,
|
|
11
|
+
TEntityName,
|
|
12
|
+
TEntity,
|
|
13
|
+
& TValue
|
|
14
|
+
& {
|
|
15
|
+
[key in keyof TEntity['columns']]: TEntity['columns'][key]
|
|
16
|
+
}
|
|
17
|
+
>
|
|
15
18
|
|
|
16
19
|
transform<T>(cb: (value: TValue) => T): TypedEntitySelection<TSchema, TEntityName, TEntity, T>
|
|
17
20
|
|
|
18
21
|
$<
|
|
19
22
|
TNestedValue,
|
|
20
23
|
TKey extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasManyBy'] | keyof TEntity['hasOne']) & string,
|
|
21
|
-
TAlias extends string | null = null
|
|
24
|
+
TAlias extends string | null = null,
|
|
22
25
|
>(
|
|
23
26
|
name: TKey,
|
|
24
27
|
...args: TypedEntitySelectionParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
25
|
-
): TypedEntitySelection<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
): TypedEntitySelection<
|
|
29
|
+
TSchema,
|
|
30
|
+
TEntityName,
|
|
31
|
+
TEntity,
|
|
32
|
+
& TValue
|
|
33
|
+
& {
|
|
34
|
+
[key in TAlias extends null ? TKey : TAlias]: TypedEntitySelectionResult<TEntity, TKey, TNestedValue>
|
|
35
|
+
}
|
|
36
|
+
>
|
|
37
|
+
|
|
38
|
+
omit<TField extends keyof TValue>(
|
|
39
|
+
...fields: TField[]
|
|
40
|
+
): TypedEntitySelection<TSchema, TEntityName, TEntity, Omit<TValue, TField>>
|
|
29
41
|
|
|
30
42
|
meta<
|
|
31
|
-
TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne'])
|
|
43
|
+
TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne']),
|
|
32
44
|
>(
|
|
33
45
|
field: TField,
|
|
34
46
|
flags: ('readable' | 'updatable')[],
|
|
35
47
|
): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue>
|
|
36
|
-
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
export type TypedEntitySelectionCallback<
|
|
@@ -43,75 +54,112 @@ export type TypedEntitySelectionCallback<
|
|
|
43
54
|
TValue,
|
|
44
55
|
> = (select: TypedEntitySelection<TSchema, EntityName, TEntity, {}>) => TypedEntitySelection<TSchema, EntityName, TEntity, TValue>
|
|
45
56
|
|
|
46
|
-
|
|
47
57
|
export type TypedHasManyArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasMany'] & string, TAlias extends string | null = null> =
|
|
48
58
|
& ContentClientInput.HasManyRelationInput<TEntity['hasMany'][TKey]>
|
|
49
59
|
& { as?: TAlias }
|
|
50
60
|
|
|
51
|
-
export type TypedHasManyFields<
|
|
61
|
+
export type TypedHasManyFields<
|
|
62
|
+
TSchema extends SchemaTypeLike,
|
|
63
|
+
TEntity extends EntityTypeLike,
|
|
64
|
+
TKey extends keyof TEntity['hasMany'] & string,
|
|
65
|
+
TNestedValue,
|
|
66
|
+
> =
|
|
52
67
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
|
|
53
68
|
| TypedEntitySelection<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
|
|
54
69
|
|
|
55
|
-
export type TypedHasManyParams<
|
|
70
|
+
export type TypedHasManyParams<
|
|
71
|
+
TSchema extends SchemaTypeLike,
|
|
72
|
+
TEntity extends EntityTypeLike,
|
|
73
|
+
TKey extends keyof TEntity['hasMany'] & string,
|
|
74
|
+
TNestedValue,
|
|
75
|
+
TAlias extends string | null = null,
|
|
76
|
+
> =
|
|
56
77
|
| [
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
args: TypedHasManyArgs<TEntity, TKey, TAlias>,
|
|
79
|
+
fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
59
80
|
]
|
|
60
81
|
| [
|
|
61
|
-
|
|
82
|
+
fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
62
83
|
]
|
|
63
84
|
|
|
64
|
-
|
|
65
|
-
|
|
85
|
+
export type TypedHasManyByArgs<
|
|
86
|
+
TEntity extends EntityTypeLike,
|
|
87
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
88
|
+
TAlias extends string | null = null,
|
|
89
|
+
> =
|
|
66
90
|
& ContentClientInput.HasManyByRelationInput<TEntity['hasManyBy'][TKey]['entity'], TEntity['hasManyBy'][TKey]['by']>
|
|
67
91
|
& { as?: TAlias }
|
|
68
92
|
|
|
69
|
-
export type TypedHasManyByFields<
|
|
93
|
+
export type TypedHasManyByFields<
|
|
94
|
+
TSchema extends SchemaTypeLike,
|
|
95
|
+
TEntity extends EntityTypeLike,
|
|
96
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
97
|
+
TNestedValue,
|
|
98
|
+
> =
|
|
70
99
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
|
|
71
100
|
| TypedEntitySelection<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
|
|
72
101
|
|
|
73
|
-
export type TypedHasManyByParams<
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
export type TypedHasManyByParams<
|
|
103
|
+
TSchema extends SchemaTypeLike,
|
|
104
|
+
TEntity extends EntityTypeLike,
|
|
105
|
+
TKey extends keyof TEntity['hasManyBy'] & string,
|
|
106
|
+
TNestedValue,
|
|
107
|
+
TAlias extends string | null = null,
|
|
108
|
+
> = [
|
|
109
|
+
args: TypedHasManyByArgs<TEntity, TKey, TAlias>,
|
|
110
|
+
fields: TypedHasManyByFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
111
|
+
]
|
|
79
112
|
|
|
80
113
|
export type TypedHasOneArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasOne'] & string, TAlias extends string | null = null> =
|
|
81
114
|
& ContentClientInput.HasOneRelationInput<TEntity['hasOne'][TKey]>
|
|
82
115
|
& { as?: TAlias }
|
|
83
116
|
|
|
84
|
-
export type TypedHasOneFields<
|
|
117
|
+
export type TypedHasOneFields<
|
|
118
|
+
TSchema extends SchemaTypeLike,
|
|
119
|
+
TEntity extends EntityTypeLike,
|
|
120
|
+
TKey extends keyof TEntity['hasOne'] & string,
|
|
121
|
+
TNestedValue,
|
|
122
|
+
> =
|
|
85
123
|
| TypedEntitySelectionCallback<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
|
|
86
124
|
| TypedEntitySelection<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
|
|
87
125
|
|
|
88
|
-
export type TypedHasOneParams<
|
|
126
|
+
export type TypedHasOneParams<
|
|
127
|
+
TSchema extends SchemaTypeLike,
|
|
128
|
+
TEntity extends EntityTypeLike,
|
|
129
|
+
TKey extends keyof TEntity['hasOne'] & string,
|
|
130
|
+
TNestedValue,
|
|
131
|
+
TAlias extends string | null = null,
|
|
132
|
+
> =
|
|
89
133
|
| [
|
|
90
|
-
|
|
91
|
-
|
|
134
|
+
args: TypedHasOneArgs<TEntity, TKey, TAlias>,
|
|
135
|
+
fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
92
136
|
]
|
|
93
137
|
| [
|
|
94
|
-
|
|
138
|
+
fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
|
|
95
139
|
]
|
|
96
140
|
|
|
97
|
-
|
|
98
141
|
export type TypedColumnArgs<TAlias extends string | null = null> = { as?: TAlias }
|
|
99
142
|
export type TypedColumnParams<TAlias extends string | null = null> =
|
|
100
143
|
| [
|
|
101
|
-
|
|
144
|
+
args: TypedColumnArgs<TAlias>,
|
|
102
145
|
]
|
|
103
146
|
| []
|
|
104
147
|
|
|
105
|
-
export type TypedEntitySelectionParams<
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
TKey extends keyof TEntity['
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
148
|
+
export type TypedEntitySelectionParams<
|
|
149
|
+
TSchema extends SchemaTypeLike,
|
|
150
|
+
TEntity extends EntityTypeLike,
|
|
151
|
+
TKey extends string,
|
|
152
|
+
TNestedValue,
|
|
153
|
+
TAlias extends string | null = null,
|
|
154
|
+
> = TKey extends keyof TEntity['columns'] ? TypedColumnParams<TAlias>
|
|
155
|
+
: TKey extends keyof TEntity['hasMany'] ? TypedHasManyParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
156
|
+
: TKey extends keyof TEntity['hasManyBy'] ? TypedHasManyByParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
157
|
+
: TKey extends keyof TEntity['hasOne'] ? TypedHasOneParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
|
|
158
|
+
: never
|
|
159
|
+
|
|
160
|
+
export type TypedEntitySelectionResult<TEntity extends EntityTypeLike, TKey extends string, TValue> = TKey extends keyof TEntity['columns']
|
|
161
|
+
? TEntity['columns'][TKey]
|
|
162
|
+
: TKey extends keyof TEntity['hasMany'] ? TValue[]
|
|
163
|
+
: TKey extends keyof TEntity['hasManyBy'] ? null | TValue
|
|
164
|
+
: TKey extends keyof TEntity['hasOne'] ? null | TValue
|
|
165
|
+
: never
|
package/src/types/Input.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Input, JSONObject } from '@contember/schema'
|
|
2
2
|
import { EntityTypeLike } from './Schema'
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
export namespace ContentClientInput {
|
|
6
5
|
export type ConnectRelationInput<TEntity extends EntityTypeLike> = {
|
|
7
6
|
/** @internal */
|
|
@@ -55,7 +54,7 @@ export namespace ContentClientInput {
|
|
|
55
54
|
readonly upsert: {
|
|
56
55
|
readonly by: UniqueWhere<TEntity>
|
|
57
56
|
readonly update: UpdateDataInput<TEntity>
|
|
58
|
-
readonly
|
|
57
|
+
readonly create: CreateDataInput<TEntity>
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -108,7 +107,6 @@ export namespace ContentClientInput {
|
|
|
108
107
|
|
|
109
108
|
export type CreateManyRelationInput<TEntity extends EntityTypeLike> = readonly CreateOneRelationInput<TEntity>[]
|
|
110
109
|
|
|
111
|
-
|
|
112
110
|
export type UpdateDataInput<TEntity extends EntityTypeLike> =
|
|
113
111
|
& {
|
|
114
112
|
/**
|
|
@@ -197,7 +195,6 @@ export namespace ContentClientInput {
|
|
|
197
195
|
export type HasManyRelationInput<TEntity extends EntityTypeLike> = ListQueryInput<TEntity>
|
|
198
196
|
export type HasManyRelationPaginateInput<TEntity extends EntityTypeLike> = PaginationQueryInput<TEntity>
|
|
199
197
|
|
|
200
|
-
|
|
201
198
|
export type UpdateOneRelationInput<TEntity extends EntityTypeLike> =
|
|
202
199
|
| CreateRelationInput<TEntity>
|
|
203
200
|
| ConnectRelationInput<TEntity>
|
|
@@ -216,10 +213,8 @@ export namespace ContentClientInput {
|
|
|
216
213
|
| UpdateSpecifiedRelationInput<TEntity>
|
|
217
214
|
| UpsertSpecifiedRelationInput<TEntity>
|
|
218
215
|
|
|
219
|
-
|
|
220
216
|
export type UpdateManyRelationInput<TEntity extends EntityTypeLike> = Array<UpdateManyRelationInputItem<TEntity>>
|
|
221
217
|
|
|
222
|
-
|
|
223
218
|
export type FieldOrderBy<TEntity extends EntityTypeLike> =
|
|
224
219
|
& {
|
|
225
220
|
/** @internal */
|
|
@@ -241,7 +236,6 @@ export namespace ContentClientInput {
|
|
|
241
236
|
}
|
|
242
237
|
& FieldOrderBy<TEntity>
|
|
243
238
|
|
|
244
|
-
|
|
245
239
|
export type UniqueWhere<TEntity extends EntityTypeLike> =
|
|
246
240
|
& {
|
|
247
241
|
/**
|
|
@@ -251,7 +245,6 @@ export namespace ContentClientInput {
|
|
|
251
245
|
}
|
|
252
246
|
& TEntity['unique']
|
|
253
247
|
|
|
254
|
-
|
|
255
248
|
export type Where<TEntity extends EntityTypeLike> =
|
|
256
249
|
& {
|
|
257
250
|
/** @internal */
|
|
@@ -270,7 +263,6 @@ export namespace ContentClientInput {
|
|
|
270
263
|
readonly [key in keyof TEntity['hasOne']]?: Where<TEntity['hasOne'][key]> | null
|
|
271
264
|
}
|
|
272
265
|
|
|
273
|
-
|
|
274
266
|
export type AnyOrderBy = Input.OrderBy<`${Input.OrderDirection}`>[]
|
|
275
267
|
export type AnyListQueryInput =
|
|
276
268
|
& Omit<Input.ListQueryInput, 'orderBy'>
|
package/src/types/Result.ts
CHANGED
|
@@ -1,26 +1,58 @@
|
|
|
1
1
|
import { Result } from '@contember/schema'
|
|
2
2
|
|
|
3
|
-
export type
|
|
4
|
-
readonly ok:
|
|
5
|
-
readonly errorMessage:
|
|
3
|
+
export type TransactionOkResult<V> = {
|
|
4
|
+
readonly ok: true
|
|
5
|
+
readonly errorMessage: null
|
|
6
|
+
readonly errors: []
|
|
7
|
+
readonly validation: ValidationOkResult
|
|
8
|
+
readonly data: V
|
|
9
|
+
}
|
|
10
|
+
export type TransactionFailResult<V> = {
|
|
11
|
+
readonly ok: false
|
|
12
|
+
readonly errorMessage: string
|
|
6
13
|
readonly errors: MutationError[]
|
|
7
14
|
readonly validation: ValidationResult
|
|
8
15
|
readonly data: V
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
export type
|
|
18
|
+
export type TransactionResult<V> =
|
|
19
|
+
| TransactionOkResult<V>
|
|
20
|
+
| TransactionFailResult<V>
|
|
21
|
+
|
|
22
|
+
export type MutationOkResult<Value = unknown> = {
|
|
23
|
+
readonly ok: true
|
|
24
|
+
readonly errorMessage: null
|
|
25
|
+
readonly errors: []
|
|
26
|
+
readonly node: Value | null // still may be null
|
|
27
|
+
readonly validation: ValidationOkResult
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type MutationFailResult = {
|
|
12
31
|
readonly ok: boolean
|
|
13
|
-
readonly errorMessage: string
|
|
32
|
+
readonly errorMessage: string
|
|
14
33
|
readonly errors: MutationError[]
|
|
15
|
-
readonly node:
|
|
16
|
-
readonly validation
|
|
34
|
+
readonly node: null
|
|
35
|
+
readonly validation: ValidationResult
|
|
17
36
|
}
|
|
18
37
|
|
|
19
|
-
export type
|
|
20
|
-
|
|
38
|
+
export type MutationResult<Value = unknown> =
|
|
39
|
+
| MutationOkResult<Value>
|
|
40
|
+
| MutationFailResult
|
|
41
|
+
|
|
42
|
+
export type ValidationOkResult = {
|
|
43
|
+
readonly valid: true
|
|
44
|
+
readonly errors: []
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type ValidationFailResult = {
|
|
48
|
+
readonly valid: false
|
|
21
49
|
readonly errors: ValidationError[]
|
|
22
50
|
}
|
|
23
51
|
|
|
52
|
+
export type ValidationResult =
|
|
53
|
+
| ValidationOkResult
|
|
54
|
+
| ValidationFailResult
|
|
55
|
+
|
|
24
56
|
export type ValidationError = {
|
|
25
57
|
readonly path: Path
|
|
26
58
|
readonly message: { text: string }
|
package/src/types/Schema.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { SchemaEntityNames } from '../types'
|
|
2
2
|
import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
|
|
3
3
|
|
|
4
|
-
export const createListArgs = (
|
|
4
|
+
export const createListArgs = (
|
|
5
|
+
entity: SchemaEntityNames<string>,
|
|
6
|
+
args: { filter?: any; orderBy?: any; limit?: number; offset?: number },
|
|
7
|
+
type: 'list' | 'paginate' = 'list',
|
|
8
|
+
): GraphQlFieldTypedArgs => {
|
|
5
9
|
return {
|
|
6
10
|
filter: {
|
|
7
11
|
graphQlType: `${entity.name}Where`,
|
|
@@ -8,7 +8,6 @@ export const createMutationOperationSet = (
|
|
|
8
8
|
| ContentMutation<any>
|
|
9
9
|
| ContentMutation<any>[],
|
|
10
10
|
): ContentOperationSet<any> => {
|
|
11
|
-
|
|
12
11
|
if (input instanceof ContentOperation) {
|
|
13
12
|
return new ContentOperationSet(
|
|
14
13
|
[new GraphQlField('mut', input.fieldName, input.args, input.selection)],
|
|
@@ -32,11 +31,14 @@ export const createMutationOperationSet = (
|
|
|
32
31
|
}
|
|
33
32
|
return new GraphQlField(alias, mutation.fieldName, mutation.args, mutation.selection)
|
|
34
33
|
}),
|
|
35
|
-
res =>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
res =>
|
|
35
|
+
Object.fromEntries(
|
|
36
|
+
Object.entries(input).map(([alias, mutation]) => {
|
|
37
|
+
if (mutation.type === 'query') {
|
|
38
|
+
return [alias, mutation.parse(res[alias]?.value ?? null)]
|
|
39
|
+
}
|
|
40
|
+
return [alias, mutation.parse(res[alias] ?? null)]
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
41
43
|
)
|
|
42
44
|
}
|
|
@@ -5,7 +5,6 @@ import { GraphQlField } from '@contember/graphql-builder'
|
|
|
5
5
|
export const createQueryOperationSet = (
|
|
6
6
|
input: Record<string, ContentQuery<any>> | ContentQuery<any>,
|
|
7
7
|
): ContentOperationSet<any> => {
|
|
8
|
-
|
|
9
8
|
if (input instanceof ContentOperation) {
|
|
10
9
|
return new ContentOperationSet(
|
|
11
10
|
[new GraphQlField('value', input.fieldName, input.args, input.selection)],
|