@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.
@@ -866,6 +866,28 @@ export declare type KeyFunction = () => Key;
866
866
  */
867
867
  export declare function matchesCondition(row: Row, condition: Condition): boolean;
868
868
 
869
+ /**
870
+ * Match a query against a value as a case-insensitive ordered subsequence.
871
+ *
872
+ * @remarks
873
+ * Every query character must appear in order in the value, but the characters
874
+ * do not need to be contiguous. Query characters are literal, including
875
+ * whitespace. Matching applies JavaScript `toLowerCase()` to both inputs
876
+ * without locale-specific folding or Unicode normalization. An empty query
877
+ * matches every value.
878
+ *
879
+ * @param value - The text searched for the query's characters
880
+ * @param query - The characters that must all appear in order
881
+ * @returns Whether the case-folded query is a subsequence of the case-folded value
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * matchesFuzzy('Database', 'dbe') // true
886
+ * matchesFuzzy('Database', 'abd') // false
887
+ * ```
888
+ */
889
+ export declare function matchesFuzzy(value: string, query: string): boolean;
890
+
869
891
  export declare function matchesGlobPattern(value: string, pattern: string): boolean;
870
892
 
871
893
  export declare function matchesLikePattern(value: string, pattern: string): boolean;
@@ -866,6 +866,28 @@ export declare type KeyFunction = () => Key;
866
866
  */
867
867
  export declare function matchesCondition(row: Row, condition: Condition): boolean;
868
868
 
869
+ /**
870
+ * Match a query against a value as a case-insensitive ordered subsequence.
871
+ *
872
+ * @remarks
873
+ * Every query character must appear in order in the value, but the characters
874
+ * do not need to be contiguous. Query characters are literal, including
875
+ * whitespace. Matching applies JavaScript `toLowerCase()` to both inputs
876
+ * without locale-specific folding or Unicode normalization. An empty query
877
+ * matches every value.
878
+ *
879
+ * @param value - The text searched for the query's characters
880
+ * @param query - The characters that must all appear in order
881
+ * @returns Whether the case-folded query is a subsequence of the case-folded value
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * matchesFuzzy('Database', 'dbe') // true
886
+ * matchesFuzzy('Database', 'abd') // false
887
+ * ```
888
+ */
889
+ export declare function matchesFuzzy(value: string, query: string): boolean;
890
+
869
891
  export declare function matchesGlobPattern(value: string, pattern: string): boolean;
870
892
 
871
893
  export declare function matchesLikePattern(value: string, pattern: string): boolean;
@@ -384,6 +384,37 @@ function equalsValue(left, right) {
384
384
  }
385
385
  }
386
386
  /**
387
+ * Match a query against a value as a case-insensitive ordered subsequence.
388
+ *
389
+ * @remarks
390
+ * Every query character must appear in order in the value, but the characters
391
+ * do not need to be contiguous. Query characters are literal, including
392
+ * whitespace. Matching applies JavaScript `toLowerCase()` to both inputs
393
+ * without locale-specific folding or Unicode normalization. An empty query
394
+ * matches every value.
395
+ *
396
+ * @param value - The text searched for the query's characters
397
+ * @param query - The characters that must all appear in order
398
+ * @returns Whether the case-folded query is a subsequence of the case-folded value
399
+ *
400
+ * @example
401
+ * ```ts
402
+ * matchesFuzzy('Database', 'dbe') // true
403
+ * matchesFuzzy('Database', 'abd') // false
404
+ * ```
405
+ */
406
+ function matchesFuzzy(value, query) {
407
+ const folded = value.toLowerCase();
408
+ const wanted = query.toLowerCase();
409
+ let cursor = 0;
410
+ for (const char of wanted) {
411
+ const found = folded.indexOf(char, cursor);
412
+ if (found === -1) return false;
413
+ cursor = found + 1;
414
+ }
415
+ return true;
416
+ }
417
+ /**
387
418
  * Match a value against a wildcard pattern in LINEAR time — the shared, ReDoS-SAFE
388
419
  * engine behind {@link matchesLikePattern} and {@link matchesGlobPattern}.
389
420
  *
@@ -3020,23 +3051,25 @@ var Table = class {
3020
3051
  #prepare(row) {
3021
3052
  if (!isRecord(row)) throw new DatabaseError("VALIDATION", `Row for table '${this.#name}' is not a record`, { table: this.#name });
3022
3053
  const prepared = { ...row };
3023
- if (prepared[this.#key] === void 0) if (this.#generate !== void 0) try {
3024
- prepared[this.#key] = this.#generate();
3025
- } catch (cause) {
3026
- throw new DatabaseError("VALIDATION", `Failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
3027
- table: this.#name,
3028
- column: this.#key,
3029
- cause
3030
- });
3031
- }
3032
- else try {
3033
- prepared[this.#key] = crypto.randomUUID();
3034
- } catch (cause) {
3035
- throw new DatabaseError("DRIVER", `Host failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
3036
- table: this.#name,
3037
- column: this.#key,
3038
- cause
3039
- });
3054
+ if (prepared[this.#key] === void 0) {
3055
+ if (this.#generate !== void 0) try {
3056
+ prepared[this.#key] = this.#generate();
3057
+ } catch (cause) {
3058
+ throw new DatabaseError("VALIDATION", `Failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
3059
+ table: this.#name,
3060
+ column: this.#key,
3061
+ cause
3062
+ });
3063
+ }
3064
+ else try {
3065
+ prepared[this.#key] = crypto.randomUUID();
3066
+ } catch (cause) {
3067
+ throw new DatabaseError("DRIVER", `Host failed to generate primary column '${this.#key}' for table '${this.#name}'`, {
3068
+ table: this.#name,
3069
+ column: this.#key,
3070
+ cause
3071
+ });
3072
+ }
3040
3073
  }
3041
3074
  return prepared;
3042
3075
  }
@@ -3591,6 +3624,6 @@ function createMemoryDriver() {
3591
3624
  return new MemoryDriver();
3592
3625
  }
3593
3626
  //#endregion
3594
- export { DEFAULT_PRIMARY, Database, DatabaseError, MAX_PATTERN_LENGTH, MemoryDriver, applyQuery, auditDriver, bindRowKey, checkAbort, cloneDriverMetadata, cloneDriverSchema, cloneMigrationInput, compareValues, computeAggregate, conformDriver, createDatabase, createMemoryDriver, driverFindings, equalsValue, extractKey, filterRows, isColumnSchema, isDatabaseError, isDriverMetadata, isDriverSchema, isKey, isMigration, isMigrationInput, isMigrationStep, isTableSchema, matchesCondition, matchesGlobPattern, matchesLikePattern, matchesQuery, matchesWildcardPattern, migrateRows, normalizeDriverSchema, planMigration, projectMigrationSchema, shapeToColumnSchema, shapeToColumnStorage, sortRows, validatePage };
3627
+ export { DEFAULT_PRIMARY, Database, DatabaseError, MAX_PATTERN_LENGTH, MemoryDriver, applyQuery, auditDriver, bindRowKey, checkAbort, cloneDriverMetadata, cloneDriverSchema, cloneMigrationInput, compareValues, computeAggregate, conformDriver, createDatabase, createMemoryDriver, driverFindings, equalsValue, extractKey, filterRows, isColumnSchema, isDatabaseError, isDriverMetadata, isDriverSchema, isKey, isMigration, isMigrationInput, isMigrationStep, isTableSchema, matchesCondition, matchesFuzzy, matchesGlobPattern, matchesLikePattern, matchesQuery, matchesWildcardPattern, migrateRows, normalizeDriverSchema, planMigration, projectMigrationSchema, shapeToColumnSchema, shapeToColumnStorage, sortRows, validatePage };
3595
3628
 
3596
3629
  //# sourceMappingURL=index.js.map