@contember/schema-utils 1.1.0-alpha.4 → 1.1.0-alpha.7
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/acl/AllowAllPermissionFactory.d.ts.map +1 -1
- package/dist/src/acl/AllowAllPermissionFactory.js.map +1 -1
- package/dist/src/acl/index.js +5 -1
- package/dist/src/acl/index.js.map +1 -1
- package/dist/src/dataUtils.d.ts +2 -2
- package/dist/src/dataUtils.d.ts.map +1 -1
- package/dist/src/dataUtils.js +1 -1
- package/dist/src/dataUtils.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +25 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/model/NamingHelper.d.ts +1 -1
- package/dist/src/model/NamingHelper.d.ts.map +1 -1
- package/dist/src/model/NamingHelper.js.map +1 -1
- package/dist/src/model/index.js +5 -1
- package/dist/src/model/index.js.map +1 -1
- package/dist/src/tsconfig.tsbuildinfo +1 -1
- package/dist/src/type-schema/acl.d.ts +8 -0
- package/dist/src/type-schema/acl.d.ts.map +1 -0
- package/dist/src/type-schema/acl.js +88 -0
- package/dist/src/type-schema/acl.js.map +1 -0
- package/dist/src/type-schema/index.d.ts +4 -0
- package/dist/src/type-schema/index.d.ts.map +1 -0
- package/dist/src/type-schema/index.js +20 -0
- package/dist/src/type-schema/index.js.map +1 -0
- package/dist/src/type-schema/model.d.ts +30 -0
- package/dist/src/type-schema/model.d.ts.map +1 -0
- package/dist/src/type-schema/model.js +148 -0
- package/dist/src/type-schema/model.js.map +1 -0
- package/dist/src/type-schema/validation.d.ts +15 -0
- package/dist/src/type-schema/validation.d.ts.map +1 -0
- package/dist/src/type-schema/validation.js +95 -0
- package/dist/src/type-schema/validation.js.map +1 -0
- package/dist/src/utils/index.js +5 -1
- package/dist/src/utils/index.js.map +1 -1
- package/dist/src/validation/AclValidator.d.ts +1 -2
- package/dist/src/validation/AclValidator.d.ts.map +1 -1
- package/dist/src/validation/AclValidator.js +22 -197
- package/dist/src/validation/AclValidator.js.map +1 -1
- package/dist/src/validation/ModelValidator.d.ts +1 -1
- package/dist/src/validation/ModelValidator.d.ts.map +1 -1
- package/dist/src/validation/ModelValidator.js +48 -219
- package/dist/src/validation/ModelValidator.js.map +1 -1
- package/dist/src/validation/SchemaValidator.d.ts.map +1 -1
- package/dist/src/validation/SchemaValidator.js +5 -19
- package/dist/src/validation/SchemaValidator.js.map +1 -1
- package/dist/src/validation/ValidationValidator.d.ts +1 -3
- package/dist/src/validation/ValidationValidator.d.ts.map +1 -1
- package/dist/src/validation/ValidationValidator.js +28 -201
- package/dist/src/validation/ValidationValidator.js.map +1 -1
- package/dist/src/validation/index.d.ts +2 -0
- package/dist/src/validation/index.d.ts.map +1 -1
- package/dist/src/validation/index.js +7 -1
- package/dist/src/validation/index.js.map +1 -1
- package/package.json +3 -2
- package/src/acl/AllowAllPermissionFactory.ts +2 -2
- package/src/dataUtils.ts +3 -3
- package/src/index.ts +8 -0
- package/src/model/NamingHelper.ts +1 -1
- package/src/tsconfig.json +3 -0
- package/src/type-schema/acl.ts +100 -0
- package/src/type-schema/index.ts +3 -0
- package/src/type-schema/model.ts +173 -0
- package/src/type-schema/validation.ts +100 -0
- package/src/validation/AclValidator.ts +42 -239
- package/src/validation/ModelValidator.ts +63 -263
- package/src/validation/SchemaValidator.ts +6 -21
- package/src/validation/ValidationValidator.ts +41 -222
- package/src/validation/index.ts +2 -0
- package/dist/src/validation/utils.d.ts +0 -18
- package/dist/src/validation/utils.d.ts.map +0 -1
- package/dist/src/validation/utils.js +0 -36
- package/dist/src/validation/utils.js.map +0 -1
- package/src/validation/utils.ts +0 -45
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.modelSchema = void 0;
|
|
27
|
+
const Typesafe = __importStar(require("@contember/typesafe"));
|
|
28
|
+
const schema_1 = require("@contember/schema");
|
|
29
|
+
const orderBySchema = Typesafe.array(Typesafe.object({
|
|
30
|
+
path: Typesafe.array(Typesafe.string),
|
|
31
|
+
direction: Typesafe.enumeration(schema_1.Model.OrderDirection.asc, schema_1.Model.OrderDirection.desc),
|
|
32
|
+
}));
|
|
33
|
+
const joiningColumnSchema = Typesafe.object({
|
|
34
|
+
columnName: Typesafe.string,
|
|
35
|
+
onDelete: Typesafe.enumeration(schema_1.Model.OnDelete.cascade, schema_1.Model.OnDelete.restrict, schema_1.Model.OnDelete.setNull),
|
|
36
|
+
});
|
|
37
|
+
const oneHasManyRelationSchema = Typesafe.intersection(Typesafe.object({
|
|
38
|
+
type: Typesafe.literal(schema_1.Model.RelationType.OneHasMany),
|
|
39
|
+
name: Typesafe.string,
|
|
40
|
+
target: Typesafe.string,
|
|
41
|
+
ownedBy: Typesafe.string,
|
|
42
|
+
}), Typesafe.partial({
|
|
43
|
+
orderBy: orderBySchema,
|
|
44
|
+
}));
|
|
45
|
+
const oneHasManyRelationSchemaCheck = true;
|
|
46
|
+
const manyHasOneRelationSchema = Typesafe.intersection(Typesafe.object({
|
|
47
|
+
type: Typesafe.literal(schema_1.Model.RelationType.ManyHasOne),
|
|
48
|
+
name: Typesafe.string,
|
|
49
|
+
target: Typesafe.string,
|
|
50
|
+
joiningColumn: joiningColumnSchema,
|
|
51
|
+
nullable: Typesafe.boolean,
|
|
52
|
+
}), Typesafe.partial({
|
|
53
|
+
inversedBy: Typesafe.string,
|
|
54
|
+
}));
|
|
55
|
+
const manyHasOneRelationSchemaCheck = true;
|
|
56
|
+
const oneHasOneInverseRelationSchema = Typesafe.object({
|
|
57
|
+
type: Typesafe.literal(schema_1.Model.RelationType.OneHasOne),
|
|
58
|
+
name: Typesafe.string,
|
|
59
|
+
target: Typesafe.string,
|
|
60
|
+
ownedBy: Typesafe.string,
|
|
61
|
+
nullable: Typesafe.boolean,
|
|
62
|
+
});
|
|
63
|
+
const oneHasOneInverseRelationSchemaCheck = true;
|
|
64
|
+
const oneHasOneOwningRelationSchema = Typesafe.intersection(Typesafe.object({
|
|
65
|
+
type: Typesafe.literal(schema_1.Model.RelationType.OneHasOne),
|
|
66
|
+
name: Typesafe.string,
|
|
67
|
+
target: Typesafe.string,
|
|
68
|
+
joiningColumn: joiningColumnSchema,
|
|
69
|
+
nullable: Typesafe.boolean,
|
|
70
|
+
}), Typesafe.partial({
|
|
71
|
+
inversedBy: Typesafe.string,
|
|
72
|
+
orphanRemoval: Typesafe.literal(true),
|
|
73
|
+
}));
|
|
74
|
+
const oneHasOneOwningRelationSchemaCheck = true;
|
|
75
|
+
const manyHasManyOwningRelationSchema = Typesafe.intersection(Typesafe.object({
|
|
76
|
+
type: Typesafe.literal(schema_1.Model.RelationType.ManyHasMany),
|
|
77
|
+
name: Typesafe.string,
|
|
78
|
+
target: Typesafe.string,
|
|
79
|
+
joiningTable: Typesafe.object({
|
|
80
|
+
tableName: Typesafe.string,
|
|
81
|
+
joiningColumn: joiningColumnSchema,
|
|
82
|
+
inverseJoiningColumn: joiningColumnSchema,
|
|
83
|
+
eventLog: Typesafe.object({
|
|
84
|
+
enabled: Typesafe.boolean,
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
}), Typesafe.partial({
|
|
88
|
+
inversedBy: Typesafe.string,
|
|
89
|
+
orderBy: orderBySchema,
|
|
90
|
+
}));
|
|
91
|
+
const manyHasManyOwningRelationSchemaCheck = true;
|
|
92
|
+
const manyHasManyInverseRelationSchema = Typesafe.intersection(Typesafe.object({
|
|
93
|
+
type: Typesafe.literal(schema_1.Model.RelationType.ManyHasMany),
|
|
94
|
+
name: Typesafe.string,
|
|
95
|
+
target: Typesafe.string,
|
|
96
|
+
ownedBy: Typesafe.string,
|
|
97
|
+
}), Typesafe.partial({
|
|
98
|
+
orderBy: orderBySchema,
|
|
99
|
+
}));
|
|
100
|
+
const manyHasManyInverseRelationSchemaCheck = true;
|
|
101
|
+
const intersectionSchema = Typesafe.intersection(Typesafe.object({
|
|
102
|
+
precedence: Typesafe.enumeration('ALWAYS', 'BY DEFAULT'),
|
|
103
|
+
}), Typesafe.partial({
|
|
104
|
+
start: Typesafe.number,
|
|
105
|
+
}));
|
|
106
|
+
const intersectionSchemaCheck = true;
|
|
107
|
+
const columnSchema = Typesafe.intersection(Typesafe.object({
|
|
108
|
+
name: Typesafe.string,
|
|
109
|
+
columnName: Typesafe.string,
|
|
110
|
+
columnType: Typesafe.string,
|
|
111
|
+
nullable: Typesafe.boolean,
|
|
112
|
+
type: Typesafe.enumeration(...Object.values(schema_1.Model.ColumnType)),
|
|
113
|
+
}), Typesafe.partial({
|
|
114
|
+
typeAlias: Typesafe.string,
|
|
115
|
+
default: Typesafe.union(Typesafe.string, Typesafe.number, Typesafe.boolean, Typesafe.null_),
|
|
116
|
+
sequence: intersectionSchema,
|
|
117
|
+
}));
|
|
118
|
+
const columnSchemaCheck = true;
|
|
119
|
+
const fieldSchema = Typesafe.union(oneHasOneInverseRelationSchema, oneHasOneOwningRelationSchema, oneHasManyRelationSchema, manyHasOneRelationSchema, manyHasManyInverseRelationSchema, manyHasManyOwningRelationSchema, columnSchema);
|
|
120
|
+
const viewSchemaInner = Typesafe.intersection(Typesafe.object({
|
|
121
|
+
sql: Typesafe.string,
|
|
122
|
+
}), Typesafe.partial({
|
|
123
|
+
dependencies: Typesafe.array(Typesafe.string),
|
|
124
|
+
}));
|
|
125
|
+
const viewSchemaCheck = true;
|
|
126
|
+
const viewSchema = viewSchemaInner;
|
|
127
|
+
const entitySchema = Typesafe.intersection(Typesafe.object({
|
|
128
|
+
name: Typesafe.string,
|
|
129
|
+
primary: Typesafe.string,
|
|
130
|
+
primaryColumn: Typesafe.string,
|
|
131
|
+
tableName: Typesafe.string,
|
|
132
|
+
fields: Typesafe.record(Typesafe.string, fieldSchema),
|
|
133
|
+
unique: Typesafe.record(Typesafe.string, Typesafe.object({
|
|
134
|
+
fields: Typesafe.array(Typesafe.string),
|
|
135
|
+
name: Typesafe.string,
|
|
136
|
+
})),
|
|
137
|
+
eventLog: Typesafe.object({
|
|
138
|
+
enabled: Typesafe.boolean,
|
|
139
|
+
}),
|
|
140
|
+
}), Typesafe.partial({
|
|
141
|
+
view: viewSchema,
|
|
142
|
+
}));
|
|
143
|
+
const entitySchemaCheck = true;
|
|
144
|
+
exports.modelSchema = Typesafe.object({
|
|
145
|
+
entities: Typesafe.record(Typesafe.string, entitySchema),
|
|
146
|
+
enums: Typesafe.record(Typesafe.string, Typesafe.array(Typesafe.string)),
|
|
147
|
+
});
|
|
148
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["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Aa,EAAE,QAAQ,CAAC,MAAM;IAC9B,SAAS,EAAE,QAAQ,CAAC,MAAM;IAC1B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IACrD,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC;QACxD,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;QACvC,IAAI,EAAE,QAAQ,CAAC,MAAM;KACrB,CAAC,CAAC;IACH,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC;QACzB,OAAO,EAAE,QAAQ,CAAC,OAAO;KACzB,CAAC;CACF,CAAC,EACF,QAAQ,CAAC,OAAO,CAAC;IAChB,IAAI,EAAE,UAAU;CAChB,CAAC,CACF,CAAA;AAED,MAAM,iBAAiB,GAAmE,IAAI,CAAA;AAEjF,QAAA,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IACxD,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CACxE,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as Typesafe from '@contember/typesafe';
|
|
2
|
+
import { Validation } from '@contember/schema';
|
|
3
|
+
export declare const validationSchema: Typesafe.Type<{
|
|
4
|
+
readonly [x: string]: {
|
|
5
|
+
readonly [x: string]: readonly {
|
|
6
|
+
readonly validator: Validation.Validator;
|
|
7
|
+
readonly message: {
|
|
8
|
+
readonly text: string;
|
|
9
|
+
} & {
|
|
10
|
+
readonly parameters?: readonly (string | number)[] | undefined;
|
|
11
|
+
};
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/type-schema/validation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AA+F9C,eAAO,MAAM,gBAAgB;;;;;;;;;;;EAG5B,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.validationSchema = void 0;
|
|
27
|
+
const Typesafe = __importStar(require("@contember/typesafe"));
|
|
28
|
+
const schema_1 = require("@contember/schema");
|
|
29
|
+
const messageSchema = Typesafe.intersection(Typesafe.object({
|
|
30
|
+
text: Typesafe.string,
|
|
31
|
+
}), Typesafe.partial({
|
|
32
|
+
parameters: Typesafe.array(Typesafe.union(Typesafe.string, Typesafe.number)),
|
|
33
|
+
}));
|
|
34
|
+
const literalArgumentFactory = (inner) => Typesafe.object({
|
|
35
|
+
type: Typesafe.literal(schema_1.Validation.ArgumentType.literal),
|
|
36
|
+
value: inner,
|
|
37
|
+
});
|
|
38
|
+
const validatorArgumentSchema = Typesafe.object({
|
|
39
|
+
type: Typesafe.literal(schema_1.Validation.ArgumentType.validator),
|
|
40
|
+
validator: (v, p) => validatorSchema(v, p),
|
|
41
|
+
});
|
|
42
|
+
const pathArgumentSchema = Typesafe.object({
|
|
43
|
+
type: Typesafe.literal(schema_1.Validation.ArgumentType.path),
|
|
44
|
+
path: Typesafe.array(Typesafe.string),
|
|
45
|
+
});
|
|
46
|
+
const validatorSchema = Typesafe.union(Typesafe.object({
|
|
47
|
+
operation: Typesafe.literal('and'),
|
|
48
|
+
args: Typesafe.array(validatorArgumentSchema),
|
|
49
|
+
}), Typesafe.object({
|
|
50
|
+
operation: Typesafe.literal('or'),
|
|
51
|
+
args: Typesafe.array(validatorArgumentSchema),
|
|
52
|
+
}), Typesafe.object({
|
|
53
|
+
operation: Typesafe.literal('conditional'),
|
|
54
|
+
args: Typesafe.tuple(validatorArgumentSchema, validatorArgumentSchema),
|
|
55
|
+
}), Typesafe.object({
|
|
56
|
+
operation: Typesafe.literal('pattern'),
|
|
57
|
+
args: Typesafe.tuple(literalArgumentFactory(Typesafe.tuple(Typesafe.string, Typesafe.string))),
|
|
58
|
+
}), Typesafe.object({
|
|
59
|
+
operation: Typesafe.literal('lengthRange'),
|
|
60
|
+
args: Typesafe.tuple(literalArgumentFactory(Typesafe.union(Typesafe.null_, Typesafe.number)), literalArgumentFactory(Typesafe.union(Typesafe.null_, Typesafe.number))),
|
|
61
|
+
}), Typesafe.object({
|
|
62
|
+
operation: Typesafe.literal('range'),
|
|
63
|
+
args: Typesafe.tuple(literalArgumentFactory(Typesafe.union(Typesafe.null_, Typesafe.number)), literalArgumentFactory(Typesafe.union(Typesafe.null_, Typesafe.number))),
|
|
64
|
+
}), Typesafe.object({
|
|
65
|
+
operation: Typesafe.literal('equals'),
|
|
66
|
+
args: Typesafe.tuple(literalArgumentFactory(Typesafe.anyJson)),
|
|
67
|
+
}), Typesafe.object({
|
|
68
|
+
operation: Typesafe.literal('not'),
|
|
69
|
+
args: Typesafe.tuple(validatorArgumentSchema),
|
|
70
|
+
}), Typesafe.object({
|
|
71
|
+
operation: Typesafe.literal('empty'),
|
|
72
|
+
args: Typesafe.tuple(),
|
|
73
|
+
}), Typesafe.object({
|
|
74
|
+
operation: Typesafe.literal('defined'),
|
|
75
|
+
args: Typesafe.tuple(),
|
|
76
|
+
}), Typesafe.object({
|
|
77
|
+
operation: Typesafe.literal('inContext'),
|
|
78
|
+
args: Typesafe.tuple(pathArgumentSchema, validatorArgumentSchema),
|
|
79
|
+
}), Typesafe.object({
|
|
80
|
+
operation: Typesafe.literal('every'),
|
|
81
|
+
args: Typesafe.tuple(validatorArgumentSchema),
|
|
82
|
+
}), Typesafe.object({
|
|
83
|
+
operation: Typesafe.literal('any'),
|
|
84
|
+
args: Typesafe.tuple(validatorArgumentSchema),
|
|
85
|
+
}), Typesafe.object({
|
|
86
|
+
operation: Typesafe.literal('filter'),
|
|
87
|
+
args: Typesafe.tuple(validatorArgumentSchema, validatorArgumentSchema),
|
|
88
|
+
}));
|
|
89
|
+
const validatorSchemaCheck = true;
|
|
90
|
+
const validationRuleSchema = Typesafe.object({
|
|
91
|
+
validator: validatorSchema,
|
|
92
|
+
message: messageSchema,
|
|
93
|
+
});
|
|
94
|
+
exports.validationSchema = Typesafe.record(Typesafe.string, Typesafe.record(Typesafe.string, Typesafe.array(validationRuleSchema)));
|
|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AC,uBAAuB,CAAC;CAC7C,CAAC,EACF,QAAQ,CAAC,MAAM,CAAC;IACf,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC;IACrC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;CACtE,CAAC,CACF,CAAA;AACD,MAAM,oBAAoB,GAA8E,IAAI,CAAA;AAE5G,MAAM,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC;IAC5C,SAAS,EAAE,eAAsD;IACjE,OAAO,EAAE,aAAa;CACtB,CAAC,CAAA;AAEW,QAAA,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAC9C,QAAQ,CAAC,MAAM,EACf,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC,CACtE,CAAA"}
|
package/dist/src/utils/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B;AAC7B,yCAAsB;AACtB,gDAA6B"}
|
|
@@ -3,13 +3,12 @@ import { ValidationError } from './errors';
|
|
|
3
3
|
export declare class AclValidator {
|
|
4
4
|
private readonly model;
|
|
5
5
|
constructor(model: Model.Schema);
|
|
6
|
-
validate(schema:
|
|
6
|
+
validate(schema: Acl.Schema): ValidationError[];
|
|
7
7
|
private validateRoles;
|
|
8
8
|
private validateRolePermissions;
|
|
9
9
|
private validateInherits;
|
|
10
10
|
private validateVariables;
|
|
11
11
|
private validateVariable;
|
|
12
|
-
private validateStagesDefinition;
|
|
13
12
|
private validatePermissions;
|
|
14
13
|
private validateEntityPermissions;
|
|
15
14
|
private validatePredicates;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AclValidator.d.ts","sourceRoot":"","sources":["../../../src/validation/AclValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"AclValidator.d.ts","sourceRoot":"","sources":["../../../src/validation/AclValidator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAG9C,OAAO,EAAgB,eAAe,EAAE,MAAM,UAAU,CAAA;AAGxD,qBAAa,YAAY;IACZ,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,KAAK,CAAC,MAAM;IAEzC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,GAAG,eAAe,EAAE;IAMtD,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,yBAAyB;IAoBjC,OAAO,CAAC,kBAAkB;IAc1B,OAAO,CAAC,2BAA2B;IA2BnC,OAAO,CAAC,kBAAkB;IAiB1B,OAAO,CAAC,wBAAwB;IAiBhC,OAAO,CAAC,iBAAiB;CAYzB"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AclValidator = void 0;
|
|
4
|
-
const schema_1 = require("@contember/schema");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
4
|
const acl_1 = require("../acl");
|
|
7
5
|
const model_1 = require("../model");
|
|
8
6
|
const errors_1 = require("./errors");
|
|
@@ -12,164 +10,52 @@ class AclValidator {
|
|
|
12
10
|
}
|
|
13
11
|
validate(schema) {
|
|
14
12
|
const errorBuilder = new errors_1.ErrorBuilder([], ['acl']);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
errorBuilder.add('Must be an object');
|
|
18
|
-
validSchema = { roles: {} };
|
|
19
|
-
}
|
|
20
|
-
else if (!schema.roles) {
|
|
21
|
-
errorBuilder.for('roles').add('Property is missing');
|
|
22
|
-
validSchema = { roles: {} };
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
validSchema = { roles: this.validateRoles(schema.roles, errorBuilder) };
|
|
26
|
-
}
|
|
27
|
-
return [validSchema, errorBuilder.errors];
|
|
13
|
+
this.validateRoles(schema.roles, errorBuilder);
|
|
14
|
+
return errorBuilder.errors;
|
|
28
15
|
}
|
|
29
16
|
validateRoles(roles, errorBuilder) {
|
|
30
|
-
if (!(0, utils_1.isObject)(roles)) {
|
|
31
|
-
errorBuilder.add('Must be an object');
|
|
32
|
-
return {};
|
|
33
|
-
}
|
|
34
|
-
const validRoles = {};
|
|
35
17
|
for (const role in roles) {
|
|
36
18
|
if (!roles.hasOwnProperty(role)) {
|
|
37
19
|
continue;
|
|
38
20
|
}
|
|
39
|
-
|
|
40
|
-
// errorBuilder.add('Role "admin" is reserved.')
|
|
41
|
-
// continue
|
|
42
|
-
// }
|
|
43
|
-
const rolePermissions = this.validateRolePermissions(roles[role], Object.keys(roles), errorBuilder.for(role));
|
|
44
|
-
if (rolePermissions !== undefined) {
|
|
45
|
-
validRoles[role] = rolePermissions;
|
|
46
|
-
}
|
|
21
|
+
this.validateRolePermissions(roles[role], Object.keys(roles), errorBuilder.for(role));
|
|
47
22
|
}
|
|
48
|
-
return validRoles;
|
|
49
23
|
}
|
|
50
24
|
validateRolePermissions(permissions, roles, errorBuilder) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
const { inherits: inheritsIn, variables: variablesIn, stages: stagesIn, entities: entitiesIn, implicit: implicitIn, ...plugins } = permissions;
|
|
56
|
-
const inherits = this.validateInherits(inheritsIn, roles, errorBuilder.for('inherits'));
|
|
57
|
-
const variables = this.validateVariables(variablesIn, errorBuilder.for('variables'));
|
|
58
|
-
const stages = this.validateStagesDefinition(stagesIn, errorBuilder.for('stages'));
|
|
59
|
-
const entities = this.validatePermissions(entitiesIn, permissions.variables || {}, errorBuilder.for('entities'));
|
|
25
|
+
this.validateInherits(permissions.inherits, roles, errorBuilder.for('inherits'));
|
|
26
|
+
this.validateVariables(permissions.variables, errorBuilder.for('variables'));
|
|
27
|
+
this.validatePermissions(permissions.entities, permissions.variables || {}, errorBuilder.for('entities'));
|
|
60
28
|
// todo: plugins validation
|
|
61
|
-
const result = { variables, stages, entities };
|
|
62
|
-
if (inherits !== undefined) {
|
|
63
|
-
result.inherits = inherits;
|
|
64
|
-
}
|
|
65
|
-
if (implicitIn !== undefined) {
|
|
66
|
-
if (typeof implicitIn !== 'boolean') {
|
|
67
|
-
errorBuilder.for('implicit').add('Must be boolean');
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
result.implicit = implicitIn;
|
|
71
|
-
}
|
|
72
|
-
return { ...plugins, ...result };
|
|
73
29
|
}
|
|
74
30
|
validateInherits(inherits, roles, errorBuilder) {
|
|
75
31
|
if (inherits === undefined) {
|
|
76
32
|
return undefined;
|
|
77
33
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const validRoles = [];
|
|
84
|
-
for (const inheritsFrom of inherits) {
|
|
85
|
-
if (!roles.includes(inheritsFrom)) {
|
|
86
|
-
// todo: check recursion
|
|
87
|
-
errorBuilder.for(inheritsFrom).add('Referenced role not exists.');
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
validRoles.push(inheritsFrom);
|
|
91
|
-
}
|
|
34
|
+
for (const inheritsFrom of inherits) {
|
|
35
|
+
if (!roles.includes(inheritsFrom)) {
|
|
36
|
+
errorBuilder.for(inheritsFrom).add('Referenced role not exists.');
|
|
92
37
|
}
|
|
93
|
-
return validRoles;
|
|
94
38
|
}
|
|
95
39
|
}
|
|
96
40
|
validateVariables(variables, errorBuilder) {
|
|
97
|
-
let validVariables = {};
|
|
98
|
-
if (!(0, utils_1.isObject)(variables)) {
|
|
99
|
-
errorBuilder.add('Must be an object');
|
|
100
|
-
return {};
|
|
101
|
-
}
|
|
102
41
|
for (const varName in variables) {
|
|
103
42
|
if (!variables.hasOwnProperty(varName)) {
|
|
104
43
|
continue;
|
|
105
44
|
}
|
|
106
|
-
|
|
107
|
-
if (validVariable) {
|
|
108
|
-
validVariables[varName] = validVariable;
|
|
109
|
-
}
|
|
45
|
+
this.validateVariable(variables[varName], errorBuilder.for(varName));
|
|
110
46
|
}
|
|
111
|
-
return validVariables;
|
|
112
47
|
}
|
|
113
48
|
validateVariable(variable, errorBuilder) {
|
|
114
|
-
if (!(0, utils_1.isObject)(variable)) {
|
|
115
|
-
errorBuilder.add('Must be an object');
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (!(0, utils_1.hasStringProperty)(variable, 'type')) {
|
|
119
|
-
errorBuilder.add('Variable type is not defined');
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
49
|
switch (variable.type) {
|
|
123
|
-
case
|
|
124
|
-
if (!(0, utils_1.hasStringProperty)(variable, 'entityName')) {
|
|
125
|
-
errorBuilder.add('Entity name must be specified for this type of variable');
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
50
|
+
case 'entity':
|
|
128
51
|
if (!this.model.entities[variable.entityName]) {
|
|
129
52
|
errorBuilder.add(`Entity "${variable.entityName}" not found`);
|
|
130
53
|
return;
|
|
131
54
|
}
|
|
132
|
-
const extra = (0, utils_1.checkExtraProperties)(variable, ['entityName', 'type']);
|
|
133
|
-
if (extra.length) {
|
|
134
|
-
errorBuilder.add('Unsupported properties found: ' + extra.join(', '));
|
|
135
|
-
}
|
|
136
|
-
return { type: schema_1.Acl.VariableType.entity, entityName: variable.entityName };
|
|
137
|
-
case schema_1.Acl.VariableType.predefined:
|
|
138
|
-
if (!(0, utils_1.hasStringProperty)(variable, 'value')) {
|
|
139
|
-
errorBuilder.add('Variable value type must be specified for this type of variable');
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
if (variable.value !== 'identityID' && variable.value !== 'personID') {
|
|
143
|
-
errorBuilder.add('Unknown predefined variable');
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const extra2 = (0, utils_1.checkExtraProperties)(variable, ['type', 'value']);
|
|
147
|
-
if (extra2.length) {
|
|
148
|
-
errorBuilder.add('Unsupported properties found: ' + extra2.join(', '));
|
|
149
|
-
}
|
|
150
|
-
return { type: variable.type, value: variable.value };
|
|
151
|
-
default:
|
|
152
|
-
errorBuilder.add(`Variable type "${variable.type}" is not supported.`);
|
|
153
55
|
}
|
|
154
56
|
return;
|
|
155
57
|
}
|
|
156
|
-
validateStagesDefinition(stages, errorBuilder) {
|
|
157
|
-
if (stages === '*') {
|
|
158
|
-
return '*';
|
|
159
|
-
}
|
|
160
|
-
if (!Array.isArray(stages) || !(0, utils_1.everyIs)(stages, (it) => typeof it === 'string')) {
|
|
161
|
-
errorBuilder.add('Stages must be either "*" or array of stage names');
|
|
162
|
-
return [];
|
|
163
|
-
}
|
|
164
|
-
// todo validate stages ??
|
|
165
|
-
return stages;
|
|
166
|
-
}
|
|
167
58
|
validatePermissions(permissions, variables, errorBuilder) {
|
|
168
|
-
if (!(0, utils_1.isObject)(permissions)) {
|
|
169
|
-
errorBuilder.add('Must be an object');
|
|
170
|
-
return {};
|
|
171
|
-
}
|
|
172
|
-
const validPermissions = {};
|
|
173
59
|
for (const entityName in permissions) {
|
|
174
60
|
if (!permissions.hasOwnProperty(entityName)) {
|
|
175
61
|
continue;
|
|
@@ -179,108 +65,54 @@ class AclValidator {
|
|
|
179
65
|
continue;
|
|
180
66
|
}
|
|
181
67
|
const entity = (0, model_1.getEntity)(this.model, entityName);
|
|
182
|
-
|
|
183
|
-
if (entityPermissions) {
|
|
184
|
-
validPermissions[entityName] = entityPermissions;
|
|
185
|
-
}
|
|
68
|
+
this.validateEntityPermissions(permissions[entityName], entity, variables, errorBuilder.for(entityName));
|
|
186
69
|
}
|
|
187
|
-
return validPermissions;
|
|
188
70
|
}
|
|
189
71
|
validateEntityPermissions(entityPermissions, entity, variables, errorBuilder) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const extra = (0, utils_1.checkExtraProperties)(entityPermissions, ['predicates', 'operations']);
|
|
195
|
-
if (extra.length) {
|
|
196
|
-
errorBuilder.add('Unsupported properties found: ' + extra.join(', '));
|
|
197
|
-
}
|
|
198
|
-
const predicates = this.validatePredicates(entityPermissions.predicates, entity, variables, errorBuilder.for('predicates'));
|
|
199
|
-
const operations = this.validateOperations(entityPermissions.operations, entity, entityPermissions.predicates, errorBuilder.for('operations'));
|
|
200
|
-
return { operations, predicates };
|
|
72
|
+
this.validatePredicates(entityPermissions.predicates, entity, variables, errorBuilder.for('predicates'));
|
|
73
|
+
this.validateOperations(entityPermissions.operations, entity, entityPermissions.predicates, errorBuilder.for('operations'));
|
|
201
74
|
}
|
|
202
75
|
validatePredicates(predicates, entity, variables, errorBuilder) {
|
|
203
|
-
if (!(0, utils_1.isObject)(predicates)) {
|
|
204
|
-
errorBuilder.add('Must be an object');
|
|
205
|
-
return {};
|
|
206
|
-
}
|
|
207
|
-
const validPredicates = {};
|
|
208
76
|
for (const predicateName in predicates) {
|
|
209
77
|
if (!predicates.hasOwnProperty(predicateName)) {
|
|
210
78
|
continue;
|
|
211
79
|
}
|
|
212
|
-
|
|
213
|
-
if (predicate) {
|
|
214
|
-
validPredicates[predicateName] = predicate;
|
|
215
|
-
}
|
|
80
|
+
this.validatePredicateDefinition(predicates[predicateName], entity, variables, errorBuilder.for(predicateName));
|
|
216
81
|
}
|
|
217
|
-
return validPredicates;
|
|
218
82
|
}
|
|
219
83
|
validatePredicateDefinition(predicate, entity, variables, errorBuilder) {
|
|
220
|
-
if (!(0, utils_1.isObject)(predicate)) {
|
|
221
|
-
errorBuilder.add('Must be an object');
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
84
|
const processor = new acl_1.PredicateDefinitionProcessor(this.model);
|
|
225
|
-
|
|
226
|
-
const result = processor.process(entity, predicate, {
|
|
85
|
+
processor.process(entity, predicate, {
|
|
227
86
|
handleColumn: ctx => {
|
|
228
87
|
if (typeof ctx.value === 'string' && !variables[ctx.value]) {
|
|
229
|
-
valid = false;
|
|
230
88
|
errorBuilder.for(...ctx.path).add(`Undefined variable ${ctx.value}`);
|
|
231
89
|
}
|
|
232
90
|
return ctx.value;
|
|
233
91
|
},
|
|
234
92
|
handleRelation: ctx => {
|
|
235
93
|
if (typeof ctx.value === 'string' && !variables[ctx.value]) {
|
|
236
|
-
valid = false;
|
|
237
94
|
errorBuilder.for(...ctx.path).add(`Undefined variable ${ctx.value}`);
|
|
238
95
|
}
|
|
239
96
|
return ctx.value;
|
|
240
97
|
},
|
|
241
98
|
handleUndefinedField: ctx => {
|
|
242
99
|
errorBuilder.for(...ctx.path).add(`Undefined field ${ctx.name} on entity ${ctx.entity.name}`);
|
|
243
|
-
valid = false;
|
|
244
100
|
return ctx.value;
|
|
245
101
|
},
|
|
246
102
|
});
|
|
247
|
-
if (!valid) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
return result;
|
|
251
103
|
}
|
|
252
104
|
validateOperations(operations, entity, predicates, errorBuilder) {
|
|
253
|
-
if (!(0, utils_1.isObject)(operations)) {
|
|
254
|
-
errorBuilder.add('Must be an object');
|
|
255
|
-
return {};
|
|
256
|
-
}
|
|
257
|
-
const extra = (0, utils_1.checkExtraProperties)(operations, ['read', 'create', 'update', 'delete', 'customPrimary']);
|
|
258
|
-
if (extra.length) {
|
|
259
|
-
errorBuilder.add('Unsupported properties found: ' + extra.join(', '));
|
|
260
|
-
}
|
|
261
|
-
const validOperations = {};
|
|
262
105
|
if (operations.delete !== undefined) {
|
|
263
|
-
|
|
106
|
+
this.validatePredicate(operations.delete, predicates, errorBuilder.for('delete'));
|
|
264
107
|
}
|
|
265
108
|
for (const op of ['read', 'create', 'update']) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
if (operations.customPrimary !== undefined) {
|
|
271
|
-
if (typeof operations.customPrimary !== 'boolean') {
|
|
272
|
-
errorBuilder.for('customPrimary').add('Must be boolean');
|
|
109
|
+
const operation = operations[op];
|
|
110
|
+
if (operation !== undefined) {
|
|
111
|
+
this.validateFieldPermissions(operation, entity, predicates, errorBuilder.for(op));
|
|
273
112
|
}
|
|
274
|
-
validOperations.customPrimary = operations.customPrimary;
|
|
275
113
|
}
|
|
276
|
-
return validOperations;
|
|
277
114
|
}
|
|
278
115
|
validateFieldPermissions(permissions, entity, predicates, errorBuilder) {
|
|
279
|
-
if (!(0, utils_1.isObject)(permissions)) {
|
|
280
|
-
errorBuilder.add('Must be an object');
|
|
281
|
-
return {};
|
|
282
|
-
}
|
|
283
|
-
const valid = {};
|
|
284
116
|
for (const field in permissions) {
|
|
285
117
|
if (!permissions.hasOwnProperty(field)) {
|
|
286
118
|
continue;
|
|
@@ -288,23 +120,16 @@ class AclValidator {
|
|
|
288
120
|
if (!entity.fields[field]) {
|
|
289
121
|
errorBuilder.add(`Field ${field} not found on entity ${entity.name}`);
|
|
290
122
|
}
|
|
291
|
-
|
|
123
|
+
this.validatePredicate(permissions[field], predicates, errorBuilder.for(field));
|
|
292
124
|
}
|
|
293
|
-
return valid;
|
|
294
125
|
}
|
|
295
126
|
validatePredicate(predicate, predicates, errorBuilder) {
|
|
296
127
|
if (predicate === false || predicate === true) {
|
|
297
|
-
return
|
|
298
|
-
}
|
|
299
|
-
if (typeof predicate !== 'string') {
|
|
300
|
-
errorBuilder.add('Predicate must be either boolean or predicate reference');
|
|
301
|
-
return false;
|
|
128
|
+
return;
|
|
302
129
|
}
|
|
303
130
|
if (!predicates[predicate]) {
|
|
304
131
|
errorBuilder.add(`Predicate ${predicate} not found`);
|
|
305
|
-
return false;
|
|
306
132
|
}
|
|
307
|
-
return predicate;
|
|
308
133
|
}
|
|
309
134
|
}
|
|
310
135
|
exports.AclValidator = AclValidator;
|