@powersync/service-sync-rules 0.0.0-dev-20240708103353
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/LICENSE +67 -0
- package/README.md +129 -0
- package/dist/DartSchemaGenerator.d.ts +12 -0
- package/dist/DartSchemaGenerator.js +39 -0
- package/dist/DartSchemaGenerator.js.map +1 -0
- package/dist/ExpressionType.d.ts +33 -0
- package/dist/ExpressionType.js +61 -0
- package/dist/ExpressionType.js.map +1 -0
- package/dist/IdSequence.d.ts +4 -0
- package/dist/IdSequence.js +9 -0
- package/dist/IdSequence.js.map +1 -0
- package/dist/JsSchemaGenerator.d.ts +12 -0
- package/dist/JsSchemaGenerator.js +42 -0
- package/dist/JsSchemaGenerator.js.map +1 -0
- package/dist/SchemaGenerator.d.ts +14 -0
- package/dist/SchemaGenerator.js +26 -0
- package/dist/SchemaGenerator.js.map +1 -0
- package/dist/SourceTableInterface.d.ts +5 -0
- package/dist/SourceTableInterface.js +2 -0
- package/dist/SourceTableInterface.js.map +1 -0
- package/dist/SqlBucketDescriptor.d.ts +37 -0
- package/dist/SqlBucketDescriptor.js +111 -0
- package/dist/SqlBucketDescriptor.js.map +1 -0
- package/dist/SqlDataQuery.d.ts +39 -0
- package/dist/SqlDataQuery.js +239 -0
- package/dist/SqlDataQuery.js.map +1 -0
- package/dist/SqlParameterQuery.d.ts +85 -0
- package/dist/SqlParameterQuery.js +311 -0
- package/dist/SqlParameterQuery.js.map +1 -0
- package/dist/SqlSyncRules.d.ts +52 -0
- package/dist/SqlSyncRules.js +264 -0
- package/dist/SqlSyncRules.js.map +1 -0
- package/dist/StaticSchema.d.ts +26 -0
- package/dist/StaticSchema.js +61 -0
- package/dist/StaticSchema.js.map +1 -0
- package/dist/StaticSqlParameterQuery.d.ts +27 -0
- package/dist/StaticSqlParameterQuery.js +96 -0
- package/dist/StaticSqlParameterQuery.js.map +1 -0
- package/dist/TablePattern.d.ts +17 -0
- package/dist/TablePattern.js +56 -0
- package/dist/TablePattern.js.map +1 -0
- package/dist/TableQuerySchema.d.ts +9 -0
- package/dist/TableQuerySchema.js +34 -0
- package/dist/TableQuerySchema.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +58 -0
- package/dist/errors.js.map +1 -0
- package/dist/generators.d.ts +6 -0
- package/dist/generators.js +7 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/json_schema.d.ts +3 -0
- package/dist/json_schema.js +52 -0
- package/dist/json_schema.js.map +1 -0
- package/dist/request_functions.d.ts +17 -0
- package/dist/request_functions.js +41 -0
- package/dist/request_functions.js.map +1 -0
- package/dist/sql_filters.d.ts +125 -0
- package/dist/sql_filters.js +599 -0
- package/dist/sql_filters.js.map +1 -0
- package/dist/sql_functions.d.ts +61 -0
- package/dist/sql_functions.js +863 -0
- package/dist/sql_functions.js.map +1 -0
- package/dist/sql_support.d.ts +25 -0
- package/dist/sql_support.js +254 -0
- package/dist/sql_support.js.map +1 -0
- package/dist/types.d.ts +262 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +44 -0
- package/dist/utils.js +167 -0
- package/dist/utils.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Expr, ExprRef, NodeLocation, SelectedColumn } from 'pgsql-ast-parser';
|
|
2
|
+
import { nil } from 'pgsql-ast-parser/src/utils.js';
|
|
3
|
+
import { SqlRuleError } from './errors.js';
|
|
4
|
+
import { SqlFunction } from './sql_functions.js';
|
|
5
|
+
import { ClauseError, CompiledClause, ParameterMatchClause, ParameterValueClause, QuerySchema, RowValueClause, StaticValueClause, TrueIfParametersMatch } from './types.js';
|
|
6
|
+
export declare const MATCH_CONST_FALSE: TrueIfParametersMatch;
|
|
7
|
+
export declare const MATCH_CONST_TRUE: TrueIfParametersMatch;
|
|
8
|
+
export interface SqlToolsOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Default table name, if any. I.e. SELECT FROM <table>.
|
|
11
|
+
*
|
|
12
|
+
* Used for to determine the table when using bare column names.
|
|
13
|
+
*/
|
|
14
|
+
table?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Set of tables used for FilterParameters.
|
|
17
|
+
*
|
|
18
|
+
* This is tables that can be used to filter the data on, e.g.:
|
|
19
|
+
* "bucket" (bucket parameters for data query)
|
|
20
|
+
* "token_parameters" (token parameters for parameter query)
|
|
21
|
+
*/
|
|
22
|
+
parameter_tables?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Set of tables used in QueryParameters.
|
|
25
|
+
*
|
|
26
|
+
* If not specified, defaults to [table].
|
|
27
|
+
*/
|
|
28
|
+
value_tables?: string[];
|
|
29
|
+
/**
|
|
30
|
+
* For debugging / error messages.
|
|
31
|
+
*/
|
|
32
|
+
sql: string;
|
|
33
|
+
/**
|
|
34
|
+
* true if values in parameter tables can be expanded, i.e. `WHERE value IN parameters.something`.
|
|
35
|
+
*
|
|
36
|
+
* Only one parameter may be expanded.
|
|
37
|
+
*/
|
|
38
|
+
supports_expanding_parameters?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* true if expressions on parameters are supported, e.g. upper(token_parameters.user_id)
|
|
41
|
+
*/
|
|
42
|
+
supports_parameter_expressions?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Schema for validations.
|
|
45
|
+
*/
|
|
46
|
+
schema?: QuerySchema;
|
|
47
|
+
}
|
|
48
|
+
export declare class SqlTools {
|
|
49
|
+
default_table?: string;
|
|
50
|
+
value_tables: string[];
|
|
51
|
+
/**
|
|
52
|
+
* ['bucket'] for data queries
|
|
53
|
+
* ['token_parameters', 'user_parameters'] for parameter queries
|
|
54
|
+
*/
|
|
55
|
+
parameter_tables: string[];
|
|
56
|
+
sql: string;
|
|
57
|
+
errors: SqlRuleError[];
|
|
58
|
+
supports_expanding_parameters: boolean;
|
|
59
|
+
supports_parameter_expressions: boolean;
|
|
60
|
+
schema?: QuerySchema;
|
|
61
|
+
constructor(options: SqlToolsOptions);
|
|
62
|
+
error(message: string, expr: NodeLocation | Expr | undefined): ClauseError;
|
|
63
|
+
warn(message: string, expr: NodeLocation | Expr | undefined): void;
|
|
64
|
+
/**
|
|
65
|
+
* Compile the where clause into a ParameterMatchClause.
|
|
66
|
+
*
|
|
67
|
+
* A ParameterMatchClause takes a data row, and returns filter values that
|
|
68
|
+
* would make the expression true for the row.
|
|
69
|
+
*/
|
|
70
|
+
compileWhereClause(where: Expr | nil): ParameterMatchClause;
|
|
71
|
+
compileRowValueExtractor(expr: Expr | nil): RowValueClause | ClauseError;
|
|
72
|
+
compileParameterValueExtractor(expr: Expr | nil): ParameterValueClause | StaticValueClause | ClauseError;
|
|
73
|
+
/**
|
|
74
|
+
* Given an expression, return a compiled clause.
|
|
75
|
+
*/
|
|
76
|
+
compileClause(expr: Expr | nil): CompiledClause;
|
|
77
|
+
/**
|
|
78
|
+
* "some_column" => "some_column"
|
|
79
|
+
* "table.some_column" => "some_column".
|
|
80
|
+
* "some_function() AS some_column" => "some_column"
|
|
81
|
+
* "some_function() some_column" => "some_column"
|
|
82
|
+
* "some_function()" => error
|
|
83
|
+
*/
|
|
84
|
+
getOutputName(column: SelectedColumn): string;
|
|
85
|
+
getSpecificOutputName(column: SelectedColumn): string;
|
|
86
|
+
/**
|
|
87
|
+
* Check if an expression is a parameter_table reference.
|
|
88
|
+
*/
|
|
89
|
+
isParameterRef(expr: Expr): expr is ExprRef;
|
|
90
|
+
/**
|
|
91
|
+
* Check if an expression is a value_tables reference.
|
|
92
|
+
*
|
|
93
|
+
* This means the expression can be evaluated directly on a value row.
|
|
94
|
+
*/
|
|
95
|
+
isTableRef(expr: Expr): expr is ExprRef;
|
|
96
|
+
private checkRef;
|
|
97
|
+
getParameterRefClause(expr: ExprRef): ParameterValueClause;
|
|
98
|
+
refHasSchema(ref: ExprRef): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Get the table name from an expression.
|
|
101
|
+
*
|
|
102
|
+
* Only "value" tables are supported here, not parameter values.
|
|
103
|
+
*/
|
|
104
|
+
getTableName(ref: ExprRef): string;
|
|
105
|
+
/**
|
|
106
|
+
* Given a function, compile a clause with the function over compiled arguments.
|
|
107
|
+
*
|
|
108
|
+
* For functions with multiple arguments, the following combinations are supported:
|
|
109
|
+
* fn(StaticValueClause, StaticValueClause) => StaticValueClause
|
|
110
|
+
* fn(ParameterValueClause, ParameterValueClause) => ParameterValueClause
|
|
111
|
+
* fn(RowValueClause, RowValueClause) => RowValueClause
|
|
112
|
+
* fn(ParameterValueClause, StaticValueClause) => ParameterValueClause
|
|
113
|
+
* fn(RowValueClause, StaticValueClause) => RowValueClause
|
|
114
|
+
*
|
|
115
|
+
* This is not supported, and will likely never be supported:
|
|
116
|
+
* fn(ParameterValueClause, RowValueClause) => error
|
|
117
|
+
*
|
|
118
|
+
* @param fnImpl The function or operator implementation
|
|
119
|
+
* @param argClauses The compiled argument clauses
|
|
120
|
+
* @param debugArgExpressions The original parsed expressions, for debug info only
|
|
121
|
+
* @returns a compiled function clause
|
|
122
|
+
*/
|
|
123
|
+
composeFunction(fnImpl: SqlFunction, argClauses: CompiledClause[], debugArgExpressions: Expr[]): CompiledClause;
|
|
124
|
+
parameterFunction(): void;
|
|
125
|
+
}
|