durcno 1.0.0-alpha.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.
Files changed (174) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +56 -0
  3. package/dist/bin.cjs +13522 -0
  4. package/dist/src/_virtual/_rolldown/runtime.mjs +28 -0
  5. package/dist/src/cli/helpers.mjs +16 -0
  6. package/dist/src/columns/bigint.d.mts +19 -0
  7. package/dist/src/columns/bigint.mjs +32 -0
  8. package/dist/src/columns/bigserial.d.mts +24 -0
  9. package/dist/src/columns/bigserial.mjs +35 -0
  10. package/dist/src/columns/boolean.d.mts +19 -0
  11. package/dist/src/columns/boolean.mjs +31 -0
  12. package/dist/src/columns/bytea.d.mts +19 -0
  13. package/dist/src/columns/bytea.mjs +33 -0
  14. package/dist/src/columns/char.d.mts +32 -0
  15. package/dist/src/columns/char.mjs +44 -0
  16. package/dist/src/columns/cidr.d.mts +19 -0
  17. package/dist/src/columns/cidr.mjs +31 -0
  18. package/dist/src/columns/common.d.mts +233 -0
  19. package/dist/src/columns/common.mjs +276 -0
  20. package/dist/src/columns/date.d.mts +19 -0
  21. package/dist/src/columns/date.mjs +32 -0
  22. package/dist/src/columns/enum.d.mts +21 -0
  23. package/dist/src/columns/enum.mjs +35 -0
  24. package/dist/src/columns/inet.d.mts +19 -0
  25. package/dist/src/columns/inet.mjs +36 -0
  26. package/dist/src/columns/integer.d.mts +19 -0
  27. package/dist/src/columns/integer.mjs +32 -0
  28. package/dist/src/columns/json.d.mts +52 -0
  29. package/dist/src/columns/json.mjs +67 -0
  30. package/dist/src/columns/jsonb.d.mts +53 -0
  31. package/dist/src/columns/jsonb.mjs +68 -0
  32. package/dist/src/columns/macaddr.d.mts +19 -0
  33. package/dist/src/columns/macaddr.mjs +31 -0
  34. package/dist/src/columns/numeric.d.mts +42 -0
  35. package/dist/src/columns/numeric.mjs +57 -0
  36. package/dist/src/columns/postgis/geography/index.d.mts +18 -0
  37. package/dist/src/columns/postgis/geography/index.mjs +17 -0
  38. package/dist/src/columns/postgis/geography/linestring.d.mts +38 -0
  39. package/dist/src/columns/postgis/geography/linestring.mjs +70 -0
  40. package/dist/src/columns/postgis/geography/multilinestring.d.mts +39 -0
  41. package/dist/src/columns/postgis/geography/multilinestring.mjs +70 -0
  42. package/dist/src/columns/postgis/geography/multipoint.d.mts +38 -0
  43. package/dist/src/columns/postgis/geography/multipoint.mjs +70 -0
  44. package/dist/src/columns/postgis/geography/multipolygon.d.mts +40 -0
  45. package/dist/src/columns/postgis/geography/multipolygon.mjs +70 -0
  46. package/dist/src/columns/postgis/geography/point.d.mts +36 -0
  47. package/dist/src/columns/postgis/geography/point.mjs +69 -0
  48. package/dist/src/columns/postgis/geography/polygon.d.mts +39 -0
  49. package/dist/src/columns/postgis/geography/polygon.mjs +70 -0
  50. package/dist/src/columns/serial.d.mts +24 -0
  51. package/dist/src/columns/serial.mjs +35 -0
  52. package/dist/src/columns/smallint.d.mts +19 -0
  53. package/dist/src/columns/smallint.mjs +32 -0
  54. package/dist/src/columns/smallserial.d.mts +24 -0
  55. package/dist/src/columns/smallserial.mjs +35 -0
  56. package/dist/src/columns/text.d.mts +19 -0
  57. package/dist/src/columns/text.mjs +30 -0
  58. package/dist/src/columns/time.d.mts +44 -0
  59. package/dist/src/columns/time.mjs +47 -0
  60. package/dist/src/columns/timestamp.d.mts +44 -0
  61. package/dist/src/columns/timestamp.mjs +47 -0
  62. package/dist/src/columns/uuid.d.mts +33 -0
  63. package/dist/src/columns/uuid.mjs +44 -0
  64. package/dist/src/columns/varchar.d.mts +32 -0
  65. package/dist/src/columns/varchar.mjs +44 -0
  66. package/dist/src/connectors/bun.d.mts +18 -0
  67. package/dist/src/connectors/bun.mjs +97 -0
  68. package/dist/src/connectors/common.d.mts +148 -0
  69. package/dist/src/connectors/common.mjs +65 -0
  70. package/dist/src/connectors/pg.d.mts +18 -0
  71. package/dist/src/connectors/pg.mjs +103 -0
  72. package/dist/src/connectors/pglite.d.mts +19 -0
  73. package/dist/src/connectors/pglite.mjs +94 -0
  74. package/dist/src/connectors/postgres.d.mts +18 -0
  75. package/dist/src/connectors/postgres.mjs +93 -0
  76. package/dist/src/constraints/check.d.mts +88 -0
  77. package/dist/src/constraints/check.mjs +307 -0
  78. package/dist/src/constraints/primary-key.d.mts +28 -0
  79. package/dist/src/constraints/primary-key.mjs +36 -0
  80. package/dist/src/constraints/unique.d.mts +28 -0
  81. package/dist/src/constraints/unique.mjs +36 -0
  82. package/dist/src/db.d.mts +180 -0
  83. package/dist/src/db.mjs +191 -0
  84. package/dist/src/entity.mjs +23 -0
  85. package/dist/src/enumtype.d.mts +27 -0
  86. package/dist/src/enumtype.mjs +42 -0
  87. package/dist/src/filters/array.d.mts +97 -0
  88. package/dist/src/filters/array.mjs +150 -0
  89. package/dist/src/filters/custom.d.mts +12 -0
  90. package/dist/src/filters/custom.mjs +7 -0
  91. package/dist/src/filters/index.d.mts +155 -0
  92. package/dist/src/filters/index.mjs +318 -0
  93. package/dist/src/functions/index.d.mts +24 -0
  94. package/dist/src/functions/index.mjs +29 -0
  95. package/dist/src/index.d.mts +129 -0
  96. package/dist/src/index.mjs +78 -0
  97. package/dist/src/indexes.d.mts +31 -0
  98. package/dist/src/indexes.mjs +43 -0
  99. package/dist/src/migration/consts.d.mts +8 -0
  100. package/dist/src/migration/consts.mjs +8 -0
  101. package/dist/src/migration/ddl.d.mts +747 -0
  102. package/dist/src/migration/ddl.mjs +1084 -0
  103. package/dist/src/migration/index.d.mts +15 -0
  104. package/dist/src/migration/index.mjs +5 -0
  105. package/dist/src/migration/snapshot.d.mts +169 -0
  106. package/dist/src/migration/snapshot.mjs +123 -0
  107. package/dist/src/migration/statement.d.mts +89 -0
  108. package/dist/src/migration/statement.mjs +61 -0
  109. package/dist/src/models.d.mts +34 -0
  110. package/dist/src/models.mjs +27 -0
  111. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/index.mjs +126 -0
  112. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/utilities.mjs +29 -0
  113. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.mjs +165 -0
  114. package/dist/src/node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.mjs +92 -0
  115. package/dist/src/query-builders/aggregates.d.mts +20 -0
  116. package/dist/src/query-builders/aggregates.mjs +43 -0
  117. package/dist/src/query-builders/count.d.mts +19 -0
  118. package/dist/src/query-builders/count.mjs +36 -0
  119. package/dist/src/query-builders/delete.d.mts +19 -0
  120. package/dist/src/query-builders/delete.mjs +57 -0
  121. package/dist/src/query-builders/distinct.d.mts +19 -0
  122. package/dist/src/query-builders/distinct.mjs +42 -0
  123. package/dist/src/query-builders/exists.d.mts +19 -0
  124. package/dist/src/query-builders/exists.mjs +37 -0
  125. package/dist/src/query-builders/first.d.mts +17 -0
  126. package/dist/src/query-builders/first.mjs +46 -0
  127. package/dist/src/query-builders/insert-returning.d.mts +16 -0
  128. package/dist/src/query-builders/insert-returning.mjs +63 -0
  129. package/dist/src/query-builders/insert.d.mts +22 -0
  130. package/dist/src/query-builders/insert.mjs +93 -0
  131. package/dist/src/query-builders/orderby-clause.d.mts +14 -0
  132. package/dist/src/query-builders/orderby-clause.mjs +20 -0
  133. package/dist/src/query-builders/pre.d.mts +36 -0
  134. package/dist/src/query-builders/pre.mjs +60 -0
  135. package/dist/src/query-builders/query-promise.d.mts +14 -0
  136. package/dist/src/query-builders/query-promise.mjs +21 -0
  137. package/dist/src/query-builders/query.d.mts +14 -0
  138. package/dist/src/query-builders/query.mjs +17 -0
  139. package/dist/src/query-builders/raw.d.mts +14 -0
  140. package/dist/src/query-builders/raw.mjs +26 -0
  141. package/dist/src/query-builders/rq.d.mts +36 -0
  142. package/dist/src/query-builders/rq.mjs +231 -0
  143. package/dist/src/query-builders/select.d.mts +48 -0
  144. package/dist/src/query-builders/select.mjs +118 -0
  145. package/dist/src/query-builders/update.d.mts +24 -0
  146. package/dist/src/query-builders/update.mjs +99 -0
  147. package/dist/src/sequence.d.mts +48 -0
  148. package/dist/src/sequence.mjs +53 -0
  149. package/dist/src/sql.d.mts +15 -0
  150. package/dist/src/sql.mjs +36 -0
  151. package/dist/src/symbols.d.mts +4 -0
  152. package/dist/src/symbols.mjs +4 -0
  153. package/dist/src/table.d.mts +144 -0
  154. package/dist/src/table.mjs +134 -0
  155. package/dist/src/types.d.mts +4 -0
  156. package/dist/src/utils.mjs +10 -0
  157. package/dist/src/validators/zod.d.mts +23 -0
  158. package/dist/src/validators/zod.mjs +27 -0
  159. package/dist/src/wkx/binaryreader.mjs +56 -0
  160. package/dist/src/wkx/binarywriter.mjs +110 -0
  161. package/dist/src/wkx/geometry.mjs +101 -0
  162. package/dist/src/wkx/geometrycollection.mjs +113 -0
  163. package/dist/src/wkx/index.mjs +18 -0
  164. package/dist/src/wkx/linestring.mjs +124 -0
  165. package/dist/src/wkx/multilinestring.mjs +133 -0
  166. package/dist/src/wkx/multipoint.mjs +120 -0
  167. package/dist/src/wkx/multipolygon.mjs +155 -0
  168. package/dist/src/wkx/parser.mjs +183 -0
  169. package/dist/src/wkx/point.mjs +159 -0
  170. package/dist/src/wkx/polygon.mjs +189 -0
  171. package/dist/src/wkx/types.mjs +37 -0
  172. package/dist/src/wkx/wktparser.mjs +109 -0
  173. package/dist/src/wkx/zigzag.mjs +18 -0
  174. package/package.json +100 -0
@@ -0,0 +1,183 @@
1
+ import { BinaryReader } from "./binaryreader.mjs";
2
+ import { ZigZag, init_zigzag } from "./zigzag.mjs";
3
+ import { Geometry, init_geometry } from "./geometry.mjs";
4
+ import { Types, init_types } from "./types.mjs";
5
+ import { GeometryCollection } from "./geometrycollection.mjs";
6
+ import { Point, init_point } from "./point.mjs";
7
+ import { LineString } from "./linestring.mjs";
8
+ import { MultiLineString } from "./multilinestring.mjs";
9
+ import { MultiPoint } from "./multipoint.mjs";
10
+ import { Polygon } from "./polygon.mjs";
11
+ import { MultiPolygon } from "./multipolygon.mjs";
12
+ import { WktParser } from "./wktparser.mjs";
13
+ //#region src/wkx/parser.ts
14
+ init_geometry();
15
+ init_point();
16
+ init_types();
17
+ init_zigzag();
18
+ function parse(value, options) {
19
+ if (typeof value === "string" || value instanceof WktParser) return parseWkt(value);
20
+ else if (Buffer.isBuffer(value) || value instanceof BinaryReader) return parseWkb(value, options);
21
+ else throw new Error("first argument must be a string or Buffer");
22
+ }
23
+ function parseWkt(value) {
24
+ let wktParser;
25
+ let srid;
26
+ if (value instanceof WktParser) wktParser = value;
27
+ else wktParser = new WktParser(value);
28
+ const match = wktParser.matchRegex([/^SRID=(\d+);/]);
29
+ if (match) srid = parseInt(match[1], 10);
30
+ const geometryType = wktParser.matchType();
31
+ const dimension = wktParser.matchDimension();
32
+ const options = {
33
+ srid,
34
+ hasZ: dimension.hasZ,
35
+ hasM: dimension.hasM
36
+ };
37
+ switch (geometryType) {
38
+ case Types.wkt.Point: return Point._parseWkt(wktParser, options);
39
+ case Types.wkt.LineString: return LineString._parseWkt(wktParser, options);
40
+ case Types.wkt.Polygon: return Polygon._parseWkt(wktParser, options);
41
+ case Types.wkt.MultiPoint: return MultiPoint._parseWkt(wktParser, options);
42
+ case Types.wkt.MultiLineString: return MultiLineString._parseWkt(wktParser, options);
43
+ case Types.wkt.MultiPolygon: return MultiPolygon._parseWkt(wktParser, options);
44
+ case Types.wkt.GeometryCollection: return GeometryCollection._parseWkt(wktParser, options);
45
+ default: throw new Error("GeometryType " + geometryType + " not supported");
46
+ }
47
+ }
48
+ function parseWkb(value, parentOptions) {
49
+ let binaryReader;
50
+ let wkbType;
51
+ let geometryType;
52
+ const options = {};
53
+ if (value instanceof BinaryReader) binaryReader = value;
54
+ else binaryReader = new BinaryReader(value);
55
+ binaryReader.isBigEndian = !binaryReader.readInt8();
56
+ wkbType = binaryReader.readUInt32();
57
+ options.hasSrid = (wkbType & 536870912) === 536870912;
58
+ options.isEwkb = !!(wkbType & 536870912) || !!(wkbType & 1073741824) || !!(wkbType & 2147483648);
59
+ if (options.hasSrid) options.srid = binaryReader.readUInt32();
60
+ options.hasZ = false;
61
+ options.hasM = false;
62
+ if (!options.isEwkb && (!parentOptions || !parentOptions.isEwkb)) if (wkbType >= 1e3 && wkbType < 2e3) {
63
+ options.hasZ = true;
64
+ geometryType = wkbType - 1e3;
65
+ } else if (wkbType >= 2e3 && wkbType < 3e3) {
66
+ options.hasM = true;
67
+ geometryType = wkbType - 2e3;
68
+ } else if (wkbType >= 3e3 && wkbType < 4e3) {
69
+ options.hasZ = true;
70
+ options.hasM = true;
71
+ geometryType = wkbType - 3e3;
72
+ } else geometryType = wkbType;
73
+ else {
74
+ if (wkbType & 2147483648) options.hasZ = true;
75
+ if (wkbType & 1073741824) options.hasM = true;
76
+ geometryType = wkbType & 15;
77
+ }
78
+ switch (geometryType) {
79
+ case Types.wkb.Point: return Point._parseWkb(binaryReader, options);
80
+ case Types.wkb.LineString: return LineString._parseWkb(binaryReader, options);
81
+ case Types.wkb.Polygon: return Polygon._parseWkb(binaryReader, options);
82
+ case Types.wkb.MultiPoint: return MultiPoint._parseWkb(binaryReader, options);
83
+ case Types.wkb.MultiLineString: return MultiLineString._parseWkb(binaryReader, options);
84
+ case Types.wkb.MultiPolygon: return MultiPolygon._parseWkb(binaryReader, options);
85
+ case Types.wkb.GeometryCollection: return GeometryCollection._parseWkb(binaryReader, options);
86
+ default: throw new Error("GeometryType " + geometryType + " not supported");
87
+ }
88
+ }
89
+ function parseTwkb(value) {
90
+ let binaryReader;
91
+ const options = {};
92
+ if (value instanceof BinaryReader) binaryReader = value;
93
+ else binaryReader = new BinaryReader(value);
94
+ const type = binaryReader.readUInt8();
95
+ const metadataHeader = binaryReader.readUInt8();
96
+ const geometryType = type & 15;
97
+ options.precision = ZigZag.decode(type >> 4);
98
+ options.precisionFactor = 10 ** options.precision;
99
+ options.hasBoundingBox = metadataHeader >> 0 & 1;
100
+ options.hasSizeAttribute = metadataHeader >> 1 & 1;
101
+ options.hasIdList = metadataHeader >> 2 & 1;
102
+ options.hasExtendedPrecision = metadataHeader >> 3 & 1;
103
+ options.isEmpty = metadataHeader >> 4 & 1;
104
+ if (options.hasExtendedPrecision) {
105
+ const extendedPrecision = binaryReader.readUInt8();
106
+ options.hasZ = (extendedPrecision & 1) === 1;
107
+ options.hasM = (extendedPrecision & 2) === 2;
108
+ options.zPrecision = ZigZag.decode((extendedPrecision & 28) >> 2);
109
+ options.zPrecisionFactor = 10 ** options.zPrecision;
110
+ options.mPrecision = ZigZag.decode((extendedPrecision & 224) >> 5);
111
+ options.mPrecisionFactor = 10 ** options.mPrecision;
112
+ } else {
113
+ options.hasZ = false;
114
+ options.hasM = false;
115
+ }
116
+ if (options.hasSizeAttribute) binaryReader.readVarInt();
117
+ if (options.hasBoundingBox) {
118
+ let dimensions = 2;
119
+ if (options.hasZ) dimensions++;
120
+ if (options.hasM) dimensions++;
121
+ for (let i = 0; i < dimensions; i++) {
122
+ binaryReader.readVarInt();
123
+ binaryReader.readVarInt();
124
+ }
125
+ }
126
+ switch (geometryType) {
127
+ case Types.wkb.Point: return Point._parseTwkb(binaryReader, options);
128
+ case Types.wkb.LineString: return LineString._parseTwkb(binaryReader, options);
129
+ case Types.wkb.Polygon: return Polygon._parseTwkb(binaryReader, options);
130
+ case Types.wkb.MultiPoint: return MultiPoint._parseTwkb(binaryReader, options);
131
+ case Types.wkb.MultiLineString: return MultiLineString._parseTwkb(binaryReader, options);
132
+ case Types.wkb.MultiPolygon: return MultiPolygon._parseTwkb(binaryReader, options);
133
+ case Types.wkb.GeometryCollection: return GeometryCollection._parseTwkb(binaryReader, options);
134
+ default: throw new Error("GeometryType " + geometryType + " not supported");
135
+ }
136
+ }
137
+ function parseGeoJSON(value) {
138
+ return parseGeoJSONInternal(value);
139
+ }
140
+ function parseGeoJSONInternal(value, isSubGeometry = false) {
141
+ let geometry;
142
+ const geometryType = value.type;
143
+ switch (geometryType) {
144
+ case Types.geoJSON.Point:
145
+ geometry = Point._parseGeoJSON(value);
146
+ break;
147
+ case Types.geoJSON.LineString:
148
+ geometry = LineString._parseGeoJSON(value);
149
+ break;
150
+ case Types.geoJSON.Polygon:
151
+ geometry = Polygon._parseGeoJSON(value);
152
+ break;
153
+ case Types.geoJSON.MultiPoint:
154
+ geometry = MultiPoint._parseGeoJSON(value);
155
+ break;
156
+ case Types.geoJSON.MultiLineString:
157
+ geometry = MultiLineString._parseGeoJSON(value);
158
+ break;
159
+ case Types.geoJSON.MultiPolygon:
160
+ geometry = MultiPolygon._parseGeoJSON(value);
161
+ break;
162
+ case Types.geoJSON.GeometryCollection:
163
+ geometry = GeometryCollection._parseGeoJSON(value);
164
+ break;
165
+ default: throw new Error("GeometryType " + geometryType + " not supported");
166
+ }
167
+ const valueWithCrs = value;
168
+ if (valueWithCrs.crs && valueWithCrs.crs.type && valueWithCrs.crs.type === "name" && valueWithCrs.crs.properties && valueWithCrs.crs.properties.name) {
169
+ const crs = valueWithCrs.crs.properties.name;
170
+ if (crs.indexOf("EPSG:") === 0) geometry.srid = parseInt(crs.substring(5));
171
+ else if (crs.indexOf("urn:ogc:def:crs:EPSG::") === 0) geometry.srid = parseInt(crs.substring(22));
172
+ else throw new Error("Unsupported crs: " + crs);
173
+ } else if (!isSubGeometry) geometry.srid = 4326;
174
+ return geometry;
175
+ }
176
+ Geometry.parse = parse;
177
+ Geometry.parseTwkb = parseTwkb;
178
+ Geometry.parseGeoJSON = parseGeoJSON;
179
+ Geometry._parseWkt = parseWkt;
180
+ Geometry._parseWkb = parseWkb;
181
+ Geometry._parseGeoJSON = parseGeoJSONInternal;
182
+ //#endregion
183
+ export {};
@@ -0,0 +1,159 @@
1
+ import { __esmMin, __exportAll } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
3
+ import { ZigZag, init_zigzag } from "./zigzag.mjs";
4
+ import { Geometry, init_geometry } from "./geometry.mjs";
5
+ import { Types, init_types } from "./types.mjs";
6
+ //#region src/wkx/point.ts
7
+ var point_exports = /* @__PURE__ */ __exportAll({ Point: () => Point });
8
+ var Point;
9
+ var init_point = __esmMin((() => {
10
+ init_binarywriter();
11
+ init_geometry();
12
+ init_types();
13
+ init_zigzag();
14
+ Point = class Point extends Geometry {
15
+ x;
16
+ y;
17
+ z;
18
+ m;
19
+ constructor(x, y, z, m, srid) {
20
+ super();
21
+ this.x = x;
22
+ this.y = y;
23
+ this.z = z;
24
+ this.m = m;
25
+ this.srid = srid;
26
+ this.hasZ = z !== void 0;
27
+ this.hasM = m !== void 0;
28
+ }
29
+ static Z(x, y, z, srid) {
30
+ const point = new Point(x, y, z, void 0, srid);
31
+ point.hasZ = true;
32
+ return point;
33
+ }
34
+ static M(x, y, m, srid) {
35
+ const point = new Point(x, y, void 0, m, srid);
36
+ point.hasM = true;
37
+ return point;
38
+ }
39
+ static ZM(x, y, z, m, srid) {
40
+ const point = new Point(x, y, z, m, srid);
41
+ point.hasZ = true;
42
+ point.hasM = true;
43
+ return point;
44
+ }
45
+ static _parseWkt(value, options) {
46
+ const point = new Point();
47
+ point.srid = options.srid;
48
+ point.hasZ = options.hasZ;
49
+ point.hasM = options.hasM;
50
+ if (value.isMatch(["EMPTY"])) return point;
51
+ value.expectGroupStart();
52
+ const coordinate = value.matchCoordinate(options);
53
+ point.x = coordinate.x;
54
+ point.y = coordinate.y;
55
+ point.z = coordinate.z;
56
+ point.m = coordinate.m;
57
+ value.expectGroupEnd();
58
+ return point;
59
+ }
60
+ static _parseWkb(value, options) {
61
+ const point = Point._readWkbPoint(value, options);
62
+ point.srid = options.srid;
63
+ return point;
64
+ }
65
+ static _readWkbPoint(value, options) {
66
+ return new Point(value.readDouble(), value.readDouble(), options.hasZ ? value.readDouble() : void 0, options.hasM ? value.readDouble() : void 0);
67
+ }
68
+ static _parseTwkb(value, options) {
69
+ const point = new Point();
70
+ point.hasZ = options.hasZ || false;
71
+ point.hasM = options.hasM || false;
72
+ if (options.isEmpty) return point;
73
+ point.x = ZigZag.decode(value.readVarInt()) / (options.precisionFactor || 1);
74
+ point.y = ZigZag.decode(value.readVarInt()) / (options.precisionFactor || 1);
75
+ point.z = options.hasZ ? ZigZag.decode(value.readVarInt()) / (options.zPrecisionFactor || 1) : void 0;
76
+ point.m = options.hasM ? ZigZag.decode(value.readVarInt()) / (options.mPrecisionFactor || 1) : void 0;
77
+ return point;
78
+ }
79
+ static _readTwkbPoint(value, options, previousPoint) {
80
+ previousPoint.x = (previousPoint.x || 0) + ZigZag.decode(value.readVarInt()) / (options.precisionFactor || 1);
81
+ previousPoint.y = (previousPoint.y || 0) + ZigZag.decode(value.readVarInt()) / (options.precisionFactor || 1);
82
+ if (options.hasZ) previousPoint.z = (previousPoint.z || 0) + ZigZag.decode(value.readVarInt()) / (options.zPrecisionFactor || 1);
83
+ if (options.hasM) previousPoint.m = (previousPoint.m || 0) + ZigZag.decode(value.readVarInt()) / (options.mPrecisionFactor || 1);
84
+ return new Point(previousPoint.x, previousPoint.y, previousPoint.z, previousPoint.m);
85
+ }
86
+ static _parseGeoJSON(value) {
87
+ return Point._readGeoJSONPoint(value.coordinates);
88
+ }
89
+ static _readGeoJSONPoint(coordinates) {
90
+ if (coordinates.length === 0) return new Point();
91
+ return new Point(coordinates.at(0), coordinates.at(1), coordinates.at(2), coordinates.at(3));
92
+ }
93
+ toWkt() {
94
+ if (typeof this.x === "undefined" && typeof this.y === "undefined" && typeof this.z === "undefined" && typeof this.m === "undefined") return this._getWktType(Types.wkt.Point, true);
95
+ return this._getWktType(Types.wkt.Point, false) + "(" + this._getWktCoordinate(this) + ")";
96
+ }
97
+ toWkb(parentOptions) {
98
+ const wkb = new BinaryWriter(this._getWkbSize());
99
+ wkb.writeInt8(1);
100
+ this._writeWkbType(wkb, Types.wkb.Point, parentOptions);
101
+ if (typeof this.x === "undefined" && typeof this.y === "undefined") {
102
+ wkb.writeDoubleLE(NaN);
103
+ wkb.writeDoubleLE(NaN);
104
+ if (this.hasZ) wkb.writeDoubleLE(NaN);
105
+ if (this.hasM) wkb.writeDoubleLE(NaN);
106
+ } else this._writeWkbPoint(wkb);
107
+ return wkb.buffer;
108
+ }
109
+ _writeWkbPoint(wkb) {
110
+ wkb.writeDoubleLE(this.x);
111
+ wkb.writeDoubleLE(this.y);
112
+ if (this.hasZ) wkb.writeDoubleLE(this.z);
113
+ if (this.hasM) wkb.writeDoubleLE(this.m);
114
+ }
115
+ toTwkb() {
116
+ const twkb = new BinaryWriter(0, true);
117
+ const precision = Geometry.getTwkbPrecision(5, 0, 0);
118
+ const isEmpty = typeof this.x === "undefined" && typeof this.y === "undefined";
119
+ this._writeTwkbHeader(twkb, Types.wkb.Point, precision, isEmpty);
120
+ if (!isEmpty) this._writeTwkbPoint(twkb, precision, new Point(0, 0, 0, 0));
121
+ return twkb.buffer;
122
+ }
123
+ _writeTwkbPoint(twkb, precision, previousPoint) {
124
+ const x = (this.x || 0) * precision.xyFactor;
125
+ const y = (this.y || 0) * precision.xyFactor;
126
+ const z = (this.z || 0) * precision.zFactor;
127
+ const m = (this.m || 0) * precision.mFactor;
128
+ twkb.writeVarInt(ZigZag.encode(x - (previousPoint.x || 0)));
129
+ twkb.writeVarInt(ZigZag.encode(y - (previousPoint.y || 0)));
130
+ if (this.hasZ) twkb.writeVarInt(ZigZag.encode(z - (previousPoint.z || 0)));
131
+ if (this.hasM) twkb.writeVarInt(ZigZag.encode(m - (previousPoint.m || 0)));
132
+ previousPoint.x = x;
133
+ previousPoint.y = y;
134
+ previousPoint.z = z;
135
+ previousPoint.m = m;
136
+ }
137
+ _getWkbSize() {
138
+ let size = 21;
139
+ if (this.hasZ) size += 8;
140
+ if (this.hasM) size += 8;
141
+ return size;
142
+ }
143
+ toGeoJSON(options) {
144
+ const geoJSON = super.toGeoJSON(options);
145
+ geoJSON.type = Types.geoJSON.Point;
146
+ if (typeof this.x === "undefined" && typeof this.y === "undefined") geoJSON.coordinates = [];
147
+ else if (typeof this.z !== "undefined") geoJSON.coordinates = [
148
+ this.x,
149
+ this.y,
150
+ this.z
151
+ ];
152
+ else geoJSON.coordinates = [this.x, this.y];
153
+ return geoJSON;
154
+ }
155
+ };
156
+ }));
157
+ //#endregion
158
+ init_point();
159
+ export { Point, init_point, point_exports };
@@ -0,0 +1,189 @@
1
+ import { BinaryWriter, init_binarywriter } from "./binarywriter.mjs";
2
+ import { Geometry, init_geometry } from "./geometry.mjs";
3
+ import { Types, init_types } from "./types.mjs";
4
+ import { Point, init_point } from "./point.mjs";
5
+ //#region src/wkx/polygon.ts
6
+ init_binarywriter();
7
+ init_geometry();
8
+ init_point();
9
+ init_types();
10
+ var Polygon = class Polygon extends Geometry {
11
+ exteriorRing;
12
+ interiorRings;
13
+ constructor(exteriorRing, interiorRings, srid) {
14
+ super();
15
+ this.exteriorRing = exteriorRing || [];
16
+ this.interiorRings = interiorRings || [];
17
+ this.srid = srid;
18
+ if (this.exteriorRing.length > 0) {
19
+ this.hasZ = this.exteriorRing[0].hasZ;
20
+ this.hasM = this.exteriorRing[0].hasM;
21
+ }
22
+ }
23
+ static Z(exteriorRing, interiorRings, srid) {
24
+ const polygon = new Polygon(exteriorRing, interiorRings, srid);
25
+ polygon.hasZ = true;
26
+ return polygon;
27
+ }
28
+ static M(exteriorRing, interiorRings, srid) {
29
+ const polygon = new Polygon(exteriorRing, interiorRings, srid);
30
+ polygon.hasM = true;
31
+ return polygon;
32
+ }
33
+ static ZM(exteriorRing, interiorRings, srid) {
34
+ const polygon = new Polygon(exteriorRing, interiorRings, srid);
35
+ polygon.hasZ = true;
36
+ polygon.hasM = true;
37
+ return polygon;
38
+ }
39
+ static _parseWkt(value, options) {
40
+ const polygon = new Polygon();
41
+ polygon.srid = options.srid;
42
+ polygon.hasZ = options.hasZ;
43
+ polygon.hasM = options.hasM;
44
+ if (value.isMatch(["EMPTY"])) return polygon;
45
+ value.expectGroupStart();
46
+ value.expectGroupStart();
47
+ polygon.exteriorRing = polygon.exteriorRing.concat(value.matchCoordinates(options));
48
+ value.expectGroupEnd();
49
+ while (value.isMatch([","])) {
50
+ value.expectGroupStart();
51
+ polygon.interiorRings.push(value.matchCoordinates(options));
52
+ value.expectGroupEnd();
53
+ }
54
+ value.expectGroupEnd();
55
+ return polygon;
56
+ }
57
+ static _parseWkb(value, options) {
58
+ const polygon = new Polygon();
59
+ polygon.srid = options.srid;
60
+ polygon.hasZ = options.hasZ || false;
61
+ polygon.hasM = options.hasM || false;
62
+ const ringCount = value.readUInt32();
63
+ if (ringCount > 0) {
64
+ const exteriorRingCount = value.readUInt32();
65
+ for (let i = 0; i < exteriorRingCount; i++) polygon.exteriorRing.push(Point._readWkbPoint(value, options));
66
+ for (let i = 1; i < ringCount; i++) {
67
+ const interiorRing = [];
68
+ const interiorRingCount = value.readUInt32();
69
+ for (let j = 0; j < interiorRingCount; j++) interiorRing.push(Point._readWkbPoint(value, options));
70
+ polygon.interiorRings.push(interiorRing);
71
+ }
72
+ }
73
+ return polygon;
74
+ }
75
+ static _parseTwkb(value, options) {
76
+ const polygon = new Polygon();
77
+ polygon.hasZ = options.hasZ || false;
78
+ polygon.hasM = options.hasM || false;
79
+ if (options.isEmpty) return polygon;
80
+ const previousPoint = new Point(0, 0, options.hasZ ? 0 : void 0, options.hasM ? 0 : void 0);
81
+ const ringCount = value.readVarInt();
82
+ const exteriorRingCount = value.readVarInt();
83
+ for (let i = 0; i < exteriorRingCount; i++) polygon.exteriorRing.push(Point._readTwkbPoint(value, options, previousPoint));
84
+ for (let i = 1; i < ringCount; i++) {
85
+ const interiorRing = [];
86
+ const interiorRingCount = value.readVarInt();
87
+ for (let j = 0; j < interiorRingCount; j++) interiorRing.push(Point._readTwkbPoint(value, options, previousPoint));
88
+ polygon.interiorRings.push(interiorRing);
89
+ }
90
+ return polygon;
91
+ }
92
+ static _parseGeoJSON(value) {
93
+ const polygon = new Polygon();
94
+ if (value.coordinates.length > 0 && value.coordinates[0].length > 0) polygon.hasZ = value.coordinates[0][0].length > 2;
95
+ for (let i = 0; i < value.coordinates.length; i++) {
96
+ if (i > 0) polygon.interiorRings.push([]);
97
+ for (let j = 0; j < value.coordinates[i].length; j++) if (i === 0) polygon.exteriorRing.push(Point._readGeoJSONPoint(value.coordinates[i][j]));
98
+ else polygon.interiorRings[i - 1].push(Point._readGeoJSONPoint(value.coordinates[i][j]));
99
+ }
100
+ return polygon;
101
+ }
102
+ toWkt() {
103
+ if (this.exteriorRing.length === 0) return this._getWktType(Types.wkt.Polygon, true);
104
+ return this._getWktType(Types.wkt.Polygon, false) + this._toInnerWkt();
105
+ }
106
+ _toInnerWkt() {
107
+ let innerWkt = "((";
108
+ for (let i = 0; i < this.exteriorRing.length; i++) innerWkt += this._getWktCoordinate(this.exteriorRing[i]) + ",";
109
+ innerWkt = innerWkt.slice(0, -1);
110
+ innerWkt += ")";
111
+ for (let i = 0; i < this.interiorRings.length; i++) {
112
+ innerWkt += ",(";
113
+ for (let j = 0; j < this.interiorRings[i].length; j++) innerWkt += this._getWktCoordinate(this.interiorRings[i][j]) + ",";
114
+ innerWkt = innerWkt.slice(0, -1);
115
+ innerWkt += ")";
116
+ }
117
+ innerWkt += ")";
118
+ return innerWkt;
119
+ }
120
+ toWkb(parentOptions) {
121
+ const wkb = new BinaryWriter(this._getWkbSize());
122
+ wkb.writeInt8(1);
123
+ this._writeWkbType(wkb, Types.wkb.Polygon, parentOptions);
124
+ if (this.exteriorRing.length > 0) {
125
+ wkb.writeUInt32LE(1 + this.interiorRings.length);
126
+ wkb.writeUInt32LE(this.exteriorRing.length);
127
+ } else wkb.writeUInt32LE(0);
128
+ for (let i = 0; i < this.exteriorRing.length; i++) this.exteriorRing[i]._writeWkbPoint(wkb);
129
+ for (let i = 0; i < this.interiorRings.length; i++) {
130
+ wkb.writeUInt32LE(this.interiorRings[i].length);
131
+ for (let j = 0; j < this.interiorRings[i].length; j++) this.interiorRings[i][j]._writeWkbPoint(wkb);
132
+ }
133
+ return wkb.buffer;
134
+ }
135
+ toTwkb() {
136
+ const twkb = new BinaryWriter(0, true);
137
+ const precision = Geometry.getTwkbPrecision(5, 0, 0);
138
+ const isEmpty = this.exteriorRing.length === 0;
139
+ this._writeTwkbHeader(twkb, Types.wkb.Polygon, precision, isEmpty);
140
+ if (this.exteriorRing.length > 0) {
141
+ twkb.writeVarInt(1 + this.interiorRings.length);
142
+ twkb.writeVarInt(this.exteriorRing.length);
143
+ const previousPoint = new Point(0, 0, 0, 0);
144
+ for (let i = 0; i < this.exteriorRing.length; i++) this.exteriorRing[i]._writeTwkbPoint(twkb, precision, previousPoint);
145
+ for (let i = 0; i < this.interiorRings.length; i++) {
146
+ twkb.writeVarInt(this.interiorRings[i].length);
147
+ for (let j = 0; j < this.interiorRings[i].length; j++) this.interiorRings[i][j]._writeTwkbPoint(twkb, precision, previousPoint);
148
+ }
149
+ }
150
+ return twkb.buffer;
151
+ }
152
+ _getWkbSize() {
153
+ let coordinateSize = 16;
154
+ if (this.hasZ) coordinateSize += 8;
155
+ if (this.hasM) coordinateSize += 8;
156
+ let size = 9;
157
+ if (this.exteriorRing.length > 0) size += 4 + this.exteriorRing.length * coordinateSize;
158
+ for (let i = 0; i < this.interiorRings.length; i++) size += 4 + this.interiorRings[i].length * coordinateSize;
159
+ return size;
160
+ }
161
+ toGeoJSON(options) {
162
+ const geoJSON = super.toGeoJSON(options);
163
+ geoJSON.type = Types.geoJSON.Polygon;
164
+ geoJSON.coordinates = [];
165
+ if (this.exteriorRing.length > 0) {
166
+ const exteriorRing = [];
167
+ for (let i = 0; i < this.exteriorRing.length; i++) if (this.hasZ) exteriorRing.push([
168
+ this.exteriorRing[i].x,
169
+ this.exteriorRing[i].y,
170
+ this.exteriorRing[i].z
171
+ ]);
172
+ else exteriorRing.push([this.exteriorRing[i].x, this.exteriorRing[i].y]);
173
+ geoJSON.coordinates.push(exteriorRing);
174
+ }
175
+ for (let j = 0; j < this.interiorRings.length; j++) {
176
+ const interiorRing = [];
177
+ for (let k = 0; k < this.interiorRings[j].length; k++) if (this.hasZ) interiorRing.push([
178
+ this.interiorRings[j][k].x,
179
+ this.interiorRings[j][k].y,
180
+ this.interiorRings[j][k].z
181
+ ]);
182
+ else interiorRing.push([this.interiorRings[j][k].x, this.interiorRings[j][k].y]);
183
+ geoJSON.coordinates.push(interiorRing);
184
+ }
185
+ return geoJSON;
186
+ }
187
+ };
188
+ //#endregion
189
+ export { Polygon };
@@ -0,0 +1,37 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
+ //#region src/wkx/types.ts
3
+ var Types;
4
+ var init_types = __esmMin((() => {
5
+ Types = {
6
+ wkt: {
7
+ Point: "POINT",
8
+ LineString: "LINESTRING",
9
+ Polygon: "POLYGON",
10
+ MultiPoint: "MULTIPOINT",
11
+ MultiLineString: "MULTILINESTRING",
12
+ MultiPolygon: "MULTIPOLYGON",
13
+ GeometryCollection: "GEOMETRYCOLLECTION"
14
+ },
15
+ wkb: {
16
+ Point: 1,
17
+ LineString: 2,
18
+ Polygon: 3,
19
+ MultiPoint: 4,
20
+ MultiLineString: 5,
21
+ MultiPolygon: 6,
22
+ GeometryCollection: 7
23
+ },
24
+ geoJSON: {
25
+ Point: "Point",
26
+ LineString: "LineString",
27
+ Polygon: "Polygon",
28
+ MultiPoint: "MultiPoint",
29
+ MultiLineString: "MultiLineString",
30
+ MultiPolygon: "MultiPolygon",
31
+ GeometryCollection: "GeometryCollection"
32
+ }
33
+ };
34
+ }));
35
+ //#endregion
36
+ init_types();
37
+ export { Types, init_types };
@@ -0,0 +1,109 @@
1
+ import { __toCommonJS } from "../_virtual/_rolldown/runtime.mjs";
2
+ import { Types, init_types } from "./types.mjs";
3
+ import { init_point, point_exports } from "./point.mjs";
4
+ //#region src/wkx/wktparser.ts
5
+ init_types();
6
+ var WktParser = class {
7
+ value;
8
+ position;
9
+ constructor(value) {
10
+ this.value = value;
11
+ this.position = 0;
12
+ }
13
+ match(tokens) {
14
+ this.skipWhitespaces();
15
+ for (let i = 0; i < tokens.length; i++) if (this.value.substring(this.position).indexOf(tokens[i]) === 0) {
16
+ this.position += tokens[i].length;
17
+ return tokens[i];
18
+ }
19
+ return null;
20
+ }
21
+ matchRegex(tokens) {
22
+ this.skipWhitespaces();
23
+ for (let i = 0; i < tokens.length; i++) {
24
+ const match = this.value.substring(this.position).match(tokens[i]);
25
+ if (match) {
26
+ this.position += match[0].length;
27
+ return match;
28
+ }
29
+ }
30
+ return null;
31
+ }
32
+ isMatch(tokens) {
33
+ this.skipWhitespaces();
34
+ for (let i = 0; i < tokens.length; i++) if (this.value.substring(this.position).indexOf(tokens[i]) === 0) {
35
+ this.position += tokens[i].length;
36
+ return true;
37
+ }
38
+ return false;
39
+ }
40
+ matchType() {
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) throw new Error("Expected geometry type");
51
+ return geometryType;
52
+ }
53
+ matchDimension() {
54
+ switch (this.match([
55
+ "ZM",
56
+ "Z",
57
+ "M"
58
+ ])) {
59
+ case "ZM": return {
60
+ hasZ: true,
61
+ hasM: true
62
+ };
63
+ case "Z": return {
64
+ hasZ: true,
65
+ hasM: false
66
+ };
67
+ case "M": return {
68
+ hasZ: false,
69
+ hasM: true
70
+ };
71
+ default: return {
72
+ hasZ: false,
73
+ hasM: false
74
+ };
75
+ }
76
+ }
77
+ expectGroupStart() {
78
+ if (!this.isMatch(["("])) throw new Error("Expected group start");
79
+ }
80
+ expectGroupEnd() {
81
+ if (!this.isMatch([")"])) throw new Error("Expected group end");
82
+ }
83
+ matchCoordinate(options) {
84
+ const { Point } = (init_point(), __toCommonJS(point_exports));
85
+ let match;
86
+ if (options.hasZ && options.hasM) match = this.matchRegex([/^(\S*)\s+(\S*)\s+(\S*)\s+([^\s,)]*)/]);
87
+ else if (options.hasZ || options.hasM) match = this.matchRegex([/^(\S*)\s+(\S*)\s+([^\s,)]*)/]);
88
+ else match = this.matchRegex([/^(\S*)\s+([^\s,)]*)/]);
89
+ if (!match) throw new Error("Expected coordinates");
90
+ if (options.hasZ && options.hasM) return new Point(parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]), parseFloat(match[4]));
91
+ else if (options.hasZ) return new Point(parseFloat(match[1]), parseFloat(match[2]), parseFloat(match[3]));
92
+ else if (options.hasM) return new Point(parseFloat(match[1]), parseFloat(match[2]), void 0, parseFloat(match[3]));
93
+ else return new Point(parseFloat(match[1]), parseFloat(match[2]));
94
+ }
95
+ matchCoordinates(options) {
96
+ const coordinates = [];
97
+ do {
98
+ const startsWithBracket = this.isMatch(["("]);
99
+ coordinates.push(this.matchCoordinate(options));
100
+ if (startsWithBracket) this.expectGroupEnd();
101
+ } while (this.isMatch([","]));
102
+ return coordinates;
103
+ }
104
+ skipWhitespaces() {
105
+ while (this.position < this.value.length && this.value[this.position] === " ") this.position++;
106
+ }
107
+ };
108
+ //#endregion
109
+ export { WktParser };
@@ -0,0 +1,18 @@
1
+ import { __esmMin } from "../_virtual/_rolldown/runtime.mjs";
2
+ //#region src/wkx/zigzag.ts
3
+ function encode(value) {
4
+ return value << 1 ^ value >> 31;
5
+ }
6
+ function decode(value) {
7
+ return value >> 1 ^ -(value & 1);
8
+ }
9
+ var ZigZag;
10
+ var init_zigzag = __esmMin((() => {
11
+ ZigZag = {
12
+ encode,
13
+ decode
14
+ };
15
+ }));
16
+ //#endregion
17
+ init_zigzag();
18
+ export { ZigZag, init_zigzag };