@vectoriahq/quac 0.10.0 → 0.12.0
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BoundingBox, QgsProject } from '../model/QgsProject.ts';
|
|
2
|
-
import type { StacCatalog } from '../model/Stac.ts';
|
|
2
|
+
import type { StacCatalog, StacCollection } from '../model/Stac.ts';
|
|
3
3
|
/**
|
|
4
4
|
* The catalogue a QGIS Server would serve for a project: the QUAC plugin's
|
|
5
5
|
* route, as a pure function of the project's text and the server's address, so
|
|
@@ -82,3 +82,25 @@ export interface ServerCatalogueOptions {
|
|
|
82
82
|
* 2026-11-07). The list is the same for every layer.
|
|
83
83
|
*/
|
|
84
84
|
export declare function serverWmsCrsList(project: QgsProject): string[];
|
|
85
|
+
/**
|
|
86
|
+
* How `withoutHiddenFields` reads the other layers a Collection refers to: the
|
|
87
|
+
* fields a layer hides, by its project layer id, and the id a layer is served
|
|
88
|
+
* under, or null where it is not served.
|
|
89
|
+
*/
|
|
90
|
+
export interface HiddenFieldContext {
|
|
91
|
+
hiddenOf: (layerId: string) => ReadonlySet<string>;
|
|
92
|
+
servedId: (layerId: string) => string | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A layer's Collection with every mention of the fields it hides from WMS or
|
|
96
|
+
* WFS dropped, as QGIS Server leaves them out of what it serves: its columns,
|
|
97
|
+
* its form order, its preset filters, its display field, a style's categorised
|
|
98
|
+
* field, a relation joined on a hidden field, and any expression that uses one.
|
|
99
|
+
* A lock whose expression uses one becomes `true`, and a field editable only
|
|
100
|
+
* while such an expression holds becomes read-only, so that hiding a field
|
|
101
|
+
* never unlocks an edit. A relation or Value Relation to a layer that is not
|
|
102
|
+
* served is dropped, and one to a served layer names it by its served id. For
|
|
103
|
+
* an application that serves a project's layers itself, as
|
|
104
|
+
* `generateServerStacCatalogue` does for QGIS Server.
|
|
105
|
+
*/
|
|
106
|
+
export declare function withoutHiddenFields(source: StacCollection, layerId: string, context: HiddenFieldContext): StacCollection;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildStacExtent, unionBboxes, withDataType } from "./normalizedProject.js";
|
|
2
2
|
import { serverLayerTree, wmsPublishedLayerIds } from "./serverLayerTree.js";
|
|
3
|
-
import { generateStacCatalogue } from "./stacCatalogue.js";
|
|
3
|
+
import { generateStacCatalogue, QUAC_CATEGORISED_FIELD } from "./stacCatalogue.js";
|
|
4
4
|
import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
|
|
5
5
|
import { mapQtTypeToStacTableType } from "./wmsStacCatalogue.js";
|
|
6
6
|
import { declareQuacExtension, QUAC_SCHEMA_URL } from "../model/quacExtension.js";
|
|
@@ -185,8 +185,6 @@ function mentionsAny(expression, fields) {
|
|
|
185
185
|
const SOURCE_FIELDS = ['quac:wfs_endpoint', 'quac:wfs_type_name', 'quac:wfs_srs_name', 'quac:arcgis_layer_url', 'quac:arcgis_where', 'quac:max_zoom'];
|
|
186
186
|
function serveCollection(source, context) {
|
|
187
187
|
const layerId = source.id;
|
|
188
|
-
const layer = context.layersById.get(layerId);
|
|
189
|
-
const hidden = hiddenFieldsOf(layer);
|
|
190
188
|
const wmsName = context.servedIds.get(layerId);
|
|
191
189
|
const wfsTypeName = context.wfsPublished.has(layerId) ? source['quac:qgis_server_wfs_type_name'] : undefined;
|
|
192
190
|
const collection = { ...source, id: wmsName, links: [], assets: {} };
|
|
@@ -210,13 +208,36 @@ function serveCollection(source, context) {
|
|
|
210
208
|
collection.stac_extensions = extensions;
|
|
211
209
|
else
|
|
212
210
|
delete collection.stac_extensions;
|
|
211
|
+
const shown = withoutHiddenFields(collection, layerId, {
|
|
212
|
+
hiddenOf: (id) => hiddenFieldsOf(context.layersById.get(id)),
|
|
213
|
+
servedId: (id) => context.servedIds.get(id) ?? null
|
|
214
|
+
});
|
|
215
|
+
serveFieldTypes(shown, context.fieldTypes[layerId] ?? {});
|
|
216
|
+
return shown;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* A layer's Collection with every mention of the fields it hides from WMS or
|
|
220
|
+
* WFS dropped, as QGIS Server leaves them out of what it serves: its columns,
|
|
221
|
+
* its form order, its preset filters, its display field, a style's categorised
|
|
222
|
+
* field, a relation joined on a hidden field, and any expression that uses one.
|
|
223
|
+
* A lock whose expression uses one becomes `true`, and a field editable only
|
|
224
|
+
* while such an expression holds becomes read-only, so that hiding a field
|
|
225
|
+
* never unlocks an edit. A relation or Value Relation to a layer that is not
|
|
226
|
+
* served is dropped, and one to a served layer names it by its served id. For
|
|
227
|
+
* an application that serves a project's layers itself, as
|
|
228
|
+
* `generateServerStacCatalogue` does for QGIS Server.
|
|
229
|
+
*/
|
|
230
|
+
export function withoutHiddenFields(source, layerId, context) {
|
|
231
|
+
const collection = { ...source };
|
|
232
|
+
const hidden = new Set(context.hiddenOf(layerId));
|
|
213
233
|
if (hidden.has(String(collection['quac:display_field'])))
|
|
214
234
|
delete collection['quac:display_field'];
|
|
215
235
|
serveFormOrder(collection, hidden);
|
|
216
236
|
serveFilters(collection, hidden);
|
|
217
237
|
serveRelations(collection, hidden, context);
|
|
218
238
|
serveLocks(collection, hidden);
|
|
219
|
-
serveColumns(collection, hidden, context
|
|
239
|
+
serveColumns(collection, hidden, context);
|
|
240
|
+
serveStyleFields(collection, hidden);
|
|
220
241
|
return collection;
|
|
221
242
|
}
|
|
222
243
|
function serveFormOrder(collection, hidden) {
|
|
@@ -239,10 +260,10 @@ function serveRelations(collection, hidden, context) {
|
|
|
239
260
|
if (!Array.isArray(relations))
|
|
240
261
|
return;
|
|
241
262
|
const kept = relations.flatMap((relation) => {
|
|
242
|
-
const parentId = context.
|
|
263
|
+
const parentId = context.servedId(relation.parent_collection_id);
|
|
243
264
|
if (!parentId)
|
|
244
265
|
return [];
|
|
245
|
-
const parentHidden =
|
|
266
|
+
const parentHidden = context.hiddenOf(relation.parent_collection_id);
|
|
246
267
|
if (relation.fields.some((pair) => hidden.has(pair.child) || parentHidden.has(pair.parent)))
|
|
247
268
|
return [];
|
|
248
269
|
return [{ ...relation, parent_collection_id: parentId }];
|
|
@@ -262,19 +283,40 @@ function serveLocks(collection, hidden) {
|
|
|
262
283
|
}
|
|
263
284
|
collection['quac:locks'] = served;
|
|
264
285
|
}
|
|
265
|
-
function serveColumns(collection, hidden, context
|
|
286
|
+
function serveColumns(collection, hidden, context) {
|
|
266
287
|
const columns = collection['table:columns'];
|
|
267
288
|
if (!Array.isArray(columns))
|
|
268
289
|
return;
|
|
269
|
-
const fieldTypes = context.fieldTypes[layerId] ?? {};
|
|
270
290
|
const kept = columns
|
|
271
291
|
.filter((column) => !hidden.has(column.name))
|
|
272
|
-
.map((column) =>
|
|
292
|
+
.map((column) => serveColumn(column, hidden, context));
|
|
273
293
|
if (kept.length > 0)
|
|
274
294
|
collection['table:columns'] = kept;
|
|
275
295
|
else
|
|
276
296
|
delete collection['table:columns'];
|
|
277
297
|
}
|
|
298
|
+
/** Each column with the `type` QGIS Server reports for its field (`withFieldType`). */
|
|
299
|
+
function serveFieldTypes(collection, fieldTypes) {
|
|
300
|
+
const columns = collection['table:columns'];
|
|
301
|
+
if (Array.isArray(columns))
|
|
302
|
+
collection['table:columns'] = columns.map((column) => withFieldType(column, fieldTypes[column.name]));
|
|
303
|
+
}
|
|
304
|
+
/** A style asset's categorised field, dropped where the layer hides it. */
|
|
305
|
+
function serveStyleFields(collection, hidden) {
|
|
306
|
+
if (!collection.assets)
|
|
307
|
+
return;
|
|
308
|
+
const assets = {};
|
|
309
|
+
for (const [key, asset] of Object.entries(collection.assets)) {
|
|
310
|
+
if (hidden.has(String(asset[QUAC_CATEGORISED_FIELD]))) {
|
|
311
|
+
const served = { ...asset };
|
|
312
|
+
delete served[QUAC_CATEGORISED_FIELD];
|
|
313
|
+
assets[key] = served;
|
|
314
|
+
}
|
|
315
|
+
else
|
|
316
|
+
assets[key] = asset;
|
|
317
|
+
}
|
|
318
|
+
collection.assets = assets;
|
|
319
|
+
}
|
|
278
320
|
/** The column with the `type` QGIS Server reports for its field, and the `data_type` beside it, where QGIS Server reports one. */
|
|
279
321
|
function withFieldType(column, fieldType) {
|
|
280
322
|
const type = fieldType ? mapQtTypeToStacTableType(fieldType.type, fieldType.typeName) : undefined;
|
|
@@ -317,8 +359,8 @@ function serveColumn(source, hidden, context) {
|
|
|
317
359
|
}
|
|
318
360
|
const relation = column['quac:value_relation'];
|
|
319
361
|
if (relation) {
|
|
320
|
-
const lookupId = context.
|
|
321
|
-
const lookupHidden =
|
|
362
|
+
const lookupId = context.servedId(relation.collection);
|
|
363
|
+
const lookupHidden = context.hiddenOf(relation.collection);
|
|
322
364
|
const usesHidden = [relation.key, relation.value, relation.order_field].some((field) => field !== undefined && lookupHidden.has(field))
|
|
323
365
|
|| mentionsAny(relation.filter, lookupHidden)
|
|
324
366
|
|| mentionsAny(relation.filter, hidden);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldRange } from '../model/QgsProject.ts';
|
|
1
|
+
import type { FieldRange, FieldUuidFormat } from '../model/QgsProject.ts';
|
|
2
2
|
import type { StacCollection } from '../model/Stac.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Why a new feature's field is refused:
|
|
@@ -78,4 +78,11 @@ export declare function isBlankFieldValue(value: unknown): boolean;
|
|
|
78
78
|
* type deal with those. Text holding a number is read as that number.
|
|
79
79
|
*/
|
|
80
80
|
export declare function isOutsideFieldRange(value: unknown, range: Pick<FieldRange, 'min' | 'max'>): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* A new identifier written as QGIS's `uuid()` writes it, for a field whose
|
|
83
|
+
* default is one: `{…}` with hyphens (`with_braces`), hyphens alone
|
|
84
|
+
* (`without_braces`), or 32 hex digits (`id128`), as QGIS's `fcnUuid`
|
|
85
|
+
* (`QgsExpressionFunction`) writes them.
|
|
86
|
+
*/
|
|
87
|
+
export declare function newQgisUuid(format: FieldUuidFormat): string;
|
|
81
88
|
export {};
|
|
@@ -89,6 +89,20 @@ export function isOutsideFieldRange(value, range) {
|
|
|
89
89
|
return false;
|
|
90
90
|
return (range.min !== undefined && number < range.min) || (range.max !== undefined && number > range.max);
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* A new identifier written as QGIS's `uuid()` writes it, for a field whose
|
|
94
|
+
* default is one: `{…}` with hyphens (`with_braces`), hyphens alone
|
|
95
|
+
* (`without_braces`), or 32 hex digits (`id128`), as QGIS's `fcnUuid`
|
|
96
|
+
* (`QgsExpressionFunction`) writes them.
|
|
97
|
+
*/
|
|
98
|
+
export function newQgisUuid(format) {
|
|
99
|
+
const uuid = crypto.randomUUID();
|
|
100
|
+
if (format === 'without_braces')
|
|
101
|
+
return uuid;
|
|
102
|
+
if (format === 'id128')
|
|
103
|
+
return uuid.replaceAll('-', '');
|
|
104
|
+
return `{${uuid}}`;
|
|
105
|
+
}
|
|
92
106
|
const KNOWN_TYPES = new Set(['string', 'int', 'long', 'double', 'boolean', 'date', 'time', 'timestamp']);
|
|
93
107
|
const DATE_TYPES = new Set(['date', 'time', 'timestamp']);
|
|
94
108
|
function uncheckedRules(column, type, unique, dateFormat) {
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { readSqlFeatureTest } from './parse/sqlFeatureFilter.ts';
|
|
|
23
23
|
export type { FeatureTest } from './parse/sqlFeatureFilter.ts';
|
|
24
24
|
export { publishLayerFeatures } from './generate/publishLayer.ts';
|
|
25
25
|
export type { PublishedLayer, PublishRefusal } from './generate/publishLayer.ts';
|
|
26
|
-
export { validateNewFeature, readNewFeatureFields, isBlankFieldValue, isOutsideFieldRange } from './generate/validateNewFeature.ts';
|
|
26
|
+
export { validateNewFeature, readNewFeatureFields, isBlankFieldValue, isOutsideFieldRange, newQgisUuid } from './generate/validateNewFeature.ts';
|
|
27
27
|
export type { NewFeatureCheck, NewFeatureProblem, UncheckedFieldRule } from './generate/validateNewFeature.ts';
|
|
28
28
|
export type { FeatureFilter, FeatureFilterDialect } from './model/featureFilter.ts';
|
|
29
29
|
export type { DelimitedTextOptions } from './model/delimitedText.ts';
|
|
@@ -78,7 +78,8 @@ export { devLog } from './util/devLog.ts';
|
|
|
78
78
|
export { getFileNameFromPath, getLowerCaseExtension, getNormalisedFileBasename, getParentFolderPath } from './util/fileName.ts';
|
|
79
79
|
export { DEFAULT_WFS_VERSION, SPOKEN_WFS_VERSIONS, WFS_CAPABILITIES_VERSION, WFS_FALLBACK_VERSION } from './util/wfsVersions.ts';
|
|
80
80
|
export { QUAC_SCHEMA_URL, declareQuacExtension, isNewerQuacMajor, listQuacExtension, readQuacVersion } from './model/quacExtension.ts';
|
|
81
|
-
export { generateServerStacCatalogue } from './generate/serverStacCatalogue.ts';
|
|
81
|
+
export { generateServerStacCatalogue, withoutHiddenFields } from './generate/serverStacCatalogue.ts';
|
|
82
|
+
export type { HiddenFieldContext } from './generate/serverStacCatalogue.ts';
|
|
82
83
|
export { serverLayerTree } from './generate/serverLayerTree.ts';
|
|
83
84
|
export type { ServerLayerTree, ServerLayerTreeGroup, ServerLayerTreeLayer, ServerLayerTreeNode } from './generate/serverLayerTree.ts';
|
|
84
85
|
export { PROJ_CODE, PROJECTION_EXTENSION, readCollectionCrs } from './model/stacProjection.ts';
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export { DEFAULT_DELIMITED_TEXT_OPTIONS, QUAC_DELIMITED_TEXT, readCollectionDeli
|
|
|
17
17
|
export { QUAC_FEATURE_FILTER, readCollectionFeatureFilter } from "./model/featureFilter.js";
|
|
18
18
|
export { readSqlFeatureTest } from "./parse/sqlFeatureFilter.js";
|
|
19
19
|
export { publishLayerFeatures } from "./generate/publishLayer.js";
|
|
20
|
-
export { validateNewFeature, readNewFeatureFields, isBlankFieldValue, isOutsideFieldRange } from "./generate/validateNewFeature.js";
|
|
20
|
+
export { validateNewFeature, readNewFeatureFields, isBlankFieldValue, isOutsideFieldRange, newQgisUuid } from "./generate/validateNewFeature.js";
|
|
21
21
|
export { decodeAssetPath, encodeAssetPath, isRelativeHref, readCollectionDataPath, readCollectionOnlineFile } from "./model/stacHref.js";
|
|
22
22
|
export { DATA_ROLE, findAssetByRole, readDataAsset } from "./model/stacAssetRoles.js";
|
|
23
23
|
export { THUMBNAIL_ROLE, readCollectionAttribution, readCollectionDeprecation, readCollectionSelfHref, readCollectionThumbnail } from "./model/stacCollectionNotes.js";
|
|
@@ -51,6 +51,6 @@ export { devLog } from "./util/devLog.js";
|
|
|
51
51
|
export { getFileNameFromPath, getLowerCaseExtension, getNormalisedFileBasename, getParentFolderPath } from "./util/fileName.js";
|
|
52
52
|
export { DEFAULT_WFS_VERSION, SPOKEN_WFS_VERSIONS, WFS_CAPABILITIES_VERSION, WFS_FALLBACK_VERSION } from "./util/wfsVersions.js";
|
|
53
53
|
export { QUAC_SCHEMA_URL, declareQuacExtension, isNewerQuacMajor, listQuacExtension, readQuacVersion } from "./model/quacExtension.js";
|
|
54
|
-
export { generateServerStacCatalogue } from "./generate/serverStacCatalogue.js";
|
|
54
|
+
export { generateServerStacCatalogue, withoutHiddenFields } from "./generate/serverStacCatalogue.js";
|
|
55
55
|
export { serverLayerTree } from "./generate/serverLayerTree.js";
|
|
56
56
|
export { PROJ_CODE, PROJECTION_EXTENSION, readCollectionCrs } from "./model/stacProjection.js";
|