@contember/client-content 1.3.0-alpha.10

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 (145) hide show
  1. package/dist/development/ContentClient.cjs +27 -0
  2. package/dist/development/ContentClient.cjs.map +1 -0
  3. package/dist/development/ContentClient.js +27 -0
  4. package/dist/development/ContentClient.js.map +1 -0
  5. package/dist/development/ContentQueryBuilder.cjs +147 -0
  6. package/dist/development/ContentQueryBuilder.cjs.map +1 -0
  7. package/dist/development/ContentQueryBuilder.js +147 -0
  8. package/dist/development/ContentQueryBuilder.js.map +1 -0
  9. package/dist/development/index.cjs +11 -0
  10. package/dist/development/index.cjs.map +1 -0
  11. package/dist/development/index.js +11 -0
  12. package/dist/development/index.js.map +1 -0
  13. package/dist/development/nodes/ContentEntitySelection.cjs +161 -0
  14. package/dist/development/nodes/ContentEntitySelection.cjs.map +1 -0
  15. package/dist/development/nodes/ContentEntitySelection.js +161 -0
  16. package/dist/development/nodes/ContentEntitySelection.js.map +1 -0
  17. package/dist/development/nodes/ContentOperation.cjs +16 -0
  18. package/dist/development/nodes/ContentOperation.cjs.map +1 -0
  19. package/dist/development/nodes/ContentOperation.js +16 -0
  20. package/dist/development/nodes/ContentOperation.js.map +1 -0
  21. package/dist/development/utils/ContentOperationSet.cjs +10 -0
  22. package/dist/development/utils/ContentOperationSet.cjs.map +1 -0
  23. package/dist/development/utils/ContentOperationSet.js +10 -0
  24. package/dist/development/utils/ContentOperationSet.js.map +1 -0
  25. package/dist/development/utils/createListArgs.cjs +24 -0
  26. package/dist/development/utils/createListArgs.cjs.map +1 -0
  27. package/dist/development/utils/createListArgs.js +24 -0
  28. package/dist/development/utils/createListArgs.js.map +1 -0
  29. package/dist/development/utils/createMutationOperationSet.cjs +37 -0
  30. package/dist/development/utils/createMutationOperationSet.cjs.map +1 -0
  31. package/dist/development/utils/createMutationOperationSet.js +37 -0
  32. package/dist/development/utils/createMutationOperationSet.js.map +1 -0
  33. package/dist/development/utils/createQueryOperationSet.cjs +19 -0
  34. package/dist/development/utils/createQueryOperationSet.cjs.map +1 -0
  35. package/dist/development/utils/createQueryOperationSet.js +19 -0
  36. package/dist/development/utils/createQueryOperationSet.js.map +1 -0
  37. package/dist/development/utils/createTypedArgs.cjs +14 -0
  38. package/dist/development/utils/createTypedArgs.cjs.map +1 -0
  39. package/dist/development/utils/createTypedArgs.js +14 -0
  40. package/dist/development/utils/createTypedArgs.js.map +1 -0
  41. package/dist/development/utils/mutationFragments.cjs +55 -0
  42. package/dist/development/utils/mutationFragments.cjs.map +1 -0
  43. package/dist/development/utils/mutationFragments.js +55 -0
  44. package/dist/development/utils/mutationFragments.js.map +1 -0
  45. package/dist/production/ContentClient.cjs +27 -0
  46. package/dist/production/ContentClient.cjs.map +1 -0
  47. package/dist/production/ContentClient.js +27 -0
  48. package/dist/production/ContentClient.js.map +1 -0
  49. package/dist/production/ContentQueryBuilder.cjs +147 -0
  50. package/dist/production/ContentQueryBuilder.cjs.map +1 -0
  51. package/dist/production/ContentQueryBuilder.js +147 -0
  52. package/dist/production/ContentQueryBuilder.js.map +1 -0
  53. package/dist/production/index.cjs +11 -0
  54. package/dist/production/index.cjs.map +1 -0
  55. package/dist/production/index.js +11 -0
  56. package/dist/production/index.js.map +1 -0
  57. package/dist/production/nodes/ContentEntitySelection.cjs +161 -0
  58. package/dist/production/nodes/ContentEntitySelection.cjs.map +1 -0
  59. package/dist/production/nodes/ContentEntitySelection.js +161 -0
  60. package/dist/production/nodes/ContentEntitySelection.js.map +1 -0
  61. package/dist/production/nodes/ContentOperation.cjs +16 -0
  62. package/dist/production/nodes/ContentOperation.cjs.map +1 -0
  63. package/dist/production/nodes/ContentOperation.js +16 -0
  64. package/dist/production/nodes/ContentOperation.js.map +1 -0
  65. package/dist/production/utils/ContentOperationSet.cjs +10 -0
  66. package/dist/production/utils/ContentOperationSet.cjs.map +1 -0
  67. package/dist/production/utils/ContentOperationSet.js +10 -0
  68. package/dist/production/utils/ContentOperationSet.js.map +1 -0
  69. package/dist/production/utils/createListArgs.cjs +24 -0
  70. package/dist/production/utils/createListArgs.cjs.map +1 -0
  71. package/dist/production/utils/createListArgs.js +24 -0
  72. package/dist/production/utils/createListArgs.js.map +1 -0
  73. package/dist/production/utils/createMutationOperationSet.cjs +37 -0
  74. package/dist/production/utils/createMutationOperationSet.cjs.map +1 -0
  75. package/dist/production/utils/createMutationOperationSet.js +37 -0
  76. package/dist/production/utils/createMutationOperationSet.js.map +1 -0
  77. package/dist/production/utils/createQueryOperationSet.cjs +19 -0
  78. package/dist/production/utils/createQueryOperationSet.cjs.map +1 -0
  79. package/dist/production/utils/createQueryOperationSet.js +19 -0
  80. package/dist/production/utils/createQueryOperationSet.js.map +1 -0
  81. package/dist/production/utils/createTypedArgs.cjs +14 -0
  82. package/dist/production/utils/createTypedArgs.cjs.map +1 -0
  83. package/dist/production/utils/createTypedArgs.js +14 -0
  84. package/dist/production/utils/createTypedArgs.js.map +1 -0
  85. package/dist/production/utils/mutationFragments.cjs +55 -0
  86. package/dist/production/utils/mutationFragments.cjs.map +1 -0
  87. package/dist/production/utils/mutationFragments.js +55 -0
  88. package/dist/production/utils/mutationFragments.js.map +1 -0
  89. package/dist/types/ContentClient.d.ts +17 -0
  90. package/dist/types/ContentClient.d.ts.map +1 -0
  91. package/dist/types/ContentQueryBuilder.d.ts +25 -0
  92. package/dist/types/ContentQueryBuilder.d.ts.map +1 -0
  93. package/dist/types/TypedContentQueryBuilder.d.ts +21 -0
  94. package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -0
  95. package/dist/types/index.d.ts +6 -0
  96. package/dist/types/index.d.ts.map +1 -0
  97. package/dist/types/nodes/ContentEntitySelection.d.ts +51 -0
  98. package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -0
  99. package/dist/types/nodes/ContentOperation.d.ts +30 -0
  100. package/dist/types/nodes/ContentOperation.d.ts.map +1 -0
  101. package/dist/types/nodes/TypedEntitySelection.d.ts +45 -0
  102. package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -0
  103. package/dist/types/nodes/index.d.ts +4 -0
  104. package/dist/types/nodes/index.d.ts.map +1 -0
  105. package/dist/types/tsconfig.tsbuildinfo +1 -0
  106. package/dist/types/types/Input.d.ts +203 -0
  107. package/dist/types/types/Input.d.ts.map +1 -0
  108. package/dist/types/types/Result.d.ts +39 -0
  109. package/dist/types/types/Result.d.ts.map +1 -0
  110. package/dist/types/types/Schema.d.ts +43 -0
  111. package/dist/types/types/Schema.d.ts.map +1 -0
  112. package/dist/types/types/index.d.ts +4 -0
  113. package/dist/types/types/index.d.ts.map +1 -0
  114. package/dist/types/utils/ContentOperationSet.d.ts +13 -0
  115. package/dist/types/utils/ContentOperationSet.d.ts.map +1 -0
  116. package/dist/types/utils/createListArgs.d.ts +9 -0
  117. package/dist/types/utils/createListArgs.d.ts.map +1 -0
  118. package/dist/types/utils/createMutationOperationSet.d.ts +4 -0
  119. package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -0
  120. package/dist/types/utils/createQueryOperationSet.d.ts +4 -0
  121. package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -0
  122. package/dist/types/utils/createTypedArgs.d.ts +3 -0
  123. package/dist/types/utils/createTypedArgs.d.ts.map +1 -0
  124. package/dist/types/utils/mutationFragments.d.ts +3 -0
  125. package/dist/types/utils/mutationFragments.d.ts.map +1 -0
  126. package/package.json +48 -0
  127. package/src/ContentClient.ts +41 -0
  128. package/src/ContentQueryBuilder.ts +204 -0
  129. package/src/TypedContentQueryBuilder.ts +76 -0
  130. package/src/index.ts +5 -0
  131. package/src/nodes/ContentEntitySelection.ts +240 -0
  132. package/src/nodes/ContentOperation.ts +23 -0
  133. package/src/nodes/TypedEntitySelection.ts +111 -0
  134. package/src/nodes/index.ts +3 -0
  135. package/src/tsconfig.json +14 -0
  136. package/src/types/Input.ts +281 -0
  137. package/src/types/Result.ts +43 -0
  138. package/src/types/Schema.ts +49 -0
  139. package/src/types/index.ts +3 -0
  140. package/src/utils/ContentOperationSet.ts +11 -0
  141. package/src/utils/createListArgs.ts +23 -0
  142. package/src/utils/createMutationOperationSet.ts +42 -0
  143. package/src/utils/createQueryOperationSet.ts +20 -0
  144. package/src/utils/createTypedArgs.ts +15 -0
  145. package/src/utils/mutationFragments.ts +52 -0
@@ -0,0 +1,43 @@
1
+ import { Result } from '@contember/schema'
2
+
3
+ export type TransactionResult<V> = {
4
+ readonly ok: boolean
5
+ readonly errorMessage: string | null
6
+ readonly errors: MutationError[]
7
+ readonly validation: ValidationResult
8
+ readonly data: V
9
+ }
10
+
11
+ export type MutationResult<Value = unknown> = {
12
+ readonly ok: boolean
13
+ readonly errorMessage: string | null
14
+ readonly errors: MutationError[]
15
+ readonly node: Value | null
16
+ readonly validation?: ValidationResult
17
+ }
18
+
19
+ export type ValidationResult = {
20
+ readonly valid: boolean
21
+ readonly errors: ValidationError[]
22
+ }
23
+
24
+ export type ValidationError = {
25
+ readonly path: Path
26
+ readonly message: { text: string }
27
+ }
28
+
29
+ export type MutationError = {
30
+ readonly paths: Path[]
31
+ readonly message: string
32
+ readonly type: Result.ExecutionErrorType
33
+ }
34
+
35
+ export type Path = Array<FieldPath | IndexPath>
36
+
37
+ export type FieldPath = {
38
+ readonly field: string
39
+ }
40
+ export type IndexPath = {
41
+ readonly index: number
42
+ readonly alias: string | null
43
+ }
@@ -0,0 +1,49 @@
1
+ import { JSONObject } from '@contember/schema'
2
+
3
+ export type SchemaEntityNames<Name extends string> = {
4
+ readonly name: Name
5
+ readonly scalars: string[]
6
+ readonly fields: {
7
+ readonly [fieldName: string]:
8
+ | {
9
+ readonly type: 'column'
10
+ }
11
+ | {
12
+ readonly type: 'many' | 'one'
13
+ readonly entity: string
14
+ }
15
+ }
16
+ }
17
+
18
+ export type SchemaNames = {
19
+ entities: {
20
+ [entityName: string]: SchemaEntityNames<string>
21
+ }
22
+ }
23
+
24
+ export type EntityTypeLike = {
25
+ name: string
26
+ unique: JSONObject
27
+ columns: {
28
+ [columnName: string]: any
29
+ }
30
+ hasOne: {
31
+ [relationName: string]: EntityTypeLike
32
+ }
33
+ hasMany: {
34
+ [relationName: string]: EntityTypeLike
35
+ }
36
+ hasManyBy: {
37
+ [relationName: string]: {
38
+ entity: EntityTypeLike
39
+ by: JSONObject
40
+ }
41
+ }
42
+ }
43
+
44
+ export type SchemaTypeLike = {
45
+ entities: {
46
+ [entityName: string]: EntityTypeLike
47
+ }
48
+ }
49
+
@@ -0,0 +1,3 @@
1
+ export * from './Input'
2
+ export * from './Result'
3
+ export * from './Schema'
@@ -0,0 +1,11 @@
1
+ import { GraphQlSelectionSet } from '@contember/graphql-builder'
2
+
3
+ export class ContentOperationSet<TValue> {
4
+ constructor(
5
+ /** @internal */
6
+ public readonly selection: GraphQlSelectionSet,
7
+ /** @internal */
8
+ public readonly parse: (value: any) => TValue = it => it as TValue,
9
+ ) {
10
+ }
11
+ }
@@ -0,0 +1,23 @@
1
+ import { SchemaEntityNames } from '../types'
2
+ import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
3
+
4
+ export const createListArgs = (entity: SchemaEntityNames<string>, args: { filter?: any, orderBy?: any, limit?: number, offset?: number }, type: 'list' | 'paginate' = 'list'): GraphQlFieldTypedArgs => {
5
+ return {
6
+ filter: {
7
+ graphQlType: `${entity.name}Where`,
8
+ value: args.filter,
9
+ },
10
+ orderBy: {
11
+ graphQlType: `[${entity.name}OrderBy!]`,
12
+ value: args.orderBy,
13
+ },
14
+ [type === 'list' ? 'limit' : 'first']: {
15
+ graphQlType: 'Int',
16
+ value: args.limit,
17
+ },
18
+ [type === 'list' ? 'offset' : 'skip']: {
19
+ graphQlType: 'Int',
20
+ value: args.offset,
21
+ },
22
+ }
23
+ }
@@ -0,0 +1,42 @@
1
+ import { ContentMutation, ContentOperation, ContentQuery } from '../nodes'
2
+ import { GraphQlField } from '@contember/graphql-builder'
3
+ import { ContentOperationSet } from './ContentOperationSet'
4
+
5
+ export const createMutationOperationSet = (
6
+ input:
7
+ | Record<string, ContentMutation<any> | ContentQuery<any>>
8
+ | ContentMutation<any>
9
+ | ContentMutation<any>[],
10
+ ): ContentOperationSet<any> => {
11
+
12
+ if (input instanceof ContentOperation) {
13
+ return new ContentOperationSet(
14
+ [new GraphQlField('mut', input.fieldName, input.args, input.selection)],
15
+ it => input.parse(it.mut),
16
+ )
17
+ }
18
+
19
+ if (Array.isArray(input)) {
20
+ return new ContentOperationSet(
21
+ input.map((mut, i) => new GraphQlField('mut_' + i++, mut.fieldName, mut.args, mut.selection)),
22
+ data => input.map((mut, i) => mut.parse(data['mut_' + i] ?? null)),
23
+ )
24
+ }
25
+
26
+ return new ContentOperationSet(
27
+ Object.entries(input).map(([alias, mutation]) => {
28
+ if (mutation.type === 'query') {
29
+ return new GraphQlField(alias, 'query', {}, [
30
+ new GraphQlField('value', mutation.fieldName, mutation.args, mutation.selection),
31
+ ])
32
+ }
33
+ return new GraphQlField(alias, mutation.fieldName, mutation.args, mutation.selection)
34
+ }),
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
+ })),
41
+ )
42
+ }
@@ -0,0 +1,20 @@
1
+ import { ContentOperation, ContentQuery } from '../nodes'
2
+ import { ContentOperationSet } from './ContentOperationSet'
3
+ import { GraphQlField } from '@contember/graphql-builder'
4
+
5
+ export const createQueryOperationSet = (
6
+ input: Record<string, ContentQuery<any>> | ContentQuery<any>,
7
+ ): ContentOperationSet<any> => {
8
+
9
+ if (input instanceof ContentOperation) {
10
+ return new ContentOperationSet(
11
+ [new GraphQlField('value', input.fieldName, input.args, input.selection)],
12
+ it => input.parse(it.value),
13
+ )
14
+ }
15
+
16
+ return new ContentOperationSet(
17
+ Object.entries(input).map(([alias, query]) => new GraphQlField(alias, query.fieldName, query.args, query.selection)),
18
+ res => Object.fromEntries(Object.entries(input).map(([alias, query]) => [alias, query.parse(res[alias] ?? null)])),
19
+ )
20
+ }
@@ -0,0 +1,15 @@
1
+ import { GraphQlFieldTypedArgs } from '@contember/graphql-builder'
2
+
3
+ export const createTypedArgs = <TArgs extends Record<string, any>>(
4
+ args: TArgs,
5
+ types: { [key in keyof TArgs]: string },
6
+ ): GraphQlFieldTypedArgs => {
7
+ const typedArgs: GraphQlFieldTypedArgs = {}
8
+ for (const key in args) {
9
+ typedArgs[key] = {
10
+ graphQlType: types[key],
11
+ value: args[key],
12
+ }
13
+ }
14
+ return typedArgs
15
+ }
@@ -0,0 +1,52 @@
1
+ import { GraphQlField, GraphQlFragment, GraphQlFragmentSpread, GraphQlInlineFragment } from '@contember/graphql-builder'
2
+
3
+ export const mutationFragments: Record<string, GraphQlFragment> = {
4
+ MutationError: new GraphQlFragment('MutationError', '_MutationError', [
5
+ new GraphQlField(null, 'paths', {}, [
6
+ new GraphQlInlineFragment('_FieldPathFragment', [
7
+ new GraphQlField(null, 'field'),
8
+ ]),
9
+ new GraphQlInlineFragment('_IndexPathFragment', [
10
+ new GraphQlField(null, 'index'),
11
+ new GraphQlField(null, 'alias'),
12
+ ]),
13
+ ]),
14
+ new GraphQlField(null, 'message'),
15
+ new GraphQlField(null, 'type'),
16
+ ]),
17
+ TransactionResult: new GraphQlFragment('TransactionResult', 'TransactionResult', [
18
+ new GraphQlField(null, 'ok'),
19
+ new GraphQlField(null, 'errorMessage'),
20
+ new GraphQlField(null, 'errors', {}, [
21
+ new GraphQlField(null, 'paths', {}, [
22
+ new GraphQlInlineFragment('_FieldPathFragment', [
23
+ new GraphQlField(null, 'field'),
24
+ ]),
25
+ new GraphQlInlineFragment('_IndexPathFragment', [
26
+ new GraphQlField(null, 'index'),
27
+ new GraphQlField(null, 'alias'),
28
+ ]),
29
+ ]),
30
+ ]),
31
+ new GraphQlField(null, 'validation', {}, [
32
+ new GraphQlFragmentSpread('ValidationResult'),
33
+ ]),
34
+ ]),
35
+ ValidationResult: new GraphQlFragment('ValidationResult', '_ValidationResult', [
36
+ new GraphQlField(null, 'valid'),
37
+ new GraphQlField(null, 'errors', {}, [
38
+ new GraphQlField(null, 'path', {}, [
39
+ new GraphQlInlineFragment('_FieldPathFragment', [
40
+ new GraphQlField(null, 'field'),
41
+ ]),
42
+ new GraphQlInlineFragment('_IndexPathFragment', [
43
+ new GraphQlField(null, 'index'),
44
+ new GraphQlField(null, 'alias'),
45
+ ]),
46
+ ]),
47
+ new GraphQlField(null, 'message', {}, [
48
+ new GraphQlField(null, 'text'),
49
+ ]),
50
+ ]),
51
+ ]),
52
+ }