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