@contember/client-content 2.1.0-alpha.3 → 2.1.0-alpha.35

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 (149) hide show
  1. package/package.json +6 -6
  2. package/src/ContentClient.ts +36 -9
  3. package/src/ContentQueryBuilder.ts +44 -35
  4. package/src/MutationFailedError.ts +19 -0
  5. package/src/TypedContentQueryBuilder.ts +0 -4
  6. package/src/nodes/ContentEntitySelection.ts +35 -17
  7. package/src/nodes/TypedEntitySelection.ts +96 -48
  8. package/src/types/Input.ts +1 -9
  9. package/src/types/Result.ts +41 -9
  10. package/src/types/Schema.ts +0 -1
  11. package/src/utils/createListArgs.ts +5 -1
  12. package/src/utils/createMutationOperationSet.ts +9 -7
  13. package/src/utils/createQueryOperationSet.ts +0 -1
  14. package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
  15. package/tests/cases/unit/__snapshots__/query.test.ts.snap +200 -60
  16. package/tests/cases/unit/mutation.test.ts +48 -3
  17. package/tests/cases/unit/query.test.ts +91 -66
  18. package/tests/cases/unit/types.test.ts +31 -27
  19. package/tests/client/entities.ts +2 -0
  20. package/tests/client/enums.ts +5 -0
  21. package/tests/client/names.ts +129 -117
  22. package/tests/generate.ts +0 -1
  23. package/tests/lib.ts +0 -1
  24. package/tests/schema.ts +1 -2
  25. package/dist/development/index.cjs +0 -13
  26. package/dist/development/index.cjs.map +0 -1
  27. package/dist/development/index.js +0 -13
  28. package/dist/development/index.js.map +0 -1
  29. package/dist/development/src/ContentClient.cjs +0 -27
  30. package/dist/development/src/ContentClient.cjs.map +0 -1
  31. package/dist/development/src/ContentClient.js +0 -27
  32. package/dist/development/src/ContentClient.js.map +0 -1
  33. package/dist/development/src/ContentQueryBuilder.cjs +0 -175
  34. package/dist/development/src/ContentQueryBuilder.cjs.map +0 -1
  35. package/dist/development/src/ContentQueryBuilder.js +0 -175
  36. package/dist/development/src/ContentQueryBuilder.js.map +0 -1
  37. package/dist/development/src/nodes/ContentEntitySelection.cjs +0 -207
  38. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +0 -1
  39. package/dist/development/src/nodes/ContentEntitySelection.js +0 -207
  40. package/dist/development/src/nodes/ContentEntitySelection.js.map +0 -1
  41. package/dist/development/src/nodes/ContentOperation.cjs +0 -16
  42. package/dist/development/src/nodes/ContentOperation.cjs.map +0 -1
  43. package/dist/development/src/nodes/ContentOperation.js +0 -16
  44. package/dist/development/src/nodes/ContentOperation.js.map +0 -1
  45. package/dist/development/src/utils/ContentOperationSet.cjs +0 -10
  46. package/dist/development/src/utils/ContentOperationSet.cjs.map +0 -1
  47. package/dist/development/src/utils/ContentOperationSet.js +0 -10
  48. package/dist/development/src/utils/ContentOperationSet.js.map +0 -1
  49. package/dist/development/src/utils/createListArgs.cjs +0 -24
  50. package/dist/development/src/utils/createListArgs.cjs.map +0 -1
  51. package/dist/development/src/utils/createListArgs.js +0 -24
  52. package/dist/development/src/utils/createListArgs.js.map +0 -1
  53. package/dist/development/src/utils/createMutationOperationSet.cjs +0 -37
  54. package/dist/development/src/utils/createMutationOperationSet.cjs.map +0 -1
  55. package/dist/development/src/utils/createMutationOperationSet.js +0 -37
  56. package/dist/development/src/utils/createMutationOperationSet.js.map +0 -1
  57. package/dist/development/src/utils/createQueryOperationSet.cjs +0 -19
  58. package/dist/development/src/utils/createQueryOperationSet.cjs.map +0 -1
  59. package/dist/development/src/utils/createQueryOperationSet.js +0 -19
  60. package/dist/development/src/utils/createQueryOperationSet.js.map +0 -1
  61. package/dist/development/src/utils/createTypedArgs.cjs +0 -17
  62. package/dist/development/src/utils/createTypedArgs.cjs.map +0 -1
  63. package/dist/development/src/utils/createTypedArgs.js +0 -17
  64. package/dist/development/src/utils/createTypedArgs.js.map +0 -1
  65. package/dist/development/src/utils/mutationFragments.cjs +0 -55
  66. package/dist/development/src/utils/mutationFragments.cjs.map +0 -1
  67. package/dist/development/src/utils/mutationFragments.js +0 -55
  68. package/dist/development/src/utils/mutationFragments.js.map +0 -1
  69. package/dist/production/index.cjs +0 -13
  70. package/dist/production/index.cjs.map +0 -1
  71. package/dist/production/index.js +0 -13
  72. package/dist/production/index.js.map +0 -1
  73. package/dist/production/src/ContentClient.cjs +0 -27
  74. package/dist/production/src/ContentClient.cjs.map +0 -1
  75. package/dist/production/src/ContentClient.js +0 -27
  76. package/dist/production/src/ContentClient.js.map +0 -1
  77. package/dist/production/src/ContentQueryBuilder.cjs +0 -175
  78. package/dist/production/src/ContentQueryBuilder.cjs.map +0 -1
  79. package/dist/production/src/ContentQueryBuilder.js +0 -175
  80. package/dist/production/src/ContentQueryBuilder.js.map +0 -1
  81. package/dist/production/src/nodes/ContentEntitySelection.cjs +0 -207
  82. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +0 -1
  83. package/dist/production/src/nodes/ContentEntitySelection.js +0 -207
  84. package/dist/production/src/nodes/ContentEntitySelection.js.map +0 -1
  85. package/dist/production/src/nodes/ContentOperation.cjs +0 -16
  86. package/dist/production/src/nodes/ContentOperation.cjs.map +0 -1
  87. package/dist/production/src/nodes/ContentOperation.js +0 -16
  88. package/dist/production/src/nodes/ContentOperation.js.map +0 -1
  89. package/dist/production/src/utils/ContentOperationSet.cjs +0 -10
  90. package/dist/production/src/utils/ContentOperationSet.cjs.map +0 -1
  91. package/dist/production/src/utils/ContentOperationSet.js +0 -10
  92. package/dist/production/src/utils/ContentOperationSet.js.map +0 -1
  93. package/dist/production/src/utils/createListArgs.cjs +0 -24
  94. package/dist/production/src/utils/createListArgs.cjs.map +0 -1
  95. package/dist/production/src/utils/createListArgs.js +0 -24
  96. package/dist/production/src/utils/createListArgs.js.map +0 -1
  97. package/dist/production/src/utils/createMutationOperationSet.cjs +0 -37
  98. package/dist/production/src/utils/createMutationOperationSet.cjs.map +0 -1
  99. package/dist/production/src/utils/createMutationOperationSet.js +0 -37
  100. package/dist/production/src/utils/createMutationOperationSet.js.map +0 -1
  101. package/dist/production/src/utils/createQueryOperationSet.cjs +0 -19
  102. package/dist/production/src/utils/createQueryOperationSet.cjs.map +0 -1
  103. package/dist/production/src/utils/createQueryOperationSet.js +0 -19
  104. package/dist/production/src/utils/createQueryOperationSet.js.map +0 -1
  105. package/dist/production/src/utils/createTypedArgs.cjs +0 -17
  106. package/dist/production/src/utils/createTypedArgs.cjs.map +0 -1
  107. package/dist/production/src/utils/createTypedArgs.js +0 -17
  108. package/dist/production/src/utils/createTypedArgs.js.map +0 -1
  109. package/dist/production/src/utils/mutationFragments.cjs +0 -55
  110. package/dist/production/src/utils/mutationFragments.cjs.map +0 -1
  111. package/dist/production/src/utils/mutationFragments.js +0 -55
  112. package/dist/production/src/utils/mutationFragments.js.map +0 -1
  113. package/dist/types/ContentClient.d.ts +0 -17
  114. package/dist/types/ContentClient.d.ts.map +0 -1
  115. package/dist/types/ContentQueryBuilder.d.ts +0 -27
  116. package/dist/types/ContentQueryBuilder.d.ts.map +0 -1
  117. package/dist/types/TypedContentQueryBuilder.d.ts +0 -21
  118. package/dist/types/TypedContentQueryBuilder.d.ts.map +0 -1
  119. package/dist/types/index.d.ts +0 -7
  120. package/dist/types/index.d.ts.map +0 -1
  121. package/dist/types/nodes/ContentEntitySelection.d.ts +0 -61
  122. package/dist/types/nodes/ContentEntitySelection.d.ts.map +0 -1
  123. package/dist/types/nodes/ContentOperation.d.ts +0 -30
  124. package/dist/types/nodes/ContentOperation.d.ts.map +0 -1
  125. package/dist/types/nodes/TypedEntitySelection.d.ts +0 -53
  126. package/dist/types/nodes/TypedEntitySelection.d.ts.map +0 -1
  127. package/dist/types/nodes/index.d.ts +0 -4
  128. package/dist/types/nodes/index.d.ts.map +0 -1
  129. package/dist/types/tsconfig.tsbuildinfo +0 -1
  130. package/dist/types/types/Input.d.ts +0 -201
  131. package/dist/types/types/Input.d.ts.map +0 -1
  132. package/dist/types/types/Result.d.ts +0 -39
  133. package/dist/types/types/Result.d.ts.map +0 -1
  134. package/dist/types/types/Schema.d.ts +0 -46
  135. package/dist/types/types/Schema.d.ts.map +0 -1
  136. package/dist/types/types/index.d.ts +0 -4
  137. package/dist/types/types/index.d.ts.map +0 -1
  138. package/dist/types/utils/ContentOperationSet.d.ts +0 -13
  139. package/dist/types/utils/ContentOperationSet.d.ts.map +0 -1
  140. package/dist/types/utils/createListArgs.d.ts +0 -9
  141. package/dist/types/utils/createListArgs.d.ts.map +0 -1
  142. package/dist/types/utils/createMutationOperationSet.d.ts +0 -4
  143. package/dist/types/utils/createMutationOperationSet.d.ts.map +0 -1
  144. package/dist/types/utils/createQueryOperationSet.d.ts +0 -4
  145. package/dist/types/utils/createQueryOperationSet.d.ts.map +0 -1
  146. package/dist/types/utils/createTypedArgs.d.ts +0 -3
  147. package/dist/types/utils/createTypedArgs.d.ts.map +0 -1
  148. package/dist/types/utils/mutationFragments.d.ts +0 -3
  149. package/dist/types/utils/mutationFragments.d.ts.map +0 -1
@@ -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 create: CreateDataInput<TEntity>
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'>
@@ -1,26 +1,58 @@
1
1
  import { Result } from '@contember/schema'
2
2
 
3
- export type TransactionResult<V> = {
4
- readonly ok: boolean
5
- readonly errorMessage: string | null
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 MutationResult<Value = unknown> = {
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 | null
32
+ readonly errorMessage: string
14
33
  readonly errors: MutationError[]
15
- readonly node: Value | null
16
- readonly validation?: ValidationResult
34
+ readonly node: null
35
+ readonly validation: ValidationResult
17
36
  }
18
37
 
19
- export type ValidationResult = {
20
- readonly valid: boolean
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 }
@@ -49,4 +49,3 @@ export type SchemaTypeLike = {
49
49
  [entityName: string]: EntityTypeLike
50
50
  }
51
51
  }
52
-
@@ -1,7 +1,11 @@
1
1
  import { SchemaEntityNames } from '../types'
2
2
  import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
3
3
 
4
- export const createListArgs = (entity: SchemaEntityNames<string>, args: { filter?: any; orderBy?: any; limit?: number; offset?: number }, type: 'list' | 'paginate' = 'list'): GraphQlFieldTypedArgs => {
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 => Object.fromEntries(Object.entries(input).map(([alias, mutation]) => {
36
- if (mutation.type === 'query') {
37
- return [alias, mutation.parse(res[alias]?.value ?? null)]
38
- }
39
- return [alias, mutation.parse(res[alias] ?? null)]
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)],