@vectoriahq/quac 0.0.0-stage → 0.2.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.
- package/LICENSE +202 -0
- package/README.md +35 -2
- package/dist/generate/arcgisStacCatalogue.d.ts +46 -0
- package/dist/generate/arcgisStacCatalogue.js +189 -0
- package/dist/generate/externalStacCatalogue.d.ts +53 -0
- package/dist/generate/externalStacCatalogue.js +143 -0
- package/dist/generate/fileLayerCollection.d.ts +44 -0
- package/dist/generate/fileLayerCollection.js +72 -0
- package/dist/generate/folderStacCatalogue.d.ts +48 -0
- package/dist/generate/folderStacCatalogue.js +69 -0
- package/dist/generate/normalizedProject.d.ts +452 -0
- package/dist/generate/normalizedProject.js +877 -0
- package/dist/generate/ogcFeaturesStacCatalogue.d.ts +49 -0
- package/dist/generate/ogcFeaturesStacCatalogue.js +207 -0
- package/dist/generate/qmlForLayer.d.ts +17 -0
- package/dist/generate/qmlForLayer.js +36 -0
- package/dist/generate/serverLayerTree.d.ts +44 -0
- package/dist/generate/serverLayerTree.js +50 -0
- package/dist/generate/serverStacCatalogue.d.ts +84 -0
- package/dist/generate/serverStacCatalogue.js +327 -0
- package/dist/generate/stacCatalogue.d.ts +110 -0
- package/dist/generate/stacCatalogue.js +887 -0
- package/dist/generate/wfsStacCatalogue.d.ts +37 -0
- package/dist/generate/wfsStacCatalogue.js +127 -0
- package/dist/generate/wmsStacCatalogue.d.ts +46 -0
- package/dist/generate/wmsStacCatalogue.js +229 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +52 -0
- package/dist/model/QgsProject.d.ts +724 -0
- package/dist/model/QgsProject.js +15 -0
- package/dist/model/Stac.d.ts +322 -0
- package/dist/model/Stac.js +16 -0
- package/dist/model/WmsProject.d.ts +105 -0
- package/dist/model/WmsProject.js +1 -0
- package/dist/model/arcgis.d.ts +134 -0
- package/dist/model/arcgis.js +1 -0
- package/dist/model/delimitedText.d.ts +38 -0
- package/dist/model/delimitedText.js +46 -0
- package/dist/model/featureFilter.d.ts +41 -0
- package/dist/model/featureFilter.js +24 -0
- package/dist/model/fieldIconAddress.d.ts +27 -0
- package/dist/model/fieldIconAddress.js +93 -0
- package/dist/model/ogcFeatures.d.ts +40 -0
- package/dist/model/ogcFeatures.js +6 -0
- package/dist/model/quacExtension.d.ts +28 -0
- package/dist/model/quacExtension.js +75 -0
- package/dist/model/stacAssetRoles.d.ts +33 -0
- package/dist/model/stacAssetRoles.js +44 -0
- package/dist/model/stacCollectionNotes.d.ts +21 -0
- package/dist/model/stacCollectionNotes.js +44 -0
- package/dist/model/stacHref.d.ts +56 -0
- package/dist/model/stacHref.js +93 -0
- package/dist/model/stacPmtiles.d.ts +38 -0
- package/dist/model/stacPmtiles.js +69 -0
- package/dist/model/stacSizeAndCount.d.ts +14 -0
- package/dist/model/stacSizeAndCount.js +20 -0
- package/dist/model/stacStyles.d.ts +93 -0
- package/dist/model/stacStyles.js +87 -0
- package/dist/model/stacTreeWalk.d.ts +36 -0
- package/dist/model/stacTreeWalk.js +76 -0
- package/dist/model/stacWms.d.ts +18 -0
- package/dist/model/stacWms.js +73 -0
- package/dist/model/stacWmts.d.ts +34 -0
- package/dist/model/stacWmts.js +90 -0
- package/dist/model/stacXyz.d.ts +24 -0
- package/dist/model/stacXyz.js +46 -0
- package/dist/model/wfs.d.ts +136 -0
- package/dist/model/wfs.js +1 -0
- package/dist/parse/collectLayerVisibility.d.ts +10 -0
- package/dist/parse/collectLayerVisibility.js +22 -0
- package/dist/parse/customProperties.d.ts +18 -0
- package/dist/parse/customProperties.js +43 -0
- package/dist/parse/geometrySiblings.d.ts +25 -0
- package/dist/parse/geometrySiblings.js +83 -0
- package/dist/parse/parseBrandColour.d.ts +14 -0
- package/dist/parse/parseBrandColour.js +25 -0
- package/dist/parse/parseDataDefinedEditable.d.ts +38 -0
- package/dist/parse/parseDataDefinedEditable.js +76 -0
- package/dist/parse/parseDataSource.d.ts +53 -0
- package/dist/parse/parseDataSource.js +484 -0
- package/dist/parse/parseExtent.d.ts +17 -0
- package/dist/parse/parseExtent.js +49 -0
- package/dist/parse/parseFormLayout.d.ts +26 -0
- package/dist/parse/parseFormLayout.js +60 -0
- package/dist/parse/parseGetProjectSettings.d.ts +15 -0
- package/dist/parse/parseGetProjectSettings.js +172 -0
- package/dist/parse/parseLayers.d.ts +23 -0
- package/dist/parse/parseLayers.js +1125 -0
- package/dist/parse/parseLegendTree.d.ts +20 -0
- package/dist/parse/parseLegendTree.js +66 -0
- package/dist/parse/parseMeasurement.d.ts +20 -0
- package/dist/parse/parseMeasurement.js +66 -0
- package/dist/parse/parseMergin.d.ts +19 -0
- package/dist/parse/parseMergin.js +51 -0
- package/dist/parse/parseProjectVariables.d.ts +9 -0
- package/dist/parse/parseProjectVariables.js +19 -0
- package/dist/parse/parseQfieldSync.d.ts +47 -0
- package/dist/parse/parseQfieldSync.js +95 -0
- package/dist/parse/parseQgsXml.d.ts +15 -0
- package/dist/parse/parseQgsXml.js +100 -0
- package/dist/parse/parseRelations.d.ts +19 -0
- package/dist/parse/parseRelations.js +64 -0
- package/dist/parse/parseStyle.d.ts +33 -0
- package/dist/parse/parseStyle.js +128 -0
- package/dist/parse/parseWmsPublishing.d.ts +21 -0
- package/dist/parse/parseWmsPublishing.js +38 -0
- package/dist/parse/projectProperties.d.ts +15 -0
- package/dist/parse/projectProperties.js +27 -0
- package/dist/parse/qgisExpression.d.ts +194 -0
- package/dist/parse/qgisExpression.js +859 -0
- package/dist/parse/qtDateFormat.d.ts +74 -0
- package/dist/parse/qtDateFormat.js +324 -0
- package/dist/parse/qtRegex.d.ts +67 -0
- package/dist/parse/qtRegex.js +397 -0
- package/dist/parse/readProjectFile.d.ts +7 -0
- package/dist/parse/readProjectFile.js +27 -0
- package/dist/sources/qgisServerUrl.d.ts +6 -0
- package/dist/sources/qgisServerUrl.js +17 -0
- package/dist/sources/stacDocuments.d.ts +40 -0
- package/dist/sources/stacDocuments.js +85 -0
- package/dist/sources/stacItems.d.ts +109 -0
- package/dist/sources/stacItems.js +287 -0
- package/dist/util/catalogueFileFormats.d.ts +58 -0
- package/dist/util/catalogueFileFormats.js +64 -0
- package/dist/util/devLog.d.ts +10 -0
- package/dist/util/devLog.js +22 -0
- package/dist/util/fileName.d.ts +18 -0
- package/dist/util/fileName.js +45 -0
- package/dist/util/nonBlankText.d.ts +2 -0
- package/dist/util/nonBlankText.js +4 -0
- package/dist/util/wfsVersions.d.ts +9 -0
- package/dist/util/wfsVersions.js +13 -0
- package/package.json +55 -4
- package/src/schema/quac.schema.json +939 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { buildStacExtent, unionBboxes, withDataType } from "./normalizedProject.js";
|
|
2
|
+
import { serverLayerTree, wmsPublishedLayerIds } from "./serverLayerTree.js";
|
|
3
|
+
import { generateStacCatalogue } from "./stacCatalogue.js";
|
|
4
|
+
import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
|
|
5
|
+
import { mapQtTypeToStacTableType } from "./wmsStacCatalogue.js";
|
|
6
|
+
import { declareQuacExtension, QUAC_SCHEMA_URL } from "../model/quacExtension.js";
|
|
7
|
+
import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, WMS_REQUEST_PARAMETERS } from "../model/stacWms.js";
|
|
8
|
+
/**
|
|
9
|
+
* The catalogue a QGIS Server would serve for a project: the QUAC plugin's
|
|
10
|
+
* route, as a pure function of the project's text and the server's address, so
|
|
11
|
+
* that the plugin's Python port has one function to agree with.
|
|
12
|
+
*
|
|
13
|
+
* It starts from the catalogue a project file gives (`generateStacCatalogue`)
|
|
14
|
+
* and applies the project's own QGIS Server settings, as GetProjectSettings
|
|
15
|
+
* does:
|
|
16
|
+
*
|
|
17
|
+
* - A layer or group whose name the project leaves out of WMS
|
|
18
|
+
* (`WMSRestrictedLayers`) is left out, with every layer inside the group. A
|
|
19
|
+
* layer published for WFS but left out of WMS is left out too, because a
|
|
20
|
+
* server's Collection id is the WMS name (D1). A file the project splits into
|
|
21
|
+
* a layer per shape is left out: the project route writes it as one
|
|
22
|
+
* Collection, and QGIS Server names each of its layers separately.
|
|
23
|
+
* - Each Collection's id is the layer's WMS name, and every reference to
|
|
24
|
+
* another Collection is rewritten to that id or, where that Collection is not
|
|
25
|
+
* served, dropped.
|
|
26
|
+
* - Its data is reached through the server only: a WFS GetFeature data asset
|
|
27
|
+
* where the project publishes the layer for WFS, and a WMS link always, in
|
|
28
|
+
* the CRS `chooseWmsCrs` picks from `serverWmsCrsList`. No
|
|
29
|
+
* file path, style asset, `via` link or detail of the layer's own data source
|
|
30
|
+
* is written, nor an Attachment widget's default folder.
|
|
31
|
+
* - A field the project hides from WMS or from WFS is left out of
|
|
32
|
+
* `table:columns`, and every mention of it is dropped: from the form order,
|
|
33
|
+
* the preset filters, the display field, a relation's join, and any
|
|
34
|
+
* expression that uses it, except that a lock's expression becomes `true`
|
|
35
|
+
* and a field editable only while an expression holds becomes read-only, so
|
|
36
|
+
* that hiding a field never unlocks an edit.
|
|
37
|
+
*
|
|
38
|
+
* - The top-level Catalog's extent covers the served layers only, so a layer the
|
|
39
|
+
* project keeps off the web does not widen it.
|
|
40
|
+
*
|
|
41
|
+
* Two inputs come from QGIS Server rather than the project's text, which does
|
|
42
|
+
* not hold them: each field's type, as GetProjectSettings reports it, which
|
|
43
|
+
* gives the column its `type`; and the WGS84 box of a layer whose project saves
|
|
44
|
+
* no `<wgs84extent>`. A field or layer left out of them has none.
|
|
45
|
+
*
|
|
46
|
+
* The access answers of the person asking are not applied; the plugin applies
|
|
47
|
+
* them to this function's result.
|
|
48
|
+
*
|
|
49
|
+
* Throws for a server address that `serverWmsEndpoint` refuses: one that is not
|
|
50
|
+
* an `http` or `https` address, has no host, holds a space or a control
|
|
51
|
+
* character, or holds a user name or password, which every served data address
|
|
52
|
+
* would repeat.
|
|
53
|
+
*/
|
|
54
|
+
export function generateServerStacCatalogue(project, options) {
|
|
55
|
+
const wmsHref = serverWmsEndpoint(options.serverAddress);
|
|
56
|
+
if (!wmsHref)
|
|
57
|
+
throw new Error('The server address must be an http or https address with a host, and hold no user name, password, space or control character, in its query either.');
|
|
58
|
+
const layerWgs84Extents = options.layerWgs84Extents ?? {};
|
|
59
|
+
const catalogue = generateStacCatalogue(project, [], { layerWgs84Extents: new Map(Object.entries(layerWgs84Extents)) });
|
|
60
|
+
const layersById = new Map(project.layers.map((layer) => [layer.id, layer]));
|
|
61
|
+
const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
|
|
62
|
+
const servedLayerIds = wmsPublishedLayerIds(serverLayerTree(project));
|
|
63
|
+
const wfsPublished = new Set(project.wfsTransactionLayers?.published ?? []);
|
|
64
|
+
const servedIds = new Map();
|
|
65
|
+
const walkIds = (node) => {
|
|
66
|
+
for (const collection of node.collections ?? []) {
|
|
67
|
+
const wmsName = collection['quac:qgis_server_wms_name'];
|
|
68
|
+
if (servedLayerIds.has(collection.id) && typeof wmsName === 'string')
|
|
69
|
+
servedIds.set(collection.id, wmsName);
|
|
70
|
+
}
|
|
71
|
+
for (const child of node.catalogs ?? [])
|
|
72
|
+
walkIds(child);
|
|
73
|
+
};
|
|
74
|
+
walkIds(catalogue);
|
|
75
|
+
const context = {
|
|
76
|
+
layersById,
|
|
77
|
+
servedIds,
|
|
78
|
+
wfsPublished,
|
|
79
|
+
serverAddress: options.serverAddress,
|
|
80
|
+
wmsHref,
|
|
81
|
+
wmsCrs: chooseWmsCrs(serverWmsCrsList(project)),
|
|
82
|
+
fieldTypes: options.fieldTypes ?? {}
|
|
83
|
+
};
|
|
84
|
+
const serveCatalog = (node) => {
|
|
85
|
+
const collections = (node.collections ?? []).filter((collection) => servedIds.has(collection.id)).map((collection) => serveCollection(collection, context));
|
|
86
|
+
const catalogs = (node.catalogs ?? []).filter((child) => !restricted.has(child.title ?? '')).map(serveCatalog);
|
|
87
|
+
const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(collections, catalogs)] };
|
|
88
|
+
delete served.collections;
|
|
89
|
+
delete served.catalogs;
|
|
90
|
+
delete served.stac_extensions;
|
|
91
|
+
if (collections.length > 0)
|
|
92
|
+
served.collections = collections;
|
|
93
|
+
if (catalogs.length > 0)
|
|
94
|
+
served.catalogs = catalogs;
|
|
95
|
+
return served;
|
|
96
|
+
};
|
|
97
|
+
const served = serveCatalog(catalogue);
|
|
98
|
+
const servedBox = unionBboxes([...servedIds.keys()].map((layerId) => layersById.get(layerId)?.wgs84Extent ?? layerWgs84Extents[layerId] ?? null));
|
|
99
|
+
if (servedBox)
|
|
100
|
+
served['extent'] = buildStacExtent(servedBox);
|
|
101
|
+
else
|
|
102
|
+
delete served['extent'];
|
|
103
|
+
const active = served['quac:active_collection'];
|
|
104
|
+
const activeId = typeof active === 'string' ? servedIds.get(active) : undefined;
|
|
105
|
+
if (activeId)
|
|
106
|
+
served['quac:active_collection'] = activeId;
|
|
107
|
+
else
|
|
108
|
+
delete served['quac:active_collection'];
|
|
109
|
+
return declareQuacExtension(served);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The address a served layer's WMS link names: the server's address as
|
|
113
|
+
* written, its scheme lower-cased, less its fragment and any query parameter a
|
|
114
|
+
* WMS request sets, such as `SERVICE` or `REQUEST`. Other parameters, such as
|
|
115
|
+
* `MAP`, are kept as written. The rule is spelled out rather than left to the
|
|
116
|
+
* `URL` class, so that the plugin's Python gives the same address.
|
|
117
|
+
* Null for an address that is not
|
|
118
|
+
* `http` or `https`, has no host, holds a user name or password, or holds a
|
|
119
|
+
* space or a control character. A query holding `@` or the word `password`,
|
|
120
|
+
* in any case and escaped or not, is refused too: it may hold a project's
|
|
121
|
+
* database connection, such as `MAP=postgresql://user:secret@db/…`, which every
|
|
122
|
+
* served address would repeat.
|
|
123
|
+
*/
|
|
124
|
+
export function serverWmsEndpoint(serverAddress) {
|
|
125
|
+
if ([...serverAddress].some((char) => char.charCodeAt(0) <= 0x20 || char.charCodeAt(0) === 0x7f))
|
|
126
|
+
return null;
|
|
127
|
+
const match = /^(https?):\/\/([^/?#]*)([^?#]*)(?:\?([^#]*))?/i.exec(serverAddress);
|
|
128
|
+
if (!match)
|
|
129
|
+
return null;
|
|
130
|
+
const [, scheme, authority, path, query] = match;
|
|
131
|
+
if (!authority || authority.includes('@'))
|
|
132
|
+
return null;
|
|
133
|
+
if (/@|%40|password/i.test(query ?? ''))
|
|
134
|
+
return null;
|
|
135
|
+
const kept = (query ?? '').split('&').filter((pair) => pair !== '' && !WMS_REQUEST_PARAMETERS.has(pair.split('=')[0].toUpperCase()));
|
|
136
|
+
return `${scheme.toLowerCase()}://${authority}${path}${kept.length > 0 ? `?${kept.join('&')}` : ''}`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The CRSs QGIS Server offers a project's WMS layers in: the project's
|
|
140
|
+
* restriction where it saves one, else the project's own CRS, EPSG:4326 and
|
|
141
|
+
* EPSG:3857 (`QgsServerProjectUtils::wmsOutputCrsList`,
|
|
142
|
+
* `src/server/qgsserverprojectutils.cpp`, `qgis/QGIS@master`, read
|
|
143
|
+
* 2026-11-07). The list is the same for every layer.
|
|
144
|
+
*/
|
|
145
|
+
export function serverWmsCrsList(project) {
|
|
146
|
+
if (project.wmsCrsList && project.wmsCrsList.length > 0)
|
|
147
|
+
return [...project.wmsCrsList];
|
|
148
|
+
const projectCrs = project.projectCrs ?? '';
|
|
149
|
+
const crsList = [projectCrs];
|
|
150
|
+
if (projectCrs.toUpperCase() !== 'EPSG:4326')
|
|
151
|
+
crsList.push('EPSG:4326');
|
|
152
|
+
if (projectCrs.toUpperCase() !== 'EPSG:3857')
|
|
153
|
+
crsList.push('EPSG:3857');
|
|
154
|
+
return crsList;
|
|
155
|
+
}
|
|
156
|
+
function childLinks(collections, catalogs) {
|
|
157
|
+
return [
|
|
158
|
+
...collections.map((collection) => ({ rel: 'child', href: `./collections/${encodeURIComponent(collection.id)}.json`, type: 'application/json', title: collection.title })),
|
|
159
|
+
...catalogs.map((catalog) => ({ rel: 'child', href: `./catalogs/${encodeURIComponent(catalog.id)}/catalog.json`, type: 'application/json', title: catalog.title }))
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
/** The fields of a layer QGIS Server hides from either service. */
|
|
163
|
+
function hiddenFieldsOf(layer) {
|
|
164
|
+
return new Set([...(layer?.serverHiddenFields?.wms ?? []), ...(layer?.serverHiddenFields?.wfs ?? [])]);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Whether an expression names one of the fields, in double quotes or bare.
|
|
168
|
+
* It errs towards yes: a word inside a string literal that matches a field name
|
|
169
|
+
* counts, so a hidden name is never kept by mistake.
|
|
170
|
+
*/
|
|
171
|
+
function mentionsAny(expression, fields) {
|
|
172
|
+
if (typeof expression !== 'string' || fields.size === 0)
|
|
173
|
+
return false;
|
|
174
|
+
for (const field of fields) {
|
|
175
|
+
const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
176
|
+
if (new RegExp(`(^|[^A-Za-z0-9_])${escaped}($|[^A-Za-z0-9_])`).test(expression))
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/** Fields that name where a layer's own data comes from, which a server's catalogue never carries. */
|
|
182
|
+
const SOURCE_FIELDS = ['quac:wfs_endpoint', 'quac:wfs_type_name', 'quac:wfs_srs_name', 'quac:arcgis_layer_url', 'quac:arcgis_where', 'quac:max_zoom'];
|
|
183
|
+
function serveCollection(source, context) {
|
|
184
|
+
const layerId = source.id;
|
|
185
|
+
const layer = context.layersById.get(layerId);
|
|
186
|
+
const hidden = hiddenFieldsOf(layer);
|
|
187
|
+
const wmsName = context.servedIds.get(layerId);
|
|
188
|
+
const wfsTypeName = context.wfsPublished.has(layerId) ? source['quac:qgis_server_wfs_type_name'] : undefined;
|
|
189
|
+
const collection = { ...source, id: wmsName, links: [], assets: {} };
|
|
190
|
+
for (const field of SOURCE_FIELDS)
|
|
191
|
+
delete collection[field];
|
|
192
|
+
const links = [{ rel: 'wms', href: context.wmsHref, type: 'image/png', 'wms:layers': [wmsName], 'wms:styles': [''], 'wms:transparent': true, 'quac:wms_crs': context.wmsCrs }];
|
|
193
|
+
collection.links = links;
|
|
194
|
+
if (typeof wfsTypeName === 'string') {
|
|
195
|
+
collection.assets = { data: wfsGetFeatureAsset(context.serverAddress, wfsTypeName, wmsName) };
|
|
196
|
+
collection['quac:wfs_endpoint'] = context.serverAddress;
|
|
197
|
+
collection['quac:wfs_type_name'] = wfsTypeName;
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
delete collection.assets;
|
|
201
|
+
collection['quac:editable'] = false;
|
|
202
|
+
}
|
|
203
|
+
const extensions = (source.stac_extensions ?? []).filter((url) => url !== QUAC_SCHEMA_URL && url !== WEB_MAP_LINKS_EXTENSION);
|
|
204
|
+
extensions.push(WEB_MAP_LINKS_EXTENSION);
|
|
205
|
+
if (extensions.length > 0)
|
|
206
|
+
collection.stac_extensions = extensions;
|
|
207
|
+
else
|
|
208
|
+
delete collection.stac_extensions;
|
|
209
|
+
if (hidden.has(String(collection['quac:display_field'])))
|
|
210
|
+
delete collection['quac:display_field'];
|
|
211
|
+
serveFormOrder(collection, hidden);
|
|
212
|
+
serveFilters(collection, hidden);
|
|
213
|
+
serveRelations(collection, hidden, context);
|
|
214
|
+
serveLocks(collection, hidden);
|
|
215
|
+
serveColumns(collection, hidden, context, layerId);
|
|
216
|
+
return collection;
|
|
217
|
+
}
|
|
218
|
+
function serveFormOrder(collection, hidden) {
|
|
219
|
+
const order = collection['quac:form_order'];
|
|
220
|
+
if (Array.isArray(order))
|
|
221
|
+
collection['quac:form_order'] = order.filter((name) => !hidden.has(String(name)));
|
|
222
|
+
}
|
|
223
|
+
function serveFilters(collection, hidden) {
|
|
224
|
+
const filters = collection['quac:filters'];
|
|
225
|
+
if (!Array.isArray(filters))
|
|
226
|
+
return;
|
|
227
|
+
const kept = filters.filter((filter) => !hidden.has(String(filter.field)));
|
|
228
|
+
if (kept.length > 0)
|
|
229
|
+
collection['quac:filters'] = kept;
|
|
230
|
+
else
|
|
231
|
+
delete collection['quac:filters'];
|
|
232
|
+
}
|
|
233
|
+
function serveRelations(collection, hidden, context) {
|
|
234
|
+
const relations = collection['quac:related_to'];
|
|
235
|
+
if (!Array.isArray(relations))
|
|
236
|
+
return;
|
|
237
|
+
const kept = relations.flatMap((relation) => {
|
|
238
|
+
const parentId = context.servedIds.get(relation.parent_collection_id);
|
|
239
|
+
if (!parentId)
|
|
240
|
+
return [];
|
|
241
|
+
const parentHidden = hiddenFieldsOf(context.layersById.get(relation.parent_collection_id));
|
|
242
|
+
if (relation.fields.some((pair) => hidden.has(pair.child) || parentHidden.has(pair.parent)))
|
|
243
|
+
return [];
|
|
244
|
+
return [{ ...relation, parent_collection_id: parentId }];
|
|
245
|
+
});
|
|
246
|
+
if (kept.length > 0)
|
|
247
|
+
collection['quac:related_to'] = kept;
|
|
248
|
+
else
|
|
249
|
+
delete collection['quac:related_to'];
|
|
250
|
+
}
|
|
251
|
+
function serveLocks(collection, hidden) {
|
|
252
|
+
const locks = collection['quac:locks'];
|
|
253
|
+
if (!locks || typeof locks !== 'object')
|
|
254
|
+
return;
|
|
255
|
+
const served = {};
|
|
256
|
+
for (const [edit, lock] of Object.entries(locks)) {
|
|
257
|
+
served[edit] = lock && typeof lock === 'object' && mentionsAny(lock.expression, hidden) ? true : lock;
|
|
258
|
+
}
|
|
259
|
+
collection['quac:locks'] = served;
|
|
260
|
+
}
|
|
261
|
+
function serveColumns(collection, hidden, context, layerId) {
|
|
262
|
+
const columns = collection['table:columns'];
|
|
263
|
+
if (!Array.isArray(columns))
|
|
264
|
+
return;
|
|
265
|
+
const fieldTypes = context.fieldTypes[layerId] ?? {};
|
|
266
|
+
const kept = columns
|
|
267
|
+
.filter((column) => !hidden.has(column.name))
|
|
268
|
+
.map((column) => withFieldType(serveColumn(column, hidden, context), fieldTypes[column.name]));
|
|
269
|
+
if (kept.length > 0)
|
|
270
|
+
collection['table:columns'] = kept;
|
|
271
|
+
else
|
|
272
|
+
delete collection['table:columns'];
|
|
273
|
+
}
|
|
274
|
+
/** The column with the `type` QGIS Server reports for its field, and the `data_type` beside it, where QGIS Server reports one. */
|
|
275
|
+
function withFieldType(column, fieldType) {
|
|
276
|
+
const type = fieldType ? mapQtTypeToStacTableType(fieldType.type, fieldType.typeName) : undefined;
|
|
277
|
+
return type ? withDataType({ ...column, type }) : column;
|
|
278
|
+
}
|
|
279
|
+
function serveColumn(source, hidden, context) {
|
|
280
|
+
const column = { ...source };
|
|
281
|
+
const visibleWhen = column['quac:visible_when'];
|
|
282
|
+
if (Array.isArray(visibleWhen)) {
|
|
283
|
+
const kept = visibleWhen.filter((expression) => !mentionsAny(expression, hidden));
|
|
284
|
+
if (kept.length > 0)
|
|
285
|
+
column['quac:visible_when'] = kept;
|
|
286
|
+
else
|
|
287
|
+
delete column['quac:visible_when'];
|
|
288
|
+
}
|
|
289
|
+
// The expression locks the field while it is false, so dropping it alone
|
|
290
|
+
// would unlock the field: it becomes read-only instead.
|
|
291
|
+
if (mentionsAny(column['quac:editable_when'], hidden)) {
|
|
292
|
+
delete column['quac:editable_when'];
|
|
293
|
+
column['quac:editable'] = false;
|
|
294
|
+
}
|
|
295
|
+
// The folder an Attachment widget saves is a path on the author's machine.
|
|
296
|
+
const attachment = column['quac:attachment'];
|
|
297
|
+
if (attachment && 'default_root' in attachment) {
|
|
298
|
+
const served = { ...attachment };
|
|
299
|
+
delete served.default_root;
|
|
300
|
+
column['quac:attachment'] = served;
|
|
301
|
+
}
|
|
302
|
+
const fieldDefault = column['quac:default'];
|
|
303
|
+
if (fieldDefault?.kind === 'expression' && mentionsAny(fieldDefault.expression, hidden))
|
|
304
|
+
delete column['quac:default'];
|
|
305
|
+
const constraints = column['quac:constraints'];
|
|
306
|
+
if (constraints && mentionsAny(constraints.expression?.expression, hidden)) {
|
|
307
|
+
const rest = { ...constraints };
|
|
308
|
+
delete rest.expression;
|
|
309
|
+
if (Object.keys(rest).length > 0)
|
|
310
|
+
column['quac:constraints'] = rest;
|
|
311
|
+
else
|
|
312
|
+
delete column['quac:constraints'];
|
|
313
|
+
}
|
|
314
|
+
const relation = column['quac:value_relation'];
|
|
315
|
+
if (relation) {
|
|
316
|
+
const lookupId = context.servedIds.get(relation.collection);
|
|
317
|
+
const lookupHidden = hiddenFieldsOf(context.layersById.get(relation.collection));
|
|
318
|
+
const usesHidden = [relation.key, relation.value, relation.order_field].some((field) => field !== undefined && lookupHidden.has(field))
|
|
319
|
+
|| mentionsAny(relation.filter, lookupHidden)
|
|
320
|
+
|| mentionsAny(relation.filter, hidden);
|
|
321
|
+
if (!lookupId || usesHidden)
|
|
322
|
+
delete column['quac:value_relation'];
|
|
323
|
+
else
|
|
324
|
+
column['quac:value_relation'] = { ...relation, collection: lookupId };
|
|
325
|
+
}
|
|
326
|
+
return column;
|
|
327
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { QgisServerNames } from './normalizedProject.ts';
|
|
2
|
+
import type { BoundingBox, FileDataSource, LayerEntry, QgsProject, WfsTransactionLayers, WmsPublishing } from '../model/QgsProject.ts';
|
|
3
|
+
import type { StacCatalog, StacCollection } from '../model/Stac.ts';
|
|
4
|
+
import type { FeatureCollection } from 'geojson';
|
|
5
|
+
/**
|
|
6
|
+
* Inputs to the STAC generator: per-layer optional GeoJSON FeatureCollection
|
|
7
|
+
* (used to derive `table:columns` from real properties when available).
|
|
8
|
+
*/
|
|
9
|
+
export interface StacCompanionData {
|
|
10
|
+
/** Layer id matching QgsProject.LayerEntry.id. */
|
|
11
|
+
layerId: string;
|
|
12
|
+
/** GeoJSON FeatureCollection if loaded; null for unmatched/WFS layers. */
|
|
13
|
+
geojson: FeatureCollection | null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates a STAC Catalog tree from a parsed QgsProject.
|
|
17
|
+
*
|
|
18
|
+
* Mapping:
|
|
19
|
+
* QgsProject → top-level Catalog
|
|
20
|
+
* QgsProject.layerTree → nested Catalogs (groups) + Collection links
|
|
21
|
+
* LayerEntry → Collection
|
|
22
|
+
* LayerEntry.dataSource → Asset within the Collection
|
|
23
|
+
* GeoJSON properties → table:columns extension on the Collection
|
|
24
|
+
*
|
|
25
|
+
* Pure function — no side effects, no I/O. Companion GeoJSONs are passed
|
|
26
|
+
* in by the caller; if absent for a given layer, the Collection is still
|
|
27
|
+
* emitted but `table:columns` is omitted.
|
|
28
|
+
*
|
|
29
|
+
* This is a thin wrapper: `qgsProjectToNormalized` resolves the QGS-specific
|
|
30
|
+
* wording, assets and columns into the shared `NormalizedProject`, and
|
|
31
|
+
* `generateStacFromNormalized` (see normalizedProject.ts) builds the catalogue.
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateStacCatalogue(project: QgsProject, companions?: StacCompanionData[], options?: {
|
|
34
|
+
selfHref?: string;
|
|
35
|
+
projectPath?: string;
|
|
36
|
+
projectFileName?: string;
|
|
37
|
+
initialView?: BoundingBox | null;
|
|
38
|
+
layerWgs84Extents?: Map<string, BoundingBox>;
|
|
39
|
+
}): StacCatalog;
|
|
40
|
+
/**
|
|
41
|
+
* The key a style asset takes for the field its renderer classifies by, when
|
|
42
|
+
* that renderer is a categorised one. The project author's declaration.
|
|
43
|
+
*/
|
|
44
|
+
export declare const QUAC_CATEGORISED_FIELD = "quac:categorised_field";
|
|
45
|
+
/**
|
|
46
|
+
* The key a data asset takes for the shapes of feature its Collection holds,
|
|
47
|
+
* from QGIS file sources' `|geometrytype=`: a list of `Point`, `LineString` and
|
|
48
|
+
* `Polygon`, a `Multi*` geometry counting as its single-part shape.
|
|
49
|
+
*/
|
|
50
|
+
export declare const QUAC_GEOMETRY_FILTER = "quac:geometry_filter";
|
|
51
|
+
type GeometryFilterShape = NonNullable<FileDataSource['geometryTypeFilter']>;
|
|
52
|
+
/**
|
|
53
|
+
* The shapes a Collection's data asset keeps, or null where it names none, or
|
|
54
|
+
* names anything this does not read, so a data file is read whole.
|
|
55
|
+
*/
|
|
56
|
+
export declare function readCollectionGeometryFilter(collection: StacCollection): GeometryFilterShape[] | null;
|
|
57
|
+
/**
|
|
58
|
+
* The key a data asset takes for the table of a GeoPackage its Collection
|
|
59
|
+
* reads, from a QGIS file source's `|layername=`.
|
|
60
|
+
*/
|
|
61
|
+
export declare const QUAC_LAYER_NAME = "quac:layer_name";
|
|
62
|
+
/** The table a Collection's data asset names, or null where it names none. */
|
|
63
|
+
export declare function readCollectionLayerName(collection: StacCollection): string | null;
|
|
64
|
+
/**
|
|
65
|
+
* The names QGIS Server would give the layer if it served the project
|
|
66
|
+
* (`QgsWmsLayerInfos::buildWmsLayerInfos`, `src/server/services/wms/qgswmslayerinfos.cpp`,
|
|
67
|
+
* and `QgsMapLayerServerProperties::wfsTypeName`, `src/core/qgsmaplayerserverproperties.cpp`,
|
|
68
|
+
* `qgis/QGIS@master`, read 2026-11-03). Its WMS name is its layer id where the
|
|
69
|
+
* project ticks **Use layer ids as names**, else its short name, else its name,
|
|
70
|
+
* and none where the project leaves it out of WMS. Its WFS type name, given
|
|
71
|
+
* only where the project publishes it for WFS, is its short name or else its
|
|
72
|
+
* name, with each space made `_` and each `:` and em dash made `-`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function qgisServerNamesOf(layer: LayerEntry, context: {
|
|
75
|
+
wmsPublishing: WmsPublishing | null;
|
|
76
|
+
wfsTransactionLayers: WfsTransactionLayers | null;
|
|
77
|
+
}): QgisServerNames;
|
|
78
|
+
/** The title of the `via` link to the QGIS project a layer's Collection was written from. */
|
|
79
|
+
export declare const QGIS_PROJECT_LINK_TITLE = "QGIS project";
|
|
80
|
+
/**
|
|
81
|
+
* The description a Collection takes where its QGIS layer or group has no
|
|
82
|
+
* abstract of its own, since STAC requires one. `isQgisPlaceholderDescription`
|
|
83
|
+
* tells it apart from one the project wrote.
|
|
84
|
+
*/
|
|
85
|
+
export declare function qgisPlaceholderDescription(kind: 'layer' | 'group', name: string): string;
|
|
86
|
+
/** Whether a description is the one `qgisPlaceholderDescription` writes. */
|
|
87
|
+
export declare function isQgisPlaceholderDescription(description: string | undefined): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* A QGIS style asset's address, taken back apart — the counterpart of the href
|
|
90
|
+
* `buildStyleAssets` writes, kept beside it so the two cannot drift.
|
|
91
|
+
*
|
|
92
|
+
* The address is `./project.qgs#<layer-id>/<style-name>`, with the document
|
|
93
|
+
* path and both halves of the fragment percent-encoded, and the document absent
|
|
94
|
+
* for a caller that did not know where the project file sat. Because the
|
|
95
|
+
* document path is escaped, the first `#` is always the one starting the
|
|
96
|
+
* fragment — a project named `Assets #2.qgs` has its `#` as `%23`, where
|
|
97
|
+
* unescaped it would cut the address in half and leave every layer in that
|
|
98
|
+
* project unstyled.
|
|
99
|
+
*
|
|
100
|
+
* Returns null for an href with no such fragment — a style file sitting
|
|
101
|
+
* beside the data, which is the folder catalogue's shape and is dereferenced by
|
|
102
|
+
* fetching it rather than by reading the project.
|
|
103
|
+
*/
|
|
104
|
+
export declare function parseQgisStyleAssetHref(href: string): {
|
|
105
|
+
/** Path of the project document the style is in; null for a bare fragment. */
|
|
106
|
+
documentPath: string | null;
|
|
107
|
+
layerId: string;
|
|
108
|
+
styleName: string;
|
|
109
|
+
} | null;
|
|
110
|
+
export {};
|