@prisma-next/extension-postgis 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +283 -0
- package/dist/codec-types-DODPC0GY.d.mts +59 -0
- package/dist/codec-types-DODPC0GY.d.mts.map +1 -0
- package/dist/codec-types.d.mts +2 -0
- package/dist/codec-types.mjs +1 -0
- package/dist/column-types.d.mts +26 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +28 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/constants-dLvIWSgv.mjs +6 -0
- package/dist/constants-dLvIWSgv.mjs.map +1 -0
- package/dist/control.d.mts +7 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +189 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-DUKzIH9c.mjs +516 -0
- package/dist/descriptor-meta-DUKzIH9c.mjs.map +1 -0
- package/dist/geojson-Cj4ldHQ0.d.mts +61 -0
- package/dist/geojson-Cj4ldHQ0.d.mts.map +1 -0
- package/dist/geojson.d.mts +2 -0
- package/dist/geojson.mjs +60 -0
- package/dist/geojson.mjs.map +1 -0
- package/dist/operation-types-C2s9tY0P.d.mts +123 -0
- package/dist/operation-types-C2s9tY0P.d.mts.map +1 -0
- package/dist/operation-types.d.mts +2 -0
- package/dist/operation-types.mjs +1 -0
- package/dist/pack.d.mts +75 -0
- package/dist/pack.d.mts.map +1 -0
- package/dist/pack.mjs +2 -0
- package/dist/runtime.d.mts +19 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +22 -0
- package/dist/runtime.mjs.map +1 -0
- package/package.json +64 -0
- package/src/contract.d.ts +91 -0
- package/src/contract.json +40 -0
- package/src/contract.ts +61 -0
- package/src/core/authoring.ts +18 -0
- package/src/core/codecs.ts +193 -0
- package/src/core/constants.ts +3 -0
- package/src/core/contract-space-constants.ts +30 -0
- package/src/core/descriptor-meta.ts +186 -0
- package/src/core/ewkb.ts +284 -0
- package/src/core/geojson.ts +131 -0
- package/src/core/registry.ts +14 -0
- package/src/exports/codec-types.ts +7 -0
- package/src/exports/column-types.ts +38 -0
- package/src/exports/control.ts +101 -0
- package/src/exports/geojson.ts +19 -0
- package/src/exports/operation-types.ts +7 -0
- package/src/exports/pack.ts +1 -0
- package/src/exports/runtime.ts +34 -0
- package/src/types/codec-types.ts +16 -0
- package/src/types/operation-types.ts +81 -0
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { t as POSTGIS_GEOMETRY_CODEC_ID } from "./constants-dLvIWSgv.mjs";
|
|
2
|
+
import { buildOperation, codecOf, toExpr } from "@prisma-next/sql-relational-core/expression";
|
|
3
|
+
import { buildCodecDescriptorRegistry } from "@prisma-next/sql-relational-core/codec-descriptor-registry";
|
|
4
|
+
import { CodecDescriptorImpl, CodecImpl } from "@prisma-next/framework-components/codec";
|
|
5
|
+
import { type } from "arktype";
|
|
6
|
+
//#region src/core/authoring.ts
|
|
7
|
+
const postgisAuthoringTypes = { postgis: { Geometry: {
|
|
8
|
+
kind: "typeConstructor",
|
|
9
|
+
args: [{
|
|
10
|
+
kind: "number",
|
|
11
|
+
name: "srid",
|
|
12
|
+
integer: true,
|
|
13
|
+
minimum: 0
|
|
14
|
+
}],
|
|
15
|
+
output: {
|
|
16
|
+
codecId: POSTGIS_GEOMETRY_CODEC_ID,
|
|
17
|
+
nativeType: "geometry",
|
|
18
|
+
typeParams: { srid: {
|
|
19
|
+
kind: "arg",
|
|
20
|
+
index: 0
|
|
21
|
+
} }
|
|
22
|
+
}
|
|
23
|
+
} } };
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/core/ewkb.ts
|
|
26
|
+
const FLAG_Z = 2147483648;
|
|
27
|
+
const FLAG_M = 1073741824;
|
|
28
|
+
const FLAG_SRID = 536870912;
|
|
29
|
+
const TYPE_MASK = 536870911;
|
|
30
|
+
const TYPE_POINT = 1;
|
|
31
|
+
const TYPE_LINESTRING = 2;
|
|
32
|
+
const TYPE_POLYGON = 3;
|
|
33
|
+
const TYPE_MULTIPOINT = 4;
|
|
34
|
+
const TYPE_MULTILINESTRING = 5;
|
|
35
|
+
const TYPE_MULTIPOLYGON = 6;
|
|
36
|
+
const HEX_PAIR_RE = /^[0-9a-fA-F]{2}$/;
|
|
37
|
+
function hexToBytes(hex) {
|
|
38
|
+
if (hex.length % 2 !== 0) throw new Error("Geometry wire value: odd-length hex string");
|
|
39
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
40
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
41
|
+
const pair = hex.slice(i * 2, i * 2 + 2);
|
|
42
|
+
if (!HEX_PAIR_RE.test(pair)) throw new Error(`Geometry wire value: invalid hex byte at offset ${i * 2}`);
|
|
43
|
+
bytes[i] = Number.parseInt(pair, 16);
|
|
44
|
+
}
|
|
45
|
+
return bytes;
|
|
46
|
+
}
|
|
47
|
+
var Reader = class {
|
|
48
|
+
offset = 0;
|
|
49
|
+
view;
|
|
50
|
+
constructor(bytes) {
|
|
51
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
52
|
+
}
|
|
53
|
+
requireBytes(needed) {
|
|
54
|
+
if (this.offset + needed > this.view.byteLength) throw new Error(`Geometry wire value: unexpected end of buffer (need ${needed} bytes at offset ${this.offset}, ${this.view.byteLength - this.offset} available)`);
|
|
55
|
+
}
|
|
56
|
+
readUint8() {
|
|
57
|
+
this.requireBytes(1);
|
|
58
|
+
const v = this.view.getUint8(this.offset);
|
|
59
|
+
this.offset += 1;
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
readUint32(littleEndian) {
|
|
63
|
+
this.requireBytes(4);
|
|
64
|
+
const v = this.view.getUint32(this.offset, littleEndian);
|
|
65
|
+
this.offset += 4;
|
|
66
|
+
return v >>> 0;
|
|
67
|
+
}
|
|
68
|
+
readFloat64(littleEndian) {
|
|
69
|
+
this.requireBytes(8);
|
|
70
|
+
const v = this.view.getFloat64(this.offset, littleEndian);
|
|
71
|
+
this.offset += 8;
|
|
72
|
+
return v;
|
|
73
|
+
}
|
|
74
|
+
hasRemaining() {
|
|
75
|
+
return this.offset !== this.view.byteLength;
|
|
76
|
+
}
|
|
77
|
+
remainingBytes() {
|
|
78
|
+
return this.view.byteLength - this.offset;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function readHeader(reader) {
|
|
82
|
+
const byteOrder = reader.readUint8();
|
|
83
|
+
if (byteOrder !== 0 && byteOrder !== 1) throw new Error(`Geometry wire value: invalid byte order ${byteOrder}`);
|
|
84
|
+
const littleEndian = byteOrder === 1;
|
|
85
|
+
const typeCode = reader.readUint32(littleEndian);
|
|
86
|
+
if ((typeCode & FLAG_Z) !== 0 || (typeCode & FLAG_M) !== 0) throw new Error("Geometry wire value: Z/M coordinates are not supported");
|
|
87
|
+
const geomType = typeCode & TYPE_MASK;
|
|
88
|
+
if ((typeCode & FLAG_SRID) !== 0) return {
|
|
89
|
+
geomType,
|
|
90
|
+
littleEndian,
|
|
91
|
+
srid: reader.readUint32(littleEndian)
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
geomType,
|
|
95
|
+
littleEndian
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function readPosition(reader, littleEndian) {
|
|
99
|
+
return [reader.readFloat64(littleEndian), reader.readFloat64(littleEndian)];
|
|
100
|
+
}
|
|
101
|
+
function readPoint(reader, header) {
|
|
102
|
+
const coords = readPosition(reader, header.littleEndian);
|
|
103
|
+
return header.srid !== void 0 ? {
|
|
104
|
+
type: "Point",
|
|
105
|
+
coordinates: coords,
|
|
106
|
+
srid: header.srid
|
|
107
|
+
} : {
|
|
108
|
+
type: "Point",
|
|
109
|
+
coordinates: coords
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function readLineString(reader, header) {
|
|
113
|
+
const n = reader.readUint32(header.littleEndian);
|
|
114
|
+
const coords = [];
|
|
115
|
+
for (let i = 0; i < n; i++) coords.push(readPosition(reader, header.littleEndian));
|
|
116
|
+
return header.srid !== void 0 ? {
|
|
117
|
+
type: "LineString",
|
|
118
|
+
coordinates: coords,
|
|
119
|
+
srid: header.srid
|
|
120
|
+
} : {
|
|
121
|
+
type: "LineString",
|
|
122
|
+
coordinates: coords
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function readPolygon(reader, header) {
|
|
126
|
+
const numRings = reader.readUint32(header.littleEndian);
|
|
127
|
+
const rings = [];
|
|
128
|
+
for (let r = 0; r < numRings; r++) {
|
|
129
|
+
const n = reader.readUint32(header.littleEndian);
|
|
130
|
+
const ring = [];
|
|
131
|
+
for (let i = 0; i < n; i++) ring.push(readPosition(reader, header.littleEndian));
|
|
132
|
+
rings.push(ring);
|
|
133
|
+
}
|
|
134
|
+
return header.srid !== void 0 ? {
|
|
135
|
+
type: "Polygon",
|
|
136
|
+
coordinates: rings,
|
|
137
|
+
srid: header.srid
|
|
138
|
+
} : {
|
|
139
|
+
type: "Polygon",
|
|
140
|
+
coordinates: rings
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function readSubGeometry(reader) {
|
|
144
|
+
const header = readHeader(reader);
|
|
145
|
+
switch (header.geomType) {
|
|
146
|
+
case TYPE_POINT: return readPoint(reader, header);
|
|
147
|
+
case TYPE_LINESTRING: return readLineString(reader, header);
|
|
148
|
+
case TYPE_POLYGON: return readPolygon(reader, header);
|
|
149
|
+
default: throw new Error(`Geometry wire value: unsupported sub-type ${header.geomType}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function readMultiPoint(reader, header) {
|
|
153
|
+
const n = reader.readUint32(header.littleEndian);
|
|
154
|
+
const coords = [];
|
|
155
|
+
for (let i = 0; i < n; i++) {
|
|
156
|
+
const sub = readSubGeometry(reader);
|
|
157
|
+
if (sub.type !== "Point") throw new Error("Geometry wire value: MultiPoint contains non-Point sub-geometry");
|
|
158
|
+
coords.push(sub.coordinates);
|
|
159
|
+
}
|
|
160
|
+
return header.srid !== void 0 ? {
|
|
161
|
+
type: "MultiPoint",
|
|
162
|
+
coordinates: coords,
|
|
163
|
+
srid: header.srid
|
|
164
|
+
} : {
|
|
165
|
+
type: "MultiPoint",
|
|
166
|
+
coordinates: coords
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function readMultiLineString(reader, header) {
|
|
170
|
+
const n = reader.readUint32(header.littleEndian);
|
|
171
|
+
const lines = [];
|
|
172
|
+
for (let i = 0; i < n; i++) {
|
|
173
|
+
const sub = readSubGeometry(reader);
|
|
174
|
+
if (sub.type !== "LineString") throw new Error("Geometry wire value: MultiLineString contains non-LineString sub-geometry");
|
|
175
|
+
lines.push(sub.coordinates);
|
|
176
|
+
}
|
|
177
|
+
return header.srid !== void 0 ? {
|
|
178
|
+
type: "MultiLineString",
|
|
179
|
+
coordinates: lines,
|
|
180
|
+
srid: header.srid
|
|
181
|
+
} : {
|
|
182
|
+
type: "MultiLineString",
|
|
183
|
+
coordinates: lines
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function readMultiPolygon(reader, header) {
|
|
187
|
+
const n = reader.readUint32(header.littleEndian);
|
|
188
|
+
const polys = [];
|
|
189
|
+
for (let i = 0; i < n; i++) {
|
|
190
|
+
const sub = readSubGeometry(reader);
|
|
191
|
+
if (sub.type !== "Polygon") throw new Error("Geometry wire value: MultiPolygon contains non-Polygon sub-geometry");
|
|
192
|
+
polys.push(sub.coordinates);
|
|
193
|
+
}
|
|
194
|
+
return header.srid !== void 0 ? {
|
|
195
|
+
type: "MultiPolygon",
|
|
196
|
+
coordinates: polys,
|
|
197
|
+
srid: header.srid
|
|
198
|
+
} : {
|
|
199
|
+
type: "MultiPolygon",
|
|
200
|
+
coordinates: polys
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function decodeEWKBHex(hex) {
|
|
204
|
+
const reader = new Reader(hexToBytes(hex));
|
|
205
|
+
const geometry = readGeometryBody(reader, readHeader(reader));
|
|
206
|
+
if (reader.hasRemaining()) throw new Error(`Geometry wire value: trailing data after geometry (${reader.remainingBytes()} bytes)`);
|
|
207
|
+
return geometry;
|
|
208
|
+
}
|
|
209
|
+
function readGeometryBody(reader, header) {
|
|
210
|
+
switch (header.geomType) {
|
|
211
|
+
case TYPE_POINT: return readPoint(reader, header);
|
|
212
|
+
case TYPE_LINESTRING: return readLineString(reader, header);
|
|
213
|
+
case TYPE_POLYGON: return readPolygon(reader, header);
|
|
214
|
+
case TYPE_MULTIPOINT: return readMultiPoint(reader, header);
|
|
215
|
+
case TYPE_MULTILINESTRING: return readMultiLineString(reader, header);
|
|
216
|
+
case TYPE_MULTIPOLYGON: return readMultiPolygon(reader, header);
|
|
217
|
+
default: throw new Error(`Geometry wire value: unsupported geometry type ${header.geomType}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Encode a GeoJSON-shaped geometry to an EWKT string PostGIS understands
|
|
222
|
+
* via `'<ewkt>'::geometry`. We use EWKT (not EWKB) on the way in so the
|
|
223
|
+
* generated SQL stays human-readable.
|
|
224
|
+
*/
|
|
225
|
+
function encodeEWKT(value) {
|
|
226
|
+
const sridPrefix = value.srid !== void 0 ? `SRID=${value.srid};` : "";
|
|
227
|
+
switch (value.type) {
|
|
228
|
+
case "Point": return `${sridPrefix}POINT(${formatPosition(value.coordinates)})`;
|
|
229
|
+
case "LineString": return `${sridPrefix}LINESTRING(${value.coordinates.map(formatPosition).join(",")})`;
|
|
230
|
+
case "Polygon": return `${sridPrefix}POLYGON(${formatRings(value.coordinates)})`;
|
|
231
|
+
case "MultiPoint": return `${sridPrefix}MULTIPOINT(${value.coordinates.map(formatPosition).join(",")})`;
|
|
232
|
+
case "MultiLineString": return `${sridPrefix}MULTILINESTRING(${value.coordinates.map((line) => `(${line.map(formatPosition).join(",")})`).join(",")})`;
|
|
233
|
+
case "MultiPolygon": return `${sridPrefix}MULTIPOLYGON(${value.coordinates.map((poly) => `(${formatRings(poly)})`).join(",")})`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function formatPosition(p) {
|
|
237
|
+
if (!Number.isFinite(p[0]) || !Number.isFinite(p[1])) throw new Error("Geometry encode: coordinates must be finite numbers");
|
|
238
|
+
return `${p[0]} ${p[1]}`;
|
|
239
|
+
}
|
|
240
|
+
function formatRings(rings) {
|
|
241
|
+
return rings.map((ring) => `(${ring.map(formatPosition).join(",")})`).join(",");
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/core/codecs.ts
|
|
245
|
+
const geometryParamsSchema = type({ srid: "number" }).narrow((params, ctx) => {
|
|
246
|
+
const { srid } = params;
|
|
247
|
+
if (!Number.isInteger(srid)) return ctx.mustBe("an integer");
|
|
248
|
+
if (srid < 0) return ctx.mustBe("a non-negative integer");
|
|
249
|
+
return true;
|
|
250
|
+
});
|
|
251
|
+
const POSTGIS_GEOMETRY_META = { db: { sql: { postgres: { nativeType: "geometry" } } } };
|
|
252
|
+
const allowedGeometryTypes = new Set([
|
|
253
|
+
"Point",
|
|
254
|
+
"LineString",
|
|
255
|
+
"Polygon",
|
|
256
|
+
"MultiPoint",
|
|
257
|
+
"MultiLineString",
|
|
258
|
+
"MultiPolygon"
|
|
259
|
+
]);
|
|
260
|
+
function assertGeometry(value) {
|
|
261
|
+
if (!value || typeof value !== "object") throw new Error("Geometry value must be a GeoJSON-shaped object");
|
|
262
|
+
const type = value.type;
|
|
263
|
+
if (typeof type !== "string" || !allowedGeometryTypes.has(type)) throw new Error(`Geometry value: unsupported type "${String(type)}" (expected Point, LineString, Polygon, MultiPoint, MultiLineString, or MultiPolygon)`);
|
|
264
|
+
if (!Array.isArray(value.coordinates)) throw new Error("Geometry value: \"coordinates\" must be an array");
|
|
265
|
+
}
|
|
266
|
+
var PostgisGeometryCodec = class extends CodecImpl {
|
|
267
|
+
constructor(descriptor) {
|
|
268
|
+
super(descriptor);
|
|
269
|
+
}
|
|
270
|
+
async encode(value, _ctx) {
|
|
271
|
+
assertGeometry(value);
|
|
272
|
+
return encodeEWKT(value);
|
|
273
|
+
}
|
|
274
|
+
async decode(wire, _ctx) {
|
|
275
|
+
if (typeof wire !== "string") throw new Error("Geometry wire value must be a string");
|
|
276
|
+
return decodeEWKBHex(wire);
|
|
277
|
+
}
|
|
278
|
+
encodeJson(value) {
|
|
279
|
+
assertGeometry(value);
|
|
280
|
+
return value;
|
|
281
|
+
}
|
|
282
|
+
decodeJson(json) {
|
|
283
|
+
assertGeometry(json);
|
|
284
|
+
return json;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var PostgisGeometryDescriptor = class extends CodecDescriptorImpl {
|
|
288
|
+
codecId = POSTGIS_GEOMETRY_CODEC_ID;
|
|
289
|
+
traits = ["equality"];
|
|
290
|
+
targetTypes = ["geometry"];
|
|
291
|
+
meta = POSTGIS_GEOMETRY_META;
|
|
292
|
+
paramsSchema = geometryParamsSchema;
|
|
293
|
+
renderOutputType(params) {
|
|
294
|
+
const srid = params?.srid;
|
|
295
|
+
if (srid === void 0) return "Geometry";
|
|
296
|
+
return `Geometry<${srid}>`;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The runtime calls `factory(undefined)(ctx)` to materialize a
|
|
300
|
+
* representative codec for parameterised descriptors that ship a
|
|
301
|
+
* no-params column variant (here, `geometryColumn` vs `geometry({ srid })`).
|
|
302
|
+
* The runtime cast widens `params` to `unknown`, so guarding with an
|
|
303
|
+
* optional read keeps the typed call site (`factory({ srid })`)
|
|
304
|
+
* strict while still producing an SRID-agnostic codec for
|
|
305
|
+
* representative use. Encode/decode for an unparameterised column
|
|
306
|
+
* runs through this representative; the wire format already carries
|
|
307
|
+
* SRID inside the EWKT/EWKB payload, so it's dimension-independent.
|
|
308
|
+
*/
|
|
309
|
+
factory(_params) {
|
|
310
|
+
return () => new PostgisGeometryCodec(this);
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
const codecDescriptorMap = { geometry: new PostgisGeometryDescriptor() };
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/core/registry.ts
|
|
316
|
+
/**
|
|
317
|
+
* Registry of every codec descriptor shipped by `@prisma-next/extension-postgis`.
|
|
318
|
+
*
|
|
319
|
+
* Public consumer surface for the postgis codec set. Currently a single
|
|
320
|
+
* entry (`pg/geometry@1`); the registry shape stays consistent with
|
|
321
|
+
* the other codec-shipping packages so consumers don't need to
|
|
322
|
+
* special-case extensions.
|
|
323
|
+
*/
|
|
324
|
+
const postgisCodecRegistry = buildCodecDescriptorRegistry(Object.values(codecDescriptorMap));
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/core/descriptor-meta.ts
|
|
327
|
+
const postgisTypeId = "pg/geometry@1";
|
|
328
|
+
/**
|
|
329
|
+
* Build the PostGIS query operations exposed on `geometry` columns.
|
|
330
|
+
*
|
|
331
|
+
* Each operation lowers to a function-template that the SQL renderer
|
|
332
|
+
* stitches into the surrounding statement (`{{self}}` is the receiver,
|
|
333
|
+
* `{{argN}}` are the call arguments). All templates rely on the implicit
|
|
334
|
+
* `geometry`/`float8`/`bool` casts already wired up by the SQL family —
|
|
335
|
+
* we only add the PostGIS-specific function names.
|
|
336
|
+
*/
|
|
337
|
+
function postgisQueryOperations() {
|
|
338
|
+
return {
|
|
339
|
+
distance: {
|
|
340
|
+
self: { codecId: postgisTypeId },
|
|
341
|
+
impl: (self, other) => {
|
|
342
|
+
const selfCodec = codecOf(self);
|
|
343
|
+
return buildOperation({
|
|
344
|
+
method: "distance",
|
|
345
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
346
|
+
returns: {
|
|
347
|
+
codecId: "pg/float8@1",
|
|
348
|
+
nullable: false
|
|
349
|
+
},
|
|
350
|
+
lowering: {
|
|
351
|
+
targetFamily: "sql",
|
|
352
|
+
strategy: "function",
|
|
353
|
+
template: "ST_Distance({{self}}, {{arg0}})"
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
distanceSphere: {
|
|
359
|
+
self: { codecId: postgisTypeId },
|
|
360
|
+
impl: (self, other) => {
|
|
361
|
+
const selfCodec = codecOf(self);
|
|
362
|
+
return buildOperation({
|
|
363
|
+
method: "distanceSphere",
|
|
364
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
365
|
+
returns: {
|
|
366
|
+
codecId: "pg/float8@1",
|
|
367
|
+
nullable: false
|
|
368
|
+
},
|
|
369
|
+
lowering: {
|
|
370
|
+
targetFamily: "sql",
|
|
371
|
+
strategy: "function",
|
|
372
|
+
template: "ST_DistanceSphere({{self}}, {{arg0}})"
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
},
|
|
377
|
+
dwithin: {
|
|
378
|
+
self: { codecId: postgisTypeId },
|
|
379
|
+
impl: (self, other, distance) => {
|
|
380
|
+
const selfCodec = codecOf(self);
|
|
381
|
+
return buildOperation({
|
|
382
|
+
method: "dwithin",
|
|
383
|
+
args: [
|
|
384
|
+
toExpr(self, selfCodec),
|
|
385
|
+
toExpr(other, selfCodec),
|
|
386
|
+
toExpr(distance, { codecId: "pg/float8@1" })
|
|
387
|
+
],
|
|
388
|
+
returns: {
|
|
389
|
+
codecId: "pg/bool@1",
|
|
390
|
+
nullable: false
|
|
391
|
+
},
|
|
392
|
+
lowering: {
|
|
393
|
+
targetFamily: "sql",
|
|
394
|
+
strategy: "function",
|
|
395
|
+
template: "ST_DWithin({{self}}, {{arg0}}, {{arg1}})"
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
contains: {
|
|
401
|
+
self: { codecId: postgisTypeId },
|
|
402
|
+
impl: (self, other) => {
|
|
403
|
+
const selfCodec = codecOf(self);
|
|
404
|
+
return buildOperation({
|
|
405
|
+
method: "contains",
|
|
406
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
407
|
+
returns: {
|
|
408
|
+
codecId: "pg/bool@1",
|
|
409
|
+
nullable: false
|
|
410
|
+
},
|
|
411
|
+
lowering: {
|
|
412
|
+
targetFamily: "sql",
|
|
413
|
+
strategy: "function",
|
|
414
|
+
template: "ST_Contains({{self}}, {{arg0}})"
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
within: {
|
|
420
|
+
self: { codecId: postgisTypeId },
|
|
421
|
+
impl: (self, other) => {
|
|
422
|
+
const selfCodec = codecOf(self);
|
|
423
|
+
return buildOperation({
|
|
424
|
+
method: "within",
|
|
425
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
426
|
+
returns: {
|
|
427
|
+
codecId: "pg/bool@1",
|
|
428
|
+
nullable: false
|
|
429
|
+
},
|
|
430
|
+
lowering: {
|
|
431
|
+
targetFamily: "sql",
|
|
432
|
+
strategy: "function",
|
|
433
|
+
template: "ST_Within({{self}}, {{arg0}})"
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
intersects: {
|
|
439
|
+
self: { codecId: postgisTypeId },
|
|
440
|
+
impl: (self, other) => {
|
|
441
|
+
const selfCodec = codecOf(self);
|
|
442
|
+
return buildOperation({
|
|
443
|
+
method: "intersects",
|
|
444
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
445
|
+
returns: {
|
|
446
|
+
codecId: "pg/bool@1",
|
|
447
|
+
nullable: false
|
|
448
|
+
},
|
|
449
|
+
lowering: {
|
|
450
|
+
targetFamily: "sql",
|
|
451
|
+
strategy: "function",
|
|
452
|
+
template: "ST_Intersects({{self}}, {{arg0}})"
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
intersectsBbox: {
|
|
458
|
+
self: { codecId: postgisTypeId },
|
|
459
|
+
impl: (self, other) => {
|
|
460
|
+
const selfCodec = codecOf(self);
|
|
461
|
+
return buildOperation({
|
|
462
|
+
method: "intersectsBbox",
|
|
463
|
+
args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],
|
|
464
|
+
returns: {
|
|
465
|
+
codecId: "pg/bool@1",
|
|
466
|
+
nullable: false
|
|
467
|
+
},
|
|
468
|
+
lowering: {
|
|
469
|
+
targetFamily: "sql",
|
|
470
|
+
strategy: "function",
|
|
471
|
+
template: "({{self}} && {{arg0}})"
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
const postgisPackMeta = {
|
|
479
|
+
kind: "extension",
|
|
480
|
+
id: "postgis",
|
|
481
|
+
familyId: "sql",
|
|
482
|
+
targetId: "postgres",
|
|
483
|
+
version: "0.0.1",
|
|
484
|
+
capabilities: { postgres: { "postgis.geometry": true } },
|
|
485
|
+
authoring: { type: postgisAuthoringTypes },
|
|
486
|
+
types: {
|
|
487
|
+
codecTypes: {
|
|
488
|
+
codecDescriptors: Array.from(postgisCodecRegistry.values()),
|
|
489
|
+
import: {
|
|
490
|
+
package: "@prisma-next/extension-postgis/codec-types",
|
|
491
|
+
named: "CodecTypes",
|
|
492
|
+
alias: "PostgisTypes"
|
|
493
|
+
},
|
|
494
|
+
typeImports: [{
|
|
495
|
+
package: "@prisma-next/extension-postgis/codec-types",
|
|
496
|
+
named: "Geometry",
|
|
497
|
+
alias: "Geometry"
|
|
498
|
+
}]
|
|
499
|
+
},
|
|
500
|
+
queryOperationTypes: { import: {
|
|
501
|
+
package: "@prisma-next/extension-postgis/operation-types",
|
|
502
|
+
named: "QueryOperationTypes",
|
|
503
|
+
alias: "PostgisQueryOperationTypes"
|
|
504
|
+
} },
|
|
505
|
+
storage: [{
|
|
506
|
+
typeId: postgisTypeId,
|
|
507
|
+
familyId: "sql",
|
|
508
|
+
targetId: "postgres",
|
|
509
|
+
nativeType: "geometry"
|
|
510
|
+
}]
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
//#endregion
|
|
514
|
+
export { postgisQueryOperations as n, postgisCodecRegistry as r, postgisPackMeta as t };
|
|
515
|
+
|
|
516
|
+
//# sourceMappingURL=descriptor-meta-DUKzIH9c.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"descriptor-meta-DUKzIH9c.mjs","names":["arktype"],"sources":["../src/core/authoring.ts","../src/core/ewkb.ts","../src/core/codecs.ts","../src/core/registry.ts","../src/core/descriptor-meta.ts"],"sourcesContent":["import type { AuthoringTypeNamespace } from '@prisma-next/framework-components/authoring';\nimport { POSTGIS_GEOMETRY_CODEC_ID } from './constants';\n\nexport const postgisAuthoringTypes = {\n postgis: {\n Geometry: {\n kind: 'typeConstructor',\n args: [{ kind: 'number', name: 'srid', integer: true, minimum: 0 }],\n output: {\n codecId: POSTGIS_GEOMETRY_CODEC_ID,\n nativeType: 'geometry',\n typeParams: {\n srid: { kind: 'arg', index: 0 },\n },\n },\n },\n },\n} as const satisfies AuthoringTypeNamespace;\n","/**\n * Minimal EWKB (Extended Well-Known Binary) reader for the PostGIS codec.\n *\n * `node-postgres` returns geometry columns as hex-encoded EWKB strings by\n * default. This reader parses the subset we ship with the extension —\n * Point, LineString, Polygon, and the Multi* counterparts — into GeoJSON\n * objects. Z and M coordinates are not supported; if a wire value carries\n * them, decoding throws so the caller can detect the mismatch instead of\n * silently dropping data.\n */\n\nimport type {\n Geometry,\n GeometryLineString,\n GeometryMultiLineString,\n GeometryMultiPoint,\n GeometryMultiPolygon,\n GeometryPoint,\n GeometryPolygon,\n Position,\n} from './geojson';\n\nconst FLAG_Z = 0x80000000;\nconst FLAG_M = 0x40000000;\nconst FLAG_SRID = 0x20000000;\nconst TYPE_MASK = 0x1fffffff;\n\nconst TYPE_POINT = 1;\nconst TYPE_LINESTRING = 2;\nconst TYPE_POLYGON = 3;\nconst TYPE_MULTIPOINT = 4;\nconst TYPE_MULTILINESTRING = 5;\nconst TYPE_MULTIPOLYGON = 6;\n\nconst HEX_PAIR_RE = /^[0-9a-fA-F]{2}$/;\n\nfunction hexToBytes(hex: string): Uint8Array {\n if (hex.length % 2 !== 0) {\n throw new Error('Geometry wire value: odd-length hex string');\n }\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < bytes.length; i++) {\n const pair = hex.slice(i * 2, i * 2 + 2);\n if (!HEX_PAIR_RE.test(pair)) {\n throw new Error(`Geometry wire value: invalid hex byte at offset ${i * 2}`);\n }\n bytes[i] = Number.parseInt(pair, 16);\n }\n return bytes;\n}\n\nclass Reader {\n private offset = 0;\n private readonly view: DataView;\n\n constructor(bytes: Uint8Array) {\n this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n }\n\n private requireBytes(needed: number): void {\n if (this.offset + needed > this.view.byteLength) {\n throw new Error(\n `Geometry wire value: unexpected end of buffer (need ${needed} bytes at offset ${this.offset}, ${this.view.byteLength - this.offset} available)`,\n );\n }\n }\n\n readUint8(): number {\n this.requireBytes(1);\n const v = this.view.getUint8(this.offset);\n this.offset += 1;\n return v;\n }\n\n readUint32(littleEndian: boolean): number {\n this.requireBytes(4);\n const v = this.view.getUint32(this.offset, littleEndian);\n this.offset += 4;\n return v >>> 0;\n }\n\n readFloat64(littleEndian: boolean): number {\n this.requireBytes(8);\n const v = this.view.getFloat64(this.offset, littleEndian);\n this.offset += 8;\n return v;\n }\n\n hasRemaining(): boolean {\n return this.offset !== this.view.byteLength;\n }\n\n remainingBytes(): number {\n return this.view.byteLength - this.offset;\n }\n}\n\ntype Header = {\n readonly geomType: number;\n readonly littleEndian: boolean;\n readonly srid?: number;\n};\n\nfunction readHeader(reader: Reader): Header {\n const byteOrder = reader.readUint8();\n if (byteOrder !== 0 && byteOrder !== 1) {\n throw new Error(`Geometry wire value: invalid byte order ${byteOrder}`);\n }\n const littleEndian = byteOrder === 1;\n const typeCode = reader.readUint32(littleEndian);\n if ((typeCode & FLAG_Z) !== 0 || (typeCode & FLAG_M) !== 0) {\n throw new Error('Geometry wire value: Z/M coordinates are not supported');\n }\n const geomType = typeCode & TYPE_MASK;\n if ((typeCode & FLAG_SRID) !== 0) {\n return { geomType, littleEndian, srid: reader.readUint32(littleEndian) };\n }\n return { geomType, littleEndian };\n}\n\nfunction readPosition(reader: Reader, littleEndian: boolean): Position {\n const x = reader.readFloat64(littleEndian);\n const y = reader.readFloat64(littleEndian);\n return [x, y];\n}\n\nfunction readPoint(reader: Reader, header: Header): GeometryPoint {\n const coords = readPosition(reader, header.littleEndian);\n return header.srid !== undefined\n ? { type: 'Point', coordinates: coords, srid: header.srid }\n : { type: 'Point', coordinates: coords };\n}\n\nfunction readLineString(reader: Reader, header: Header): GeometryLineString {\n const n = reader.readUint32(header.littleEndian);\n const coords: Position[] = [];\n for (let i = 0; i < n; i++) coords.push(readPosition(reader, header.littleEndian));\n return header.srid !== undefined\n ? { type: 'LineString', coordinates: coords, srid: header.srid }\n : { type: 'LineString', coordinates: coords };\n}\n\nfunction readPolygon(reader: Reader, header: Header): GeometryPolygon {\n const numRings = reader.readUint32(header.littleEndian);\n const rings: Position[][] = [];\n for (let r = 0; r < numRings; r++) {\n const n = reader.readUint32(header.littleEndian);\n const ring: Position[] = [];\n for (let i = 0; i < n; i++) ring.push(readPosition(reader, header.littleEndian));\n rings.push(ring);\n }\n return header.srid !== undefined\n ? { type: 'Polygon', coordinates: rings, srid: header.srid }\n : { type: 'Polygon', coordinates: rings };\n}\n\nfunction readSubGeometry(reader: Reader): Geometry {\n // Multi* geometries embed sub-WKB records; each carries its own header.\n const header = readHeader(reader);\n switch (header.geomType) {\n case TYPE_POINT:\n return readPoint(reader, header);\n case TYPE_LINESTRING:\n return readLineString(reader, header);\n case TYPE_POLYGON:\n return readPolygon(reader, header);\n default:\n throw new Error(`Geometry wire value: unsupported sub-type ${header.geomType}`);\n }\n}\n\nfunction readMultiPoint(reader: Reader, header: Header): GeometryMultiPoint {\n const n = reader.readUint32(header.littleEndian);\n const coords: Position[] = [];\n for (let i = 0; i < n; i++) {\n const sub = readSubGeometry(reader);\n if (sub.type !== 'Point') {\n throw new Error('Geometry wire value: MultiPoint contains non-Point sub-geometry');\n }\n coords.push(sub.coordinates);\n }\n return header.srid !== undefined\n ? { type: 'MultiPoint', coordinates: coords, srid: header.srid }\n : { type: 'MultiPoint', coordinates: coords };\n}\n\nfunction readMultiLineString(reader: Reader, header: Header): GeometryMultiLineString {\n const n = reader.readUint32(header.littleEndian);\n const lines: ReadonlyArray<Position>[] = [];\n for (let i = 0; i < n; i++) {\n const sub = readSubGeometry(reader);\n if (sub.type !== 'LineString') {\n throw new Error('Geometry wire value: MultiLineString contains non-LineString sub-geometry');\n }\n lines.push(sub.coordinates);\n }\n return header.srid !== undefined\n ? { type: 'MultiLineString', coordinates: lines, srid: header.srid }\n : { type: 'MultiLineString', coordinates: lines };\n}\n\nfunction readMultiPolygon(reader: Reader, header: Header): GeometryMultiPolygon {\n const n = reader.readUint32(header.littleEndian);\n const polys: ReadonlyArray<ReadonlyArray<Position>>[] = [];\n for (let i = 0; i < n; i++) {\n const sub = readSubGeometry(reader);\n if (sub.type !== 'Polygon') {\n throw new Error('Geometry wire value: MultiPolygon contains non-Polygon sub-geometry');\n }\n polys.push(sub.coordinates);\n }\n return header.srid !== undefined\n ? { type: 'MultiPolygon', coordinates: polys, srid: header.srid }\n : { type: 'MultiPolygon', coordinates: polys };\n}\n\nexport function decodeEWKBHex(hex: string): Geometry {\n const reader = new Reader(hexToBytes(hex));\n const header = readHeader(reader);\n const geometry = readGeometryBody(reader, header);\n if (reader.hasRemaining()) {\n throw new Error(\n `Geometry wire value: trailing data after geometry (${reader.remainingBytes()} bytes)`,\n );\n }\n return geometry;\n}\n\nfunction readGeometryBody(reader: Reader, header: Header): Geometry {\n switch (header.geomType) {\n case TYPE_POINT:\n return readPoint(reader, header);\n case TYPE_LINESTRING:\n return readLineString(reader, header);\n case TYPE_POLYGON:\n return readPolygon(reader, header);\n case TYPE_MULTIPOINT:\n return readMultiPoint(reader, header);\n case TYPE_MULTILINESTRING:\n return readMultiLineString(reader, header);\n case TYPE_MULTIPOLYGON:\n return readMultiPolygon(reader, header);\n default:\n throw new Error(`Geometry wire value: unsupported geometry type ${header.geomType}`);\n }\n}\n\n/**\n * Encode a GeoJSON-shaped geometry to an EWKT string PostGIS understands\n * via `'<ewkt>'::geometry`. We use EWKT (not EWKB) on the way in so the\n * generated SQL stays human-readable.\n */\nexport function encodeEWKT(value: Geometry): string {\n const sridPrefix = value.srid !== undefined ? `SRID=${value.srid};` : '';\n switch (value.type) {\n case 'Point':\n return `${sridPrefix}POINT(${formatPosition(value.coordinates)})`;\n case 'LineString':\n return `${sridPrefix}LINESTRING(${value.coordinates.map(formatPosition).join(',')})`;\n case 'Polygon':\n return `${sridPrefix}POLYGON(${formatRings(value.coordinates)})`;\n case 'MultiPoint':\n return `${sridPrefix}MULTIPOINT(${value.coordinates.map(formatPosition).join(',')})`;\n case 'MultiLineString':\n return `${sridPrefix}MULTILINESTRING(${value.coordinates\n .map((line) => `(${line.map(formatPosition).join(',')})`)\n .join(',')})`;\n case 'MultiPolygon':\n return `${sridPrefix}MULTIPOLYGON(${value.coordinates\n .map((poly) => `(${formatRings(poly)})`)\n .join(',')})`;\n }\n}\n\nfunction formatPosition(p: Position): string {\n if (!Number.isFinite(p[0]) || !Number.isFinite(p[1])) {\n throw new Error('Geometry encode: coordinates must be finite numbers');\n }\n return `${p[0]} ${p[1]}`;\n}\n\nfunction formatRings(rings: ReadonlyArray<ReadonlyArray<Position>>): string {\n return rings.map((ring) => `(${ring.map(formatPosition).join(',')})`).join(',');\n}\n","/**\n * Geometry codec for the PostGIS extension.\n *\n * Mirrors the descriptor + class pattern used by other codec-shipping\n * packages (e.g. pgvector). Three artefacts:\n *\n * 1. `PostgisGeometryCodec` extends {@link CodecImpl} with the runtime\n * encode/decode conversions. Wire formats:\n * - encode: EWKT (`'SRID=4326;POINT(...)'`) — PostgreSQL parses\n * this when cast to `::geometry`.\n * - decode: hex EWKB — the default representation `node-postgres`\n * hands back for `geometry` columns. We parse it into a\n * GeoJSON-shaped object so callers see structured data, not\n * opaque hex.\n * 2. `PostgisGeometryDescriptor` extends {@link CodecDescriptorImpl}\n * with the codec id, traits, target types, params schema\n * (`{ srid: number }`, validated as a non-negative integer), and\n * the emit-path `renderOutputType` producing `Geometry<${srid}>` /\n * `Geometry` when no SRID is supplied.\n * 3. `pgGeometryColumn({ srid })` per-codec column helper invoking\n * `descriptor.factory({ srid })` and passing the bare\n * `nativeType: 'geometry'`. The family-layer `expandNativeType`\n * hook renders the parameterised form\n * (`geometry(Geometry,${srid})`) at emit/verify time from\n * `nativeType` + `typeParams`.\n *\n * The geometry codec's encode/decode is parameter-independent — the\n * wire format already carries SRID inside the EWKT/EWKB payload, so the\n * resolved codec for every `(srid)` instance is the same shared codec\n * today. The factory threads the closure for future per-instance state\n * (e.g. SRID cross-checks) without rewriting the constructor.\n */\n\nimport type { JsonValue } from '@prisma-next/contract/types';\nimport {\n type AnyCodecDescriptor,\n type CodecCallContext,\n CodecDescriptorImpl,\n CodecImpl,\n type CodecInstanceContext,\n type ColumnHelperFor,\n type ColumnHelperForStrict,\n column,\n} from '@prisma-next/framework-components/codec';\nimport type { ExtractCodecTypes } from '@prisma-next/sql-relational-core/ast';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { type as arktype } from 'arktype';\nimport { POSTGIS_GEOMETRY_CODEC_ID } from './constants';\nimport { decodeEWKBHex, encodeEWKT } from './ewkb';\nimport type { Geometry } from './geojson';\n\ntype GeometryParams = { readonly srid: number };\n\nconst geometryParamsSchema = arktype({\n srid: 'number',\n}).narrow((params, ctx) => {\n const { srid } = params;\n if (!Number.isInteger(srid)) {\n return ctx.mustBe('an integer');\n }\n if (srid < 0) {\n return ctx.mustBe('a non-negative integer');\n }\n return true;\n}) satisfies StandardSchemaV1<GeometryParams>;\n\nconst POSTGIS_GEOMETRY_META = {\n db: { sql: { postgres: { nativeType: 'geometry' } } },\n} as const;\n\nconst allowedGeometryTypes = new Set([\n 'Point',\n 'LineString',\n 'Polygon',\n 'MultiPoint',\n 'MultiLineString',\n 'MultiPolygon',\n]);\n\nfunction assertGeometry(value: unknown): asserts value is Geometry {\n if (!value || typeof value !== 'object') {\n throw new Error('Geometry value must be a GeoJSON-shaped object');\n }\n const type = (value as { type?: unknown }).type;\n if (typeof type !== 'string' || !allowedGeometryTypes.has(type)) {\n throw new Error(\n `Geometry value: unsupported type \"${String(type)}\" (expected Point, LineString, Polygon, MultiPoint, MultiLineString, or MultiPolygon)`,\n );\n }\n if (!Array.isArray((value as { coordinates?: unknown }).coordinates)) {\n throw new Error('Geometry value: \"coordinates\" must be an array');\n }\n}\n\nexport class PostgisGeometryCodec extends CodecImpl<\n typeof POSTGIS_GEOMETRY_CODEC_ID,\n readonly ['equality'],\n string,\n Geometry\n> {\n constructor(descriptor: AnyCodecDescriptor) {\n super(descriptor);\n }\n\n async encode(value: Geometry, _ctx: CodecCallContext): Promise<string> {\n assertGeometry(value);\n return encodeEWKT(value);\n }\n\n async decode(wire: string, _ctx: CodecCallContext): Promise<Geometry> {\n if (typeof wire !== 'string') {\n throw new Error('Geometry wire value must be a string');\n }\n return decodeEWKBHex(wire);\n }\n\n encodeJson(value: Geometry): JsonValue {\n assertGeometry(value);\n return value as unknown as JsonValue;\n }\n\n decodeJson(json: JsonValue): Geometry {\n assertGeometry(json);\n return json;\n }\n}\n\nexport class PostgisGeometryDescriptor extends CodecDescriptorImpl<GeometryParams> {\n override readonly codecId = POSTGIS_GEOMETRY_CODEC_ID;\n override readonly traits = ['equality'] as const;\n override readonly targetTypes = ['geometry'] as const;\n override readonly meta = POSTGIS_GEOMETRY_META;\n override readonly paramsSchema: StandardSchemaV1<GeometryParams> = geometryParamsSchema;\n override renderOutputType(params: GeometryParams): string {\n const srid = (params as GeometryParams | undefined)?.srid;\n if (srid === undefined) return 'Geometry';\n return `Geometry<${srid}>`;\n }\n /**\n * The runtime calls `factory(undefined)(ctx)` to materialize a\n * representative codec for parameterised descriptors that ship a\n * no-params column variant (here, `geometryColumn` vs `geometry({ srid })`).\n * The runtime cast widens `params` to `unknown`, so guarding with an\n * optional read keeps the typed call site (`factory({ srid })`)\n * strict while still producing an SRID-agnostic codec for\n * representative use. Encode/decode for an unparameterised column\n * runs through this representative; the wire format already carries\n * SRID inside the EWKT/EWKB payload, so it's dimension-independent.\n */\n override factory(_params: GeometryParams): (ctx: CodecInstanceContext) => PostgisGeometryCodec {\n return () => new PostgisGeometryCodec(this);\n }\n}\n\nexport const postgisGeometryDescriptor = new PostgisGeometryDescriptor();\n\n/**\n * Per-codec column helper for `pg/geometry@1` with an SRID constraint.\n *\n * Generic over `S extends number` so the column site preserves the\n * SRID literal in `typeParams` (e.g. `pgGeometryColumn({ srid: 4326 })`\n * packs `typeParams: { srid: 4326 }`).\n *\n * Passes the bare `nativeType: 'geometry'`; the family-layer\n * `expandNativeType` hook renders the parameterised form\n * (`geometry(Geometry,${srid})`) at emit/verify time from `nativeType`\n * + `typeParams`.\n *\n * @throws {RangeError} If `srid` is not a non-negative integer.\n */\nexport const pgGeometryColumn = <S extends number>(options: { readonly srid: S }) => {\n const { srid } = options;\n if (!Number.isInteger(srid) || srid < 0) {\n throw new RangeError(`postgis: srid must be a non-negative integer, got ${srid}`);\n }\n return column(\n postgisGeometryDescriptor.factory({ srid }),\n postgisGeometryDescriptor.codecId,\n { srid },\n 'geometry',\n );\n};\n\npgGeometryColumn satisfies ColumnHelperFor<PostgisGeometryDescriptor>;\npgGeometryColumn satisfies ColumnHelperForStrict<PostgisGeometryDescriptor>;\n\nconst codecDescriptorMap = {\n geometry: postgisGeometryDescriptor,\n} as const;\n\nexport type CodecTypes = ExtractCodecTypes<typeof codecDescriptorMap>;\n\nexport const codecDescriptors: readonly AnyCodecDescriptor[] = Object.values(codecDescriptorMap);\n","import { buildCodecDescriptorRegistry } from '@prisma-next/sql-relational-core/codec-descriptor-registry';\nimport type { CodecDescriptorRegistry } from '@prisma-next/sql-relational-core/query-lane-context';\nimport { codecDescriptors } from './codecs';\n\n/**\n * Registry of every codec descriptor shipped by `@prisma-next/extension-postgis`.\n *\n * Public consumer surface for the postgis codec set. Currently a single\n * entry (`pg/geometry@1`); the registry shape stays consistent with\n * the other codec-shipping packages so consumers don't need to\n * special-case extensions.\n */\nexport const postgisCodecRegistry: CodecDescriptorRegistry =\n buildCodecDescriptorRegistry(codecDescriptors);\n","import { buildOperation, codecOf, toExpr } from '@prisma-next/sql-relational-core/expression';\nimport type { CodecTypes } from '../types/codec-types';\nimport type { QueryOperationTypes } from '../types/operation-types';\nimport { postgisAuthoringTypes } from './authoring';\nimport { postgisCodecRegistry } from './registry';\n\nconst postgisTypeId = 'pg/geometry@1' as const;\n\ntype CodecTypesBase = Record<string, { readonly input: unknown; readonly output: unknown }>;\n\n/**\n * Build the PostGIS query operations exposed on `geometry` columns.\n *\n * Each operation lowers to a function-template that the SQL renderer\n * stitches into the surrounding statement (`{{self}}` is the receiver,\n * `{{argN}}` are the call arguments). All templates rely on the implicit\n * `geometry`/`float8`/`bool` casts already wired up by the SQL family —\n * we only add the PostGIS-specific function names.\n */\nexport function postgisQueryOperations<CT extends CodecTypesBase>(): QueryOperationTypes<CT> {\n return {\n distance: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'distance',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_Distance({{self}}, {{arg0}})',\n },\n });\n },\n },\n distanceSphere: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'distanceSphere',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/float8@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_DistanceSphere({{self}}, {{arg0}})',\n },\n });\n },\n },\n dwithin: {\n self: { codecId: postgisTypeId },\n impl: (self, other, distance) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'dwithin',\n args: [\n toExpr(self, selfCodec),\n toExpr(other, selfCodec),\n toExpr(distance, { codecId: 'pg/float8@1' }),\n ],\n returns: { codecId: 'pg/bool@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_DWithin({{self}}, {{arg0}}, {{arg1}})',\n },\n });\n },\n },\n contains: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'contains',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/bool@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_Contains({{self}}, {{arg0}})',\n },\n });\n },\n },\n within: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'within',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/bool@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_Within({{self}}, {{arg0}})',\n },\n });\n },\n },\n intersects: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'intersects',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/bool@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: 'ST_Intersects({{self}}, {{arg0}})',\n },\n });\n },\n },\n intersectsBbox: {\n self: { codecId: postgisTypeId },\n impl: (self, other) => {\n const selfCodec = codecOf(self);\n return buildOperation({\n method: 'intersectsBbox',\n args: [toExpr(self, selfCodec), toExpr(other, selfCodec)],\n returns: { codecId: 'pg/bool@1', nullable: false },\n lowering: {\n targetFamily: 'sql',\n strategy: 'function',\n template: '({{self}} && {{arg0}})',\n },\n });\n },\n },\n };\n}\n\nconst postgisPackMetaBase = {\n kind: 'extension',\n id: 'postgis',\n familyId: 'sql',\n targetId: 'postgres',\n version: '0.0.1',\n capabilities: {\n postgres: {\n 'postgis.geometry': true,\n },\n },\n authoring: {\n type: postgisAuthoringTypes,\n },\n types: {\n codecTypes: {\n codecDescriptors: Array.from(postgisCodecRegistry.values()),\n import: {\n package: '@prisma-next/extension-postgis/codec-types',\n named: 'CodecTypes',\n alias: 'PostgisTypes',\n },\n typeImports: [\n {\n package: '@prisma-next/extension-postgis/codec-types',\n named: 'Geometry',\n alias: 'Geometry',\n },\n ],\n },\n queryOperationTypes: {\n import: {\n package: '@prisma-next/extension-postgis/operation-types',\n named: 'QueryOperationTypes',\n alias: 'PostgisQueryOperationTypes',\n },\n },\n storage: [\n { typeId: postgisTypeId, familyId: 'sql', targetId: 'postgres', nativeType: 'geometry' },\n ],\n },\n} as const;\n\nexport const postgisPackMeta: typeof postgisPackMetaBase & {\n readonly __codecTypes?: CodecTypes;\n} = postgisPackMetaBase;\n"],"mappings":";;;;;;AAGA,MAAa,wBAAwB,EACnC,SAAS,EACP,UAAU;CACR,MAAM;CACN,MAAM,CAAC;EAAE,MAAM;EAAU,MAAM;EAAQ,SAAS;EAAM,SAAS;EAAG,CAAC;CACnE,QAAQ;EACN,SAAS;EACT,YAAY;EACZ,YAAY,EACV,MAAM;GAAE,MAAM;GAAO,OAAO;GAAG,EAChC;EACF;CACF,EACF,EACF;;;ACKD,MAAM,SAAS;AACf,MAAM,SAAS;AACf,MAAM,YAAY;AAClB,MAAM,YAAY;AAElB,MAAM,aAAa;AACnB,MAAM,kBAAkB;AACxB,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;AAC7B,MAAM,oBAAoB;AAE1B,MAAM,cAAc;AAEpB,SAAS,WAAW,KAAyB;CAC3C,IAAI,IAAI,SAAS,MAAM,GACrB,MAAM,IAAI,MAAM,6CAA6C;CAE/D,MAAM,QAAQ,IAAI,WAAW,IAAI,SAAS,EAAE;CAC5C,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ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//#region src/core/geojson.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* GeoJSON-shaped value types used by the PostGIS codec.
|
|
4
|
+
*
|
|
5
|
+
* The codec speaks GeoJSON-style objects to JavaScript callers and
|
|
6
|
+
* EWKT/EWKB on the wire. This file is the single source of truth for the
|
|
7
|
+
* value shapes; the public type re-export lives in `exports/geojson.ts`.
|
|
8
|
+
*/
|
|
9
|
+
type Position = readonly [number, number];
|
|
10
|
+
type GeometryPoint = {
|
|
11
|
+
readonly type: 'Point';
|
|
12
|
+
readonly coordinates: Position;
|
|
13
|
+
readonly srid?: number;
|
|
14
|
+
};
|
|
15
|
+
type GeometryLineString = {
|
|
16
|
+
readonly type: 'LineString';
|
|
17
|
+
readonly coordinates: ReadonlyArray<Position>;
|
|
18
|
+
readonly srid?: number;
|
|
19
|
+
};
|
|
20
|
+
type GeometryPolygon = {
|
|
21
|
+
readonly type: 'Polygon';
|
|
22
|
+
readonly coordinates: ReadonlyArray<ReadonlyArray<Position>>;
|
|
23
|
+
readonly srid?: number;
|
|
24
|
+
};
|
|
25
|
+
type GeometryMultiPoint = {
|
|
26
|
+
readonly type: 'MultiPoint';
|
|
27
|
+
readonly coordinates: ReadonlyArray<Position>;
|
|
28
|
+
readonly srid?: number;
|
|
29
|
+
};
|
|
30
|
+
type GeometryMultiLineString = {
|
|
31
|
+
readonly type: 'MultiLineString';
|
|
32
|
+
readonly coordinates: ReadonlyArray<ReadonlyArray<Position>>;
|
|
33
|
+
readonly srid?: number;
|
|
34
|
+
};
|
|
35
|
+
type GeometryMultiPolygon = {
|
|
36
|
+
readonly type: 'MultiPolygon';
|
|
37
|
+
readonly coordinates: ReadonlyArray<ReadonlyArray<ReadonlyArray<Position>>>;
|
|
38
|
+
readonly srid?: number;
|
|
39
|
+
};
|
|
40
|
+
type Geometry = GeometryPoint | GeometryLineString | GeometryPolygon | GeometryMultiPoint | GeometryMultiLineString | GeometryMultiPolygon;
|
|
41
|
+
/**
|
|
42
|
+
* Construct a Point. Convenience for the common "lng/lat" case.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* point(-122.4194, 37.7749, 4326)
|
|
46
|
+
*/
|
|
47
|
+
declare function point(longitude: number, latitude: number, srid?: number): GeometryPoint;
|
|
48
|
+
/**
|
|
49
|
+
* Construct a Polygon from a single outer ring of `[lng, lat]` pairs.
|
|
50
|
+
* If the first and last positions differ, the ring is closed automatically.
|
|
51
|
+
*/
|
|
52
|
+
declare function polygon(ring: ReadonlyArray<Position>, srid?: number): GeometryPolygon;
|
|
53
|
+
/**
|
|
54
|
+
* Construct a rectangular Polygon from a bounding box.
|
|
55
|
+
*
|
|
56
|
+
* @param bbox - `[minLng, minLat, maxLng, maxLat]`
|
|
57
|
+
*/
|
|
58
|
+
declare function bboxPolygon(bbox: readonly [number, number, number, number], srid?: number): GeometryPolygon;
|
|
59
|
+
//#endregion
|
|
60
|
+
export { GeometryMultiPolygon as a, Position as c, polygon as d, GeometryMultiPoint as i, bboxPolygon as l, GeometryLineString as n, GeometryPoint as o, GeometryMultiLineString as r, GeometryPolygon as s, Geometry as t, point as u };
|
|
61
|
+
//# sourceMappingURL=geojson-Cj4ldHQ0.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-Cj4ldHQ0.d.mts","names":[],"sources":["../src/core/geojson.ts"],"mappings":";;AAQA;;;;;AAEA;KAFY,QAAA;AAAA,KAEA,aAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,QAAA;EAAA,SACb,IAAA;AAAA;AAAA,KAGC,kBAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,aAAA,CAAc,QAAA;EAAA,SAC3B,IAAA;AAAA;AAAA,KAGC,eAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,aAAA,CAAc,aAAA,CAAc,QAAA;EAAA,SACzC,IAAA;AAAA;AAAA,KAGC,kBAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,aAAA,CAAc,QAAA;EAAA,SAC3B,IAAA;AAAA;AAAA,KAGC,uBAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,aAAA,CAAc,aAAA,CAAc,QAAA;EAAA,SACzC,IAAA;AAAA;AAAA,KAGC,oBAAA;EAAA,SACD,IAAA;EAAA,SACA,WAAA,EAAa,aAAA,CAAc,aAAA,CAAc,aAAA,CAAc,QAAA;EAAA,SACvD,IAAA;AAAA;AAAA,KAGC,QAAA,GACR,aAAA,GACA,kBAAA,GACA,eAAA,GACA,kBAAA,GACA,uBAAA,GACA,oBAAA;;;;;AAxBJ;;iBAgCgB,KAAA,CAAM,SAAA,UAAmB,QAAA,UAAkB,IAAA,YAAgB,aAAA;;;;;iBAa3D,OAAA,CAAQ,IAAA,EAAM,aAAA,CAAc,QAAA,GAAW,IAAA,YAAgB,eAAA;;;;AAvCvE;;iBAoEgB,WAAA,CACd,IAAA,6CACA,IAAA,YACC,eAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as GeometryMultiPolygon, c as Position, d as polygon, i as GeometryMultiPoint, l as bboxPolygon, n as GeometryLineString, o as GeometryPoint, r as GeometryMultiLineString, s as GeometryPolygon, t as Geometry, u as point } from "./geojson-Cj4ldHQ0.mjs";
|
|
2
|
+
export { type Geometry, type GeometryLineString, type GeometryMultiLineString, type GeometryMultiPoint, type GeometryMultiPolygon, type GeometryPoint, type GeometryPolygon, type Position, bboxPolygon, point, polygon };
|