powersync 0.1.0 → 0.1.1
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 +14 -14
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.js +9 -8
- package/dist/commands/instance/sync-rules/generate-schema.js +6 -6
- package/dist/constants.d.ts +2 -5
- package/dist/constants.js +4 -2
- package/dist/service/accounts.client.js +11129 -25
- package/dist/service/powersync.client.js +37453 -113
- package/dist/service/types.js +1 -1
- package/dist/service/utils.js +6 -6
- package/dist/utils.js +3 -3
- package/oclif.manifest.json +1 -1
- package/package.json +28 -20
- package/dist/powersync-sdk/accounts/api.d.ts +0 -717
- package/dist/powersync-sdk/accounts/api.js +0 -182
- package/dist/powersync-sdk/accounts/client.d.ts +0 -1096
- package/dist/powersync-sdk/accounts/client.js +0 -124
- package/dist/powersync-sdk/accounts/codecs.d.ts +0 -32
- package/dist/powersync-sdk/accounts/codecs.js +0 -93
- package/dist/powersync-sdk/accounts/index.d.ts +0 -4
- package/dist/powersync-sdk/accounts/index.js +0 -4
- package/dist/powersync-sdk/accounts/models.d.ts +0 -260
- package/dist/powersync-sdk/accounts/models.js +0 -96
- package/dist/powersync-sdk/accounts/routes.d.ts +0 -44
- package/dist/powersync-sdk/accounts/routes.js +0 -45
- package/dist/powersync-sdk/accounts/source.d.ts +0 -76
- package/dist/powersync-sdk/accounts/source.js +0 -32
- package/dist/powersync-sdk/errors/errors.d.ts +0 -62
- package/dist/powersync-sdk/errors/errors.js +0 -115
- package/dist/powersync-sdk/errors/index.d.ts +0 -2
- package/dist/powersync-sdk/errors/index.js +0 -2
- package/dist/powersync-sdk/errors/utils.d.ts +0 -4
- package/dist/powersync-sdk/errors/utils.js +0 -18
- package/dist/powersync-sdk/fetch-clients/codecs.d.ts +0 -4
- package/dist/powersync-sdk/fetch-clients/codecs.js +0 -34
- package/dist/powersync-sdk/fetch-clients/decoders.d.ts +0 -3
- package/dist/powersync-sdk/fetch-clients/decoders.js +0 -35
- package/dist/powersync-sdk/fetch-clients/definitions.d.ts +0 -97
- package/dist/powersync-sdk/fetch-clients/definitions.js +0 -22
- package/dist/powersync-sdk/fetch-clients/errors.d.ts +0 -7
- package/dist/powersync-sdk/fetch-clients/errors.js +0 -19
- package/dist/powersync-sdk/fetch-clients/index.d.ts +0 -5
- package/dist/powersync-sdk/fetch-clients/index.js +0 -5
- package/dist/powersync-sdk/fetch-clients/node-client.d.ts +0 -9
- package/dist/powersync-sdk/fetch-clients/node-client.js +0 -107
- package/dist/powersync-sdk/fetch-clients/request.d.ts +0 -11
- package/dist/powersync-sdk/fetch-clients/request.js +0 -138
- package/dist/powersync-sdk/fetch-clients/streaming.d.ts +0 -65
- package/dist/powersync-sdk/fetch-clients/streaming.js +0 -99
- package/dist/powersync-sdk/fetch-clients/utils.d.ts +0 -13
- package/dist/powersync-sdk/fetch-clients/utils.js +0 -43
- package/dist/powersync-sdk/fetch-clients/web-client.d.ts +0 -14
- package/dist/powersync-sdk/fetch-clients/web-client.js +0 -56
- package/dist/powersync-sdk/json/index.d.ts +0 -4
- package/dist/powersync-sdk/json/index.js +0 -3
- package/dist/powersync-sdk/json/json.d.ts +0 -5
- package/dist/powersync-sdk/json/json.js +0 -35
- package/dist/powersync-sdk/json/json_container.d.ts +0 -18
- package/dist/powersync-sdk/json/json_container.js +0 -28
- package/dist/powersync-sdk/json/json_stringify.d.ts +0 -36
- package/dist/powersync-sdk/json/json_stringify.js +0 -162
- package/dist/powersync-sdk/powersync/client.d.ts +0 -449
- package/dist/powersync-sdk/powersync/client.js +0 -53
- package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +0 -327
- package/dist/powersync-sdk/powersync/config/HostedConfig.js +0 -92
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +0 -211
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +0 -97
- package/dist/powersync-sdk/powersync/config/normalize.d.ts +0 -32
- package/dist/powersync-sdk/powersync/config/normalize.js +0 -85
- package/dist/powersync-sdk/powersync/definitions.d.ts +0 -149
- package/dist/powersync-sdk/powersync/definitions.js +0 -97
- package/dist/powersync-sdk/powersync/index.d.ts +0 -8
- package/dist/powersync-sdk/powersync/index.js +0 -8
- package/dist/powersync-sdk/powersync/internal_routes.d.ts +0 -247
- package/dist/powersync-sdk/powersync/internal_routes.js +0 -69
- package/dist/powersync-sdk/powersync/routes.d.ts +0 -779
- package/dist/powersync-sdk/powersync/routes.js +0 -191
- package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +0 -31
- package/dist/powersync-sdk/sdk-clients/endpoints.js +0 -48
- package/dist/powersync-sdk/sdk-clients/index.d.ts +0 -3
- package/dist/powersync-sdk/sdk-clients/index.js +0 -3
- package/dist/powersync-sdk/sdk-clients/pagination.d.ts +0 -14
- package/dist/powersync-sdk/sdk-clients/pagination.js +0 -21
- package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +0 -17
- package/dist/powersync-sdk/sdk-clients/sdk-client.js +0 -30
- package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +0 -31
- package/dist/powersync-sdk/streaming/bson/buffer-array.js +0 -79
- package/dist/powersync-sdk/streaming/bson/constants.d.ts +0 -2
- package/dist/powersync-sdk/streaming/bson/constants.js +0 -1
- package/dist/powersync-sdk/streaming/bson/decoder.d.ts +0 -10
- package/dist/powersync-sdk/streaming/bson/decoder.js +0 -62
- package/dist/powersync-sdk/streaming/bson/encoder.d.ts +0 -10
- package/dist/powersync-sdk/streaming/bson/encoder.js +0 -23
- package/dist/powersync-sdk/streaming/bson/header.d.ts +0 -11
- package/dist/powersync-sdk/streaming/bson/header.js +0 -52
- package/dist/powersync-sdk/streaming/bson/index.d.ts +0 -5
- package/dist/powersync-sdk/streaming/bson/index.js +0 -5
- package/dist/powersync-sdk/streaming/core/backpressure.d.ts +0 -15
- package/dist/powersync-sdk/streaming/core/backpressure.js +0 -34
- package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +0 -6
- package/dist/powersync-sdk/streaming/core/cross-stream.js +0 -17
- package/dist/powersync-sdk/streaming/core/index.d.ts +0 -4
- package/dist/powersync-sdk/streaming/core/index.js +0 -4
- package/dist/powersync-sdk/streaming/core/node-utils.d.ts +0 -7
- package/dist/powersync-sdk/streaming/core/node-utils.js +0 -11
- package/dist/powersync-sdk/streaming/core/transformers.d.ts +0 -41
- package/dist/powersync-sdk/streaming/core/transformers.js +0 -70
- package/dist/powersync-sdk/streaming/core/utils.d.ts +0 -36
- package/dist/powersync-sdk/streaming/core/utils.js +0 -66
- package/dist/powersync-sdk/streaming/index.d.ts +0 -3
- package/dist/powersync-sdk/streaming/index.js +0 -3
- package/dist/powersync-sdk/streaming/web.d.ts +0 -4
- package/dist/powersync-sdk/streaming/web.js +0 -4
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +0 -36
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +0 -58
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +0 -18
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +0 -348
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +0 -118
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +0 -131
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +0 -134
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +0 -122
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +0 -158
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +0 -14
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +0 -165
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +0 -11
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +0 -207
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +0 -30
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +0 -29
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +0 -2
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +0 -111
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +0 -9
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +0 -9
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +0 -5
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +0 -9
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +0 -12
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +0 -35
- package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +0 -33
- package/dist/powersync-sdk/sync-rules/ExpressionType.js +0 -62
- package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +0 -4
- package/dist/powersync-sdk/sync-rules/IdSequence.js +0 -7
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +0 -12
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +0 -38
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +0 -14
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +0 -24
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +0 -5
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +0 -1
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +0 -37
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +0 -116
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +0 -39
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +0 -245
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +0 -43
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +0 -254
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +0 -52
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +0 -252
- package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +0 -26
- package/dist/powersync-sdk/sync-rules/StaticSchema.js +0 -71
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +0 -24
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +0 -71
- package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +0 -17
- package/dist/powersync-sdk/sync-rules/TablePattern.js +0 -56
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +0 -9
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +0 -41
- package/dist/powersync-sdk/sync-rules/errors.d.ts +0 -22
- package/dist/powersync-sdk/sync-rules/errors.js +0 -60
- package/dist/powersync-sdk/sync-rules/generators.d.ts +0 -6
- package/dist/powersync-sdk/sync-rules/generators.js +0 -6
- package/dist/powersync-sdk/sync-rules/index.d.ts +0 -17
- package/dist/powersync-sdk/sync-rules/index.js +0 -17
- package/dist/powersync-sdk/sync-rules/json_schema.d.ts +0 -3
- package/dist/powersync-sdk/sync-rules/json_schema.js +0 -50
- package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +0 -91
- package/dist/powersync-sdk/sync-rules/sql_filters.js +0 -491
- package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +0 -53
- package/dist/powersync-sdk/sync-rules/sql_functions.js +0 -755
- package/dist/powersync-sdk/sync-rules/sql_support.d.ts +0 -22
- package/dist/powersync-sdk/sync-rules/sql_support.js +0 -208
- package/dist/powersync-sdk/sync-rules/types.d.ts +0 -174
- package/dist/powersync-sdk/sync-rules/types.js +0 -9
- package/dist/powersync-sdk/sync-rules/utils.d.ts +0 -45
- package/dist/powersync-sdk/sync-rules/utils.js +0 -163
- package/dist/service/accounts.client.d.ts +0 -26
- package/dist/service/powersync.client.d.ts +0 -269
- package/dist/service/types.d.ts +0 -69
- package/dist/service/utils.d.ts +0 -5
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
/* eslint-disable guard-for-in */
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
/* eslint-disable unicorn/no-array-callback-reference */
|
|
5
|
-
/* eslint-disable unicorn/consistent-destructuring */
|
|
6
|
-
/* eslint-disable eqeqeq */
|
|
7
|
-
/* eslint-disable no-eq-null */
|
|
8
|
-
/* eslint-disable camelcase */
|
|
9
|
-
import { parse } from 'pgsql-ast-parser';
|
|
10
|
-
import { StaticSqlParameterQuery } from './StaticSqlParameterQuery.js';
|
|
11
|
-
import { TablePattern } from './TablePattern.js';
|
|
12
|
-
import { TableQuerySchema } from './TableQuerySchema.js';
|
|
13
|
-
import { SqlRuleError } from './errors.js';
|
|
14
|
-
import { SqlTools } from './sql_filters.js';
|
|
15
|
-
import { checkUnsupportedFeatures, isClauseError } from './sql_support.js';
|
|
16
|
-
import { filterJsonRow, getBucketId, isJsonValue, isSelectStatement } from './utils.js';
|
|
17
|
-
/**
|
|
18
|
-
* Represents a parameter query, such as:
|
|
19
|
-
*
|
|
20
|
-
* SELECT id as user_id FROM users WHERE users.user_id = token_parameters.user_id
|
|
21
|
-
* SELECT id as user_id, token_parameters.is_admin as is_admin FROM users WHERE users.user_id = token_parameters.user_id
|
|
22
|
-
*/
|
|
23
|
-
export class SqlParameterQuery {
|
|
24
|
-
/** _Output_ bucket parameters */
|
|
25
|
-
bucket_parameters;
|
|
26
|
-
columns;
|
|
27
|
-
descriptor_name;
|
|
28
|
-
errors = [];
|
|
29
|
-
expanded_input_parameter;
|
|
30
|
-
filter;
|
|
31
|
-
id;
|
|
32
|
-
/** _Input_ token / user parameters */
|
|
33
|
-
input_parameters;
|
|
34
|
-
lookup_columns;
|
|
35
|
-
lookup_extractors = {};
|
|
36
|
-
sourceTable;
|
|
37
|
-
sql;
|
|
38
|
-
static_columns;
|
|
39
|
-
static_extractors = {};
|
|
40
|
-
static_tools;
|
|
41
|
-
table;
|
|
42
|
-
tools;
|
|
43
|
-
// eslint-disable-next-line no-useless-constructor, prettier/prettier
|
|
44
|
-
constructor() { }
|
|
45
|
-
static fromSql(descriptor_name, sql, schema) {
|
|
46
|
-
const parsed = parse(sql, { locationTracking: true });
|
|
47
|
-
const rows = new SqlParameterQuery();
|
|
48
|
-
if (parsed.length > 1) {
|
|
49
|
-
throw new SqlRuleError('Only a single SELECT statement is supported', sql, parsed[1]?._location);
|
|
50
|
-
}
|
|
51
|
-
const q = parsed[0];
|
|
52
|
-
if (!isSelectStatement(q)) {
|
|
53
|
-
throw new SqlRuleError('Only SELECT statements are supported', sql, q._location);
|
|
54
|
-
}
|
|
55
|
-
if (q.from == null) {
|
|
56
|
-
// E.g. SELECT token_parameters.user_id as user_id WHERE token_parameters.is_admin
|
|
57
|
-
return StaticSqlParameterQuery.fromSql(descriptor_name, sql, q);
|
|
58
|
-
}
|
|
59
|
-
rows.errors.push(...checkUnsupportedFeatures(sql, q));
|
|
60
|
-
if (q.from.length != 1 || q.from[0].type != 'table') {
|
|
61
|
-
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
62
|
-
}
|
|
63
|
-
const tableRef = q.from?.[0].name;
|
|
64
|
-
if (tableRef?.name == null) {
|
|
65
|
-
throw new SqlRuleError('Must SELECT from a single table', sql, q.from?.[0]._location);
|
|
66
|
-
}
|
|
67
|
-
const alias = q.from?.[0].name.alias ?? tableRef.name;
|
|
68
|
-
if (tableRef.name != alias) {
|
|
69
|
-
rows.errors.push(new SqlRuleError('Table aliases not supported in parameter queries', sql, q.from?.[0]._location));
|
|
70
|
-
}
|
|
71
|
-
const sourceTable = new TablePattern(tableRef.schema, tableRef.name);
|
|
72
|
-
let querySchema;
|
|
73
|
-
if (schema) {
|
|
74
|
-
const tables = schema.getTables(sourceTable);
|
|
75
|
-
if (tables.length === 0) {
|
|
76
|
-
const e = new SqlRuleError(`Table ${sourceTable.schema}.${sourceTable.tablePattern} not found`, sql, q.from?.[0]?._location);
|
|
77
|
-
e.type = 'warning';
|
|
78
|
-
rows.errors.push(e);
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
querySchema = new TableQuerySchema(tables, alias);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const tools = new SqlTools({
|
|
85
|
-
parameter_tables: ['token_parameters', 'user_parameters'],
|
|
86
|
-
schema: querySchema,
|
|
87
|
-
sql,
|
|
88
|
-
supports_expanding_parameters: true,
|
|
89
|
-
table: alias
|
|
90
|
-
});
|
|
91
|
-
const { where } = q;
|
|
92
|
-
const filter = tools.compileWhereClause(where);
|
|
93
|
-
const bucket_parameters = (q.columns ?? []).map((column) => tools.getOutputName(column));
|
|
94
|
-
rows.sourceTable = sourceTable;
|
|
95
|
-
rows.table = alias;
|
|
96
|
-
rows.sql = sql;
|
|
97
|
-
rows.filter = filter;
|
|
98
|
-
rows.descriptor_name = descriptor_name;
|
|
99
|
-
rows.bucket_parameters = bucket_parameters;
|
|
100
|
-
rows.input_parameters = filter.bucketParameters;
|
|
101
|
-
const expandedParams = rows.input_parameters.filter((param) => param.endsWith('[*]'));
|
|
102
|
-
if (expandedParams.length > 1) {
|
|
103
|
-
rows.errors.push(new SqlRuleError('Cannot have multiple array input parameters', sql));
|
|
104
|
-
}
|
|
105
|
-
rows.expanded_input_parameter = expandedParams[0];
|
|
106
|
-
rows.columns = q.columns ?? [];
|
|
107
|
-
rows.static_columns = [];
|
|
108
|
-
rows.lookup_columns = [];
|
|
109
|
-
rows.static_tools = new SqlTools({
|
|
110
|
-
// This is used for values not on the parameter query table - these operate directly on
|
|
111
|
-
parameter_tables: [],
|
|
112
|
-
sql,
|
|
113
|
-
// token_parameters or user_parameters.
|
|
114
|
-
table: undefined,
|
|
115
|
-
value_tables: ['token_parameters', 'user_parameters']
|
|
116
|
-
});
|
|
117
|
-
for (const column of q.columns ?? []) {
|
|
118
|
-
const name = tools.getSpecificOutputName(column);
|
|
119
|
-
if (tools.isTableRef(column.expr)) {
|
|
120
|
-
rows.lookup_columns.push(column);
|
|
121
|
-
const extractor = tools.compileStaticExtractor(column.expr);
|
|
122
|
-
if (isClauseError(extractor)) {
|
|
123
|
-
// Error logged already
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
rows.lookup_extractors[name] = extractor;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
rows.static_columns.push(column);
|
|
130
|
-
const extractor = rows.static_tools.compileStaticExtractor(column.expr);
|
|
131
|
-
if (isClauseError(extractor)) {
|
|
132
|
-
// Error logged already
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
rows.static_extractors[name] = extractor;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
rows.tools = tools;
|
|
139
|
-
rows.errors.push(...tools.errors, ...rows.static_tools.errors);
|
|
140
|
-
return rows;
|
|
141
|
-
}
|
|
142
|
-
applies(table) {
|
|
143
|
-
return this.sourceTable.matches(table);
|
|
144
|
-
}
|
|
145
|
-
evaluateParameterRow(row) {
|
|
146
|
-
const tables = {
|
|
147
|
-
[this.table]: row
|
|
148
|
-
};
|
|
149
|
-
try {
|
|
150
|
-
const filterParameters = this.filter.filter(tables);
|
|
151
|
-
const result = [];
|
|
152
|
-
for (const filterParamSet of filterParameters) {
|
|
153
|
-
const lookup = [this.descriptor_name, this.id];
|
|
154
|
-
lookup.push(...this.input_parameters.map((param) => {
|
|
155
|
-
return filterParamSet[param];
|
|
156
|
-
}));
|
|
157
|
-
const data = this.transformRows(row);
|
|
158
|
-
const role = {
|
|
159
|
-
bucket_parameters: data.map((row) => filterJsonRow(row)),
|
|
160
|
-
lookup
|
|
161
|
-
};
|
|
162
|
-
result.push(role);
|
|
163
|
-
}
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
|
-
catch (error) {
|
|
167
|
-
return [{ error: error.message ?? `Evaluating parameter query failed` }];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
getLookups(parameters) {
|
|
171
|
-
if (!this.expanded_input_parameter) {
|
|
172
|
-
const lookup = [this.descriptor_name, this.id];
|
|
173
|
-
lookup.push(...this.input_parameters.map((param) => {
|
|
174
|
-
// Scalar value
|
|
175
|
-
return this.lookupParam(param, parameters);
|
|
176
|
-
}));
|
|
177
|
-
return [lookup];
|
|
178
|
-
}
|
|
179
|
-
const arrayString = this.lookupParam(this.expanded_input_parameter.slice(0, Math.max(0, this.expanded_input_parameter.length - 3)), parameters);
|
|
180
|
-
if (arrayString == null || typeof arrayString !== 'string') {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
let values;
|
|
184
|
-
try {
|
|
185
|
-
values = JSON.parse(arrayString);
|
|
186
|
-
if (!Array.isArray(values)) {
|
|
187
|
-
return [];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
catch {
|
|
191
|
-
return [];
|
|
192
|
-
}
|
|
193
|
-
return values.map((expandedValue) => {
|
|
194
|
-
const lookup = [this.descriptor_name, this.id];
|
|
195
|
-
lookup.push(...this.input_parameters.map((param) => {
|
|
196
|
-
if (param == this.expanded_input_parameter) {
|
|
197
|
-
// Expand array value
|
|
198
|
-
return expandedValue;
|
|
199
|
-
}
|
|
200
|
-
// Scalar value
|
|
201
|
-
return this.lookupParam(param, parameters);
|
|
202
|
-
}));
|
|
203
|
-
return lookup;
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
lookupParam(param, parameters) {
|
|
207
|
-
const [table, column] = param.split('.');
|
|
208
|
-
const pt = parameters[table];
|
|
209
|
-
return pt?.[column] ?? null;
|
|
210
|
-
}
|
|
211
|
-
async queryBucketIds(options) {
|
|
212
|
-
const lookups = this.getLookups(options.parameters);
|
|
213
|
-
if (lookups.length === 0) {
|
|
214
|
-
return [];
|
|
215
|
-
}
|
|
216
|
-
const parameters = await options.getParameterSets(lookups);
|
|
217
|
-
return this.resolveBucketIds(parameters, options.parameters);
|
|
218
|
-
}
|
|
219
|
-
resolveBucketIds(bucketParameters, parameters) {
|
|
220
|
-
const tables = { token_parameters: parameters.token_parameters, user_parameters: parameters.user_parameters };
|
|
221
|
-
// Filters have already been applied and gotten us the set of bucketParameters - don't attempt to filter again.
|
|
222
|
-
// We _do_ need to evaluate the output columns here, using a combination of precomputed bucketParameters,
|
|
223
|
-
// and values from token parameters.
|
|
224
|
-
return bucketParameters
|
|
225
|
-
.map((lookup) => {
|
|
226
|
-
const result = {};
|
|
227
|
-
for (const name of this.bucket_parameters) {
|
|
228
|
-
if (name in this.lookup_extractors) {
|
|
229
|
-
result[`bucket.${name}`] = lookup[name];
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
const value = this.static_extractors[name].evaluate(tables);
|
|
233
|
-
if (!isJsonValue(value)) {
|
|
234
|
-
// Not valid - exclude.
|
|
235
|
-
// Should we error instead?
|
|
236
|
-
return null;
|
|
237
|
-
}
|
|
238
|
-
result[`bucket.${name}`] = value;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return getBucketId(this.descriptor_name, this.bucket_parameters, result);
|
|
242
|
-
})
|
|
243
|
-
.filter((lookup) => lookup != null);
|
|
244
|
-
}
|
|
245
|
-
transformRows(row) {
|
|
246
|
-
const tables = { [this.table]: row };
|
|
247
|
-
const result = {};
|
|
248
|
-
for (const key in this.lookup_extractors) {
|
|
249
|
-
const extractor = this.lookup_extractors[key];
|
|
250
|
-
result[key] = extractor.evaluate(tables);
|
|
251
|
-
}
|
|
252
|
-
return [result];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Scalar } from 'yaml';
|
|
2
|
-
import { IdSequence } from './IdSequence.js';
|
|
3
|
-
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
4
|
-
import { QueryParseResult, SqlBucketDescriptor } from './SqlBucketDescriptor.js';
|
|
5
|
-
import { TablePattern } from './TablePattern.js';
|
|
6
|
-
import { YamlError } from './errors.js';
|
|
7
|
-
import { EvaluateRowOptions, EvaluatedParameters, EvaluatedRow, EvaluationError, QueryBucketIdOptions, SourceSchema, SqliteRow, SyncParameters, SyncRules } from './types.js';
|
|
8
|
-
export declare class SqlSyncRules implements SyncRules {
|
|
9
|
-
bucket_descriptors: SqlBucketDescriptor[];
|
|
10
|
-
content: string;
|
|
11
|
-
errors: YamlError[];
|
|
12
|
-
idSequence: IdSequence;
|
|
13
|
-
constructor(content: string);
|
|
14
|
-
static fromYaml(yaml: string, options?: {
|
|
15
|
-
schema?: SourceSchema;
|
|
16
|
-
throwOnError?: boolean;
|
|
17
|
-
}): SqlSyncRules;
|
|
18
|
-
static tokenError(token: any, message: string): YamlError;
|
|
19
|
-
static validate(yaml: string, options?: {
|
|
20
|
-
schema?: SourceSchema;
|
|
21
|
-
}): YamlError[];
|
|
22
|
-
debugGetOutputTables(): Record<string, any[]>;
|
|
23
|
-
/**
|
|
24
|
-
* Throws errors.
|
|
25
|
-
*/
|
|
26
|
-
evaluateParameterRow(table: SourceTableInterface, row: SqliteRow): EvaluatedParameters[];
|
|
27
|
-
evaluateParameterRowWithErrors(table: SourceTableInterface, row: SqliteRow): {
|
|
28
|
-
errors: EvaluationError[];
|
|
29
|
-
results: EvaluatedParameters[];
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Throws errors.
|
|
33
|
-
*/
|
|
34
|
-
evaluateRow(options: EvaluateRowOptions): EvaluatedRow[];
|
|
35
|
-
evaluateRowWithErrors(options: EvaluateRowOptions): {
|
|
36
|
-
errors: EvaluationError[];
|
|
37
|
-
results: EvaluatedRow[];
|
|
38
|
-
};
|
|
39
|
-
getSourceTables(): TablePattern[];
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated For testing only.
|
|
42
|
-
*/
|
|
43
|
-
getStaticBucketIds(parameters: SyncParameters): string[];
|
|
44
|
-
/**
|
|
45
|
-
* Note: This can error hard.
|
|
46
|
-
*/
|
|
47
|
-
queryBucketIds(options: QueryBucketIdOptions): Promise<string[]>;
|
|
48
|
-
tableSyncsData(table: SourceTableInterface): boolean;
|
|
49
|
-
tableSyncsParameters(table: SourceTableInterface): boolean;
|
|
50
|
-
throwOnError(): void;
|
|
51
|
-
withScalar(scalar: Scalar, cb: (value: string) => QueryParseResult): QueryParseResult;
|
|
52
|
-
}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
/* eslint-disable no-unsafe-optional-chaining */
|
|
3
|
-
/* eslint-disable no-await-in-loop */
|
|
4
|
-
/* eslint-disable unicorn/no-array-callback-reference */
|
|
5
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
6
|
-
/* eslint-disable eqeqeq */
|
|
7
|
-
/* eslint-disable no-eq-null */
|
|
8
|
-
/* eslint-disable camelcase */
|
|
9
|
-
import { LineCounter, Scalar, YAMLSeq, parseDocument } from 'yaml';
|
|
10
|
-
import { IdSequence } from './IdSequence.js';
|
|
11
|
-
import { SqlBucketDescriptor } from './SqlBucketDescriptor.js';
|
|
12
|
-
import { SqlRuleError, SyncRulesErrors, YamlError } from './errors.js';
|
|
13
|
-
import { validateSyncRulesSchema } from './json_schema.js';
|
|
14
|
-
import { isEvaluatedParameters, isEvaluatedRow, isEvaluationError } from './types.js';
|
|
15
|
-
export class SqlSyncRules {
|
|
16
|
-
bucket_descriptors = [];
|
|
17
|
-
content;
|
|
18
|
-
errors = [];
|
|
19
|
-
idSequence = new IdSequence();
|
|
20
|
-
constructor(content) {
|
|
21
|
-
this.content = content;
|
|
22
|
-
}
|
|
23
|
-
static fromYaml(yaml, options) {
|
|
24
|
-
const throwOnError = options?.throwOnError ?? true;
|
|
25
|
-
const schema = options?.schema;
|
|
26
|
-
const lineCounter = new LineCounter();
|
|
27
|
-
const parsed = parseDocument(yaml, { keepSourceTokens: true, lineCounter, schema: 'core' });
|
|
28
|
-
const rules = new SqlSyncRules(yaml);
|
|
29
|
-
if (parsed.errors.length > 0) {
|
|
30
|
-
rules.errors.push(...parsed.errors.map((error) => {
|
|
31
|
-
return new YamlError(error);
|
|
32
|
-
}));
|
|
33
|
-
if (throwOnError) {
|
|
34
|
-
rules.throwOnError();
|
|
35
|
-
}
|
|
36
|
-
return rules;
|
|
37
|
-
}
|
|
38
|
-
const bucketMap = parsed.get('bucket_definitions');
|
|
39
|
-
if (bucketMap == null) {
|
|
40
|
-
rules.errors.push(new YamlError(new Error(`'bucket_definitions' is required`)));
|
|
41
|
-
if (throwOnError) {
|
|
42
|
-
rules.throwOnError();
|
|
43
|
-
}
|
|
44
|
-
return rules;
|
|
45
|
-
}
|
|
46
|
-
for (const entry of bucketMap.items) {
|
|
47
|
-
const { key: keyScalar, value } = entry;
|
|
48
|
-
const key = keyScalar.toString();
|
|
49
|
-
const parameters = value.get('parameters', true);
|
|
50
|
-
const dataQueries = value.get('data', true);
|
|
51
|
-
const descriptor = new SqlBucketDescriptor(key, rules.idSequence);
|
|
52
|
-
if (parameters instanceof Scalar) {
|
|
53
|
-
rules.withScalar(parameters, (q) => {
|
|
54
|
-
return descriptor.addParameterQuery(q);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
else if (parameters instanceof YAMLSeq) {
|
|
58
|
-
for (const item of parameters.items) {
|
|
59
|
-
rules.withScalar(item, (q) => {
|
|
60
|
-
return descriptor.addParameterQuery(q, schema);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
descriptor.addParameterQuery('SELECT', schema);
|
|
66
|
-
}
|
|
67
|
-
if (!(dataQueries instanceof YAMLSeq)) {
|
|
68
|
-
rules.errors.push(this.tokenError(dataQueries ?? value, `'data' must be an array`));
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
for (const query of dataQueries.items) {
|
|
72
|
-
rules.withScalar(query, (q) => {
|
|
73
|
-
return descriptor.addDataQuery(q, schema);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
rules.bucket_descriptors.push(descriptor);
|
|
77
|
-
}
|
|
78
|
-
// Validate that there are no additional properties.
|
|
79
|
-
// Since these errors don't contain line numbers, do this last.
|
|
80
|
-
const valid = validateSyncRulesSchema(parsed.toJSON());
|
|
81
|
-
if (!valid) {
|
|
82
|
-
rules.errors.push(...validateSyncRulesSchema.errors.map((e) => {
|
|
83
|
-
return new YamlError(e);
|
|
84
|
-
}));
|
|
85
|
-
}
|
|
86
|
-
if (throwOnError) {
|
|
87
|
-
rules.throwOnError();
|
|
88
|
-
}
|
|
89
|
-
return rules;
|
|
90
|
-
}
|
|
91
|
-
static tokenError(token, message) {
|
|
92
|
-
const start = token?.srcToken?.offset ?? 0;
|
|
93
|
-
const end = start + 1;
|
|
94
|
-
return new YamlError(new Error(message), { end, start });
|
|
95
|
-
}
|
|
96
|
-
static validate(yaml, options) {
|
|
97
|
-
try {
|
|
98
|
-
const rules = this.fromYaml(yaml, options);
|
|
99
|
-
return rules.errors;
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
if (error instanceof SyncRulesErrors) {
|
|
103
|
-
return error.errors;
|
|
104
|
-
}
|
|
105
|
-
if (error instanceof YamlError) {
|
|
106
|
-
return [error];
|
|
107
|
-
}
|
|
108
|
-
return [new YamlError(error)];
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
debugGetOutputTables() {
|
|
112
|
-
const result = {};
|
|
113
|
-
for (const bucket of this.bucket_descriptors) {
|
|
114
|
-
for (const q of bucket.data_queries) {
|
|
115
|
-
result[q.table] ??= [];
|
|
116
|
-
const r = {
|
|
117
|
-
query: q.sql
|
|
118
|
-
};
|
|
119
|
-
result[q.table].push(r);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Throws errors.
|
|
126
|
-
*/
|
|
127
|
-
evaluateParameterRow(table, row) {
|
|
128
|
-
const { errors, results } = this.evaluateParameterRowWithErrors(table, row);
|
|
129
|
-
if (errors.length > 0) {
|
|
130
|
-
throw new Error(errors[0].error);
|
|
131
|
-
}
|
|
132
|
-
return results;
|
|
133
|
-
}
|
|
134
|
-
evaluateParameterRowWithErrors(table, row) {
|
|
135
|
-
const rawResults = [];
|
|
136
|
-
for (const query of this.bucket_descriptors) {
|
|
137
|
-
rawResults.push(...query.evaluateParameterRow(table, row));
|
|
138
|
-
}
|
|
139
|
-
const results = rawResults.filter(isEvaluatedParameters);
|
|
140
|
-
const errors = rawResults.filter(isEvaluationError);
|
|
141
|
-
return { errors, results };
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Throws errors.
|
|
145
|
-
*/
|
|
146
|
-
evaluateRow(options) {
|
|
147
|
-
const { errors, results } = this.evaluateRowWithErrors(options);
|
|
148
|
-
if (errors.length > 0) {
|
|
149
|
-
throw new Error(errors[0].error);
|
|
150
|
-
}
|
|
151
|
-
return results;
|
|
152
|
-
}
|
|
153
|
-
evaluateRowWithErrors(options) {
|
|
154
|
-
const rawResults = [];
|
|
155
|
-
for (const query of this.bucket_descriptors) {
|
|
156
|
-
rawResults.push(...query.evaluateRow(options));
|
|
157
|
-
}
|
|
158
|
-
const results = rawResults.filter(isEvaluatedRow);
|
|
159
|
-
const errors = rawResults.filter(isEvaluationError);
|
|
160
|
-
return { errors, results };
|
|
161
|
-
}
|
|
162
|
-
getSourceTables() {
|
|
163
|
-
const sourceTables = new Map();
|
|
164
|
-
for (const bucket of this.bucket_descriptors) {
|
|
165
|
-
for (const r of bucket.getSourceTables()) {
|
|
166
|
-
const key = `${r.connectionTag}.${r.schema}.${r.tablePattern}`;
|
|
167
|
-
sourceTables.set(key, r);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return [...sourceTables.values()];
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* @deprecated For testing only.
|
|
174
|
-
*/
|
|
175
|
-
getStaticBucketIds(parameters) {
|
|
176
|
-
const results = [];
|
|
177
|
-
for (const bucket of this.bucket_descriptors) {
|
|
178
|
-
results.push(...bucket.getStaticBucketIds(parameters));
|
|
179
|
-
}
|
|
180
|
-
return results;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Note: This can error hard.
|
|
184
|
-
*/
|
|
185
|
-
async queryBucketIds(options) {
|
|
186
|
-
const results = [];
|
|
187
|
-
for (const bucket of this.bucket_descriptors) {
|
|
188
|
-
results.push(...(await bucket.queryBucketIds(options)));
|
|
189
|
-
}
|
|
190
|
-
return results;
|
|
191
|
-
}
|
|
192
|
-
tableSyncsData(table) {
|
|
193
|
-
for (const bucket of this.bucket_descriptors) {
|
|
194
|
-
if (bucket.tableSyncsData(table)) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
tableSyncsParameters(table) {
|
|
201
|
-
for (const bucket of this.bucket_descriptors) {
|
|
202
|
-
if (bucket.tableSyncsParameters(table)) {
|
|
203
|
-
return true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
throwOnError() {
|
|
209
|
-
if (this.errors.some((e) => e.type != 'warning')) {
|
|
210
|
-
throw new SyncRulesErrors(this.errors);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
withScalar(scalar, cb) {
|
|
214
|
-
const value = scalar.toString();
|
|
215
|
-
const wrapped = (value) => {
|
|
216
|
-
try {
|
|
217
|
-
return cb(value);
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
return {
|
|
221
|
-
errors: [error],
|
|
222
|
-
parsed: false
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
const result = wrapped(value);
|
|
227
|
-
for (const err of result.errors) {
|
|
228
|
-
let sourceOffset = scalar.srcToken.offset;
|
|
229
|
-
if (scalar.type == Scalar.QUOTE_DOUBLE || scalar.type == Scalar.QUOTE_SINGLE) {
|
|
230
|
-
// TODO: Is there a better way to do this?
|
|
231
|
-
sourceOffset += 1;
|
|
232
|
-
}
|
|
233
|
-
let offset;
|
|
234
|
-
let end;
|
|
235
|
-
if (err instanceof SqlRuleError && err.location) {
|
|
236
|
-
offset = err.location.start + sourceOffset;
|
|
237
|
-
end = err.location.end + sourceOffset;
|
|
238
|
-
}
|
|
239
|
-
else if (typeof err.token?._location?.start === 'number') {
|
|
240
|
-
offset = sourceOffset + err.token?._location?.start;
|
|
241
|
-
end = sourceOffset + err.token?._location?.end;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
offset = sourceOffset;
|
|
245
|
-
end = sourceOffset + Math.max(value.length, 1);
|
|
246
|
-
}
|
|
247
|
-
const pos = { end, start: offset };
|
|
248
|
-
this.errors.push(new YamlError(err, pos));
|
|
249
|
-
}
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { TablePattern } from './TablePattern.js';
|
|
2
|
-
import { SourceSchema, SourceSchemaTable } from './types.js';
|
|
3
|
-
export interface SourceSchemaDefinition {
|
|
4
|
-
name: string;
|
|
5
|
-
tables: SourceTableDefinition[];
|
|
6
|
-
}
|
|
7
|
-
export interface SourceTableDefinition {
|
|
8
|
-
columns: SourceColumnDefinition[];
|
|
9
|
-
name: string;
|
|
10
|
-
}
|
|
11
|
-
export interface SourceColumnDefinition {
|
|
12
|
-
name: string;
|
|
13
|
-
/**
|
|
14
|
-
* Postgres type.
|
|
15
|
-
*/
|
|
16
|
-
pg_type: string;
|
|
17
|
-
}
|
|
18
|
-
export interface SourceConnectionDefinition {
|
|
19
|
-
schemas: SourceSchemaDefinition[];
|
|
20
|
-
tag: string;
|
|
21
|
-
}
|
|
22
|
-
export declare class StaticSchema implements SourceSchema {
|
|
23
|
-
private tables;
|
|
24
|
-
constructor(connections: SourceConnectionDefinition[]);
|
|
25
|
-
getTables(sourceTable: TablePattern): SourceSchemaTable[];
|
|
26
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
import { ExpressionType } from './ExpressionType.js';
|
|
3
|
-
class SourceTableDetails {
|
|
4
|
-
connectionTag;
|
|
5
|
-
schema;
|
|
6
|
-
table;
|
|
7
|
-
columns;
|
|
8
|
-
constructor(connection, schema, table) {
|
|
9
|
-
this.connectionTag = connection.tag;
|
|
10
|
-
this.schema = schema.name;
|
|
11
|
-
this.table = table.name;
|
|
12
|
-
this.columns = Object.fromEntries(table.columns.map((column) => {
|
|
13
|
-
return [column.name, mapColumn(column)];
|
|
14
|
-
}));
|
|
15
|
-
}
|
|
16
|
-
getColumns() {
|
|
17
|
-
return Object.values(this.columns);
|
|
18
|
-
}
|
|
19
|
-
getType(column) {
|
|
20
|
-
return this.columns[column]?.type;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export class StaticSchema {
|
|
24
|
-
tables;
|
|
25
|
-
constructor(connections) {
|
|
26
|
-
this.tables = [];
|
|
27
|
-
for (const connection of connections) {
|
|
28
|
-
for (const schema of connection.schemas) {
|
|
29
|
-
for (const table of schema.tables) {
|
|
30
|
-
this.tables.push(new SourceTableDetails(connection, schema, table));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
getTables(sourceTable) {
|
|
36
|
-
const filtered = this.tables.filter((t) => sourceTable.matches(t));
|
|
37
|
-
return filtered;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function mapColumn(column) {
|
|
41
|
-
return {
|
|
42
|
-
name: column.name,
|
|
43
|
-
type: mapType(column.pg_type)
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function mapType(type) {
|
|
47
|
-
if (type?.endsWith('[]')) {
|
|
48
|
-
return ExpressionType.TEXT;
|
|
49
|
-
}
|
|
50
|
-
switch (type) {
|
|
51
|
-
case 'bool': {
|
|
52
|
-
return ExpressionType.INTEGER;
|
|
53
|
-
}
|
|
54
|
-
case 'bytea': {
|
|
55
|
-
return ExpressionType.BLOB;
|
|
56
|
-
}
|
|
57
|
-
case 'int2':
|
|
58
|
-
case 'int4':
|
|
59
|
-
case 'int8':
|
|
60
|
-
case 'oid': {
|
|
61
|
-
return ExpressionType.INTEGER;
|
|
62
|
-
}
|
|
63
|
-
case 'float4':
|
|
64
|
-
case 'float8': {
|
|
65
|
-
return ExpressionType.REAL;
|
|
66
|
-
}
|
|
67
|
-
default: {
|
|
68
|
-
return ExpressionType.TEXT;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SelectFromStatement, SelectedColumn } from 'pgsql-ast-parser';
|
|
2
|
-
import { SqlRuleError } from './errors.js';
|
|
3
|
-
import { SqlTools } from './sql_filters.js';
|
|
4
|
-
import { ParameterMatchClause, StaticRowValueClause, SyncParameters } from './types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Represents a bucket parameter query without any tables, e.g.:
|
|
7
|
-
*
|
|
8
|
-
* SELECT token_parameters.user_id
|
|
9
|
-
* SELECT token_parameters.user_id as user_id WHERE token_parameters.is_admin
|
|
10
|
-
*/
|
|
11
|
-
export declare class StaticSqlParameterQuery {
|
|
12
|
-
/** _Output_ bucket parameters */
|
|
13
|
-
bucket_parameters?: string[];
|
|
14
|
-
columns?: SelectedColumn[];
|
|
15
|
-
descriptor_name?: string;
|
|
16
|
-
errors: SqlRuleError[];
|
|
17
|
-
filter?: ParameterMatchClause;
|
|
18
|
-
id?: string;
|
|
19
|
-
sql?: string;
|
|
20
|
-
static_extractors: Record<string, StaticRowValueClause>;
|
|
21
|
-
tools?: SqlTools;
|
|
22
|
-
static fromSql(descriptor_name: string, sql: string, q: SelectFromStatement): StaticSqlParameterQuery;
|
|
23
|
-
getStaticBucketIds(parameters: SyncParameters): string[];
|
|
24
|
-
}
|