@contember/engine-content-api 1.1.0-rc.3 → 1.2.0-alpha.3

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 (67) hide show
  1. package/dist/src/acl/VariableInjector.d.ts.map +1 -1
  2. package/dist/src/acl/VariableInjector.js +9 -7
  3. package/dist/src/acl/VariableInjector.js.map +1 -1
  4. package/dist/src/acl/VariableUtils.d.ts.map +1 -1
  5. package/dist/src/acl/VariableUtils.js +18 -12
  6. package/dist/src/acl/VariableUtils.js.map +1 -1
  7. package/dist/src/introspection/content-schema.types.d.ts +19 -223
  8. package/dist/src/introspection/content-schema.types.d.ts.map +1 -1
  9. package/dist/src/introspection/content-schema.types.js +2 -2
  10. package/dist/src/introspection/content-schema.types.js.map +1 -1
  11. package/dist/src/resolvers/GraphQlQueryAstFactory.js +2 -2
  12. package/dist/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  13. package/dist/src/resolvers/MutationResolver.js +14 -14
  14. package/dist/src/resolvers/MutationResolver.js.map +1 -1
  15. package/dist/src/resolvers/ReadHelpers.js +7 -7
  16. package/dist/src/resolvers/ReadHelpers.js.map +1 -1
  17. package/dist/src/schema/MutationProvider.js +4 -4
  18. package/dist/src/schema/MutationProvider.js.map +1 -1
  19. package/dist/src/schema/QueryProvider.js +3 -3
  20. package/dist/src/schema/QueryProvider.js.map +1 -1
  21. package/dist/src/schema/ResultSchemaTypeProvider.d.ts +2 -2
  22. package/dist/src/schema/ResultSchemaTypeProvider.d.ts.map +1 -1
  23. package/dist/src/schema/entities/FieldArgsVisitor.d.ts +4 -4
  24. package/dist/src/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  25. package/dist/src/tsconfig.tsbuildinfo +1 -1
  26. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js +6 -1
  27. package/dist/tests/cases/integration/graphQlRequests/delete/aclDelete.test.js.map +1 -1
  28. package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js +12 -2
  29. package/dist/tests/cases/integration/graphQlRequests/insert/acl/setField.test.js.map +1 -1
  30. package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js +6 -1
  31. package/dist/tests/cases/integration/graphQlRequests/insert/aclInsert.test.js.map +1 -1
  32. package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js +24 -4
  33. package/dist/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.js.map +1 -1
  34. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js +6 -1
  35. package/dist/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.js.map +1 -1
  36. package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js +24 -4
  37. package/dist/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.js.map +1 -1
  38. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js +6 -3
  39. package/dist/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.js.map +1 -1
  40. package/dist/tests/cases/unit/aclVariablesFactory.test.js +8 -6
  41. package/dist/tests/cases/unit/aclVariablesFactory.test.js.map +1 -1
  42. package/dist/tests/cases/unit/predicatesInjector.test.js +12 -6
  43. package/dist/tests/cases/unit/predicatesInjector.test.js.map +1 -1
  44. package/dist/tests/cases/unit/variableInjector.test.js +15 -3
  45. package/dist/tests/cases/unit/variableInjector.test.js.map +1 -1
  46. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  47. package/dist/tests/src/testGraphql.js +10 -2
  48. package/dist/tests/src/testGraphql.js.map +1 -1
  49. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  50. package/graphql.codegen.yml +0 -3
  51. package/package.json +16 -16
  52. package/src/acl/VariableInjector.ts +10 -8
  53. package/src/acl/VariableUtils.ts +18 -13
  54. package/src/introspection/content-schema.types.ts +19 -286
  55. package/src/resolvers/GraphQlQueryAstFactory.ts +3 -3
  56. package/tests/cases/integration/graphQlRequests/delete/aclDelete.test.ts +7 -2
  57. package/tests/cases/integration/graphQlRequests/insert/acl/setField.test.ts +13 -3
  58. package/tests/cases/integration/graphQlRequests/insert/aclInsert.test.ts +7 -2
  59. package/tests/cases/integration/graphQlRequests/query/acl/fieldRestrictedByLocale.test.ts +24 -4
  60. package/tests/cases/integration/graphQlRequests/query/acl/nestedPredicate.test.ts +6 -1
  61. package/tests/cases/integration/graphQlRequests/update/acl/aclUpdate.test.ts +25 -5
  62. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +5 -5
  63. package/tests/cases/unit/aclVariablesFactory.test.ts +8 -6
  64. package/tests/cases/unit/predicatesInjector.test.ts +12 -6
  65. package/tests/cases/unit/variableInjector.test.ts +17 -5
  66. package/tests/src/testGraphql.ts +9 -2
  67. package/jasmine.json +0 -7
@@ -45,7 +45,12 @@ test('querying id and title', async () => {
45
45
  schema: schema,
46
46
  permissions: permissions,
47
47
  variables: {
48
- localeVariable: ['cs'],
48
+ localeVariable: {
49
+ definition: {
50
+ type: Acl.VariableType.condition,
51
+ },
52
+ value: [{ in: ['cs'] }],
53
+ },
49
54
  },
50
55
  query: GQL`
51
56
  query {
@@ -121,7 +126,12 @@ test('querying with extra where', async () => {
121
126
  schema: schema,
122
127
  permissions: permissions,
123
128
  variables: {
124
- localeVariable: ['cs'],
129
+ localeVariable: {
130
+ definition: {
131
+ type: Acl.VariableType.condition,
132
+ },
133
+ value: [{ in: ['cs'] }],
134
+ },
125
135
  },
126
136
  query: GQL`
127
137
  query {
@@ -167,7 +177,12 @@ test('querying only id', async () => {
167
177
  schema: schema,
168
178
  permissions: permissions,
169
179
  variables: {
170
- localeVariable: ['cs'],
180
+ localeVariable: {
181
+ definition: {
182
+ type: Acl.VariableType.condition,
183
+ },
184
+ value: [{ in: ['cs'] }],
185
+ },
171
186
  },
172
187
  query: GQL`
173
188
  query {
@@ -239,7 +254,12 @@ test('querying on nested field', async () => {
239
254
  schema: schema,
240
255
  permissions: permissions,
241
256
  variables: {
242
- localeVariable: ['cs'],
257
+ localeVariable: {
258
+ definition: {
259
+ type: Acl.VariableType.condition,
260
+ },
261
+ value: [{ in: ['cs'] }],
262
+ },
243
263
  },
244
264
  query: GQL`
245
265
  query {
@@ -58,7 +58,12 @@ test('querying post + author name', async () => {
58
58
  schema: schema,
59
59
  permissions: permissions,
60
60
  variables: {
61
- countryVariable: ['Czechia'],
61
+ countryVariable: {
62
+ definition: {
63
+ type: Acl.VariableType.condition,
64
+ },
65
+ value: [{ in: ['Czechia'] }],
66
+ },
62
67
  },
63
68
  query: GQL`
64
69
  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 { Acl, Model } from '@contember/schema'
5
5
  import { GQL, SQL } from '../../../../../src/tags'
6
6
  import { testUuid } from '../../../../../src/testUuid'
7
7
 
@@ -35,7 +35,12 @@ test('update name', async () => {
35
35
  },
36
36
  },
37
37
  variables: {
38
- name_variable: ['John', 'Jack'],
38
+ name_variable: {
39
+ definition: {
40
+ type: Acl.VariableType.condition,
41
+ },
42
+ value: [{ in: ['John', 'Jack'] }],
43
+ },
39
44
  },
40
45
  executes: [
41
46
  ...sqlTransaction([
@@ -98,7 +103,12 @@ test('update name - denied', async () => {
98
103
  },
99
104
  },
100
105
  variables: {
101
- name_variable: ['John', 'Jack'],
106
+ name_variable: {
107
+ definition: {
108
+ type: Acl.VariableType.condition,
109
+ },
110
+ value: [{ in: ['John', 'Jack'] }],
111
+ },
102
112
  },
103
113
  executes: [
104
114
  ...failedTransaction([
@@ -176,8 +186,18 @@ test('update m:n', async () => {
176
186
  },
177
187
  },
178
188
  variables: {
179
- post_name_variable: ['Lorem ipsum', 'Dolor sit'],
180
- category_name_variable: ['foo', 'bar'],
189
+ post_name_variable: {
190
+ definition: {
191
+ type: Acl.VariableType.condition,
192
+ },
193
+ value: [{ in: ['Lorem ipsum', 'Dolor sit'] }],
194
+ },
195
+ category_name_variable: {
196
+ definition: {
197
+ type: Acl.VariableType.condition,
198
+ },
199
+ value: [{ in: ['foo', 'bar'] }],
200
+ },
181
201
  },
182
202
  query: GQL`mutation {
183
203
  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,13 +5,14 @@ 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
  },
@@ -22,7 +23,7 @@ describe('create acl variables', () => {
22
23
  personId: null,
23
24
  memberships: [{ role: 'author', variables: [{ name: 'authorID', values: [testUuid(2)] }] }],
24
25
  }), {
25
- author__authorID: [testUuid(2)],
26
+ author__authorID: { definition, value: [testUuid(2)] },
26
27
  })
27
28
  })
28
29
 
@@ -33,7 +34,7 @@ describe('create acl variables', () => {
33
34
  author: {
34
35
  stages: '*',
35
36
  variables: {
36
- authorID: { type: Acl.VariableType.entity, entityName: 'Author' },
37
+ authorID: definition,
37
38
  },
38
39
  entities: {},
39
40
  },
@@ -43,18 +44,19 @@ describe('create acl variables', () => {
43
44
  personId: null,
44
45
  memberships: [{ role: 'author', variables: [] }],
45
46
  }), {
46
- author__authorID: [],
47
+ author__authorID: { definition, value: [] },
47
48
  })
48
49
  })
49
50
 
50
51
 
51
52
  it('predefined', () => {
53
+ const definition: Acl.PredefinedVariable = { type: Acl.VariableType.predefined, value: 'identityID' }
52
54
  assert.deepStrictEqual(createAclVariables({
53
55
  roles: {
54
56
  author: {
55
57
  stages: '*',
56
58
  variables: {
57
- authorIdentity: { type: Acl.VariableType.predefined, value: 'identityID' },
59
+ authorIdentity: definition,
58
60
  },
59
61
  entities: {},
60
62
  },
@@ -64,7 +66,7 @@ describe('create acl variables', () => {
64
66
  personId: null,
65
67
  memberships: [{ role: 'author', variables: [] }],
66
68
  }), {
67
- author__authorIdentity: [testUuid(1)],
69
+ author__authorIdentity: { definition, value: [testUuid(1)] },
68
70
  })
69
71
  })
70
72
  })
@@ -44,10 +44,18 @@ const permissions: Acl.Permissions = {
44
44
 
45
45
  describe('Predicates injector', () => {
46
46
 
47
+ const variables: Acl.VariablesMap = {
48
+ localeVariable: {
49
+ definition: {
50
+ type: Acl.VariableType.condition,
51
+ },
52
+ value: [{ in: ['cs'] }],
53
+ },
54
+ }
47
55
  it('injects predicate', () => {
48
56
  const injector = new PredicatesInjector(
49
57
  schema,
50
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
58
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
51
59
  )
52
60
  const result = injector.inject(schema.entities['PostLocale'], {})
53
61
 
@@ -59,7 +67,7 @@ describe('Predicates injector', () => {
59
67
  it('merges predicate with explicit where', () => {
60
68
  const injector = new PredicatesInjector(
61
69
  schema,
62
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
70
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
63
71
  )
64
72
  const result = injector.inject(schema.entities['PostLocale'], { id: { in: [1, 2] } })
65
73
 
@@ -71,9 +79,7 @@ describe('Predicates injector', () => {
71
79
  id: { in: [1, 2] },
72
80
  },
73
81
  {
74
- locale: {
75
- in: ['cs'],
76
- },
82
+ locale: { in: ['cs'] },
77
83
  },
78
84
  ],
79
85
  },
@@ -87,7 +93,7 @@ describe('Predicates injector', () => {
87
93
  it('injects predicate to where', () => {
88
94
  const injector = new PredicatesInjector(
89
95
  schema,
90
- new PredicateFactory(permissions, new VariableInjector(schema, { localeVariable: ['cs'] })),
96
+ new PredicateFactory(permissions, new VariableInjector(schema, variables)),
91
97
  )
92
98
 
93
99
  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,21 @@ 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: {
23
+ definition: {
24
+ type: Acl.VariableType.entity,
25
+ entityName: 'Site',
26
+ },
27
+ value: ids,
28
+ },
29
+ locale: {
30
+ definition: {
31
+ type: Acl.VariableType.condition,
32
+ },
33
+ value: [{ eq: 'cs' }],
34
+ },
23
35
  })
24
36
  const result = injector.inject(schema.entities['PostLocale'], {
25
37
  or: [
@@ -53,7 +65,7 @@ describe('Variable injector', () => {
53
65
  and: [
54
66
  {
55
67
  post: {
56
- site: { id: { in: [1, 2] } },
68
+ site: { id: { in: ids } },
57
69
  },
58
70
  },
59
71
  {
@@ -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)
package/jasmine.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "spec_files": [
3
- "dist/tests/cases/**/*.js"
4
- ],
5
- "stopSpecOnExpectationFailure": false,
6
- "random": false
7
- }