@contember/client-content 2.1.0-alpha.30 → 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 (158) hide show
  1. package/package.json +6 -6
  2. package/src/ContentClient.ts +23 -16
  3. package/src/ContentQueryBuilder.ts +44 -35
  4. package/src/MutationFailedError.ts +8 -6
  5. package/src/TypedContentQueryBuilder.ts +0 -4
  6. package/src/nodes/ContentEntitySelection.ts +19 -14
  7. package/src/nodes/TypedEntitySelection.ts +92 -48
  8. package/src/types/Input.ts +1 -9
  9. package/src/types/Schema.ts +0 -1
  10. package/src/utils/createListArgs.ts +5 -1
  11. package/src/utils/createMutationOperationSet.ts +9 -7
  12. package/src/utils/createQueryOperationSet.ts +0 -1
  13. package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +814 -878
  14. package/tests/cases/unit/__snapshots__/query.test.ts.snap +84 -77
  15. package/tests/cases/unit/mutation.test.ts +0 -4
  16. package/tests/cases/unit/query.test.ts +62 -67
  17. package/tests/cases/unit/types.test.ts +26 -28
  18. package/tests/client/entities.ts +2 -0
  19. package/tests/client/enums.ts +5 -0
  20. package/tests/client/names.ts +129 -117
  21. package/tests/generate.ts +0 -1
  22. package/tests/lib.ts +0 -1
  23. package/tests/schema.ts +1 -2
  24. package/dist/development/index.cjs +0 -13
  25. package/dist/development/index.cjs.map +0 -1
  26. package/dist/development/index.js +0 -13
  27. package/dist/development/index.js.map +0 -1
  28. package/dist/development/src/ContentClient.cjs +0 -39
  29. package/dist/development/src/ContentClient.cjs.map +0 -1
  30. package/dist/development/src/ContentClient.js +0 -39
  31. package/dist/development/src/ContentClient.js.map +0 -1
  32. package/dist/development/src/ContentQueryBuilder.cjs +0 -175
  33. package/dist/development/src/ContentQueryBuilder.cjs.map +0 -1
  34. package/dist/development/src/ContentQueryBuilder.js +0 -175
  35. package/dist/development/src/ContentQueryBuilder.js.map +0 -1
  36. package/dist/development/src/MutationFailedError.cjs +0 -11
  37. package/dist/development/src/MutationFailedError.cjs.map +0 -1
  38. package/dist/development/src/MutationFailedError.js +0 -11
  39. package/dist/development/src/MutationFailedError.js.map +0 -1
  40. package/dist/development/src/nodes/ContentEntitySelection.cjs +0 -219
  41. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +0 -1
  42. package/dist/development/src/nodes/ContentEntitySelection.js +0 -219
  43. package/dist/development/src/nodes/ContentEntitySelection.js.map +0 -1
  44. package/dist/development/src/nodes/ContentOperation.cjs +0 -16
  45. package/dist/development/src/nodes/ContentOperation.cjs.map +0 -1
  46. package/dist/development/src/nodes/ContentOperation.js +0 -16
  47. package/dist/development/src/nodes/ContentOperation.js.map +0 -1
  48. package/dist/development/src/utils/ContentOperationSet.cjs +0 -10
  49. package/dist/development/src/utils/ContentOperationSet.cjs.map +0 -1
  50. package/dist/development/src/utils/ContentOperationSet.js +0 -10
  51. package/dist/development/src/utils/ContentOperationSet.js.map +0 -1
  52. package/dist/development/src/utils/createListArgs.cjs +0 -24
  53. package/dist/development/src/utils/createListArgs.cjs.map +0 -1
  54. package/dist/development/src/utils/createListArgs.js +0 -24
  55. package/dist/development/src/utils/createListArgs.js.map +0 -1
  56. package/dist/development/src/utils/createMutationOperationSet.cjs +0 -37
  57. package/dist/development/src/utils/createMutationOperationSet.cjs.map +0 -1
  58. package/dist/development/src/utils/createMutationOperationSet.js +0 -37
  59. package/dist/development/src/utils/createMutationOperationSet.js.map +0 -1
  60. package/dist/development/src/utils/createQueryOperationSet.cjs +0 -19
  61. package/dist/development/src/utils/createQueryOperationSet.cjs.map +0 -1
  62. package/dist/development/src/utils/createQueryOperationSet.js +0 -19
  63. package/dist/development/src/utils/createQueryOperationSet.js.map +0 -1
  64. package/dist/development/src/utils/createTypedArgs.cjs +0 -17
  65. package/dist/development/src/utils/createTypedArgs.cjs.map +0 -1
  66. package/dist/development/src/utils/createTypedArgs.js +0 -17
  67. package/dist/development/src/utils/createTypedArgs.js.map +0 -1
  68. package/dist/development/src/utils/mutationFragments.cjs +0 -55
  69. package/dist/development/src/utils/mutationFragments.cjs.map +0 -1
  70. package/dist/development/src/utils/mutationFragments.js +0 -55
  71. package/dist/development/src/utils/mutationFragments.js.map +0 -1
  72. package/dist/production/index.cjs +0 -13
  73. package/dist/production/index.cjs.map +0 -1
  74. package/dist/production/index.js +0 -13
  75. package/dist/production/index.js.map +0 -1
  76. package/dist/production/src/ContentClient.cjs +0 -39
  77. package/dist/production/src/ContentClient.cjs.map +0 -1
  78. package/dist/production/src/ContentClient.js +0 -39
  79. package/dist/production/src/ContentClient.js.map +0 -1
  80. package/dist/production/src/ContentQueryBuilder.cjs +0 -175
  81. package/dist/production/src/ContentQueryBuilder.cjs.map +0 -1
  82. package/dist/production/src/ContentQueryBuilder.js +0 -175
  83. package/dist/production/src/ContentQueryBuilder.js.map +0 -1
  84. package/dist/production/src/MutationFailedError.cjs +0 -11
  85. package/dist/production/src/MutationFailedError.cjs.map +0 -1
  86. package/dist/production/src/MutationFailedError.js +0 -11
  87. package/dist/production/src/MutationFailedError.js.map +0 -1
  88. package/dist/production/src/nodes/ContentEntitySelection.cjs +0 -219
  89. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +0 -1
  90. package/dist/production/src/nodes/ContentEntitySelection.js +0 -219
  91. package/dist/production/src/nodes/ContentEntitySelection.js.map +0 -1
  92. package/dist/production/src/nodes/ContentOperation.cjs +0 -16
  93. package/dist/production/src/nodes/ContentOperation.cjs.map +0 -1
  94. package/dist/production/src/nodes/ContentOperation.js +0 -16
  95. package/dist/production/src/nodes/ContentOperation.js.map +0 -1
  96. package/dist/production/src/utils/ContentOperationSet.cjs +0 -10
  97. package/dist/production/src/utils/ContentOperationSet.cjs.map +0 -1
  98. package/dist/production/src/utils/ContentOperationSet.js +0 -10
  99. package/dist/production/src/utils/ContentOperationSet.js.map +0 -1
  100. package/dist/production/src/utils/createListArgs.cjs +0 -24
  101. package/dist/production/src/utils/createListArgs.cjs.map +0 -1
  102. package/dist/production/src/utils/createListArgs.js +0 -24
  103. package/dist/production/src/utils/createListArgs.js.map +0 -1
  104. package/dist/production/src/utils/createMutationOperationSet.cjs +0 -37
  105. package/dist/production/src/utils/createMutationOperationSet.cjs.map +0 -1
  106. package/dist/production/src/utils/createMutationOperationSet.js +0 -37
  107. package/dist/production/src/utils/createMutationOperationSet.js.map +0 -1
  108. package/dist/production/src/utils/createQueryOperationSet.cjs +0 -19
  109. package/dist/production/src/utils/createQueryOperationSet.cjs.map +0 -1
  110. package/dist/production/src/utils/createQueryOperationSet.js +0 -19
  111. package/dist/production/src/utils/createQueryOperationSet.js.map +0 -1
  112. package/dist/production/src/utils/createTypedArgs.cjs +0 -17
  113. package/dist/production/src/utils/createTypedArgs.cjs.map +0 -1
  114. package/dist/production/src/utils/createTypedArgs.js +0 -17
  115. package/dist/production/src/utils/createTypedArgs.js.map +0 -1
  116. package/dist/production/src/utils/mutationFragments.cjs +0 -55
  117. package/dist/production/src/utils/mutationFragments.cjs.map +0 -1
  118. package/dist/production/src/utils/mutationFragments.js +0 -55
  119. package/dist/production/src/utils/mutationFragments.js.map +0 -1
  120. package/dist/types/ContentClient.d.ts +0 -27
  121. package/dist/types/ContentClient.d.ts.map +0 -1
  122. package/dist/types/ContentQueryBuilder.d.ts +0 -27
  123. package/dist/types/ContentQueryBuilder.d.ts.map +0 -1
  124. package/dist/types/MutationFailedError.d.ts +0 -13
  125. package/dist/types/MutationFailedError.d.ts.map +0 -1
  126. package/dist/types/TypedContentQueryBuilder.d.ts +0 -21
  127. package/dist/types/TypedContentQueryBuilder.d.ts.map +0 -1
  128. package/dist/types/index.d.ts +0 -7
  129. package/dist/types/index.d.ts.map +0 -1
  130. package/dist/types/nodes/ContentEntitySelection.d.ts +0 -62
  131. package/dist/types/nodes/ContentEntitySelection.d.ts.map +0 -1
  132. package/dist/types/nodes/ContentOperation.d.ts +0 -30
  133. package/dist/types/nodes/ContentOperation.d.ts.map +0 -1
  134. package/dist/types/nodes/TypedEntitySelection.d.ts +0 -54
  135. package/dist/types/nodes/TypedEntitySelection.d.ts.map +0 -1
  136. package/dist/types/nodes/index.d.ts +0 -4
  137. package/dist/types/nodes/index.d.ts.map +0 -1
  138. package/dist/types/tsconfig.tsbuildinfo +0 -1
  139. package/dist/types/types/Input.d.ts +0 -201
  140. package/dist/types/types/Input.d.ts.map +0 -1
  141. package/dist/types/types/Result.d.ts +0 -60
  142. package/dist/types/types/Result.d.ts.map +0 -1
  143. package/dist/types/types/Schema.d.ts +0 -46
  144. package/dist/types/types/Schema.d.ts.map +0 -1
  145. package/dist/types/types/index.d.ts +0 -4
  146. package/dist/types/types/index.d.ts.map +0 -1
  147. package/dist/types/utils/ContentOperationSet.d.ts +0 -13
  148. package/dist/types/utils/ContentOperationSet.d.ts.map +0 -1
  149. package/dist/types/utils/createListArgs.d.ts +0 -9
  150. package/dist/types/utils/createListArgs.d.ts.map +0 -1
  151. package/dist/types/utils/createMutationOperationSet.d.ts +0 -4
  152. package/dist/types/utils/createMutationOperationSet.d.ts.map +0 -1
  153. package/dist/types/utils/createQueryOperationSet.d.ts +0 -4
  154. package/dist/types/utils/createQueryOperationSet.d.ts.map +0 -1
  155. package/dist/types/utils/createTypedArgs.d.ts +0 -3
  156. package/dist/types/utils/createTypedArgs.d.ts.map +0 -1
  157. package/dist/types/utils/mutationFragments.d.ts +0 -3
  158. 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.30",
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.30",
33
- "@contember/graphql-client": "2.1.0-alpha.30",
34
- "@contember/schema": "2.1.0-alpha.30"
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.30",
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
  }
@@ -7,9 +7,7 @@ import { createQueryOperationSet } from './utils/createQueryOperationSet'
7
7
  import { MutationError, ValidationResult } from './types'
8
8
  import { MutationFailedError } from './MutationFailedError'
9
9
 
10
-
11
- export type QueryExecutorOptions =
12
- & GraphQlClientRequestOptions
10
+ export type QueryExecutorOptions = GraphQlClientRequestOptions
13
11
 
14
12
  export class ContentClient {
15
13
  constructor(
@@ -17,9 +15,11 @@ export class ContentClient {
17
15
  ) {
18
16
  }
19
17
 
20
-
21
18
  public async query<Value>(query: ContentQuery<Value>, options?: QueryExecutorOptions): Promise<Value>
22
- 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>
23
23
  public async query(queries: Record<string, ContentQuery<any>> | ContentQuery<any>, options?: QueryExecutorOptions): Promise<any> {
24
24
  const printer = new GraphQlQueryPrinter()
25
25
  const operationSet = createQueryOperationSet(queries)
@@ -28,10 +28,16 @@ export class ContentClient {
28
28
  return operationSet.parse(result)
29
29
  }
30
30
 
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>>(mutations: { [K in keyof Values]: ContentMutation<Values[K]> | ContentQuery<Values[K]> }, options?: QueryExecutorOptions): Promise<Values>
34
- 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> {
35
41
  const operationSet = createMutationOperationSet(input)
36
42
 
37
43
  const printer = new GraphQlQueryPrinter()
@@ -41,13 +47,14 @@ export class ContentClient {
41
47
  return operationSet.parse(result)
42
48
  }
43
49
 
44
-
45
- public async mutateOrThrow<Value extends {
46
- readonly ok: boolean
47
- readonly errorMessage: string | null
48
- readonly errors: MutationError[]
49
- readonly validation: ValidationResult
50
- }>(mutation: ContentMutation<Value>, options?: QueryExecutorOptions): Promise<Value & { readonly ok: true; readonly errorMessage: null }> {
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 }> {
51
58
  const result = await this.mutate(mutation, options)
52
59
  if (!result.ok) {
53
60
  throw new MutationFailedError(
@@ -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>,
@@ -1,12 +1,14 @@
1
1
  import { MutationError, ValidationResult } from './types'
2
2
  import { ContentMutation } from './nodes'
3
3
 
4
- export class MutationFailedError<Value extends {
5
- readonly ok: false
6
- readonly errorMessage: string
7
- readonly errors: MutationError[]
8
- readonly validation: ValidationResult
9
- }> extends Error {
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 {
10
12
  constructor(
11
13
  message: string,
12
14
  public readonly request: ContentMutation<Value>,
@@ -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]
@@ -130,11 +135,14 @@ export class ContentEntitySelection {
130
135
  ])
131
136
  }
132
137
 
133
-
134
138
  transform(transform: (value: any, context: ContentTransformContext) => any): ContentEntitySelection {
135
- return new ContentEntitySelection(this.context, this.selectionSet, !this.transformFn ? transform : (value, ctx) => {
136
- return transform(this.transformFn!(value, ctx), ctx)
137
- })
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
+ )
138
146
  }
139
147
 
140
148
  private _column(
@@ -155,14 +163,13 @@ export class ContentEntitySelection {
155
163
  return this.withField(field)
156
164
  }
157
165
 
158
-
159
166
  private _many(
160
167
  name: string,
161
168
  args: EntitySelectionManyArgs,
162
169
  fields:
163
170
  | ContentEntitySelectionCallback
164
171
  | ContentEntitySelection,
165
- ): ContentEntitySelection{
172
+ ): ContentEntitySelection {
166
173
  const alias = args.as ?? name
167
174
  const fieldInfo = this.context.entity.fields[name]
168
175
  if (!fieldInfo) {
@@ -193,7 +200,6 @@ export class ContentEntitySelection {
193
200
  return selectionWithField.withFieldTransform(alias, it => it.map(nestedTransform))
194
201
  }
195
202
 
196
-
197
203
  private _manyBy(
198
204
  name: string,
199
205
  args: EntitySelectionManyByArgs,
@@ -289,7 +295,6 @@ export class ContentEntitySelection {
289
295
  return selectionWithField.withFieldTransform(alias, (it, ctx) => it !== null ? nestedTransform(it, ctx) : null)
290
296
  }
291
297
 
292
-
293
298
  private withField(field: GraphQlField) {
294
299
  return new ContentEntitySelection(this.context, [
295
300
  ...this.selectionSet,
@@ -2,42 +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
+ ): TypedEntitySelection<
29
+ TSchema,
30
+ TEntityName,
31
+ TEntity,
32
+ & TValue
33
+ & {
34
+ [key in TAlias extends null ? TKey : TAlias]: TypedEntitySelectionResult<TEntity, TKey, TNestedValue>
35
+ }
36
+ >
28
37
 
29
38
  omit<TField extends keyof TValue>(
30
39
  ...fields: TField[]
31
40
  ): TypedEntitySelection<TSchema, TEntityName, TEntity, Omit<TValue, TField>>
32
41
 
33
-
34
42
  meta<
35
- TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne'])
43
+ TField extends (keyof TEntity['columns'] | keyof TEntity['hasMany'] | keyof TEntity['hasOne']),
36
44
  >(
37
45
  field: TField,
38
46
  flags: ('readable' | 'updatable')[],
39
47
  ): TypedEntitySelection<TSchema, TEntityName, TEntity, TValue>
40
-
41
48
  }
42
49
 
43
50
  export type TypedEntitySelectionCallback<
@@ -47,75 +54,112 @@ export type TypedEntitySelectionCallback<
47
54
  TValue,
48
55
  > = (select: TypedEntitySelection<TSchema, EntityName, TEntity, {}>) => TypedEntitySelection<TSchema, EntityName, TEntity, TValue>
49
56
 
50
-
51
57
  export type TypedHasManyArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasMany'] & string, TAlias extends string | null = null> =
52
58
  & ContentClientInput.HasManyRelationInput<TEntity['hasMany'][TKey]>
53
59
  & { as?: TAlias }
54
60
 
55
- 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
+ > =
56
67
  | TypedEntitySelectionCallback<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
57
68
  | TypedEntitySelection<TSchema, TEntity['hasMany'][TKey]['name'], TEntity['hasMany'][TKey], TNestedValue>
58
69
 
59
- 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
+ > =
60
77
  | [
61
- args: TypedHasManyArgs<TEntity, TKey, TAlias>,
62
- fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
78
+ args: TypedHasManyArgs<TEntity, TKey, TAlias>,
79
+ fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
63
80
  ]
64
81
  | [
65
- fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
82
+ fields: TypedHasManyFields<TSchema, TEntity, TKey, TNestedValue>,
66
83
  ]
67
84
 
68
-
69
- 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
+ > =
70
90
  & ContentClientInput.HasManyByRelationInput<TEntity['hasManyBy'][TKey]['entity'], TEntity['hasManyBy'][TKey]['by']>
71
91
  & { as?: TAlias }
72
92
 
73
- 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
+ > =
74
99
  | TypedEntitySelectionCallback<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
75
100
  | TypedEntitySelection<TSchema, TEntity['hasManyBy'][TKey]['entity']['name'], TEntity['hasManyBy'][TKey]['entity'], TNestedValue>
76
101
 
77
- export type TypedHasManyByParams<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasManyBy'] & string, TNestedValue, TAlias extends string | null = null> =
78
- | [
79
- args: TypedHasManyByArgs<TEntity, TKey, TAlias>,
80
- fields: TypedHasManyByFields<TSchema, TEntity, TKey, TNestedValue>
81
- ]
82
-
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
+ ]
83
112
 
84
113
  export type TypedHasOneArgs<TEntity extends EntityTypeLike, TKey extends keyof TEntity['hasOne'] & string, TAlias extends string | null = null> =
85
114
  & ContentClientInput.HasOneRelationInput<TEntity['hasOne'][TKey]>
86
115
  & { as?: TAlias }
87
116
 
88
- 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
+ > =
89
123
  | TypedEntitySelectionCallback<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
90
124
  | TypedEntitySelection<TSchema, TEntity['hasOne'][TKey]['name'], TEntity['hasOne'][TKey], TNestedValue>
91
125
 
92
- 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
+ > =
93
133
  | [
94
- args: TypedHasOneArgs<TEntity, TKey, TAlias>,
95
- fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>
134
+ args: TypedHasOneArgs<TEntity, TKey, TAlias>,
135
+ fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
96
136
  ]
97
137
  | [
98
- fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>
138
+ fields: TypedHasOneFields<TSchema, TEntity, TKey, TNestedValue>,
99
139
  ]
100
140
 
101
-
102
141
  export type TypedColumnArgs<TAlias extends string | null = null> = { as?: TAlias }
103
142
  export type TypedColumnParams<TAlias extends string | null = null> =
104
143
  | [
105
- args: TypedColumnArgs<TAlias>
144
+ args: TypedColumnArgs<TAlias>,
106
145
  ]
107
146
  | []
108
147
 
109
- export type TypedEntitySelectionParams<TSchema extends SchemaTypeLike, TEntity extends EntityTypeLike, TKey extends string, TNestedValue, TAlias extends string | null = null> =
110
- TKey extends keyof TEntity['columns'] ? TypedColumnParams<TAlias>
111
- : TKey extends keyof TEntity['hasMany'] ? TypedHasManyParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
112
- : TKey extends keyof TEntity['hasManyBy'] ? TypedHasManyByParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
113
- : TKey extends keyof TEntity['hasOne'] ? TypedHasOneParams<TSchema, TEntity, TKey, TNestedValue, TAlias>
114
- : never
115
-
116
- export type TypedEntitySelectionResult<TEntity extends EntityTypeLike, TKey extends string, TValue> =
117
- TKey extends keyof TEntity['columns'] ? TEntity['columns'][TKey]
118
- : TKey extends keyof TEntity['hasMany'] ? TValue[]
119
- : TKey extends keyof TEntity['hasManyBy'] ? null | TValue
120
- : TKey extends keyof TEntity['hasOne'] ? null | TValue
121
- : 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