search-input-query-parser 0.4.0 → 0.5.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.
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.searchStringToParadeDbSql = exports.searchQueryToParadeDbSql = exports.searchStringToIlikeSql = exports.searchQueryToIlikeSql = exports.searchStringToTsVectorSql = exports.searchQueryToTsVectorSql = exports.searchStringToSql = exports.searchQueryToSql = exports.parseExpression = void 0;
18
+ // Re-export everything from parser.ts
19
+ __exportStar(require("./parser"), exports);
20
+ // Re-export everything from validator.ts
21
+ __exportStar(require("./validator"), exports);
22
+ // Re-export everything from lexer.ts
23
+ __exportStar(require("./lexer"), exports);
24
+ // Re-export everything from first-pass-parser.ts with renamed types to avoid conflicts
25
+ var first_pass_parser_1 = require("./first-pass-parser");
26
+ Object.defineProperty(exports, "parseExpression", { enumerable: true, get: function () { return first_pass_parser_1.parseExpression; } });
27
+ // Re-export SQL-related files with renamed types to avoid conflicts
28
+ var search_query_to_sql_1 = require("./search-query-to-sql");
29
+ Object.defineProperty(exports, "searchQueryToSql", { enumerable: true, get: function () { return search_query_to_sql_1.searchQueryToSql; } });
30
+ Object.defineProperty(exports, "searchStringToSql", { enumerable: true, get: function () { return search_query_to_sql_1.searchStringToSql; } });
31
+ var search_query_to_tsvector_sql_1 = require("./search-query-to-tsvector-sql");
32
+ Object.defineProperty(exports, "searchQueryToTsVectorSql", { enumerable: true, get: function () { return search_query_to_tsvector_sql_1.searchQueryToTsVectorSql; } });
33
+ Object.defineProperty(exports, "searchStringToTsVectorSql", { enumerable: true, get: function () { return search_query_to_tsvector_sql_1.searchStringToTsVectorSql; } });
34
+ var search_query_to_ilike_sql_1 = require("./search-query-to-ilike-sql");
35
+ Object.defineProperty(exports, "searchQueryToIlikeSql", { enumerable: true, get: function () { return search_query_to_ilike_sql_1.searchQueryToIlikeSql; } });
36
+ Object.defineProperty(exports, "searchStringToIlikeSql", { enumerable: true, get: function () { return search_query_to_ilike_sql_1.searchStringToIlikeSql; } });
37
+ var search_query_to_paradedb_sql_1 = require("./search-query-to-paradedb-sql");
38
+ Object.defineProperty(exports, "searchQueryToParadeDbSql", { enumerable: true, get: function () { return search_query_to_paradedb_sql_1.searchQueryToParadeDbSql; } });
39
+ Object.defineProperty(exports, "searchStringToParadeDbSql", { enumerable: true, get: function () { return search_query_to_paradedb_sql_1.searchStringToParadeDbSql; } });
40
+ // Re-export utility functions
41
+ __exportStar(require("./validate-expression-fields"), exports);
42
+ __exportStar(require("./validate-string"), exports);
43
+ __exportStar(require("./validate-wildcard"), exports);
44
+ __exportStar(require("./validate-in-expression"), exports);
45
+ __exportStar(require("./parse-in-values"), exports);
46
+ __exportStar(require("./parse-primary"), exports);
47
+ __exportStar(require("./parse-range-expression"), exports);
48
+ __exportStar(require("./transform-to-expression"), exports);
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringify = exports.SearchQueryErrorCode = exports.parseSearchInputQuery = void 0;
3
+ exports.parseSearchInputQuery = exports.stringify = void 0;
4
4
  const lexer_1 = require("./lexer");
5
5
  const first_pass_parser_1 = require("./first-pass-parser");
6
6
  const validator_1 = require("./validator");
7
- Object.defineProperty(exports, "SearchQueryErrorCode", { enumerable: true, get: function () { return validator_1.SearchQueryErrorCode; } });
8
7
  const validate_expression_fields_1 = require("./validate-expression-fields");
9
8
  const transform_to_expression_1 = require("./transform-to-expression");
10
9
  // Helper function to stringify expressions
@@ -23,11 +22,11 @@ const stringify = (expr) => {
23
22
  }
24
23
  return `${expr.field.value}:${expr.operator}${expr.value.value}`;
25
24
  case "NOT":
26
- return `NOT (${stringify(expr.expression)})`;
25
+ return `NOT (${(0, exports.stringify)(expr.expression)})`;
27
26
  case "AND":
28
- return `(${stringify(expr.left)} AND ${stringify(expr.right)})`;
27
+ return `(${(0, exports.stringify)(expr.left)} AND ${(0, exports.stringify)(expr.right)})`;
29
28
  case "OR":
30
- return `(${stringify(expr.left)} OR ${stringify(expr.right)})`;
29
+ return `(${(0, exports.stringify)(expr.left)} OR ${(0, exports.stringify)(expr.right)})`;
31
30
  case "IN": {
32
31
  const values = expr.values.map((v) => v.value).join(",");
33
32
  return `${expr.field.value}:IN(${values})`;
@@ -0,0 +1,22 @@
1
+ // Re-export everything from parser.ts
2
+ export * from "./parser";
3
+ // Re-export everything from validator.ts
4
+ export * from "./validator";
5
+ // Re-export everything from lexer.ts
6
+ export * from "./lexer";
7
+ // Re-export everything from first-pass-parser.ts with renamed types to avoid conflicts
8
+ export { parseExpression, } from "./first-pass-parser";
9
+ // Re-export SQL-related files with renamed types to avoid conflicts
10
+ export { searchQueryToSql, searchStringToSql, } from "./search-query-to-sql";
11
+ export { searchQueryToTsVectorSql, searchStringToTsVectorSql, } from "./search-query-to-tsvector-sql";
12
+ export { searchQueryToIlikeSql, searchStringToIlikeSql, } from "./search-query-to-ilike-sql";
13
+ export { searchQueryToParadeDbSql, searchStringToParadeDbSql, } from "./search-query-to-paradedb-sql";
14
+ // Re-export utility functions
15
+ export * from "./validate-expression-fields";
16
+ export * from "./validate-string";
17
+ export * from "./validate-wildcard";
18
+ export * from "./validate-in-expression";
19
+ export * from "./parse-in-values";
20
+ export * from "./parse-primary";
21
+ export * from "./parse-range-expression";
22
+ export * from "./transform-to-expression";
@@ -4,7 +4,7 @@ import { validateSearchQuery, SearchQueryErrorCode, } from "./validator";
4
4
  import { validateExpressionFields } from "./validate-expression-fields";
5
5
  import { transformToExpression } from "./transform-to-expression";
6
6
  // Helper function to stringify expressions
7
- const stringify = (expr) => {
7
+ export const stringify = (expr) => {
8
8
  var _a;
9
9
  switch (expr.type) {
10
10
  case "SEARCH_TERM":
@@ -79,4 +79,3 @@ export const parseSearchInputQuery = (input, fieldSchemas = []) => {
79
79
  };
80
80
  }
81
81
  };
82
- export { SearchQueryErrorCode, stringify, };
@@ -0,0 +1,16 @@
1
+ export * from "./parser";
2
+ export * from "./validator";
3
+ export * from "./lexer";
4
+ export { parseExpression, type PositionLength, type StringLiteral, type WildcardPattern as FirstPassWildcardPattern, type AndExpression, type OrExpression, type NotExpression, type InExpression as FirstPassInExpression, type FirstPassExpression, type ParseResult, } from "./first-pass-parser";
5
+ export { searchQueryToSql, searchStringToSql, type SqlQueryResult as SqlQueryResultBase, type SearchType, type SearchQueryOptions as SearchQueryOptionsBase, } from "./search-query-to-sql";
6
+ export { searchQueryToTsVectorSql, searchStringToTsVectorSql, type SqlQueryResult as TsVectorSqlQueryResult, type SearchQueryOptions as TsVectorSearchQueryOptions, } from "./search-query-to-tsvector-sql";
7
+ export { searchQueryToIlikeSql, searchStringToIlikeSql, type SqlQueryResult as IlikeSqlQueryResult, type SearchQueryOptions as IlikeSearchQueryOptions, } from "./search-query-to-ilike-sql";
8
+ export { searchQueryToParadeDbSql, searchStringToParadeDbSql, type SqlQueryResult as ParadeDbSqlQueryResult, type SearchQueryOptions as ParadeDbSearchQueryOptions, } from "./search-query-to-paradedb-sql";
9
+ export * from "./validate-expression-fields";
10
+ export * from "./validate-string";
11
+ export * from "./validate-wildcard";
12
+ export * from "./validate-in-expression";
13
+ export * from "./parse-in-values";
14
+ export * from "./parse-primary";
15
+ export * from "./parse-range-expression";
16
+ export * from "./transform-to-expression";
@@ -1,28 +1,28 @@
1
1
  import { PositionLength } from "./first-pass-parser";
2
- import { ValidationError, SearchQueryErrorCode } from "./validator";
3
- interface FieldSchema {
2
+ import { ValidationError } from "./validator";
3
+ export interface FieldSchema {
4
4
  name: string;
5
5
  type: "string" | "number" | "date" | "boolean";
6
6
  }
7
- type SearchTerm = {
7
+ export type SearchTerm = {
8
8
  readonly type: "SEARCH_TERM";
9
9
  readonly value: string;
10
10
  } & PositionLength;
11
- type WildcardPattern = {
11
+ export type WildcardPattern = {
12
12
  readonly type: "WILDCARD";
13
13
  readonly prefix: string;
14
14
  readonly quoted: boolean;
15
15
  } & PositionLength;
16
- type Field = {
16
+ export type Field = {
17
17
  readonly type: "FIELD";
18
18
  readonly value: string;
19
19
  } & PositionLength;
20
- type Value = {
20
+ export type Value = {
21
21
  readonly type: "VALUE";
22
22
  readonly value: string;
23
23
  } & PositionLength;
24
- type RangeOperator = ">=" | ">" | "<=" | "<" | "BETWEEN";
25
- type RangeExpression = {
24
+ export type RangeOperator = ">=" | ">" | "<=" | "<" | "BETWEEN";
25
+ export type RangeExpression = {
26
26
  readonly type: "RANGE";
27
27
  readonly field: Field;
28
28
  readonly operator: RangeOperator;
@@ -34,35 +34,34 @@ export type FieldValue = {
34
34
  readonly field: Field;
35
35
  readonly value: Value;
36
36
  };
37
- type And = {
37
+ export type And = {
38
38
  readonly type: "AND";
39
39
  readonly left: Expression;
40
40
  readonly right: Expression;
41
41
  } & PositionLength;
42
- type Or = {
42
+ export type Or = {
43
43
  readonly type: "OR";
44
44
  readonly left: Expression;
45
45
  readonly right: Expression;
46
46
  } & PositionLength;
47
- type Not = {
47
+ export type Not = {
48
48
  readonly type: "NOT";
49
49
  readonly expression: Expression;
50
50
  } & PositionLength;
51
- type InExpression = {
51
+ export type InExpression = {
52
52
  readonly type: "IN";
53
53
  readonly field: Field;
54
54
  readonly values: Value[];
55
55
  } & PositionLength;
56
- type Expression = SearchTerm | WildcardPattern | FieldValue | RangeExpression | And | Or | Not | InExpression;
57
- type SearchQuery = {
56
+ export type Expression = SearchTerm | WildcardPattern | FieldValue | RangeExpression | And | Or | Not | InExpression;
57
+ export type SearchQuery = {
58
58
  readonly type: "SEARCH_QUERY";
59
59
  readonly expression: Expression | null;
60
60
  };
61
- type SearchQueryError = {
61
+ export type SearchQueryError = {
62
62
  readonly type: "SEARCH_QUERY_ERROR";
63
63
  readonly expression: null;
64
64
  readonly errors: ValidationError[];
65
65
  };
66
- declare const stringify: (expr: Expression) => string;
66
+ export declare const stringify: (expr: Expression) => string;
67
67
  export declare const parseSearchInputQuery: (input: string, fieldSchemas?: FieldSchema[]) => SearchQuery | SearchQueryError;
68
- export { type SearchQuery, type SearchQueryError, type Expression, type ValidationError, SearchQueryErrorCode, type FieldSchema, type RangeOperator, type RangeExpression, type WildcardPattern, type Value, stringify, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "search-input-query-parser",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A parser for advanced search query syntax with field:value support",
5
5
  "keywords": [
6
6
  "search",
@@ -19,6 +19,11 @@
19
19
  ],
20
20
  "exports": {
21
21
  ".": {
22
+ "types": "./dist/types/index.d.ts",
23
+ "import": "./dist/esm/index.js",
24
+ "require": "./dist/cjs/index.js"
25
+ },
26
+ "./parser": {
22
27
  "types": "./dist/types/parser.d.ts",
23
28
  "import": "./dist/esm/parser.js",
24
29
  "require": "./dist/cjs/parser.js"
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ // Re-export everything from parser.ts
2
+ export * from "./parser";
3
+
4
+ // Re-export everything from validator.ts
5
+ export * from "./validator";
6
+
7
+ // Re-export everything from lexer.ts
8
+ export * from "./lexer";
9
+
10
+ // Re-export everything from first-pass-parser.ts with renamed types to avoid conflicts
11
+ export {
12
+ parseExpression,
13
+ type PositionLength,
14
+ type StringLiteral,
15
+ type WildcardPattern as FirstPassWildcardPattern,
16
+ type AndExpression,
17
+ type OrExpression,
18
+ type NotExpression,
19
+ type InExpression as FirstPassInExpression,
20
+ type FirstPassExpression,
21
+ type ParseResult,
22
+ } from "./first-pass-parser";
23
+
24
+ // Re-export SQL-related files with renamed types to avoid conflicts
25
+ export {
26
+ searchQueryToSql,
27
+ searchStringToSql,
28
+ type SqlQueryResult as SqlQueryResultBase,
29
+ type SearchType,
30
+ type SearchQueryOptions as SearchQueryOptionsBase,
31
+ } from "./search-query-to-sql";
32
+
33
+ export {
34
+ searchQueryToTsVectorSql,
35
+ searchStringToTsVectorSql,
36
+ type SqlQueryResult as TsVectorSqlQueryResult,
37
+ type SearchQueryOptions as TsVectorSearchQueryOptions,
38
+ } from "./search-query-to-tsvector-sql";
39
+
40
+ export {
41
+ searchQueryToIlikeSql,
42
+ searchStringToIlikeSql,
43
+ type SqlQueryResult as IlikeSqlQueryResult,
44
+ type SearchQueryOptions as IlikeSearchQueryOptions,
45
+ } from "./search-query-to-ilike-sql";
46
+
47
+ export {
48
+ searchQueryToParadeDbSql,
49
+ searchStringToParadeDbSql,
50
+ type SqlQueryResult as ParadeDbSqlQueryResult,
51
+ type SearchQueryOptions as ParadeDbSearchQueryOptions,
52
+ } from "./search-query-to-paradedb-sql";
53
+
54
+ // Re-export utility functions
55
+ export * from "./validate-expression-fields";
56
+ export * from "./validate-string";
57
+ export * from "./validate-wildcard";
58
+ export * from "./validate-in-expression";
59
+ export * from "./parse-in-values";
60
+ export * from "./parse-primary";
61
+ export * from "./parse-range-expression";
62
+ export * from "./transform-to-expression";
package/src/parser.ts CHANGED
@@ -13,36 +13,36 @@ import { validateExpressionFields } from "./validate-expression-fields";
13
13
  import { transformToExpression } from "./transform-to-expression";
14
14
 
15
15
  // Schema types for range queries
16
- interface FieldSchema {
16
+ export interface FieldSchema {
17
17
  name: string;
18
18
  type: "string" | "number" | "date" | "boolean";
19
19
  }
20
20
 
21
21
  // Second Pass AST types (semantic analysis)
22
- type SearchTerm = {
22
+ export type SearchTerm = {
23
23
  readonly type: "SEARCH_TERM";
24
24
  readonly value: string;
25
25
  } & PositionLength;
26
26
 
27
- type WildcardPattern = {
27
+ export type WildcardPattern = {
28
28
  readonly type: "WILDCARD";
29
29
  readonly prefix: string;
30
30
  readonly quoted: boolean;
31
31
  } & PositionLength;
32
32
 
33
- type Field = {
33
+ export type Field = {
34
34
  readonly type: "FIELD";
35
35
  readonly value: string;
36
36
  } & PositionLength;
37
37
 
38
- type Value = {
38
+ export type Value = {
39
39
  readonly type: "VALUE";
40
40
  readonly value: string;
41
41
  } & PositionLength;
42
42
 
43
- type RangeOperator = ">=" | ">" | "<=" | "<" | "BETWEEN";
43
+ export type RangeOperator = ">=" | ">" | "<=" | "<" | "BETWEEN";
44
44
 
45
- type RangeExpression = {
45
+ export type RangeExpression = {
46
46
  readonly type: "RANGE";
47
47
  readonly field: Field;
48
48
  readonly operator: RangeOperator;
@@ -56,30 +56,30 @@ export type FieldValue = {
56
56
  readonly value: Value;
57
57
  };
58
58
 
59
- type And = {
59
+ export type And = {
60
60
  readonly type: "AND";
61
61
  readonly left: Expression;
62
62
  readonly right: Expression;
63
63
  } & PositionLength;
64
64
 
65
- type Or = {
65
+ export type Or = {
66
66
  readonly type: "OR";
67
67
  readonly left: Expression;
68
68
  readonly right: Expression;
69
69
  } & PositionLength;
70
70
 
71
- type Not = {
71
+ export type Not = {
72
72
  readonly type: "NOT";
73
73
  readonly expression: Expression;
74
74
  } & PositionLength;
75
75
 
76
- type InExpression = {
76
+ export type InExpression = {
77
77
  readonly type: "IN";
78
78
  readonly field: Field;
79
79
  readonly values: Value[];
80
80
  } & PositionLength;
81
81
 
82
- type Expression =
82
+ export type Expression =
83
83
  | SearchTerm
84
84
  | WildcardPattern
85
85
  | FieldValue
@@ -89,19 +89,19 @@ type Expression =
89
89
  | Not
90
90
  | InExpression;
91
91
 
92
- type SearchQuery = {
92
+ export type SearchQuery = {
93
93
  readonly type: "SEARCH_QUERY";
94
94
  readonly expression: Expression | null;
95
95
  };
96
96
 
97
- type SearchQueryError = {
97
+ export type SearchQueryError = {
98
98
  readonly type: "SEARCH_QUERY_ERROR";
99
99
  readonly expression: null;
100
100
  readonly errors: ValidationError[];
101
101
  };
102
102
 
103
103
  // Helper function to stringify expressions
104
- const stringify = (expr: Expression): string => {
104
+ export const stringify = (expr: Expression): string => {
105
105
  switch (expr.type) {
106
106
  case "SEARCH_TERM":
107
107
  return expr.value;
@@ -210,16 +210,3 @@ export const parseSearchInputQuery = (
210
210
  }
211
211
  };
212
212
 
213
- export {
214
- type SearchQuery,
215
- type SearchQueryError,
216
- type Expression,
217
- type ValidationError,
218
- SearchQueryErrorCode,
219
- type FieldSchema,
220
- type RangeOperator,
221
- type RangeExpression,
222
- type WildcardPattern,
223
- type Value,
224
- stringify,
225
- };