powersync 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +339 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +9 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +8 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.js +49 -0
- package/dist/commands/instance/config.d.ts +6 -0
- package/dist/commands/instance/config.js +23 -0
- package/dist/commands/instance/create.d.ts +16 -0
- package/dist/commands/instance/create.js +163 -0
- package/dist/commands/instance/deploy.d.ts +15 -0
- package/dist/commands/instance/deploy.js +142 -0
- package/dist/commands/instance/destroy.d.ts +9 -0
- package/dist/commands/instance/destroy.js +42 -0
- package/dist/commands/instance/schema.d.ts +6 -0
- package/dist/commands/instance/schema.js +20 -0
- package/dist/commands/instance/set.d.ts +9 -0
- package/dist/commands/instance/set.js +31 -0
- package/dist/commands/instance/status.d.ts +6 -0
- package/dist/commands/instance/status.js +21 -0
- package/dist/commands/instance/stop.d.ts +9 -0
- package/dist/commands/instance/stop.js +42 -0
- package/dist/commands/instance/sync-rules/deploy.d.ts +10 -0
- package/dist/commands/instance/sync-rules/deploy.js +49 -0
- package/dist/commands/instance/sync-rules/generate-schema.d.ts +10 -0
- package/dist/commands/instance/sync-rules/generate-schema.js +55 -0
- package/dist/commands/instance/sync-rules/validate.d.ts +9 -0
- package/dist/commands/instance/sync-rules/validate.js +29 -0
- package/dist/commands/instances.d.ts +6 -0
- package/dist/commands/instances.js +20 -0
- package/dist/constants.d.ts +11 -0
- package/dist/constants.js +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/powersync-sdk/accounts/api.d.ts +717 -0
- package/dist/powersync-sdk/accounts/api.js +182 -0
- package/dist/powersync-sdk/accounts/client.d.ts +1096 -0
- package/dist/powersync-sdk/accounts/client.js +124 -0
- package/dist/powersync-sdk/accounts/codecs.d.ts +32 -0
- package/dist/powersync-sdk/accounts/codecs.js +93 -0
- package/dist/powersync-sdk/accounts/index.d.ts +4 -0
- package/dist/powersync-sdk/accounts/index.js +4 -0
- package/dist/powersync-sdk/accounts/models.d.ts +260 -0
- package/dist/powersync-sdk/accounts/models.js +96 -0
- package/dist/powersync-sdk/accounts/routes.d.ts +44 -0
- package/dist/powersync-sdk/accounts/routes.js +45 -0
- package/dist/powersync-sdk/accounts/source.d.ts +76 -0
- package/dist/powersync-sdk/accounts/source.js +32 -0
- package/dist/powersync-sdk/errors/errors.d.ts +62 -0
- package/dist/powersync-sdk/errors/errors.js +115 -0
- package/dist/powersync-sdk/errors/index.d.ts +2 -0
- package/dist/powersync-sdk/errors/index.js +2 -0
- package/dist/powersync-sdk/errors/utils.d.ts +4 -0
- package/dist/powersync-sdk/errors/utils.js +18 -0
- package/dist/powersync-sdk/fetch-clients/codecs.d.ts +4 -0
- package/dist/powersync-sdk/fetch-clients/codecs.js +34 -0
- package/dist/powersync-sdk/fetch-clients/decoders.d.ts +3 -0
- package/dist/powersync-sdk/fetch-clients/decoders.js +35 -0
- package/dist/powersync-sdk/fetch-clients/definitions.d.ts +97 -0
- package/dist/powersync-sdk/fetch-clients/definitions.js +22 -0
- package/dist/powersync-sdk/fetch-clients/errors.d.ts +7 -0
- package/dist/powersync-sdk/fetch-clients/errors.js +19 -0
- package/dist/powersync-sdk/fetch-clients/index.d.ts +5 -0
- package/dist/powersync-sdk/fetch-clients/index.js +5 -0
- package/dist/powersync-sdk/fetch-clients/node-client.d.ts +9 -0
- package/dist/powersync-sdk/fetch-clients/node-client.js +107 -0
- package/dist/powersync-sdk/fetch-clients/request.d.ts +11 -0
- package/dist/powersync-sdk/fetch-clients/request.js +138 -0
- package/dist/powersync-sdk/fetch-clients/streaming.d.ts +65 -0
- package/dist/powersync-sdk/fetch-clients/streaming.js +99 -0
- package/dist/powersync-sdk/fetch-clients/utils.d.ts +13 -0
- package/dist/powersync-sdk/fetch-clients/utils.js +43 -0
- package/dist/powersync-sdk/fetch-clients/web-client.d.ts +14 -0
- package/dist/powersync-sdk/fetch-clients/web-client.js +56 -0
- package/dist/powersync-sdk/json/index.d.ts +4 -0
- package/dist/powersync-sdk/json/index.js +3 -0
- package/dist/powersync-sdk/json/json.d.ts +5 -0
- package/dist/powersync-sdk/json/json.js +35 -0
- package/dist/powersync-sdk/json/json_container.d.ts +18 -0
- package/dist/powersync-sdk/json/json_container.js +28 -0
- package/dist/powersync-sdk/json/json_stringify.d.ts +36 -0
- package/dist/powersync-sdk/json/json_stringify.js +162 -0
- package/dist/powersync-sdk/powersync/client.d.ts +449 -0
- package/dist/powersync-sdk/powersync/client.js +53 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +327 -0
- package/dist/powersync-sdk/powersync/config/HostedConfig.js +92 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +211 -0
- package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +97 -0
- package/dist/powersync-sdk/powersync/config/normalize.d.ts +32 -0
- package/dist/powersync-sdk/powersync/config/normalize.js +85 -0
- package/dist/powersync-sdk/powersync/definitions.d.ts +149 -0
- package/dist/powersync-sdk/powersync/definitions.js +97 -0
- package/dist/powersync-sdk/powersync/index.d.ts +8 -0
- package/dist/powersync-sdk/powersync/index.js +8 -0
- package/dist/powersync-sdk/powersync/internal_routes.d.ts +247 -0
- package/dist/powersync-sdk/powersync/internal_routes.js +69 -0
- package/dist/powersync-sdk/powersync/routes.d.ts +779 -0
- package/dist/powersync-sdk/powersync/routes.js +191 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +31 -0
- package/dist/powersync-sdk/sdk-clients/endpoints.js +48 -0
- package/dist/powersync-sdk/sdk-clients/index.d.ts +3 -0
- package/dist/powersync-sdk/sdk-clients/index.js +3 -0
- package/dist/powersync-sdk/sdk-clients/pagination.d.ts +14 -0
- package/dist/powersync-sdk/sdk-clients/pagination.js +21 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +17 -0
- package/dist/powersync-sdk/sdk-clients/sdk-client.js +30 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +31 -0
- package/dist/powersync-sdk/streaming/bson/buffer-array.js +79 -0
- package/dist/powersync-sdk/streaming/bson/constants.d.ts +2 -0
- package/dist/powersync-sdk/streaming/bson/constants.js +1 -0
- package/dist/powersync-sdk/streaming/bson/decoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/decoder.js +62 -0
- package/dist/powersync-sdk/streaming/bson/encoder.d.ts +10 -0
- package/dist/powersync-sdk/streaming/bson/encoder.js +23 -0
- package/dist/powersync-sdk/streaming/bson/header.d.ts +11 -0
- package/dist/powersync-sdk/streaming/bson/header.js +52 -0
- package/dist/powersync-sdk/streaming/bson/index.d.ts +5 -0
- package/dist/powersync-sdk/streaming/bson/index.js +5 -0
- package/dist/powersync-sdk/streaming/core/backpressure.d.ts +15 -0
- package/dist/powersync-sdk/streaming/core/backpressure.js +34 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +6 -0
- package/dist/powersync-sdk/streaming/core/cross-stream.js +17 -0
- package/dist/powersync-sdk/streaming/core/index.d.ts +4 -0
- package/dist/powersync-sdk/streaming/core/index.js +4 -0
- package/dist/powersync-sdk/streaming/core/node-utils.d.ts +7 -0
- package/dist/powersync-sdk/streaming/core/node-utils.js +11 -0
- package/dist/powersync-sdk/streaming/core/transformers.d.ts +41 -0
- package/dist/powersync-sdk/streaming/core/transformers.js +70 -0
- package/dist/powersync-sdk/streaming/core/utils.d.ts +36 -0
- package/dist/powersync-sdk/streaming/core/utils.js +66 -0
- package/dist/powersync-sdk/streaming/index.d.ts +3 -0
- package/dist/powersync-sdk/streaming/index.js +3 -0
- package/dist/powersync-sdk/streaming/web.d.ts +4 -0
- package/dist/powersync-sdk/streaming/web.js +4 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +36 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +58 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +18 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +348 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +118 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +131 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +134 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +122 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +158 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +165 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +11 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +207 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +30 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +29 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +2 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +111 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +9 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +9 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +35 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +33 -0
- package/dist/powersync-sdk/sync-rules/ExpressionType.js +62 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +4 -0
- package/dist/powersync-sdk/sync-rules/IdSequence.js +7 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +12 -0
- package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +38 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +14 -0
- package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +24 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +5 -0
- package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +1 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +37 -0
- package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +116 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +39 -0
- package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +245 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +43 -0
- package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +254 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +52 -0
- package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +252 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +26 -0
- package/dist/powersync-sdk/sync-rules/StaticSchema.js +71 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +24 -0
- package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +71 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/TablePattern.js +56 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +9 -0
- package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +41 -0
- package/dist/powersync-sdk/sync-rules/errors.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/errors.js +60 -0
- package/dist/powersync-sdk/sync-rules/generators.d.ts +6 -0
- package/dist/powersync-sdk/sync-rules/generators.js +6 -0
- package/dist/powersync-sdk/sync-rules/index.d.ts +17 -0
- package/dist/powersync-sdk/sync-rules/index.js +17 -0
- package/dist/powersync-sdk/sync-rules/json_schema.d.ts +3 -0
- package/dist/powersync-sdk/sync-rules/json_schema.js +50 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +91 -0
- package/dist/powersync-sdk/sync-rules/sql_filters.js +491 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +53 -0
- package/dist/powersync-sdk/sync-rules/sql_functions.js +755 -0
- package/dist/powersync-sdk/sync-rules/sql_support.d.ts +22 -0
- package/dist/powersync-sdk/sync-rules/sql_support.js +208 -0
- package/dist/powersync-sdk/sync-rules/types.d.ts +174 -0
- package/dist/powersync-sdk/sync-rules/types.js +9 -0
- package/dist/powersync-sdk/sync-rules/utils.d.ts +45 -0
- package/dist/powersync-sdk/sync-rules/utils.js +163 -0
- package/dist/service/accounts.client.d.ts +26 -0
- package/dist/service/accounts.client.js +26 -0
- package/dist/service/powersync.client.d.ts +269 -0
- package/dist/service/powersync.client.js +135 -0
- package/dist/service/types.d.ts +69 -0
- package/dist/service/types.js +1 -0
- package/dist/service/utils.d.ts +5 -0
- package/dist/service/utils.js +7 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +52 -0
- package/oclif.manifest.json +514 -0
- package/package.json +81 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import BinaryWriter from './binarywriter.js';
|
|
2
|
+
import Geometry from './geometry.js';
|
|
3
|
+
import Point from './point.js';
|
|
4
|
+
import Types from './types.js';
|
|
5
|
+
function Polygon(exteriorRing, interiorRings, srid) {
|
|
6
|
+
Geometry.call(this);
|
|
7
|
+
this.exteriorRing = exteriorRing || [];
|
|
8
|
+
this.interiorRings = interiorRings || [];
|
|
9
|
+
this.srid = srid;
|
|
10
|
+
if (this.exteriorRing.length > 0) {
|
|
11
|
+
this.hasZ = this.exteriorRing[0].hasZ;
|
|
12
|
+
this.hasM = this.exteriorRing[0].hasM;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// util.inherits(Polygon, Geometry);
|
|
16
|
+
Polygon.Z = function (exteriorRing, interiorRings, srid) {
|
|
17
|
+
const polygon = new Polygon(exteriorRing, interiorRings, srid);
|
|
18
|
+
polygon.hasZ = true;
|
|
19
|
+
return polygon;
|
|
20
|
+
};
|
|
21
|
+
Polygon.M = function (exteriorRing, interiorRings, srid) {
|
|
22
|
+
const polygon = new Polygon(exteriorRing, interiorRings, srid);
|
|
23
|
+
polygon.hasM = true;
|
|
24
|
+
return polygon;
|
|
25
|
+
};
|
|
26
|
+
Polygon.ZM = function (exteriorRing, interiorRings, srid) {
|
|
27
|
+
const polygon = new Polygon(exteriorRing, interiorRings, srid);
|
|
28
|
+
polygon.hasZ = true;
|
|
29
|
+
polygon.hasM = true;
|
|
30
|
+
return polygon;
|
|
31
|
+
};
|
|
32
|
+
Polygon._parseWkt = function (value, options) {
|
|
33
|
+
const polygon = new Polygon();
|
|
34
|
+
polygon.srid = options.srid;
|
|
35
|
+
polygon.hasZ = options.hasZ;
|
|
36
|
+
polygon.hasM = options.hasM;
|
|
37
|
+
if (value.isMatch(['EMPTY']))
|
|
38
|
+
return polygon;
|
|
39
|
+
value.expectGroupStart();
|
|
40
|
+
value.expectGroupStart();
|
|
41
|
+
polygon.exteriorRing.push.apply(polygon.exteriorRing, value.matchCoordinates(options));
|
|
42
|
+
value.expectGroupEnd();
|
|
43
|
+
while (value.isMatch([','])) {
|
|
44
|
+
value.expectGroupStart();
|
|
45
|
+
polygon.interiorRings.push(value.matchCoordinates(options));
|
|
46
|
+
value.expectGroupEnd();
|
|
47
|
+
}
|
|
48
|
+
value.expectGroupEnd();
|
|
49
|
+
return polygon;
|
|
50
|
+
};
|
|
51
|
+
Polygon._parseWkb = function (value, options) {
|
|
52
|
+
const polygon = new Polygon();
|
|
53
|
+
polygon.srid = options.srid;
|
|
54
|
+
polygon.hasZ = options.hasZ;
|
|
55
|
+
polygon.hasM = options.hasM;
|
|
56
|
+
const ringCount = value.readUInt32();
|
|
57
|
+
if (ringCount > 0) {
|
|
58
|
+
const exteriorRingCount = value.readUInt32();
|
|
59
|
+
for (var i = 0; i < exteriorRingCount; i++)
|
|
60
|
+
polygon.exteriorRing.push(Point._readWkbPoint(value, options));
|
|
61
|
+
for (i = 1; i < ringCount; i++) {
|
|
62
|
+
const interiorRing = [];
|
|
63
|
+
const interiorRingCount = value.readUInt32();
|
|
64
|
+
for (let j = 0; j < interiorRingCount; j++)
|
|
65
|
+
interiorRing.push(Point._readWkbPoint(value, options));
|
|
66
|
+
polygon.interiorRings.push(interiorRing);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return polygon;
|
|
70
|
+
};
|
|
71
|
+
Polygon._parseTwkb = function (value, options) {
|
|
72
|
+
const polygon = new Polygon();
|
|
73
|
+
polygon.hasZ = options.hasZ;
|
|
74
|
+
polygon.hasM = options.hasM;
|
|
75
|
+
if (options.isEmpty)
|
|
76
|
+
return polygon;
|
|
77
|
+
const previousPoint = new Point(0, 0, options.hasZ ? 0 : undefined, options.hasM ? 0 : undefined);
|
|
78
|
+
const ringCount = value.readVarInt();
|
|
79
|
+
const exteriorRingCount = value.readVarInt();
|
|
80
|
+
for (var i = 0; i < exteriorRingCount; i++)
|
|
81
|
+
polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
82
|
+
for (i = 1; i < ringCount; i++) {
|
|
83
|
+
const interiorRing = [];
|
|
84
|
+
const interiorRingCount = value.readVarInt();
|
|
85
|
+
for (let j = 0; j < interiorRingCount; j++)
|
|
86
|
+
interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
|
|
87
|
+
polygon.interiorRings.push(interiorRing);
|
|
88
|
+
}
|
|
89
|
+
return polygon;
|
|
90
|
+
};
|
|
91
|
+
Polygon._parseGeoJSON = function (value) {
|
|
92
|
+
const polygon = new Polygon();
|
|
93
|
+
if (value.coordinates.length > 0 && value.coordinates[0].length > 0)
|
|
94
|
+
polygon.hasZ = value.coordinates[0][0].length > 2;
|
|
95
|
+
for (let i = 0; i < value.coordinates.length; i++) {
|
|
96
|
+
if (i > 0)
|
|
97
|
+
polygon.interiorRings.push([]);
|
|
98
|
+
for (let j = 0; j < value.coordinates[i].length; j++) {
|
|
99
|
+
if (i === 0)
|
|
100
|
+
polygon.exteriorRing.push(Point._readGeoJSONPoint(value.coordinates[i][j]));
|
|
101
|
+
else
|
|
102
|
+
polygon.interiorRings[i - 1].push(Point._readGeoJSONPoint(value.coordinates[i][j]));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return polygon;
|
|
106
|
+
};
|
|
107
|
+
Polygon.prototype.toWkt = function () {
|
|
108
|
+
if (this.exteriorRing.length === 0)
|
|
109
|
+
return this._getWktType(Types.wkt.Polygon, true);
|
|
110
|
+
return this._getWktType(Types.wkt.Polygon, false) + this._toInnerWkt();
|
|
111
|
+
};
|
|
112
|
+
Polygon.prototype._toInnerWkt = function () {
|
|
113
|
+
let innerWkt = '((';
|
|
114
|
+
for (var i = 0; i < this.exteriorRing.length; i++)
|
|
115
|
+
innerWkt += this._getWktCoordinate(this.exteriorRing[i]) + ',';
|
|
116
|
+
innerWkt = innerWkt.slice(0, -1);
|
|
117
|
+
innerWkt += ')';
|
|
118
|
+
for (i = 0; i < this.interiorRings.length; i++) {
|
|
119
|
+
innerWkt += ',(';
|
|
120
|
+
for (let j = 0; j < this.interiorRings[i].length; j++) {
|
|
121
|
+
innerWkt += this._getWktCoordinate(this.interiorRings[i][j]) + ',';
|
|
122
|
+
}
|
|
123
|
+
innerWkt = innerWkt.slice(0, -1);
|
|
124
|
+
innerWkt += ')';
|
|
125
|
+
}
|
|
126
|
+
innerWkt += ')';
|
|
127
|
+
return innerWkt;
|
|
128
|
+
};
|
|
129
|
+
Polygon.prototype.toWkb = function (parentOptions) {
|
|
130
|
+
const wkb = new BinaryWriter(this._getWkbSize());
|
|
131
|
+
wkb.writeInt8(1);
|
|
132
|
+
this._writeWkbType(wkb, Types.wkb.Polygon, parentOptions);
|
|
133
|
+
if (this.exteriorRing.length > 0) {
|
|
134
|
+
wkb.writeUInt32LE(1 + this.interiorRings.length);
|
|
135
|
+
wkb.writeUInt32LE(this.exteriorRing.length);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
wkb.writeUInt32LE(0);
|
|
139
|
+
}
|
|
140
|
+
for (var i = 0; i < this.exteriorRing.length; i++)
|
|
141
|
+
this.exteriorRing[i]._writeWkbPoint(wkb);
|
|
142
|
+
for (i = 0; i < this.interiorRings.length; i++) {
|
|
143
|
+
wkb.writeUInt32LE(this.interiorRings[i].length);
|
|
144
|
+
for (let j = 0; j < this.interiorRings[i].length; j++)
|
|
145
|
+
this.interiorRings[i][j]._writeWkbPoint(wkb);
|
|
146
|
+
}
|
|
147
|
+
return wkb.buffer;
|
|
148
|
+
};
|
|
149
|
+
Polygon.prototype.toTwkb = function () {
|
|
150
|
+
const twkb = new BinaryWriter(0, true);
|
|
151
|
+
const precision = Geometry.getTwkbPrecision(5, 0, 0);
|
|
152
|
+
const isEmpty = this.exteriorRing.length === 0;
|
|
153
|
+
this._writeTwkbHeader(twkb, Types.wkb.Polygon, precision, isEmpty);
|
|
154
|
+
if (this.exteriorRing.length > 0) {
|
|
155
|
+
twkb.writeVarInt(1 + this.interiorRings.length);
|
|
156
|
+
twkb.writeVarInt(this.exteriorRing.length);
|
|
157
|
+
const previousPoint = new Point(0, 0, 0, 0);
|
|
158
|
+
for (var i = 0; i < this.exteriorRing.length; i++)
|
|
159
|
+
this.exteriorRing[i]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
160
|
+
for (i = 0; i < this.interiorRings.length; i++) {
|
|
161
|
+
twkb.writeVarInt(this.interiorRings[i].length);
|
|
162
|
+
for (let j = 0; j < this.interiorRings[i].length; j++)
|
|
163
|
+
this.interiorRings[i][j]._writeTwkbPoint(twkb, precision, previousPoint);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return twkb.buffer;
|
|
167
|
+
};
|
|
168
|
+
Polygon.prototype._getWkbSize = function () {
|
|
169
|
+
let coordinateSize = 16;
|
|
170
|
+
if (this.hasZ)
|
|
171
|
+
coordinateSize += 8;
|
|
172
|
+
if (this.hasM)
|
|
173
|
+
coordinateSize += 8;
|
|
174
|
+
let size = 1 + 4 + 4;
|
|
175
|
+
if (this.exteriorRing.length > 0)
|
|
176
|
+
size += 4 + this.exteriorRing.length * coordinateSize;
|
|
177
|
+
for (let i = 0; i < this.interiorRings.length; i++)
|
|
178
|
+
size += 4 + this.interiorRings[i].length * coordinateSize;
|
|
179
|
+
return size;
|
|
180
|
+
};
|
|
181
|
+
Polygon.prototype.toGeoJSON = function (options) {
|
|
182
|
+
const geoJSON = Geometry.prototype.toGeoJSON.call(this, options);
|
|
183
|
+
geoJSON.type = Types.geoJSON.Polygon;
|
|
184
|
+
geoJSON.coordinates = [];
|
|
185
|
+
if (this.exteriorRing.length > 0) {
|
|
186
|
+
const exteriorRing = [];
|
|
187
|
+
for (let i = 0; i < this.exteriorRing.length; i++) {
|
|
188
|
+
if (this.hasZ)
|
|
189
|
+
exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y, this.exteriorRing[i].z]);
|
|
190
|
+
else
|
|
191
|
+
exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y]);
|
|
192
|
+
}
|
|
193
|
+
geoJSON.coordinates.push(exteriorRing);
|
|
194
|
+
}
|
|
195
|
+
for (let j = 0; j < this.interiorRings.length; j++) {
|
|
196
|
+
const interiorRing = [];
|
|
197
|
+
for (let k = 0; k < this.interiorRings[j].length; k++) {
|
|
198
|
+
if (this.hasZ)
|
|
199
|
+
interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y, this.interiorRings[j][k].z]);
|
|
200
|
+
else
|
|
201
|
+
interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y]);
|
|
202
|
+
}
|
|
203
|
+
geoJSON.coordinates.push(interiorRing);
|
|
204
|
+
}
|
|
205
|
+
return geoJSON;
|
|
206
|
+
};
|
|
207
|
+
export default Polygon;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
geoJSON: {
|
|
3
|
+
GeometryCollection: string;
|
|
4
|
+
LineString: string;
|
|
5
|
+
MultiLineString: string;
|
|
6
|
+
MultiPoint: string;
|
|
7
|
+
MultiPolygon: string;
|
|
8
|
+
Point: string;
|
|
9
|
+
Polygon: string;
|
|
10
|
+
};
|
|
11
|
+
wkb: {
|
|
12
|
+
GeometryCollection: number;
|
|
13
|
+
LineString: number;
|
|
14
|
+
MultiLineString: number;
|
|
15
|
+
MultiPoint: number;
|
|
16
|
+
MultiPolygon: number;
|
|
17
|
+
Point: number;
|
|
18
|
+
Polygon: number;
|
|
19
|
+
};
|
|
20
|
+
wkt: {
|
|
21
|
+
GeometryCollection: string;
|
|
22
|
+
LineString: string;
|
|
23
|
+
MultiLineString: string;
|
|
24
|
+
MultiPoint: string;
|
|
25
|
+
MultiPolygon: string;
|
|
26
|
+
Point: string;
|
|
27
|
+
Polygon: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export default _default;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
geoJSON: {
|
|
3
|
+
GeometryCollection: 'GeometryCollection',
|
|
4
|
+
LineString: 'LineString',
|
|
5
|
+
MultiLineString: 'MultiLineString',
|
|
6
|
+
MultiPoint: 'MultiPoint',
|
|
7
|
+
MultiPolygon: 'MultiPolygon',
|
|
8
|
+
Point: 'Point',
|
|
9
|
+
Polygon: 'Polygon'
|
|
10
|
+
},
|
|
11
|
+
wkb: {
|
|
12
|
+
GeometryCollection: 7,
|
|
13
|
+
LineString: 2,
|
|
14
|
+
MultiLineString: 5,
|
|
15
|
+
MultiPoint: 4,
|
|
16
|
+
MultiPolygon: 6,
|
|
17
|
+
Point: 1,
|
|
18
|
+
Polygon: 3
|
|
19
|
+
},
|
|
20
|
+
wkt: {
|
|
21
|
+
GeometryCollection: 'GEOMETRYCOLLECTION',
|
|
22
|
+
LineString: 'LINESTRING',
|
|
23
|
+
MultiLineString: 'MULTILINESTRING',
|
|
24
|
+
MultiPoint: 'MULTIPOINT',
|
|
25
|
+
MultiPolygon: 'MULTIPOLYGON',
|
|
26
|
+
Point: 'POINT',
|
|
27
|
+
Polygon: 'POLYGON'
|
|
28
|
+
}
|
|
29
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import Point from './point.js';
|
|
4
|
+
import Types from './types.js';
|
|
5
|
+
function WktParser(value) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
this.position = 0;
|
|
8
|
+
}
|
|
9
|
+
WktParser.prototype.match = function (tokens) {
|
|
10
|
+
this.skipWhitespaces();
|
|
11
|
+
for (const token of tokens) {
|
|
12
|
+
if (this.value.slice(Math.max(0, this.position)).indexOf(token) === 0) {
|
|
13
|
+
this.position += token.length;
|
|
14
|
+
return token;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
WktParser.prototype.matchRegex = function (tokens) {
|
|
20
|
+
this.skipWhitespaces();
|
|
21
|
+
for (const token of tokens) {
|
|
22
|
+
const match = this.value.slice(Math.max(0, this.position)).match(token);
|
|
23
|
+
if (match) {
|
|
24
|
+
this.position += match[0].length;
|
|
25
|
+
return match;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
WktParser.prototype.isMatch = function (tokens) {
|
|
31
|
+
this.skipWhitespaces();
|
|
32
|
+
for (const token of tokens) {
|
|
33
|
+
if (this.value.slice(Math.max(0, this.position)).indexOf(token) === 0) {
|
|
34
|
+
this.position += token.length;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
WktParser.prototype.matchType = function () {
|
|
41
|
+
const geometryType = this.match([
|
|
42
|
+
Types.wkt.Point,
|
|
43
|
+
Types.wkt.LineString,
|
|
44
|
+
Types.wkt.Polygon,
|
|
45
|
+
Types.wkt.MultiPoint,
|
|
46
|
+
Types.wkt.MultiLineString,
|
|
47
|
+
Types.wkt.MultiPolygon,
|
|
48
|
+
Types.wkt.GeometryCollection
|
|
49
|
+
]);
|
|
50
|
+
if (!geometryType)
|
|
51
|
+
throw new Error('Expected geometry type');
|
|
52
|
+
return geometryType;
|
|
53
|
+
};
|
|
54
|
+
WktParser.prototype.matchDimension = function () {
|
|
55
|
+
const dimension = this.match(['ZM', 'Z', 'M']);
|
|
56
|
+
switch (dimension) {
|
|
57
|
+
case 'ZM': {
|
|
58
|
+
return { hasM: true, hasZ: true };
|
|
59
|
+
}
|
|
60
|
+
case 'Z': {
|
|
61
|
+
return { hasM: false, hasZ: true };
|
|
62
|
+
}
|
|
63
|
+
case 'M': {
|
|
64
|
+
return { hasM: true, hasZ: false };
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
67
|
+
return { hasM: false, hasZ: false };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
WktParser.prototype.expectGroupStart = function () {
|
|
72
|
+
if (!this.isMatch(['(']))
|
|
73
|
+
throw new Error('Expected group start');
|
|
74
|
+
};
|
|
75
|
+
WktParser.prototype.expectGroupEnd = function () {
|
|
76
|
+
if (!this.isMatch([')']))
|
|
77
|
+
throw new Error('Expected group end');
|
|
78
|
+
};
|
|
79
|
+
WktParser.prototype.matchCoordinate = function (options) {
|
|
80
|
+
let match;
|
|
81
|
+
if (options.hasZ && options.hasM)
|
|
82
|
+
match = this.matchRegex([/^(\S*)\s+(\S*)\s+(\S*)\s+([^\s),]*)/]);
|
|
83
|
+
else if (options.hasZ || options.hasM)
|
|
84
|
+
match = this.matchRegex([/^(\S*)\s+(\S*)\s+([^\s),]*)/]);
|
|
85
|
+
else
|
|
86
|
+
match = this.matchRegex([/^(\S*)\s+([^\s),]*)/]);
|
|
87
|
+
if (!match)
|
|
88
|
+
throw new Error('Expected coordinates');
|
|
89
|
+
if (options.hasZ && options.hasM)
|
|
90
|
+
return new Point(Number.parseFloat(match[1]), Number.parseFloat(match[2]), Number.parseFloat(match[3]), Number.parseFloat(match[4]));
|
|
91
|
+
if (options.hasZ)
|
|
92
|
+
return new Point(Number.parseFloat(match[1]), Number.parseFloat(match[2]), Number.parseFloat(match[3]));
|
|
93
|
+
if (options.hasM)
|
|
94
|
+
return new Point(Number.parseFloat(match[1]), Number.parseFloat(match[2]), undefined, Number.parseFloat(match[3]));
|
|
95
|
+
return new Point(Number.parseFloat(match[1]), Number.parseFloat(match[2]));
|
|
96
|
+
};
|
|
97
|
+
WktParser.prototype.matchCoordinates = function (options) {
|
|
98
|
+
const coordinates = [];
|
|
99
|
+
do {
|
|
100
|
+
const startsWithBracket = this.isMatch(['(']);
|
|
101
|
+
coordinates.push(this.matchCoordinate(options));
|
|
102
|
+
if (startsWithBracket)
|
|
103
|
+
this.expectGroupEnd();
|
|
104
|
+
} while (this.isMatch([',']));
|
|
105
|
+
return coordinates;
|
|
106
|
+
};
|
|
107
|
+
WktParser.prototype.skipWhitespaces = function () {
|
|
108
|
+
while (this.position < this.value.length && this.value[this.position] === ' ')
|
|
109
|
+
this.position++;
|
|
110
|
+
};
|
|
111
|
+
export default WktParser;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './geometry.js';
|
|
3
|
+
export * from './point.js';
|
|
4
|
+
export * from './linestring.js';
|
|
5
|
+
export * from './polygon.js';
|
|
6
|
+
export * from './multipoint.js';
|
|
7
|
+
export * from './multilinestring.js';
|
|
8
|
+
export * from './multipolygon.js';
|
|
9
|
+
export * from './geometrycollection.js';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './geometry.js';
|
|
3
|
+
export * from './point.js';
|
|
4
|
+
export * from './linestring.js';
|
|
5
|
+
export * from './polygon.js';
|
|
6
|
+
export * from './multipoint.js';
|
|
7
|
+
export * from './multilinestring.js';
|
|
8
|
+
export * from './multipolygon.js';
|
|
9
|
+
export * from './geometrycollection.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SchemaGenerator } from './SchemaGenerator.js';
|
|
2
|
+
import { SqlSyncRules } from './SqlSyncRules.js';
|
|
3
|
+
import { SourceSchema } from './types.js';
|
|
4
|
+
export declare class DartSchemaGenerator extends SchemaGenerator {
|
|
5
|
+
readonly fileName = "schema.dart";
|
|
6
|
+
readonly key = "dart";
|
|
7
|
+
readonly label = "Dart";
|
|
8
|
+
readonly mediaType = "text/x-dart";
|
|
9
|
+
generate(source: SqlSyncRules, schema: SourceSchema): string;
|
|
10
|
+
private generateColumn;
|
|
11
|
+
private generateTable;
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/* eslint-disable unicorn/filename-case */
|
|
2
|
+
/* eslint-disable no-bitwise */
|
|
3
|
+
import { TYPE_INTEGER, TYPE_REAL, TYPE_TEXT } from './ExpressionType.js';
|
|
4
|
+
import { SchemaGenerator } from './SchemaGenerator.js';
|
|
5
|
+
export class DartSchemaGenerator extends SchemaGenerator {
|
|
6
|
+
fileName = 'schema.dart';
|
|
7
|
+
key = 'dart';
|
|
8
|
+
label = 'Dart';
|
|
9
|
+
mediaType = 'text/x-dart';
|
|
10
|
+
generate(source, schema) {
|
|
11
|
+
const tables = super.getAllTables(source, schema);
|
|
12
|
+
return `Schema([
|
|
13
|
+
${tables.map((table) => this.generateTable(table.name, table.columns)).join(',\n ')}
|
|
14
|
+
])
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
generateColumn(column) {
|
|
18
|
+
const t = column.type;
|
|
19
|
+
if (t.typeFlags & TYPE_TEXT) {
|
|
20
|
+
return `Column.text('${column.name}')`;
|
|
21
|
+
}
|
|
22
|
+
if (t.typeFlags & TYPE_REAL) {
|
|
23
|
+
return `Column.real('${column.name}')`;
|
|
24
|
+
}
|
|
25
|
+
if (t.typeFlags & TYPE_INTEGER) {
|
|
26
|
+
return `Column.integer('${column.name}')`;
|
|
27
|
+
}
|
|
28
|
+
return `Column.text('${column.name}')`;
|
|
29
|
+
}
|
|
30
|
+
generateTable(name, columns) {
|
|
31
|
+
return `Table('${name}', [
|
|
32
|
+
${columns.map((c) => this.generateColumn(c)).join(',\n ')}
|
|
33
|
+
])`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const TYPE_NONE = 0;
|
|
2
|
+
export declare const TYPE_BLOB = 1;
|
|
3
|
+
export declare const TYPE_TEXT = 2;
|
|
4
|
+
export declare const TYPE_INTEGER = 4;
|
|
5
|
+
export declare const TYPE_REAL = 8;
|
|
6
|
+
export type SqliteType = 'blob' | 'integer' | 'null' | 'real' | 'text';
|
|
7
|
+
export interface ColumnDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
type: ExpressionType;
|
|
10
|
+
}
|
|
11
|
+
export declare class ExpressionType {
|
|
12
|
+
/**
|
|
13
|
+
* Any type.
|
|
14
|
+
*/
|
|
15
|
+
static ANY: ExpressionType;
|
|
16
|
+
static ANY_JSON: ExpressionType;
|
|
17
|
+
static BLOB: ExpressionType;
|
|
18
|
+
static INTEGER: ExpressionType;
|
|
19
|
+
/**
|
|
20
|
+
* Always null.
|
|
21
|
+
*/
|
|
22
|
+
static NONE: ExpressionType;
|
|
23
|
+
static NUMERIC: ExpressionType;
|
|
24
|
+
static REAL: ExpressionType;
|
|
25
|
+
static TEXT: ExpressionType;
|
|
26
|
+
readonly typeFlags: number;
|
|
27
|
+
private constructor();
|
|
28
|
+
static fromTypeText(type: 'numeric' | SqliteType): ExpressionType;
|
|
29
|
+
static of(typeFlags: number): ExpressionType;
|
|
30
|
+
and(other: ExpressionType): ExpressionType;
|
|
31
|
+
isNumericOnly(): boolean;
|
|
32
|
+
or(other: ExpressionType): ExpressionType;
|
|
33
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/* eslint-disable unicorn/filename-case */
|
|
2
|
+
/* eslint-disable eqeqeq */
|
|
3
|
+
/* eslint-disable no-bitwise */
|
|
4
|
+
export const TYPE_NONE = 0;
|
|
5
|
+
export const TYPE_BLOB = 1;
|
|
6
|
+
export const TYPE_TEXT = 2;
|
|
7
|
+
export const TYPE_INTEGER = 4;
|
|
8
|
+
export const TYPE_REAL = 8;
|
|
9
|
+
export class ExpressionType {
|
|
10
|
+
/**
|
|
11
|
+
* Any type.
|
|
12
|
+
*/
|
|
13
|
+
static ANY = new ExpressionType(TYPE_BLOB | TYPE_TEXT | TYPE_INTEGER | TYPE_REAL);
|
|
14
|
+
static ANY_JSON = new ExpressionType(TYPE_TEXT | TYPE_INTEGER | TYPE_REAL);
|
|
15
|
+
static BLOB = new ExpressionType(TYPE_BLOB);
|
|
16
|
+
static INTEGER = new ExpressionType(TYPE_INTEGER);
|
|
17
|
+
/**
|
|
18
|
+
* Always null.
|
|
19
|
+
*/
|
|
20
|
+
static NONE = new ExpressionType(0);
|
|
21
|
+
static NUMERIC = new ExpressionType(TYPE_INTEGER | TYPE_REAL);
|
|
22
|
+
static REAL = new ExpressionType(TYPE_REAL);
|
|
23
|
+
static TEXT = new ExpressionType(TYPE_TEXT);
|
|
24
|
+
typeFlags;
|
|
25
|
+
constructor(typeFlags) {
|
|
26
|
+
this.typeFlags = typeFlags;
|
|
27
|
+
}
|
|
28
|
+
static fromTypeText(type) {
|
|
29
|
+
if (type == 'null') {
|
|
30
|
+
return ExpressionType.NONE;
|
|
31
|
+
}
|
|
32
|
+
if (type == 'blob') {
|
|
33
|
+
return ExpressionType.BLOB;
|
|
34
|
+
}
|
|
35
|
+
if (type == 'text') {
|
|
36
|
+
return ExpressionType.TEXT;
|
|
37
|
+
}
|
|
38
|
+
if (type == 'integer') {
|
|
39
|
+
return ExpressionType.INTEGER;
|
|
40
|
+
}
|
|
41
|
+
if (type == 'real') {
|
|
42
|
+
return ExpressionType.REAL;
|
|
43
|
+
}
|
|
44
|
+
if (type == 'numeric') {
|
|
45
|
+
return ExpressionType.NUMERIC;
|
|
46
|
+
}
|
|
47
|
+
return ExpressionType.NONE;
|
|
48
|
+
}
|
|
49
|
+
static of(typeFlags) {
|
|
50
|
+
// TODO: cache?
|
|
51
|
+
return new ExpressionType(typeFlags);
|
|
52
|
+
}
|
|
53
|
+
and(other) {
|
|
54
|
+
return ExpressionType.of(this.typeFlags & other.typeFlags);
|
|
55
|
+
}
|
|
56
|
+
isNumericOnly() {
|
|
57
|
+
return this.typeFlags != TYPE_NONE && (this.typeFlags & (TYPE_INTEGER | TYPE_REAL)) == this.typeFlags;
|
|
58
|
+
}
|
|
59
|
+
or(other) {
|
|
60
|
+
return ExpressionType.of(this.typeFlags | other.typeFlags);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SchemaGenerator } from './SchemaGenerator.js';
|
|
2
|
+
import { SqlSyncRules } from './SqlSyncRules.js';
|
|
3
|
+
import { SourceSchema } from './types.js';
|
|
4
|
+
export declare class JsSchemaGenerator extends SchemaGenerator {
|
|
5
|
+
readonly fileName = "schema.js";
|
|
6
|
+
readonly key = "js";
|
|
7
|
+
readonly label = "JavaScript";
|
|
8
|
+
readonly mediaType = "application/javascript";
|
|
9
|
+
generate(source: SqlSyncRules, schema: SourceSchema): string;
|
|
10
|
+
private generateColumn;
|
|
11
|
+
private generateTable;
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable unicorn/filename-case */
|
|
2
|
+
/* eslint-disable no-bitwise */
|
|
3
|
+
import { TYPE_INTEGER, TYPE_REAL, TYPE_TEXT } from './ExpressionType.js';
|
|
4
|
+
import { SchemaGenerator } from './SchemaGenerator.js';
|
|
5
|
+
export class JsSchemaGenerator extends SchemaGenerator {
|
|
6
|
+
fileName = 'schema.js';
|
|
7
|
+
key = 'js';
|
|
8
|
+
label = 'JavaScript';
|
|
9
|
+
mediaType = 'application/javascript';
|
|
10
|
+
generate(source, schema) {
|
|
11
|
+
const tables = super.getAllTables(source, schema);
|
|
12
|
+
return `new Schema([
|
|
13
|
+
${tables.map((table) => this.generateTable(table.name, table.columns)).join(',\n ')}
|
|
14
|
+
])
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
generateColumn(column) {
|
|
18
|
+
const t = column.type;
|
|
19
|
+
if (t.typeFlags & TYPE_TEXT) {
|
|
20
|
+
return `new Column({ name: '${column.name}', type: ColumnType.TEXT })`;
|
|
21
|
+
}
|
|
22
|
+
if (t.typeFlags & TYPE_REAL) {
|
|
23
|
+
return `new Column({ name: '${column.name}', type: ColumnType.REAL })`;
|
|
24
|
+
}
|
|
25
|
+
if (t.typeFlags & TYPE_INTEGER) {
|
|
26
|
+
return `new Column({ name: '${column.name}', type: ColumnType.INTEGER })`;
|
|
27
|
+
}
|
|
28
|
+
return `new Column({ name: '${column.name}', type: ColumnType.TEXT })`;
|
|
29
|
+
}
|
|
30
|
+
generateTable(name, columns) {
|
|
31
|
+
return `new Table({
|
|
32
|
+
name: '${name}',
|
|
33
|
+
columns: [
|
|
34
|
+
${columns.map((c) => this.generateColumn(c)).join(',\n ')}
|
|
35
|
+
]
|
|
36
|
+
})`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ColumnDefinition } from './ExpressionType.js';
|
|
2
|
+
import { SqlSyncRules } from './SqlSyncRules.js';
|
|
3
|
+
import { SourceSchema } from './types.js';
|
|
4
|
+
export declare abstract class SchemaGenerator {
|
|
5
|
+
protected getAllTables(source: SqlSyncRules, schema: SourceSchema): {
|
|
6
|
+
columns: ColumnDefinition[];
|
|
7
|
+
name: string;
|
|
8
|
+
}[];
|
|
9
|
+
abstract readonly fileName: string;
|
|
10
|
+
abstract generate(source: SqlSyncRules, schema: SourceSchema): string;
|
|
11
|
+
abstract readonly key: string;
|
|
12
|
+
abstract readonly label: string;
|
|
13
|
+
abstract readonly mediaType: string;
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class SchemaGenerator {
|
|
2
|
+
getAllTables(source, schema) {
|
|
3
|
+
const tables = {};
|
|
4
|
+
for (const descriptor of source.bucket_descriptors) {
|
|
5
|
+
for (const query of descriptor.data_queries) {
|
|
6
|
+
const outTables = query.getColumnOutputs(schema);
|
|
7
|
+
for (const table of outTables) {
|
|
8
|
+
tables[table.name] ??= {};
|
|
9
|
+
for (const column of table.columns) {
|
|
10
|
+
if (column.name !== 'id') {
|
|
11
|
+
tables[table.name][column.name] ??= column;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return Object.entries(tables).map(([name, columns]) => {
|
|
18
|
+
return {
|
|
19
|
+
columns: Object.values(columns),
|
|
20
|
+
name
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|