@contember/engine-content-api 1.2.0-alpha.1 → 1.2.0-alpha.4

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 (83) hide show
  1. package/dist/src/acl/VariableInjector.d.ts +0 -1
  2. package/dist/src/acl/VariableInjector.d.ts.map +1 -1
  3. package/dist/src/acl/VariableInjector.js +4 -14
  4. package/dist/src/acl/VariableInjector.js.map +1 -1
  5. package/dist/src/acl/VariableUtils.d.ts +2 -13
  6. package/dist/src/acl/VariableUtils.d.ts.map +1 -1
  7. package/dist/src/acl/VariableUtils.js +5 -16
  8. package/dist/src/acl/VariableUtils.js.map +1 -1
  9. package/dist/src/input-validation/EntityRulesResolver.js +3 -3
  10. package/dist/src/input-validation/EntityRulesResolver.js.map +1 -1
  11. package/dist/src/input-validation/ValidationContext.d.ts +2 -2
  12. package/dist/src/input-validation/ValidationContext.d.ts.map +1 -1
  13. package/dist/src/input-validation/ValidationContext.js.map +1 -1
  14. package/dist/src/introspection/content-schema.types.d.ts +19 -223
  15. package/dist/src/introspection/content-schema.types.d.ts.map +1 -1
  16. package/dist/src/introspection/content-schema.types.js +2 -2
  17. package/dist/src/introspection/content-schema.types.js.map +1 -1
  18. package/dist/src/resolvers/GraphQlQueryAstFactory.js +2 -2
  19. package/dist/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  20. package/dist/src/resolvers/MutationResolver.js +14 -14
  21. package/dist/src/resolvers/MutationResolver.js.map +1 -1
  22. package/dist/src/resolvers/ReadHelpers.js +7 -7
  23. package/dist/src/resolvers/ReadHelpers.js.map +1 -1
  24. package/dist/src/schema/MutationProvider.js +4 -4
  25. package/dist/src/schema/MutationProvider.js.map +1 -1
  26. package/dist/src/schema/QueryProvider.js +3 -3
  27. package/dist/src/schema/QueryProvider.js.map +1 -1
  28. package/dist/src/schema/ResultSchemaTypeProvider.d.ts +2 -2
  29. package/dist/src/schema/ResultSchemaTypeProvider.d.ts.map +1 -1
  30. package/dist/src/schema/entities/FieldArgsVisitor.d.ts +4 -4
  31. package/dist/src/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  32. package/dist/src/tsconfig.tsbuildinfo +1 -1
  33. package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts +2 -0
  34. package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts.map +1 -0
  35. package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js +38 -0
  36. package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js.map +1 -0
  37. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js +1 -1
  38. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js.map +1 -1
  39. package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js +2 -2
  40. package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js.map +1 -1
  41. package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js +1 -1
  42. package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js.map +1 -1
  43. package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js +4 -4
  44. package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js.map +1 -1
  45. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js +1 -1
  46. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js.map +1 -1
  47. package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js +4 -4
  48. package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js.map +1 -1
  49. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js +6 -3
  50. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js.map +1 -1
  51. package/dist/tests/cases/unit/aclVariablesFactory.test.js +7 -33
  52. package/dist/tests/cases/unit/aclVariablesFactory.test.js.map +1 -1
  53. package/dist/tests/cases/unit/orderbyHelper.test.js +1 -0
  54. package/dist/tests/cases/unit/orderbyHelper.test.js.map +1 -1
  55. package/dist/tests/cases/unit/predicatesInjector.test.js +7 -6
  56. package/dist/tests/cases/unit/predicatesInjector.test.js.map +1 -1
  57. package/dist/tests/cases/unit/variableInjector.test.js +4 -3
  58. package/dist/tests/cases/unit/variableInjector.test.js.map +1 -1
  59. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  60. package/dist/tests/src/testGraphql.js +10 -2
  61. package/dist/tests/src/testGraphql.js.map +1 -1
  62. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  63. package/graphql.codegen.yml +0 -3
  64. package/package.json +16 -16
  65. package/src/acl/VariableInjector.ts +2 -15
  66. package/src/acl/VariableUtils.ts +7 -23
  67. package/src/input-validation/EntityRulesResolver.ts +3 -3
  68. package/src/input-validation/ValidationContext.ts +2 -2
  69. package/src/introspection/content-schema.types.ts +19 -286
  70. package/src/resolvers/GraphQlQueryAstFactory.ts +3 -3
  71. package/tests/cases/integration/graphQlDb/insert/insertSequence.test.ts +34 -0
  72. package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +2 -2
  73. package/tests/cases/integration/graphQlRequests/insert/acl/setField.test.ts +3 -3
  74. package/tests/cases/integration/graphQlRequests/insert/aclInsert.test.ts +2 -2
  75. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +4 -4
  76. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +1 -1
  77. package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +5 -5
  78. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +5 -5
  79. package/tests/cases/unit/aclVariablesFactory.test.ts +8 -35
  80. package/tests/cases/unit/orderbyHelper.test.ts +1 -0
  81. package/tests/cases/unit/predicatesInjector.test.ts +7 -6
  82. package/tests/cases/unit/variableInjector.test.ts +6 -5
  83. package/tests/src/testGraphql.ts +9 -2
@@ -1,7 +1,7 @@
1
1
  import { test } from 'vitest'
2
2
  import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test'
3
3
  import { SchemaBuilder } from '@contember/schema-definition'
4
- import { Model } from '@contember/schema'
4
+ import { Acl, Model } from '@contember/schema'
5
5
  import { GQL, SQL } from '../../../../../src/tags'
6
6
  import { testUuid } from '../../../../../src/testUuid'
7
7
 
@@ -34,7 +34,7 @@ test('set a name - allowed', async () => {
34
34
  },
35
35
  },
36
36
  variables: {
37
- name_variable: ['John', 'Jack'],
37
+ name_variable: { in: ['John', 'Jack'] },
38
38
  },
39
39
  executes: [
40
40
  ...sqlTransaction([
@@ -89,7 +89,7 @@ test('set a name - denied', async () => {
89
89
  },
90
90
  },
91
91
  variables: {
92
- name_variable: ['John', 'Jack'],
92
+ name_variable: { in: ['John', 'Jack'] },
93
93
  },
94
94
  executes: [
95
95
  ...failedTransaction([
@@ -1,7 +1,7 @@
1
1
  import { test } from 'vitest'
2
2
  import { execute, sqlTransaction } from '../../../../src/test'
3
3
  import { SchemaBuilder } from '@contember/schema-definition'
4
- import { Model } from '@contember/schema'
4
+ import { Acl, Model } from '@contember/schema'
5
5
  import { GQL, SQL } from '../../../../src/tags'
6
6
  import { testUuid } from '../../../../src/testUuid'
7
7
 
@@ -27,7 +27,7 @@ test('insert author (with acl)', async () => {
27
27
  },
28
28
  },
29
29
  variables: {
30
- name_variable: ['John', 'Jack'],
30
+ name_variable: { in: ['John', 'Jack'] },
31
31
  },
32
32
  query: GQL`
33
33
  mutation {
@@ -45,7 +45,7 @@ test('querying id and title', async () => {
45
45
  schema: schema,
46
46
  permissions: permissions,
47
47
  variables: {
48
- localeVariable: ['cs'],
48
+ localeVariable: { in: ['cs'] },
49
49
  },
50
50
  query: GQL`
51
51
  query {
@@ -121,7 +121,7 @@ test('querying with extra where', async () => {
121
121
  schema: schema,
122
122
  permissions: permissions,
123
123
  variables: {
124
- localeVariable: ['cs'],
124
+ localeVariable: { in: ['cs'] },
125
125
  },
126
126
  query: GQL`
127
127
  query {
@@ -167,7 +167,7 @@ test('querying only id', async () => {
167
167
  schema: schema,
168
168
  permissions: permissions,
169
169
  variables: {
170
- localeVariable: ['cs'],
170
+ localeVariable: { in: ['cs'] },
171
171
  },
172
172
  query: GQL`
173
173
  query {
@@ -239,7 +239,7 @@ test('querying on nested field', async () => {
239
239
  schema: schema,
240
240
  permissions: permissions,
241
241
  variables: {
242
- localeVariable: ['cs'],
242
+ localeVariable: { in: ['cs'] },
243
243
  },
244
244
  query: GQL`
245
245
  query {
@@ -58,7 +58,7 @@ test('querying post + author name', async () => {
58
58
  schema: schema,
59
59
  permissions: permissions,
60
60
  variables: {
61
- countryVariable: ['Czechia'],
61
+ countryVariable: { in: ['Czechia'] },
62
62
  },
63
63
  query: GQL`
64
64
  query {
@@ -1,7 +1,7 @@
1
1
  import { test } from 'vitest'
2
2
  import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test'
3
3
  import { SchemaBuilder } from '@contember/schema-definition'
4
- import { Model } from '@contember/schema'
4
+ import { Model } from '@contember/schema'
5
5
  import { GQL, SQL } from '../../../../../src/tags'
6
6
  import { testUuid } from '../../../../../src/testUuid'
7
7
 
@@ -35,7 +35,7 @@ test('update name', async () => {
35
35
  },
36
36
  },
37
37
  variables: {
38
- name_variable: ['John', 'Jack'],
38
+ name_variable: { in: ['John', 'Jack'] },
39
39
  },
40
40
  executes: [
41
41
  ...sqlTransaction([
@@ -98,7 +98,7 @@ test('update name - denied', async () => {
98
98
  },
99
99
  },
100
100
  variables: {
101
- name_variable: ['John', 'Jack'],
101
+ name_variable: { in: ['John', 'Jack'] },
102
102
  },
103
103
  executes: [
104
104
  ...failedTransaction([
@@ -176,8 +176,8 @@ test('update m:n', async () => {
176
176
  },
177
177
  },
178
178
  variables: {
179
- post_name_variable: ['Lorem ipsum', 'Dolor sit'],
180
- category_name_variable: ['foo', 'bar'],
179
+ post_name_variable: { in: ['Lorem ipsum', 'Dolor sit'] },
180
+ category_name_variable: { in: ['foo', 'bar'] },
181
181
  },
182
182
  query: GQL`mutation {
183
183
  updatePost(by: {id: "${testUuid(1)}"}, data: {categories: [
@@ -30,20 +30,20 @@ const testSchema = async (test: Test) => {
30
30
  const graphQlSchemaBuilder = schemaFactory.create(schemaWithAcl, authorizator)
31
31
  const graphQlSchema = graphQlSchemaBuilder.build()
32
32
 
33
- const result = await graphql(
34
- graphQlSchema,
35
- `
33
+ const result = await graphql({
34
+ schema: graphQlSchema,
35
+ source: `
36
36
  {
37
37
  _info {
38
38
  description
39
39
  }
40
40
  }
41
41
  `,
42
- )
42
+ })
43
43
  const errors = (result.errors || []).map(it => it.message)
44
44
  assert.deepEqual(errors, [])
45
45
 
46
- const textSchema = printSchema(graphQlSchema)
46
+ const textSchema = printSchema(graphQlSchema) + '\n'
47
47
 
48
48
  const filename = path.join(__dirname, test.graphQlSchemaFile)
49
49
  let expectedSchema: string
@@ -5,24 +5,21 @@ import { testUuid } from '@contember/engine-api-tester'
5
5
 
6
6
  describe('create acl variables', () => {
7
7
 
8
+ const definition: Acl.EntityVariable = { type: Acl.VariableType.entity, entityName: 'Author' }
8
9
  it('prefix from memberships', () => {
9
10
  assert.deepStrictEqual(createAclVariables({
10
11
  roles: {
11
12
  author: {
12
13
  stages: '*',
13
14
  variables: {
14
- authorID: { type: Acl.VariableType.entity, entityName: 'Author' },
15
+ authorID: definition,
15
16
  },
16
17
  entities: {
17
18
  },
18
19
  },
19
20
  },
20
- }, {
21
- identityId: testUuid(1),
22
- personId: null,
23
- memberships: [{ role: 'author', variables: [{ name: 'authorID', values: [testUuid(2)] }] }],
24
- }), {
25
- author__authorID: [testUuid(2)],
21
+ }, [{ role: 'author', variables: [{ name: 'authorID', condition: { in: [testUuid(2)] } }] }]), {
22
+ author__authorID: { in: [testUuid(2)] },
26
23
  })
27
24
  })
28
25
 
@@ -33,38 +30,14 @@ describe('create acl variables', () => {
33
30
  author: {
34
31
  stages: '*',
35
32
  variables: {
36
- authorID: { type: Acl.VariableType.entity, entityName: 'Author' },
33
+ authorID: definition,
37
34
  },
38
35
  entities: {},
39
36
  },
40
37
  },
41
- }, {
42
- identityId: testUuid(1),
43
- personId: null,
44
- memberships: [{ role: 'author', variables: [] }],
45
- }), {
46
- author__authorID: [],
47
- })
48
- })
49
-
50
-
51
- it('predefined', () => {
52
- assert.deepStrictEqual(createAclVariables({
53
- roles: {
54
- author: {
55
- stages: '*',
56
- variables: {
57
- authorIdentity: { type: Acl.VariableType.predefined, value: 'identityID' },
58
- },
59
- entities: {},
60
- },
61
- },
62
- }, {
63
- identityId: testUuid(1),
64
- personId: null,
65
- memberships: [{ role: 'author', variables: [] }],
66
- }), {
67
- author__authorIdentity: [testUuid(1)],
38
+ }, [{ role: 'author', variables: [] }],
39
+ ), {
40
+ author__authorID: { never: true },
68
41
  })
69
42
  })
70
43
  })
@@ -11,6 +11,7 @@ const entity: Model.Entity = {
11
11
  fields: {},
12
12
  unique: {},
13
13
  eventLog: { enabled: true },
14
+ indexes: {},
14
15
  }
15
16
 
16
17
  describe('order by helper', () => {
@@ -44,10 +44,13 @@ const permissions: Acl.Permissions = {
44
44
 
45
45
  describe('Predicates injector', () => {
46
46
 
47
+ const variables: Acl.VariablesMap = {
48
+ localeVariable: { in: ['cs'] },
49
+ }
47
50
  it('injects predicate', () => {
48
51
  const injector = new PredicatesInjector(
49
52
  schema,
50
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
53
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
51
54
  )
52
55
  const result = injector.inject(schema.entities['PostLocale'], {})
53
56
 
@@ -59,7 +62,7 @@ describe('Predicates injector', () => {
59
62
  it('merges predicate with explicit where', () => {
60
63
  const injector = new PredicatesInjector(
61
64
  schema,
62
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
65
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
63
66
  )
64
67
  const result = injector.inject(schema.entities['PostLocale'], { id: { in: [1, 2] } })
65
68
 
@@ -71,9 +74,7 @@ describe('Predicates injector', () => {
71
74
  id: { in: [1, 2] },
72
75
  },
73
76
  {
74
- locale: {
75
- in: ['cs'],
76
- },
77
+ locale: { in: ['cs'] },
77
78
  },
78
79
  ],
79
80
  },
@@ -87,7 +88,7 @@ describe('Predicates injector', () => {
87
88
  it('injects predicate to where', () => {
88
89
  const injector = new PredicatesInjector(
89
90
  schema,
90
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
91
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
91
92
  )
92
93
 
93
94
  const result = injector.inject(schema.entities['PostLocale'], { title: { eq: 'abc' } })
@@ -1,7 +1,7 @@
1
1
  import { VariableInjector } from '../../../src/acl'
2
2
  import { SchemaBuilder } from '@contember/schema-definition'
3
- import { Model } from '@contember/schema'
4
- import { describe, it, assert } from 'vitest'
3
+ import { Acl, Model } from '@contember/schema'
4
+ import { assert, describe, it } from 'vitest'
5
5
 
6
6
  describe('Variable injector', () => {
7
7
 
@@ -17,9 +17,10 @@ describe('Variable injector', () => {
17
17
  )
18
18
  .buildSchema()
19
19
 
20
+ const ids = ['91528a5c-839b-4114-9952-d661914a607f', '1e2f3937-a0b1-4105-8aae-6da8ac9fc146']
20
21
  const injector = new VariableInjector(schema, {
21
- site: [1, 2],
22
- locale: 'cs',
22
+ site: { in: ids },
23
+ locale: { eq: 'cs' },
23
24
  })
24
25
  const result = injector.inject(schema.entities['PostLocale'], {
25
26
  or: [
@@ -53,7 +54,7 @@ describe('Variable injector', () => {
53
54
  and: [
54
55
  {
55
56
  post: {
56
- site: { id: { in: [1, 2] } },
57
+ site: { id: { in: ids } },
57
58
  },
58
59
  },
59
60
  {
@@ -10,10 +10,17 @@ export interface Test {
10
10
  }
11
11
 
12
12
  export const executeGraphQlTest = async (test: Test) => {
13
- const rawResponse = await graphql(test.schema, test.query, null, test.context, test.queryVariables)
13
+ const rawResponse = await graphql({
14
+ schema: test.schema,
15
+ source: test.query,
16
+ contextValue: test.context,
17
+ variableValues: test.queryVariables,
18
+ })
14
19
  const response = JSON.parse(JSON.stringify(rawResponse))
15
20
  if ('errors' in rawResponse) {
16
- console.error((rawResponse.errors as any)[0])
21
+ if (rawResponse.errors?.length === 1 && 'originalError' in (rawResponse.errors as any)[0]) {
22
+ throw (rawResponse.errors as any)[0].originalError
23
+ }
17
24
  rawResponse.errors = (rawResponse.errors as any).map(({ message }: any) => ({ message }))
18
25
  }
19
26
  assert.deepStrictEqual(response, test.return)