powersync 0.1.0 → 0.1.2
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 +11 -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 +5 -7
- 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,71 +0,0 @@
|
|
|
1
|
-
import { SqlTools } from './sql_filters.js';
|
|
2
|
-
import { checkUnsupportedFeatures, isClauseError } from './sql_support.js';
|
|
3
|
-
import { getBucketId, isJsonValue } from './utils.js';
|
|
4
|
-
/**
|
|
5
|
-
* Represents a bucket parameter query without any tables, e.g.:
|
|
6
|
-
*
|
|
7
|
-
* SELECT token_parameters.user_id
|
|
8
|
-
* SELECT token_parameters.user_id as user_id WHERE token_parameters.is_admin
|
|
9
|
-
*/
|
|
10
|
-
export class StaticSqlParameterQuery {
|
|
11
|
-
/** _Output_ bucket parameters */
|
|
12
|
-
bucket_parameters;
|
|
13
|
-
columns;
|
|
14
|
-
descriptor_name;
|
|
15
|
-
errors = [];
|
|
16
|
-
filter;
|
|
17
|
-
id;
|
|
18
|
-
sql;
|
|
19
|
-
static_extractors = {};
|
|
20
|
-
tools;
|
|
21
|
-
static fromSql(descriptor_name, sql, q) {
|
|
22
|
-
const query = new StaticSqlParameterQuery();
|
|
23
|
-
query.errors.push(...checkUnsupportedFeatures(sql, q));
|
|
24
|
-
const tools = new SqlTools({
|
|
25
|
-
sql,
|
|
26
|
-
table: undefined,
|
|
27
|
-
value_tables: ['token_parameters', 'user_parameters']
|
|
28
|
-
});
|
|
29
|
-
const { where } = q;
|
|
30
|
-
const filter = tools.compileWhereClause(where);
|
|
31
|
-
const columns = q.columns ?? [];
|
|
32
|
-
const bucket_parameters = columns.map((column) => tools.getOutputName(column));
|
|
33
|
-
query.sql = sql;
|
|
34
|
-
query.descriptor_name = descriptor_name;
|
|
35
|
-
query.bucket_parameters = bucket_parameters;
|
|
36
|
-
query.columns = columns;
|
|
37
|
-
query.tools = tools;
|
|
38
|
-
query.filter = filter;
|
|
39
|
-
for (const column of columns) {
|
|
40
|
-
const name = tools.getSpecificOutputName(column);
|
|
41
|
-
const extractor = tools.compileStaticExtractor(column.expr);
|
|
42
|
-
if (isClauseError(extractor)) {
|
|
43
|
-
// Error logged already
|
|
44
|
-
continue;
|
|
45
|
-
}
|
|
46
|
-
query.static_extractors[name] = extractor;
|
|
47
|
-
}
|
|
48
|
-
query.errors.push(...tools.errors);
|
|
49
|
-
return query;
|
|
50
|
-
}
|
|
51
|
-
getStaticBucketIds(parameters) {
|
|
52
|
-
const tables = { token_parameters: parameters.token_parameters, user_parameters: parameters.user_parameters };
|
|
53
|
-
const filtered = this.filter.filter(tables);
|
|
54
|
-
if (filtered.length === 0) {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
const result = {};
|
|
58
|
-
for (const name of this.bucket_parameters) {
|
|
59
|
-
const value = this.static_extractors[name].evaluate(tables);
|
|
60
|
-
if (isJsonValue(value)) {
|
|
61
|
-
result[`bucket.${name}`] = value;
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
// Not valid.
|
|
65
|
-
// Should we error instead?
|
|
66
|
-
return [];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return [getBucketId(this.descriptor_name, this.bucket_parameters, result)];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { SourceTableInterface } from './SourceTableInterface.js';
|
|
2
|
-
export declare const DEFAULT_TAG = "default";
|
|
3
|
-
export declare const DEFAULT_SCHEMA = "public";
|
|
4
|
-
/**
|
|
5
|
-
* Some pattern matching SourceTables.
|
|
6
|
-
*/
|
|
7
|
-
export declare class TablePattern {
|
|
8
|
-
readonly connectionTag: string;
|
|
9
|
-
readonly schema: string;
|
|
10
|
-
readonly tablePattern: string;
|
|
11
|
-
constructor(schema: string | undefined, tablePattern: string);
|
|
12
|
-
get isWildcard(): boolean;
|
|
13
|
-
get name(): string;
|
|
14
|
-
get tablePrefix(): string;
|
|
15
|
-
matches(table: SourceTableInterface): boolean;
|
|
16
|
-
suffix(table: string): string;
|
|
17
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_TAG = 'default';
|
|
2
|
-
export const DEFAULT_SCHEMA = 'public';
|
|
3
|
-
/**
|
|
4
|
-
* Some pattern matching SourceTables.
|
|
5
|
-
*/
|
|
6
|
-
export class TablePattern {
|
|
7
|
-
connectionTag;
|
|
8
|
-
schema;
|
|
9
|
-
tablePattern;
|
|
10
|
-
constructor(schema, tablePattern) {
|
|
11
|
-
schema ??= DEFAULT_SCHEMA;
|
|
12
|
-
const splitSchema = schema.split('.');
|
|
13
|
-
if (splitSchema.length > 2) {
|
|
14
|
-
throw new Error(`Invalid schema: ${schema}`);
|
|
15
|
-
}
|
|
16
|
-
if (splitSchema.length === 2) {
|
|
17
|
-
this.connectionTag = splitSchema[0];
|
|
18
|
-
this.schema = splitSchema[1];
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
this.connectionTag = DEFAULT_TAG;
|
|
22
|
-
this.schema = schema;
|
|
23
|
-
}
|
|
24
|
-
this.tablePattern = tablePattern;
|
|
25
|
-
}
|
|
26
|
-
get isWildcard() {
|
|
27
|
-
return this.tablePattern.endsWith('%');
|
|
28
|
-
}
|
|
29
|
-
get name() {
|
|
30
|
-
if (this.isWildcard) {
|
|
31
|
-
throw new Error('Cannot get name for wildcard table');
|
|
32
|
-
}
|
|
33
|
-
return this.tablePattern;
|
|
34
|
-
}
|
|
35
|
-
get tablePrefix() {
|
|
36
|
-
if (!this.isWildcard) {
|
|
37
|
-
throw new Error('Not a wildcard table');
|
|
38
|
-
}
|
|
39
|
-
return this.tablePattern.slice(0, Math.max(0, this.tablePattern.length - 1));
|
|
40
|
-
}
|
|
41
|
-
matches(table) {
|
|
42
|
-
if (this.connectionTag != table.connectionTag || this.schema != table.schema) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (this.isWildcard) {
|
|
46
|
-
return table.table.startsWith(this.tablePrefix);
|
|
47
|
-
}
|
|
48
|
-
return this.tablePattern == table.table;
|
|
49
|
-
}
|
|
50
|
-
suffix(table) {
|
|
51
|
-
if (!this.isWildcard) {
|
|
52
|
-
return '';
|
|
53
|
-
}
|
|
54
|
-
return table.slice(this.tablePrefix.length);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ColumnDefinition, ExpressionType } from './ExpressionType.js';
|
|
2
|
-
import { QuerySchema, SourceSchemaTable } from './types.js';
|
|
3
|
-
export declare class TableQuerySchema implements QuerySchema {
|
|
4
|
-
private tables;
|
|
5
|
-
private alias;
|
|
6
|
-
constructor(tables: SourceSchemaTable[], alias: string);
|
|
7
|
-
getColumns(table: string): ColumnDefinition[];
|
|
8
|
-
getType(table: string, column: string): ExpressionType;
|
|
9
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
/* eslint-disable no-eq-null */
|
|
3
|
-
/* eslint-disable eqeqeq */
|
|
4
|
-
import { ExpressionType } from './ExpressionType.js';
|
|
5
|
-
export class TableQuerySchema {
|
|
6
|
-
tables;
|
|
7
|
-
alias;
|
|
8
|
-
// eslint-disable-next-line no-useless-constructor
|
|
9
|
-
constructor(tables, alias
|
|
10
|
-
// eslint-disable-next-line prettier/prettier
|
|
11
|
-
) {
|
|
12
|
-
this.tables = tables;
|
|
13
|
-
this.alias = alias;
|
|
14
|
-
}
|
|
15
|
-
getColumns(table) {
|
|
16
|
-
if (table != this.alias) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
const columns = {};
|
|
20
|
-
for (const table of this.tables) {
|
|
21
|
-
for (const col of table.getColumns()) {
|
|
22
|
-
if (!(col.name in columns)) {
|
|
23
|
-
columns[col.name] = col;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return Object.values(columns);
|
|
28
|
-
}
|
|
29
|
-
getType(table, column) {
|
|
30
|
-
if (table != this.alias) {
|
|
31
|
-
return ExpressionType.NONE;
|
|
32
|
-
}
|
|
33
|
-
for (const table of this.tables) {
|
|
34
|
-
const t = table.getType(column);
|
|
35
|
-
if (t != null) {
|
|
36
|
-
return t;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return ExpressionType.NONE;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Expr, NodeLocation } from 'pgsql-ast-parser';
|
|
2
|
-
export interface ErrorLocation {
|
|
3
|
-
end: number;
|
|
4
|
-
start: number;
|
|
5
|
-
}
|
|
6
|
-
export declare class SqlRuleError extends Error {
|
|
7
|
-
sql: string;
|
|
8
|
-
location?: ErrorLocation;
|
|
9
|
-
type: 'fatal' | 'warning';
|
|
10
|
-
constructor(message: string, sql: string, location?: Expr | NodeLocation);
|
|
11
|
-
}
|
|
12
|
-
export declare class YamlError extends Error {
|
|
13
|
-
source: Error;
|
|
14
|
-
location: ErrorLocation;
|
|
15
|
-
type: 'fatal' | 'warning';
|
|
16
|
-
constructor(source: Error, location?: ErrorLocation);
|
|
17
|
-
}
|
|
18
|
-
export declare class SyncRulesErrors extends Error {
|
|
19
|
-
errors: YamlError[];
|
|
20
|
-
constructor(errors: YamlError[]);
|
|
21
|
-
static constructMessage(errors: YamlError[]): string;
|
|
22
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import * as yaml from 'yaml';
|
|
2
|
-
function getLocation(location) {
|
|
3
|
-
if (location != null && !isLocation(location)) {
|
|
4
|
-
return location._location;
|
|
5
|
-
}
|
|
6
|
-
if (isLocation(location)) {
|
|
7
|
-
return location;
|
|
8
|
-
}
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
function isLocation(location) {
|
|
12
|
-
return (location != null &&
|
|
13
|
-
typeof location.start === 'number' &&
|
|
14
|
-
typeof location.end === 'number');
|
|
15
|
-
}
|
|
16
|
-
export class SqlRuleError extends Error {
|
|
17
|
-
sql;
|
|
18
|
-
location;
|
|
19
|
-
type = 'fatal';
|
|
20
|
-
constructor(message, sql, location) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.sql = sql;
|
|
23
|
-
this.location = getLocation(location) ?? { end: sql.length, start: 0 };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
export class YamlError extends Error {
|
|
27
|
-
source;
|
|
28
|
-
location;
|
|
29
|
-
type = 'fatal';
|
|
30
|
-
constructor(source, location) {
|
|
31
|
-
super(source.message);
|
|
32
|
-
this.source = source;
|
|
33
|
-
if (location == null && source instanceof yaml.YAMLError) {
|
|
34
|
-
location = {
|
|
35
|
-
end: source.pos[1],
|
|
36
|
-
start: source.pos[0]
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
else if (location == null) {
|
|
40
|
-
location = {
|
|
41
|
-
end: 10,
|
|
42
|
-
start: 0
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
if (source instanceof YamlError || source instanceof SqlRuleError) {
|
|
46
|
-
this.type = source.type;
|
|
47
|
-
}
|
|
48
|
-
this.location = location;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class SyncRulesErrors extends Error {
|
|
52
|
-
errors;
|
|
53
|
-
constructor(errors) {
|
|
54
|
-
super(SyncRulesErrors.constructMessage(errors));
|
|
55
|
-
this.errors = errors;
|
|
56
|
-
}
|
|
57
|
-
static constructMessage(errors) {
|
|
58
|
-
return errors.map((e) => e.message).join(', ');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './errors.js';
|
|
2
|
-
export * from './IdSequence.js';
|
|
3
|
-
export * from './SourceTableInterface.js';
|
|
4
|
-
export * from './sql_filters.js';
|
|
5
|
-
export * from './sql_functions.js';
|
|
6
|
-
export * from './SqlSyncRules.js';
|
|
7
|
-
export * from './TablePattern.js';
|
|
8
|
-
export * from './types.js';
|
|
9
|
-
export * from './utils.js';
|
|
10
|
-
export * from './SqlParameterQuery.js';
|
|
11
|
-
export * from './json_schema.js';
|
|
12
|
-
export * from './StaticSchema.js';
|
|
13
|
-
export * from './ExpressionType.js';
|
|
14
|
-
export * from './SchemaGenerator.js';
|
|
15
|
-
export * from './DartSchemaGenerator.js';
|
|
16
|
-
export * from './JsSchemaGenerator.js';
|
|
17
|
-
export * from './generators.js';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './errors.js';
|
|
2
|
-
export * from './IdSequence.js';
|
|
3
|
-
export * from './SourceTableInterface.js';
|
|
4
|
-
export * from './sql_filters.js';
|
|
5
|
-
export * from './sql_functions.js';
|
|
6
|
-
export * from './SqlSyncRules.js';
|
|
7
|
-
export * from './TablePattern.js';
|
|
8
|
-
export * from './types.js';
|
|
9
|
-
export * from './utils.js';
|
|
10
|
-
export * from './SqlParameterQuery.js';
|
|
11
|
-
export * from './json_schema.js';
|
|
12
|
-
export * from './StaticSchema.js';
|
|
13
|
-
export * from './ExpressionType.js';
|
|
14
|
-
export * from './SchemaGenerator.js';
|
|
15
|
-
export * from './DartSchemaGenerator.js';
|
|
16
|
-
export * from './JsSchemaGenerator.js';
|
|
17
|
-
export * from './generators.js';
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
/* eslint-disable camelcase */
|
|
4
|
-
import ajvModule from 'ajv';
|
|
5
|
-
// Hack to make this work both in NodeJS and a browser
|
|
6
|
-
const Ajv = ajvModule.default ?? ajvModule;
|
|
7
|
-
const ajv = new Ajv({ allErrors: true, verbose: true });
|
|
8
|
-
export const syncRulesSchema = {
|
|
9
|
-
additionalProperties: false,
|
|
10
|
-
properties: {
|
|
11
|
-
bucket_definitions: {
|
|
12
|
-
description: 'List of bucket definitions',
|
|
13
|
-
examples: [{ global: { data: 'select * from mytable' } }],
|
|
14
|
-
patternProperties: {
|
|
15
|
-
'.*': {
|
|
16
|
-
additionalProperties: false,
|
|
17
|
-
examples: [{ data: ['select * from mytable'] }],
|
|
18
|
-
properties: {
|
|
19
|
-
data: {
|
|
20
|
-
description: 'Data queries',
|
|
21
|
-
items: {
|
|
22
|
-
type: 'string'
|
|
23
|
-
},
|
|
24
|
-
type: 'array'
|
|
25
|
-
},
|
|
26
|
-
parameters: {
|
|
27
|
-
anyOf: [
|
|
28
|
-
{ description: 'Parameter query', type: 'string' },
|
|
29
|
-
{
|
|
30
|
-
description: 'Parameter queries',
|
|
31
|
-
items: {
|
|
32
|
-
type: 'string'
|
|
33
|
-
},
|
|
34
|
-
type: 'array'
|
|
35
|
-
}
|
|
36
|
-
],
|
|
37
|
-
description: 'Parameter query(ies)'
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
required: ['data'],
|
|
41
|
-
type: 'object'
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
type: 'object'
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
required: ['bucket_definitions'],
|
|
48
|
-
type: 'object'
|
|
49
|
-
};
|
|
50
|
-
export const validateSyncRulesSchema = ajv.compile(syncRulesSchema);
|
|
@@ -1,91 +0,0 @@
|
|
|
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 { ClauseError, CompiledClause, ParameterMatchClause, QuerySchema, StaticRowValueClause, TrueIfParametersMatch } from './types.js';
|
|
5
|
-
export declare const MATCH_CONST_FALSE: TrueIfParametersMatch;
|
|
6
|
-
export declare const MATCH_CONST_TRUE: TrueIfParametersMatch;
|
|
7
|
-
export interface SqlToolsOptions {
|
|
8
|
-
/**
|
|
9
|
-
* Set of tables used for FilterParameters.
|
|
10
|
-
*
|
|
11
|
-
* This is tables that can be used to filter the data on, e.g.:
|
|
12
|
-
* "bucket" (bucket parameters for data query)
|
|
13
|
-
* "token_parameters" (token parameters for parameter query)
|
|
14
|
-
*/
|
|
15
|
-
parameter_tables?: string[];
|
|
16
|
-
schema?: QuerySchema;
|
|
17
|
-
/**
|
|
18
|
-
* For debugging / error messages.
|
|
19
|
-
*/
|
|
20
|
-
sql: string;
|
|
21
|
-
/**
|
|
22
|
-
* true if values in parameter tables can be expanded, i.e. `WHERE value IN parameters.something`.
|
|
23
|
-
*
|
|
24
|
-
* Only one parameter may be expanded.
|
|
25
|
-
*/
|
|
26
|
-
supports_expanding_parameters?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Default table name, if any. I.e. SELECT FROM <table>.
|
|
29
|
-
*
|
|
30
|
-
* Used for to determine the table when using bare column names.
|
|
31
|
-
*/
|
|
32
|
-
table?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Set of tables used in QueryParameters.
|
|
35
|
-
*
|
|
36
|
-
* If not specified, defaults to [table].
|
|
37
|
-
*/
|
|
38
|
-
value_tables?: string[];
|
|
39
|
-
}
|
|
40
|
-
export declare class SqlTools {
|
|
41
|
-
default_table?: string;
|
|
42
|
-
errors: SqlRuleError[];
|
|
43
|
-
parameter_tables: string[];
|
|
44
|
-
schema?: QuerySchema;
|
|
45
|
-
sql: string;
|
|
46
|
-
supports_expanding_parameters: boolean;
|
|
47
|
-
value_tables: string[];
|
|
48
|
-
constructor(options: SqlToolsOptions);
|
|
49
|
-
/**
|
|
50
|
-
* Given an expression, return a compiled clause.
|
|
51
|
-
*/
|
|
52
|
-
compileClause(expr: Expr | nil): CompiledClause;
|
|
53
|
-
compileStaticExtractor(expr: Expr | nil): ClauseError | StaticRowValueClause;
|
|
54
|
-
/**
|
|
55
|
-
* Compile the where clause into a ParameterMatchClause.
|
|
56
|
-
*
|
|
57
|
-
* A ParameterMatchClause takes a data row, and returns filter values that
|
|
58
|
-
* would make the expression true for the row.
|
|
59
|
-
*/
|
|
60
|
-
compileWhereClause(where: Expr | nil): ParameterMatchClause;
|
|
61
|
-
error(message: string, expr: Expr | NodeLocation | undefined): ClauseError;
|
|
62
|
-
/**
|
|
63
|
-
* "some_column" => "some_column"
|
|
64
|
-
* "table.some_column" => "some_column".
|
|
65
|
-
* "some_function() AS some_column" => "some_column"
|
|
66
|
-
* "some_function() some_column" => "some_column"
|
|
67
|
-
* "some_function()" => error
|
|
68
|
-
*/
|
|
69
|
-
getOutputName(column: SelectedColumn): string;
|
|
70
|
-
getParameterRef(expr: Expr): string | undefined;
|
|
71
|
-
getSpecificOutputName(column: SelectedColumn): string;
|
|
72
|
-
/**
|
|
73
|
-
* Get the table name from an expression.
|
|
74
|
-
*
|
|
75
|
-
* Only "value" tables are supported here, not parameter values.
|
|
76
|
-
*/
|
|
77
|
-
getTableName(ref: ExprRef): string;
|
|
78
|
-
/**
|
|
79
|
-
* Check if an expression is a parameter_table reference.
|
|
80
|
-
*/
|
|
81
|
-
isParameterRef(expr: Expr): expr is ExprRef;
|
|
82
|
-
/**
|
|
83
|
-
* Check if an expression is a value_tables reference.
|
|
84
|
-
*
|
|
85
|
-
* This means the expression can be evaluated directly on a value row.
|
|
86
|
-
*/
|
|
87
|
-
isTableRef(expr: Expr): expr is ExprRef;
|
|
88
|
-
refHasSchema(ref: ExprRef): boolean;
|
|
89
|
-
warn(message: string, expr: Expr | NodeLocation | undefined): void;
|
|
90
|
-
private checkRef;
|
|
91
|
-
}
|