@did-btcr2/common 2.2.1 → 3.0.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/cjs/canonicalization.js +66 -54
- package/dist/cjs/canonicalization.js.map +1 -1
- package/dist/cjs/constants.js +28 -24
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.js +5 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/json-patch.js +98 -0
- package/dist/cjs/json-patch.js.map +1 -0
- package/dist/cjs/logger.js +46 -12
- package/dist/cjs/logger.js.map +1 -1
- package/dist/cjs/utils/date.js +32 -0
- package/dist/cjs/utils/date.js.map +1 -0
- package/dist/cjs/utils/json.js +280 -0
- package/dist/cjs/utils/json.js.map +1 -0
- package/dist/cjs/utils/set.js +23 -0
- package/dist/cjs/utils/set.js.map +1 -0
- package/dist/cjs/utils/string.js +55 -0
- package/dist/cjs/utils/string.js.map +1 -0
- package/dist/esm/canonicalization.js +66 -54
- package/dist/esm/canonicalization.js.map +1 -1
- package/dist/esm/constants.js +28 -24
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.js +5 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-patch.js +98 -0
- package/dist/esm/json-patch.js.map +1 -0
- package/dist/esm/logger.js +46 -12
- package/dist/esm/logger.js.map +1 -1
- package/dist/esm/utils/date.js +32 -0
- package/dist/esm/utils/date.js.map +1 -0
- package/dist/esm/utils/json.js +280 -0
- package/dist/esm/utils/json.js.map +1 -0
- package/dist/esm/utils/set.js +23 -0
- package/dist/esm/utils/set.js.map +1 -0
- package/dist/esm/utils/string.js +55 -0
- package/dist/esm/utils/string.js.map +1 -0
- package/dist/types/canonicalization.d.ts +38 -29
- package/dist/types/canonicalization.d.ts.map +1 -1
- package/dist/types/constants.d.ts +6 -11
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces.d.ts +2 -2
- package/dist/types/interfaces.d.ts.map +1 -1
- package/dist/types/json-patch.d.ts +47 -0
- package/dist/types/json-patch.d.ts.map +1 -0
- package/dist/types/logger.d.ts +31 -8
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/types.d.ts +13 -5
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/date.d.ts +19 -0
- package/dist/types/utils/date.d.ts.map +1 -0
- package/dist/types/utils/json.d.ts +89 -0
- package/dist/types/utils/json.d.ts.map +1 -0
- package/dist/types/utils/set.d.ts +14 -0
- package/dist/types/utils/set.d.ts.map +1 -0
- package/dist/types/utils/string.d.ts +39 -0
- package/dist/types/utils/string.d.ts.map +1 -0
- package/package.json +3 -4
- package/src/canonicalization.ts +75 -58
- package/src/constants.ts +30 -25
- package/src/index.ts +5 -5
- package/src/interfaces.ts +2 -2
- package/src/json-patch.ts +103 -0
- package/src/logger.ts +59 -27
- package/src/types.ts +13 -7
- package/src/utils/date.ts +32 -0
- package/src/utils/json.ts +315 -0
- package/src/utils/set.ts +23 -0
- package/src/utils/string.ts +59 -0
- package/dist/cjs/exts.js +0 -182
- package/dist/cjs/exts.js.map +0 -1
- package/dist/cjs/patch.js +0 -163
- package/dist/cjs/patch.js.map +0 -1
- package/dist/esm/exts.js +0 -182
- package/dist/esm/exts.js.map +0 -1
- package/dist/esm/patch.js +0 -163
- package/dist/esm/patch.js.map +0 -1
- package/dist/types/exts.d.ts +0 -82
- package/dist/types/exts.d.ts.map +0 -1
- package/dist/types/patch.d.ts +0 -63
- package/dist/types/patch.d.ts.map +0 -1
- package/src/exts.ts +0 -293
- package/src/patch.ts +0 -181
- package/src/rdf-canonize.d.ts +0 -6
package/dist/esm/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sha256 } from '@noble/hashes/sha2';
|
|
2
|
+
import { bytesToHex } from '@noble/hashes/utils';
|
|
2
3
|
export const ID_PLACEHOLDER_VALUE = 'did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
|
|
3
4
|
export const OP_RETURN = 0x6a;
|
|
4
5
|
export const OP_PUSH32 = 0x20;
|
|
@@ -7,31 +8,36 @@ export const MULTIBASE_URI_PREFIX = 'urn:mb:';
|
|
|
7
8
|
export const INITIAL_BLOCK_REWARD = 50;
|
|
8
9
|
export const HALVING_INTERVAL = 150;
|
|
9
10
|
export const COINBASE_MATURITY_DELAY = 100;
|
|
10
|
-
export const
|
|
11
|
+
export const DEFAULT_POLAR_CONFIG = {
|
|
11
12
|
username: 'polaruser',
|
|
12
13
|
password: 'polarpass',
|
|
13
14
|
host: 'http://127.0.0.1:18443',
|
|
14
15
|
allowDefaultWallet: true,
|
|
15
16
|
version: '28.1.0'
|
|
16
17
|
};
|
|
17
|
-
export const POLAR_ALICE_CLIENT_CONFIG = {
|
|
18
|
-
username: 'polaruser',
|
|
19
|
-
password: 'polarpass',
|
|
20
|
-
host: 'http://127.0.0.1:18444',
|
|
21
|
-
allowDefaultWallet: true,
|
|
22
|
-
version: '28.1.0'
|
|
23
|
-
};
|
|
24
18
|
export const DEFAULT_REST_CONFIG = { host: 'http://localhost:3000' };
|
|
25
|
-
export const DEFAULT_RPC_CONFIG =
|
|
19
|
+
export const DEFAULT_RPC_CONFIG = DEFAULT_POLAR_CONFIG;
|
|
26
20
|
export const DEFAULT_BLOCK_CONFIRMATIONS = 7;
|
|
21
|
+
/**
|
|
22
|
+
* Load a default RPC config, allowing environment overrides to avoid hard-coding credentials/hosts in bundles.
|
|
23
|
+
* @returns {typeof DEFAULT_POLAR_CONFIG} The RPC config.
|
|
24
|
+
*/
|
|
25
|
+
export function getDefaultRpcConfig() {
|
|
26
|
+
return {
|
|
27
|
+
...DEFAULT_POLAR_CONFIG,
|
|
28
|
+
host: process.env.BTCR2_RPC_HOST ?? DEFAULT_POLAR_CONFIG.host,
|
|
29
|
+
username: process.env.BTCR2_RPC_USER ?? DEFAULT_POLAR_CONFIG.username,
|
|
30
|
+
password: process.env.BTCR2_RPC_PASS ?? DEFAULT_POLAR_CONFIG.password,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
27
33
|
// Fixed public key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0xe7, 0x01] / [231, 1]
|
|
28
34
|
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX = new Uint8Array([0xe7, 0x01]);
|
|
29
35
|
// Hash of the BIP-340 Multikey prefix
|
|
30
|
-
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH =
|
|
36
|
+
export const BIP340_PUBLIC_KEY_MULTIBASE_PREFIX_HASH = bytesToHex(sha256(BIP340_PUBLIC_KEY_MULTIBASE_PREFIX));
|
|
31
37
|
// Fixed secret key header bytes per the Data Integrity BIP340 Cryptosuite spec: [0x81, 0x26] / [129, 38]
|
|
32
38
|
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX = new Uint8Array([0x81, 0x26]);
|
|
33
39
|
// Hash of the BIP-340 Multikey prefix
|
|
34
|
-
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH =
|
|
40
|
+
export const BIP340_SECRET_KEY_MULTIBASE_PREFIX_HASH = bytesToHex(sha256(BIP340_SECRET_KEY_MULTIBASE_PREFIX));
|
|
35
41
|
// curve's field size
|
|
36
42
|
export const B256 = 2n ** 256n;
|
|
37
43
|
// curve's field prime
|
|
@@ -68,35 +74,32 @@ export const W3C_DID_RESOLUTION_V1 = 'https://w3id.org/did-resolution/v1';
|
|
|
68
74
|
export const CONTEXT_URL_MAP = {
|
|
69
75
|
w3c: {
|
|
70
76
|
did: {
|
|
71
|
-
v1:
|
|
72
|
-
v1_1:
|
|
77
|
+
v1: W3C_DID_V1,
|
|
78
|
+
v1_1: W3C_DID_V1_1,
|
|
73
79
|
},
|
|
74
80
|
didresolution: {
|
|
75
|
-
v1:
|
|
81
|
+
v1: W3C_DID_RESOLUTION_V1,
|
|
76
82
|
},
|
|
77
83
|
security: {
|
|
78
|
-
v2:
|
|
84
|
+
v2: W3C_SECURITY_V2,
|
|
79
85
|
},
|
|
80
86
|
dataintegrity: {
|
|
81
|
-
v1:
|
|
82
|
-
v2:
|
|
87
|
+
v1: W3C_DATA_INTEGRITY_V1,
|
|
88
|
+
v2: W3C_DATA_INTEGRITY_V2,
|
|
83
89
|
},
|
|
84
90
|
zcap: {
|
|
85
|
-
v1:
|
|
91
|
+
v1: W3C_ZCAP_V1,
|
|
86
92
|
},
|
|
87
93
|
jsonldpatch: {
|
|
88
|
-
v1:
|
|
94
|
+
v1: W3C_JSONLD_PATCH_V1,
|
|
89
95
|
},
|
|
90
96
|
multikey: {
|
|
91
|
-
v1:
|
|
97
|
+
v1: W3C_MULTIKEY_V1,
|
|
92
98
|
},
|
|
93
99
|
},
|
|
94
100
|
btcr2: {
|
|
95
|
-
diddocument: {
|
|
96
|
-
v1: 'https://dcdpr.github.io/did-btcr2-js/ns/did-document/v1',
|
|
97
|
-
},
|
|
98
101
|
method: {
|
|
99
|
-
v1:
|
|
102
|
+
v1: BTCR2_METHOD_CONTEXT
|
|
100
103
|
},
|
|
101
104
|
},
|
|
102
105
|
};
|
|
@@ -109,6 +112,7 @@ export const BTCR2_MULTIKEY_CONTEXT = [
|
|
|
109
112
|
CONTEXT_URL_MAP.w3c.multikey.v1
|
|
110
113
|
];
|
|
111
114
|
export const BTCR2_DID_UPDATE_PAYLOAD_CONTEXT = [
|
|
115
|
+
CONTEXT_URL_MAP.btcr2.method.v1,
|
|
112
116
|
CONTEXT_URL_MAP.w3c.security.v2,
|
|
113
117
|
CONTEXT_URL_MAP.w3c.zcap.v1,
|
|
114
118
|
CONTEXT_URL_MAP.w3c.jsonldpatch.v1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.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,EAAE;CAChC,CAAC;AAEF,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;IAC/B,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;IAC/B,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;IAC3B,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;CACnC,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import './exts.js';
|
|
2
1
|
export * from './canonicalization.js';
|
|
3
2
|
export * from './constants.js';
|
|
4
3
|
export * from './errors.js';
|
|
5
4
|
export * from './interfaces.js';
|
|
5
|
+
export * from './json-patch.js';
|
|
6
6
|
export * from './logger.js';
|
|
7
|
-
export * from './patch.js';
|
|
8
7
|
export * from './types.js';
|
|
9
|
-
export * from './
|
|
8
|
+
export * from './utils/date.js';
|
|
9
|
+
export * from './utils/json.js';
|
|
10
|
+
export * from './utils/set.js';
|
|
11
|
+
export * from './utils/string.js';
|
|
10
12
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import jsonPatch from 'fast-json-patch';
|
|
2
|
+
import { MethodError } from './errors.js';
|
|
3
|
+
const { applyPatch, compare, deepClone } = jsonPatch;
|
|
4
|
+
/**
|
|
5
|
+
* Thin wrapper around fast-json-patch to keep a stable API within this package.
|
|
6
|
+
* @class JSONPatch
|
|
7
|
+
* @type {JSONPatch}
|
|
8
|
+
*/
|
|
9
|
+
export class JSONPatch {
|
|
10
|
+
/**
|
|
11
|
+
* Applies a JSON Patch to a source document and returns the patched document.
|
|
12
|
+
* Does not mutate the input document.
|
|
13
|
+
* @param {JSONObject} sourceDocument - The source JSON document to apply the patch to.
|
|
14
|
+
* @param {PatchOperation[]} operations - The JSON Patch operations to apply.
|
|
15
|
+
* @returns {JSONObject} The patched JSON document.
|
|
16
|
+
*/
|
|
17
|
+
static apply(sourceDocument, operations, options = {}) {
|
|
18
|
+
const mutate = options.mutate ?? false;
|
|
19
|
+
const cloneFn = options.clone ?? deepClone;
|
|
20
|
+
const docClone = mutate ? sourceDocument : cloneFn(sourceDocument);
|
|
21
|
+
const validationError = this.validateOperations(operations);
|
|
22
|
+
if (validationError) {
|
|
23
|
+
throw new MethodError('Invalid JSON Patch operations', 'JSON_PATCH_APPLY_ERROR', { error: validationError });
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const result = applyPatch(docClone, operations, true, mutate);
|
|
27
|
+
if (result.newDocument === undefined) {
|
|
28
|
+
throw new MethodError('JSON Patch application failed', 'JSON_PATCH_APPLY_ERROR', { result });
|
|
29
|
+
}
|
|
30
|
+
return result.newDocument;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new MethodError('JSON Patch application failed', 'JSON_PATCH_APPLY_ERROR', { error });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Compute a JSON Patch diff from source => target.
|
|
38
|
+
* @param {JSONObject} sourceDocument - The source JSON document.
|
|
39
|
+
* @param {JSONObject} targetDocument - The target JSON document.
|
|
40
|
+
* @param {string} [path] - An optional base path to prefix to each operation.
|
|
41
|
+
* @returns {PatchOperation[]} The computed JSON Patch operations.
|
|
42
|
+
*/
|
|
43
|
+
static diff(sourceDocument, targetDocument, path = '') {
|
|
44
|
+
const ops = compare(sourceDocument ?? {}, targetDocument ?? {});
|
|
45
|
+
if (!path)
|
|
46
|
+
return ops;
|
|
47
|
+
const prefix = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
48
|
+
return ops.map(op => ({
|
|
49
|
+
...op,
|
|
50
|
+
path: this.joinPointer(prefix, op.path)
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Join a base pointer prefix with an operation path ensuring correct escaping.
|
|
55
|
+
* @param {string} prefix - The base pointer prefix.
|
|
56
|
+
* @param {string} opPath - The operation path.
|
|
57
|
+
* @returns {string} The joined pointer.
|
|
58
|
+
*/
|
|
59
|
+
static joinPointer(prefix, opPath) {
|
|
60
|
+
if (!prefix)
|
|
61
|
+
return opPath;
|
|
62
|
+
const normalizedPrefix = prefix.startsWith('/') ? prefix : `/${prefix}`;
|
|
63
|
+
return `${this.escapeSegmentPath(normalizedPrefix)}${opPath}`;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Escape a JSON Pointer segment according to RFC 6901.
|
|
67
|
+
* @param {string} pointer - The JSON Pointer to escape.
|
|
68
|
+
* @returns {string} The escaped JSON Pointer.
|
|
69
|
+
*/
|
|
70
|
+
static escapeSegmentPath(pointer) {
|
|
71
|
+
return pointer
|
|
72
|
+
.split('/')
|
|
73
|
+
.map((segment, idx) => idx === 0 ? segment : segment.replace(/~/g, '~0').replace(/\//g, '~1'))
|
|
74
|
+
.join('/');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Validate JSON Patch operations.
|
|
78
|
+
* @param {PatchOperation[]} operations - The operations to validate.
|
|
79
|
+
* @returns {Error | null} An Error if validation fails, otherwise null.
|
|
80
|
+
*/
|
|
81
|
+
static validateOperations(operations) {
|
|
82
|
+
if (!Array.isArray(operations))
|
|
83
|
+
return new Error('Operations must be an array');
|
|
84
|
+
for (const op of operations) {
|
|
85
|
+
if (!op || typeof op !== 'object')
|
|
86
|
+
return new Error('Operation must be an object');
|
|
87
|
+
if (typeof op.op !== 'string')
|
|
88
|
+
return new Error('Operation.op must be a string');
|
|
89
|
+
if (typeof op.path !== 'string')
|
|
90
|
+
return new Error('Operation.path must be a string');
|
|
91
|
+
if ((op.op === 'move' || op.op === 'copy') && typeof op.from !== 'string') {
|
|
92
|
+
return new Error(`Operation.from must be a string for op=${op.op}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=json-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-patch.js","sourceRoot":"","sources":["../../src/json-patch.ts"],"names":[],"mappings":"AAAA,OAAO,SAAwB,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI1C,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC;AAErD;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACpB;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CACV,cAAgC,EAChC,UAA4B,EAC5B,UAA6D,EAAE;QAE/D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,SAAS,CAAC;QAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACnE,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAC5D,IAAI,eAAe,EAAE,CAAC;YACpB,MAAM,IAAI,WAAW,CAAC,+BAA+B,EAAE,wBAAwB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AC;gBAC1E,OAAO,IAAI,KAAK,CAAC,0CAA0C,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;YACtE,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/esm/logger.js
CHANGED
|
@@ -44,16 +44,33 @@ const LEVEL_METHODS = {
|
|
|
44
44
|
* - File/line tracing
|
|
45
45
|
* - Timestamps
|
|
46
46
|
* - Colorized output
|
|
47
|
+
* @class Logger
|
|
48
|
+
* @type {Logger}
|
|
47
49
|
*/
|
|
48
50
|
export class Logger {
|
|
49
51
|
levels;
|
|
50
52
|
namespace;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
useColors;
|
|
54
|
+
static shared;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new Logger instance.
|
|
57
|
+
* @param {string} namespace - Optional namespace for log messages.
|
|
58
|
+
* @param {Object} options - Configuration options.
|
|
59
|
+
* @param {Level[]} options.levels - Log levels to enable.
|
|
60
|
+
* @param {boolean} options.useColors - Whether to use colored output.
|
|
61
|
+
*/
|
|
62
|
+
constructor(namespace, options = {}) {
|
|
63
|
+
this.levels = options.levels || LOG_LEVELS[NODE_ENV] || [];
|
|
64
|
+
this.namespace = namespace || 'did-btcr2-js';
|
|
65
|
+
const envForce = process.env.LOG_COLORS;
|
|
66
|
+
this.useColors = options.useColors || (envForce ? envForce !== '0' && envForce.toLowerCase() !== 'false' : Boolean(process.stdout.isTTY));
|
|
54
67
|
}
|
|
55
68
|
/**
|
|
56
69
|
* Logs a message with the specified level.
|
|
70
|
+
* @param {Level} level - The log level.
|
|
71
|
+
* @param {unknown} message - The message to log.
|
|
72
|
+
* @param {...unknown[]} args - Additional arguments to log.
|
|
73
|
+
* @returns {void}
|
|
57
74
|
*/
|
|
58
75
|
_log(level, message, ...args) {
|
|
59
76
|
if (!this.levels.includes(level))
|
|
@@ -62,9 +79,10 @@ export class Logger {
|
|
|
62
79
|
const method = LEVEL_METHODS[level];
|
|
63
80
|
const timestamp = new Date().toISOString();
|
|
64
81
|
const namespace = this.namespace ? `[${this.namespace}]` : '';
|
|
65
|
-
|
|
82
|
+
const render = this.useColors ? color : (v) => v;
|
|
83
|
+
const renderGray = this.useColors ? chalk.gray : (v) => v;
|
|
84
|
+
console[method](`${renderGray(timestamp)} ${namespace} ${render(level)}: ${message}`, ...args);
|
|
66
85
|
}
|
|
67
|
-
// 🔹 Instance-based logging methods
|
|
68
86
|
debug(message, ...args) {
|
|
69
87
|
this._log('debug', message, ...args);
|
|
70
88
|
return this;
|
|
@@ -95,27 +113,43 @@ export class Logger {
|
|
|
95
113
|
}
|
|
96
114
|
/**
|
|
97
115
|
* Static methods for convenience (auto-instantiate).
|
|
116
|
+
* These use a shared singleton instance.
|
|
117
|
+
* @param {unknown} message - The message to log.
|
|
118
|
+
* @param {...unknown[]} args - Additional arguments to log.
|
|
119
|
+
* @returns {void}
|
|
98
120
|
*/
|
|
99
121
|
static debug(message, ...args) {
|
|
100
|
-
|
|
122
|
+
Logger.instance().debug(message, ...args);
|
|
101
123
|
}
|
|
102
124
|
static error(message, ...args) {
|
|
103
|
-
|
|
125
|
+
Logger.instance().error(message, ...args);
|
|
104
126
|
}
|
|
105
127
|
static info(message, ...args) {
|
|
106
|
-
|
|
128
|
+
Logger.instance().info(message, ...args);
|
|
107
129
|
}
|
|
108
130
|
static warn(message, ...args) {
|
|
109
|
-
|
|
131
|
+
Logger.instance().warn(message, ...args);
|
|
110
132
|
}
|
|
111
133
|
static security(message, ...args) {
|
|
112
|
-
|
|
134
|
+
Logger.instance().security(message, ...args);
|
|
113
135
|
}
|
|
114
136
|
static log(message, ...args) {
|
|
115
|
-
|
|
137
|
+
Logger.instance().log(message, ...args);
|
|
116
138
|
}
|
|
117
139
|
static newline() {
|
|
118
|
-
|
|
140
|
+
Logger.instance().newline();
|
|
141
|
+
}
|
|
142
|
+
static instance(levels, useColors) {
|
|
143
|
+
if (!Logger.shared) {
|
|
144
|
+
Logger.shared = new Logger(undefined, { levels, useColors });
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (levels)
|
|
148
|
+
Logger.shared.levels = levels;
|
|
149
|
+
if (useColors !== undefined)
|
|
150
|
+
Logger.shared.useColors = useColors;
|
|
151
|
+
}
|
|
152
|
+
return Logger.shared;
|
|
119
153
|
}
|
|
120
154
|
}
|
|
121
155
|
//# sourceMappingURL=logger.js.map
|
package/dist/esm/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,MAAM,CAAN,IAAY,GAIX;AAJD,WAAY,GAAG;IACb,kCAA2B,CAAA;IAC3B,gCAAyB,CAAA;IACzB,oBAAa,CAAA;AACf,CAAC,EAJW,GAAG,KAAH,GAAG,QAId;AAID,MAAM,CAAC,MAAM,QAAQ,GAAI,OAAO,CAAC,GAAG,CAAC,QAAgB,IAAI,GAAG,CAAC,WAAW,CAAC;AAEzE;;GAEG;AACH,MAAM,UAAU,GAAyB;IACvC,WAAW,EAAG,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC;IAC1D,IAAI,EAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;IACtC,UAAU,EAAI,CAAC,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,YAAY,GAAiC;IACjD,KAAK,EAAM,KAAK,CAAC,KAAK;IACtB,KAAK,EAAM,KAAK,CAAC,GAAG;IACpB,IAAI,EAAO,KAAK,CAAC,IAAI;IACrB,GAAG,EAAQ,KAAK,CAAC,IAAI;IACrB,IAAI,EAAO,KAAK,CAAC,MAAM;IACvB,QAAQ,EAAG,KAAK,CAAC,OAAO;CACzB,CAAC;AAEF;;GAEG;AACH,oCAAoC;AACpC,MAAM,aAAa,GAAiC;IAClD,KAAK,EAAM,OA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MAAM,CAAC,SAAS,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QAC/D,CAAC;aAAM,CAAC;YACN,IAAI,MAAM;gBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YAC1C,IAAI,SAAS,KAAK,SAAS;gBAAE,MAAM,CAAC,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;QACnE,CAAC;QACD,OAAO,MAAM,CAAC,MAAM,CAAC;IACvB,CAAC;CACF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for date-related operations.
|
|
3
|
+
* @name DateUtils
|
|
4
|
+
* @class DateUtils
|
|
5
|
+
*/
|
|
6
|
+
export class DateUtils {
|
|
7
|
+
/**
|
|
8
|
+
* Render an ISO 8601 UTC timestamp without fractional seconds.
|
|
9
|
+
* @param {Date} [date=new Date()] - The date to format.
|
|
10
|
+
* @returns {string} The formatted date string.
|
|
11
|
+
*/
|
|
12
|
+
static getUTCDateTime(date = new Date()) {
|
|
13
|
+
const time = date.getTime();
|
|
14
|
+
if (Number.isNaN(time)) {
|
|
15
|
+
throw new Error(`Invalid date: ${date}`);
|
|
16
|
+
}
|
|
17
|
+
return date.toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Unix timestamp in seconds (integer).
|
|
21
|
+
* @param {Date} [date=new Date()] - The date to convert.
|
|
22
|
+
* @returns {number} The Unix timestamp in seconds.
|
|
23
|
+
*/
|
|
24
|
+
static toUnixSeconds(date = new Date()) {
|
|
25
|
+
const time = date.getTime();
|
|
26
|
+
if (Number.isNaN(time)) {
|
|
27
|
+
throw new Error(`Invalid date: ${date}`);
|
|
28
|
+
}
|
|
29
|
+
return Math.floor(date.getTime() / 1000);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/utils/date.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,SAAS;IACpB;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,OAAa,IAAI,IAAI,EAAE;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,aAAa,CAAC,OAAa,IAAI,IAAI,EAAE;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC5B,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IAC3C,CAAC;CACF"}
|