graphile-postgis 2.9.7 → 2.9.8
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/esm/plugins/codec.js +40 -0
- package/package.json +2 -2
- package/plugins/codec.js +40 -0
package/esm/plugins/codec.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'graphile-build-pg';
|
|
2
2
|
import sql from 'pg-sql2';
|
|
3
|
+
import { GIS_SUBTYPE_NAME } from '../constants';
|
|
4
|
+
import { getGISTypeDetails } from '../utils';
|
|
3
5
|
/**
|
|
4
6
|
* Map from PostGIS uppercase geometry type names (from geometrytype()) to
|
|
5
7
|
* our mixed-case format used by resolveType lookups.
|
|
@@ -45,6 +47,11 @@ const GIS_TYPE_NORMALIZE = {
|
|
|
45
47
|
function normalizeGisType(raw) {
|
|
46
48
|
return GIS_TYPE_NORMALIZE[raw] ?? raw;
|
|
47
49
|
}
|
|
50
|
+
function getGeometrySubtypeName(typmod) {
|
|
51
|
+
const { subtype } = getGISTypeDetails(typmod);
|
|
52
|
+
const subtypeName = GIS_SUBTYPE_NAME[subtype];
|
|
53
|
+
return subtypeName && subtypeName !== 'Geometry' ? subtypeName : null;
|
|
54
|
+
}
|
|
48
55
|
/**
|
|
49
56
|
* Build a codec for a PostGIS geometry or geography type.
|
|
50
57
|
*
|
|
@@ -168,6 +175,39 @@ export const PostgisCodecPlugin = {
|
|
|
168
175
|
event.pgCodec = buildGisCodec('geography', typeNamespace.nspname, type._id, serviceName);
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
178
|
+
},
|
|
179
|
+
/**
|
|
180
|
+
* Annotate geometry/geography attributes with their subtype (Point,
|
|
181
|
+
* Polygon, LineString, etc.) decoded from the PostgreSQL type modifier.
|
|
182
|
+
*
|
|
183
|
+
* The atttypmod encodes subtype + SRID + Z/M flags. We decode it with
|
|
184
|
+
* getGISTypeDetails() and store the human-readable subtype name on
|
|
185
|
+
* attribute.extensions.geometrySubtype so the _meta plugin can expose it.
|
|
186
|
+
*/
|
|
187
|
+
async pgCodecs_attribute(_info, event) {
|
|
188
|
+
const { pgAttribute, attribute } = event;
|
|
189
|
+
const codecName = attribute.codec?.name;
|
|
190
|
+
if (codecName !== 'geometry' && codecName !== 'geography') {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const typmod = pgAttribute.atttypmod;
|
|
194
|
+
// atttypmod of -1 or null means no modifier (unconstrained geometry)
|
|
195
|
+
if (typmod == null || typmod === -1) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const subtypeName = getGeometrySubtypeName(typmod);
|
|
200
|
+
if (subtypeName) {
|
|
201
|
+
if (!attribute.extensions) {
|
|
202
|
+
attribute.extensions = {};
|
|
203
|
+
}
|
|
204
|
+
attribute.extensions.geometrySubtype = subtypeName;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// If the modifier can't be decoded, silently skip — the column
|
|
209
|
+
// will still work, just without subtype info in _meta.
|
|
210
|
+
}
|
|
171
211
|
}
|
|
172
212
|
}
|
|
173
213
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "graphile-postgis",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8",
|
|
4
4
|
"description": "PostGIS support for PostGraphile v5",
|
|
5
5
|
"author": "Constructive <developers@constructive.io>",
|
|
6
6
|
"homepage": "https://github.com/constructive-io/constructive",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"makage": "^0.3.0",
|
|
64
64
|
"pgsql-test": "^4.7.6"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "f1a0d4315e0f23ba6b8299a7dc2ddceab465d24d"
|
|
67
67
|
}
|
package/plugins/codec.js
CHANGED
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.PostgisCodecPlugin = void 0;
|
|
7
7
|
require("graphile-build-pg");
|
|
8
8
|
const pg_sql2_1 = __importDefault(require("pg-sql2"));
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
9
11
|
/**
|
|
10
12
|
* Map from PostGIS uppercase geometry type names (from geometrytype()) to
|
|
11
13
|
* our mixed-case format used by resolveType lookups.
|
|
@@ -51,6 +53,11 @@ const GIS_TYPE_NORMALIZE = {
|
|
|
51
53
|
function normalizeGisType(raw) {
|
|
52
54
|
return GIS_TYPE_NORMALIZE[raw] ?? raw;
|
|
53
55
|
}
|
|
56
|
+
function getGeometrySubtypeName(typmod) {
|
|
57
|
+
const { subtype } = (0, utils_1.getGISTypeDetails)(typmod);
|
|
58
|
+
const subtypeName = constants_1.GIS_SUBTYPE_NAME[subtype];
|
|
59
|
+
return subtypeName && subtypeName !== 'Geometry' ? subtypeName : null;
|
|
60
|
+
}
|
|
54
61
|
/**
|
|
55
62
|
* Build a codec for a PostGIS geometry or geography type.
|
|
56
63
|
*
|
|
@@ -174,6 +181,39 @@ exports.PostgisCodecPlugin = {
|
|
|
174
181
|
event.pgCodec = buildGisCodec('geography', typeNamespace.nspname, type._id, serviceName);
|
|
175
182
|
return;
|
|
176
183
|
}
|
|
184
|
+
},
|
|
185
|
+
/**
|
|
186
|
+
* Annotate geometry/geography attributes with their subtype (Point,
|
|
187
|
+
* Polygon, LineString, etc.) decoded from the PostgreSQL type modifier.
|
|
188
|
+
*
|
|
189
|
+
* The atttypmod encodes subtype + SRID + Z/M flags. We decode it with
|
|
190
|
+
* getGISTypeDetails() and store the human-readable subtype name on
|
|
191
|
+
* attribute.extensions.geometrySubtype so the _meta plugin can expose it.
|
|
192
|
+
*/
|
|
193
|
+
async pgCodecs_attribute(_info, event) {
|
|
194
|
+
const { pgAttribute, attribute } = event;
|
|
195
|
+
const codecName = attribute.codec?.name;
|
|
196
|
+
if (codecName !== 'geometry' && codecName !== 'geography') {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const typmod = pgAttribute.atttypmod;
|
|
200
|
+
// atttypmod of -1 or null means no modifier (unconstrained geometry)
|
|
201
|
+
if (typmod == null || typmod === -1) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
try {
|
|
205
|
+
const subtypeName = getGeometrySubtypeName(typmod);
|
|
206
|
+
if (subtypeName) {
|
|
207
|
+
if (!attribute.extensions) {
|
|
208
|
+
attribute.extensions = {};
|
|
209
|
+
}
|
|
210
|
+
attribute.extensions.geometrySubtype = subtypeName;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// If the modifier can't be decoded, silently skip — the column
|
|
215
|
+
// will still work, just without subtype info in _meta.
|
|
216
|
+
}
|
|
177
217
|
}
|
|
178
218
|
}
|
|
179
219
|
}
|