@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.
- package/dist/development/ContentClient.cjs +27 -0
- package/dist/development/ContentClient.cjs.map +1 -0
- package/dist/development/ContentClient.js +27 -0
- package/dist/development/ContentClient.js.map +1 -0
- package/dist/development/ContentQueryBuilder.cjs +147 -0
- package/dist/development/ContentQueryBuilder.cjs.map +1 -0
- package/dist/development/ContentQueryBuilder.js +147 -0
- package/dist/development/ContentQueryBuilder.js.map +1 -0
- package/dist/development/index.cjs +11 -0
- package/dist/development/index.cjs.map +1 -0
- package/dist/development/index.js +11 -0
- package/dist/development/index.js.map +1 -0
- package/dist/development/nodes/ContentEntitySelection.cjs +161 -0
- package/dist/development/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/development/nodes/ContentEntitySelection.js +161 -0
- package/dist/development/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/development/nodes/ContentOperation.cjs +16 -0
- package/dist/development/nodes/ContentOperation.cjs.map +1 -0
- package/dist/development/nodes/ContentOperation.js +16 -0
- package/dist/development/nodes/ContentOperation.js.map +1 -0
- package/dist/development/utils/ContentOperationSet.cjs +10 -0
- package/dist/development/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/development/utils/ContentOperationSet.js +10 -0
- package/dist/development/utils/ContentOperationSet.js.map +1 -0
- package/dist/development/utils/createListArgs.cjs +24 -0
- package/dist/development/utils/createListArgs.cjs.map +1 -0
- package/dist/development/utils/createListArgs.js +24 -0
- package/dist/development/utils/createListArgs.js.map +1 -0
- package/dist/development/utils/createMutationOperationSet.cjs +37 -0
- package/dist/development/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/development/utils/createMutationOperationSet.js +37 -0
- package/dist/development/utils/createMutationOperationSet.js.map +1 -0
- package/dist/development/utils/createQueryOperationSet.cjs +19 -0
- package/dist/development/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/development/utils/createQueryOperationSet.js +19 -0
- package/dist/development/utils/createQueryOperationSet.js.map +1 -0
- package/dist/development/utils/createTypedArgs.cjs +14 -0
- package/dist/development/utils/createTypedArgs.cjs.map +1 -0
- package/dist/development/utils/createTypedArgs.js +14 -0
- package/dist/development/utils/createTypedArgs.js.map +1 -0
- package/dist/development/utils/mutationFragments.cjs +55 -0
- package/dist/development/utils/mutationFragments.cjs.map +1 -0
- package/dist/development/utils/mutationFragments.js +55 -0
- package/dist/development/utils/mutationFragments.js.map +1 -0
- package/dist/production/ContentClient.cjs +27 -0
- package/dist/production/ContentClient.cjs.map +1 -0
- package/dist/production/ContentClient.js +27 -0
- package/dist/production/ContentClient.js.map +1 -0
- package/dist/production/ContentQueryBuilder.cjs +147 -0
- package/dist/production/ContentQueryBuilder.cjs.map +1 -0
- package/dist/production/ContentQueryBuilder.js +147 -0
- package/dist/production/ContentQueryBuilder.js.map +1 -0
- package/dist/production/index.cjs +11 -0
- package/dist/production/index.cjs.map +1 -0
- package/dist/production/index.js +11 -0
- package/dist/production/index.js.map +1 -0
- package/dist/production/nodes/ContentEntitySelection.cjs +161 -0
- package/dist/production/nodes/ContentEntitySelection.cjs.map +1 -0
- package/dist/production/nodes/ContentEntitySelection.js +161 -0
- package/dist/production/nodes/ContentEntitySelection.js.map +1 -0
- package/dist/production/nodes/ContentOperation.cjs +16 -0
- package/dist/production/nodes/ContentOperation.cjs.map +1 -0
- package/dist/production/nodes/ContentOperation.js +16 -0
- package/dist/production/nodes/ContentOperation.js.map +1 -0
- package/dist/production/utils/ContentOperationSet.cjs +10 -0
- package/dist/production/utils/ContentOperationSet.cjs.map +1 -0
- package/dist/production/utils/ContentOperationSet.js +10 -0
- package/dist/production/utils/ContentOperationSet.js.map +1 -0
- package/dist/production/utils/createListArgs.cjs +24 -0
- package/dist/production/utils/createListArgs.cjs.map +1 -0
- package/dist/production/utils/createListArgs.js +24 -0
- package/dist/production/utils/createListArgs.js.map +1 -0
- package/dist/production/utils/createMutationOperationSet.cjs +37 -0
- package/dist/production/utils/createMutationOperationSet.cjs.map +1 -0
- package/dist/production/utils/createMutationOperationSet.js +37 -0
- package/dist/production/utils/createMutationOperationSet.js.map +1 -0
- package/dist/production/utils/createQueryOperationSet.cjs +19 -0
- package/dist/production/utils/createQueryOperationSet.cjs.map +1 -0
- package/dist/production/utils/createQueryOperationSet.js +19 -0
- package/dist/production/utils/createQueryOperationSet.js.map +1 -0
- package/dist/production/utils/createTypedArgs.cjs +14 -0
- package/dist/production/utils/createTypedArgs.cjs.map +1 -0
- package/dist/production/utils/createTypedArgs.js +14 -0
- package/dist/production/utils/createTypedArgs.js.map +1 -0
- package/dist/production/utils/mutationFragments.cjs +55 -0
- package/dist/production/utils/mutationFragments.cjs.map +1 -0
- package/dist/production/utils/mutationFragments.js +55 -0
- package/dist/production/utils/mutationFragments.js.map +1 -0
- package/dist/types/ContentClient.d.ts +17 -0
- package/dist/types/ContentClient.d.ts.map +1 -0
- package/dist/types/ContentQueryBuilder.d.ts +25 -0
- package/dist/types/ContentQueryBuilder.d.ts.map +1 -0
- package/dist/types/TypedContentQueryBuilder.d.ts +21 -0
- package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/nodes/ContentEntitySelection.d.ts +51 -0
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -0
- package/dist/types/nodes/ContentOperation.d.ts +30 -0
- package/dist/types/nodes/ContentOperation.d.ts.map +1 -0
- package/dist/types/nodes/TypedEntitySelection.d.ts +45 -0
- package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -0
- package/dist/types/nodes/index.d.ts +4 -0
- package/dist/types/nodes/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/dist/types/types/Input.d.ts +203 -0
- package/dist/types/types/Input.d.ts.map +1 -0
- package/dist/types/types/Result.d.ts +39 -0
- package/dist/types/types/Result.d.ts.map +1 -0
- package/dist/types/types/Schema.d.ts +43 -0
- package/dist/types/types/Schema.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +4 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/ContentOperationSet.d.ts +13 -0
- package/dist/types/utils/ContentOperationSet.d.ts.map +1 -0
- package/dist/types/utils/createListArgs.d.ts +9 -0
- package/dist/types/utils/createListArgs.d.ts.map +1 -0
- package/dist/types/utils/createMutationOperationSet.d.ts +4 -0
- package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -0
- package/dist/types/utils/createQueryOperationSet.d.ts +4 -0
- package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -0
- package/dist/types/utils/createTypedArgs.d.ts +3 -0
- package/dist/types/utils/createTypedArgs.d.ts.map +1 -0
- package/dist/types/utils/mutationFragments.d.ts +3 -0
- package/dist/types/utils/mutationFragments.d.ts.map +1 -0
- package/package.json +48 -0
- package/src/ContentClient.ts +41 -0
- package/src/ContentQueryBuilder.ts +204 -0
- package/src/TypedContentQueryBuilder.ts +76 -0
- package/src/index.ts +5 -0
- package/src/nodes/ContentEntitySelection.ts +240 -0
- package/src/nodes/ContentOperation.ts +23 -0
- package/src/nodes/TypedEntitySelection.ts +111 -0
- package/src/nodes/index.ts +3 -0
- package/src/tsconfig.json +14 -0
- package/src/types/Input.ts +281 -0
- package/src/types/Result.ts +43 -0
- package/src/types/Schema.ts +49 -0
- package/src/types/index.ts +3 -0
- package/src/utils/ContentOperationSet.ts +11 -0
- package/src/utils/createListArgs.ts +23 -0
- package/src/utils/createMutationOperationSet.ts +42 -0
- package/src/utils/createQueryOperationSet.ts +20 -0
- package/src/utils/createTypedArgs.ts +15 -0
- 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,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
|
+
}
|