@trayio/commons 4.73.0 → 4.74.0
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as t from 'io-ts';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
import { Codec } from '../codec/Codec';
|
|
4
|
+
declare const uuidTypeDescriptor: t.BrandC<t.StringC, UuidBrand>;
|
|
5
|
+
export type Uuid = t.TypeOf<typeof uuidTypeDescriptor>;
|
|
6
|
+
export interface UuidBrand {
|
|
7
|
+
readonly Uuid: unique symbol;
|
|
8
|
+
}
|
|
9
|
+
export interface UuidInterface {
|
|
10
|
+
typeDescriptor: t.BrandC<t.StringC, UuidBrand>;
|
|
11
|
+
typeCodec: Codec<Uuid>;
|
|
12
|
+
fromString: (value: string) => E.Either<Error, Uuid>;
|
|
13
|
+
decodeBinary: (value: Uuid) => ArrayBuffer;
|
|
14
|
+
}
|
|
15
|
+
export declare const Uuid: UuidInterface;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=Uuid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uuid.d.ts","sourceRoot":"","sources":["../../src/uuid/Uuid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAC3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAQvC,QAAA,MAAM,kBAAkB,gCAIvB,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAIvD,MAAM,WAAW,SAAS;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,aAAa;IAC7B,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC/C,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IACvB,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACrD,YAAY,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,WAAW,CAAC;CAC3C;AAED,eAAO,MAAM,IAAI,EAAE,aAalB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.Uuid = void 0;
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
29
|
+
const isUuid = (s) => {
|
|
30
|
+
const exp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
31
|
+
return exp.test(s);
|
|
32
|
+
};
|
|
33
|
+
const uuidTypeDescriptor = t.brand(t.string, (input) => isUuid(input), 'Uuid');
|
|
34
|
+
const uuidTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(uuidTypeDescriptor);
|
|
35
|
+
exports.Uuid = {
|
|
36
|
+
typeDescriptor: uuidTypeDescriptor,
|
|
37
|
+
typeCodec: uuidTypeCodec,
|
|
38
|
+
fromString: (value) => uuidTypeCodec.decode(value),
|
|
39
|
+
decodeBinary: (value) => {
|
|
40
|
+
const binary = Buffer.from(uuidTypeCodec.encode(value), 'utf-8');
|
|
41
|
+
return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uuid.unit.test.d.ts","sourceRoot":"","sources":["../../src/uuid/Uuid.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const Uuid_1 = require("./Uuid");
|
|
28
|
+
describe('Uuid', () => {
|
|
29
|
+
test('should create uuid type for valid string', () => {
|
|
30
|
+
const testValue = '3fa04423-4a2c-462f-8032-8cdd6f1cd5cd';
|
|
31
|
+
const uuidResult = Uuid_1.Uuid.fromString(testValue);
|
|
32
|
+
const uuid = E.getOrElse((error) => {
|
|
33
|
+
throw new Error('This is not a valid UUID');
|
|
34
|
+
})(uuidResult);
|
|
35
|
+
expect(uuid.toString()).toStrictEqual(testValue);
|
|
36
|
+
});
|
|
37
|
+
test('should fail when string is invalid', () => {
|
|
38
|
+
const testValue = 'some-invalid-uuid';
|
|
39
|
+
const uuidResult = Uuid_1.Uuid.fromString(testValue);
|
|
40
|
+
expect(E.isLeft(uuidResult)).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|