@balena/sbvr-types
Advanced tools
Comparing version 4.0.0-build-4-x-f4445710f9a70ae60f90494f63911989c3c8fc48-1 to 4.0.0-build-big-int-parsing-f52cae46de1703f88fc31a251a524dc201d34e9e-1
@@ -8,8 +8,6 @@ # Change Log | ||
# v4.0.0 | ||
## (2022-12-20) | ||
## (2023-03-17) | ||
* Set minimum supported nodejs version to 16.13.0 and tsconfig to es2021 [Pagan Gazzard] | ||
* Switch `JSON` to use `JSON` db type instead of `TEXT` [Pagan Gazzard] | ||
* Switch `Boolean` to use `BOOLEAN` db type instead of `INTEGER` [Pagan Gazzard] | ||
* Assert that JSON input typeof is object [Josh Bowling] | ||
* Switch 'Big Integer' & 'Big Serial' parsing to use native BigInt JS type [Thodoris Greasidis] | ||
* Add Big Serial type [Josh Bowling] | ||
@@ -16,0 +14,0 @@ # v3.4.19 |
"use strict"; | ||
const BigInteger = require("./types/big-integer"); | ||
const BigSerial = require("./types/big-serial"); | ||
const Boolean = require("./types/boolean"); | ||
@@ -23,2 +24,3 @@ const CaseInsensitiveText = require("./types/case-insensitive-text"); | ||
'Big Integer': BigInteger, | ||
'Big Serial': BigSerial, | ||
Boolean, | ||
@@ -25,0 +27,0 @@ 'Case Insensitive Text': CaseInsensitiveText, |
@@ -40,6 +40,11 @@ export interface DatabaseTypeFn { | ||
}; | ||
bigint: { | ||
(value: any, required: true): Promise<bigint>; | ||
(value: undefined | null, required: false): Promise<null>; | ||
<U_2>(value: U_2, required: boolean): Promise<bigint | null>; | ||
}; | ||
text: (length?: number) => { | ||
(value: any, required: true): Promise<string>; | ||
(value: undefined | null, required: false): Promise<null>; | ||
<U_2>(value: U_2, required: boolean): Promise<string | null>; | ||
<U_3>(value: U_3, required: boolean): Promise<string | null>; | ||
}; | ||
@@ -49,4 +54,4 @@ date: { | ||
(value: undefined | null, required: false): Promise<null>; | ||
<U_3>(value: U_3, required: boolean): Promise<Date | null>; | ||
<U_4>(value: U_4, required: boolean): Promise<Date | null>; | ||
}; | ||
}; |
@@ -40,2 +40,9 @@ "use strict"; | ||
}), | ||
bigint: checkRequired((value) => { | ||
if (value === '') { | ||
throw new Error('Cannot convert empty string to a BigInt'); | ||
} | ||
const processedValue = BigInt(value); | ||
return processedValue; | ||
}), | ||
text: (length) => checkRequired((value) => { | ||
@@ -42,0 +49,0 @@ if (typeof value !== 'string') { |
@@ -9,2 +9,3 @@ export declare const types: { | ||
}; | ||
export declare const fetchProcessing: (data: any) => any; | ||
export declare const nativeFactTypes: { | ||
@@ -23,5 +24,5 @@ Integer: { | ||
export declare const validate: { | ||
(value: any, required: true): Promise<number>; | ||
(value: any, required: true): Promise<bigint>; | ||
(value: null | undefined, required: false): Promise<null>; | ||
<U>(value: U, required: boolean): Promise<number | null>; | ||
<U>(value: U, required: boolean): Promise<bigint | null>; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validate = exports.nativeFactTypes = exports.types = void 0; | ||
exports.validate = exports.nativeFactTypes = exports.fetchProcessing = exports.types = void 0; | ||
const TypeUtils = require("../type-utils"); | ||
@@ -13,2 +13,9 @@ exports.types = { | ||
}; | ||
const fetchProcessing = (data) => { | ||
if (data == null) { | ||
return data; | ||
} | ||
return BigInt(data); | ||
}; | ||
exports.fetchProcessing = fetchProcessing; | ||
exports.nativeFactTypes = { | ||
@@ -18,3 +25,3 @@ Integer: TypeUtils.nativeFactTypeTemplates.comparison, | ||
}; | ||
exports.validate = TypeUtils.validate.integer; | ||
exports.validate = TypeUtils.validate.bigint; | ||
//# sourceMappingURL=big-integer.js.map |
@@ -12,5 +12,5 @@ import * as TypeUtils from '../type-utils'; | ||
export declare const validate: { | ||
(value: any, required: true): Promise<boolean>; | ||
(value: any, required: true): Promise<number>; | ||
(value: null | undefined, required: false): Promise<null>; | ||
<U>(value: U, required: boolean): Promise<boolean | null>; | ||
<U>(value: U, required: boolean): Promise<number | null>; | ||
}; |
@@ -5,4 +5,4 @@ "use strict"; | ||
const TypeUtils = require("../type-utils"); | ||
const typeFunc = (necessity, index, defaultValue = ' DEFAULT FALSE') => 'BOOLEAN' + defaultValue + necessity + index; | ||
typeFunc.castType = 'BOOLEAN'; | ||
const typeFunc = (necessity, index, defaultValue = ' DEFAULT 0') => 'INTEGER' + defaultValue + necessity + index; | ||
typeFunc.castType = 'INTEGER'; | ||
exports.types = { | ||
@@ -23,4 +23,4 @@ postgres: typeFunc, | ||
} | ||
return value === 1; | ||
return value; | ||
}); | ||
//# sourceMappingURL=boolean.js.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
} | ||
catch { | ||
catch (_a) { | ||
bcrypt = require('bcryptjs'); | ||
@@ -12,0 +12,0 @@ } |
@@ -6,5 +6,5 @@ "use strict"; | ||
exports.types = { | ||
postgres: 'JSONB', | ||
mysql: 'JSON', | ||
websql: 'JSON', | ||
postgres: 'TEXT', | ||
mysql: 'TEXT', | ||
websql: 'TEXT', | ||
odata: { | ||
@@ -17,9 +17,6 @@ name: 'Edm.String', | ||
exports.validate = TypeUtils.validate.checkRequired((value) => { | ||
if (typeof value !== 'object') { | ||
throw new Error(`is not an object/array: ${typeof value}`); | ||
} | ||
try { | ||
return JSON.stringify(value); | ||
} | ||
catch { | ||
catch (_a) { | ||
throw new Error('cannot be turned into JSON: ' + value); | ||
@@ -26,0 +23,0 @@ } |
@@ -14,3 +14,3 @@ "use strict"; | ||
} | ||
catch { | ||
catch (_a) { | ||
const shajs = require('sha.js'); | ||
@@ -17,0 +17,0 @@ sha256 = (value) => { |
{ | ||
"name": "@balena/sbvr-types", | ||
"version": "4.0.0-build-4-x-f4445710f9a70ae60f90494f63911989c3c8fc48-1", | ||
"version": "4.0.0-build-big-int-parsing-f52cae46de1703f88fc31a251a524dc201d34e9e-1", | ||
"description": "SBVR type definitions.", | ||
@@ -54,8 +54,5 @@ "main": "out", | ||
}, | ||
"engines": { | ||
"node": ">=16.13.0" | ||
}, | ||
"versionist": { | ||
"publishedAt": "2022-12-20T13:42:03.147Z" | ||
"publishedAt": "2023-03-17T09:28:43.091Z" | ||
} | ||
} |
import type { SbvrType } from './type-utils'; | ||
import * as BigInteger from './types/big-integer'; | ||
import * as BigSerial from './types/big-serial'; | ||
import * as Boolean from './types/boolean'; | ||
@@ -25,2 +26,3 @@ import * as CaseInsensitiveText from './types/case-insensitive-text'; | ||
'Big Integer': BigInteger, | ||
'Big Serial': BigSerial, | ||
Boolean, | ||
@@ -27,0 +29,0 @@ 'Case Insensitive Text': CaseInsensitiveText, |
@@ -61,2 +61,9 @@ export interface DatabaseTypeFn { | ||
}), | ||
bigint: checkRequired((value: any) => { | ||
if (value === '') { | ||
throw new Error('Cannot convert empty string to a BigInt'); | ||
} | ||
const processedValue = BigInt(value); | ||
return processedValue; | ||
}), | ||
text: (length?: number) => | ||
@@ -63,0 +70,0 @@ checkRequired((value: any) => { |
@@ -12,2 +12,9 @@ import * as TypeUtils from '../type-utils'; | ||
export const fetchProcessing = (data: any) => { | ||
if (data == null) { | ||
return data; | ||
} | ||
return BigInt(data); | ||
}; | ||
export const nativeFactTypes = { | ||
@@ -18,2 +25,2 @@ Integer: TypeUtils.nativeFactTypeTemplates.comparison, | ||
export const validate = TypeUtils.validate.integer; | ||
export const validate = TypeUtils.validate.bigint; |
@@ -6,5 +6,5 @@ import * as TypeUtils from '../type-utils'; | ||
index: string, | ||
defaultValue = ' DEFAULT FALSE', | ||
) => 'BOOLEAN' + defaultValue + necessity + index; | ||
typeFunc.castType = 'BOOLEAN'; | ||
defaultValue = ' DEFAULT 0', | ||
) => 'INTEGER' + defaultValue + necessity + index; | ||
typeFunc.castType = 'INTEGER'; | ||
@@ -20,3 +20,3 @@ export const types = { | ||
// `BOOLEAN` on sqlite/websql is just an alias for `INTEGER` hence the `=== 1` check | ||
// Support both `1` from the "boolean" columns that are actually INTEGER types and `true` for truly boolean results | ||
export const fetchProcessing = (data: any) => data === true || data === 1; | ||
@@ -34,3 +34,3 @@ | ||
} | ||
return value === 1; | ||
return value; | ||
}); |
import * as TypeUtils from '../type-utils'; | ||
export const types = { | ||
postgres: 'JSONB', | ||
mysql: 'JSON', | ||
websql: 'JSON', | ||
postgres: 'TEXT', | ||
mysql: 'TEXT', | ||
websql: 'TEXT', | ||
odata: { | ||
@@ -15,7 +15,2 @@ name: 'Edm.String', // TODO: What should this really be? | ||
export const validate = TypeUtils.validate.checkRequired((value) => { | ||
// Disallow primitives | ||
if (typeof value !== 'object') { | ||
throw new Error(`is not an object/array: ${typeof value}`); | ||
} | ||
try { | ||
@@ -22,0 +17,0 @@ return JSON.stringify(value); |
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2021", | ||
"target": "es2018", | ||
"strict": true, | ||
@@ -6,0 +6,0 @@ "noImplicitAny": true, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114366
97
1741