@orkestrel/database 0.0.9 → 0.0.11
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 +51 -17
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +22 -0
- package/dist/src/core/index.d.ts +22 -0
- package/dist/src/core/index.js +51 -18
- package/dist/src/core/index.js.map +1 -1
- package/package.json +14 -13
package/dist/src/core/index.cjs
CHANGED
|
@@ -385,6 +385,37 @@ function equalsValue(left, right) {
|
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
/**
|
|
388
|
+
* Match a query against a value as a case-insensitive ordered subsequence.
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* Every query character must appear in order in the value, but the characters
|
|
392
|
+
* do not need to be contiguous. Query characters are literal, including
|
|
393
|
+
* whitespace. Matching applies JavaScript `toLowerCase()` to both inputs
|
|
394
|
+
* without locale-specific folding or Unicode normalization. An empty query
|
|
395
|
+
* matches every value.
|
|
396
|
+
*
|
|
397
|
+
* @param value - The text searched for the query's characters
|
|
398
|
+
* @param query - The characters that must all appear in order
|
|
399
|
+
* @returns Whether the case-folded query is a subsequence of the case-folded value
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```ts
|
|
403
|
+
* matchesFuzzy('Database', 'dbe') // true
|
|
404
|
+
* matchesFuzzy('Database', 'abd') // false
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
function matchesFuzzy(value, query) {
|
|
408
|
+
const folded = value.toLowerCase();
|
|
409
|
+
const wanted = query.toLowerCase();
|
|
410
|
+
let cursor = 0;
|
|
411
|
+
for (const char of wanted) {
|
|
412
|
+
const found = folded.indexOf(char, cursor);
|
|
413
|
+
if (found === -1) return false;
|
|
414
|
+
cursor = found + 1;
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
388
419
|
* Match a value against a wildcard pattern in LINEAR time — the shared, ReDoS-SAFE
|
|
389
420
|
* engine behind {@link matchesLikePattern} and {@link matchesGlobPattern}.
|
|
390
421
|
*
|
|
@@ -3021,23 +3052,25 @@ var Table = class {
|
|
|
3021
3052
|
#prepare(row) {
|
|
3022
3053
|
if (!(0, _orkestrel_contract.isRecord)(row)) throw new DatabaseError("VALIDATION", `Row for table '${this.#name}' is not a record`, { table: this.#name });
|
|
3023
3054
|
const prepared = { ...row };
|
|
3024
|
-
if (prepared[this.#key] === void 0)
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
table
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
table
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3055
|
+
if (prepared[this.#key] === void 0) {
|
|
3056
|
+
if (this.#generate !== void 0) try {
|
|
3057
|
+
prepared[this.#key] = this.#generate();
|
|
3058
|
+
} catch (cause) {
|
|
3059
|
+
throw new DatabaseError("VALIDATION", `Failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
|
|
3060
|
+
table: this.#name,
|
|
3061
|
+
column: this.#key,
|
|
3062
|
+
cause
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
else try {
|
|
3066
|
+
prepared[this.#key] = crypto.randomUUID();
|
|
3067
|
+
} catch (cause) {
|
|
3068
|
+
throw new DatabaseError("DRIVER", `Host failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
|
|
3069
|
+
table: this.#name,
|
|
3070
|
+
column: this.#key,
|
|
3071
|
+
cause
|
|
3072
|
+
});
|
|
3073
|
+
}
|
|
3041
3074
|
}
|
|
3042
3075
|
return prepared;
|
|
3043
3076
|
}
|
|
@@ -3623,6 +3656,7 @@ exports.isMigrationInput = isMigrationInput;
|
|
|
3623
3656
|
exports.isMigrationStep = isMigrationStep;
|
|
3624
3657
|
exports.isTableSchema = isTableSchema;
|
|
3625
3658
|
exports.matchesCondition = matchesCondition;
|
|
3659
|
+
exports.matchesFuzzy = matchesFuzzy;
|
|
3626
3660
|
exports.matchesGlobPattern = matchesGlobPattern;
|
|
3627
3661
|
exports.matchesLikePattern = matchesLikePattern;
|
|
3628
3662
|
exports.matchesQuery = matchesQuery;
|