@centia-io/sdk 0.2.12 → 0.2.13

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.
@@ -3046,6 +3046,157 @@
3046
3046
  }
3047
3047
  };
3048
3048
 
3049
+ //#endregion
3050
+ //#region src/ogc/Ogc.ts
3051
+ /** Default CRS of the OGC API: WGS 84 in longitude/latitude order. */
3052
+ const OGC_CRS84 = "http://www.opengis.net/def/crs/OGC/1.3/CRS84";
3053
+ /**
3054
+ * CRS URI for an EPSG code, e.g. `ogcEpsgCrs(25832)`. Note that
3055
+ * `ogcEpsgCrs(4326)` is latitude/longitude order; use `OGC_CRS84` for lon/lat.
3056
+ */
3057
+ function ogcEpsgCrs(epsg) {
3058
+ return `http://www.opengis.net/def/crs/EPSG/0/${epsg}`;
3059
+ }
3060
+ function bboxToString(bbox) {
3061
+ return typeof bbox === "string" ? bbox : bbox.join(",");
3062
+ }
3063
+ function spatialQuery(options) {
3064
+ const query = {};
3065
+ if ((options === null || options === void 0 ? void 0 : options.bbox) !== void 0) query.bbox = bboxToString(options.bbox);
3066
+ if ((options === null || options === void 0 ? void 0 : options.bboxCrs) !== void 0) query["bbox-crs"] = options.bboxCrs;
3067
+ if ((options === null || options === void 0 ? void 0 : options.crs) !== void 0) query.crs = options.crs;
3068
+ if ((options === null || options === void 0 ? void 0 : options.datetime) !== void 0) query.datetime = options.datetime;
3069
+ return query;
3070
+ }
3071
+ function nonEmpty(query) {
3072
+ return Object.keys(query).length > 0 ? query : void 0;
3073
+ }
3074
+ /**
3075
+ * OGC API Features (Part 1 Core, Part 2 CRS) and OGC API Maps (Part 1 Core)
3076
+ * wrapper for `/api/v4/ogc/database/{database}`.
3077
+ *
3078
+ * The endpoints accept Bearer token, HTTP Basic and anonymous requests. A
3079
+ * Bearer token must match the `database` in the path. Anonymous callers read
3080
+ * layers below `Read/write`; a `Read/write` collection answers 401 (Basic
3081
+ * challenge) for anonymous callers and 403 for identities without privilege.
3082
+ * Geofence rules, versioning and workflow are applied server-side.
3083
+ *
3084
+ * Map images cannot be fetched through this client; use `mapUrl` /
3085
+ * `datasetMapUrl` to build image URLs for `<img>` tags or map libraries.
3086
+ *
3087
+ * ```ts
3088
+ * const ogc = new Ogc(createCentiaClient({ baseUrl, auth }));
3089
+ * const page = await ogc.getItems('my_database', 'my_schema.roads', { bbox: [9, 55, 10, 56], limit: 100 });
3090
+ * ```
3091
+ */
3092
+ var Ogc = class {
3093
+ constructor(client) {
3094
+ this.client = client;
3095
+ }
3096
+ basePath(database) {
3097
+ return `api/v4/ogc/database/${encodeURIComponent(database)}`;
3098
+ }
3099
+ collectionPath(database, collectionId) {
3100
+ return `${this.basePath(database)}/collections/${encodeURIComponent(collectionId)}`;
3101
+ }
3102
+ /** The landing page with links to conformance, collections and the OpenAPI document. */
3103
+ async getLandingPage(database) {
3104
+ var _this = this;
3105
+ return _this.client.request({
3106
+ path: _this.basePath(database),
3107
+ method: "GET"
3108
+ });
3109
+ }
3110
+ /** Conformance classes implemented by the server. */
3111
+ async getConformance(database) {
3112
+ var _this2 = this;
3113
+ return _this2.client.request({
3114
+ path: `${_this2.basePath(database)}/conformance`,
3115
+ method: "GET"
3116
+ });
3117
+ }
3118
+ /** The collections (OWS-enabled layers) the caller may read, paged. */
3119
+ async getCollections(database, options) {
3120
+ var _this3 = this;
3121
+ const query = {};
3122
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) query.limit = String(options.limit);
3123
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) query.offset = String(options.offset);
3124
+ return _this3.client.request({
3125
+ path: `${_this3.basePath(database)}/collections`,
3126
+ method: "GET",
3127
+ query: nonEmpty(query)
3128
+ });
3129
+ }
3130
+ /**
3131
+ * One collection. Throws a `CentiaApiError` with status 404 (unknown),
3132
+ * 401 (anonymous caller, credentials required) or 403 (no privilege).
3133
+ */
3134
+ async getCollection(database, collectionId) {
3135
+ var _this4 = this;
3136
+ return _this4.client.request({
3137
+ path: _this4.collectionPath(database, collectionId),
3138
+ method: "GET"
3139
+ });
3140
+ }
3141
+ /**
3142
+ * Features of a collection as a GeoJSON FeatureCollection page. The default
3143
+ * page size is 10; follow `links` with `rel: 'next'` or pass `offset`.
3144
+ */
3145
+ async getItems(database, collectionId, options) {
3146
+ var _this5 = this;
3147
+ const query = {};
3148
+ if ((options === null || options === void 0 ? void 0 : options.limit) !== void 0) query.limit = String(options.limit);
3149
+ if ((options === null || options === void 0 ? void 0 : options.offset) !== void 0) query.offset = String(options.offset);
3150
+ Object.assign(query, spatialQuery(options));
3151
+ return _this5.client.request({
3152
+ path: `${_this5.collectionPath(database, collectionId)}/items`,
3153
+ method: "GET",
3154
+ query: nonEmpty(query),
3155
+ accept: "application/geo+json"
3156
+ });
3157
+ }
3158
+ /** One feature by primary key. Throws a 404 `CentiaApiError` when it does not exist. */
3159
+ async getItem(database, collectionId, featureId, options) {
3160
+ var _this6 = this;
3161
+ const query = {};
3162
+ if ((options === null || options === void 0 ? void 0 : options.crs) !== void 0) query.crs = options.crs;
3163
+ if ((options === null || options === void 0 ? void 0 : options.datetime) !== void 0) query.datetime = options.datetime;
3164
+ return _this6.client.request({
3165
+ path: `${_this6.collectionPath(database, collectionId)}/items/${encodeURIComponent(String(featureId))}`,
3166
+ method: "GET",
3167
+ query: nonEmpty(query),
3168
+ accept: "application/geo+json"
3169
+ });
3170
+ }
3171
+ /**
3172
+ * URL of a rendered map of one collection (PNG/JPEG), without fetching it.
3173
+ * Authorization travels in the `Authorization` header, so for protected
3174
+ * collections fetch the image with the header set (or use Basic auth).
3175
+ */
3176
+ mapUrl(database, collectionId, options) {
3177
+ return this.buildUrl(`${this.collectionPath(database, collectionId)}/map`, this.mapQuery(options));
3178
+ }
3179
+ /** URL of a rendered map of several collections of the same schema. */
3180
+ datasetMapUrl(database, collections, options) {
3181
+ const query = _objectSpread2({ collections: collections.join(",") }, this.mapQuery(options));
3182
+ return this.buildUrl(`${this.basePath(database)}/map`, query);
3183
+ }
3184
+ mapQuery(options) {
3185
+ const query = spatialQuery(options);
3186
+ if ((options === null || options === void 0 ? void 0 : options.width) !== void 0) query.width = String(options.width);
3187
+ if ((options === null || options === void 0 ? void 0 : options.height) !== void 0) query.height = String(options.height);
3188
+ if ((options === null || options === void 0 ? void 0 : options.format) !== void 0) query.f = options.format;
3189
+ if ((options === null || options === void 0 ? void 0 : options.transparent) !== void 0) query.transparent = String(options.transparent);
3190
+ if ((options === null || options === void 0 ? void 0 : options.bgcolor) !== void 0) query.bgcolor = options.bgcolor;
3191
+ return query;
3192
+ }
3193
+ buildUrl(path, query) {
3194
+ let url = `${this.client.baseUrl}/${path}`;
3195
+ if (Object.keys(query).length > 0) url += `?${new URLSearchParams(query).toString()}`;
3196
+ return url;
3197
+ }
3198
+ };
3199
+
3049
3200
  //#endregion
3050
3201
  //#region src/keyvalue/Keyvalue.ts
3051
3202
  /**
@@ -3314,6 +3465,8 @@ exports.Keyvalue = Keyvalue;
3314
3465
  exports.Mapcache = Mapcache;
3315
3466
  exports.Meta = Meta;
3316
3467
  exports.NotLoggedInError = NotLoggedInError;
3468
+ exports.OGC_CRS84 = OGC_CRS84;
3469
+ exports.Ogc = Ogc;
3317
3470
  exports.Ows = Ows;
3318
3471
  exports.PasswordFlow = PasswordFlow;
3319
3472
  exports.Rpc = Rpc;
@@ -3333,4 +3486,5 @@ exports.createCentiaClient = createCentiaClient;
3333
3486
  exports.createSqlBuilder = createSqlBuilder;
3334
3487
  exports.createTokenProvider = createTokenProvider;
3335
3488
  exports.isCentiaApiError = isCentiaApiError;
3489
+ exports.ogcEpsgCrs = ogcEpsgCrs;
3336
3490
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centia-io/sdk",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "Centia-io TypeScript SDK",
5
5
  "author": "Martin Høgh",
6
6
  "license": "MIT",