@venizia/ignis-helpers 0.2.0-38 → 0.2.0-39
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/cjs/modules/base.d.ts +4 -1
- package/dist/cjs/modules/base.d.ts.map +1 -1
- package/dist/cjs/modules/base.js +12 -4
- package/dist/cjs/modules/base.js.map +1 -1
- package/dist/cjs/modules/logger/resolver.d.ts.map +1 -1
- package/dist/cjs/modules/logger/resolver.js +6 -0
- package/dist/cjs/modules/logger/resolver.js.map +1 -1
- package/dist/cjs/modules/logger/slot.d.ts +27 -0
- package/dist/cjs/modules/logger/slot.d.ts.map +1 -0
- package/dist/cjs/modules/logger/slot.js +68 -0
- package/dist/cjs/modules/logger/slot.js.map +1 -0
- package/dist/cjs/modules/uid/uuid/common/constants.d.ts +5 -4
- package/dist/cjs/modules/uid/uuid/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/uid/uuid/common/constants.js +5 -4
- package/dist/cjs/modules/uid/uuid/common/constants.js.map +1 -1
- package/dist/cjs/modules/uid/uuid/helper.d.ts +13 -52
- package/dist/cjs/modules/uid/uuid/helper.d.ts.map +1 -1
- package/dist/cjs/modules/uid/uuid/helper.js +17 -137
- package/dist/cjs/modules/uid/uuid/helper.js.map +1 -1
- package/dist/cjs/modules/uid/uuid/index.d.ts +2 -0
- package/dist/cjs/modules/uid/uuid/index.d.ts.map +1 -1
- package/dist/cjs/modules/uid/uuid/index.js +2 -0
- package/dist/cjs/modules/uid/uuid/index.js.map +1 -1
- package/dist/cjs/modules/uid/uuid/sha1.d.ts +7 -11
- package/dist/cjs/modules/uid/uuid/sha1.d.ts.map +1 -1
- package/dist/cjs/modules/uid/uuid/sha1.js +7 -11
- package/dist/cjs/modules/uid/uuid/sha1.js.map +1 -1
- package/dist/cjs/modules/uid/uuid/v4.d.ts +5 -0
- package/dist/cjs/modules/uid/uuid/v4.d.ts.map +1 -0
- package/dist/cjs/modules/uid/uuid/v4.js +49 -0
- package/dist/cjs/modules/uid/uuid/v4.js.map +1 -0
- package/dist/cjs/modules/uid/uuid/v5.d.ts +15 -0
- package/dist/cjs/modules/uid/uuid/v5.d.ts.map +1 -0
- package/dist/cjs/modules/uid/uuid/v5.js +84 -0
- package/dist/cjs/modules/uid/uuid/v5.js.map +1 -0
- package/dist/cjs/modules/uid/uuid/v7.d.ts +4 -36
- package/dist/cjs/modules/uid/uuid/v7.d.ts.map +1 -1
- package/dist/cjs/modules/uid/uuid/v7.js +66 -82
- package/dist/cjs/modules/uid/uuid/v7.js.map +1 -1
- package/dist/cjs/uuid.d.ts +2 -0
- package/dist/cjs/uuid.d.ts.map +1 -0
- package/dist/cjs/uuid.js +19 -0
- package/dist/cjs/uuid.js.map +1 -0
- package/dist/esm/modules/base.d.ts +4 -1
- package/dist/esm/modules/base.d.ts.map +1 -1
- package/dist/esm/modules/base.js +12 -4
- package/dist/esm/modules/base.js.map +1 -1
- package/dist/esm/modules/logger/resolver.d.ts.map +1 -1
- package/dist/esm/modules/logger/resolver.js +6 -0
- package/dist/esm/modules/logger/resolver.js.map +1 -1
- package/dist/esm/modules/logger/slot.d.ts +27 -0
- package/dist/esm/modules/logger/slot.d.ts.map +1 -0
- package/dist/esm/modules/logger/slot.js +62 -0
- package/dist/esm/modules/logger/slot.js.map +1 -0
- package/dist/esm/modules/uid/uuid/common/constants.d.ts +5 -4
- package/dist/esm/modules/uid/uuid/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/common/constants.js +5 -4
- package/dist/esm/modules/uid/uuid/common/constants.js.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.d.ts +13 -52
- package/dist/esm/modules/uid/uuid/helper.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/helper.js +17 -137
- package/dist/esm/modules/uid/uuid/helper.js.map +1 -1
- package/dist/esm/modules/uid/uuid/index.d.ts +2 -0
- package/dist/esm/modules/uid/uuid/index.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/index.js +2 -0
- package/dist/esm/modules/uid/uuid/index.js.map +1 -1
- package/dist/esm/modules/uid/uuid/sha1.d.ts +7 -11
- package/dist/esm/modules/uid/uuid/sha1.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/sha1.js +7 -11
- package/dist/esm/modules/uid/uuid/sha1.js.map +1 -1
- package/dist/esm/modules/uid/uuid/v4.d.ts +5 -0
- package/dist/esm/modules/uid/uuid/v4.d.ts.map +1 -0
- package/dist/esm/modules/uid/uuid/v4.js +45 -0
- package/dist/esm/modules/uid/uuid/v4.js.map +1 -0
- package/dist/esm/modules/uid/uuid/v5.d.ts +15 -0
- package/dist/esm/modules/uid/uuid/v5.d.ts.map +1 -0
- package/dist/esm/modules/uid/uuid/v5.js +80 -0
- package/dist/esm/modules/uid/uuid/v5.js.map +1 -0
- package/dist/esm/modules/uid/uuid/v7.d.ts +4 -36
- package/dist/esm/modules/uid/uuid/v7.d.ts.map +1 -1
- package/dist/esm/modules/uid/uuid/v7.js +64 -80
- package/dist/esm/modules/uid/uuid/v7.js.map +1 -1
- package/dist/esm/uuid.d.ts +2 -0
- package/dist/esm/uuid.d.ts.map +1 -0
- package/dist/esm/uuid.js +3 -0
- package/dist/esm/uuid.js.map +1 -0
- package/package.json +7 -1
|
@@ -2,11 +2,14 @@ import { ILogger } from './logger/common/types';
|
|
|
2
2
|
export declare class BaseHelper {
|
|
3
3
|
scope: string;
|
|
4
4
|
identifier: string;
|
|
5
|
-
logger: ILogger;
|
|
6
5
|
constructor(opts: {
|
|
7
6
|
scope: string;
|
|
8
7
|
identifier?: string;
|
|
9
8
|
});
|
|
9
|
+
/** The helper's logger, resolved on first read - a helper that never logs never builds one. */
|
|
10
|
+
get logger(): ILogger;
|
|
11
|
+
/** Installs one logger on this helper - a test spy, or a host overriding the global resolver. */
|
|
12
|
+
set logger(value: ILogger);
|
|
10
13
|
getIdentifier(): string;
|
|
11
14
|
getLogger(): ILogger;
|
|
12
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,qBAAa,UAAU;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAGxD,qBAAa,UAAU;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAKxD,+FAA+F;IAC/F,IAAI,MAAM,IAAI,OAAO,CAKpB;IAED,iGAAiG;IACjG,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAExB;IAED,aAAa;IAIb,SAAS,IAAI,OAAO;CAGrB"}
|
package/dist/cjs/modules/base.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseHelper = void 0;
|
|
4
|
-
const
|
|
4
|
+
const slot_1 = require("./logger/slot");
|
|
5
5
|
class BaseHelper {
|
|
6
6
|
constructor(opts) {
|
|
7
|
-
this.logger = resolver_1.LoggerResolver.resolve({
|
|
8
|
-
scopes: [opts.scope, opts.identifier ?? ''].filter(el => el && el.length > 0),
|
|
9
|
-
});
|
|
10
7
|
this.scope = opts.scope ?? '';
|
|
11
8
|
this.identifier = opts.identifier ?? '';
|
|
12
9
|
}
|
|
10
|
+
/** The helper's logger, resolved on first read - a helper that never logs never builds one. */
|
|
11
|
+
get logger() {
|
|
12
|
+
return (0, slot_1.resolveHelperLogger)({
|
|
13
|
+
helper: this,
|
|
14
|
+
scopes: [this.scope, this.identifier].filter(scope => scope && scope.length > 0),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** Installs one logger on this helper - a test spy, or a host overriding the global resolver. */
|
|
18
|
+
set logger(value) {
|
|
19
|
+
(0, slot_1.setHelperLogger)({ helper: this, logger: value });
|
|
20
|
+
}
|
|
13
21
|
getIdentifier() {
|
|
14
22
|
return this.identifier;
|
|
15
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/modules/base.ts"],"names":[],"mappings":";;;AACA,gDAA6E;AAE7E,MAAa,UAAU;IAIrB,YAAY,IAA4C;QACtD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED,+FAA+F;IAC/F,IAAI,MAAM;QACR,OAAO,IAAA,0BAAmB,EAAC;YACzB,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;SACjF,CAAC,CAAC;IACL,CAAC;IAED,iGAAiG;IACjG,IAAI,MAAM,CAAC,KAAc;QACvB,IAAA,sBAAe,EAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACnD,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AA7BD,gCA6BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAa,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAa,MAAM,gBAAgB,CAAC;AAGpD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAK,OAAO,CAAC;AAoD3E,4JAA4J;AAC5J,qBAAa,cAAc;IACzB,2FAA2F;IAC3F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAIrC;IAEF,OAAO,CAAC,MAAM,CAAC,MAAM,CAAyC;IAC9D,OAAO,CAAC,MAAM,CAAC,UAAU,CAAK;IAE9B,kNAAkN;IAClN,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,eAAe,CAAA;KAAE,GAAG,IAAI;IAKrD,MAAM,CAAC,KAAK,IAAI,IAAI;IAKpB,wGAAwG;IACxG,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAIlC,kFAAkF;IAClF,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO;IAI3D;;;;OAIG;IACH,MAAM,CAAC,uBAAuB,IAAI,IAAI;IAetC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO;IAIxD,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAS;CACjD"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LoggerResolver = void 0;
|
|
4
4
|
const abstract_1 = require("./base/abstract");
|
|
5
5
|
const console_1 = require("./base/console");
|
|
6
|
+
const slot_1 = require("./slot");
|
|
6
7
|
/** Caches the resolved target and re-reads it only when `LoggerResolver`'s generation moves - one integer compare per call, so an instance built before `LoggerFactory` loaded upgrades the moment it does, without being reconstructed. Mutual reference with LoggerResolver is by design - hence the `no-use-before-define` disables. */
|
|
7
8
|
class ResolvedLogger extends abstract_1.AbstractLogger {
|
|
8
9
|
constructor(scopes) {
|
|
@@ -90,4 +91,9 @@ class LoggerResolver {
|
|
|
90
91
|
static { this.hasWarnedConsoleFallback = false; }
|
|
91
92
|
}
|
|
92
93
|
exports.LoggerResolver = LoggerResolver;
|
|
94
|
+
// Registers the real resolver with the slot `BaseHelper` reads. Importing this module - which any
|
|
95
|
+
// graph carrying `LoggerFactory` does - is what upgrades every helper from the console fallback,
|
|
96
|
+
// including helpers constructed before it loaded: the logger is resolved on first use, not in the
|
|
97
|
+
// constructor.
|
|
98
|
+
slot_1.loggerSlot.resolve = opts => LoggerResolver.resolve({ scopes: opts.scopes });
|
|
93
99
|
//# sourceMappingURL=resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAA+C;
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../../src/modules/logger/resolver.ts"],"names":[],"mappings":";;;AACA,8CAAiD;AACjD,4CAA+C;AAE/C,iCAAoC;AAIpC,2UAA2U;AAC3U,MAAM,cAAe,SAAQ,yBAAc;IAIzC,YAA6B,MAAqB;QAChD,KAAK,EAAE,CAAC;QADmB,WAAM,GAAN,MAAM,CAAe;QAF1C,qBAAgB,GAAG,CAAC,CAAC,CAAC;IAI9B,CAAC;IAEO,aAAa;QACnB,mEAAmE;QACnE,MAAM,UAAU,GAAG,cAAc,CAAC,iBAAiB,EAAE,CAAC;QACtD,IAAI,CAAC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AAI,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QAED,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC;QACrC,uBAAa,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CACpD,mSAAmS,CACpS,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,OAAO,CAAC,IAA+B;QAC5C,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;aAEc,6BAAwB,GAAG,KAAK,CAAC;;AAxDlD,wCAyDC;AAED,kGAAkG;AAClG,iGAAiG;AACjG,kGAAkG;AAClG,eAAe;AACf,iBAAU,CAAC,OAAO,GAAG,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ILogger } from './common/types';
|
|
2
|
+
export type TLoggerResolver = (opts: {
|
|
3
|
+
scopes: Array<string>;
|
|
4
|
+
}) => ILogger;
|
|
5
|
+
/**
|
|
6
|
+
* Where the logger module installs its resolver, and the only reference `BaseHelper` holds to it.
|
|
7
|
+
*
|
|
8
|
+
* A slot rather than an import: `BaseHelper` sits under every class in the framework, so importing
|
|
9
|
+
* the resolver put 1033 B gzipped into every browser bundle that touched any helper.
|
|
10
|
+
*/
|
|
11
|
+
export declare const loggerSlot: {
|
|
12
|
+
resolve?: TLoggerResolver;
|
|
13
|
+
};
|
|
14
|
+
/** What a helper logs through when nothing installed a resolver: the console, tagged with its scope. */
|
|
15
|
+
export declare const consoleFallbackLogger: (opts: {
|
|
16
|
+
scopes: Array<string>;
|
|
17
|
+
}) => ILogger;
|
|
18
|
+
/** Resolves a helper's logger on first read and caches it. */
|
|
19
|
+
export declare const resolveHelperLogger: (opts: {
|
|
20
|
+
helper: object;
|
|
21
|
+
scopes: Array<string>;
|
|
22
|
+
}) => ILogger;
|
|
23
|
+
export declare const setHelperLogger: (opts: {
|
|
24
|
+
helper: object;
|
|
25
|
+
logger: ILogger;
|
|
26
|
+
}) => void;
|
|
27
|
+
//# sourceMappingURL=slot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.d.ts","sourceRoot":"","sources":["../../../../src/modules/logger/slot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAa,MAAM,gBAAgB,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAK,OAAO,CAAC;AAE3E;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE;IAAE,OAAO,CAAC,EAAE,eAAe,CAAA;CAAO,CAAC;AAgC5D,wGAAwG;AACxG,eAAO,MAAM,qBAAqB,GAAI,MAAM;IAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAG,OAmBvE,CAAC;AAKF,8DAA8D;AAC9D,eAAO,MAAM,mBAAmB,GAAI,MAAM;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAAE,KAAG,OAWrF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,MAAM;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,KAAG,IAE3E,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setHelperLogger = exports.resolveHelperLogger = exports.consoleFallbackLogger = exports.loggerSlot = void 0;
|
|
4
|
+
const types_1 = require("./common/types");
|
|
5
|
+
/**
|
|
6
|
+
* Where the logger module installs its resolver, and the only reference `BaseHelper` holds to it.
|
|
7
|
+
*
|
|
8
|
+
* A slot rather than an import: `BaseHelper` sits under every class in the framework, so importing
|
|
9
|
+
* the resolver put 1033 B gzipped into every browser bundle that touched any helper.
|
|
10
|
+
*/
|
|
11
|
+
exports.loggerSlot = {};
|
|
12
|
+
/** Writes one line to the console; `emerg` and anything unrecognised land on `error`. */
|
|
13
|
+
const writeToConsole = (opts) => {
|
|
14
|
+
const { prefix, level, message, args } = opts;
|
|
15
|
+
const line = `${prefix} ${message}`;
|
|
16
|
+
switch (level) {
|
|
17
|
+
case types_1.LogLevels.DEBUG: {
|
|
18
|
+
globalThis.console.debug(line, ...args);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case types_1.LogLevels.INFO: {
|
|
22
|
+
globalThis.console.info(line, ...args);
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
case types_1.LogLevels.WARN: {
|
|
26
|
+
globalThis.console.warn(line, ...args);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
default: {
|
|
30
|
+
globalThis.console.error(line, ...args);
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/** What a helper logs through when nothing installed a resolver: the console, tagged with its scope. */
|
|
36
|
+
const consoleFallbackLogger = (opts) => {
|
|
37
|
+
const { scopes } = opts;
|
|
38
|
+
const prefix = `[${scopes.filter(scope => scope && scope.length > 0).join('-')}]`;
|
|
39
|
+
return {
|
|
40
|
+
debug: (message, ...args) => writeToConsole({ prefix, level: types_1.LogLevels.DEBUG, message, args }),
|
|
41
|
+
info: (message, ...args) => writeToConsole({ prefix, level: types_1.LogLevels.INFO, message, args }),
|
|
42
|
+
warn: (message, ...args) => writeToConsole({ prefix, level: types_1.LogLevels.WARN, message, args }),
|
|
43
|
+
error: (message, ...args) => writeToConsole({ prefix, level: types_1.LogLevels.ERROR, message, args }),
|
|
44
|
+
emerg: (message, ...args) => writeToConsole({ prefix, level: types_1.LogLevels.EMERG, message, args }),
|
|
45
|
+
log: (level, message, ...args) => writeToConsole({ prefix, level, message, args }),
|
|
46
|
+
for: (methodName) => (0, exports.consoleFallbackLogger)({ scopes: [...scopes, methodName] }),
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.consoleFallbackLogger = consoleFallbackLogger;
|
|
50
|
+
/** One logger per helper. A `WeakMap`, not a field: a mixin's anonymous class cannot emit a private member (TS4094). */
|
|
51
|
+
const loggerByHelper = new WeakMap();
|
|
52
|
+
/** Resolves a helper's logger on first read and caches it. */
|
|
53
|
+
const resolveHelperLogger = (opts) => {
|
|
54
|
+
const { helper, scopes } = opts;
|
|
55
|
+
const cached = loggerByHelper.get(helper);
|
|
56
|
+
if (cached) {
|
|
57
|
+
return cached;
|
|
58
|
+
}
|
|
59
|
+
const resolved = (exports.loggerSlot.resolve ?? exports.consoleFallbackLogger)({ scopes });
|
|
60
|
+
loggerByHelper.set(helper, resolved);
|
|
61
|
+
return resolved;
|
|
62
|
+
};
|
|
63
|
+
exports.resolveHelperLogger = resolveHelperLogger;
|
|
64
|
+
const setHelperLogger = (opts) => {
|
|
65
|
+
loggerByHelper.set(opts.helper, opts.logger);
|
|
66
|
+
};
|
|
67
|
+
exports.setHelperLogger = setHelperLogger;
|
|
68
|
+
//# sourceMappingURL=slot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slot.js","sourceRoot":"","sources":["../../../../src/modules/logger/slot.ts"],"names":[],"mappings":";;;AACA,0CAA2C;AAK3C;;;;;GAKG;AACU,QAAA,UAAU,GAAkC,EAAE,CAAC;AAE5D,yFAAyF;AACzF,MAAM,cAAc,GAAG,CAAC,IAKvB,EAAQ,EAAE;IACT,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC9C,MAAM,IAAI,GAAG,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;IAEpC,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,iBAAS,CAAC,KAAK,CAAC,CA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;IAC3E,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAXW,QAAA,mBAAmB,uBAW9B;AAEK,MAAM,eAAe,GAAG,CAAC,IAAyC,EAAQ,EAAE;IACjF,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;AAC/C,CAAC,CAAC;AAFW,QAAA,eAAe,mBAE1B"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The four namespaces RFC 9562 names. A namespace
|
|
3
|
-
* `name` under two namespaces answers two ids
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* The four namespaces RFC 9562 names. A namespace partitions the deterministic space, so one
|
|
3
|
+
* `name` under two namespaces answers two ids.
|
|
4
|
+
*
|
|
5
|
+
* Need your own? Mint it ONCE (`bun -e "console.log(crypto.randomUUID())"`) and pin it as a
|
|
6
|
+
* constant. Generating one at runtime makes `uuidV5` answer a different id every call, silently.
|
|
6
7
|
*/
|
|
7
8
|
export declare class UuidNamespaces {
|
|
8
9
|
/** Fully-qualified domain names. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/uid/uuid/common/constants.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/uid/uuid/common/constants.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,qBAAa,cAAc;IACzB,oCAAoC;IACpC,MAAM,CAAC,QAAQ,CAAC,GAAG,0CAA0C;IAE7D,4FAA4F;IAC5F,MAAM,CAAC,QAAQ,CAAC,GAAG,0CAA0C;IAE7D,8BAA8B;IAC9B,MAAM,CAAC,QAAQ,CAAC,GAAG,0CAA0C;IAE7D,iCAAiC;IACjC,MAAM,CAAC,QAAQ,CAAC,IAAI,0CAA0C;CAC/D;AAED,2FAA2F;AAC3F,eAAO,MAAM,eAAe,UAE3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,YAAY,QACoD,CAAC;AAE9E,2KAA2K;AAC3K,eAAO,MAAM,qBAAqB,KAAK,CAAC"}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MAX_CACHED_NAMESPACES = exports.UUID_PATTERN = exports.UUID_HEX_OCTETS = exports.UuidNamespaces = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* The four namespaces RFC 9562 names. A namespace
|
|
6
|
-
* `name` under two namespaces answers two ids
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* The four namespaces RFC 9562 names. A namespace partitions the deterministic space, so one
|
|
6
|
+
* `name` under two namespaces answers two ids.
|
|
7
|
+
*
|
|
8
|
+
* Need your own? Mint it ONCE (`bun -e "console.log(crypto.randomUUID())"`) and pin it as a
|
|
9
|
+
* constant. Generating one at runtime makes `uuidV5` answer a different id every call, silently.
|
|
9
10
|
*/
|
|
10
11
|
class UuidNamespaces {
|
|
11
12
|
/** Fully-qualified domain names. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/uid/uuid/common/constants.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/uid/uuid/common/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,cAAc;IACzB,oCAAoC;aACpB,QAAG,GAAG,sCAAsC,CAAC;IAE7D,4FAA4F;aAC5E,QAAG,GAAG,sCAAsC,CAAC;IAE7D,8BAA8B;aACd,QAAG,GAAG,sCAAsC,CAAC;IAE7D,iCAAiC;aACjB,SAAI,GAAG,sCAAsC,CAAC;;AAXhE,wCAYC;AAED,2FAA2F;AAC9E,QAAA,eAAe,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CACtE,CAAC,KAAK,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CACtC,CAAC;AAEF;;;GAGG;AACU,QAAA,YAAY,GACvB,2EAA2E,CAAC;AAE9E,2KAA2K;AAC9J,QAAA,qBAAqB,GAAG,EAAE,CAAC"}
|
|
@@ -1,72 +1,33 @@
|
|
|
1
1
|
import { BaseHelper } from '../../base';
|
|
2
2
|
import type { IUuidInspection } from './common/types';
|
|
3
3
|
/**
|
|
4
|
-
* One door for every UUID IGNIS mints
|
|
5
|
-
*
|
|
4
|
+
* One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,
|
|
5
|
+
* `v4()` for a random token.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* - `v5()` - a deterministic key from business data (an idempotency key). The same inputs always
|
|
10
|
-
* answer the same id, which is the point and also the limit: anyone holding the inputs can
|
|
11
|
-
* reproduce it, so it is never a secret. It gives a STABLE key; the unique index on the column is
|
|
12
|
-
* what actually enforces idempotency.
|
|
13
|
-
* - `v4()` - a random public identifier or token. No clock, nothing to correlate, 122 random bits.
|
|
14
|
-
*
|
|
15
|
-
* `crypto.randomUUID` is used when the host has it, and rebuilt from `getRandomValues` when it does
|
|
16
|
-
* not: browsers gate that one API on a SECURE CONTEXT, and on `http://<lan-ip>` it is simply
|
|
17
|
-
* missing (see {@link RequestIdGenerator} for the measurement).
|
|
7
|
+
* A facade over {@link uuidV4}, {@link uuidV5} and {@link uuidV7} - importing one of those from
|
|
8
|
+
* `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.
|
|
18
9
|
*/
|
|
19
10
|
export declare class UuidHelper extends BaseHelper {
|
|
20
11
|
/** Realm-keyed: a dual CJS+ESM build puts two copies of this class in one process. */
|
|
21
12
|
private static readonly SHARED_SLOT;
|
|
22
|
-
/**
|
|
23
|
-
private static readonly V5_INPUT_SIZE;
|
|
24
|
-
/** 256 ids of entropy per `getRandomValues` call. */
|
|
25
|
-
private static readonly POOL_SIZE;
|
|
26
|
-
private readonly v7Generator;
|
|
27
|
-
/**
|
|
28
|
-
* Random - a public identifier or a token.
|
|
29
|
-
*
|
|
30
|
-
* A bound function, not a method: one `crypto.randomUUID` costs ~32 ns, and a method forwarding
|
|
31
|
-
* to it measured 40 ns. The wrapper was a fifth of the cost, so there is no wrapper.
|
|
32
|
-
*/
|
|
13
|
+
/** Random - a public identifier or a token. */
|
|
33
14
|
readonly v4: () => string;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* millisecond per 4096 ids. `inspect()` reports what the id carries, which is why a creation time
|
|
41
|
-
* read back inside a burst can sit a few milliseconds in the future.
|
|
42
|
-
*/
|
|
15
|
+
/** Deterministic - same inputs, same id. Reproducible therefore not secret. */
|
|
16
|
+
readonly v5: (opts: {
|
|
17
|
+
namespace: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}) => string;
|
|
20
|
+
/** Time-ordered - a database key. A burst past 4096 ids per millisecond leads the wall clock. */
|
|
43
21
|
readonly v7: () => string;
|
|
44
|
-
private readonly encoder;
|
|
45
|
-
/** Parsed namespace bytes: an idempotency key reuses one namespace for every call, and parsing 36 characters each time is work already done. */
|
|
46
|
-
private readonly namespaces;
|
|
47
|
-
private readonly pool;
|
|
48
|
-
private offset;
|
|
49
|
-
/** `namespace | name` for `v5`, grown only when a name outruns it. {@link v5Name} views the name half. */
|
|
50
|
-
private v5Input;
|
|
51
|
-
private v5Name;
|
|
52
22
|
constructor(opts?: {
|
|
53
23
|
scope?: string;
|
|
54
24
|
});
|
|
55
25
|
static getInstance(): UuidHelper;
|
|
56
|
-
/** Lowercase, version 1-8, RFC variant
|
|
26
|
+
/** Lowercase, version 1-8, RFC variant - the nil and max placeholders are refused. */
|
|
57
27
|
static isValid(value: string): boolean;
|
|
58
|
-
/**
|
|
59
|
-
v5(opts: {
|
|
60
|
-
namespace: string;
|
|
61
|
-
name: string;
|
|
62
|
-
}): string;
|
|
63
|
-
/** What the id says about itself, or undefined when it is not a UUID. A v7 id also carries the moment it was minted. */
|
|
28
|
+
/** Reads the version, and for v7 the creation time; undefined when it is not a UUID. */
|
|
64
29
|
inspect(opts: {
|
|
65
30
|
value: string;
|
|
66
31
|
}): IUuidInspection | undefined;
|
|
67
|
-
private resolveNamespace;
|
|
68
|
-
/** Reads the pool in place: a `subarray` view per id measured 19 ns, more than the entropy costs. */
|
|
69
|
-
private v4FromPool;
|
|
70
|
-
private format;
|
|
71
32
|
}
|
|
72
33
|
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,UAAU;IACxC,sFAAsF;IACtF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAoD;IAEvF,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAAU;IAEnC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAU;IAE5E,iGAAiG;IACjG,QAAQ,CAAC,EAAE,EAAE,MAAM,MAAM,CAAU;gBAEvB,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IAIrC,MAAM,CAAC,WAAW,IAAI,UAAU;IAWhC,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAItC,wFAAwF;IACxF,OAAO,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,eAAe,GAAG,SAAS;CAe9D"}
|
|
@@ -1,52 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UuidHelper = void 0;
|
|
4
|
-
const constants_1 = require("../../../common/constants");
|
|
5
4
|
const base_1 = require("../../base");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
5
|
+
const constants_1 = require("./common/constants");
|
|
6
|
+
const v4_1 = require("./v4");
|
|
7
|
+
const v5_1 = require("./v5");
|
|
9
8
|
const v7_1 = require("./v7");
|
|
10
9
|
/**
|
|
11
|
-
* One door for every UUID IGNIS mints
|
|
12
|
-
*
|
|
10
|
+
* One door for every UUID IGNIS mints: `v7()` for a database key, `v5()` for a deterministic key,
|
|
11
|
+
* `v4()` for a random token.
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `v5()` - a deterministic key from business data (an idempotency key). The same inputs always
|
|
17
|
-
* answer the same id, which is the point and also the limit: anyone holding the inputs can
|
|
18
|
-
* reproduce it, so it is never a secret. It gives a STABLE key; the unique index on the column is
|
|
19
|
-
* what actually enforces idempotency.
|
|
20
|
-
* - `v4()` - a random public identifier or token. No clock, nothing to correlate, 122 random bits.
|
|
21
|
-
*
|
|
22
|
-
* `crypto.randomUUID` is used when the host has it, and rebuilt from `getRandomValues` when it does
|
|
23
|
-
* not: browsers gate that one API on a SECURE CONTEXT, and on `http://<lan-ip>` it is simply
|
|
24
|
-
* missing (see {@link RequestIdGenerator} for the measurement).
|
|
13
|
+
* A facade over {@link uuidV4}, {@link uuidV5} and {@link uuidV7} - importing one of those from
|
|
14
|
+
* `@venizia/ignis-helpers/uuid` leaves the other two out of a browser bundle.
|
|
25
15
|
*/
|
|
26
16
|
class UuidHelper extends base_1.BaseHelper {
|
|
27
17
|
/** Realm-keyed: a dual CJS+ESM build puts two copies of this class in one process. */
|
|
28
18
|
static { this.SHARED_SLOT = Symbol.for('@venizia/ignis-helpers:uuid-helper'); }
|
|
29
|
-
/** Fits a namespace plus a ~160-character name without growing; longer names reallocate once. */
|
|
30
|
-
static { this.V5_INPUT_SIZE = 512; }
|
|
31
|
-
/** 256 ids of entropy per `getRandomValues` call. */
|
|
32
|
-
static { this.POOL_SIZE = 16 * 256; }
|
|
33
19
|
constructor(opts) {
|
|
34
20
|
super({ scope: opts?.scope ?? UuidHelper.name });
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
/**
|
|
38
|
-
this.
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
/** `namespace | name` for `v5`, grown only when a name outruns it. {@link v5Name} views the name half. */
|
|
42
|
-
this.v5Input = new Uint8Array(UuidHelper.V5_INPUT_SIZE);
|
|
43
|
-
this.v5Name = this.v5Input.subarray(16);
|
|
44
|
-
// Resolved once: whether a host exposes `randomUUID` is fixed for the life of a realm. Bound,
|
|
45
|
-
// not wrapped - the extra call frame measured 8 ns on every id.
|
|
46
|
-
const native = globalThis.crypto?.randomUUID;
|
|
47
|
-
this.v4 =
|
|
48
|
-
typeof native === 'function' ? native.bind(globalThis.crypto) : () => this.v4FromPool();
|
|
49
|
-
this.v7 = this.v7Generator.nextId;
|
|
21
|
+
/** Random - a public identifier or a token. */
|
|
22
|
+
this.v4 = v4_1.uuidV4;
|
|
23
|
+
/** Deterministic - same inputs, same id. Reproducible therefore not secret. */
|
|
24
|
+
this.v5 = v5_1.uuidV5;
|
|
25
|
+
/** Time-ordered - a database key. A burst past 4096 ids per millisecond leads the wall clock. */
|
|
26
|
+
this.v7 = v7_1.uuidV7;
|
|
50
27
|
}
|
|
51
28
|
static getInstance() {
|
|
52
29
|
const shared = Reflect.get(globalThis, UuidHelper.SHARED_SLOT);
|
|
@@ -57,32 +34,14 @@ class UuidHelper extends base_1.BaseHelper {
|
|
|
57
34
|
Reflect.set(globalThis, UuidHelper.SHARED_SLOT, created);
|
|
58
35
|
return created;
|
|
59
36
|
}
|
|
60
|
-
/** Lowercase, version 1-8, RFC variant
|
|
37
|
+
/** Lowercase, version 1-8, RFC variant - the nil and max placeholders are refused. */
|
|
61
38
|
static isValid(value) {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
/** Deterministic - `SHA-1(namespace + name)`. The same inputs answer the same id, forever, on every host. */
|
|
65
|
-
v5(opts) {
|
|
66
|
-
const { namespace, name } = opts;
|
|
67
|
-
const namespaceBytes = this.resolveNamespace({ namespace });
|
|
68
|
-
// Encoded straight into the scratch buffer behind the namespace: `encode()` would allocate an
|
|
69
|
-
// array per call only to copy it. UTF-8 never exceeds 3 bytes per UTF-16 code unit.
|
|
70
|
-
const required = 16 + name.length * 3;
|
|
71
|
-
if (required > this.v5Input.length) {
|
|
72
|
-
this.v5Input = new Uint8Array(required);
|
|
73
|
-
this.v5Name = this.v5Input.subarray(16);
|
|
74
|
-
}
|
|
75
|
-
this.v5Input.set(namespaceBytes);
|
|
76
|
-
const { written } = this.encoder.encodeInto(name, this.v5Name);
|
|
77
|
-
const digest = sha1_1.Sha1Digest.of({ bytes: this.v5Input.subarray(0, 16 + written) });
|
|
78
|
-
digest[6] = (digest[6] & 0x0f) | 0x50;
|
|
79
|
-
digest[8] = (digest[8] & 0x3f) | 0x80;
|
|
80
|
-
return this.format({ bytes: digest });
|
|
39
|
+
return constants_1.UUID_PATTERN.test(value);
|
|
81
40
|
}
|
|
82
|
-
/**
|
|
41
|
+
/** Reads the version, and for v7 the creation time; undefined when it is not a UUID. */
|
|
83
42
|
inspect(opts) {
|
|
84
43
|
const { value } = opts;
|
|
85
|
-
if (!
|
|
44
|
+
if (!constants_1.UUID_PATTERN.test(value)) {
|
|
86
45
|
return undefined;
|
|
87
46
|
}
|
|
88
47
|
const version = Number.parseInt(value[14], 16);
|
|
@@ -92,85 +51,6 @@ class UuidHelper extends base_1.BaseHelper {
|
|
|
92
51
|
const milliseconds = Number.parseInt(value.slice(0, 8) + value.slice(9, 13), 16);
|
|
93
52
|
return { version, createdAt: new Date(milliseconds) };
|
|
94
53
|
}
|
|
95
|
-
resolveNamespace(opts) {
|
|
96
|
-
const { namespace } = opts;
|
|
97
|
-
const cached = this.namespaces.get(namespace);
|
|
98
|
-
if (cached) {
|
|
99
|
-
return cached;
|
|
100
|
-
}
|
|
101
|
-
if (!UuidHelper.isValid(namespace)) {
|
|
102
|
-
throw (0, error_1.getError)({
|
|
103
|
-
statusCode: constants_1.HTTP.ResultCodes.RS_5.InternalServerError,
|
|
104
|
-
message: `[${UuidHelper.name}][v5] namespace must be a UUID - received: ${namespace}`,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const bytes = new Uint8Array(16);
|
|
108
|
-
const hex = namespace.replaceAll('-', '');
|
|
109
|
-
for (let index = 0; index < 16; index++) {
|
|
110
|
-
bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
111
|
-
}
|
|
112
|
-
if (this.namespaces.size < constants_2.MAX_CACHED_NAMESPACES) {
|
|
113
|
-
this.namespaces.set(namespace, bytes);
|
|
114
|
-
}
|
|
115
|
-
return bytes;
|
|
116
|
-
}
|
|
117
|
-
/** Reads the pool in place: a `subarray` view per id measured 19 ns, more than the entropy costs. */
|
|
118
|
-
v4FromPool() {
|
|
119
|
-
if (this.offset > UuidHelper.POOL_SIZE - 16) {
|
|
120
|
-
globalThis.crypto.getRandomValues(this.pool);
|
|
121
|
-
this.offset = 0;
|
|
122
|
-
}
|
|
123
|
-
const pool = this.pool;
|
|
124
|
-
const at = this.offset;
|
|
125
|
-
this.offset = at + 16;
|
|
126
|
-
const version = (pool[at + 6] & 0x0f) | 0x40;
|
|
127
|
-
const variant = (pool[at + 8] & 0x3f) | 0x80;
|
|
128
|
-
const hex = constants_2.UUID_HEX_OCTETS;
|
|
129
|
-
return (hex[pool[at]] +
|
|
130
|
-
hex[pool[at + 1]] +
|
|
131
|
-
hex[pool[at + 2]] +
|
|
132
|
-
hex[pool[at + 3]] +
|
|
133
|
-
'-' +
|
|
134
|
-
hex[pool[at + 4]] +
|
|
135
|
-
hex[pool[at + 5]] +
|
|
136
|
-
'-' +
|
|
137
|
-
hex[version] +
|
|
138
|
-
hex[pool[at + 7]] +
|
|
139
|
-
'-' +
|
|
140
|
-
hex[variant] +
|
|
141
|
-
hex[pool[at + 9]] +
|
|
142
|
-
'-' +
|
|
143
|
-
hex[pool[at + 10]] +
|
|
144
|
-
hex[pool[at + 11]] +
|
|
145
|
-
hex[pool[at + 12]] +
|
|
146
|
-
hex[pool[at + 13]] +
|
|
147
|
-
hex[pool[at + 14]] +
|
|
148
|
-
hex[pool[at + 15]]);
|
|
149
|
-
}
|
|
150
|
-
format(opts) {
|
|
151
|
-
const { bytes } = opts;
|
|
152
|
-
const hex = constants_2.UUID_HEX_OCTETS;
|
|
153
|
-
return (hex[bytes[0]] +
|
|
154
|
-
hex[bytes[1]] +
|
|
155
|
-
hex[bytes[2]] +
|
|
156
|
-
hex[bytes[3]] +
|
|
157
|
-
'-' +
|
|
158
|
-
hex[bytes[4]] +
|
|
159
|
-
hex[bytes[5]] +
|
|
160
|
-
'-' +
|
|
161
|
-
hex[bytes[6]] +
|
|
162
|
-
hex[bytes[7]] +
|
|
163
|
-
'-' +
|
|
164
|
-
hex[bytes[8]] +
|
|
165
|
-
hex[bytes[9]] +
|
|
166
|
-
'-' +
|
|
167
|
-
hex[bytes[10]] +
|
|
168
|
-
hex[bytes[11]] +
|
|
169
|
-
hex[bytes[12]] +
|
|
170
|
-
hex[bytes[13]] +
|
|
171
|
-
hex[bytes[14]] +
|
|
172
|
-
hex[bytes[15]]);
|
|
173
|
-
}
|
|
174
54
|
}
|
|
175
55
|
exports.UuidHelper = UuidHelper;
|
|
176
56
|
//# sourceMappingURL=helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/helper.ts"],"names":[],"mappings":";;;AAAA,qCAAwC;AACxC,kDAAkD;AAElD,6BAA8B;AAC9B,6BAA8B;AAC9B,6BAA8B;AAE9B;;;;;;GAMG;AACH,MAAa,UAAW,SAAQ,iBAAU;IACxC,sFAAsF;aAC9D,gBAAW,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,AAAnD,CAAoD;IAWvF,YAAY,IAAyB;QACnC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QAVnD,+CAA+C;QACtC,OAAE,GAAiB,WAAM,CAAC;QAEnC,+EAA+E;QACtE,OAAE,GAA0D,WAAM,CAAC;QAE5E,iGAAiG;QACxF,OAAE,GAAiB,WAAM,CAAC;IAInC,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,MAAM,MAAM,GAA2B,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;QACvF,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC;QACjC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QACzD,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,wFAAwF;IACxF,OAAO,CAAC,IAAuB;QAC7B,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;QAEvB,IAAI,CAAC,wBAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;YAClB,OAAO,EAAE,OAAO,EAAE,CAAC;QACrB,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QACjF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;IACxD,CAAC;;AAhDH,gCAiDC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,MAAM,CAAC;AACrB,cAAc,MAAM,CAAC;AACrB,cAAc,MAAM,CAAC"}
|
|
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
18
|
__exportStar(require("./helper"), exports);
|
|
19
|
+
__exportStar(require("./v4"), exports);
|
|
20
|
+
__exportStar(require("./v5"), exports);
|
|
19
21
|
__exportStar(require("./v7"), exports);
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,uCAAqB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/uid/uuid/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,2CAAyB;AACzB,uCAAqB;AACrB,uCAAqB;AACrB,uCAAqB"}
|