@contember/engine-content-api 1.1.0-rc.2 → 1.1.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.
- package/dist/src/input-validation/EntityRulesResolver.js +3 -3
- package/dist/src/input-validation/EntityRulesResolver.js.map +1 -1
- package/dist/src/input-validation/preValidation/InputPreValidator.js +1 -1
- package/dist/src/input-validation/preValidation/InputPreValidator.js.map +1 -1
- package/dist/src/mapper/select/ConditionBuilder.d.ts.map +1 -1
- package/dist/src/mapper/select/ConditionBuilder.js +5 -4
- package/dist/src/mapper/select/ConditionBuilder.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts +2 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.d.ts.map +1 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js +38 -0
- package/dist/tests/cases/integration/graphQlDb/insert/insertSequence.test.js.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/input-validation/EntityRulesResolver.ts +3 -3
- package/src/input-validation/preValidation/InputPreValidator.ts +2 -2
- package/src/mapper/select/ConditionBuilder.ts +7 -4
- package/tests/cases/integration/graphQlDb/insert/insertSequence.test.ts +34 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-content-api",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"typings": "dist/src/index.d.ts",
|
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
"test": "vitest --no-threads"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@contember/database": "^1.1.
|
|
14
|
-
"@contember/dic": "^1.1.
|
|
15
|
-
"@contember/engine-common": "^1.1.
|
|
16
|
-
"@contember/graphql-utils": "^1.1.
|
|
17
|
-
"@contember/schema": "^1.1.
|
|
18
|
-
"@contember/schema-utils": "^1.1.
|
|
13
|
+
"@contember/database": "^1.1.1",
|
|
14
|
+
"@contember/dic": "^1.1.1",
|
|
15
|
+
"@contember/engine-common": "^1.1.1",
|
|
16
|
+
"@contember/graphql-utils": "^1.1.1",
|
|
17
|
+
"@contember/schema": "^1.1.1",
|
|
18
|
+
"@contember/schema-utils": "^1.1.1",
|
|
19
19
|
"@graphql-tools/schema": "^8.3.5",
|
|
20
20
|
"graphql-tag": "^2.12.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@contember/database-tester": "^1.1.
|
|
24
|
-
"@contember/engine-api-tester": "^1.1.
|
|
25
|
-
"@contember/schema-definition": "^1.1.
|
|
23
|
+
"@contember/database-tester": "^1.1.1",
|
|
24
|
+
"@contember/engine-api-tester": "^1.1.1",
|
|
25
|
+
"@contember/schema-definition": "^1.1.1",
|
|
26
26
|
"@graphql-codegen/cli": "^1.15.2",
|
|
27
27
|
"@graphql-codegen/typescript": "^1.15.2",
|
|
28
28
|
"@graphql-codegen/typescript-operations": "^1.15.2",
|
|
@@ -35,7 +35,7 @@ export class EntityRulesResolver {
|
|
|
35
35
|
|
|
36
36
|
public getEntityRules(entityName: string): Validation.EntityRules {
|
|
37
37
|
const definedRules = this.validationSchema[entityName] || {}
|
|
38
|
-
const fieldsNotNullFlag = acceptEveryFieldVisitor(this.model, entityName, new
|
|
38
|
+
const fieldsNotNullFlag = acceptEveryFieldVisitor(this.model, entityName, new RequiredFieldsVisitor())
|
|
39
39
|
const notNullFields = Object.keys(filterObject(fieldsNotNullFlag, (field, val) => val))
|
|
40
40
|
return notNullFields.reduce(
|
|
41
41
|
(entityRules, field) => ({
|
|
@@ -50,9 +50,9 @@ export class EntityRulesResolver {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
class
|
|
53
|
+
class RequiredFieldsVisitor implements Model.RelationByTypeVisitor<boolean>, Model.ColumnVisitor<boolean> {
|
|
54
54
|
visitColumn(entity: Model.Entity, column: Model.AnyColumn): boolean {
|
|
55
|
-
return !column.nullable
|
|
55
|
+
return !column.nullable && typeof column.default === 'undefined' && !column.sequence
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
visitManyHasManyInverse(): boolean {
|
|
@@ -105,8 +105,8 @@ export class InputPreValidator {
|
|
|
105
105
|
return data[column.name] as Input.ColumnValue | undefined
|
|
106
106
|
},
|
|
107
107
|
visitHasOne: (entity, relation) => {
|
|
108
|
-
const value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined
|
|
109
|
-
if (value === undefined) {
|
|
108
|
+
const value = data[relation.name] as Input.CreateOneRelationInput | Input.UpdateOneRelationInput | undefined | null
|
|
109
|
+
if (value === undefined || value === null) {
|
|
110
110
|
return undefined
|
|
111
111
|
}
|
|
112
112
|
if ('disconnect' in value) {
|
|
@@ -10,11 +10,14 @@ export class ConditionBuilder {
|
|
|
10
10
|
columnType: string,
|
|
11
11
|
condition: Input.Condition<any>,
|
|
12
12
|
): SqlConditionBuilder {
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const entries = Object.entries(condition)
|
|
14
|
+
.filter(<T extends keyof Input.Condition>(it: [string, any]): it is [T, Input.Condition[T]] =>
|
|
15
|
+
it[1] !== null,
|
|
16
|
+
)
|
|
17
|
+
if (entries.length === 0) {
|
|
15
18
|
return builder
|
|
16
19
|
}
|
|
17
|
-
if (
|
|
20
|
+
if (entries.length > 1) {
|
|
18
21
|
throw new UserError(
|
|
19
22
|
'Only single field is allowed. If you want to combine multiple conditions, use "and" or "or". Got: ' +
|
|
20
23
|
JSON.stringify(condition),
|
|
@@ -53,6 +56,6 @@ export class ConditionBuilder {
|
|
|
53
56
|
null: (builder, value) => value ? builder.isNull(columnIdentifier) : builder.not(clause => clause.isNull(columnIdentifier)),
|
|
54
57
|
}
|
|
55
58
|
|
|
56
|
-
return handler[
|
|
59
|
+
return handler[entries[0][0]](builder, entries[0][1])
|
|
57
60
|
}
|
|
58
61
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SchemaDefinition as def } from '@contember/schema-definition'
|
|
2
|
+
import { GQL } from '../../../../src/tags'
|
|
3
|
+
import { test } from 'vitest'
|
|
4
|
+
import { executeDbTest } from '@contember/engine-api-tester'
|
|
5
|
+
|
|
6
|
+
namespace SeqModel {
|
|
7
|
+
export class Order {
|
|
8
|
+
seqId = def.intColumn().sequence().notNull()
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
test('insert author with id', async () => {
|
|
13
|
+
const schema = def.createModel(SeqModel)
|
|
14
|
+
await executeDbTest({
|
|
15
|
+
schema: schema,
|
|
16
|
+
query: GQL`
|
|
17
|
+
mutation {
|
|
18
|
+
createOrder(data: {}) {
|
|
19
|
+
node {
|
|
20
|
+
seqId
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}`,
|
|
24
|
+
seed: [],
|
|
25
|
+
return: {
|
|
26
|
+
createOrder: {
|
|
27
|
+
node: {
|
|
28
|
+
seqId: 1,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|