@contember/client-content 2.1.0-alpha.9 → 2.1.0-beta.1

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 (106) hide show
  1. package/CLAUDE.md +52 -0
  2. package/dist/development/src/ContentClient.cjs +12 -0
  3. package/dist/development/src/ContentClient.cjs.map +1 -1
  4. package/dist/development/src/ContentClient.js +12 -0
  5. package/dist/development/src/ContentClient.js.map +1 -1
  6. package/dist/development/src/ContentQueryBuilder.cjs +26 -15
  7. package/dist/development/src/ContentQueryBuilder.cjs.map +1 -1
  8. package/dist/development/src/ContentQueryBuilder.js +26 -15
  9. package/dist/development/src/ContentQueryBuilder.js.map +1 -1
  10. package/dist/development/src/MutationFailedError.cjs +11 -0
  11. package/dist/development/src/MutationFailedError.cjs.map +1 -0
  12. package/dist/development/src/MutationFailedError.js +11 -0
  13. package/dist/development/src/MutationFailedError.js.map +1 -0
  14. package/dist/development/src/nodes/ContentEntitySelection.cjs +47 -12
  15. package/dist/development/src/nodes/ContentEntitySelection.cjs.map +1 -1
  16. package/dist/development/src/nodes/ContentEntitySelection.js +47 -12
  17. package/dist/development/src/nodes/ContentEntitySelection.js.map +1 -1
  18. package/dist/development/src/nodes/ContentOperation.cjs.map +1 -1
  19. package/dist/development/src/nodes/ContentOperation.js.map +1 -1
  20. package/dist/development/src/utils/ContentOperationSet.cjs.map +1 -1
  21. package/dist/development/src/utils/ContentOperationSet.js.map +1 -1
  22. package/dist/development/src/utils/createListArgs.cjs.map +1 -1
  23. package/dist/development/src/utils/createListArgs.js.map +1 -1
  24. package/dist/development/src/utils/createMutationOperationSet.cjs +8 -6
  25. package/dist/development/src/utils/createMutationOperationSet.cjs.map +1 -1
  26. package/dist/development/src/utils/createMutationOperationSet.js +8 -6
  27. package/dist/development/src/utils/createMutationOperationSet.js.map +1 -1
  28. package/dist/development/src/utils/createQueryOperationSet.cjs.map +1 -1
  29. package/dist/development/src/utils/createQueryOperationSet.js.map +1 -1
  30. package/dist/development/src/utils/createTypedArgs.cjs.map +1 -1
  31. package/dist/development/src/utils/createTypedArgs.js.map +1 -1
  32. package/dist/development/src/utils/mutationFragments.cjs.map +1 -1
  33. package/dist/development/src/utils/mutationFragments.js.map +1 -1
  34. package/dist/production/src/ContentClient.cjs +12 -0
  35. package/dist/production/src/ContentClient.cjs.map +1 -1
  36. package/dist/production/src/ContentClient.js +12 -0
  37. package/dist/production/src/ContentClient.js.map +1 -1
  38. package/dist/production/src/ContentQueryBuilder.cjs +26 -15
  39. package/dist/production/src/ContentQueryBuilder.cjs.map +1 -1
  40. package/dist/production/src/ContentQueryBuilder.js +26 -15
  41. package/dist/production/src/ContentQueryBuilder.js.map +1 -1
  42. package/dist/production/src/MutationFailedError.cjs +11 -0
  43. package/dist/production/src/MutationFailedError.cjs.map +1 -0
  44. package/dist/production/src/MutationFailedError.js +11 -0
  45. package/dist/production/src/MutationFailedError.js.map +1 -0
  46. package/dist/production/src/nodes/ContentEntitySelection.cjs +47 -12
  47. package/dist/production/src/nodes/ContentEntitySelection.cjs.map +1 -1
  48. package/dist/production/src/nodes/ContentEntitySelection.js +47 -12
  49. package/dist/production/src/nodes/ContentEntitySelection.js.map +1 -1
  50. package/dist/production/src/nodes/ContentOperation.cjs.map +1 -1
  51. package/dist/production/src/nodes/ContentOperation.js.map +1 -1
  52. package/dist/production/src/utils/ContentOperationSet.cjs.map +1 -1
  53. package/dist/production/src/utils/ContentOperationSet.js.map +1 -1
  54. package/dist/production/src/utils/createListArgs.cjs.map +1 -1
  55. package/dist/production/src/utils/createListArgs.js.map +1 -1
  56. package/dist/production/src/utils/createMutationOperationSet.cjs +8 -6
  57. package/dist/production/src/utils/createMutationOperationSet.cjs.map +1 -1
  58. package/dist/production/src/utils/createMutationOperationSet.js +8 -6
  59. package/dist/production/src/utils/createMutationOperationSet.js.map +1 -1
  60. package/dist/production/src/utils/createQueryOperationSet.cjs.map +1 -1
  61. package/dist/production/src/utils/createQueryOperationSet.js.map +1 -1
  62. package/dist/production/src/utils/createTypedArgs.cjs.map +1 -1
  63. package/dist/production/src/utils/createTypedArgs.js.map +1 -1
  64. package/dist/production/src/utils/mutationFragments.cjs.map +1 -1
  65. package/dist/production/src/utils/mutationFragments.js.map +1 -1
  66. package/dist/types/ContentClient.d.ts +10 -0
  67. package/dist/types/ContentClient.d.ts.map +1 -1
  68. package/dist/types/ContentQueryBuilder.d.ts.map +1 -1
  69. package/dist/types/MutationFailedError.d.ts +13 -0
  70. package/dist/types/MutationFailedError.d.ts.map +1 -0
  71. package/dist/types/TypedContentQueryBuilder.d.ts.map +1 -1
  72. package/dist/types/nodes/ContentEntitySelection.d.ts +4 -1
  73. package/dist/types/nodes/ContentEntitySelection.d.ts.map +1 -1
  74. package/dist/types/nodes/TypedEntitySelection.d.ts +1 -0
  75. package/dist/types/nodes/TypedEntitySelection.d.ts.map +1 -1
  76. package/dist/types/tsconfig.tsbuildinfo +1 -1
  77. package/dist/types/types/Input.d.ts.map +1 -1
  78. package/dist/types/types/Result.d.ts +30 -9
  79. package/dist/types/types/Result.d.ts.map +1 -1
  80. package/dist/types/utils/createListArgs.d.ts.map +1 -1
  81. package/dist/types/utils/createMutationOperationSet.d.ts.map +1 -1
  82. package/dist/types/utils/createQueryOperationSet.d.ts.map +1 -1
  83. package/package.json +6 -6
  84. package/src/ContentClient.ts +36 -9
  85. package/src/ContentQueryBuilder.ts +45 -35
  86. package/src/MutationFailedError.ts +19 -0
  87. package/src/TypedContentQueryBuilder.ts +0 -4
  88. package/src/nodes/ContentEntitySelection.ts +67 -23
  89. package/src/nodes/TypedEntitySelection.ts +96 -48
  90. package/src/types/Input.ts +1 -9
  91. package/src/types/Result.ts +41 -9
  92. package/src/types/Schema.ts +0 -1
  93. package/src/utils/createListArgs.ts +5 -1
  94. package/src/utils/createMutationOperationSet.ts +9 -7
  95. package/src/utils/createQueryOperationSet.ts +0 -1
  96. package/tests/cases/unit/__snapshots__/mutation.test.ts.snap +952 -818
  97. package/tests/cases/unit/__snapshots__/query.test.ts.snap +216 -60
  98. package/tests/cases/unit/mutation.test.ts +48 -3
  99. package/tests/cases/unit/query.test.ts +103 -82
  100. package/tests/cases/unit/types.test.ts +31 -27
  101. package/tests/client/entities.ts +2 -0
  102. package/tests/client/enums.ts +5 -0
  103. package/tests/client/names.ts +129 -117
  104. package/tests/generate.ts +0 -1
  105. package/tests/lib.ts +0 -1
  106. package/tests/schema.ts +1 -2
@@ -1,102 +1,258 @@
1
- // Bun Snapshot v1, https://goo.gl/fbAQLP
1
+ // Bun Snapshot v1, https://bun.sh/docs/test/snapshots
2
2
 
3
3
  exports[`queries list 1`] = `
4
4
  "query {
5
- \tauthors: listAuthor {
6
- \t\tid
7
- \t\tname
8
- \t\temail
9
- \t}
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
- \tauthors: listAuthor {
17
- \t\tid
18
- \t\tname
19
- \t\temail
20
- \t}
21
- \tposts: listPost {
22
- \t\tid
23
- \t\tpublishedAt
24
- \t}
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
- \tvalue: listPost {
32
- \t\tid
33
- \t\tpublishedAt
34
- \t}
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
- \tauthors: listAuthor {
42
- \t\tid
43
- \t\tname
44
- \t\temail
45
- \t\tposts {
46
- \t\t\tid
47
- \t\t\tpublishedAt
48
- \t\t\ttags {
49
- \t\t\t\tid
50
- \t\t\t\tname
51
- \t\t\t}
52
- \t\t}
53
- \t}
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
- \tauthors: listAuthor {
61
- \t\tid
62
- \t\tname
63
- \t\temail
64
- \t\tposts(filter: $PostWhere_0, limit: $Int_1) {
65
- \t\t\tid
66
- \t\t\tpublishedAt
67
- \t\t}
68
- \t}
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
- \t\t\t"query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
75
- \t\t\t\tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
76
- \t\t\t\t\tid
77
- \t\t\t\t\tname
78
- \t\t\t\t\temail
79
- \t\t\t\t}
80
- \t\t\t}
81
- \t\t\t"
82
- \t\t 1`] = `
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
- \tauthors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
85
- \t\tid
86
- \t\tname
87
- \t\temail
88
- \t}
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
- \tauthors: getAuthor(by: $AuthorUniqueWhere_0) {
96
- \t\tid
97
- \t\tname
98
- \t\temail
99
- \t}
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
  })