@balena/sbvr-types 7.0.3 → 7.0.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.
- package/.versionbot/CHANGELOG.yml +12 -1
- package/CHANGELOG.md +5 -0
- package/out/type-utils.d.ts +16 -11
- package/out/type-utils.js.map +1 -1
- package/out/types/big-integer.d.ts +5 -5
- package/out/types/big-integer.js.map +1 -1
- package/out/types/big-serial.d.ts +4 -5
- package/out/types/big-serial.js.map +1 -1
- package/out/types/boolean.d.ts +3 -5
- package/out/types/boolean.js.map +1 -1
- package/out/types/case-insensitive-text.d.ts +5 -5
- package/out/types/case-insensitive-text.js.map +1 -1
- package/out/types/color.d.ts +3 -5
- package/out/types/color.js.map +1 -1
- package/out/types/concept-type.d.ts +5 -5
- package/out/types/concept-type.js.map +1 -1
- package/out/types/date-time.d.ts +3 -5
- package/out/types/date-time.js.map +1 -1
- package/out/types/date.d.ts +3 -5
- package/out/types/date.js.map +1 -1
- package/out/types/file.d.ts +5 -5
- package/out/types/file.js.map +1 -1
- package/out/types/foreign-key.d.ts +5 -5
- package/out/types/foreign-key.js.map +1 -1
- package/out/types/hashed.d.ts +5 -5
- package/out/types/hashed.js.map +1 -1
- package/out/types/integer.d.ts +5 -5
- package/out/types/integer.js.map +1 -1
- package/out/types/interval.d.ts +5 -5
- package/out/types/interval.js.map +1 -1
- package/out/types/json.d.ts +3 -5
- package/out/types/json.js.map +1 -1
- package/out/types/real.d.ts +5 -5
- package/out/types/real.js.map +1 -1
- package/out/types/serial.d.ts +4 -5
- package/out/types/serial.js.map +1 -1
- package/out/types/sha.d.ts +5 -5
- package/out/types/sha.js.map +1 -1
- package/out/types/short-text.d.ts +5 -5
- package/out/types/short-text.js.map +1 -1
- package/out/types/text.d.ts +5 -5
- package/out/types/text.js.map +1 -1
- package/out/types/time.d.ts +3 -1
- package/out/types/time.js +2 -3
- package/out/types/time.js.map +1 -1
- package/out/types/web-resource.d.ts +3 -5
- package/out/types/web-resource.js.map +1 -1
- package/package.json +2 -2
- package/src/type-utils.ts +17 -9
- package/src/types/big-integer.ts +5 -1
- package/src/types/big-serial.ts +5 -1
- package/src/types/boolean.ts +15 -12
- package/src/types/case-insensitive-text.ts +5 -1
- package/src/types/color.ts +47 -44
- package/src/types/concept-type.ts +5 -1
- package/src/types/date-time.ts +4 -1
- package/src/types/date.ts +4 -1
- package/src/types/file.ts +27 -23
- package/src/types/foreign-key.ts +5 -1
- package/src/types/hashed.ts +11 -7
- package/src/types/integer.ts +5 -1
- package/src/types/interval.ts +5 -1
- package/src/types/json.ts +14 -11
- package/src/types/real.ts +11 -7
- package/src/types/serial.ts +5 -1
- package/src/types/sha.ts +10 -6
- package/src/types/short-text.ts +5 -1
- package/src/types/text.ts +5 -1
- package/src/types/time.ts +10 -1
- package/src/types/web-resource.ts +5 -4
package/out/types/text.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as TypeUtils from '../type-utils';
|
|
1
2
|
export declare const types: {
|
|
2
3
|
postgres: string;
|
|
3
4
|
mysql: string;
|
|
@@ -6,6 +7,8 @@ export declare const types: {
|
|
|
6
7
|
name: string;
|
|
7
8
|
};
|
|
8
9
|
};
|
|
10
|
+
type WriteType = string;
|
|
11
|
+
type DbWriteType = string;
|
|
9
12
|
export declare const nativeProperties: {
|
|
10
13
|
has: {
|
|
11
14
|
Length: (from: string) => string[];
|
|
@@ -19,8 +22,5 @@ export declare const nativeFactTypes: {
|
|
|
19
22
|
'is equal to': (from: string, to: string) => string[];
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
|
-
export declare const validate:
|
|
23
|
-
|
|
24
|
-
(value: null | undefined, required: false): Promise<null>;
|
|
25
|
-
(value: any, required: boolean): Promise<string | null>;
|
|
26
|
-
};
|
|
25
|
+
export declare const validate: TypeUtils.Validate<WriteType, DbWriteType>;
|
|
26
|
+
export {};
|
package/out/types/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/types/text.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,KAAK,EAAE;QACN,IAAI,EAAE,YAAY;KAClB;CACD,CAAC;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/types/text.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,KAAK,EAAE;QACN,IAAI,EAAE,YAAY;KAClB;CACD,CAAC;AAKW,QAAA,gBAAgB,GAAG;IAC/B,GAAG,EAAE;QACJ,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,iBAAiB,EAAE,IAAI,CAAC;KACnD;CACD,CAAC;AAEW,QAAA,eAAe,GAAG;IAC9B,IAAI,EAAE;QACL,GAAG,SAAS,CAAC,uBAAuB,CAAC,QAAQ;QAC7C,aAAa,EAAE,CAAC,IAAY,EAAE,EAAU,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QACrE,WAAW,EAAE,CAAC,IAAY,EAAE,EAAU,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;QACjE,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAU,EAAE,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;KAC9D;CACD,CAAC;AAEW,QAAA,QAAQ,GACpB,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC"}
|
package/out/types/time.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const types: {
|
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
10
|
type ReadType = string;
|
|
11
|
+
type WriteType = number | string;
|
|
12
|
+
type DbWriteType = string;
|
|
11
13
|
export declare const fetchProcessing: TypeUtils.FetchProcessing<ReadType>;
|
|
12
|
-
export declare const validate:
|
|
14
|
+
export declare const validate: TypeUtils.Validate<WriteType, DbWriteType>;
|
|
13
15
|
export {};
|
package/out/types/time.js
CHANGED
|
@@ -17,12 +17,11 @@ const fetchProcessing = (data) => {
|
|
|
17
17
|
return data;
|
|
18
18
|
};
|
|
19
19
|
exports.fetchProcessing = fetchProcessing;
|
|
20
|
-
|
|
20
|
+
exports.validate = (async (value, required) => {
|
|
21
21
|
const date = await TypeUtils.validate.date(value, required);
|
|
22
22
|
if (date == null) {
|
|
23
23
|
return date;
|
|
24
24
|
}
|
|
25
25
|
return date.toLocaleTimeString();
|
|
26
|
-
};
|
|
27
|
-
exports.validate = validate;
|
|
26
|
+
});
|
|
28
27
|
//# sourceMappingURL=time.js.map
|
package/out/types/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/types/time.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE;QACN,IAAI,EAAE,cAAc;KACpB;CACD,CAAC;
|
|
1
|
+
{"version":3,"file":"time.js","sourceRoot":"","sources":["../../src/types/time.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,MAAM;IAChB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,SAAS;IACjB,KAAK,EAAE;QACN,IAAI,EAAE,cAAc;KACpB;CACD,CAAC;AAMK,MAAM,eAAe,GAAwC,CAAC,IAAI,EAAE,EAAE;IAC5E,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QAElB,OAAO,IAAI,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3D,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AANW,QAAA,eAAe,mBAM1B;AAEW,QAAA,QAAQ,GAA+C,CAAC,KAAK,EACzE,KAAK,EACL,QAAQ,EACP,EAAE;IACH,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5D,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;AAClC,CAAC,CAIA,CAAC"}
|
|
@@ -18,6 +18,8 @@ export declare const types: {
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
type ReadType = WebResource;
|
|
21
|
+
type WriteType = WebResource;
|
|
22
|
+
type DbWriteType = string;
|
|
21
23
|
export declare const nativeProperties: {
|
|
22
24
|
has: {
|
|
23
25
|
Filename: (referencedField: ReferencedFieldNode) => ExtractJSONPathAsTextNode;
|
|
@@ -29,9 +31,5 @@ export declare const nativeProperties: {
|
|
|
29
31
|
};
|
|
30
32
|
};
|
|
31
33
|
export declare const fetchProcessing: TypeUtils.FetchProcessing<ReadType>;
|
|
32
|
-
export declare const validate:
|
|
33
|
-
(value: any, required: true): Promise<Promise<string>>;
|
|
34
|
-
(value: null | undefined, required: false): Promise<null>;
|
|
35
|
-
(value: any, required: boolean): Promise<Promise<string> | null>;
|
|
36
|
-
};
|
|
34
|
+
export declare const validate: TypeUtils.Validate<WriteType, DbWriteType>;
|
|
37
35
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-resource.js","sourceRoot":"","sources":["../../src/types/web-resource.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAgB9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,KAAK,EAAE;QACN,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE;;;;;;;;eAQA;KACb;CACD,CAAC;
|
|
1
|
+
{"version":3,"file":"web-resource.js","sourceRoot":"","sources":["../../src/types/web-resource.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAgB9B,QAAA,KAAK,GAAG;IACpB,QAAQ,EAAE,OAAO;IACjB,KAAK,EAAE,MAAM;IACb,MAAM,EAAE,MAAM;IACd,KAAK,EAAE;QACN,IAAI,EAAE,kBAAkB;QACxB,WAAW,EAAE;;;;;;;;eAQA;KACb;CACD,CAAC;AAMW,QAAA,gBAAgB,GAAG;IAC/B,GAAG,EAAE;QACJ,QAAQ,EAAE,CACT,eAAoC,EACR,EAAE,CAAC;YAC/B,uBAAuB;YACvB,eAAe;YACf,CAAC,WAAW,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SAC3C;QACD,IAAI,EAAE,CAAC,eAAoC,EAA6B,EAAE,CAAC;YAC1E,uBAAuB;YACvB,eAAe;YACf,CAAC,WAAW,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;SACvC;QACD,cAAc,EAAE,CACf,eAAoC,EACR,EAAE,CAAC;YAC/B,uBAAuB;YACvB,eAAe;YACf,CAAC,WAAW,EAAE,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;SAC/C;QACD,qBAAqB,EAAE,CACtB,eAAoC,EACR,EAAE,CAAC;YAC/B,uBAAuB;YACvB,eAAe;YACf,CAAC,WAAW,EAAE,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;SACtD;QACD,QAAQ,EAAE,CACT,eAAoC,EACR,EAAE,CAAC;YAC/B,uBAAuB;YACvB,eAAe;YACf,CAAC,WAAW,EAAE,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;SAC3C;QACD,IAAI,EAAE,CAAC,eAAoC,EAAY,EAAE,CAAC;YACzD,MAAM;YACN;gBACC,uBAAuB;gBACvB,eAAe;gBACf,CAA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;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACjD,CAAC;AACF,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/sbvr-types",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4",
|
|
4
4
|
"description": "SBVR type definitions.",
|
|
5
5
|
"main": "out",
|
|
6
6
|
"scripts": {
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
"npm": ">=8.1.0"
|
|
52
52
|
},
|
|
53
53
|
"versionist": {
|
|
54
|
-
"publishedAt": "2024-03-
|
|
54
|
+
"publishedAt": "2024-03-12T16:35:35.687Z"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/type-utils.ts
CHANGED
|
@@ -3,7 +3,7 @@ export interface DatabaseTypeFn {
|
|
|
3
3
|
castType: string;
|
|
4
4
|
}
|
|
5
5
|
export type DatabaseType = string | DatabaseTypeFn;
|
|
6
|
-
export interface SbvrType<Read = unknown> {
|
|
6
|
+
export interface SbvrType<Read = unknown, Write = any, DbWrite = unknown> {
|
|
7
7
|
types: {
|
|
8
8
|
odata: {
|
|
9
9
|
name: string;
|
|
@@ -14,16 +14,24 @@ export interface SbvrType<Read = unknown> {
|
|
|
14
14
|
websql: DatabaseType;
|
|
15
15
|
};
|
|
16
16
|
fetchProcessing?: FetchProcessing<Read>;
|
|
17
|
-
validate:
|
|
17
|
+
validate: Validate<Write, DbWrite>;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export type FetchProcessing<Read> = (data: unknown) => Read | null | undefined;
|
|
21
|
+
export interface Validate<Write, DbWrite> {
|
|
22
|
+
(value: Write, required: true): Promise<DbWrite>;
|
|
23
|
+
(value: Write, required: false): Promise<DbWrite | null>;
|
|
24
|
+
(value: Write, required: boolean): Promise<DbWrite | null>;
|
|
25
|
+
}
|
|
21
26
|
|
|
22
|
-
const checkRequired = <T>(validateFn: (value: any) => T) => {
|
|
23
|
-
function runCheck(value:
|
|
27
|
+
const checkRequired = <T>(validateFn: (value: any) => T | Promise<T>) => {
|
|
28
|
+
function runCheck(value: unknown, required: true): Promise<T>;
|
|
24
29
|
function runCheck(value: undefined | null, required: false): Promise<null>;
|
|
25
|
-
function runCheck(value:
|
|
26
|
-
async function runCheck(
|
|
30
|
+
function runCheck(value: unknown, required: boolean): Promise<T | null>;
|
|
31
|
+
async function runCheck(
|
|
32
|
+
value: unknown,
|
|
33
|
+
required: boolean,
|
|
34
|
+
): Promise<T | null> {
|
|
27
35
|
if (value == null) {
|
|
28
36
|
if (required) {
|
|
29
37
|
throw new Error('cannot be null');
|
|
@@ -53,7 +61,7 @@ export const nativeFactTypeTemplates = {
|
|
|
53
61
|
|
|
54
62
|
export const validate = {
|
|
55
63
|
checkRequired,
|
|
56
|
-
integer: checkRequired((value
|
|
64
|
+
integer: checkRequired((value) => {
|
|
57
65
|
const processedValue = parseInt(value, 10);
|
|
58
66
|
if (Number.isNaN(processedValue)) {
|
|
59
67
|
throw new Error('is not a number: ' + value);
|
|
@@ -61,7 +69,7 @@ export const validate = {
|
|
|
61
69
|
return processedValue;
|
|
62
70
|
}),
|
|
63
71
|
text: (length?: number) =>
|
|
64
|
-
checkRequired((value
|
|
72
|
+
checkRequired((value) => {
|
|
65
73
|
if (typeof value !== 'string') {
|
|
66
74
|
throw new Error('is not a string: ' + value);
|
|
67
75
|
}
|
|
@@ -72,7 +80,7 @@ export const validate = {
|
|
|
72
80
|
}
|
|
73
81
|
return value;
|
|
74
82
|
}),
|
|
75
|
-
date: checkRequired((value
|
|
83
|
+
date: checkRequired((value) => {
|
|
76
84
|
let processedValue = Number(value);
|
|
77
85
|
if (Number.isNaN(processedValue)) {
|
|
78
86
|
processedValue = value;
|
package/src/types/big-integer.ts
CHANGED
|
@@ -9,9 +9,13 @@ export const types = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
type WriteType = number;
|
|
13
|
+
type DbWriteType = number;
|
|
14
|
+
|
|
12
15
|
export const nativeFactTypes = {
|
|
13
16
|
Integer: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
14
17
|
Real: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
export const validate
|
|
20
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
21
|
+
TypeUtils.validate.integer;
|
package/src/types/big-serial.ts
CHANGED
package/src/types/boolean.ts
CHANGED
|
@@ -17,20 +17,23 @@ export const types = {
|
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
type ReadType = boolean;
|
|
20
|
+
type WriteType = boolean | 0 | 1;
|
|
21
|
+
type DbWriteType = boolean;
|
|
20
22
|
|
|
21
23
|
// `BOOLEAN` on sqlite/websql is just an alias for `INTEGER` hence the `=== 1` check
|
|
22
24
|
export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) =>
|
|
23
25
|
data === true || data === 1;
|
|
24
26
|
|
|
25
|
-
export const validate
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
28
|
+
TypeUtils.validate.checkRequired((originalValue) => {
|
|
29
|
+
// We use Number rather than parseInt as it deals with booleans and will return NaN for things like "a1"
|
|
30
|
+
const value = Number(originalValue);
|
|
31
|
+
if (value !== 0 && value !== 1) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`is not a boolean: ${JSON.stringify(
|
|
34
|
+
originalValue,
|
|
35
|
+
)} (${typeof originalValue})`,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return value === 1;
|
|
39
|
+
});
|
package/src/types/color.ts
CHANGED
|
@@ -22,6 +22,8 @@ type ReadType = {
|
|
|
22
22
|
b: number;
|
|
23
23
|
a: number;
|
|
24
24
|
};
|
|
25
|
+
type WriteType = number | ReadType;
|
|
26
|
+
type DbWriteType = number;
|
|
25
27
|
|
|
26
28
|
export const nativeProperties = {
|
|
27
29
|
has: {
|
|
@@ -58,48 +60,49 @@ export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) => {
|
|
|
58
60
|
/* eslint-enable no-bitwise */
|
|
59
61
|
};
|
|
60
62
|
|
|
61
|
-
export const validate
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
} else {
|
|
69
|
-
processedValue = 0;
|
|
70
|
-
Object.keys(value).forEach((component) => {
|
|
71
|
-
const componentValue = value[component];
|
|
72
|
-
if (Number.isNaN(componentValue) || componentValue > 255) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
'has invalid component value of ' +
|
|
75
|
-
componentValue +
|
|
76
|
-
' for component ' +
|
|
77
|
-
component,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
/* eslint-disable no-bitwise */
|
|
81
|
-
switch (component.toLowerCase()) {
|
|
82
|
-
case 'r':
|
|
83
|
-
case 'red':
|
|
84
|
-
processedValue |= componentValue << 16;
|
|
85
|
-
break;
|
|
86
|
-
case 'g':
|
|
87
|
-
case 'green':
|
|
88
|
-
processedValue |= componentValue << 8;
|
|
89
|
-
break;
|
|
90
|
-
case 'b':
|
|
91
|
-
case 'blue':
|
|
92
|
-
processedValue |= componentValue;
|
|
93
|
-
break;
|
|
94
|
-
case 'a':
|
|
95
|
-
case 'alpha':
|
|
96
|
-
processedValue |= componentValue << 24;
|
|
97
|
-
break;
|
|
98
|
-
default:
|
|
99
|
-
throw new Error('has an unknown component: ' + component);
|
|
63
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
64
|
+
TypeUtils.validate.checkRequired((value) => {
|
|
65
|
+
let processedValue: number;
|
|
66
|
+
if (typeof value !== 'object') {
|
|
67
|
+
processedValue = parseInt(value, 10);
|
|
68
|
+
if (Number.isNaN(processedValue)) {
|
|
69
|
+
throw new Error('is neither an integer or color object: ' + value);
|
|
100
70
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
71
|
+
} else {
|
|
72
|
+
processedValue = 0;
|
|
73
|
+
Object.keys(value).forEach((component) => {
|
|
74
|
+
const componentValue = value[component];
|
|
75
|
+
if (Number.isNaN(componentValue) || componentValue > 255) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'has invalid component value of ' +
|
|
78
|
+
componentValue +
|
|
79
|
+
' for component ' +
|
|
80
|
+
component,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
/* eslint-disable no-bitwise */
|
|
84
|
+
switch (component.toLowerCase()) {
|
|
85
|
+
case 'r':
|
|
86
|
+
case 'red':
|
|
87
|
+
processedValue |= componentValue << 16;
|
|
88
|
+
break;
|
|
89
|
+
case 'g':
|
|
90
|
+
case 'green':
|
|
91
|
+
processedValue |= componentValue << 8;
|
|
92
|
+
break;
|
|
93
|
+
case 'b':
|
|
94
|
+
case 'blue':
|
|
95
|
+
processedValue |= componentValue;
|
|
96
|
+
break;
|
|
97
|
+
case 'a':
|
|
98
|
+
case 'alpha':
|
|
99
|
+
processedValue |= componentValue << 24;
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
throw new Error('has an unknown component: ' + component);
|
|
103
|
+
}
|
|
104
|
+
/* eslint-enable no-bitwise */
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return processedValue;
|
|
108
|
+
});
|
|
@@ -9,9 +9,13 @@ export const types = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
type WriteType = number;
|
|
13
|
+
type DbWriteType = number;
|
|
14
|
+
|
|
12
15
|
export const nativeFactTypes = {
|
|
13
16
|
Integer: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
14
17
|
Real: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
export const validate
|
|
20
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
21
|
+
TypeUtils.validate.integer;
|
package/src/types/date-time.ts
CHANGED
|
@@ -10,6 +10,8 @@ export const types = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
type ReadType = string;
|
|
13
|
+
type WriteType = string | number;
|
|
14
|
+
type DbWriteType = Date;
|
|
13
15
|
|
|
14
16
|
export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) => {
|
|
15
17
|
if (data == null) {
|
|
@@ -37,4 +39,5 @@ export const nativeNames = {
|
|
|
37
39
|
'Current Time': ['Now'],
|
|
38
40
|
};
|
|
39
41
|
|
|
40
|
-
export const validate
|
|
42
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
43
|
+
TypeUtils.validate.date;
|
package/src/types/date.ts
CHANGED
|
@@ -10,6 +10,8 @@ export const types = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
type ReadType = string;
|
|
13
|
+
type WriteType = string | number;
|
|
14
|
+
type DbWriteType = Date;
|
|
13
15
|
|
|
14
16
|
export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) => {
|
|
15
17
|
if (data == null) {
|
|
@@ -33,4 +35,5 @@ export const nativeFactTypes = {
|
|
|
33
35
|
},
|
|
34
36
|
};
|
|
35
37
|
|
|
36
|
-
export const validate
|
|
38
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
39
|
+
TypeUtils.validate.date;
|
package/src/types/file.ts
CHANGED
|
@@ -8,26 +8,30 @@ export const types = {
|
|
|
8
8
|
},
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
type WriteType = Buffer | string;
|
|
12
|
+
type DbWriteType = Buffer;
|
|
13
|
+
|
|
14
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
15
|
+
TypeUtils.validate.checkRequired((value) => {
|
|
16
|
+
if (Buffer.isBuffer(value)) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
if (typeof value !== 'string') {
|
|
20
|
+
throw new Error(`could not be converted to binary: ${typeof value}`);
|
|
21
|
+
}
|
|
22
|
+
if (value.length % 2 !== 0) {
|
|
23
|
+
throw new Error(
|
|
24
|
+
'could not be converted to binary: hex string must have an even length',
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (!/^[a-fA-F0-9]*$/.test(value)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
'could not be converted to binary: hex string must contain only hex characters',
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return Buffer.from(value, 'hex');
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
throw new Error(`could not be converted to binary: ${e.message}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
package/src/types/foreign-key.ts
CHANGED
|
@@ -9,9 +9,13 @@ export const types = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
type WriteType = number;
|
|
13
|
+
type DbWriteType = number;
|
|
14
|
+
|
|
12
15
|
export const nativeFactTypes = {
|
|
13
16
|
Integer: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
14
17
|
Real: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
export const validate
|
|
20
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
21
|
+
TypeUtils.validate.integer;
|
package/src/types/hashed.ts
CHANGED
|
@@ -18,12 +18,16 @@ export const types = {
|
|
|
18
18
|
},
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
type WriteType = string;
|
|
22
|
+
type DbWriteType = string;
|
|
23
|
+
|
|
24
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
25
|
+
TypeUtils.validate.checkRequired(async (value) => {
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
throw new Error('is not a string');
|
|
28
|
+
}
|
|
29
|
+
const salt = await bcrypt.genSalt();
|
|
30
|
+
return bcrypt.hash(value, salt);
|
|
31
|
+
});
|
|
28
32
|
|
|
29
33
|
export const compare = bcrypt.compare.bind(bcrypt);
|
package/src/types/integer.ts
CHANGED
|
@@ -9,9 +9,13 @@ export const types = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
type WriteType = number;
|
|
13
|
+
type DbWriteType = number;
|
|
14
|
+
|
|
12
15
|
export const nativeFactTypes = {
|
|
13
16
|
Integer: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
14
17
|
Real: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
export const validate
|
|
20
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
21
|
+
TypeUtils.validate.integer;
|
package/src/types/interval.ts
CHANGED
package/src/types/json.ts
CHANGED
|
@@ -10,6 +10,8 @@ export const types = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
type ReadType = Record<string, any> | any[];
|
|
13
|
+
type WriteType = Record<string, any> | any[];
|
|
14
|
+
type DbWriteType = string;
|
|
13
15
|
|
|
14
16
|
export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) => {
|
|
15
17
|
if (typeof data === 'string') {
|
|
@@ -18,15 +20,16 @@ export const fetchProcessing: TypeUtils.FetchProcessing<ReadType> = (data) => {
|
|
|
18
20
|
return data;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
export const validate
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
24
|
+
TypeUtils.validate.checkRequired((value) => {
|
|
25
|
+
// Disallow primitives
|
|
26
|
+
if (typeof value !== 'object') {
|
|
27
|
+
throw new Error(`is not an object/array: ${typeof value}`);
|
|
28
|
+
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
30
|
+
try {
|
|
31
|
+
return JSON.stringify(value);
|
|
32
|
+
} catch {
|
|
33
|
+
throw new Error('cannot be turned into JSON: ' + value);
|
|
34
|
+
}
|
|
35
|
+
});
|
package/src/types/real.ts
CHANGED
|
@@ -9,15 +9,19 @@ export const types = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
+
type WriteType = number;
|
|
13
|
+
type DbWriteType = number;
|
|
14
|
+
|
|
12
15
|
export const nativeFactTypes = {
|
|
13
16
|
Integer: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
14
17
|
Real: TypeUtils.nativeFactTypeTemplates.comparison,
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
export const validate
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
21
|
+
TypeUtils.validate.checkRequired((value) => {
|
|
22
|
+
const processedValue = parseFloat(value);
|
|
23
|
+
if (Number.isNaN(processedValue)) {
|
|
24
|
+
throw new Error('is not a number: ' + value);
|
|
25
|
+
}
|
|
26
|
+
return processedValue;
|
|
27
|
+
});
|
package/src/types/serial.ts
CHANGED
package/src/types/sha.ts
CHANGED
|
@@ -30,14 +30,18 @@ export const types = {
|
|
|
30
30
|
},
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
type WriteType = string;
|
|
34
|
+
type DbWriteType = string;
|
|
35
|
+
|
|
33
36
|
export const validateSync = sha256;
|
|
34
37
|
|
|
35
|
-
export const validate
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
export const validate: TypeUtils.Validate<WriteType, DbWriteType> =
|
|
39
|
+
TypeUtils.validate.checkRequired((value) => {
|
|
40
|
+
if (typeof value !== 'string') {
|
|
41
|
+
throw new Error('is not a string');
|
|
42
|
+
}
|
|
43
|
+
return sha256(value);
|
|
44
|
+
});
|
|
41
45
|
|
|
42
46
|
export const compare = async (value: string, result: string) => {
|
|
43
47
|
return sha256(value) === result;
|
package/src/types/short-text.ts
CHANGED