@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
@@ -1,138 +1,134 @@
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 {
48
+ id
49
+ publishedAt
50
+ status
51
+ tags {
52
+ id
53
+ name
54
+ }
55
+ }
56
+ }
54
57
  }
55
58
  "
56
59
  `;
57
60
 
58
61
  exports[`queries nested object args 1`] = `
59
62
  "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}
63
+ authors: listAuthor {
64
+ id
65
+ name
66
+ email
67
+ posts(filter: $PostWhere_0, limit: $Int_1) {
68
+ id
69
+ publishedAt
70
+ status
71
+ }
72
+ }
69
73
  }
70
74
  "
71
75
  `;
72
76
 
73
77
  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`] = `
78
+ "query($AuthorWhere_0: AuthorWhere, $AuthorOrderBy_1: [AuthorOrderBy!], $Int_2: Int, $Int_3: Int) {
79
+ authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
80
+ id
81
+ name
82
+ email
83
+ }
84
+ }
85
+ "
86
+ 1`] = `
83
87
  "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}
88
+ authors: listAuthor(filter: $AuthorWhere_0, orderBy: $AuthorOrderBy_1, limit: $Int_2, offset: $Int_3) {
89
+ id
90
+ name
91
+ email
92
+ }
89
93
  }
90
94
  "
91
95
  `;
92
96
 
93
97
  exports[`queries get by id 1`] = `
94
98
  "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
95
- \tauthors: getAuthor(by: $AuthorUniqueWhere_0) {
96
- \t\tid
97
- \t\tname
98
- \t\temail
99
- \t}
99
+ authors: getAuthor(by: $AuthorUniqueWhere_0) {
100
+ id
101
+ name
102
+ email
103
+ }
100
104
  }
101
105
  "
102
106
  `;
103
107
 
104
- exports[`queries nested has-many transform 1`] = `
108
+ exports[`queries top level list transform 1`] = `
105
109
  [
106
110
  {
107
111
  "query":
108
- "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
109
- author: getAuthor(by: $AuthorUniqueWhere_0) {
112
+ "query {
113
+ authors: listAuthor {
110
114
  id
111
115
  name
112
116
  email
113
- posts {
114
- id
115
- publishedAt
116
- }
117
117
  }
118
118
  }
119
119
  "
120
120
  ,
121
- "variables": {
122
- "AuthorUniqueWhere_0": {
123
- "id": "123",
124
- },
125
- },
121
+ "variables": {},
126
122
  },
127
123
  ]
128
124
  `;
129
125
 
130
- exports[`queries top level list transform 1`] = `
126
+ exports[`queries top level get transform 1`] = `
131
127
  [
132
128
  {
133
129
  "query":
134
- "query {
135
- authors: listAuthor {
130
+ "query($AuthorUniqueWhere_0: AuthorUniqueWhere!) {
131
+ author: getAuthor(by: $AuthorUniqueWhere_0) {
136
132
  id
137
133
  name
138
134
  email
@@ -140,12 +136,16 @@ exports[`queries top level list transform 1`] = `
140
136
  }
141
137
  "
142
138
  ,
143
- "variables": {},
139
+ "variables": {
140
+ "AuthorUniqueWhere_0": {
141
+ "id": "123",
142
+ },
143
+ },
144
144
  },
145
145
  ]
146
146
  `;
147
147
 
148
- exports[`queries top level get transform 1`] = `
148
+ exports[`queries nested has-many transform 1`] = `
149
149
  [
150
150
  {
151
151
  "query":
@@ -154,6 +154,11 @@ exports[`queries top level get transform 1`] = `
154
154
  id
155
155
  name
156
156
  email
157
+ posts {
158
+ id
159
+ publishedAt
160
+ status
161
+ }
157
162
  }
158
163
  }
159
164
  "
@@ -175,6 +180,7 @@ exports[`queries nested has-one transform 1`] = `
175
180
  post: getPost(by: $PostUniqueWhere_0) {
176
181
  id
177
182
  publishedAt
183
+ status
178
184
  author {
179
185
  id
180
186
  name
@@ -201,6 +207,7 @@ exports[`queries nested has-many-by transform 1`] = `
201
207
  post: getPost(by: $PostUniqueWhere_0) {
202
208
  id
203
209
  publishedAt
210
+ status
204
211
  localesByLocale(by: $PostLocalesByLocaleUniqueWhere_1) {
205
212
  id
206
213
  title
@@ -22,7 +22,6 @@ describe('mutations in trx', () => {
22
22
  }))
23
23
  const result = await client.mutate(createAuthor)
24
24
 
25
-
26
25
  expect(result.data.ok).toBe(true)
27
26
  expect(calls).toHaveLength(1)
28
27
  expect(calls[0].query).toMatchSnapshot()
@@ -303,7 +302,6 @@ describe('mutations in trx', () => {
303
302
  expect(calls[0].query).toMatchSnapshot()
304
303
  expect(calls[0].variables).toMatchSnapshot()
305
304
  })
306
-
307
305
  })
308
306
  describe('mutations without trx', () => {
309
307
  test('create', async () => {
@@ -320,7 +318,6 @@ describe('mutations without trx', () => {
320
318
  })
321
319
  const result = await client.mutate(createAuthor)
322
320
 
323
-
324
321
  expect(result.ok).toBe(true)
325
322
  expect(calls).toHaveLength(1)
326
323
  expect(calls[0].query).toMatchSnapshot()
@@ -541,7 +538,6 @@ describe('mutations without trx', () => {
541
538
  expect(calls[0].variables).toMatchSnapshot()
542
539
  })
543
540
 
544
-
545
541
  test('mutate or fail - ok', async () => {
546
542
  const [client, calls] = createClient({
547
543
  mut: {
@@ -5,7 +5,6 @@ import OrderDirection = Input.OrderDirection
5
5
  import { queryBuilder } from '../../client'
6
6
 
7
7
  describe('queries', () => {
8
-
9
8
  const qb = queryBuilder
10
9
  test('list', async () => {
11
10
  const [client, calls] = createClient({
@@ -98,7 +97,6 @@ describe('queries', () => {
98
97
  expect(calls[0].variables).toEqual({})
99
98
  })
100
99
 
101
-
102
100
  test('single query', async () => {
103
101
  const [client, calls] = createClient({
104
102
  value: [
@@ -129,7 +127,6 @@ describe('queries', () => {
129
127
  expect(calls[0].variables).toEqual({})
130
128
  })
131
129
 
132
-
133
130
  test('nested object', async () => {
134
131
  const [client, calls] = createClient()
135
132
  await client.query({
@@ -142,10 +139,11 @@ describe('queries', () => {
142
139
  test('nested object args', async () => {
143
140
  const [client, calls] = createClient()
144
141
  await client.query({
145
- authors: qb.list('Author', {}, it => it.$$().$('posts', {
146
- limit: 10,
147
- filter: { tags: { name: { eq: 'foo' } } },
148
- }, it => it.$$())),
142
+ authors: qb.list('Author', {}, it =>
143
+ it.$$().$('posts', {
144
+ limit: 10,
145
+ filter: { tags: { name: { eq: 'foo' } } },
146
+ }, it => it.$$())),
149
147
  })
150
148
  expect(calls).toHaveLength(1)
151
149
  expect(calls[0].query).toMatchSnapshot()
@@ -161,7 +159,6 @@ describe('queries', () => {
161
159
  })
162
160
  })
163
161
 
164
-
165
162
  test('list with args', async () => {
166
163
  const [client, calls] = createClient()
167
164
  await client.query({
@@ -201,7 +198,6 @@ describe('queries', () => {
201
198
  )
202
199
  })
203
200
 
204
-
205
201
  test('get by id', async () => {
206
202
  const [client, calls] = createClient()
207
203
  const result = await client.query({
@@ -232,13 +228,13 @@ describe('queries', () => {
232
228
  ],
233
229
  })
234
230
  const result = await client.query({
235
- authors: qb.list('Author', {}, it => it
236
- .$$()
237
- .transform(it => ({
238
- ...it,
239
- label: `${it.name} (${it.email})`,
240
- })),
241
- ),
231
+ authors: qb.list('Author', {}, it =>
232
+ it
233
+ .$$()
234
+ .transform(it => ({
235
+ ...it,
236
+ label: `${it.name} (${it.email})`,
237
+ }))),
242
238
  })
243
239
  expect(result as any).toStrictEqual({
244
240
  authors: [
@@ -266,13 +262,13 @@ describe('queries', () => {
266
262
  },
267
263
  })
268
264
  const result = await client.query({
269
- author: qb.get('Author', { by: { id: '123' } }, it => it
270
- .$$()
271
- .transform(it => ({
272
- ...it,
273
- label: `${it.name} (${it.email})`,
274
- })),
275
- ),
265
+ author: qb.get('Author', { by: { id: '123' } }, it =>
266
+ it
267
+ .$$()
268
+ .transform(it => ({
269
+ ...it,
270
+ label: `${it.name} (${it.email})`,
271
+ }))),
276
272
  })
277
273
  expect(result as any).toStrictEqual({
278
274
  author: {
@@ -285,7 +281,6 @@ describe('queries', () => {
285
281
  expect(calls).toMatchSnapshot()
286
282
  })
287
283
 
288
-
289
284
  test('nested has-many transform', async () => {
290
285
  const [client, calls] = createClient({
291
286
  author: {
@@ -302,13 +297,14 @@ describe('queries', () => {
302
297
  },
303
298
  })
304
299
  const result = await client.query({
305
- author: qb.get('Author', { by: { id: '123' } }, it => it
306
- .$$()
307
- .$('posts', {}, it => it.$$().transform(it => ({
308
- ...it,
309
- publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
310
- }))),
311
- ),
300
+ author: qb.get('Author', { by: { id: '123' } }, it =>
301
+ it
302
+ .$$()
303
+ .$('posts', {}, it =>
304
+ it.$$().transform(it => ({
305
+ ...it,
306
+ publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
307
+ })))),
312
308
  })
313
309
  expect(result as any).toStrictEqual({
314
310
  author: {
@@ -330,7 +326,6 @@ describe('queries', () => {
330
326
  expect(calls).toMatchSnapshot()
331
327
  })
332
328
 
333
-
334
329
  test('nested has-one transform', async () => {
335
330
  const [client, calls] = createClient({
336
331
  post: {
@@ -341,19 +336,19 @@ describe('queries', () => {
341
336
  },
342
337
  },
343
338
  })
344
- const author = qb.fragment('Author', it => it
345
- .$$()
346
- .transform(it => ({
347
- ...it,
348
- label: `${it.name} (${it.email})`,
349
- })),
350
- )
339
+ const author = qb.fragment('Author', it =>
340
+ it
341
+ .$$()
342
+ .transform(it => ({
343
+ ...it,
344
+ label: `${it.name} (${it.email})`,
345
+ })))
351
346
 
352
347
  const result = await client.query({
353
- post: qb.get('Post', { by: { id: '123' } }, it => it
354
- .$$()
355
- .$('author', author),
356
- ),
348
+ post: qb.get('Post', { by: { id: '123' } }, it =>
349
+ it
350
+ .$$()
351
+ .$('author', author)),
357
352
  })
358
353
  expect(result as any).toStrictEqual({
359
354
  post: {
@@ -368,7 +363,6 @@ describe('queries', () => {
368
363
  expect(calls).toMatchSnapshot()
369
364
  })
370
365
 
371
-
372
366
  test('nested has-many-by transform', async () => {
373
367
  const [client, calls] = createClient({
374
368
  post: {
@@ -379,13 +373,14 @@ describe('queries', () => {
379
373
  },
380
374
  })
381
375
  const result = await client.query({
382
- post: qb.get('Post', { by: { id: '123' } }, it => it
383
- .$$()
384
- .$('localesByLocale', { by: { locale: { code: 'en' } } }, it => it.$$().transform(it => ({
385
- ...it,
386
- label: it.title?.toUpperCase(),
387
- }))),
388
- ),
376
+ post: qb.get('Post', { by: { id: '123' } }, it =>
377
+ it
378
+ .$$()
379
+ .$('localesByLocale', { by: { locale: { code: 'en' } } }, it =>
380
+ it.$$().transform(it => ({
381
+ ...it,
382
+ label: it.title?.toUpperCase(),
383
+ })))),
389
384
  })
390
385
  expect(result as any).toStrictEqual({
391
386
  post: {
@@ -415,21 +410,22 @@ describe('queries', () => {
415
410
  },
416
411
  })
417
412
  const result = await client.query({
418
- author: qb.get('Author', { by: { id: '123' } }, it => it
419
- .$$()
420
- .transform(it => ({
421
- ...it,
422
- value1: 'foo',
423
- }))
424
- .$('posts', {}, it => it.$$().transform(it => ({
425
- ...it,
426
- postLabel: 'foo bar',
427
- })))
428
- .transform(it => ({
429
- ...it,
430
- value2: 'bar',
431
- })),
432
- ),
413
+ author: qb.get('Author', { by: { id: '123' } }, it =>
414
+ it
415
+ .$$()
416
+ .transform(it => ({
417
+ ...it,
418
+ value1: 'foo',
419
+ }))
420
+ .$('posts', {}, it =>
421
+ it.$$().transform(it => ({
422
+ ...it,
423
+ postLabel: 'foo bar',
424
+ })))
425
+ .transform(it => ({
426
+ ...it,
427
+ value2: 'bar',
428
+ }))),
433
429
  })
434
430
  expect(result as any).toStrictEqual({
435
431
  author: {
@@ -476,5 +472,4 @@ describe('queries', () => {
476
472
  expect(calls[0].query).toMatchSnapshot()
477
473
  expect(calls[0].variables).toStrictEqual({})
478
474
  })
479
-
480
475
  })
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/ban-ts-comment */
2
2
  import { describe, expect, test } from 'bun:test'
3
3
  import { ContentClientInput } from '../../../src'
4
- import { ContemberClientEntities, FragmentOf, FragmentType, queryBuilder } from '../../client'
4
+ import { ContemberClientEntities, FragmentOf, FragmentType, PostStatus, queryBuilder } from '../../client'
5
5
  import { expectTypeOf } from 'expect-type'
6
6
 
7
7
  const qb = queryBuilder
@@ -75,10 +75,11 @@ describe('ts types', () => {
75
75
  test('has one field on fragment type', async () => {
76
76
  const fragment = qb.fragment('Post', it => it.$('author', it => it.$$().$('posts', it => it.$('id'))))
77
77
  type fragmentType = FragmentType<typeof fragment>
78
- expectTypeOf<fragmentType>().toEqualTypeOf<{ author: ({ id: string; name: string | null; email: string | null } & { posts: { id: string }[] }) | null }>()
78
+ expectTypeOf<fragmentType>().toEqualTypeOf<
79
+ { author: ({ id: string; name: string | null; email: string | null } & { posts: { id: string }[] }) | null }
80
+ >()
79
81
  })
80
82
 
81
-
82
83
  test('has one without arg', async () => {
83
84
  qb.list('Post', {}, it => it.$('author', it => it.$$()))
84
85
  })
@@ -88,13 +89,13 @@ describe('ts types', () => {
88
89
  })
89
90
 
90
91
  test('has one with invalid arg', async () => {
91
- qb.list('Post', {}, it => it
92
- .$('author',
93
- // @ts-expect-error
94
- { filter: { foo: { eq: 'xx' } } },
95
- it => it.$$(),
96
- ),
97
- )
92
+ qb.list('Post', {}, it =>
93
+ it
94
+ .$(
95
+ 'author', // @ts-expect-error
96
+ { filter: { foo: { eq: 'xx' } } },
97
+ it => it.$$(),
98
+ ))
98
99
  })
99
100
 
100
101
  test('has many without arg', async () => {
@@ -102,36 +103,33 @@ describe('ts types', () => {
102
103
  })
103
104
 
104
105
  test('has many with arg', async () => {
105
- qb.list('Post', {}, it => it.$('locales', { filter: { locale: { code: { eq: 'cs' } } } }, it => it.$$()))
106
+ qb.list('Post', {}, it => it.$('locales', { filter: { locale: { code: { eq: 'cs' } } } }, it => it.$$()))
106
107
  })
107
108
 
108
109
  test('has many with invalid arg', async () => {
109
- qb.list('Post', {}, it => it
110
- .$('locales',
111
- // @ts-expect-error
112
- { filter: { locale: { eq: 'cs' } } },
113
- it => it.$$(),
114
- ),
115
- )
110
+ qb.list('Post', {}, it =>
111
+ it
112
+ .$(
113
+ 'locales', // @ts-expect-error
114
+ { filter: { locale: { eq: 'cs' } } },
115
+ it => it.$$(),
116
+ ))
116
117
  })
117
118
 
118
119
  test('reduced has may', async () => {
119
- qb.list('Post', {}, it => it.$('localesByLocale', { by: { locale: { code: 'cs' } } }, it => it.$$()))
120
+ qb.list('Post', {}, it => it.$('localesByLocale', { by: { locale: { code: 'cs' } } }, it => it.$$()))
120
121
  })
121
122
 
122
123
  test('reduced has may - invalid "by"', async () => {
123
- qb.list('Post',
124
- {},
125
- it => it
126
- .$('localesByLocale',
127
- // @ts-expect-error
124
+ qb.list('Post', {}, it =>
125
+ it
126
+ .$(
127
+ 'localesByLocale', // @ts-expect-error
128
128
  { by: { locale: {} } },
129
129
  qb.fragment('PostLocale'),
130
- ),
131
- )
130
+ ))
132
131
  })
133
132
 
134
-
135
133
  test('invalid field', async () => {
136
134
  expect(() => {
137
135
  qb.list(
@@ -146,6 +144,6 @@ describe('ts types', () => {
146
144
  test('omit', async () => {
147
145
  const fragment = qb.fragment('Post', it => it.$$().omit('publishedAt'))
148
146
  type fragmentType = FragmentType<typeof fragment>
149
- expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string }>()
147
+ expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string; status: PostStatus | null }>()
150
148
  })
151
149
  })
@@ -1,3 +1,4 @@
1
+ import type { PostStatus } from './enums'
1
2
 
2
3
  export type JSONPrimitive = string | number | boolean | null
3
4
  export type JSONValue = JSONPrimitive | JSONObject | JSONArray
@@ -47,6 +48,7 @@ export type Post <OverRelation extends string | never = never> = {
47
48
  columns: {
48
49
  id: string
49
50
  publishedAt: string | null
51
+ status: PostStatus | null
50
52
  }
51
53
  hasOne: {
52
54
  author: Author
@@ -1,3 +1,8 @@
1
+ export type PostStatus =
2
+ | "draft"
3
+ | "published"
4
+ | "archived"
1
5
  export type ContemberClientEnums = {
6
+ PostStatus: PostStatus
2
7
  }
3
8