@onyx.dev/onyx-database 1.0.3 → 1.1.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/README.md CHANGED
@@ -20,6 +20,7 @@ TypeScript client SDK for **Onyx Cloud Database** — a zero-dependency, strict-
20
20
  - [Initialize the client](#initialize-the-client)
21
21
  - [Generate schema types](#optional-generate-typescript-types-from-your-schema)
22
22
  - [Query helpers](#query-helpers-at-a-glance)
23
+ - [Full-text search](#full-text-search-lucene)
23
24
  - [Examples](#usage-examples-with-user-role-permission)
24
25
  - [Error handling](#error-handling)
25
26
  - [HTTP retries](#http-retries)
@@ -410,7 +411,7 @@ import {
410
411
  between,
411
412
  gt, gte, lt, lte,
412
413
  like, notLike, contains, notContains,
413
- startsWith, notStartsWith, matches, notMatches,
414
+ startsWith, notStartsWith, matches, notMatches, search,
414
415
  isNull, notNull,
415
416
  asc, desc
416
417
  } from '@onyx.dev/onyx-database';
@@ -418,6 +419,7 @@ import {
418
419
 
419
420
  - Prefer `within`/`notWithin` for inclusion checks (supports arrays, comma-separated strings, or inner queries).
420
421
  - `inOp`/`notIn` remain available for backward compatibility and are exact aliases.
422
+ - `search(text, minScore?)` builds a Lucene `MATCHES` predicate on `__full_text__` and always serializes `minScore` (null when omitted).
421
423
 
422
424
  ### Inner queries (IN/NOT IN with sub-selects)
423
425
 
@@ -453,6 +455,36 @@ const rolesMissingPermission = await db
453
455
 
454
456
  ---
455
457
 
458
+ ## Full-text search (Lucene)
459
+
460
+ Use `.search(text, minScore?)` on a query builder for table-level full-text search, or call `db.search(...)` to target **all** tables (`table = "ALL"` in the request body). The search value always includes `minScore` and falls back to `null` when you omit it.
461
+
462
+ ```ts
463
+ import { desc, eq, onyx, search, tables, type Schema } from '@onyx.dev/onyx-database';
464
+
465
+ const db = onyx.init<Schema>();
466
+
467
+ // Table-specific search with a minimum score
468
+ const recentUsers = await db
469
+ .from(tables.User)
470
+ .search('user bio text', 4.4)
471
+ .orderBy(desc('createdAt'))
472
+ .limit(5)
473
+ .list();
474
+
475
+ // Search across all tables (table: "ALL")
476
+ const acrossTables = await db.search('user bio text').list({ pageSize: 5 });
477
+
478
+ // Combine a search predicate with other filters
479
+ const activeMatch = await db
480
+ .from(tables.User)
481
+ .where(search('user bio text'))
482
+ .and(eq('isActive', true))
483
+ .firstOrNull();
484
+ ```
485
+
486
+ ---
487
+
456
488
  ## Usage examples with `User`, `Role`, `Permission`
457
489
 
458
490
  > The examples assume your schema has tables named `User`, `Role`, and `Permission`.
@@ -7,6 +7,11 @@
7
7
  * ```
8
8
  */
9
9
  type QueryCriteriaOperator = 'EQUAL' | 'NOT_EQUAL' | 'IN' | 'NOT_IN' | 'GREATER_THAN' | 'GREATER_THAN_EQUAL' | 'LESS_THAN' | 'LESS_THAN_EQUAL' | 'MATCHES' | 'NOT_MATCHES' | 'BETWEEN' | 'LIKE' | 'NOT_LIKE' | 'CONTAINS' | 'CONTAINS_IGNORE_CASE' | 'NOT_CONTAINS' | 'NOT_CONTAINS_IGNORE_CASE' | 'STARTS_WITH' | 'NOT_STARTS_WITH' | 'IS_NULL' | 'NOT_NULL';
10
+ /** Value payload for full-text (Lucene) searches. */
11
+ interface FullTextQuery {
12
+ queryText: string;
13
+ minScore: number | null;
14
+ }
10
15
  /** Logical operator used to join conditions in a query. */
11
16
  type LogicalOperator = 'AND' | 'OR';
12
17
  /**
@@ -133,6 +138,7 @@ type QueryCondition = {
133
138
  */
134
139
  interface SelectQuery {
135
140
  type: 'SelectQuery';
141
+ table?: string | null;
136
142
  fields?: string[] | null;
137
143
  conditions?: QueryCondition | null;
138
144
  sort?: Sort[] | null;
@@ -473,6 +479,16 @@ interface IQueryBuilder<T = unknown> {
473
479
  * ```
474
480
  */
475
481
  resolve(...values: Array<string | string[]>): IQueryBuilder<T>;
482
+ /**
483
+ * Adds a Lucene full-text search predicate.
484
+ * @example
485
+ * ```ts
486
+ * const results = await db.from('User').search('hello world', 4.4).list();
487
+ * ```
488
+ * @param queryText - Text to match against `__full_text__`.
489
+ * @param minScore - Optional minimum score; serializes as `null` when omitted.
490
+ */
491
+ search(queryText: string, minScore?: number | null): IQueryBuilder<T>;
476
492
  /**
477
493
  * Adds a filter condition.
478
494
  * @example
@@ -861,6 +877,18 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
861
877
  * @param fields Field names to project; omit to select all.
862
878
  */
863
879
  select(...fields: string[]): IQueryBuilder<Record<string, unknown>>;
880
+ /**
881
+ * Run a Lucene full-text search across all tables.
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * const results = await db.search('hello world', 4.4).list();
886
+ * ```
887
+ *
888
+ * @param queryText Text to match against `__full_text__`.
889
+ * @param minScore Optional minimum score; serialized as `null` when omitted.
890
+ */
891
+ search(queryText: string, minScore?: number | null): IQueryBuilder<Record<string, unknown>>;
864
892
  /**
865
893
  * Include related records in the next save or delete.
866
894
  *
@@ -1395,6 +1423,7 @@ declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
1395
1423
  declare const lt: (field: string, value: unknown) => ConditionBuilderImpl;
1396
1424
  declare const lte: (field: string, value: unknown) => ConditionBuilderImpl;
1397
1425
  declare const matches: (field: string, regex: string) => ConditionBuilderImpl;
1426
+ declare const search: (queryText: string, minScore?: number | null) => ConditionBuilderImpl;
1398
1427
  declare const notMatches: (field: string, regex: string) => ConditionBuilderImpl;
1399
1428
  declare const like: (field: string, pattern: string) => ConditionBuilderImpl;
1400
1429
  declare const notLike: (field: string, pattern: string) => ConditionBuilderImpl;
@@ -1421,4 +1450,4 @@ declare const substring: (attribute: string, from: number, length: number) => st
1421
1450
  declare const replace: (attribute: string, pattern: string, repl: string) => string;
1422
1451
  declare const percentile: (attribute: string, p: number) => string;
1423
1452
 
1424
- export { within as $, type QueryCriteriaOperator as A, type Sort as B, type StreamAction as C, type OnyxDocument as D, type FetchImpl as E, type FetchResponse as F, type QueryCriteria as G, type QueryCondition as H, type IOnyxDatabase as I, type SelectQuery as J, type QueryPage as K, type LogicalOperator as L, type IConditionBuilder as M, type IQueryBuilder as N, type OnyxFacade as O, type ISaveBuilder as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type ICascadeBuilder as T, type UpdateQuery as U, type ICascadeRelationshipBuilder as V, asc as W, desc as X, eq as Y, neq as Z, inOp as _, type QueryResultsPromise as a, notIn as a0, notWithin as a1, between as a2, gt as a3, gte as a4, lt as a5, lte as a6, matches as a7, notMatches as a8, like as a9, notLike as aa, contains as ab, containsIgnoreCase as ac, notContains as ad, notContainsIgnoreCase as ae, startsWith as af, notStartsWith as ag, isNull as ah, notNull as ai, avg as aj, sum as ak, count as al, min as am, max as an, std as ao, variance as ap, median as aq, upper as ar, lower as as, substring as at, replace as au, percentile as av, type OnyxConfig as b, type SecretRecord as c, type SecretsListResponse as d, type SecretSaveRequest as e, type SchemaDataType as f, type SchemaIdentifierGenerator as g, type SchemaIdentifier as h, type SchemaAttribute as i, type SchemaIndexType as j, type SchemaIndex as k, type SchemaResolver as l, type SchemaTriggerEvent as m, type SchemaTrigger as n, type SchemaEntity as o, type SchemaRevisionMetadata as p, type SchemaRevision as q, type SchemaHistoryEntry as r, type SchemaUpsertRequest as s, type SchemaValidationResult as t, type SchemaAttributeChange as u, type SchemaIndexChange as v, type SchemaResolverChange as w, type SchemaTriggerChange as x, type SchemaTableDiff as y, type SchemaDiff as z };
1453
+ export { inOp as $, type QueryCriteriaOperator as A, type Sort as B, type StreamAction as C, type OnyxDocument as D, type FetchResponse as E, type FullTextQuery as F, type FetchImpl as G, type QueryCriteria as H, type IOnyxDatabase as I, type QueryCondition as J, type SelectQuery as K, type LogicalOperator as L, type QueryPage as M, type IConditionBuilder as N, type OnyxFacade as O, type IQueryBuilder as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type ISaveBuilder as T, type UpdateQuery as U, type ICascadeBuilder as V, type ICascadeRelationshipBuilder as W, asc as X, desc as Y, eq as Z, neq as _, type QueryResultsPromise as a, within as a0, notIn as a1, notWithin as a2, between as a3, gt as a4, gte as a5, lt as a6, lte as a7, matches as a8, search as a9, notMatches as aa, like as ab, notLike as ac, contains as ad, containsIgnoreCase as ae, notContains as af, notContainsIgnoreCase as ag, startsWith as ah, notStartsWith as ai, isNull as aj, notNull as ak, avg as al, sum as am, count as an, min as ao, max as ap, std as aq, variance as ar, median as as, upper as at, lower as au, substring as av, replace as aw, percentile as ax, type OnyxConfig as b, type SecretRecord as c, type SecretsListResponse as d, type SecretSaveRequest as e, type SchemaDataType as f, type SchemaIdentifierGenerator as g, type SchemaIdentifier as h, type SchemaAttribute as i, type SchemaIndexType as j, type SchemaIndex as k, type SchemaResolver as l, type SchemaTriggerEvent as m, type SchemaTrigger as n, type SchemaEntity as o, type SchemaRevisionMetadata as p, type SchemaRevision as q, type SchemaHistoryEntry as r, type SchemaUpsertRequest as s, type SchemaValidationResult as t, type SchemaAttributeChange as u, type SchemaIndexChange as v, type SchemaResolverChange as w, type SchemaTriggerChange as x, type SchemaTableDiff as y, type SchemaDiff as z };
@@ -7,6 +7,11 @@
7
7
  * ```
8
8
  */
9
9
  type QueryCriteriaOperator = 'EQUAL' | 'NOT_EQUAL' | 'IN' | 'NOT_IN' | 'GREATER_THAN' | 'GREATER_THAN_EQUAL' | 'LESS_THAN' | 'LESS_THAN_EQUAL' | 'MATCHES' | 'NOT_MATCHES' | 'BETWEEN' | 'LIKE' | 'NOT_LIKE' | 'CONTAINS' | 'CONTAINS_IGNORE_CASE' | 'NOT_CONTAINS' | 'NOT_CONTAINS_IGNORE_CASE' | 'STARTS_WITH' | 'NOT_STARTS_WITH' | 'IS_NULL' | 'NOT_NULL';
10
+ /** Value payload for full-text (Lucene) searches. */
11
+ interface FullTextQuery {
12
+ queryText: string;
13
+ minScore: number | null;
14
+ }
10
15
  /** Logical operator used to join conditions in a query. */
11
16
  type LogicalOperator = 'AND' | 'OR';
12
17
  /**
@@ -133,6 +138,7 @@ type QueryCondition = {
133
138
  */
134
139
  interface SelectQuery {
135
140
  type: 'SelectQuery';
141
+ table?: string | null;
136
142
  fields?: string[] | null;
137
143
  conditions?: QueryCondition | null;
138
144
  sort?: Sort[] | null;
@@ -473,6 +479,16 @@ interface IQueryBuilder<T = unknown> {
473
479
  * ```
474
480
  */
475
481
  resolve(...values: Array<string | string[]>): IQueryBuilder<T>;
482
+ /**
483
+ * Adds a Lucene full-text search predicate.
484
+ * @example
485
+ * ```ts
486
+ * const results = await db.from('User').search('hello world', 4.4).list();
487
+ * ```
488
+ * @param queryText - Text to match against `__full_text__`.
489
+ * @param minScore - Optional minimum score; serializes as `null` when omitted.
490
+ */
491
+ search(queryText: string, minScore?: number | null): IQueryBuilder<T>;
476
492
  /**
477
493
  * Adds a filter condition.
478
494
  * @example
@@ -861,6 +877,18 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
861
877
  * @param fields Field names to project; omit to select all.
862
878
  */
863
879
  select(...fields: string[]): IQueryBuilder<Record<string, unknown>>;
880
+ /**
881
+ * Run a Lucene full-text search across all tables.
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * const results = await db.search('hello world', 4.4).list();
886
+ * ```
887
+ *
888
+ * @param queryText Text to match against `__full_text__`.
889
+ * @param minScore Optional minimum score; serialized as `null` when omitted.
890
+ */
891
+ search(queryText: string, minScore?: number | null): IQueryBuilder<Record<string, unknown>>;
864
892
  /**
865
893
  * Include related records in the next save or delete.
866
894
  *
@@ -1395,6 +1423,7 @@ declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
1395
1423
  declare const lt: (field: string, value: unknown) => ConditionBuilderImpl;
1396
1424
  declare const lte: (field: string, value: unknown) => ConditionBuilderImpl;
1397
1425
  declare const matches: (field: string, regex: string) => ConditionBuilderImpl;
1426
+ declare const search: (queryText: string, minScore?: number | null) => ConditionBuilderImpl;
1398
1427
  declare const notMatches: (field: string, regex: string) => ConditionBuilderImpl;
1399
1428
  declare const like: (field: string, pattern: string) => ConditionBuilderImpl;
1400
1429
  declare const notLike: (field: string, pattern: string) => ConditionBuilderImpl;
@@ -1421,4 +1450,4 @@ declare const substring: (attribute: string, from: number, length: number) => st
1421
1450
  declare const replace: (attribute: string, pattern: string, repl: string) => string;
1422
1451
  declare const percentile: (attribute: string, p: number) => string;
1423
1452
 
1424
- export { within as $, type QueryCriteriaOperator as A, type Sort as B, type StreamAction as C, type OnyxDocument as D, type FetchImpl as E, type FetchResponse as F, type QueryCriteria as G, type QueryCondition as H, type IOnyxDatabase as I, type SelectQuery as J, type QueryPage as K, type LogicalOperator as L, type IConditionBuilder as M, type IQueryBuilder as N, type OnyxFacade as O, type ISaveBuilder as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type ICascadeBuilder as T, type UpdateQuery as U, type ICascadeRelationshipBuilder as V, asc as W, desc as X, eq as Y, neq as Z, inOp as _, type QueryResultsPromise as a, notIn as a0, notWithin as a1, between as a2, gt as a3, gte as a4, lt as a5, lte as a6, matches as a7, notMatches as a8, like as a9, notLike as aa, contains as ab, containsIgnoreCase as ac, notContains as ad, notContainsIgnoreCase as ae, startsWith as af, notStartsWith as ag, isNull as ah, notNull as ai, avg as aj, sum as ak, count as al, min as am, max as an, std as ao, variance as ap, median as aq, upper as ar, lower as as, substring as at, replace as au, percentile as av, type OnyxConfig as b, type SecretRecord as c, type SecretsListResponse as d, type SecretSaveRequest as e, type SchemaDataType as f, type SchemaIdentifierGenerator as g, type SchemaIdentifier as h, type SchemaAttribute as i, type SchemaIndexType as j, type SchemaIndex as k, type SchemaResolver as l, type SchemaTriggerEvent as m, type SchemaTrigger as n, type SchemaEntity as o, type SchemaRevisionMetadata as p, type SchemaRevision as q, type SchemaHistoryEntry as r, type SchemaUpsertRequest as s, type SchemaValidationResult as t, type SchemaAttributeChange as u, type SchemaIndexChange as v, type SchemaResolverChange as w, type SchemaTriggerChange as x, type SchemaTableDiff as y, type SchemaDiff as z };
1453
+ export { inOp as $, type QueryCriteriaOperator as A, type Sort as B, type StreamAction as C, type OnyxDocument as D, type FetchResponse as E, type FullTextQuery as F, type FetchImpl as G, type QueryCriteria as H, type IOnyxDatabase as I, type QueryCondition as J, type SelectQuery as K, type LogicalOperator as L, type QueryPage as M, type IConditionBuilder as N, type OnyxFacade as O, type IQueryBuilder as P, QueryResults as Q, type RetryOptions as R, type SecretMetadata as S, type ISaveBuilder as T, type UpdateQuery as U, type ICascadeBuilder as V, type ICascadeRelationshipBuilder as W, asc as X, desc as Y, eq as Z, neq as _, type QueryResultsPromise as a, within as a0, notIn as a1, notWithin as a2, between as a3, gt as a4, gte as a5, lt as a6, lte as a7, matches as a8, search as a9, notMatches as aa, like as ab, notLike as ac, contains as ad, containsIgnoreCase as ae, notContains as af, notContainsIgnoreCase as ag, startsWith as ah, notStartsWith as ai, isNull as aj, notNull as ak, avg as al, sum as am, count as an, min as ao, max as ap, std as aq, variance as ar, median as as, upper as at, lower as au, substring as av, replace as aw, percentile as ax, type OnyxConfig as b, type SecretRecord as c, type SecretsListResponse as d, type SecretSaveRequest as e, type SchemaDataType as f, type SchemaIdentifierGenerator as g, type SchemaIdentifier as h, type SchemaAttribute as i, type SchemaIndexType as j, type SchemaIndex as k, type SchemaResolver as l, type SchemaTriggerEvent as m, type SchemaTrigger as n, type SchemaEntity as o, type SchemaRevisionMetadata as p, type SchemaRevision as q, type SchemaHistoryEntry as r, type SchemaUpsertRequest as s, type SchemaValidationResult as t, type SchemaAttributeChange as u, type SchemaIndexChange as v, type SchemaResolverChange as w, type SchemaTriggerChange as x, type SchemaTableDiff as y, type SchemaDiff as z };
package/dist/edge.cjs CHANGED
@@ -1179,6 +1179,14 @@ var OnyxDatabaseImpl = class {
1179
1179
  qb.select(...fields);
1180
1180
  return qb;
1181
1181
  }
1182
+ search(queryText, minScore) {
1183
+ const qb = new QueryBuilderImpl(
1184
+ this,
1185
+ "ALL",
1186
+ this.defaultPartition
1187
+ );
1188
+ return qb.search(queryText, minScore);
1189
+ }
1182
1190
  cascade(...relationships) {
1183
1191
  const cb = new CascadeBuilderImpl(this);
1184
1192
  return cb.cascade(...relationships);
@@ -1465,6 +1473,7 @@ var QueryBuilderImpl = class {
1465
1473
  toSelectQuery() {
1466
1474
  return {
1467
1475
  type: "SelectQuery",
1476
+ table: this.table,
1468
1477
  fields: this.fields,
1469
1478
  conditions: this.serializableConditions(),
1470
1479
  sort: this.sort,
@@ -1504,6 +1513,13 @@ var QueryBuilderImpl = class {
1504
1513
  this.resolvers = flat.length > 0 ? flat : null;
1505
1514
  return this;
1506
1515
  }
1516
+ search(queryText, minScore) {
1517
+ return this.and({
1518
+ field: "__full_text__",
1519
+ operator: "MATCHES",
1520
+ value: { queryText, minScore: minScore ?? null }
1521
+ });
1522
+ }
1507
1523
  where(condition) {
1508
1524
  const c2 = toCondition(condition);
1509
1525
  if (!this.conditions) {
@@ -1855,6 +1871,10 @@ var ConditionBuilderImpl = class {
1855
1871
 
1856
1872
  // src/helpers/conditions.ts
1857
1873
  var c = (field, operator, value) => new ConditionBuilderImpl({ field, operator, value });
1874
+ var fullText = (queryText, minScore) => ({
1875
+ queryText,
1876
+ minScore: minScore ?? null
1877
+ });
1858
1878
  var eq = (field, value) => c(field, "EQUAL", value);
1859
1879
  var neq = (field, value) => c(field, "NOT_EQUAL", value);
1860
1880
  function inOp(field, values) {
@@ -1877,6 +1897,7 @@ var gte = (field, value) => c(field, "GREATER_THAN_EQUAL", value);
1877
1897
  var lt = (field, value) => c(field, "LESS_THAN", value);
1878
1898
  var lte = (field, value) => c(field, "LESS_THAN_EQUAL", value);
1879
1899
  var matches = (field, regex) => c(field, "MATCHES", regex);
1900
+ var search = (queryText, minScore) => c("__full_text__", "MATCHES", fullText(queryText, minScore));
1880
1901
  var notMatches = (field, regex) => c(field, "NOT_MATCHES", regex);
1881
1902
  var like = (field, pattern) => c(field, "LIKE", pattern);
1882
1903
  var notLike = (field, pattern) => c(field, "NOT_LIKE", pattern);
@@ -1943,6 +1964,7 @@ exports.percentile = percentile;
1943
1964
  exports.replace = replace;
1944
1965
  exports.sdkName = sdkName;
1945
1966
  exports.sdkVersion = sdkVersion;
1967
+ exports.search = search;
1946
1968
  exports.startsWith = startsWith;
1947
1969
  exports.std = std;
1948
1970
  exports.substring = substring;