@contember/client-content 2.1.0-alpha.9 → 2.1.0-beta.2
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/CLAUDE.md +52 -0
- package/dist/development/src/ContentClient.cjs +12 -0
- package/dist/development/src/ContentClient.cjs.map +1 -1
- package/dist/development/src/ContentClient.js +12 -0
- package/dist/development/src/ContentClient.js.map +1 -1
- package/dist/development/src/ContentQueryBuilder.cjs +26 -15
- package/dist/development/src/ContentQueryBuilder.cjs.map +1 -1
- package/dist/development/src/ContentQueryBuilder.js +26 -15
- package/dist/development/src/ContentQueryBuilder.js.map +1 -1
- package/dist/development/src/MutationFailedError.cjs +11 -0
- package/dist/development/src/MutationFailedError.cjs.map +1 -0
- package/dist/development/src/MutationFailedError.js +11 -0
- package/dist/development/src/MutationFailedError.js.map +1 -0
- package/dist/development/src/nodes/ContentEntitySelection.cjs +47 -12
- package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/development/src/nodes/ContentEntitySelection.js +47 -12
- package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/development/src/nodes/ContentOperation.cjs.map +1 -1
- package/dist/development/src/nodes/ContentOperation.js.map +1 -1
- package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/ContentOperationSet.js.map +1 -1
- package/dist/development/src/utils/createListArgs.cjs.map +1 -1
- package/dist/development/src/utils/createListArgs.js.map +1 -1
- package/dist/development/src/utils/createMutationOperationSet.cjs +8 -6
- package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/createMutationOperationSet.js +8 -6
- package/dist/development/src/utils/createMutationOperationSet.js.map +1 -1
- package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -1
- package/dist/development/src/utils/createQueryOperationSet.js.map +1 -1
- package/dist/development/src/utils/createTypedArgs.cjs.map +1 -1
- package/dist/development/src/utils/createTypedArgs.js.map +1 -1
- package/dist/development/src/utils/mutationFragments.cjs.map +1 -1
- package/dist/development/src/utils/mutationFragments.js.map +1 -1
- package/dist/production/src/ContentClient.cjs +12 -0
- package/dist/production/src/ContentClient.cjs.map +1 -1
- package/dist/production/src/ContentClient.js +12 -0
- package/dist/production/src/ContentClient.js.map +1 -1
- package/dist/production/src/ContentQueryBuilder.cjs +26 -15
- package/dist/production/src/ContentQueryBuilder.cjs.map +1 -1
- package/dist/production/src/ContentQueryBuilder.js +26 -15
- package/dist/production/src/ContentQueryBuilder.js.map +1 -1
- package/dist/production/src/MutationFailedError.cjs +11 -0
- package/dist/production/src/MutationFailedError.cjs.map +1 -0
- package/dist/production/src/MutationFailedError.js +11 -0
- package/dist/production/src/MutationFailedError.js.map +1 -0
- package/dist/production/src/nodes/ContentEntitySelection.cjs +47 -12
- package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -1
- package/dist/production/src/nodes/ContentEntitySelection.js +47 -12
- package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -1
- package/dist/production/src/nodes/ContentOperation.cjs.map +1 -1
- package/dist/production/src/nodes/ContentOperation.js.map +1 -1
- package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/ContentOperationSet.js.map +1 -1
- package/dist/production/src/utils/createListArgs.cjs.map +1 -1
- package/dist/production/src/utils/createListArgs.js.map +1 -1
- package/dist/production/src/utils/createMutationOperationSet.cjs +8 -6
- package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/createMutationOperationSet.js +8 -6
- package/dist/production/src/utils/createMutationOperationSet.js.map +1 -1
- package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -1
- package/dist/production/src/utils/createQueryOperationSet.js.map +1 -1
- package/dist/production/src/utils/createTypedArgs.cjs.map +1 -1
- package/dist/production/src/utils/createTypedArgs.js.map +1 -1
- package/dist/production/src/utils/mutationFragments.cjs.map +1 -1
- package/dist/production/src/utils/mutationFragments.js.map +1 -1
- package/dist/types/ContentClient.d.ts +10 -0
- package/dist/types/ContentClient.d.ts.map +1 -1
- package/dist/types/ContentQueryBuilder.d.ts.map +1 -1
- package/dist/types/MutationFailedError.d.ts +13 -0
- package/dist/types/MutationFailedError.d.ts.map +1 -0
- package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts +4 -1
- package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
- package/dist/types/nodes/TypedEntitySelection.d.ts +1 -0
- package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/types/Input.d.ts.map +1 -1
- package/dist/types/types/Result.d.ts +30 -9
- package/dist/types/types/Result.d.ts.map +1 -1
- package/dist/types/utils/createListArgs.d.ts.map +1 -1
- package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -1
- package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/ContentClient.ts +36 -9
- package/src/ContentQueryBuilder.ts +45 -35
- package/src/MutationFailedError.ts +19 -0
- package/src/TypedContentQueryBuilder.ts +0 -4
- package/src/nodes/ContentEntitySelection.ts +67 -23
- package/src/nodes/TypedEntitySelection.ts +96 -48
- package/src/types/Input.ts +1 -9
- package/src/types/Result.ts +41 -9
- package/src/types/Schema.ts +0 -1
- package/src/utils/createListArgs.ts +5 -1
- package/src/utils/createMutationOperationSet.ts +9 -7
- package/src/utils/createQueryOperationSet.ts +0 -1
- package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
- package/tests/cases/unit/__snapshots__/query.test.ts.snap +216 -60
- package/tests/cases/unit/mutation.test.ts +48 -3
- package/tests/cases/unit/query.test.ts +103 -82
- package/tests/cases/unit/types.test.ts +31 -27
- package/tests/client/entities.ts +2 -0
- package/tests/client/enums.ts +5 -0
- package/tests/client/names.ts +129 -117
- package/tests/generate.ts +0 -1
- package/tests/lib.ts +0 -1
- package/tests/schema.ts +1 -2
- package/vitest.config.ts +0 -3
|
@@ -1,102 +1,258 @@
|
|
|
1
|
-
// Bun Snapshot v1, https://
|
|
1
|
+
// Bun Snapshot v1, https://bun.sh/docs/test/snapshots
|
|
2
2
|
|
|
3
3
|
exports[`queries list 1`] = `
|
|
4
4
|
"query {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
authors: listAuthor {
|
|
6
|
+
id
|
|
7
|
+
name
|
|
8
|
+
email
|
|
9
|
+
}
|
|
10
10
|
}
|
|
11
11
|
"
|
|
12
12
|
`;
|
|
13
13
|
|
|
14
14
|
exports[`queries multiple queries 1`] = `
|
|
15
15
|
"query {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
authors: listAuthor {
|
|
17
|
+
id
|
|
18
|
+
name
|
|
19
|
+
email
|
|
20
|
+
}
|
|
21
|
+
posts: listPost {
|
|
22
|
+
id
|
|
23
|
+
publishedAt
|
|
24
|
+
status
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
"
|
|
27
28
|
`;
|
|
28
29
|
|
|
29
30
|
exports[`queries single query 1`] = `
|
|
30
31
|
"query {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
value: listPost {
|
|
33
|
+
id
|
|
34
|
+
publishedAt
|
|
35
|
+
status
|
|
36
|
+
}
|
|
35
37
|
}
|
|
36
38
|
"
|
|
37
39
|
`;
|
|
38
40
|
|
|
39
41
|
exports[`queries nested object 1`] = `
|
|
40
42
|
"query {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
authors: listAuthor {
|
|
44
|
+
id
|
|
45
|
+
name
|
|
46
|
+
email
|
|
47
|
+
posts: paginatePosts {
|
|
48
|
+
edges {
|
|
49
|
+
node {
|
|
50
|
+
id
|
|
51
|
+
publishedAt
|
|
52
|
+
status
|
|
53
|
+
tags: paginateTags {
|
|
54
|
+
edges {
|
|
55
|
+
node {
|
|
56
|
+
id
|
|
57
|
+
name
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
54
65
|
}
|
|
55
66
|
"
|
|
56
67
|
`;
|
|
57
68
|
|
|
58
69
|
exports[`queries nested object args 1`] = `
|
|
59
70
|
"query($PostWhere_0: PostWhere, $Int_1: Int) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
authors: listAuthor {
|
|
72
|
+
id
|
|
73
|
+
name
|
|
74
|
+
email
|
|
75
|
+
posts: paginatePosts(filter: $PostWhere_0, first: $Int_1) {
|
|
76
|
+
edges {
|
|
77
|
+
node {
|
|
78
|
+
id
|
|
79
|
+
publishedAt
|
|
80
|
+
status
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
69
85
|
}
|
|
70
86
|
"
|
|
71
87
|
`;
|
|
72
88
|
|
|
73
89
|
exports[`queries list with args:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
|
|
91
|
+
authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
|
|
92
|
+
id
|
|
93
|
+
name
|
|
94
|
+
email
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
"
|
|
98
|
+
1`] = `
|
|
83
99
|
"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
|
|
101
|
+
id
|
|
102
|
+
name
|
|
103
|
+
email
|
|
104
|
+
}
|
|
89
105
|
}
|
|
90
106
|
"
|
|
91
107
|
`;
|
|
92
108
|
|
|
93
109
|
exports[`queries get by id 1`] = `
|
|
94
110
|
"query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
authors: getAuthor(by: $AuthorUniqueWhere_0) {
|
|
112
|
+
id
|
|
113
|
+
name
|
|
114
|
+
email
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
"
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
exports[`queries top level list transform 1`] = `
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"query":
|
|
124
|
+
"query {
|
|
125
|
+
authors: listAuthor {
|
|
126
|
+
id
|
|
127
|
+
name
|
|
128
|
+
email
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
"
|
|
132
|
+
,
|
|
133
|
+
"variables": {},
|
|
134
|
+
},
|
|
135
|
+
]
|
|
136
|
+
`;
|
|
137
|
+
|
|
138
|
+
exports[`queries top level get transform 1`] = `
|
|
139
|
+
[
|
|
140
|
+
{
|
|
141
|
+
"query":
|
|
142
|
+
"query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
|
|
143
|
+
author: getAuthor(by: $AuthorUniqueWhere_0) {
|
|
144
|
+
id
|
|
145
|
+
name
|
|
146
|
+
email
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
"
|
|
150
|
+
,
|
|
151
|
+
"variables": {
|
|
152
|
+
"AuthorUniqueWhere_0": {
|
|
153
|
+
"id": "123",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
]
|
|
158
|
+
`;
|
|
159
|
+
|
|
160
|
+
exports[`queries nested has-many transform 1`] = `
|
|
161
|
+
[
|
|
162
|
+
{
|
|
163
|
+
"query":
|
|
164
|
+
"query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
|
|
165
|
+
author: getAuthor(by: $AuthorUniqueWhere_0) {
|
|
166
|
+
id
|
|
167
|
+
name
|
|
168
|
+
email
|
|
169
|
+
posts: paginatePosts {
|
|
170
|
+
edges {
|
|
171
|
+
node {
|
|
172
|
+
id
|
|
173
|
+
publishedAt
|
|
174
|
+
status
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
"
|
|
181
|
+
,
|
|
182
|
+
"variables": {
|
|
183
|
+
"AuthorUniqueWhere_0": {
|
|
184
|
+
"id": "123",
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
]
|
|
189
|
+
`;
|
|
190
|
+
|
|
191
|
+
exports[`queries nested has-one transform 1`] = `
|
|
192
|
+
[
|
|
193
|
+
{
|
|
194
|
+
"query":
|
|
195
|
+
"query($PostUniqueWhere_0: PostUniqueWhere!) {
|
|
196
|
+
post: getPost(by: $PostUniqueWhere_0) {
|
|
197
|
+
id
|
|
198
|
+
publishedAt
|
|
199
|
+
status
|
|
200
|
+
author {
|
|
201
|
+
id
|
|
202
|
+
name
|
|
203
|
+
email
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
"
|
|
208
|
+
,
|
|
209
|
+
"variables": {
|
|
210
|
+
"PostUniqueWhere_0": {
|
|
211
|
+
"id": "123",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
]
|
|
216
|
+
`;
|
|
217
|
+
|
|
218
|
+
exports[`queries nested has-many-by transform 1`] = `
|
|
219
|
+
[
|
|
220
|
+
{
|
|
221
|
+
"query":
|
|
222
|
+
"query($PostUniqueWhere_0: PostUniqueWhere!, $PostLocalesByLocaleUniqueWhere_1: PostLocalesByLocaleUniqueWhere!) {
|
|
223
|
+
post: getPost(by: $PostUniqueWhere_0) {
|
|
224
|
+
id
|
|
225
|
+
publishedAt
|
|
226
|
+
status
|
|
227
|
+
localesByLocale(by: $PostLocalesByLocaleUniqueWhere_1) {
|
|
228
|
+
id
|
|
229
|
+
title
|
|
230
|
+
content
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
"
|
|
235
|
+
,
|
|
236
|
+
"variables": {
|
|
237
|
+
"PostLocalesByLocaleUniqueWhere_1": {
|
|
238
|
+
"locale": {
|
|
239
|
+
"code": "en",
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
"PostUniqueWhere_0": {
|
|
243
|
+
"id": "123",
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
]
|
|
248
|
+
`;
|
|
249
|
+
|
|
250
|
+
exports[`queries omit 1`] = `
|
|
251
|
+
"query {
|
|
252
|
+
authors: listAuthor {
|
|
253
|
+
id
|
|
254
|
+
name
|
|
255
|
+
}
|
|
100
256
|
}
|
|
101
257
|
"
|
|
102
258
|
`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from 'bun:test'
|
|
2
2
|
import { createClient } from '../../lib'
|
|
3
3
|
import { queryBuilder } from '../../client'
|
|
4
|
+
import { expectTypeOf } from 'expect-type'
|
|
4
5
|
|
|
5
6
|
const qb = queryBuilder
|
|
6
7
|
describe('mutations in trx', () => {
|
|
@@ -21,7 +22,6 @@ describe('mutations in trx', () => {
|
|
|
21
22
|
}))
|
|
22
23
|
const result = await client.mutate(createAuthor)
|
|
23
24
|
|
|
24
|
-
|
|
25
25
|
expect(result.data.ok).toBe(true)
|
|
26
26
|
expect(calls).toHaveLength(1)
|
|
27
27
|
expect(calls[0].query).toMatchSnapshot()
|
|
@@ -302,7 +302,6 @@ describe('mutations in trx', () => {
|
|
|
302
302
|
expect(calls[0].query).toMatchSnapshot()
|
|
303
303
|
expect(calls[0].variables).toMatchSnapshot()
|
|
304
304
|
})
|
|
305
|
-
|
|
306
305
|
})
|
|
307
306
|
describe('mutations without trx', () => {
|
|
308
307
|
test('create', async () => {
|
|
@@ -319,7 +318,6 @@ describe('mutations without trx', () => {
|
|
|
319
318
|
})
|
|
320
319
|
const result = await client.mutate(createAuthor)
|
|
321
320
|
|
|
322
|
-
|
|
323
321
|
expect(result.ok).toBe(true)
|
|
324
322
|
expect(calls).toHaveLength(1)
|
|
325
323
|
expect(calls[0].query).toMatchSnapshot()
|
|
@@ -518,4 +516,51 @@ describe('mutations without trx', () => {
|
|
|
518
516
|
expect(calls[0].variables).toMatchSnapshot()
|
|
519
517
|
})
|
|
520
518
|
|
|
519
|
+
test('mutate or fail - fail', async () => {
|
|
520
|
+
const [client, calls] = createClient({
|
|
521
|
+
mut: {
|
|
522
|
+
ok: false,
|
|
523
|
+
errorMessage: 'some error',
|
|
524
|
+
mut: {
|
|
525
|
+
ok: false,
|
|
526
|
+
},
|
|
527
|
+
},
|
|
528
|
+
})
|
|
529
|
+
const createAuthor = qb.transaction(qb.create('Author', {
|
|
530
|
+
data: {
|
|
531
|
+
name: 'John',
|
|
532
|
+
email: 'xx@localhost',
|
|
533
|
+
},
|
|
534
|
+
}))
|
|
535
|
+
expect(() => client.mutateOrThrow(createAuthor)).toThrow('some error')
|
|
536
|
+
expect(calls).toHaveLength(1)
|
|
537
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
538
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
539
|
+
})
|
|
540
|
+
|
|
541
|
+
test('mutate or fail - ok', async () => {
|
|
542
|
+
const [client, calls] = createClient({
|
|
543
|
+
mut: {
|
|
544
|
+
ok: true,
|
|
545
|
+
errorMessage: null,
|
|
546
|
+
mut: {
|
|
547
|
+
ok: true,
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
})
|
|
551
|
+
const createAuthor = qb.transaction(qb.create('Author', {
|
|
552
|
+
data: {
|
|
553
|
+
name: 'John',
|
|
554
|
+
email: 'xx@localhost',
|
|
555
|
+
},
|
|
556
|
+
}))
|
|
557
|
+
const result = await client.mutateOrThrow(createAuthor)
|
|
558
|
+
expect(result.ok).toBe(true)
|
|
559
|
+
const ok = result.ok
|
|
560
|
+
expectTypeOf(ok).toEqualTypeOf<true>()
|
|
561
|
+
|
|
562
|
+
expect(calls).toHaveLength(1)
|
|
563
|
+
expect(calls[0].query).toMatchSnapshot()
|
|
564
|
+
expect(calls[0].variables).toMatchSnapshot()
|
|
565
|
+
})
|
|
521
566
|
})
|