validno 0.4.3 → 0.4.5
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/dev.d.ts
CHANGED
package/dist/dev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY;;;;;CAKf,CAAC"}
|
package/dist/dev.js
CHANGED
|
@@ -1,17 +1,60 @@
|
|
|
1
1
|
import { Schema } from "./Schema.js";
|
|
2
|
+
import isObjectId from "./utils/isObjectId.js";
|
|
3
|
+
import { ObjectId } from "mongodb";
|
|
4
|
+
export const AccessScopes = {
|
|
5
|
+
Inherit: 'inherit',
|
|
6
|
+
Public: 'public',
|
|
7
|
+
Project: 'workspace',
|
|
8
|
+
User: 'user'
|
|
9
|
+
};
|
|
10
|
+
const checkMethodScope = (value, context) => {
|
|
11
|
+
const authCollection = context.input.authCollection;
|
|
12
|
+
if (isObjectId(authCollection, ObjectId))
|
|
13
|
+
return true;
|
|
14
|
+
const mainScope = context.input.scope;
|
|
15
|
+
const methods = context.input.methods;
|
|
16
|
+
const allMethodsScopes = [
|
|
17
|
+
mainScope,
|
|
18
|
+
...Object.values(methods).filter(method => method.isActive).map(method => method.scope)
|
|
19
|
+
];
|
|
20
|
+
if (!allMethodsScopes.includes(AccessScopes.User) && !allMethodsScopes.includes(AccessScopes.Project)) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
result: false,
|
|
25
|
+
details: 'Invalid scope. To use User or Project scope, the collection must have authCollection to be set.'
|
|
26
|
+
};
|
|
27
|
+
};
|
|
2
28
|
const test = () => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
const data = {
|
|
30
|
+
scope: 'public',
|
|
31
|
+
methods: {
|
|
32
|
+
get: { isActive: false, scope: 'public' },
|
|
33
|
+
getAll: {
|
|
34
|
+
isActive: true,
|
|
35
|
+
scope: 'public',
|
|
36
|
+
sort: [Object],
|
|
37
|
+
filter: [Object],
|
|
38
|
+
search: [Object]
|
|
39
|
+
},
|
|
40
|
+
create: { isActive: true, scope: 'public' },
|
|
41
|
+
update: { isActive: false, scope: 'public', allowedFields: [] },
|
|
42
|
+
delete: { isActive: false, scope: 'public' },
|
|
43
|
+
distinct: { isActive: false, scope: 'public', fields: [] }
|
|
44
|
+
},
|
|
45
|
+
authSettings: null,
|
|
46
|
+
authCollection: null
|
|
8
47
|
};
|
|
9
48
|
const collectionSettingsSchema = new Schema({
|
|
10
|
-
|
|
49
|
+
authCollection: {
|
|
50
|
+
type: [ObjectId, null],
|
|
51
|
+
required: false,
|
|
52
|
+
},
|
|
11
53
|
scope: {
|
|
12
54
|
type: String,
|
|
13
55
|
rules: {
|
|
14
|
-
enum: Object.values(AccessScopes)
|
|
56
|
+
enum: Object.values(AccessScopes).filter(scope => scope !== AccessScopes.Inherit),
|
|
57
|
+
custom: checkMethodScope
|
|
15
58
|
},
|
|
16
59
|
},
|
|
17
60
|
methods: {
|
|
@@ -32,9 +75,9 @@ const test = () => {
|
|
|
32
75
|
},
|
|
33
76
|
required: false
|
|
34
77
|
},
|
|
35
|
-
sort: { default: { type: String } },
|
|
36
|
-
filter: { fields: { type: Array, eachType: String } },
|
|
37
|
-
search: { fields: { type: Array, eachType: String } }
|
|
78
|
+
sort: { default: { type: String, required: false } },
|
|
79
|
+
filter: { fields: { type: Array, eachType: String, required: false } },
|
|
80
|
+
search: { fields: { type: Array, eachType: String, required: false } }
|
|
38
81
|
},
|
|
39
82
|
create: {
|
|
40
83
|
isActive: { type: Boolean },
|
|
@@ -51,7 +94,7 @@ const test = () => {
|
|
|
51
94
|
rules: { enum: Object.values(AccessScopes) },
|
|
52
95
|
required: false
|
|
53
96
|
},
|
|
54
|
-
allowedFields: { type: Array, eachType: String }
|
|
97
|
+
allowedFields: { type: Array, eachType: String, required: false }
|
|
55
98
|
},
|
|
56
99
|
delete: {
|
|
57
100
|
isActive: { type: Boolean },
|
|
@@ -72,8 +115,7 @@ const test = () => {
|
|
|
72
115
|
}
|
|
73
116
|
}
|
|
74
117
|
});
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
console.log(res);
|
|
118
|
+
const validateResult = collectionSettingsSchema.validate(data);
|
|
119
|
+
console.log(validateResult);
|
|
78
120
|
};
|
|
79
121
|
test();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateType.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validateType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AACtE,OAAO,aAAa,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"validateType.d.ts","sourceRoot":"","sources":["../../../src/engine/methods/validateType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAC;AACtE,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAqLhD,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,aAAa,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;IACX,IAAI,EAAE,gBAAgB,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,OAAO,EAAE,CAAA;CACzB;AAED,iBAAS,YAAY,CAAC,KAAK,EAAE,kBAAkB,QAU9C;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -115,6 +115,10 @@ const handleTypeValidation = (key, value, requirements, keyName = key) => {
|
|
|
115
115
|
break;
|
|
116
116
|
}
|
|
117
117
|
default: {
|
|
118
|
+
if (value === null && typeBySchema !== null) {
|
|
119
|
+
result.push(_validateType.getResult(keyName, false, getDetails(false)));
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
118
122
|
const isInstanceOf = typeof typeBySchema === 'function' && value instanceof typeBySchema;
|
|
119
123
|
const isConstructorSame = typeof typeBySchema === 'function' && ((_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) === (typeBySchema === null || typeBySchema === void 0 ? void 0 : typeBySchema.name);
|
|
120
124
|
const isBothObjectId = isObjectId(value, typeBySchema);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "validno",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "A lightweight TypeScript validation library for runtime data validation. Used as part of Kodzero API framework.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"tscw": "tsc --b --watch src/",
|
|
12
12
|
"dev": "nodemon dist/dev.js",
|
|
13
13
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
14
|
+
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
|
14
15
|
"prepublishOnly": "npm run tsc"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
@@ -35,7 +36,8 @@
|
|
|
35
36
|
"@types/node": "^18.14.2",
|
|
36
37
|
"eslint": "^8.14.0",
|
|
37
38
|
"jest": "^29.7.0",
|
|
38
|
-
"mongodb": "^6.19.0"
|
|
39
|
+
"mongodb": "^6.19.0",
|
|
40
|
+
"ts-jest": "^29.4.6"
|
|
39
41
|
},
|
|
40
42
|
"directories": {
|
|
41
43
|
"test": "tests"
|