@orkestrel/database 0.0.2 → 0.0.3
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/src/core/index.cjs
CHANGED
|
@@ -24,6 +24,10 @@ var DEFAULT_PRIMARY = "id";
|
|
|
24
24
|
* `VALIDATION` {@link DatabaseError}; the cap is generous for any legitimate search.
|
|
25
25
|
*/
|
|
26
26
|
var MAX_PATTERN_LENGTH = 1024;
|
|
27
|
+
/** The number of bytes encoded by an RFC 4122 UUID. */
|
|
28
|
+
var UUID_BYTE_COUNT = 16;
|
|
29
|
+
/** The number of distinct values one UUID byte may hold. */
|
|
30
|
+
var UUID_BYTE_RANGE = 256;
|
|
27
31
|
//#endregion
|
|
28
32
|
//#region src/core/errors.ts
|
|
29
33
|
/**
|
|
@@ -1312,6 +1316,40 @@ async function auditDriver(factory) {
|
|
|
1312
1316
|
for await (const finding of driverFindings(factory)) findings.push(finding);
|
|
1313
1317
|
return findings;
|
|
1314
1318
|
}
|
|
1319
|
+
/**
|
|
1320
|
+
* Generate an RFC 4122 version 4 UUID from a number source — no host crypto global.
|
|
1321
|
+
*
|
|
1322
|
+
* @remarks
|
|
1323
|
+
* Draws exactly {@link UUID_BYTE_COUNT} values from `random`, one per byte, then
|
|
1324
|
+
* forces the version (`4`) and variant (`10xx`) bits. The default source is
|
|
1325
|
+
* `Math.random` — a pure-ECMAScript intrinsic, so generation works on every host;
|
|
1326
|
+
* pass a seeded source (`seededRandom` from `@orkestrel/contract`) and reuse it
|
|
1327
|
+
* across calls for reproducible sequences in tests and fixtures — production
|
|
1328
|
+
* identifiers should keep the default source, whose engine entropy is far larger
|
|
1329
|
+
* than a 32-bit seed. Each byte is floored and masked, so a source straying
|
|
1330
|
+
* outside `[0, 1)` (negative, `>= 1`, `NaN`, `Infinity`) can never yield a
|
|
1331
|
+
* malformed UUID. Suitable as a collision-resistant record identifier — not a
|
|
1332
|
+
* cryptographic token; never use one as a secret.
|
|
1333
|
+
*
|
|
1334
|
+
* @param random - A number source returning values in the half-open range `[0, 1)` (defaults to `Math.random`)
|
|
1335
|
+
* @returns A lowercase RFC 4122 version 4 UUID
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```ts
|
|
1339
|
+
* import { generateUUID } from '@orkestrel/database'
|
|
1340
|
+
* import { seededRandom } from '@orkestrel/contract'
|
|
1341
|
+
*
|
|
1342
|
+
* generateUUID() // e.g. '9b2f7c1e-3d4a-4f6b-8e2d-5a1c0b9f8e7d'
|
|
1343
|
+
* generateUUID(seededRandom(42)) // the same UUID on every run
|
|
1344
|
+
* ```
|
|
1345
|
+
*/
|
|
1346
|
+
function generateUUID(random = Math.random) {
|
|
1347
|
+
const bytes = Array.from({ length: 16 }, () => Math.floor(random() * 256) & 255);
|
|
1348
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
1349
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
1350
|
+
const hex = bytes.map((byte) => byte.toString(16).padStart(2, "0"));
|
|
1351
|
+
return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
|
|
1352
|
+
}
|
|
1315
1353
|
//#endregion
|
|
1316
1354
|
//#region src/core/Cursor.ts
|
|
1317
1355
|
/**
|
|
@@ -2426,6 +2464,8 @@ exports.MAX_PATTERN_LENGTH = MAX_PATTERN_LENGTH;
|
|
|
2426
2464
|
exports.MemoryDriver = MemoryDriver;
|
|
2427
2465
|
exports.Query = Query;
|
|
2428
2466
|
exports.Table = Table;
|
|
2467
|
+
exports.UUID_BYTE_COUNT = UUID_BYTE_COUNT;
|
|
2468
|
+
exports.UUID_BYTE_RANGE = UUID_BYTE_RANGE;
|
|
2429
2469
|
exports.applyCriteria = applyCriteria;
|
|
2430
2470
|
exports.auditDriver = auditDriver;
|
|
2431
2471
|
exports.checkAbort = checkAbort;
|
|
@@ -2438,6 +2478,7 @@ exports.deepEqual = deepEqual;
|
|
|
2438
2478
|
exports.driverFindings = driverFindings;
|
|
2439
2479
|
exports.extractKey = extractKey;
|
|
2440
2480
|
exports.filterRows = filterRows;
|
|
2481
|
+
exports.generateUUID = generateUUID;
|
|
2441
2482
|
exports.globMatch = globMatch;
|
|
2442
2483
|
exports.isDatabaseError = isDatabaseError;
|
|
2443
2484
|
exports.isDriverMeta = isDriverMeta;
|