@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,26 @@
|
|
|
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
|
+
name: string;
|
|
9
|
+
columns: SourceColumnDefinition[];
|
|
10
|
+
}
|
|
11
|
+
export interface SourceColumnDefinition {
|
|
12
|
+
name: string;
|
|
13
|
+
/**
|
|
14
|
+
* Postgres type.
|
|
15
|
+
*/
|
|
16
|
+
pg_type: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SourceConnectionDefinition {
|
|
19
|
+
tag: string;
|
|
20
|
+
schemas: SourceSchemaDefinition[];
|
|
21
|
+
}
|
|
22
|
+
export declare class StaticSchema implements SourceSchema {
|
|
23
|
+
private tables;
|
|
24
|
+
constructor(connections: SourceConnectionDefinition[]);
|
|
25
|
+
getTables(sourceTable: TablePattern): SourceSchemaTable[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ExpressionType } from './ExpressionType.js';
|
|
2
|
+
class SourceTableDetails {
|
|
3
|
+
constructor(connection, schema, table) {
|
|
4
|
+
this.connectionTag = connection.tag;
|
|
5
|
+
this.schema = schema.name;
|
|
6
|
+
this.table = table.name;
|
|
7
|
+
this.columns = Object.fromEntries(table.columns.map((column) => {
|
|
8
|
+
return [column.name, mapColumn(column)];
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
getType(column) {
|
|
12
|
+
return this.columns[column]?.type;
|
|
13
|
+
}
|
|
14
|
+
getColumns() {
|
|
15
|
+
return Object.values(this.columns);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export class StaticSchema {
|
|
19
|
+
constructor(connections) {
|
|
20
|
+
this.tables = [];
|
|
21
|
+
for (let connection of connections) {
|
|
22
|
+
for (let schema of connection.schemas) {
|
|
23
|
+
for (let table of schema.tables) {
|
|
24
|
+
this.tables.push(new SourceTableDetails(connection, schema, table));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
getTables(sourceTable) {
|
|
30
|
+
const filtered = this.tables.filter((t) => sourceTable.matches(t));
|
|
31
|
+
return filtered;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function mapColumn(column) {
|
|
35
|
+
return {
|
|
36
|
+
name: column.name,
|
|
37
|
+
type: mapType(column.pg_type)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function mapType(type) {
|
|
41
|
+
if (type?.endsWith('[]')) {
|
|
42
|
+
return ExpressionType.TEXT;
|
|
43
|
+
}
|
|
44
|
+
switch (type) {
|
|
45
|
+
case 'bool':
|
|
46
|
+
return ExpressionType.INTEGER;
|
|
47
|
+
case 'bytea':
|
|
48
|
+
return ExpressionType.BLOB;
|
|
49
|
+
case 'int2':
|
|
50
|
+
case 'int4':
|
|
51
|
+
case 'int8':
|
|
52
|
+
case 'oid':
|
|
53
|
+
return ExpressionType.INTEGER;
|
|
54
|
+
case 'float4':
|
|
55
|
+
case 'float8':
|
|
56
|
+
return ExpressionType.REAL;
|
|
57
|
+
default:
|
|
58
|
+
return ExpressionType.TEXT;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=StaticSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticSchema.js","sourceRoot":"","sources":["../src/StaticSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA4BvE,MAAM,kBAAkB;IAMtB,YAAY,UAAsC,EAAE,MAA8B,EAAE,KAA4B;QAC9G,IAAI,CAAC,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,WAAW,CAC/B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,MAAc;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC;IACpC,CAAC;IAED,UAAU;QACR,OAAO,MAAM,CAAC,MAAM,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,cAAc,CAAC,IAAI,CAAC;QAC7B;YACE,OAAO,cAAc,CAAC,IAAI,CAAC;KAC9B;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SelectedColumn, SelectFromStatement } from 'pgsql-ast-parser';
|
|
2
|
+
import { SqlRuleError } from './errors.js';
|
|
3
|
+
import { SqlTools } from './sql_filters.js';
|
|
4
|
+
import { ParameterValueClause, QueryParseOptions, RequestParameters } 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
|
+
static fromSql(descriptor_name: string, sql: string, q: SelectFromStatement, options?: QueryParseOptions): StaticSqlParameterQuery;
|
|
13
|
+
sql?: string;
|
|
14
|
+
columns?: SelectedColumn[];
|
|
15
|
+
parameter_extractors: Record<string, ParameterValueClause>;
|
|
16
|
+
descriptor_name?: string;
|
|
17
|
+
/** _Output_ bucket parameters */
|
|
18
|
+
bucket_parameters?: string[];
|
|
19
|
+
id?: string;
|
|
20
|
+
tools?: SqlTools;
|
|
21
|
+
filter?: ParameterValueClause;
|
|
22
|
+
errors: SqlRuleError[];
|
|
23
|
+
getStaticBucketIds(parameters: RequestParameters): string[];
|
|
24
|
+
get hasAuthenticatedBucketParameters(): boolean;
|
|
25
|
+
get usesUnauthenticatedRequestParameters(): boolean;
|
|
26
|
+
get usesDangerousRequestParameters(): boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SqlRuleError } from './errors.js';
|
|
2
|
+
import { SqlTools } from './sql_filters.js';
|
|
3
|
+
import { checkUnsupportedFeatures, isClauseError, isParameterValueClause, sqliteBool } from './sql_support.js';
|
|
4
|
+
import { getBucketId, isJsonValue } from './utils.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 class StaticSqlParameterQuery {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.parameter_extractors = {};
|
|
14
|
+
this.errors = [];
|
|
15
|
+
}
|
|
16
|
+
static fromSql(descriptor_name, sql, q, options) {
|
|
17
|
+
const query = new StaticSqlParameterQuery();
|
|
18
|
+
query.errors.push(...checkUnsupportedFeatures(sql, q));
|
|
19
|
+
const tools = new SqlTools({
|
|
20
|
+
table: undefined,
|
|
21
|
+
parameter_tables: ['token_parameters', 'user_parameters'],
|
|
22
|
+
supports_parameter_expressions: true,
|
|
23
|
+
sql
|
|
24
|
+
});
|
|
25
|
+
const where = q.where;
|
|
26
|
+
const filter = tools.compileParameterValueExtractor(where);
|
|
27
|
+
const columns = q.columns ?? [];
|
|
28
|
+
const bucket_parameters = columns.map((column) => tools.getOutputName(column));
|
|
29
|
+
query.sql = sql;
|
|
30
|
+
query.descriptor_name = descriptor_name;
|
|
31
|
+
query.bucket_parameters = bucket_parameters;
|
|
32
|
+
query.columns = columns;
|
|
33
|
+
query.tools = tools;
|
|
34
|
+
if (!isClauseError(filter)) {
|
|
35
|
+
query.filter = filter;
|
|
36
|
+
}
|
|
37
|
+
for (let column of columns) {
|
|
38
|
+
const name = tools.getSpecificOutputName(column);
|
|
39
|
+
const extractor = tools.compileParameterValueExtractor(column.expr);
|
|
40
|
+
if (isClauseError(extractor)) {
|
|
41
|
+
// Error logged already
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
query.parameter_extractors[name] = extractor;
|
|
45
|
+
}
|
|
46
|
+
query.errors.push(...tools.errors);
|
|
47
|
+
if (query.usesDangerousRequestParameters && !options?.accept_potentially_dangerous_queries) {
|
|
48
|
+
let err = new SqlRuleError('Pontially dangerous query based on unauthenticated client parameters', sql);
|
|
49
|
+
err.type = 'warning';
|
|
50
|
+
query.errors.push(err);
|
|
51
|
+
}
|
|
52
|
+
return query;
|
|
53
|
+
}
|
|
54
|
+
getStaticBucketIds(parameters) {
|
|
55
|
+
if (this.filter == null) {
|
|
56
|
+
// Error in filter clause
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
const filterValue = this.filter.lookupParameterValue(parameters);
|
|
60
|
+
if (sqliteBool(filterValue) === 0n) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
let result = {};
|
|
64
|
+
for (let name of this.bucket_parameters) {
|
|
65
|
+
const value = this.parameter_extractors[name].lookupParameterValue(parameters);
|
|
66
|
+
if (isJsonValue(value)) {
|
|
67
|
+
result[`bucket.${name}`] = value;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// Not valid.
|
|
71
|
+
// Should we error instead?
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [getBucketId(this.descriptor_name, this.bucket_parameters, result)];
|
|
76
|
+
}
|
|
77
|
+
get hasAuthenticatedBucketParameters() {
|
|
78
|
+
// select where request.jwt() ->> 'role' == 'authorized'
|
|
79
|
+
// we do not count this as a sufficient check
|
|
80
|
+
// const authenticatedFilter = this.filter!.usesAuthenticatedRequestParameters;
|
|
81
|
+
// select request.user_id() as user_id
|
|
82
|
+
const authenticatedExtractor = Object.values(this.parameter_extractors).find((clause) => isParameterValueClause(clause) && clause.usesAuthenticatedRequestParameters) != null;
|
|
83
|
+
return authenticatedExtractor;
|
|
84
|
+
}
|
|
85
|
+
get usesUnauthenticatedRequestParameters() {
|
|
86
|
+
// select where request.parameters() ->> 'include_comments'
|
|
87
|
+
const unauthenticatedFilter = this.filter.usesUnauthenticatedRequestParameters;
|
|
88
|
+
// select request.parameters() ->> 'project_id'
|
|
89
|
+
const unauthenticatedExtractor = Object.values(this.parameter_extractors).find((clause) => isParameterValueClause(clause) && clause.usesUnauthenticatedRequestParameters) != null;
|
|
90
|
+
return unauthenticatedFilter || unauthenticatedExtractor;
|
|
91
|
+
}
|
|
92
|
+
get usesDangerousRequestParameters() {
|
|
93
|
+
return this.usesUnauthenticatedRequestParameters && !this.hasAuthenticatedBucketParameters;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=StaticSqlParameterQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticSqlParameterQuery.js","sourceRoot":"","sources":["../src/StaticSqlParameterQuery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,aAAa,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE/G,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,OAAO,uBAAuB;IAApC;QAiDE,yBAAoB,GAAyC,EAAE,CAAC;QAShE,WAAM,GAAmB,EAAE,CAAC;IAwD9B,CAAC;IAjHC,MAAM,CAAC,OAAO,CAAC,eAAuB,EAAE,GAAW,EAAE,CAAsB,EAAE,OAA2B;QACtG,MAAM,KAAK,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAE5C,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAEvD,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC;YACzB,KAAK,EAAE,SAAS;YAChB,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;YACzD,8BAA8B,EAAE,IAAI;YACpC,GAAG;SACJ,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;QAEtB,MAAM,MAAM,GAAG,KAA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AC/C,MAAM,wBAAwB,GAC5B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAC3C,CAAC,MAAM,EAAE,EAAE,CAAC,sBAAsB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,oCAAoC,CAC1F,IAAI,IAAI,CAAC;QAEZ,OAAO,qBAAqB,IAAI,wBAAwB,CAAC;IAC3D,CAAC;IAED,IAAI,8BAA8B;QAChC,OAAO,IAAI,CAAC,oCAAoC,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC;IAC7F,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 tablePrefix(): string;
|
|
14
|
+
get name(): string;
|
|
15
|
+
matches(table: SourceTableInterface): boolean;
|
|
16
|
+
suffix(table: string): string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export const DEFAULT_TAG = 'default';
|
|
2
|
+
export const DEFAULT_SCHEMA = 'public';
|
|
3
|
+
/**
|
|
4
|
+
* Some pattern matching SourceTables.
|
|
5
|
+
*/
|
|
6
|
+
export class TablePattern {
|
|
7
|
+
constructor(schema, tablePattern) {
|
|
8
|
+
schema ?? (schema = DEFAULT_SCHEMA);
|
|
9
|
+
const splitSchema = schema.split('.');
|
|
10
|
+
if (splitSchema.length > 2) {
|
|
11
|
+
throw new Error(`Invalid schema: ${schema}`);
|
|
12
|
+
}
|
|
13
|
+
if (splitSchema.length == 2) {
|
|
14
|
+
this.connectionTag = splitSchema[0];
|
|
15
|
+
this.schema = splitSchema[1];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.connectionTag = DEFAULT_TAG;
|
|
19
|
+
this.schema = schema;
|
|
20
|
+
}
|
|
21
|
+
this.tablePattern = tablePattern;
|
|
22
|
+
}
|
|
23
|
+
get isWildcard() {
|
|
24
|
+
return this.tablePattern.endsWith('%');
|
|
25
|
+
}
|
|
26
|
+
get tablePrefix() {
|
|
27
|
+
if (!this.isWildcard) {
|
|
28
|
+
throw new Error('Not a wildcard table');
|
|
29
|
+
}
|
|
30
|
+
return this.tablePattern.substring(0, this.tablePattern.length - 1);
|
|
31
|
+
}
|
|
32
|
+
get name() {
|
|
33
|
+
if (this.isWildcard) {
|
|
34
|
+
throw new Error('Cannot get name for wildcard table');
|
|
35
|
+
}
|
|
36
|
+
return this.tablePattern;
|
|
37
|
+
}
|
|
38
|
+
matches(table) {
|
|
39
|
+
if (this.connectionTag != table.connectionTag || this.schema != table.schema) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (this.isWildcard) {
|
|
43
|
+
return table.table.startsWith(this.tablePrefix);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
return this.tablePattern == table.table;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
suffix(table) {
|
|
50
|
+
if (!this.isWildcard) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
return table.substring(this.tablePrefix.length);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=TablePattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TablePattern.js","sourceRoot":"","sources":["../src/TablePattern.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC;AAE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,MAAM,EAAE;YAC5E,OAAO,KAAK,CAAC;SACd;QACD,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SACjD;aAAM;YACL,OAAO,IAAI,CAAC,YAAY,IAAI,KAAK,CAAC,KAAK,CAAC;SACzC;IACH,CAAC;IAED,MAAM,CAAC,KAAa;QAClB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACpB,OAAO,EAAE,CAAC;SACX;QACD,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
getType(table: string, column: string): ExpressionType;
|
|
8
|
+
getColumns(table: string): ColumnDefinition[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ExpressionType } from './ExpressionType.js';
|
|
2
|
+
export class TableQuerySchema {
|
|
3
|
+
constructor(tables, alias) {
|
|
4
|
+
this.tables = tables;
|
|
5
|
+
this.alias = alias;
|
|
6
|
+
}
|
|
7
|
+
getType(table, column) {
|
|
8
|
+
if (table != this.alias) {
|
|
9
|
+
return ExpressionType.NONE;
|
|
10
|
+
}
|
|
11
|
+
for (let table of this.tables) {
|
|
12
|
+
const t = table.getType(column);
|
|
13
|
+
if (t != null) {
|
|
14
|
+
return t;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return ExpressionType.NONE;
|
|
18
|
+
}
|
|
19
|
+
getColumns(table) {
|
|
20
|
+
if (table != this.alias) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
let columns = {};
|
|
24
|
+
for (let table of this.tables) {
|
|
25
|
+
for (let col of table.getColumns()) {
|
|
26
|
+
if (!(col.name in columns)) {
|
|
27
|
+
columns[col.name] = col;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return Object.values(columns);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=TableQuerySchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableQuerySchema.js","sourceRoot":"","sources":["../src/TableQuerySchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGvE,MAAM,OAAO,gBAAgB;IAC3B,YAAoB,MAA2B,EAAU,KAAa;QAAlD,WAAM,GAAN,MAAM,CAAqB;QAAU,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE1E,OAAO,CAAC,KAAa,EAAE,MAAc;QACnC,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE;YACvB,OAAO,cAAc,CAAC,IAAI,CAAC;SAC5B;QACD,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YAC7B,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAChC,IAAI,CAAC,IAAI,IAAI,EAAE;gBACb,OAAO,CAAC,CAAC;aACV;SACF;QACD,OAAO,cAAc,CAAC,IAAI,CAAC;IAC7B,CAAC;IAED,UAAU,CAAC,KAAa;QACtB,IAAI,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE;YACvB,OAAO,EAAE,CAAC;SACX;QACD,IAAI,OAAO,GAAqC,EAAE,CAAC;QAEnD,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;YAC7B,KAAK,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,EAAE;gBAClC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE;oBAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;iBACzB;aACF;SACF;QACD,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Expr, NodeLocation } from 'pgsql-ast-parser';
|
|
2
|
+
export interface ErrorLocation {
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
export declare class SqlRuleError extends Error {
|
|
7
|
+
sql: string;
|
|
8
|
+
location?: ErrorLocation;
|
|
9
|
+
type: 'warning' | 'fatal';
|
|
10
|
+
constructor(message: string, sql: string, location?: NodeLocation | Expr);
|
|
11
|
+
}
|
|
12
|
+
export declare class YamlError extends Error {
|
|
13
|
+
source: Error;
|
|
14
|
+
location: ErrorLocation;
|
|
15
|
+
type: 'warning' | 'fatal';
|
|
16
|
+
constructor(source: Error, location?: ErrorLocation);
|
|
17
|
+
}
|
|
18
|
+
export declare class SyncRulesErrors extends Error {
|
|
19
|
+
errors: YamlError[];
|
|
20
|
+
static constructMessage(errors: YamlError[]): string;
|
|
21
|
+
constructor(errors: YamlError[]);
|
|
22
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as yaml from 'yaml';
|
|
2
|
+
function getLocation(location) {
|
|
3
|
+
if (location != null && !isLocation(location)) {
|
|
4
|
+
return location._location;
|
|
5
|
+
}
|
|
6
|
+
else if (isLocation(location)) {
|
|
7
|
+
return location;
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function isLocation(location) {
|
|
14
|
+
return (location != null &&
|
|
15
|
+
typeof location.start == 'number' &&
|
|
16
|
+
typeof location.end == 'number');
|
|
17
|
+
}
|
|
18
|
+
export class SqlRuleError extends Error {
|
|
19
|
+
constructor(message, sql, location) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.sql = sql;
|
|
22
|
+
this.type = 'fatal';
|
|
23
|
+
this.location = getLocation(location) ?? { start: 0, end: sql.length };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export class YamlError extends Error {
|
|
27
|
+
constructor(source, location) {
|
|
28
|
+
super(source.message);
|
|
29
|
+
this.source = source;
|
|
30
|
+
this.type = 'fatal';
|
|
31
|
+
if (location == null && source instanceof yaml.YAMLError) {
|
|
32
|
+
location = {
|
|
33
|
+
start: source.pos[0],
|
|
34
|
+
end: source.pos[1]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
else if (location == null) {
|
|
38
|
+
location = {
|
|
39
|
+
start: 0,
|
|
40
|
+
end: 10
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (source instanceof YamlError || source instanceof SqlRuleError) {
|
|
44
|
+
this.type = source.type;
|
|
45
|
+
}
|
|
46
|
+
this.location = location;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export class SyncRulesErrors extends Error {
|
|
50
|
+
static constructMessage(errors) {
|
|
51
|
+
return errors.map((e) => e.message).join(', ');
|
|
52
|
+
}
|
|
53
|
+
constructor(errors) {
|
|
54
|
+
super(SyncRulesErrors.constructMessage(errors));
|
|
55
|
+
this.errors = errors;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,SAAS,WAAW,CAAC,QAA8B;IACjD,IAAI,QAAQ,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC7C,OAAO,QAAQ,CAAC,SAAS,CAAC;KAC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,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;SACzB;QACD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,MAAM,CAAC,gBAAgB,CAAC,MAAmB;QACzC,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,YAAmB,MAAmB;QACpC,KAAK,CAAC,eAAe,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;QAD/B,WAAM,GAAN,MAAM,CAAa;IAEtC,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DartSchemaGenerator } from './DartSchemaGenerator.js';
|
|
2
|
+
import { JsSchemaGenerator } from './JsSchemaGenerator.js';
|
|
3
|
+
export const schemaGenerators = {
|
|
4
|
+
js: new JsSchemaGenerator(),
|
|
5
|
+
dart: new DartSchemaGenerator()
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=generators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators.js","sourceRoot":"","sources":["../src/generators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,EAAE,EAAE,IAAI,iBAAiB,EAAE;IAC3B,IAAI,EAAE,IAAI,mBAAmB,EAAE;CAChC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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';
|
|
18
|
+
export * from './SqlDataQuery.js';
|
|
19
|
+
export * from './request_functions.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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';
|
|
18
|
+
export * from './SqlDataQuery.js';
|
|
19
|
+
export * from './request_functions.js';
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ajvModule from 'ajv';
|
|
2
|
+
// Hack to make this work both in NodeJS and a browser
|
|
3
|
+
const Ajv = ajvModule.default ?? ajvModule;
|
|
4
|
+
const ajv = new Ajv({ allErrors: true, verbose: true });
|
|
5
|
+
export const syncRulesSchema = {
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
bucket_definitions: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
description: 'List of bucket definitions',
|
|
11
|
+
examples: [{ global: { data: 'select * from mytable' } }],
|
|
12
|
+
patternProperties: {
|
|
13
|
+
'.*': {
|
|
14
|
+
type: 'object',
|
|
15
|
+
required: ['data'],
|
|
16
|
+
examples: [{ data: ['select * from mytable'] }],
|
|
17
|
+
properties: {
|
|
18
|
+
accept_potentially_dangerous_queries: {
|
|
19
|
+
description: 'If true, disables warnings on potentially dangerous queries',
|
|
20
|
+
type: 'boolean'
|
|
21
|
+
},
|
|
22
|
+
parameters: {
|
|
23
|
+
description: 'Parameter query(ies)',
|
|
24
|
+
anyOf: [
|
|
25
|
+
{ type: 'string', description: 'Parameter query' },
|
|
26
|
+
{
|
|
27
|
+
type: 'array',
|
|
28
|
+
description: 'Parameter queries',
|
|
29
|
+
items: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
data: {
|
|
36
|
+
type: 'array',
|
|
37
|
+
description: 'Data queries',
|
|
38
|
+
items: {
|
|
39
|
+
type: 'string'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
additionalProperties: false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
required: ['bucket_definitions'],
|
|
49
|
+
additionalProperties: false
|
|
50
|
+
};
|
|
51
|
+
export const validateSyncRulesSchema = ajv.compile(syncRulesSchema);
|
|
52
|
+
//# sourceMappingURL=json_schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json_schema.js","sourceRoot":"","sources":["../src/json_schema.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,KAAK,CAAC;AAC5B,sDAAsD;AACtD,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC;AAC3C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,kBAAkB,EAAE;YAClB,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,4BAA4B;YACzC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,uBAAuB,EAAE,EAAE,CAAC;YACzD,iBAAiB,EAAE;gBACjB,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,QAAQ,EAAE,CAAC,MAAM,CAAC;oBAClB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,uBAAuB,CAAC,EAAE,CAAC;oBAC/C,UAAU,EAAE;wBACV,oCAAoC,EAAE;4BACpC,WAAW,EAAE,6DAA6D;4BAC1E,IAAI,EAAE,SAAS;yBAChB;wBACD,UAAU,EAAE;4BACV,WAAW,EAAE,sBAAsB;4BACnC,KAAK,EAAE;gCACL,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,EAAE;gCAClD;oCACE,IAAI,EAAE,OAAO;oCACb,WAAW,EAAE,mBAAmB;oCAChC,KAAK,EAAE;wCACL,IAAI,EAAE,QAAQ;qCACf;iCACF;6BACF;yBACF;wBACD,IAAI,EAAE;4BACJ,IAAI,EAAE,OAAO;4BACb,WAAW,EAAE,cAAc;4BAC3B,KAAK,EAAE;gCACL,IAAI,EAAE,QAAQ;6BACf;yBACF;qBACF;oBACD,oBAAoB,EAAE,KAAK;iBAC5B;aACF;SACF;KACF;IACD,QAAQ,EAAE,CAAC,oBAAoB,CAAC;IAChC,oBAAoB,EAAE,KAAK;CACnB,CAAC;AAEX,MAAM,CAAC,MAAM,uBAAuB,GAAQ,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ExpressionType } from './ExpressionType.js';
|
|
2
|
+
import { RequestParameters, SqliteValue } from './types.js';
|
|
3
|
+
export interface SqlParameterFunction {
|
|
4
|
+
readonly debugName: string;
|
|
5
|
+
call: (parameters: RequestParameters) => SqliteValue;
|
|
6
|
+
getReturnType(): ExpressionType;
|
|
7
|
+
/** request.user_id(), request.jwt(), token_parameters.* */
|
|
8
|
+
usesAuthenticatedRequestParameters: boolean;
|
|
9
|
+
/** request.parameters(), user_parameters.* */
|
|
10
|
+
usesUnauthenticatedRequestParameters: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const REQUEST_FUNCTIONS_NAMED: {
|
|
13
|
+
parameters: SqlParameterFunction;
|
|
14
|
+
jwt: SqlParameterFunction;
|
|
15
|
+
user_id: SqlParameterFunction;
|
|
16
|
+
};
|
|
17
|
+
export declare const REQUEST_FUNCTIONS: Record<string, SqlParameterFunction>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ExpressionType } from './ExpressionType.js';
|
|
2
|
+
const request_parameters = {
|
|
3
|
+
debugName: 'request.parameters',
|
|
4
|
+
call(parameters) {
|
|
5
|
+
return parameters.raw_user_parameters;
|
|
6
|
+
},
|
|
7
|
+
getReturnType() {
|
|
8
|
+
return ExpressionType.TEXT;
|
|
9
|
+
},
|
|
10
|
+
usesAuthenticatedRequestParameters: false,
|
|
11
|
+
usesUnauthenticatedRequestParameters: true
|
|
12
|
+
};
|
|
13
|
+
const request_jwt = {
|
|
14
|
+
debugName: 'request.jwt',
|
|
15
|
+
call(parameters) {
|
|
16
|
+
return parameters.raw_token_payload;
|
|
17
|
+
},
|
|
18
|
+
getReturnType() {
|
|
19
|
+
return ExpressionType.TEXT;
|
|
20
|
+
},
|
|
21
|
+
usesAuthenticatedRequestParameters: true,
|
|
22
|
+
usesUnauthenticatedRequestParameters: false
|
|
23
|
+
};
|
|
24
|
+
const request_user_id = {
|
|
25
|
+
debugName: 'request.user_id',
|
|
26
|
+
call(parameters) {
|
|
27
|
+
return parameters.user_id;
|
|
28
|
+
},
|
|
29
|
+
getReturnType() {
|
|
30
|
+
return ExpressionType.TEXT;
|
|
31
|
+
},
|
|
32
|
+
usesAuthenticatedRequestParameters: true,
|
|
33
|
+
usesUnauthenticatedRequestParameters: false
|
|
34
|
+
};
|
|
35
|
+
export const REQUEST_FUNCTIONS_NAMED = {
|
|
36
|
+
parameters: request_parameters,
|
|
37
|
+
jwt: request_jwt,
|
|
38
|
+
user_id: request_user_id
|
|
39
|
+
};
|
|
40
|
+
export const REQUEST_FUNCTIONS = REQUEST_FUNCTIONS_NAMED;
|
|
41
|
+
//# sourceMappingURL=request_functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request_functions.js","sourceRoot":"","sources":["../src/request_functions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAarD,MAAM,kBAAkB,GAAyB;IAC/C,SAAS,EAAE,oBAAoB;IAC/B,IAAI,CAAC,UAA6B;QAChC,OAAO,UAAU,CAAC,mBAAmB,CAAC;IACxC,CAAC;IACD,aAAa;QACX,OAAO,cAAc,CAAC,IAAI,CAAC;IAC7B,CAAC;IACD,kCAAkC,EAAE,KAAK;IACzC,oCAAoC,EAAE,IAAI;CAC3C,CAAC;AAEF,MAAM,WAAW,GAAyB;IACxC,SAAS,EAAE,aAAa;IACxB,IAAI,CAAC,UAA6B;QAChC,OAAO,UAAU,CAAC,iBAAiB,CAAC;IACtC,CAAC;IACD,aAAa;QACX,OAAO,cAAc,CAAC,IAAI,CAAC;IAC7B,CAAC;IACD,kCAAkC,EAAE,IAAI;IACxC,oCAAoC,EAAE,KAAK;CAC5C,CAAC;AAEF,MAAM,eAAe,GAAyB;IAC5C,SAAS,EAAE,iBAAiB;IAC5B,IAAI,CAAC,UAA6B;QAChC,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IACD,aAAa;QACX,OAAO,cAAc,CAAC,IAAI,CAAC;IAC7B,CAAC;IACD,kCAAkC,EAAE,IAAI;IACxC,oCAAoC,EAAE,KAAK;CAC5C,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,UAAU,EAAE,kBAAkB;IAC9B,GAAG,EAAE,WAAW;IAChB,OAAO,EAAE,eAAe;CACzB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAyC,uBAAuB,CAAC"}
|