@powfix/core-js 0.22.0 → 0.22.1
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/index.node.cjs +321 -6
- package/dist/index.node.js +321 -6
- package/package.json +2 -2
package/dist/index.node.cjs
CHANGED
|
@@ -76137,8 +76137,323 @@ var Validator2 = import_index2.default.Validator;
|
|
|
76137
76137
|
var ValidationErrorItemOrigin = import_index2.default.ValidationErrorItemOrigin;
|
|
76138
76138
|
var ValidationErrorItemType = import_index2.default.ValidationErrorItemType;
|
|
76139
76139
|
|
|
76140
|
+
// node_modules/@powfix/uuid/dist/index.node.js
|
|
76141
|
+
var Uint8ArrayUtils2 = class {
|
|
76142
|
+
static fromHex(hex) {
|
|
76143
|
+
return Uint8Array.from(hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []);
|
|
76144
|
+
}
|
|
76145
|
+
static toHex(bytes) {
|
|
76146
|
+
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
76147
|
+
}
|
|
76148
|
+
};
|
|
76149
|
+
var UUID2 = class _UUID {
|
|
76150
|
+
/* --------------------------------------------------------------------
|
|
76151
|
+
* Regular expressions used to validate UUIDs in different string forms
|
|
76152
|
+
* -------------------------------------------------------------------- */
|
|
76153
|
+
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
76154
|
+
static REGEX_HEX = /^[0-9a-fA-F]{8}[0-9a-fA-F]{4}[1-5][0-9a-fA-F]{3}[89abAB][0-9a-fA-F]{3}[0-9a-fA-F]{12}$/;
|
|
76155
|
+
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
76156
|
+
static REGEX_RFC4122 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
76157
|
+
/* --------------------------------------------------------------------
|
|
76158
|
+
* Constant lengths used throughout the class
|
|
76159
|
+
* -------------------------------------------------------------------- */
|
|
76160
|
+
/** Number of bytes that represent a UUID. */
|
|
76161
|
+
static BYTE_LENGTH = 16;
|
|
76162
|
+
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
76163
|
+
static STR_LENGTH = 36;
|
|
76164
|
+
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
76165
|
+
static HEX_STR_LENGTH = 32;
|
|
76166
|
+
/* --------------------------------------------------------------------
|
|
76167
|
+
* Validation helpers
|
|
76168
|
+
* -------------------------------------------------------------------- */
|
|
76169
|
+
/**
|
|
76170
|
+
* Checks if the supplied value is a valid hex representation of a UUID.
|
|
76171
|
+
* @param hex - The string to validate.
|
|
76172
|
+
* @returns true if the string matches {@link REGEX_HEX}.
|
|
76173
|
+
*/
|
|
76174
|
+
static isValidHex(hex) {
|
|
76175
|
+
if (typeof hex !== "string") {
|
|
76176
|
+
return false;
|
|
76177
|
+
}
|
|
76178
|
+
return _UUID.REGEX_HEX.test(hex);
|
|
76179
|
+
}
|
|
76180
|
+
/**
|
|
76181
|
+
* Checks if the supplied value is a valid RFC 4122 UUID string.
|
|
76182
|
+
* @param str - The string to validate.
|
|
76183
|
+
* @returns true if the string matches {@link REGEX_RFC4122}.
|
|
76184
|
+
*/
|
|
76185
|
+
static isValidString(str) {
|
|
76186
|
+
if (typeof str !== "string") {
|
|
76187
|
+
return false;
|
|
76188
|
+
}
|
|
76189
|
+
return _UUID.REGEX_RFC4122.test(str);
|
|
76190
|
+
}
|
|
76191
|
+
/**
|
|
76192
|
+
* Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
|
|
76193
|
+
* @param bytes - The view to check.
|
|
76194
|
+
* @returns true if the byte length is correct.
|
|
76195
|
+
*/
|
|
76196
|
+
static isValidBytes(bytes) {
|
|
76197
|
+
return bytes.byteLength === _UUID.BYTE_LENGTH;
|
|
76198
|
+
}
|
|
76199
|
+
/**
|
|
76200
|
+
* Generic validation that accepts either a string (hex or RFC 4122 format)
|
|
76201
|
+
* or an ArrayBufferView containing the raw bytes.
|
|
76202
|
+
* @param input - The value to validate.
|
|
76203
|
+
* @returns true if the input is a valid representation of a UUID.
|
|
76204
|
+
*/
|
|
76205
|
+
static isValid(input) {
|
|
76206
|
+
if (typeof input === "string") {
|
|
76207
|
+
const length = input.length;
|
|
76208
|
+
switch (length) {
|
|
76209
|
+
case _UUID.STR_LENGTH:
|
|
76210
|
+
return _UUID.isValidString(input);
|
|
76211
|
+
case _UUID.HEX_STR_LENGTH:
|
|
76212
|
+
return _UUID.isValidHex(input);
|
|
76213
|
+
default:
|
|
76214
|
+
return false;
|
|
76215
|
+
}
|
|
76216
|
+
} else if (input instanceof _UUID) {
|
|
76217
|
+
return _UUID.isValidBytes(input.bytes);
|
|
76218
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
76219
|
+
return _UUID.isValidBytes(input);
|
|
76220
|
+
} else {
|
|
76221
|
+
return false;
|
|
76222
|
+
}
|
|
76223
|
+
}
|
|
76224
|
+
static version(input) {
|
|
76225
|
+
return this.parse(input)[6] >> 4 & 15;
|
|
76226
|
+
}
|
|
76227
|
+
/* --------------------------------------------------------------------
|
|
76228
|
+
* Parsing / formatting helpers
|
|
76229
|
+
* -------------------------------------------------------------------- */
|
|
76230
|
+
/**
|
|
76231
|
+
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
76232
|
+
* @param hex - The plain hexadecimal UUID.
|
|
76233
|
+
* @returns The formatted RFC 4122 string.
|
|
76234
|
+
*/
|
|
76235
|
+
static formatHex(hex) {
|
|
76236
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76237
|
+
throw new Error(`hex length should be ${_UUID.HEX_STR_LENGTH}`);
|
|
76238
|
+
}
|
|
76239
|
+
return hex.slice(0, 8) + "-" + hex.slice(8, 12) + "-" + hex.slice(12, 16) + "-" + hex.slice(16, 20) + "-" + hex.slice(20);
|
|
76240
|
+
}
|
|
76241
|
+
/** Removes all hyphens from a UUID string. */
|
|
76242
|
+
static stripHyphens(str) {
|
|
76243
|
+
return str.replace(/-/g, "");
|
|
76244
|
+
}
|
|
76245
|
+
/**
|
|
76246
|
+
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
76247
|
+
* @param hex - The hex string to parse.
|
|
76248
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76249
|
+
*/
|
|
76250
|
+
static parseHex(hex) {
|
|
76251
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76252
|
+
throw new Error(`Invalid hex string, length should be ${_UUID.HEX_STR_LENGTH}`);
|
|
76253
|
+
}
|
|
76254
|
+
return Uint8ArrayUtils2.fromHex(hex);
|
|
76255
|
+
}
|
|
76256
|
+
/**
|
|
76257
|
+
* Parses an RFC 4122 string into a Uint8Array.
|
|
76258
|
+
* @param str - The formatted UUID string.
|
|
76259
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76260
|
+
*/
|
|
76261
|
+
static parseString(str) {
|
|
76262
|
+
if (str.length !== _UUID.STR_LENGTH) {
|
|
76263
|
+
throw new Error(`Invalid UUID string, invalid character length should be ${_UUID.STR_LENGTH}`);
|
|
76264
|
+
}
|
|
76265
|
+
if (!_UUID.isValid(str)) {
|
|
76266
|
+
throw new Error("Invalid UUID string, should be RFC 4122 format");
|
|
76267
|
+
}
|
|
76268
|
+
const hex = _UUID.stripHyphens(str);
|
|
76269
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76270
|
+
throw new Error("Invalid UUID string, invalid character length after strip hyphens");
|
|
76271
|
+
}
|
|
76272
|
+
return Uint8ArrayUtils2.fromHex(hex);
|
|
76273
|
+
}
|
|
76274
|
+
/**
|
|
76275
|
+
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
76276
|
+
* @param bytes - The view to parse.
|
|
76277
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76278
|
+
*/
|
|
76279
|
+
static parseBytes(bytes) {
|
|
76280
|
+
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
76281
|
+
if (view.length !== _UUID.BYTE_LENGTH) {
|
|
76282
|
+
throw new Error(`Expected ${_UUID.BYTE_LENGTH} bytes`);
|
|
76283
|
+
}
|
|
76284
|
+
return new Uint8Array(view);
|
|
76285
|
+
}
|
|
76286
|
+
/* --------------------------------------------------------------------
|
|
76287
|
+
* Factory methods
|
|
76288
|
+
* -------------------------------------------------------------------- */
|
|
76289
|
+
/**
|
|
76290
|
+
* Creates a UUID instance from a plain hexadecimal string.
|
|
76291
|
+
* @param hex - The hex representation of the UUID.
|
|
76292
|
+
* @returns A new {@link UUID} object.
|
|
76293
|
+
*/
|
|
76294
|
+
static fromHex(hex) {
|
|
76295
|
+
return new this(this.parseHex(hex));
|
|
76296
|
+
}
|
|
76297
|
+
/**
|
|
76298
|
+
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
76299
|
+
* @param str - The UUID string with hyphens.
|
|
76300
|
+
* @returns A new {@link UUID} object.
|
|
76301
|
+
*/
|
|
76302
|
+
static fromString(str) {
|
|
76303
|
+
return new this(this.parseString(str));
|
|
76304
|
+
}
|
|
76305
|
+
/**
|
|
76306
|
+
* Creates a UUID instance from raw bytes.
|
|
76307
|
+
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
76308
|
+
* @returns A new {@link UUID} object.
|
|
76309
|
+
*/
|
|
76310
|
+
static fromBytes(bytes) {
|
|
76311
|
+
return new this(this.parseBytes(bytes));
|
|
76312
|
+
}
|
|
76313
|
+
/**
|
|
76314
|
+
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
76315
|
+
* @param input - The value to parse.
|
|
76316
|
+
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
76317
|
+
*/
|
|
76318
|
+
static parse(input) {
|
|
76319
|
+
if (typeof input === "string") {
|
|
76320
|
+
const length = input.length;
|
|
76321
|
+
switch (length) {
|
|
76322
|
+
case _UUID.STR_LENGTH:
|
|
76323
|
+
return this.parseString(input);
|
|
76324
|
+
case _UUID.HEX_STR_LENGTH:
|
|
76325
|
+
return this.parseHex(input);
|
|
76326
|
+
default:
|
|
76327
|
+
throw new Error(`Invalid input string, length should be ${_UUID.STR_LENGTH} or ${_UUID.HEX_STR_LENGTH}`);
|
|
76328
|
+
}
|
|
76329
|
+
} else if (input instanceof _UUID) {
|
|
76330
|
+
return input.toBytes();
|
|
76331
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
76332
|
+
return this.parseBytes(input);
|
|
76333
|
+
} else {
|
|
76334
|
+
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
76335
|
+
}
|
|
76336
|
+
}
|
|
76337
|
+
/**
|
|
76338
|
+
* Creates a UUID from any supported input type.
|
|
76339
|
+
* @param input - The value to parse.
|
|
76340
|
+
* @returns A new {@link UUID} object.
|
|
76341
|
+
*/
|
|
76342
|
+
static from(input) {
|
|
76343
|
+
return this.fromBytes(_UUID.parse(input));
|
|
76344
|
+
}
|
|
76345
|
+
/** Returns the nil (all zero) UUID. */
|
|
76346
|
+
static nil() {
|
|
76347
|
+
return this.fromBytes(new Uint8Array(_UUID.BYTE_LENGTH));
|
|
76348
|
+
}
|
|
76349
|
+
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
76350
|
+
static max() {
|
|
76351
|
+
return this.fromBytes(new Uint8Array(_UUID.BYTE_LENGTH).fill(255));
|
|
76352
|
+
}
|
|
76353
|
+
/* --------------------------------------------------------------------
|
|
76354
|
+
* Equality / comparison
|
|
76355
|
+
* -------------------------------------------------------------------- */
|
|
76356
|
+
/**
|
|
76357
|
+
* Compares multiple UUIDs for strict equality.
|
|
76358
|
+
* @param inputs - The UUIDs to compare (at least two required).
|
|
76359
|
+
* @returns true if all provided UUIDs are identical.
|
|
76360
|
+
*/
|
|
76361
|
+
static equals(...inputs) {
|
|
76362
|
+
const n = inputs.length;
|
|
76363
|
+
if (n < 2) {
|
|
76364
|
+
throw new Error("At least two UUIDs required for comparison");
|
|
76365
|
+
}
|
|
76366
|
+
const ref = this.parse(inputs[0]);
|
|
76367
|
+
for (let i = 1; i < n; ++i) {
|
|
76368
|
+
const b = this.parse(inputs[i]);
|
|
76369
|
+
for (let j = 0; j < _UUID.BYTE_LENGTH; ++j) {
|
|
76370
|
+
if (ref[j] !== b[j]) return false;
|
|
76371
|
+
}
|
|
76372
|
+
}
|
|
76373
|
+
return true;
|
|
76374
|
+
}
|
|
76375
|
+
/**
|
|
76376
|
+
* Lexicographically compares two UUIDs.
|
|
76377
|
+
* @param uuid1 - The first UUID.
|
|
76378
|
+
* @param uuid2 - The second UUID.
|
|
76379
|
+
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
76380
|
+
*/
|
|
76381
|
+
static compare(uuid1, uuid2) {
|
|
76382
|
+
const a = this.parse(uuid1);
|
|
76383
|
+
const b = this.parse(uuid2);
|
|
76384
|
+
for (let i = 0; i < _UUID.BYTE_LENGTH; i++) {
|
|
76385
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
76386
|
+
}
|
|
76387
|
+
return 0;
|
|
76388
|
+
}
|
|
76389
|
+
/* --------------------------------------------------------------------
|
|
76390
|
+
* Instance members
|
|
76391
|
+
* -------------------------------------------------------------------- */
|
|
76392
|
+
/** Raw byte representation of the UUID. */
|
|
76393
|
+
bytes;
|
|
76394
|
+
// Cached string and hex representations to avoid recomputation.
|
|
76395
|
+
_str;
|
|
76396
|
+
_hex;
|
|
76397
|
+
/**
|
|
76398
|
+
* Constructs a new {@link UUID} instance from any supported input type.
|
|
76399
|
+
* @param input - The value to parse (string or ArrayBufferView).
|
|
76400
|
+
*/
|
|
76401
|
+
constructor(input) {
|
|
76402
|
+
this.bytes = _UUID.parse(input);
|
|
76403
|
+
}
|
|
76404
|
+
/** Instance wrapper for {@link equals}. */
|
|
76405
|
+
equals(...inputs) {
|
|
76406
|
+
return _UUID.equals(this, ...inputs);
|
|
76407
|
+
}
|
|
76408
|
+
/** Instance wrapper for {@link compare}. */
|
|
76409
|
+
compare(other) {
|
|
76410
|
+
return _UUID.compare(this, other);
|
|
76411
|
+
}
|
|
76412
|
+
version() {
|
|
76413
|
+
return _UUID.version(this);
|
|
76414
|
+
}
|
|
76415
|
+
/**
|
|
76416
|
+
* Returns the RFC 4122 string representation of this UUID.
|
|
76417
|
+
* @returns The formatted UUID string.
|
|
76418
|
+
*/
|
|
76419
|
+
toString() {
|
|
76420
|
+
if (this._str != null) {
|
|
76421
|
+
return this._str;
|
|
76422
|
+
}
|
|
76423
|
+
const hex = this.toHex();
|
|
76424
|
+
this._str = _UUID.formatHex(hex);
|
|
76425
|
+
return this._str;
|
|
76426
|
+
}
|
|
76427
|
+
/**
|
|
76428
|
+
* Returns the plain hexadecimal representation of this UUID.
|
|
76429
|
+
* @returns A 32‑character hex string.
|
|
76430
|
+
*/
|
|
76431
|
+
toHex() {
|
|
76432
|
+
if (this._hex != null) {
|
|
76433
|
+
return this._hex;
|
|
76434
|
+
}
|
|
76435
|
+
this._hex = Uint8ArrayUtils2.toHex(this.bytes);
|
|
76436
|
+
return this._hex;
|
|
76437
|
+
}
|
|
76438
|
+
/**
|
|
76439
|
+
* Returns a copy of the raw byte array.
|
|
76440
|
+
* @returns A new Uint8Array containing the UUID bytes.
|
|
76441
|
+
*/
|
|
76442
|
+
toBytes() {
|
|
76443
|
+
return new Uint8Array(this.bytes);
|
|
76444
|
+
}
|
|
76445
|
+
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
76446
|
+
toJSON() {
|
|
76447
|
+
return this.toString();
|
|
76448
|
+
}
|
|
76449
|
+
};
|
|
76450
|
+
var UUID22 = class extends UUID2 {
|
|
76451
|
+
toBuffer() {
|
|
76452
|
+
return Buffer.from(this.bytes);
|
|
76453
|
+
}
|
|
76454
|
+
};
|
|
76455
|
+
|
|
76140
76456
|
// src/nodejs/utils/sequelize-utils/SequelizeUtils.ts
|
|
76141
|
-
var import_node = require("@powfix/uuid/node");
|
|
76142
76457
|
var SequelizeUtils = class _SequelizeUtils {
|
|
76143
76458
|
static decimal2Number(value) {
|
|
76144
76459
|
if (value === null || value === void 0) {
|
|
@@ -76156,7 +76471,7 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76156
76471
|
allowNull: false,
|
|
76157
76472
|
primaryKey: true,
|
|
76158
76473
|
unique: true,
|
|
76159
|
-
defaultValue: () =>
|
|
76474
|
+
defaultValue: () => UUID22.from(UuidUtils.v4()).toBuffer()
|
|
76160
76475
|
})
|
|
76161
76476
|
});
|
|
76162
76477
|
static buildUuidColumn(options) {
|
|
@@ -76166,10 +76481,10 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76166
76481
|
type: "binary(16)",
|
|
76167
76482
|
get() {
|
|
76168
76483
|
const value = this.getDataValue(columnName);
|
|
76169
|
-
return value != null ?
|
|
76484
|
+
return value != null ? UUID22.from(value) : value;
|
|
76170
76485
|
},
|
|
76171
76486
|
set(input) {
|
|
76172
|
-
const value = input != null ?
|
|
76487
|
+
const value = input != null ? UUID22.from(input).toBuffer() : input;
|
|
76173
76488
|
this.setDataValue(columnName, value);
|
|
76174
76489
|
},
|
|
76175
76490
|
...overrideOptions
|
|
@@ -76179,10 +76494,10 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76179
76494
|
type: "binary(16)",
|
|
76180
76495
|
get() {
|
|
76181
76496
|
const value = this.getDataValue(columnName);
|
|
76182
|
-
return
|
|
76497
|
+
return UUID22.from(value);
|
|
76183
76498
|
},
|
|
76184
76499
|
set(input) {
|
|
76185
|
-
const value =
|
|
76500
|
+
const value = UUID22.from(input).toBuffer();
|
|
76186
76501
|
this.setDataValue(columnName, value);
|
|
76187
76502
|
},
|
|
76188
76503
|
...overrideOptions
|
package/dist/index.node.js
CHANGED
|
@@ -76079,8 +76079,323 @@ var Validator2 = import_index2.default.Validator;
|
|
|
76079
76079
|
var ValidationErrorItemOrigin = import_index2.default.ValidationErrorItemOrigin;
|
|
76080
76080
|
var ValidationErrorItemType = import_index2.default.ValidationErrorItemType;
|
|
76081
76081
|
|
|
76082
|
+
// node_modules/@powfix/uuid/dist/index.node.js
|
|
76083
|
+
var Uint8ArrayUtils2 = class {
|
|
76084
|
+
static fromHex(hex) {
|
|
76085
|
+
return Uint8Array.from(hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []);
|
|
76086
|
+
}
|
|
76087
|
+
static toHex(bytes) {
|
|
76088
|
+
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
|
|
76089
|
+
}
|
|
76090
|
+
};
|
|
76091
|
+
var UUID2 = class _UUID {
|
|
76092
|
+
/* --------------------------------------------------------------------
|
|
76093
|
+
* Regular expressions used to validate UUIDs in different string forms
|
|
76094
|
+
* -------------------------------------------------------------------- */
|
|
76095
|
+
/** Matches a 32‑character hexadecimal representation of a UUID without hyphens. */
|
|
76096
|
+
static REGEX_HEX = /^[0-9a-fA-F]{8}[0-9a-fA-F]{4}[1-5][0-9a-fA-F]{3}[89abAB][0-9a-fA-F]{3}[0-9a-fA-F]{12}$/;
|
|
76097
|
+
/** Matches the RFC 4122 canonical UUID format with hyphens. */
|
|
76098
|
+
static REGEX_RFC4122 = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
76099
|
+
/* --------------------------------------------------------------------
|
|
76100
|
+
* Constant lengths used throughout the class
|
|
76101
|
+
* -------------------------------------------------------------------- */
|
|
76102
|
+
/** Number of bytes that represent a UUID. */
|
|
76103
|
+
static BYTE_LENGTH = 16;
|
|
76104
|
+
/** Total length of an RFC 4122 UUID string (including hyphens). */
|
|
76105
|
+
static STR_LENGTH = 36;
|
|
76106
|
+
/** Length of a UUID represented as a plain hexadecimal string. */
|
|
76107
|
+
static HEX_STR_LENGTH = 32;
|
|
76108
|
+
/* --------------------------------------------------------------------
|
|
76109
|
+
* Validation helpers
|
|
76110
|
+
* -------------------------------------------------------------------- */
|
|
76111
|
+
/**
|
|
76112
|
+
* Checks if the supplied value is a valid hex representation of a UUID.
|
|
76113
|
+
* @param hex - The string to validate.
|
|
76114
|
+
* @returns true if the string matches {@link REGEX_HEX}.
|
|
76115
|
+
*/
|
|
76116
|
+
static isValidHex(hex) {
|
|
76117
|
+
if (typeof hex !== "string") {
|
|
76118
|
+
return false;
|
|
76119
|
+
}
|
|
76120
|
+
return _UUID.REGEX_HEX.test(hex);
|
|
76121
|
+
}
|
|
76122
|
+
/**
|
|
76123
|
+
* Checks if the supplied value is a valid RFC 4122 UUID string.
|
|
76124
|
+
* @param str - The string to validate.
|
|
76125
|
+
* @returns true if the string matches {@link REGEX_RFC4122}.
|
|
76126
|
+
*/
|
|
76127
|
+
static isValidString(str) {
|
|
76128
|
+
if (typeof str !== "string") {
|
|
76129
|
+
return false;
|
|
76130
|
+
}
|
|
76131
|
+
return _UUID.REGEX_RFC4122.test(str);
|
|
76132
|
+
}
|
|
76133
|
+
/**
|
|
76134
|
+
* Checks whether an ArrayBufferView contains exactly {@link BYTE_LENGTH} bytes.
|
|
76135
|
+
* @param bytes - The view to check.
|
|
76136
|
+
* @returns true if the byte length is correct.
|
|
76137
|
+
*/
|
|
76138
|
+
static isValidBytes(bytes) {
|
|
76139
|
+
return bytes.byteLength === _UUID.BYTE_LENGTH;
|
|
76140
|
+
}
|
|
76141
|
+
/**
|
|
76142
|
+
* Generic validation that accepts either a string (hex or RFC 4122 format)
|
|
76143
|
+
* or an ArrayBufferView containing the raw bytes.
|
|
76144
|
+
* @param input - The value to validate.
|
|
76145
|
+
* @returns true if the input is a valid representation of a UUID.
|
|
76146
|
+
*/
|
|
76147
|
+
static isValid(input) {
|
|
76148
|
+
if (typeof input === "string") {
|
|
76149
|
+
const length = input.length;
|
|
76150
|
+
switch (length) {
|
|
76151
|
+
case _UUID.STR_LENGTH:
|
|
76152
|
+
return _UUID.isValidString(input);
|
|
76153
|
+
case _UUID.HEX_STR_LENGTH:
|
|
76154
|
+
return _UUID.isValidHex(input);
|
|
76155
|
+
default:
|
|
76156
|
+
return false;
|
|
76157
|
+
}
|
|
76158
|
+
} else if (input instanceof _UUID) {
|
|
76159
|
+
return _UUID.isValidBytes(input.bytes);
|
|
76160
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
76161
|
+
return _UUID.isValidBytes(input);
|
|
76162
|
+
} else {
|
|
76163
|
+
return false;
|
|
76164
|
+
}
|
|
76165
|
+
}
|
|
76166
|
+
static version(input) {
|
|
76167
|
+
return this.parse(input)[6] >> 4 & 15;
|
|
76168
|
+
}
|
|
76169
|
+
/* --------------------------------------------------------------------
|
|
76170
|
+
* Parsing / formatting helpers
|
|
76171
|
+
* -------------------------------------------------------------------- */
|
|
76172
|
+
/**
|
|
76173
|
+
* Inserts hyphens into a 32‑character hex string to produce an RFC 4122 string.
|
|
76174
|
+
* @param hex - The plain hexadecimal UUID.
|
|
76175
|
+
* @returns The formatted RFC 4122 string.
|
|
76176
|
+
*/
|
|
76177
|
+
static formatHex(hex) {
|
|
76178
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76179
|
+
throw new Error(`hex length should be ${_UUID.HEX_STR_LENGTH}`);
|
|
76180
|
+
}
|
|
76181
|
+
return hex.slice(0, 8) + "-" + hex.slice(8, 12) + "-" + hex.slice(12, 16) + "-" + hex.slice(16, 20) + "-" + hex.slice(20);
|
|
76182
|
+
}
|
|
76183
|
+
/** Removes all hyphens from a UUID string. */
|
|
76184
|
+
static stripHyphens(str) {
|
|
76185
|
+
return str.replace(/-/g, "");
|
|
76186
|
+
}
|
|
76187
|
+
/**
|
|
76188
|
+
* Converts a plain hexadecimal UUID into a Uint8Array.
|
|
76189
|
+
* @param hex - The hex string to parse.
|
|
76190
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76191
|
+
*/
|
|
76192
|
+
static parseHex(hex) {
|
|
76193
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76194
|
+
throw new Error(`Invalid hex string, length should be ${_UUID.HEX_STR_LENGTH}`);
|
|
76195
|
+
}
|
|
76196
|
+
return Uint8ArrayUtils2.fromHex(hex);
|
|
76197
|
+
}
|
|
76198
|
+
/**
|
|
76199
|
+
* Parses an RFC 4122 string into a Uint8Array.
|
|
76200
|
+
* @param str - The formatted UUID string.
|
|
76201
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76202
|
+
*/
|
|
76203
|
+
static parseString(str) {
|
|
76204
|
+
if (str.length !== _UUID.STR_LENGTH) {
|
|
76205
|
+
throw new Error(`Invalid UUID string, invalid character length should be ${_UUID.STR_LENGTH}`);
|
|
76206
|
+
}
|
|
76207
|
+
if (!_UUID.isValid(str)) {
|
|
76208
|
+
throw new Error("Invalid UUID string, should be RFC 4122 format");
|
|
76209
|
+
}
|
|
76210
|
+
const hex = _UUID.stripHyphens(str);
|
|
76211
|
+
if (hex.length !== _UUID.HEX_STR_LENGTH) {
|
|
76212
|
+
throw new Error("Invalid UUID string, invalid character length after strip hyphens");
|
|
76213
|
+
}
|
|
76214
|
+
return Uint8ArrayUtils2.fromHex(hex);
|
|
76215
|
+
}
|
|
76216
|
+
/**
|
|
76217
|
+
* Parses an ArrayBufferView into a Uint8Array ensuring the correct byte length.
|
|
76218
|
+
* @param bytes - The view to parse.
|
|
76219
|
+
* @returns A Uint8Array containing the raw bytes.
|
|
76220
|
+
*/
|
|
76221
|
+
static parseBytes(bytes) {
|
|
76222
|
+
const view = new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
76223
|
+
if (view.length !== _UUID.BYTE_LENGTH) {
|
|
76224
|
+
throw new Error(`Expected ${_UUID.BYTE_LENGTH} bytes`);
|
|
76225
|
+
}
|
|
76226
|
+
return new Uint8Array(view);
|
|
76227
|
+
}
|
|
76228
|
+
/* --------------------------------------------------------------------
|
|
76229
|
+
* Factory methods
|
|
76230
|
+
* -------------------------------------------------------------------- */
|
|
76231
|
+
/**
|
|
76232
|
+
* Creates a UUID instance from a plain hexadecimal string.
|
|
76233
|
+
* @param hex - The hex representation of the UUID.
|
|
76234
|
+
* @returns A new {@link UUID} object.
|
|
76235
|
+
*/
|
|
76236
|
+
static fromHex(hex) {
|
|
76237
|
+
return new this(this.parseHex(hex));
|
|
76238
|
+
}
|
|
76239
|
+
/**
|
|
76240
|
+
* Creates a UUID instance from an RFC 4122 formatted string.
|
|
76241
|
+
* @param str - The UUID string with hyphens.
|
|
76242
|
+
* @returns A new {@link UUID} object.
|
|
76243
|
+
*/
|
|
76244
|
+
static fromString(str) {
|
|
76245
|
+
return new this(this.parseString(str));
|
|
76246
|
+
}
|
|
76247
|
+
/**
|
|
76248
|
+
* Creates a UUID instance from raw bytes.
|
|
76249
|
+
* @param bytes - An ArrayBufferView containing 16 bytes.
|
|
76250
|
+
* @returns A new {@link UUID} object.
|
|
76251
|
+
*/
|
|
76252
|
+
static fromBytes(bytes) {
|
|
76253
|
+
return new this(this.parseBytes(bytes));
|
|
76254
|
+
}
|
|
76255
|
+
/**
|
|
76256
|
+
* Parses any supported input (string or bytes) and returns the raw byte array.
|
|
76257
|
+
* @param input - The value to parse.
|
|
76258
|
+
* @returns A Uint8Array of length {@link BYTE_LENGTH}.
|
|
76259
|
+
*/
|
|
76260
|
+
static parse(input) {
|
|
76261
|
+
if (typeof input === "string") {
|
|
76262
|
+
const length = input.length;
|
|
76263
|
+
switch (length) {
|
|
76264
|
+
case _UUID.STR_LENGTH:
|
|
76265
|
+
return this.parseString(input);
|
|
76266
|
+
case _UUID.HEX_STR_LENGTH:
|
|
76267
|
+
return this.parseHex(input);
|
|
76268
|
+
default:
|
|
76269
|
+
throw new Error(`Invalid input string, length should be ${_UUID.STR_LENGTH} or ${_UUID.HEX_STR_LENGTH}`);
|
|
76270
|
+
}
|
|
76271
|
+
} else if (input instanceof _UUID) {
|
|
76272
|
+
return input.toBytes();
|
|
76273
|
+
} else if (ArrayBuffer.isView(input)) {
|
|
76274
|
+
return this.parseBytes(input);
|
|
76275
|
+
} else {
|
|
76276
|
+
throw new Error("Invalid input, Expected string or ArrayBufferView");
|
|
76277
|
+
}
|
|
76278
|
+
}
|
|
76279
|
+
/**
|
|
76280
|
+
* Creates a UUID from any supported input type.
|
|
76281
|
+
* @param input - The value to parse.
|
|
76282
|
+
* @returns A new {@link UUID} object.
|
|
76283
|
+
*/
|
|
76284
|
+
static from(input) {
|
|
76285
|
+
return this.fromBytes(_UUID.parse(input));
|
|
76286
|
+
}
|
|
76287
|
+
/** Returns the nil (all zero) UUID. */
|
|
76288
|
+
static nil() {
|
|
76289
|
+
return this.fromBytes(new Uint8Array(_UUID.BYTE_LENGTH));
|
|
76290
|
+
}
|
|
76291
|
+
/** Returns a UUID consisting of all 0xFF bytes. */
|
|
76292
|
+
static max() {
|
|
76293
|
+
return this.fromBytes(new Uint8Array(_UUID.BYTE_LENGTH).fill(255));
|
|
76294
|
+
}
|
|
76295
|
+
/* --------------------------------------------------------------------
|
|
76296
|
+
* Equality / comparison
|
|
76297
|
+
* -------------------------------------------------------------------- */
|
|
76298
|
+
/**
|
|
76299
|
+
* Compares multiple UUIDs for strict equality.
|
|
76300
|
+
* @param inputs - The UUIDs to compare (at least two required).
|
|
76301
|
+
* @returns true if all provided UUIDs are identical.
|
|
76302
|
+
*/
|
|
76303
|
+
static equals(...inputs) {
|
|
76304
|
+
const n = inputs.length;
|
|
76305
|
+
if (n < 2) {
|
|
76306
|
+
throw new Error("At least two UUIDs required for comparison");
|
|
76307
|
+
}
|
|
76308
|
+
const ref = this.parse(inputs[0]);
|
|
76309
|
+
for (let i = 1; i < n; ++i) {
|
|
76310
|
+
const b = this.parse(inputs[i]);
|
|
76311
|
+
for (let j = 0; j < _UUID.BYTE_LENGTH; ++j) {
|
|
76312
|
+
if (ref[j] !== b[j]) return false;
|
|
76313
|
+
}
|
|
76314
|
+
}
|
|
76315
|
+
return true;
|
|
76316
|
+
}
|
|
76317
|
+
/**
|
|
76318
|
+
* Lexicographically compares two UUIDs.
|
|
76319
|
+
* @param uuid1 - The first UUID.
|
|
76320
|
+
* @param uuid2 - The second UUID.
|
|
76321
|
+
* @returns -1 if uuid1 < uuid2, 1 if uuid1 > uuid2, 0 otherwise.
|
|
76322
|
+
*/
|
|
76323
|
+
static compare(uuid1, uuid2) {
|
|
76324
|
+
const a = this.parse(uuid1);
|
|
76325
|
+
const b = this.parse(uuid2);
|
|
76326
|
+
for (let i = 0; i < _UUID.BYTE_LENGTH; i++) {
|
|
76327
|
+
if (a[i] !== b[i]) return a[i] < b[i] ? -1 : 1;
|
|
76328
|
+
}
|
|
76329
|
+
return 0;
|
|
76330
|
+
}
|
|
76331
|
+
/* --------------------------------------------------------------------
|
|
76332
|
+
* Instance members
|
|
76333
|
+
* -------------------------------------------------------------------- */
|
|
76334
|
+
/** Raw byte representation of the UUID. */
|
|
76335
|
+
bytes;
|
|
76336
|
+
// Cached string and hex representations to avoid recomputation.
|
|
76337
|
+
_str;
|
|
76338
|
+
_hex;
|
|
76339
|
+
/**
|
|
76340
|
+
* Constructs a new {@link UUID} instance from any supported input type.
|
|
76341
|
+
* @param input - The value to parse (string or ArrayBufferView).
|
|
76342
|
+
*/
|
|
76343
|
+
constructor(input) {
|
|
76344
|
+
this.bytes = _UUID.parse(input);
|
|
76345
|
+
}
|
|
76346
|
+
/** Instance wrapper for {@link equals}. */
|
|
76347
|
+
equals(...inputs) {
|
|
76348
|
+
return _UUID.equals(this, ...inputs);
|
|
76349
|
+
}
|
|
76350
|
+
/** Instance wrapper for {@link compare}. */
|
|
76351
|
+
compare(other) {
|
|
76352
|
+
return _UUID.compare(this, other);
|
|
76353
|
+
}
|
|
76354
|
+
version() {
|
|
76355
|
+
return _UUID.version(this);
|
|
76356
|
+
}
|
|
76357
|
+
/**
|
|
76358
|
+
* Returns the RFC 4122 string representation of this UUID.
|
|
76359
|
+
* @returns The formatted UUID string.
|
|
76360
|
+
*/
|
|
76361
|
+
toString() {
|
|
76362
|
+
if (this._str != null) {
|
|
76363
|
+
return this._str;
|
|
76364
|
+
}
|
|
76365
|
+
const hex = this.toHex();
|
|
76366
|
+
this._str = _UUID.formatHex(hex);
|
|
76367
|
+
return this._str;
|
|
76368
|
+
}
|
|
76369
|
+
/**
|
|
76370
|
+
* Returns the plain hexadecimal representation of this UUID.
|
|
76371
|
+
* @returns A 32‑character hex string.
|
|
76372
|
+
*/
|
|
76373
|
+
toHex() {
|
|
76374
|
+
if (this._hex != null) {
|
|
76375
|
+
return this._hex;
|
|
76376
|
+
}
|
|
76377
|
+
this._hex = Uint8ArrayUtils2.toHex(this.bytes);
|
|
76378
|
+
return this._hex;
|
|
76379
|
+
}
|
|
76380
|
+
/**
|
|
76381
|
+
* Returns a copy of the raw byte array.
|
|
76382
|
+
* @returns A new Uint8Array containing the UUID bytes.
|
|
76383
|
+
*/
|
|
76384
|
+
toBytes() {
|
|
76385
|
+
return new Uint8Array(this.bytes);
|
|
76386
|
+
}
|
|
76387
|
+
/** JSON serialization helper – returns the RFC 4122 string. */
|
|
76388
|
+
toJSON() {
|
|
76389
|
+
return this.toString();
|
|
76390
|
+
}
|
|
76391
|
+
};
|
|
76392
|
+
var UUID22 = class extends UUID2 {
|
|
76393
|
+
toBuffer() {
|
|
76394
|
+
return Buffer.from(this.bytes);
|
|
76395
|
+
}
|
|
76396
|
+
};
|
|
76397
|
+
|
|
76082
76398
|
// src/nodejs/utils/sequelize-utils/SequelizeUtils.ts
|
|
76083
|
-
import { UUID as UUID2 } from "@powfix/uuid/node";
|
|
76084
76399
|
var SequelizeUtils = class _SequelizeUtils {
|
|
76085
76400
|
static decimal2Number(value) {
|
|
76086
76401
|
if (value === null || value === void 0) {
|
|
@@ -76098,7 +76413,7 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76098
76413
|
allowNull: false,
|
|
76099
76414
|
primaryKey: true,
|
|
76100
76415
|
unique: true,
|
|
76101
|
-
defaultValue: () =>
|
|
76416
|
+
defaultValue: () => UUID22.from(UuidUtils.v4()).toBuffer()
|
|
76102
76417
|
})
|
|
76103
76418
|
});
|
|
76104
76419
|
static buildUuidColumn(options) {
|
|
@@ -76108,10 +76423,10 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76108
76423
|
type: "binary(16)",
|
|
76109
76424
|
get() {
|
|
76110
76425
|
const value = this.getDataValue(columnName);
|
|
76111
|
-
return value != null ?
|
|
76426
|
+
return value != null ? UUID22.from(value) : value;
|
|
76112
76427
|
},
|
|
76113
76428
|
set(input) {
|
|
76114
|
-
const value = input != null ?
|
|
76429
|
+
const value = input != null ? UUID22.from(input).toBuffer() : input;
|
|
76115
76430
|
this.setDataValue(columnName, value);
|
|
76116
76431
|
},
|
|
76117
76432
|
...overrideOptions
|
|
@@ -76121,10 +76436,10 @@ var SequelizeUtils = class _SequelizeUtils {
|
|
|
76121
76436
|
type: "binary(16)",
|
|
76122
76437
|
get() {
|
|
76123
76438
|
const value = this.getDataValue(columnName);
|
|
76124
|
-
return
|
|
76439
|
+
return UUID22.from(value);
|
|
76125
76440
|
},
|
|
76126
76441
|
set(input) {
|
|
76127
|
-
const value =
|
|
76442
|
+
const value = UUID22.from(input).toBuffer();
|
|
76128
76443
|
this.setDataValue(columnName, value);
|
|
76129
76444
|
},
|
|
76130
76445
|
...overrideOptions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powfix/core-js",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "core package",
|
|
5
5
|
"author": "Kwon Kyung-Min <powfix@gmail.com>",
|
|
6
6
|
"private": false,
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"dist"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@powfix/uuid": "^0.1.2",
|
|
57
56
|
"base-64": "^1.0.0",
|
|
58
57
|
"eventemitter3": "^5.0.1",
|
|
59
58
|
"jwt-decode": "^4.0.0",
|
|
60
59
|
"uuid": "9.0.1"
|
|
61
60
|
},
|
|
62
61
|
"devDependencies": {
|
|
62
|
+
"@powfix/uuid": "^0.1.2",
|
|
63
63
|
"@types/base-64": "1.0.2",
|
|
64
64
|
"@types/node": "^24.5.1",
|
|
65
65
|
"@types/uuid": "9.0.7",
|