graphile-postgis 0.1.0 → 0.1.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/LICENSE +3 -1
- package/PostgisExtensionDetectionPlugin.d.ts +3 -0
- package/PostgisExtensionDetectionPlugin.js +28 -0
- package/PostgisInflectionPlugin.d.ts +3 -0
- package/PostgisInflectionPlugin.js +36 -0
- package/PostgisRegisterTypesPlugin.d.ts +3 -0
- package/PostgisRegisterTypesPlugin.js +232 -0
- package/PostgisVersionPlugin.d.ts +3 -0
- package/PostgisVersionPlugin.js +23 -0
- package/Postgis_GeometryCollection_GeometriesPlugin.d.ts +3 -0
- package/Postgis_GeometryCollection_GeometriesPlugin.js +43 -0
- package/Postgis_LineString_PointsPlugin.d.ts +3 -0
- package/Postgis_LineString_PointsPlugin.js +40 -0
- package/Postgis_MultiLineString_LineStringsPlugin.d.ts +3 -0
- package/Postgis_MultiLineString_LineStringsPlugin.js +38 -0
- package/Postgis_MultiPoint_PointsPlugin.d.ts +3 -0
- package/Postgis_MultiPoint_PointsPlugin.js +38 -0
- package/Postgis_MultiPolygon_PolygonsPlugin.d.ts +3 -0
- package/Postgis_MultiPolygon_PolygonsPlugin.js +38 -0
- package/Postgis_Point_LatitudeLongitudePlugin.d.ts +3 -0
- package/Postgis_Point_LatitudeLongitudePlugin.js +43 -0
- package/Postgis_Polygon_RingsPlugin.d.ts +3 -0
- package/Postgis_Polygon_RingsPlugin.js +49 -0
- package/README.md +125 -5
- package/constants.d.ts +12 -0
- package/constants.js +34 -0
- package/esm/PostgisExtensionDetectionPlugin.js +26 -0
- package/esm/PostgisInflectionPlugin.js +34 -0
- package/esm/PostgisRegisterTypesPlugin.js +227 -0
- package/esm/PostgisVersionPlugin.js +21 -0
- package/esm/Postgis_GeometryCollection_GeometriesPlugin.js +41 -0
- package/esm/Postgis_LineString_PointsPlugin.js +38 -0
- package/esm/Postgis_MultiLineString_LineStringsPlugin.js +36 -0
- package/esm/Postgis_MultiPoint_PointsPlugin.js +36 -0
- package/esm/Postgis_MultiPolygon_PolygonsPlugin.js +36 -0
- package/esm/Postgis_Point_LatitudeLongitudePlugin.js +41 -0
- package/esm/Postgis_Polygon_RingsPlugin.js +47 -0
- package/esm/constants.js +31 -0
- package/esm/index.js +33 -0
- package/esm/makeGeoJSONType.js +39 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +47 -0
- package/index.d.ts +15 -0
- package/index.js +49 -0
- package/makeGeoJSONType.d.ts +1 -0
- package/makeGeoJSONType.js +42 -0
- package/package.json +37 -52
- package/types.d.ts +59 -0
- package/types.js +2 -0
- package/utils.d.ts +5 -0
- package/utils.js +53 -0
- package/main/PostgisExtensionDetectionPlugin.js +0 -43
- package/main/PostgisInflectionPlugin.js +0 -51
- package/main/PostgisRegisterTypesPlugin.js +0 -347
- package/main/Postgis_GeometryCollection_GeometriesPlugin.js +0 -55
- package/main/Postgis_LineString_PointsPlugin.js +0 -51
- package/main/Postgis_MultiLineString_LineStringsPlugin.js +0 -51
- package/main/Postgis_MultiPoint_PointsPlugin.js +0 -51
- package/main/Postgis_MultiPolygon_PolygonsPlugin.js +0 -51
- package/main/Postgis_Point_LatitudeLongitudePlugin.js +0 -59
- package/main/Postgis_Polygon_RingsPlugin.js +0 -64
- package/main/constants.js +0 -39
- package/main/index.js +0 -93
- package/main/makeGeoJSONType.js +0 -89
- package/main/utils.js +0 -56
- package/module/PostgisExtensionDetectionPlugin.js +0 -31
- package/module/PostgisInflectionPlugin.js +0 -44
- package/module/PostgisRegisterTypesPlugin.js +0 -267
- package/module/Postgis_GeometryCollection_GeometriesPlugin.js +0 -57
- package/module/Postgis_LineString_PointsPlugin.js +0 -53
- package/module/Postgis_MultiLineString_LineStringsPlugin.js +0 -51
- package/module/Postgis_MultiPoint_PointsPlugin.js +0 -51
- package/module/Postgis_MultiPolygon_PolygonsPlugin.js +0 -51
- package/module/Postgis_Point_LatitudeLongitudePlugin.js +0 -64
- package/module/Postgis_Polygon_RingsPlugin.js +0 -66
- package/module/constants.js +0 -30
- package/module/index.js +0 -32
- package/module/makeGeoJSONType.js +0 -79
- package/module/utils.js +0 -40
package/utils.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getGISTypeName = exports.getGISTypeModifier = exports.getGISTypeDetails = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const getGISTypeDetails = (modifier) => {
|
|
6
|
+
const allZeroesHopefully = modifier >> 24;
|
|
7
|
+
if (allZeroesHopefully !== 0) {
|
|
8
|
+
throw new Error('Unsupported PostGIS modifier');
|
|
9
|
+
}
|
|
10
|
+
// Ref: https://github.com/postgis/postgis/blob/2.5.2/liblwgeom/liblwgeom.h.in#L156-L173
|
|
11
|
+
// #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
|
|
12
|
+
// #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
|
|
13
|
+
// #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
|
|
14
|
+
// #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)
|
|
15
|
+
const srid = ((modifier & 0x0fffff00) - (modifier & 0x10000000)) >> 8;
|
|
16
|
+
const subtypeNumeric = (modifier & 0x000000fc) >> 2;
|
|
17
|
+
const hasZ = (modifier & 0x00000002) >> 1 === 1;
|
|
18
|
+
const hasM = (modifier & 0x00000001) === 1;
|
|
19
|
+
if (subtypeNumeric !== constants_1.GisSubtype.Geometry &&
|
|
20
|
+
subtypeNumeric !== constants_1.GisSubtype.Point &&
|
|
21
|
+
subtypeNumeric !== constants_1.GisSubtype.LineString &&
|
|
22
|
+
subtypeNumeric !== constants_1.GisSubtype.Polygon &&
|
|
23
|
+
subtypeNumeric !== constants_1.GisSubtype.MultiPoint &&
|
|
24
|
+
subtypeNumeric !== constants_1.GisSubtype.MultiLineString &&
|
|
25
|
+
subtypeNumeric !== constants_1.GisSubtype.MultiPolygon &&
|
|
26
|
+
subtypeNumeric !== constants_1.GisSubtype.GeometryCollection) {
|
|
27
|
+
throw new Error(`Unsupported PostGIS modifier, expected 0-7, received ${subtypeNumeric} (${modifier})`);
|
|
28
|
+
}
|
|
29
|
+
const subtype = subtypeNumeric;
|
|
30
|
+
return {
|
|
31
|
+
subtype,
|
|
32
|
+
hasZ,
|
|
33
|
+
hasM,
|
|
34
|
+
srid
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.getGISTypeDetails = getGISTypeDetails;
|
|
38
|
+
const getGISTypeModifier = (subtype, hasZ, hasM, srid) => {
|
|
39
|
+
// Ref: https://github.com/postgis/postgis/blob/2.5.2/liblwgeom/liblwgeom.h.in#L156-L173
|
|
40
|
+
// #define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
|
|
41
|
+
// #define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
|
|
42
|
+
// #define TYPMOD_SET_Z(typmod) ((typmod) = typmod | 0x00000002)
|
|
43
|
+
// #define TYPMOD_SET_M(typmod) ((typmod) = typmod | 0x00000001)
|
|
44
|
+
return (((srid & 0x001fffff) << 8) +
|
|
45
|
+
((subtype & 0x0000003f) << 2) +
|
|
46
|
+
(hasZ ? 0x00000002 : 0) +
|
|
47
|
+
(hasM ? 0x00000001 : 0));
|
|
48
|
+
};
|
|
49
|
+
exports.getGISTypeModifier = getGISTypeModifier;
|
|
50
|
+
const getGISTypeName = (subtype, hasZ, hasM) => {
|
|
51
|
+
return `${constants_1.GIS_SUBTYPE_NAME[subtype]}${hasZ ? 'Z' : ''}${hasM ? 'M' : ''}`;
|
|
52
|
+
};
|
|
53
|
+
exports.getGISTypeName = getGISTypeName;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var plugin = function plugin(builder) {
|
|
9
|
-
builder.hook('build', function (build) {
|
|
10
|
-
var introspectionResultsByKind = build.pgIntrospectionResultsByKind;
|
|
11
|
-
var pgGISExtension = introspectionResultsByKind.extension.find(function (e) {
|
|
12
|
-
return e.name === 'postgis';
|
|
13
|
-
}); // Check we have the postgis extension
|
|
14
|
-
|
|
15
|
-
if (!pgGISExtension) {
|
|
16
|
-
console.warn('PostGIS extension not found in database; skipping');
|
|
17
|
-
return build;
|
|
18
|
-
} // Extract the geography and geometry types
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var pgGISGeometryType = introspectionResultsByKind.type.find(function (t) {
|
|
22
|
-
return t.name === 'geometry' && t.namespaceId === pgGISExtension.namespaceId;
|
|
23
|
-
});
|
|
24
|
-
var pgGISGeographyType = introspectionResultsByKind.type.find(function (t) {
|
|
25
|
-
return t.name === 'geography' && t.namespaceId === pgGISExtension.namespaceId;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (!pgGISGeographyType || !pgGISGeometryType) {
|
|
29
|
-
throw new Error("PostGIS is installed, but we couldn't find the geometry/geography types!");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return build.extend(build, {
|
|
33
|
-
pgGISGraphQLTypesByTypeAndSubtype: {},
|
|
34
|
-
pgGISGraphQLInterfaceTypesByType: {},
|
|
35
|
-
pgGISGeometryType: pgGISGeometryType,
|
|
36
|
-
pgGISGeographyType: pgGISGeographyType,
|
|
37
|
-
pgGISExtension: pgGISExtension
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
var _default = plugin;
|
|
43
|
-
exports["default"] = _default;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _constants = require("./constants");
|
|
13
|
-
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
|
-
|
|
18
|
-
var plugin = function plugin(builder) {
|
|
19
|
-
builder.hook('inflection', function (inflection) {
|
|
20
|
-
return _objectSpread(_objectSpread({}, inflection), {}, {
|
|
21
|
-
gisType: function gisType(type, subtype, hasZ, hasM) {
|
|
22
|
-
return this.upperCamelCase([type.name, _constants.SUBTYPE_STRING_BY_SUBTYPE[subtype], hasZ ? 'z' : null, hasM ? 'm' : null].filter(function (_) {
|
|
23
|
-
return _;
|
|
24
|
-
}).join('-'));
|
|
25
|
-
},
|
|
26
|
-
gisInterfaceName: function gisInterfaceName(type) {
|
|
27
|
-
return this.upperCamelCase("".concat(type.name, "-interface"));
|
|
28
|
-
},
|
|
29
|
-
gisDimensionInterfaceName: function gisDimensionInterfaceName(type, hasZ, hasM) {
|
|
30
|
-
return this.upperCamelCase([type.name, _constants.SUBTYPE_STRING_BY_SUBTYPE[0], hasZ ? 'z' : null, hasM ? 'm' : null].filter(function (_) {
|
|
31
|
-
return _;
|
|
32
|
-
}).join('-'));
|
|
33
|
-
},
|
|
34
|
-
geojsonFieldName: function geojsonFieldName() {
|
|
35
|
-
return "geojson";
|
|
36
|
-
},
|
|
37
|
-
gisXFieldName: function gisXFieldName(type) {
|
|
38
|
-
return type.name === 'geography' ? 'longitude' : 'x';
|
|
39
|
-
},
|
|
40
|
-
gisYFieldName: function gisYFieldName(type) {
|
|
41
|
-
return type.name === 'geography' ? 'latitude' : 'y';
|
|
42
|
-
},
|
|
43
|
-
gisZFieldName: function gisZFieldName(type) {
|
|
44
|
-
return type.name === 'geography' ? 'height' : 'z';
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var _default = plugin;
|
|
51
|
-
exports["default"] = _default;
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
|
|
16
|
-
var _utils = require("./utils");
|
|
17
|
-
|
|
18
|
-
var _makeGeoJSONType = _interopRequireDefault(require("./makeGeoJSONType"));
|
|
19
|
-
|
|
20
|
-
function _templateObject6() {
|
|
21
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["st_geomfromgeojson(", "::text)"]);
|
|
22
|
-
|
|
23
|
-
_templateObject6 = function _templateObject6() {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _templateObject5() {
|
|
31
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["st_geomfromgeojson(", "::text)::", ""]);
|
|
32
|
-
|
|
33
|
-
_templateObject5 = function _templateObject5() {
|
|
34
|
-
return data;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return data;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function _templateObject4() {
|
|
41
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["(case when ", " is null then null else json_build_object(\n ", "\n ) end)"]);
|
|
42
|
-
|
|
43
|
-
_templateObject4 = function _templateObject4() {
|
|
44
|
-
return data;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return data;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function _templateObject3() {
|
|
51
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["", "(", ")::JSON"]);
|
|
52
|
-
|
|
53
|
-
_templateObject3 = function _templateObject3() {
|
|
54
|
-
return data;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
return data;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function _templateObject2() {
|
|
61
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["", "(", ")"]);
|
|
62
|
-
|
|
63
|
-
_templateObject2 = function _templateObject2() {
|
|
64
|
-
return data;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function _templateObject() {
|
|
71
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["", "(\n ", "(", "),\n ", "(", "::text)\n )"]);
|
|
72
|
-
|
|
73
|
-
_templateObject = function _templateObject() {
|
|
74
|
-
return data;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return data;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function identity(input) {
|
|
81
|
-
return input;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
var plugin = function plugin(builder) {
|
|
85
|
-
builder.hook('build', function (build) {
|
|
86
|
-
var GeoJSON = (0, _makeGeoJSONType["default"])(build.graphql, build.inflection.builtin('GeoJSON'));
|
|
87
|
-
build.addType(GeoJSON);
|
|
88
|
-
return build.extend(build, {
|
|
89
|
-
getPostgisTypeByGeometryType: function getPostgisTypeByGeometryType(pgGISType, subtype) {
|
|
90
|
-
var hasZ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
91
|
-
var hasM = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
92
|
-
var srid = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
|
|
93
|
-
var typeModifier = (0, _utils.getGISTypeModifier)(subtype, hasZ, hasM, srid);
|
|
94
|
-
return this.pgGetGqlTypeByTypeIdAndModifier(pgGISType.id, typeModifier);
|
|
95
|
-
},
|
|
96
|
-
pgGISIncludedTypes: [],
|
|
97
|
-
pgGISIncludeType: function pgGISIncludeType(Type) {
|
|
98
|
-
this.pgGISIncludedTypes.push(Type);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
builder.hook('init', function (_, build) {
|
|
103
|
-
var newWithHooks = build.newWithHooks,
|
|
104
|
-
introspectionResultsByKind = build.pgIntrospectionResultsByKind,
|
|
105
|
-
_build$graphql = build.graphql,
|
|
106
|
-
GraphQLInt = _build$graphql.GraphQLInt,
|
|
107
|
-
GraphQLNonNull = _build$graphql.GraphQLNonNull,
|
|
108
|
-
GraphQLInterfaceType = _build$graphql.GraphQLInterfaceType,
|
|
109
|
-
GraphQLObjectType = _build$graphql.GraphQLObjectType,
|
|
110
|
-
pgRegisterGqlTypeByTypeId = build.pgRegisterGqlTypeByTypeId,
|
|
111
|
-
pgRegisterGqlInputTypeByTypeId = build.pgRegisterGqlInputTypeByTypeId,
|
|
112
|
-
pgTweaksByTypeIdAndModifer = build.pgTweaksByTypeIdAndModifer,
|
|
113
|
-
getTypeByName = build.getTypeByName,
|
|
114
|
-
sql = build.pgSql,
|
|
115
|
-
pg2gql = build.pg2gql,
|
|
116
|
-
pg2GqlMapper = build.pg2GqlMapper,
|
|
117
|
-
inflection = build.inflection,
|
|
118
|
-
constructedTypes = build.pgGISGraphQLTypesByTypeAndSubtype,
|
|
119
|
-
_interfaces = build.pgGISGraphQLInterfaceTypesByType,
|
|
120
|
-
GEOMETRY_TYPE = build.pgGISGeometryType,
|
|
121
|
-
GEOGRAPHY_TYPE = build.pgGISGeographyType,
|
|
122
|
-
POSTGIS = build.pgGISExtension,
|
|
123
|
-
includeType = build.pgGISIncludeType;
|
|
124
|
-
|
|
125
|
-
if (!GEOMETRY_TYPE || !GEOGRAPHY_TYPE) {
|
|
126
|
-
return _;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
console.warn('PostGIS plugin enabled');
|
|
130
|
-
var GeoJSON = getTypeByName(inflection.builtin('GeoJSON'));
|
|
131
|
-
var geojsonFieldName = inflection.geojsonFieldName();
|
|
132
|
-
|
|
133
|
-
function getGisInterface(type) {
|
|
134
|
-
var zmflag = -1; // no dimensional constraint; could be xy/xyz/xym/xyzm
|
|
135
|
-
|
|
136
|
-
if (!_interfaces[type.id]) {
|
|
137
|
-
_interfaces[type.id] = {};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (!_interfaces[type.id][zmflag]) {
|
|
141
|
-
var _fields;
|
|
142
|
-
|
|
143
|
-
_interfaces[type.id][zmflag] = newWithHooks(GraphQLInterfaceType, {
|
|
144
|
-
name: inflection.gisInterfaceName(type),
|
|
145
|
-
fields: (_fields = {}, (0, _defineProperty2["default"])(_fields, geojsonFieldName, {
|
|
146
|
-
type: GeoJSON,
|
|
147
|
-
description: 'Converts the object to GeoJSON'
|
|
148
|
-
}), (0, _defineProperty2["default"])(_fields, "srid", {
|
|
149
|
-
type: new GraphQLNonNull(GraphQLInt),
|
|
150
|
-
description: 'Spatial reference identifier (SRID)'
|
|
151
|
-
}), _fields),
|
|
152
|
-
resolveType: function resolveType(value, _info) {
|
|
153
|
-
var Type = constructedTypes[type.id] && constructedTypes[type.id][value.__gisType];
|
|
154
|
-
return Type;
|
|
155
|
-
},
|
|
156
|
-
description: "All ".concat(type.name, " types implement this interface")
|
|
157
|
-
}, {
|
|
158
|
-
isPgGISInterface: true,
|
|
159
|
-
pgGISType: type,
|
|
160
|
-
pgGISZMFlag: zmflag
|
|
161
|
-
}); // Force creation of all GraphQL types that could be resolved from this interface
|
|
162
|
-
|
|
163
|
-
var subtypes = [1, 2, 3, 4, 5, 6, 7];
|
|
164
|
-
|
|
165
|
-
for (var _i = 0, _subtypes = subtypes; _i < _subtypes.length; _i++) {
|
|
166
|
-
var subtype = _subtypes[_i];
|
|
167
|
-
|
|
168
|
-
for (var _i2 = 0, _arr = [false, true]; _i2 < _arr.length; _i2++) {
|
|
169
|
-
var hasZ = _arr[_i2];
|
|
170
|
-
|
|
171
|
-
for (var _i3 = 0, _arr2 = [false, true]; _i3 < _arr2.length; _i3++) {
|
|
172
|
-
var hasM = _arr2[_i3];
|
|
173
|
-
var typeModifier = (0, _utils.getGISTypeModifier)(subtype, hasZ, hasM, 0);
|
|
174
|
-
var Type = getGisType(type, typeModifier);
|
|
175
|
-
includeType(Type);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return _interfaces[type.id][zmflag];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function getGisDimensionInterface(type, hasZ, hasM) {
|
|
185
|
-
var zmflag = (hasZ ? 2 : 0) + (hasM ? 1 : 0); // Equivalent to ST_Zmflag: https://postgis.net/docs/ST_Zmflag.html
|
|
186
|
-
|
|
187
|
-
var coords = {
|
|
188
|
-
0: 'XY',
|
|
189
|
-
1: 'XYM',
|
|
190
|
-
2: 'XYZ',
|
|
191
|
-
3: 'XYZM'
|
|
192
|
-
}[zmflag];
|
|
193
|
-
|
|
194
|
-
if (!_interfaces[type.id]) {
|
|
195
|
-
_interfaces[type.id] = {};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (!_interfaces[type.id][zmflag]) {
|
|
199
|
-
var _fields2;
|
|
200
|
-
|
|
201
|
-
_interfaces[type.id][zmflag] = newWithHooks(GraphQLInterfaceType, {
|
|
202
|
-
name: inflection.gisDimensionInterfaceName(type, hasZ, hasM),
|
|
203
|
-
fields: (_fields2 = {}, (0, _defineProperty2["default"])(_fields2, geojsonFieldName, {
|
|
204
|
-
type: GeoJSON,
|
|
205
|
-
description: 'Converts the object to GeoJSON'
|
|
206
|
-
}), (0, _defineProperty2["default"])(_fields2, "srid", {
|
|
207
|
-
type: new GraphQLNonNull(GraphQLInt),
|
|
208
|
-
description: 'Spatial reference identifier (SRID)'
|
|
209
|
-
}), _fields2),
|
|
210
|
-
resolveType: function resolveType(value, _info) {
|
|
211
|
-
var Type = constructedTypes[type.id] && constructedTypes[type.id][value.__gisType];
|
|
212
|
-
return Type;
|
|
213
|
-
},
|
|
214
|
-
description: "All ".concat(type.name, " ").concat(coords, " types implement this interface")
|
|
215
|
-
}, {
|
|
216
|
-
isPgGISDimensionInterface: true,
|
|
217
|
-
pgGISType: type,
|
|
218
|
-
pgGISZMFlag: zmflag
|
|
219
|
-
}); // Force creation of all GraphQL types that could be resolved from this interface
|
|
220
|
-
|
|
221
|
-
var subtypes = [1, 2, 3, 4, 5, 6, 7];
|
|
222
|
-
|
|
223
|
-
for (var _i4 = 0, _subtypes2 = subtypes; _i4 < _subtypes2.length; _i4++) {
|
|
224
|
-
var subtype = _subtypes2[_i4];
|
|
225
|
-
var typeModifier = (0, _utils.getGISTypeModifier)(subtype, hasZ, hasM, 0);
|
|
226
|
-
var Type = getGisType(type, typeModifier);
|
|
227
|
-
includeType(Type);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return _interfaces[type.id][zmflag];
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function getGisType(type, typeModifier) {
|
|
235
|
-
var typeId = type.id;
|
|
236
|
-
var typeDetails = (0, _utils.getGISTypeDetails)(typeModifier);
|
|
237
|
-
var subtype = typeDetails.subtype,
|
|
238
|
-
hasZ = typeDetails.hasZ,
|
|
239
|
-
hasM = typeDetails.hasM,
|
|
240
|
-
srid = typeDetails.srid;
|
|
241
|
-
console.warn("Getting ".concat(type.name, " type ").concat(type.id, "|").concat(typeModifier, "|").concat(subtype, "|").concat(hasZ, "|").concat(hasM, "|").concat(srid));
|
|
242
|
-
|
|
243
|
-
if (!constructedTypes[type.id]) {
|
|
244
|
-
constructedTypes[type.id] = {};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
var typeModifierKey = typeModifier != null ? typeModifier : -1;
|
|
248
|
-
|
|
249
|
-
if (!pgTweaksByTypeIdAndModifer[typeId]) {
|
|
250
|
-
pgTweaksByTypeIdAndModifer[typeId] = {};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
if (!pgTweaksByTypeIdAndModifer[typeId][typeModifierKey]) {
|
|
254
|
-
pgTweaksByTypeIdAndModifer[typeId][typeModifierKey] = function (fragment, _resolveData) {
|
|
255
|
-
var params = [sql.literal('__gisType'), sql.fragment(_templateObject(), sql.identifier(POSTGIS.namespaceName || 'public', 'postgis_type_name' // MUST be lowercase!
|
|
256
|
-
), sql.identifier(POSTGIS.namespaceName || 'public', 'geometrytype' // MUST be lowercase!
|
|
257
|
-
), fragment, sql.identifier(POSTGIS.namespaceName || 'public', 'st_coorddim' // MUST be lowercase!
|
|
258
|
-
), fragment), sql.literal('__srid'), sql.fragment(_templateObject2(), sql.identifier(POSTGIS.namespaceName || 'public', 'st_srid' // MUST be lowercase!
|
|
259
|
-
), fragment), sql.literal('__geojson'), sql.fragment(_templateObject3(), sql.identifier(POSTGIS.namespaceName || 'public', 'st_asgeojson' // MUST be lowercase!
|
|
260
|
-
), fragment)];
|
|
261
|
-
return sql.fragment(_templateObject4(), fragment, sql.join(params, ', '));
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
var gisTypeKey = typeModifier != null ? (0, _utils.getGISTypeName)(subtype, hasZ, hasM) : -1;
|
|
266
|
-
|
|
267
|
-
if (!constructedTypes[type.id][gisTypeKey]) {
|
|
268
|
-
if (typeModifierKey === -1) {
|
|
269
|
-
constructedTypes[type.id][gisTypeKey] = getGisInterface(type);
|
|
270
|
-
} else if (subtype === 0) {
|
|
271
|
-
constructedTypes[type.id][gisTypeKey] = getGisDimensionInterface(type, hasZ, hasM);
|
|
272
|
-
} else {
|
|
273
|
-
var _fields3;
|
|
274
|
-
|
|
275
|
-
var intType = introspectionResultsByKind.type.find(function (t) {
|
|
276
|
-
return t.name === 'int4' && t.namespaceName === 'pg_catalog';
|
|
277
|
-
});
|
|
278
|
-
var jsonType = introspectionResultsByKind.type.find(function (t) {
|
|
279
|
-
return t.name === 'json' && t.namespaceName === 'pg_catalog';
|
|
280
|
-
});
|
|
281
|
-
constructedTypes[type.id][gisTypeKey] = newWithHooks(GraphQLObjectType, {
|
|
282
|
-
name: inflection.gisType(type, subtype, hasZ, hasM, srid),
|
|
283
|
-
interfaces: function interfaces() {
|
|
284
|
-
return [getGisInterface(type), getGisDimensionInterface(type, hasZ, hasM)];
|
|
285
|
-
},
|
|
286
|
-
fields: (_fields3 = {}, (0, _defineProperty2["default"])(_fields3, geojsonFieldName, {
|
|
287
|
-
type: GeoJSON,
|
|
288
|
-
resolve: function resolve(data, _args, _context, _resolveInfo) {
|
|
289
|
-
return pg2gql(data.__geojson, jsonType);
|
|
290
|
-
}
|
|
291
|
-
}), (0, _defineProperty2["default"])(_fields3, "srid", {
|
|
292
|
-
type: new GraphQLNonNull(GraphQLInt),
|
|
293
|
-
resolve: function resolve(data, _args, _context, _resolveInfo) {
|
|
294
|
-
return pg2gql(data.__srid, intType);
|
|
295
|
-
}
|
|
296
|
-
}), _fields3)
|
|
297
|
-
}, {
|
|
298
|
-
isPgGISType: true,
|
|
299
|
-
pgGISType: type,
|
|
300
|
-
pgGISTypeDetails: typeDetails
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return constructedTypes[type.id][gisTypeKey];
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
console.warn("Registering handler for ".concat(GEOGRAPHY_TYPE.id));
|
|
309
|
-
pgRegisterGqlInputTypeByTypeId(GEOGRAPHY_TYPE.id, function () {
|
|
310
|
-
return GeoJSON;
|
|
311
|
-
});
|
|
312
|
-
pg2GqlMapper[GEOGRAPHY_TYPE.id] = {
|
|
313
|
-
map: identity,
|
|
314
|
-
unmap: function unmap(o) {
|
|
315
|
-
return sql.fragment(_templateObject5(), sql.value(JSON.stringify(o)), sql.identifier(POSTGIS.namespaceName || 'public', 'geography'));
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
pgRegisterGqlTypeByTypeId(GEOGRAPHY_TYPE.id, function (_set, typeModifier) {
|
|
319
|
-
return getGisType(GEOGRAPHY_TYPE, typeModifier);
|
|
320
|
-
});
|
|
321
|
-
console.warn("Registering handler for ".concat(GEOMETRY_TYPE.id));
|
|
322
|
-
pgRegisterGqlInputTypeByTypeId(GEOMETRY_TYPE.id, function () {
|
|
323
|
-
return GeoJSON;
|
|
324
|
-
});
|
|
325
|
-
pg2GqlMapper[GEOMETRY_TYPE.id] = {
|
|
326
|
-
map: identity,
|
|
327
|
-
unmap: function unmap(o) {
|
|
328
|
-
return sql.fragment(_templateObject6(), sql.value(JSON.stringify(o)));
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
pgRegisterGqlTypeByTypeId(GEOMETRY_TYPE.id, function (_set, typeModifier) {
|
|
332
|
-
return getGisType(GEOMETRY_TYPE, typeModifier);
|
|
333
|
-
});
|
|
334
|
-
return _;
|
|
335
|
-
}, ['PostgisTypes'], ['PgTables'], ['PgTypes']);
|
|
336
|
-
builder.hook('GraphQLSchema', function (schema, build) {
|
|
337
|
-
if (!schema.types) {
|
|
338
|
-
schema.types = [];
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
schema.types = [].concat((0, _toConsumableArray2["default"])(schema.types), (0, _toConsumableArray2["default"])(build.pgGISIncludedTypes));
|
|
342
|
-
return schema;
|
|
343
|
-
});
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
var _default = plugin;
|
|
347
|
-
exports["default"] = _default;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _constants = require("./constants");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
var plugin = function plugin(builder) {
|
|
13
|
-
builder.hook('GraphQLObjectType:fields', function AddGeometriesToGeometryCollection(fields, build, context) {
|
|
14
|
-
var _context$scope = context.scope,
|
|
15
|
-
isPgGISType = _context$scope.isPgGISType,
|
|
16
|
-
pgGISType = _context$scope.pgGISType,
|
|
17
|
-
pgGISTypeDetails = _context$scope.pgGISTypeDetails;
|
|
18
|
-
|
|
19
|
-
if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== _constants.GIS_SUBTYPE.GeometryCollection) {
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var extend = build.extend,
|
|
24
|
-
pgGISGraphQLInterfaceTypesByType = build.pgGISGraphQLInterfaceTypesByType,
|
|
25
|
-
GraphQLList = build.graphql.GraphQLList;
|
|
26
|
-
var hasZ = pgGISTypeDetails.hasZ,
|
|
27
|
-
hasM = pgGISTypeDetails.hasM;
|
|
28
|
-
var zmflag = (hasZ ? 2 : 0) + (hasM ? 1 : 0); // Equivalent to ST_Zmflag: https://postgis.net/docs/ST_Zmflag.html
|
|
29
|
-
|
|
30
|
-
var Interface = pgGISGraphQLInterfaceTypesByType[pgGISType.id][zmflag];
|
|
31
|
-
|
|
32
|
-
if (!Interface) {
|
|
33
|
-
console.warn("Unexpectedly couldn't find the interface");
|
|
34
|
-
return fields;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return extend(fields, {
|
|
38
|
-
geometries: {
|
|
39
|
-
type: new GraphQLList(Interface),
|
|
40
|
-
resolve: function resolve(data) {
|
|
41
|
-
return data.__geojson.geometries.map(function (geom) {
|
|
42
|
-
return {
|
|
43
|
-
__gisType: (0, _utils.getGISTypeName)(_constants.GIS_SUBTYPE[geom.type], hasZ, hasM),
|
|
44
|
-
__srid: data.__srid,
|
|
45
|
-
__geojson: geom
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
var _default = plugin;
|
|
55
|
-
exports["default"] = _default;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _constants = require("./constants");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
var plugin = function plugin(builder) {
|
|
13
|
-
builder.hook('GraphQLObjectType:fields', function (fields, build, context) {
|
|
14
|
-
var _context$scope = context.scope,
|
|
15
|
-
isPgGISType = _context$scope.isPgGISType,
|
|
16
|
-
pgGISType = _context$scope.pgGISType,
|
|
17
|
-
pgGISTypeDetails = _context$scope.pgGISTypeDetails;
|
|
18
|
-
|
|
19
|
-
if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== _constants.GIS_SUBTYPE.LineString) {
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var extend = build.extend,
|
|
24
|
-
getPostgisTypeByGeometryType = build.getPostgisTypeByGeometryType,
|
|
25
|
-
GraphQLList = build.graphql.GraphQLList;
|
|
26
|
-
var hasZ = pgGISTypeDetails.hasZ,
|
|
27
|
-
hasM = pgGISTypeDetails.hasM,
|
|
28
|
-
srid = pgGISTypeDetails.srid;
|
|
29
|
-
var Point = getPostgisTypeByGeometryType(pgGISType, _constants.GIS_SUBTYPE.Point, hasZ, hasM, srid);
|
|
30
|
-
return extend(fields, {
|
|
31
|
-
points: {
|
|
32
|
-
type: new GraphQLList(Point),
|
|
33
|
-
resolve: function resolve(data) {
|
|
34
|
-
return data.__geojson.coordinates.map(function (coord) {
|
|
35
|
-
return {
|
|
36
|
-
__gisType: (0, _utils.getGISTypeName)(_constants.GIS_SUBTYPE.Point, hasZ, hasM),
|
|
37
|
-
__srid: data.__srid,
|
|
38
|
-
__geojson: {
|
|
39
|
-
type: 'Point',
|
|
40
|
-
coordinates: coord
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var _default = plugin;
|
|
51
|
-
exports["default"] = _default;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
|
|
8
|
-
var _constants = require("./constants");
|
|
9
|
-
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
|
|
12
|
-
var plugin = function plugin(builder) {
|
|
13
|
-
builder.hook('GraphQLObjectType:fields', function (fields, build, context) {
|
|
14
|
-
var _context$scope = context.scope,
|
|
15
|
-
isPgGISType = _context$scope.isPgGISType,
|
|
16
|
-
pgGISType = _context$scope.pgGISType,
|
|
17
|
-
pgGISTypeDetails = _context$scope.pgGISTypeDetails;
|
|
18
|
-
|
|
19
|
-
if (!isPgGISType || !pgGISTypeDetails || pgGISTypeDetails.subtype !== _constants.GIS_SUBTYPE.MultiLineString) {
|
|
20
|
-
return fields;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var extend = build.extend,
|
|
24
|
-
getPostgisTypeByGeometryType = build.getPostgisTypeByGeometryType,
|
|
25
|
-
GraphQLList = build.graphql.GraphQLList;
|
|
26
|
-
var hasZ = pgGISTypeDetails.hasZ,
|
|
27
|
-
hasM = pgGISTypeDetails.hasM,
|
|
28
|
-
srid = pgGISTypeDetails.srid;
|
|
29
|
-
var LineString = getPostgisTypeByGeometryType(pgGISType, _constants.GIS_SUBTYPE.LineString, hasZ, hasM, srid);
|
|
30
|
-
return extend(fields, {
|
|
31
|
-
lines: {
|
|
32
|
-
type: new GraphQLList(LineString),
|
|
33
|
-
resolve: function resolve(data) {
|
|
34
|
-
return data.__geojson.coordinates.map(function (coord) {
|
|
35
|
-
return {
|
|
36
|
-
__gisType: (0, _utils.getGISTypeName)(_constants.GIS_SUBTYPE.LineString, hasZ, hasM),
|
|
37
|
-
__srid: data.__srid,
|
|
38
|
-
__geojson: {
|
|
39
|
-
type: 'LineString',
|
|
40
|
-
coordinates: coord
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var _default = plugin;
|
|
51
|
-
exports["default"] = _default;
|