@trayio/commons 4.78.0 → 4.80.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.
package/dist/uuid/Uuid.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export interface UuidInterface {
|
|
|
10
10
|
typeDescriptor: t.BrandC<t.StringC, UuidBrand>;
|
|
11
11
|
typeCodec: Codec<Uuid>;
|
|
12
12
|
fromString: (value: string) => E.Either<Error, Uuid>;
|
|
13
|
+
parseUuidUnsafe: (value: string) => Uuid;
|
|
13
14
|
decodeBinary: (value: Uuid) => ArrayBuffer;
|
|
15
|
+
randomUuid: () => Uuid;
|
|
14
16
|
}
|
|
15
17
|
export declare const Uuid: UuidInterface;
|
|
16
18
|
export {};
|
package/dist/uuid/Uuid.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAElC,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,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,CAAC,KAAK,EAAE,IAAI,KAAK,WAAW,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,eAAO,MAAM,IAAI,EAAE,aAoBlB,CAAC"}
|
package/dist/uuid/Uuid.js
CHANGED
|
@@ -25,6 +25,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Uuid = void 0;
|
|
27
27
|
const t = __importStar(require("io-ts"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
+
const crypto_1 = require("crypto");
|
|
28
30
|
const TypeCodec_1 = require("../codec/TypeCodec");
|
|
29
31
|
const isUuid = (s) => {
|
|
30
32
|
const exp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -36,8 +38,15 @@ exports.Uuid = {
|
|
|
36
38
|
typeDescriptor: uuidTypeDescriptor,
|
|
37
39
|
typeCodec: uuidTypeCodec,
|
|
38
40
|
fromString: (value) => uuidTypeCodec.decode(value),
|
|
41
|
+
parseUuidUnsafe: (value) => {
|
|
42
|
+
const either = uuidTypeCodec.decode(value);
|
|
43
|
+
return E.getOrElse(() => {
|
|
44
|
+
throw new Error('String could not be parsed to Uuid');
|
|
45
|
+
})(either);
|
|
46
|
+
},
|
|
39
47
|
decodeBinary: (value) => {
|
|
40
48
|
const binary = Buffer.from(uuidTypeCodec.encode(value), 'utf-8');
|
|
41
49
|
return binary.buffer.slice(binary.byteOffset, binary.byteOffset + binary.byteLength);
|
|
42
50
|
},
|
|
51
|
+
randomUuid: () => exports.Uuid.parseUuidUnsafe((0, crypto_1.randomUUID)()),
|
|
43
52
|
};
|
|
@@ -39,4 +39,9 @@ describe('Uuid', () => {
|
|
|
39
39
|
const uuidResult = Uuid_1.Uuid.fromString(testValue);
|
|
40
40
|
expect(E.isLeft(uuidResult)).toBe(true);
|
|
41
41
|
});
|
|
42
|
+
test('should generate a random and unique UUIDs', () => {
|
|
43
|
+
const uuids = [...Array(20).keys()].map(() => Uuid_1.Uuid.randomUuid());
|
|
44
|
+
const uuidsSet = new Set(uuids.map((uuid) => uuid.toString()));
|
|
45
|
+
expect(uuidsSet.size).toBe(uuids.length);
|
|
46
|
+
});
|
|
42
47
|
});
|