@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contember/client-content",
3
3
  "license": "Apache-2.0",
4
- "version": "2.1.0-alpha.3",
4
+ "version": "2.1.0-alpha.35",
5
5
  "main": "./dist/production/index.js",
6
6
  "exports": {
7
7
  ".": {
@@ -29,17 +29,17 @@
29
29
  "ae:test": "api-extractor run"
30
30
  },
31
31
  "dependencies": {
32
- "@contember/graphql-builder": "2.1.0-alpha.3",
33
- "@contember/graphql-client": "2.1.0-alpha.3",
34
- "@contember/schema": "2.1.0-alpha.3"
32
+ "@contember/graphql-builder": "workspace:*",
33
+ "@contember/graphql-client": "workspace:*",
34
+ "@contember/schema": "workspace:*"
35
35
  },
36
36
  "devDependencies": {
37
- "@contember/client-content-generator": "2.1.0-alpha.3",
37
+ "@contember/client-content-generator": "workspace:*",
38
38
  "expect-type": "^1.1.0"
39
39
  },
40
40
  "repository": {
41
41
  "type": "git",
42
- "url": "https://github.com/contember/interface.git",
42
+ "url": "git+https://github.com/contember/contember.git",
43
43
  "directory": "packages/client-content"
44
44
  }
45
45
  }
@@ -4,10 +4,10 @@ import { GraphQlQueryPrinter } from '@contember/graphql-builder'
4
4
  import { ContentMutation, ContentQuery } from './nodes'
5
5
  import { createMutationOperationSet } from './utils/createMutationOperationSet'
6
6
  import { createQueryOperationSet } from './utils/createQueryOperationSet'
7
+ import { MutationError, ValidationResult } from './types'
8
+ import { MutationFailedError } from './MutationFailedError'
7
9
 
8
-
9
- export type QueryExecutorOptions =
10
- & GraphQlClientRequestOptions
10
+ export type QueryExecutorOptions = GraphQlClientRequestOptions
11
11
 
12
12
  export class ContentClient {
13
13
  constructor(
@@ -15,9 +15,11 @@ export class ContentClient {
15
15
  ) {
16
16
  }
17
17
 
18
-
19
18
  public async query<Value>(query: ContentQuery<Value>, options?: QueryExecutorOptions): Promise<Value>
20
- public async query<Values extends Record<string, any>>(queries: {[K in keyof Values]: ContentQuery<Values[K]>}, options?: QueryExecutorOptions): Promise<Values>
19
+ public async query<Values extends Record<string, any>>(
20
+ queries: { [K in keyof Values]: ContentQuery<Values[K]> },
21
+ options?: QueryExecutorOptions,
22
+ ): Promise<Values>
21
23
  public async query(queries: Record<string, ContentQuery<any>> | ContentQuery<any>, options?: QueryExecutorOptions): Promise<any> {
22
24
  const printer = new GraphQlQueryPrinter()
23
25
  const operationSet = createQueryOperationSet(queries)
@@ -26,10 +28,16 @@ export class ContentClient {
26
28
  return operationSet.parse(result)
27
29
  }
28
30
 
29
- public async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions,): Promise<Value>
30
- public async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions,): Promise<Value[]>
31
- public async mutate<Values extends Record<string, any>>(mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> }, options?: QueryExecutorOptions): Promise<Values>
32
- public async mutate(input: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[], options?: QueryExecutorOptions): Promise<any> {
31
+ public async mutate<Value>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions): Promise<Value>
32
+ public async mutate<Value>(mutations: ContentMutation<Value>[], options?: QueryExecutorOptions): Promise<Value[]>
33
+ public async mutate<Values extends Record<string, any>>(
34
+ mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> },
35
+ options?: QueryExecutorOptions,
36
+ ): Promise<Values>
37
+ public async mutate(
38
+ input: Record<string, ContentMutation<any> | ContentQuery<any>> | ContentMutation<any> | ContentMutation<any>[],
39
+ options?: QueryExecutorOptions,
40
+ ): Promise<any> {
33
41
  const operationSet = createMutationOperationSet(input)
34
42
 
35
43
  const printer = new GraphQlQueryPrinter()
@@ -38,4 +46,23 @@ export class ContentClient {
38
46
 
39
47
  return operationSet.parse(result)
40
48
  }
49
+
50
+ public async mutateOrThrow<
51
+ Value extends {
52
+ readonly ok: boolean
53
+ readonly errorMessage: string | null
54
+ readonly errors: MutationError[]
55
+ readonly validation: ValidationResult
56
+ },
57
+ >(mutation: ContentMutation<Value>, options?: QueryExecutorOptions): Promise<Value & { readonly ok: true; readonly errorMessage: null }> {
58
+ const result = await this.mutate(mutation, options)
59
+ if (!result.ok) {
60
+ throw new MutationFailedError(
61
+ result.errorMessage ?? 'Unknown error',
62
+ mutation as ContentMutation<Value & { readonly ok: false; readonly errorMessage: string }>,
63
+ result as Value & { readonly ok: false; readonly errorMessage: string },
64
+ )
65
+ }
66
+ return result as Value & { readonly ok: true; readonly errorMessage: null }
67
+ }
41
68
  }
@@ -1,5 +1,12 @@
1
1
  import { ContentClientInput, MutationResult, SchemaNames, TransactionResult } from './types'
2
- import { ContentEntitySelection, ContentEntitySelectionCallback, ContentEntitySelectionContext, ContentMutation, ContentOperation, ContentQuery } from './nodes'
2
+ import {
3
+ ContentEntitySelection,
4
+ ContentEntitySelectionCallback,
5
+ ContentEntitySelectionContext,
6
+ ContentMutation,
7
+ ContentOperation,
8
+ ContentQuery,
9
+ } from './nodes'
3
10
  import { createListArgs } from './utils/createListArgs'
4
11
  import { createTypedArgs } from './utils/createTypedArgs'
5
12
  import { Input } from '@contember/schema'
@@ -21,7 +28,6 @@ export class ContentQueryBuilder {
21
28
  constructor(private readonly schema: SchemaNames) {
22
29
  }
23
30
 
24
-
25
31
  public fragment(name: string, fieldsCallback?: ContentEntitySelectionCallback): ContentEntitySelection {
26
32
  const context = this.createContext(name)
27
33
 
@@ -32,8 +38,6 @@ export class ContentQueryBuilder {
32
38
  return fieldsCallback(entitySelection)
33
39
  }
34
40
 
35
-
36
-
37
41
  public count(name: string, args: Pick<ContentClientInput.AnyListQueryInput, 'filter'>): ContentQuery<number> {
38
42
  const context = this.createContext(name)
39
43
  const fieldName = `paginate${name}`
@@ -51,7 +55,6 @@ export class ContentQueryBuilder {
51
55
  })
52
56
  }
53
57
 
54
-
55
58
  public list(name: string, args: ContentClientInput.AnyListQueryInput, fields: EntitySelectionOrCallback): ContentQuery<any[]> {
56
59
  const context = this.createContext(name)
57
60
  const fieldName = `list${name}`
@@ -61,15 +64,16 @@ export class ContentQueryBuilder {
61
64
  return new ContentOperation('query', fieldName, typedArgs, selection.selectionSet, it => {
62
65
  const transformFn = selection.transformFn
63
66
  if (transformFn) {
64
- return it.map((el: any) => transformFn(el, {
65
- rootValue: it,
66
- }))
67
+ return it.map((el: any) =>
68
+ transformFn(el, {
69
+ rootValue: it,
70
+ })
71
+ )
67
72
  }
68
73
  return it
69
74
  })
70
75
  }
71
76
 
72
-
73
77
  public get(name: string, args: Input.UniqueQueryInput, fields: EntitySelectionOrCallback): ContentQuery<Record<string, unknown> | null> {
74
78
  const context = this.createContext(name)
75
79
  const fieldName = `get${name}`
@@ -89,9 +93,7 @@ export class ContentQueryBuilder {
89
93
  })
90
94
  }
91
95
 
92
-
93
96
  public create(name: string, args: Input.CreateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
94
-
95
97
  const entity = this.getEntity(name)
96
98
  const typedArgs = createTypedArgs(args, {
97
99
  data: `${entity.name}CreateInput!`,
@@ -101,7 +103,6 @@ export class ContentQueryBuilder {
101
103
  }
102
104
 
103
105
  public update(name: string, args: Input.UpdateInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
104
-
105
106
  const entity = this.getEntity(name)
106
107
  const typedArgs = createTypedArgs(args, {
107
108
  data: `${entity.name}UpdateInput!`,
@@ -111,9 +112,7 @@ export class ContentQueryBuilder {
111
112
  return this.createMutationOperation(name, 'update', typedArgs, fields)
112
113
  }
113
114
 
114
-
115
115
  public upsert(name: string, args: Input.UpsertInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
116
-
117
116
  const entity = this.getEntity(name)
118
117
  const typedArgs = createTypedArgs(args, {
119
118
  update: `${entity.name}UpdateInput!`,
@@ -124,9 +123,7 @@ export class ContentQueryBuilder {
124
123
  return this.createMutationOperation(name, 'upsert', typedArgs, fields)
125
124
  }
126
125
 
127
-
128
126
  public delete(name: string, args: Input.UniqueQueryInput, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
129
-
130
127
  const entity = this.getEntity(name)
131
128
  const typedArgs = createTypedArgs(args, {
132
129
  by: `${entity.name}UniqueWhere!`,
@@ -135,9 +132,12 @@ export class ContentQueryBuilder {
135
132
  return this.createMutationOperation(name, 'delete', typedArgs, fields)
136
133
  }
137
134
 
138
-
139
- private createMutationOperation(name: string, operation: MutationOperation, args: GraphQlFieldTypedArgs, fields?: EntitySelectionOrCallback): ContentMutation<MutationResult> {
140
-
135
+ private createMutationOperation(
136
+ name: string,
137
+ operation: MutationOperation,
138
+ args: GraphQlFieldTypedArgs,
139
+ fields?: EntitySelectionOrCallback,
140
+ ): ContentMutation<MutationResult> {
141
141
  const context = this.createContext(name)
142
142
  const fieldName = `${operation}${name}`
143
143
  const nodeSelection = fields ? this.resolveSelection(fields, context) : undefined
@@ -149,9 +149,11 @@ export class ContentQueryBuilder {
149
149
  }
150
150
  return {
151
151
  ...it,
152
- node: it.node ? nodeSelection.transformFn(it.node, {
153
- rootValue: it.node,
154
- }) : null,
152
+ node: it.node
153
+ ? nodeSelection.transformFn(it.node, {
154
+ rootValue: it.node,
155
+ })
156
+ : null,
155
157
  }
156
158
  })
157
159
  }
@@ -169,15 +171,21 @@ export class ContentQueryBuilder {
169
171
  ...this.createMutationSelection('transaction'),
170
172
  ...combined.selection,
171
173
  ]
172
- return new ContentOperation<TransactionResult<any>, 'mutation'>('mutation', 'transaction', transactionArgs, items, ({ ok, errorMessage, errors, validation, ...data }) => {
173
- return {
174
- ok,
175
- errorMessage,
176
- errors,
177
- validation,
178
- data: combined.parse(data),
179
- }
180
- })
174
+ return new ContentOperation<TransactionResult<any>, 'mutation'>(
175
+ 'mutation',
176
+ 'transaction',
177
+ transactionArgs,
178
+ items,
179
+ ({ ok, errorMessage, errors, validation, ...data }) => {
180
+ return {
181
+ ok,
182
+ errorMessage,
183
+ errors,
184
+ validation,
185
+ data: combined.parse(data),
186
+ }
187
+ },
188
+ )
181
189
  }
182
190
 
183
191
  private createMutationSelection(operation: MutationOperation, selection?: GraphQlSelectionSet): GraphQlSelectionSet {
@@ -189,9 +197,11 @@ export class ContentQueryBuilder {
189
197
  ]),
190
198
  ]
191
199
  if (operation !== 'delete') {
192
- items.push(new GraphQlField(null, 'validation', {}, [
193
- new GraphQlFragmentSpread('ValidationResult'),
194
- ]))
200
+ items.push(
201
+ new GraphQlField(null, 'validation', {}, [
202
+ new GraphQlFragmentSpread('ValidationResult'),
203
+ ]),
204
+ )
195
205
  }
196
206
  if (selection) {
197
207
  items.push(new GraphQlField(null, 'node', {}, selection))
@@ -199,7 +209,6 @@ export class ContentQueryBuilder {
199
209
  return items
200
210
  }
201
211
 
202
-
203
212
  private resolveSelection(
204
213
  fields: EntitySelectionOrCallback,
205
214
  context: ContentEntitySelectionContext<string>,
@@ -0,0 +1,19 @@
1
+ import { MutationError, ValidationResult } from './types'
2
+ import { ContentMutation } from './nodes'
3
+
4
+ export class MutationFailedError<
5
+ Value extends {
6
+ readonly ok: false
7
+ readonly errorMessage: string
8
+ readonly errors: MutationError[]
9
+ readonly validation: ValidationResult
10
+ },
11
+ > extends Error {
12
+ constructor(
13
+ message: string,
14
+ public readonly request: ContentMutation<Value>,
15
+ public readonly result: Value,
16
+ ) {
17
+ super(message)
18
+ }
19
+ }
@@ -2,14 +2,11 @@ import { ContentClientInput, MutationResult, SchemaTypeLike, TransactionResult }
2
2
  import { ContentMutation, ContentQuery, TypedEntitySelection, TypedEntitySelectionCallback } from './nodes'
3
3
  import { MutationTransactionOptions } from './ContentQueryBuilder'
4
4
 
5
-
6
5
  export type TypedContentEntitySelectionOrCallback<TSchema extends SchemaTypeLike, TEntityName extends keyof TSchema['entities'] & string, TValue> =
7
6
  | TypedEntitySelection<TSchema, TEntityName, TSchema['entities'][TEntityName], TValue>
8
7
  | TypedEntitySelectionCallback<TSchema, TEntityName, TSchema['entities'][TEntityName], TValue>
9
8
 
10
-
11
9
  export interface TypedContentQueryBuilder<TSchema extends SchemaTypeLike> {
12
-
13
10
  fragment<EntityName extends keyof TSchema['entities'] & string>(
14
11
  name: EntityName,
15
12
  ): TypedEntitySelection<TSchema, EntityName, TSchema['entities'][EntityName], {}>
@@ -73,4 +70,3 @@ export interface TypedContentQueryBuilder<TSchema extends SchemaTypeLike> {
73
70
  options?: MutationTransactionOptions,
74
71
  ): ContentMutation<TransactionResult<Values>>
75
72
  }
76
-
@@ -14,8 +14,12 @@ export type ContentEntitySelectionContext<Name extends string> = {
14
14
  export type ContentEntitySelectionCallback = (select: ContentEntitySelection) => ContentEntitySelection
15
15
 
16
16
  export type EntitySelectionCommonInput<Alias extends string | null = string | null> = { as?: Alias }
17
- export type EntitySelectionManyArgs<Alias extends string | null = string | null> = ContentClientInput.AnyListQueryInput & EntitySelectionCommonInput<Alias>
18
- export type EntitySelectionManyByArgs<Alias extends string | null = string | null> = { by: Input.UniqueWhere; filter?: Input.Where } & EntitySelectionCommonInput<Alias>
17
+ export type EntitySelectionManyArgs<Alias extends string | null = string | null> =
18
+ & ContentClientInput.AnyListQueryInput
19
+ & EntitySelectionCommonInput<Alias>
20
+ export type EntitySelectionManyByArgs<Alias extends string | null = string | null> =
21
+ & { by: Input.UniqueWhere; filter?: Input.Where }
22
+ & EntitySelectionCommonInput<Alias>
19
23
  export type EntitySelectionOneArgs<Alias extends string | null = string | null> = { filter?: Input.Where } & EntitySelectionCommonInput<Alias>
20
24
  export type EntitySelectionColumnArgs<Alias extends string | null = string | null> = EntitySelectionCommonInput<Alias>
21
25
 
@@ -27,13 +31,11 @@ export type EntitySelectionAnyArgs =
27
31
 
28
32
  export type ContentEntitySelectionOrCallback = ContentEntitySelectionCallback | ContentEntitySelection
29
33
 
30
-
31
34
  export type ContentTransformContext = {
32
35
  rootValue: unknown
33
36
  }
34
37
 
35
38
  export class ContentEntitySelection {
36
-
37
39
  /**
38
40
  * @internal
39
41
  */
@@ -47,14 +49,17 @@ export class ContentEntitySelection {
47
49
  ) {
48
50
  }
49
51
 
50
-
51
52
  $(field: string, args?: EntitySelectionColumnArgs): ContentEntitySelection
52
53
  $(field: string, args: EntitySelectionManyArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
53
54
  $(field: string, args: EntitySelectionManyByArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
54
55
  $(field: string, args: EntitySelectionOneArgs, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
55
56
  $(field: string, selection: ContentEntitySelectionOrCallback): ContentEntitySelection
56
57
 
57
- $(field: string, argsOrSelection?: EntitySelectionAnyArgs | ContentEntitySelectionOrCallback, selectionIn?: ContentEntitySelectionOrCallback): ContentEntitySelection {
58
+ $(
59
+ field: string,
60
+ argsOrSelection?: EntitySelectionAnyArgs | ContentEntitySelectionOrCallback,
61
+ selectionIn?: ContentEntitySelectionOrCallback,
62
+ ): ContentEntitySelection {
58
63
  const [args, selection] = typeof argsOrSelection === 'function' || argsOrSelection instanceof ContentEntitySelection
59
64
  ? [{}, argsOrSelection]
60
65
  : [argsOrSelection ?? {}, selectionIn]
@@ -99,6 +104,19 @@ export class ContentEntitySelection {
99
104
  return new ContentEntitySelection(this.context, nodes)
100
105
  }
101
106
 
107
+ omit(...fields: string[]): ContentEntitySelection {
108
+ return new ContentEntitySelection(
109
+ this.context,
110
+ this.selectionSet.filter(it => {
111
+ if (!(it instanceof GraphQlField)) {
112
+ return true
113
+ }
114
+ const alias = it.alias ?? it.name
115
+ return !fields.includes(alias)
116
+ }),
117
+ )
118
+ }
119
+
102
120
  meta(field: string, flags: ('readable' | 'updatable')[]): ContentEntitySelection {
103
121
  const metaField = this.selectionSet.find((it): it is GraphQlField => it instanceof GraphQlField && it.name === '_meta')
104
122
  const selectionWithoutMeta = metaField ? this.selectionSet.filter(it => it !== metaField) : this.selectionSet
@@ -117,11 +135,14 @@ export class ContentEntitySelection {
117
135
  ])
118
136
  }
119
137
 
120
-
121
138
  transform(transform: (value: any, context: ContentTransformContext) => any): ContentEntitySelection {
122
- return new ContentEntitySelection(this.context, this.selectionSet, !this.transformFn ? transform : (value, ctx) => {
123
- return transform(this.transformFn!(value, ctx), ctx)
124
- })
139
+ return new ContentEntitySelection(
140
+ this.context,
141
+ this.selectionSet,
142
+ !this.transformFn ? transform : (value, ctx) => {
143
+ return transform(this.transformFn!(value, ctx), ctx)
144
+ },
145
+ )
125
146
  }
126
147
 
127
148
  private _column(
@@ -142,14 +163,13 @@ export class ContentEntitySelection {
142
163
  return this.withField(field)
143
164
  }
144
165
 
145
-
146
166
  private _many(
147
167
  name: string,
148
168
  args: EntitySelectionManyArgs,
149
169
  fields:
150
170
  | ContentEntitySelectionCallback
151
171
  | ContentEntitySelection,
152
- ): ContentEntitySelection{
172
+ ): ContentEntitySelection {
153
173
  const alias = args.as ?? name
154
174
  const fieldInfo = this.context.entity.fields[name]
155
175
  if (!fieldInfo) {
@@ -177,10 +197,9 @@ export class ContentEntitySelection {
177
197
  if (!nestedTransform) {
178
198
  return selectionWithField
179
199
  }
180
- return this.withFieldTransform(alias, it => it.map(nestedTransform))
200
+ return selectionWithField.withFieldTransform(alias, it => it.map(nestedTransform))
181
201
  }
182
202
 
183
-
184
203
  private _manyBy(
185
204
  name: string,
186
205
  args: EntitySelectionManyByArgs,
@@ -229,7 +248,7 @@ export class ContentEntitySelection {
229
248
  if (!nestedTransform) {
230
249
  return selectionWithField
231
250
  }
232
- return this.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
251
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
233
252
  }
234
253
 
235
254
  private _one(
@@ -273,10 +292,9 @@ export class ContentEntitySelection {
273
292
  if (!nestedTransform) {
274
293
  return selectionWithField
275
294
  }
276
- return this.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
295
+ return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
277
296
  }
278
297
 
279
-
280
298
  private withField(field: GraphQlField) {
281
299
  return new ContentEntitySelection(this.context, [
282
300
  ...this.selectionSet,
@@ -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<TSchema, TEntityName, TEntity, TValue & {
12
- [key in keyof TEntity['columns']]: TEntity['columns'][key]
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<TSchema, TEntityName, TEntity, TValue & {
26
- [key in TAlias extends null ? TKey : TAlias]: TypedEntitySelectionResult<TEntity, TKey, TNestedValue>
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasMany'] & string, TNestedValue> =
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasMany'] & string, TNestedValue, TAlias extends string | null = null> =
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
- args: TypedHasManyArgs<TEntity, TKey, TAlias>,
58
- fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
78
+ args: TypedHasManyArgs<TEntity, TKey, TAlias>,
79
+ fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
59
80
  ]
60
81
  | [
61
- fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
82
+ fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
62
83
  ]
63
84
 
64
-
65
- export type TypedHasManyByArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasManyBy'] & string, TAlias extends string | null = null> =
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasManyBy'] & string, TNestedValue> =
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasManyBy'] & string, TNestedValue, TAlias extends string | null = null> =
74
- | [
75
- args: TypedHasManyByArgs<TEntity, TKey, TAlias>,
76
- fields: TypedHasManyByFields<TSchema, TEntity, TKey, TNestedValue>
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasOne'] & string, TNestedValue> =
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<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasOne'] & string, TNestedValue, TAlias extends string | null = null> =
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
- args: TypedHasOneArgs<TEntity, TKey, TAlias>,
91
- fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>
134
+ args: TypedHasOneArgs<TEntity, TKey, TAlias>,
135
+ fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
92
136
  ]
93
137
  | [
94
- fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>
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
- args: TypedColumnArgs<TAlias>
144
+ args: TypedColumnArgs<TAlias>,
102
145
  ]
103
146
  | []
104
147
 
105
- export type TypedEntitySelectionParams<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends string, TNestedValue, TAlias extends string | null = null> =
106
- TKey extends keyof TEntity['columns'] ? TypedColumnParams<TAlias>
107
- : TKey extends keyof TEntity['hasMany'] ? TypedHasManyParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
108
- : TKey extends keyof TEntity['hasManyBy'] ? TypedHasManyByParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
109
- : TKey extends keyof TEntity['hasOne'] ? TypedHasOneParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
110
- : never
111
-
112
- export type TypedEntitySelectionResult<TEntity extends EntityTypeLike, TKey extends string, TValue> =
113
- TKey extends keyof TEntity['columns'] ? TEntity['columns'][TKey]
114
- : TKey extends keyof TEntity['hasMany'] ? TValue[]
115
- : TKey extends keyof TEntity['hasManyBy'] ? null | TValue
116
- : TKey extends keyof TEntity['hasOne'] ? null | TValue
117
- : never
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