@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.
Files changed (107) 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
  107. package/vitest.config.ts +0 -3
@@ -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: [
@@ -255,6 +251,7 @@ describe('queries', () => {
255
251
  ],
256
252
  })
257
253
  expect(calls).toHaveLength(1)
254
+ expect(calls).toMatchSnapshot()
258
255
  })
259
256
 
260
257
  test('top level get transform', async () => {
@@ -265,13 +262,13 @@ describe('queries', () => {
265
262
  },
266
263
  })
267
264
  const result = await client.query({
268
- author: qb.get('Author', { by: { id: '123' } }, it => it
269
- .$$()
270
- .transform(it => ({
271
- ...it,
272
- label: `${it.name} (${it.email})`,
273
- })),
274
- ),
265
+ author: qb.get('Author', { by: { id: '123' } }, it =>
266
+ it
267
+ .$$()
268
+ .transform(it => ({
269
+ ...it,
270
+ label: `${it.name} (${it.email})`,
271
+ }))),
275
272
  })
276
273
  expect(result as any).toStrictEqual({
277
274
  author: {
@@ -281,32 +278,31 @@ describe('queries', () => {
281
278
  },
282
279
  })
283
280
  expect(calls).toHaveLength(1)
281
+ expect(calls).toMatchSnapshot()
284
282
  })
285
283
 
286
-
287
284
  test('nested has-many transform', async () => {
288
285
  const [client, calls] = createClient({
289
286
  author: {
290
287
  name: 'John',
291
288
  email: 'foo@localhost',
292
- posts: [
293
- {
294
- publishedAt: '2021-01-01T00:00:00Z',
295
- },
296
- {
297
- publishedAt: '2021-01-02T00:00:00Z',
298
- },
299
- ],
289
+ posts: {
290
+ edges: [
291
+ { node: { publishedAt: '2021-01-01T00:00:00Z' } },
292
+ { node: { publishedAt: '2021-01-02T00:00:00Z' } },
293
+ ],
294
+ },
300
295
  },
301
296
  })
302
297
  const result = await client.query({
303
- author: qb.get('Author', { by: { id: '123' } }, it => it
304
- .$$()
305
- .$('posts', {}, it => it.$$().transform(it => ({
306
- ...it,
307
- publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
308
- }))),
309
- ),
298
+ author: qb.get('Author', { by: { id: '123' } }, it =>
299
+ it
300
+ .$$()
301
+ .$('posts', {}, it =>
302
+ it.$$().transform(it => ({
303
+ ...it,
304
+ publishYear: it.publishedAt ? new Date(it.publishedAt).getFullYear() : null,
305
+ })))),
310
306
  })
311
307
  expect(result as any).toStrictEqual({
312
308
  author: {
@@ -325,9 +321,9 @@ describe('queries', () => {
325
321
  },
326
322
  })
327
323
  expect(calls).toHaveLength(1)
324
+ expect(calls).toMatchSnapshot()
328
325
  })
329
326
 
330
-
331
327
  test('nested has-one transform', async () => {
332
328
  const [client, calls] = createClient({
333
329
  post: {
@@ -338,19 +334,19 @@ describe('queries', () => {
338
334
  },
339
335
  },
340
336
  })
341
- const author = qb.fragment('Author', it => it
342
- .$$()
343
- .transform(it => ({
344
- ...it,
345
- label: `${it.name} (${it.email})`,
346
- })),
347
- )
337
+ const author = qb.fragment('Author', it =>
338
+ it
339
+ .$$()
340
+ .transform(it => ({
341
+ ...it,
342
+ label: `${it.name} (${it.email})`,
343
+ })))
348
344
 
349
345
  const result = await client.query({
350
- post: qb.get('Post', { by: { id: '123' } }, it => it
351
- .$$()
352
- .$('author', author),
353
- ),
346
+ post: qb.get('Post', { by: { id: '123' } }, it =>
347
+ it
348
+ .$$()
349
+ .$('author', author)),
354
350
  })
355
351
  expect(result as any).toStrictEqual({
356
352
  post: {
@@ -362,9 +358,9 @@ describe('queries', () => {
362
358
  },
363
359
  },
364
360
  })
361
+ expect(calls).toMatchSnapshot()
365
362
  })
366
363
 
367
-
368
364
  test('nested has-many-by transform', async () => {
369
365
  const [client, calls] = createClient({
370
366
  post: {
@@ -375,13 +371,14 @@ describe('queries', () => {
375
371
  },
376
372
  })
377
373
  const result = await client.query({
378
- post: qb.get('Post', { by: { id: '123' } }, it => it
379
- .$$()
380
- .$('localesByLocale', { by: { locale: { code: 'en' } } }, it => it.$$().transform(it => ({
381
- ...it,
382
- label: it.title?.toUpperCase(),
383
- }))),
384
- ),
374
+ post: qb.get('Post', { by: { id: '123' } }, it =>
375
+ it
376
+ .$$()
377
+ .$('localesByLocale', { by: { locale: { code: 'en' } } }, it =>
378
+ it.$$().transform(it => ({
379
+ ...it,
380
+ label: it.title?.toUpperCase(),
381
+ })))),
385
382
  })
386
383
  expect(result as any).toStrictEqual({
387
384
  post: {
@@ -392,6 +389,7 @@ describe('queries', () => {
392
389
  },
393
390
  },
394
391
  })
392
+ expect(calls).toMatchSnapshot()
395
393
  })
396
394
 
397
395
  test('multiple transforms', async () => {
@@ -399,32 +397,31 @@ describe('queries', () => {
399
397
  author: {
400
398
  name: 'John',
401
399
  email: 'foo@localhost',
402
- posts: [
403
- {
404
- publishedAt: '2021-01-01T00:00:00Z',
405
- },
406
- {
407
- publishedAt: '2021-01-02T00:00:00Z',
408
- },
409
- ],
400
+ posts: {
401
+ edges: [
402
+ { node: { publishedAt: '2021-01-01T00:00:00Z' } },
403
+ { node: { publishedAt: '2021-01-02T00:00:00Z' } },
404
+ ],
405
+ },
410
406
  },
411
407
  })
412
408
  const result = await client.query({
413
- author: qb.get('Author', { by: { id: '123' } }, it => it
414
- .$$()
415
- .transform(it => ({
416
- ...it,
417
- value1: 'foo',
418
- }))
419
- .$('posts', {}, it => it.$$().transform(it => ({
420
- ...it,
421
- postLabel: 'foo bar',
422
- })))
423
- .transform(it => ({
424
- ...it,
425
- value2: 'bar',
426
- })),
427
- ),
409
+ author: qb.get('Author', { by: { id: '123' } }, it =>
410
+ it
411
+ .$$()
412
+ .transform(it => ({
413
+ ...it,
414
+ value1: 'foo',
415
+ }))
416
+ .$('posts', {}, it =>
417
+ it.$$().transform(it => ({
418
+ ...it,
419
+ postLabel: 'foo bar',
420
+ })))
421
+ .transform(it => ({
422
+ ...it,
423
+ value2: 'bar',
424
+ }))),
428
425
  })
429
426
  expect(result as any).toStrictEqual({
430
427
  author: {
@@ -447,4 +444,28 @@ describe('queries', () => {
447
444
  expect(calls).toHaveLength(1)
448
445
  })
449
446
 
447
+ test('omit', async () => {
448
+ const [client, calls] = createClient({
449
+ authors: [
450
+ {
451
+ id: '1',
452
+ name: 'John',
453
+ },
454
+ ],
455
+ })
456
+ const result = await client.query({
457
+ authors: qb.list('Author', {}, it => it.$$().omit('email').$('posts', {}, it => it.$$()).omit('posts')),
458
+ })
459
+ expect(result).toStrictEqual({
460
+ authors: [
461
+ {
462
+ id: '1',
463
+ name: 'John',
464
+ },
465
+ ],
466
+ })
467
+ expect(calls).toHaveLength(1)
468
+ expect(calls[0].query).toMatchSnapshot()
469
+ expect(calls[0].variables).toStrictEqual({})
470
+ })
450
471
  })
@@ -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(
@@ -142,4 +140,10 @@ describe('ts types', () => {
142
140
  )
143
141
  }).toThrow('Field Post.lorem does not exist.')
144
142
  })
143
+
144
+ test('omit', async () => {
145
+ const fragment = qb.fragment('Post', it => it.$$().omit('publishedAt'))
146
+ type fragmentType = FragmentType<typeof fragment>
147
+ expectTypeOf<fragmentType>().toEqualTypeOf<{ id: string; status: PostStatus | null }>()
148
+ })
145
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