@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.
Files changed (134) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +35 -2
  3. package/dist/generate/arcgisStacCatalogue.d.ts +46 -0
  4. package/dist/generate/arcgisStacCatalogue.js +189 -0
  5. package/dist/generate/externalStacCatalogue.d.ts +53 -0
  6. package/dist/generate/externalStacCatalogue.js +143 -0
  7. package/dist/generate/fileLayerCollection.d.ts +44 -0
  8. package/dist/generate/fileLayerCollection.js +72 -0
  9. package/dist/generate/folderStacCatalogue.d.ts +48 -0
  10. package/dist/generate/folderStacCatalogue.js +69 -0
  11. package/dist/generate/normalizedProject.d.ts +452 -0
  12. package/dist/generate/normalizedProject.js +877 -0
  13. package/dist/generate/ogcFeaturesStacCatalogue.d.ts +49 -0
  14. package/dist/generate/ogcFeaturesStacCatalogue.js +207 -0
  15. package/dist/generate/qmlForLayer.d.ts +17 -0
  16. package/dist/generate/qmlForLayer.js +36 -0
  17. package/dist/generate/serverLayerTree.d.ts +44 -0
  18. package/dist/generate/serverLayerTree.js +50 -0
  19. package/dist/generate/serverStacCatalogue.d.ts +84 -0
  20. package/dist/generate/serverStacCatalogue.js +327 -0
  21. package/dist/generate/stacCatalogue.d.ts +110 -0
  22. package/dist/generate/stacCatalogue.js +887 -0
  23. package/dist/generate/wfsStacCatalogue.d.ts +37 -0
  24. package/dist/generate/wfsStacCatalogue.js +127 -0
  25. package/dist/generate/wmsStacCatalogue.d.ts +46 -0
  26. package/dist/generate/wmsStacCatalogue.js +229 -0
  27. package/dist/index.d.ts +77 -0
  28. package/dist/index.js +52 -0
  29. package/dist/model/QgsProject.d.ts +724 -0
  30. package/dist/model/QgsProject.js +15 -0
  31. package/dist/model/Stac.d.ts +322 -0
  32. package/dist/model/Stac.js +16 -0
  33. package/dist/model/WmsProject.d.ts +105 -0
  34. package/dist/model/WmsProject.js +1 -0
  35. package/dist/model/arcgis.d.ts +134 -0
  36. package/dist/model/arcgis.js +1 -0
  37. package/dist/model/delimitedText.d.ts +38 -0
  38. package/dist/model/delimitedText.js +46 -0
  39. package/dist/model/featureFilter.d.ts +41 -0
  40. package/dist/model/featureFilter.js +24 -0
  41. package/dist/model/fieldIconAddress.d.ts +27 -0
  42. package/dist/model/fieldIconAddress.js +93 -0
  43. package/dist/model/ogcFeatures.d.ts +40 -0
  44. package/dist/model/ogcFeatures.js +6 -0
  45. package/dist/model/quacExtension.d.ts +28 -0
  46. package/dist/model/quacExtension.js +75 -0
  47. package/dist/model/stacAssetRoles.d.ts +33 -0
  48. package/dist/model/stacAssetRoles.js +44 -0
  49. package/dist/model/stacCollectionNotes.d.ts +21 -0
  50. package/dist/model/stacCollectionNotes.js +44 -0
  51. package/dist/model/stacHref.d.ts +56 -0
  52. package/dist/model/stacHref.js +93 -0
  53. package/dist/model/stacPmtiles.d.ts +38 -0
  54. package/dist/model/stacPmtiles.js +69 -0
  55. package/dist/model/stacSizeAndCount.d.ts +14 -0
  56. package/dist/model/stacSizeAndCount.js +20 -0
  57. package/dist/model/stacStyles.d.ts +93 -0
  58. package/dist/model/stacStyles.js +87 -0
  59. package/dist/model/stacTreeWalk.d.ts +36 -0
  60. package/dist/model/stacTreeWalk.js +76 -0
  61. package/dist/model/stacWms.d.ts +18 -0
  62. package/dist/model/stacWms.js +73 -0
  63. package/dist/model/stacWmts.d.ts +34 -0
  64. package/dist/model/stacWmts.js +90 -0
  65. package/dist/model/stacXyz.d.ts +24 -0
  66. package/dist/model/stacXyz.js +46 -0
  67. package/dist/model/wfs.d.ts +136 -0
  68. package/dist/model/wfs.js +1 -0
  69. package/dist/parse/collectLayerVisibility.d.ts +10 -0
  70. package/dist/parse/collectLayerVisibility.js +22 -0
  71. package/dist/parse/customProperties.d.ts +18 -0
  72. package/dist/parse/customProperties.js +43 -0
  73. package/dist/parse/geometrySiblings.d.ts +25 -0
  74. package/dist/parse/geometrySiblings.js +83 -0
  75. package/dist/parse/parseBrandColour.d.ts +14 -0
  76. package/dist/parse/parseBrandColour.js +25 -0
  77. package/dist/parse/parseDataDefinedEditable.d.ts +38 -0
  78. package/dist/parse/parseDataDefinedEditable.js +76 -0
  79. package/dist/parse/parseDataSource.d.ts +53 -0
  80. package/dist/parse/parseDataSource.js +484 -0
  81. package/dist/parse/parseExtent.d.ts +17 -0
  82. package/dist/parse/parseExtent.js +49 -0
  83. package/dist/parse/parseFormLayout.d.ts +26 -0
  84. package/dist/parse/parseFormLayout.js +60 -0
  85. package/dist/parse/parseGetProjectSettings.d.ts +15 -0
  86. package/dist/parse/parseGetProjectSettings.js +172 -0
  87. package/dist/parse/parseLayers.d.ts +23 -0
  88. package/dist/parse/parseLayers.js +1125 -0
  89. package/dist/parse/parseLegendTree.d.ts +20 -0
  90. package/dist/parse/parseLegendTree.js +66 -0
  91. package/dist/parse/parseMeasurement.d.ts +20 -0
  92. package/dist/parse/parseMeasurement.js +66 -0
  93. package/dist/parse/parseMergin.d.ts +19 -0
  94. package/dist/parse/parseMergin.js +51 -0
  95. package/dist/parse/parseProjectVariables.d.ts +9 -0
  96. package/dist/parse/parseProjectVariables.js +19 -0
  97. package/dist/parse/parseQfieldSync.d.ts +47 -0
  98. package/dist/parse/parseQfieldSync.js +95 -0
  99. package/dist/parse/parseQgsXml.d.ts +15 -0
  100. package/dist/parse/parseQgsXml.js +100 -0
  101. package/dist/parse/parseRelations.d.ts +19 -0
  102. package/dist/parse/parseRelations.js +64 -0
  103. package/dist/parse/parseStyle.d.ts +33 -0
  104. package/dist/parse/parseStyle.js +128 -0
  105. package/dist/parse/parseWmsPublishing.d.ts +21 -0
  106. package/dist/parse/parseWmsPublishing.js +38 -0
  107. package/dist/parse/projectProperties.d.ts +15 -0
  108. package/dist/parse/projectProperties.js +27 -0
  109. package/dist/parse/qgisExpression.d.ts +194 -0
  110. package/dist/parse/qgisExpression.js +859 -0
  111. package/dist/parse/qtDateFormat.d.ts +74 -0
  112. package/dist/parse/qtDateFormat.js +324 -0
  113. package/dist/parse/qtRegex.d.ts +67 -0
  114. package/dist/parse/qtRegex.js +397 -0
  115. package/dist/parse/readProjectFile.d.ts +7 -0
  116. package/dist/parse/readProjectFile.js +27 -0
  117. package/dist/sources/qgisServerUrl.d.ts +6 -0
  118. package/dist/sources/qgisServerUrl.js +17 -0
  119. package/dist/sources/stacDocuments.d.ts +40 -0
  120. package/dist/sources/stacDocuments.js +85 -0
  121. package/dist/sources/stacItems.d.ts +109 -0
  122. package/dist/sources/stacItems.js +287 -0
  123. package/dist/util/catalogueFileFormats.d.ts +58 -0
  124. package/dist/util/catalogueFileFormats.js +64 -0
  125. package/dist/util/devLog.d.ts +10 -0
  126. package/dist/util/devLog.js +22 -0
  127. package/dist/util/fileName.d.ts +18 -0
  128. package/dist/util/fileName.js +45 -0
  129. package/dist/util/nonBlankText.d.ts +2 -0
  130. package/dist/util/nonBlankText.js +4 -0
  131. package/dist/util/wfsVersions.d.ts +9 -0
  132. package/dist/util/wfsVersions.js +13 -0
  133. package/package.json +55 -4
  134. package/src/schema/quac.schema.json +939 -0
@@ -0,0 +1,49 @@
1
+ import type { OgcCollection } from '../model/ogcFeatures.ts';
2
+ import type { StacCatalog, StacCollection } from '../model/Stac.ts';
3
+ /**
4
+ * Generates a STAC Catalog tree from an OGC API - Features `/collections`
5
+ * document:
6
+ * the service → top-level Catalog
7
+ * each collection → Collection with `ogcapi:` fields and an items asset
8
+ *
9
+ * The service publishes a flat list, so the catalogue has no nested Catalogs,
10
+ * and it declares no author intent — no default visibility, no display field —
11
+ * so those shared fields are left off rather than invented.
12
+ *
13
+ * A collection's `items` link is the whole of what loading it needs: features
14
+ * come back as GeoJSON from that one address, with no capabilities document or
15
+ * schema request in between. The link is resolved to an absolute URL here, so
16
+ * the Collection has an address that works wherever it is read back.
17
+ *
18
+ * Pure function — no side effects, no I/O. The caller fetches the collections
19
+ * document and passes the result in.
20
+ */
21
+ export interface OgcFeaturesStacCatalogueOptions {
22
+ /** Collection ids to emit, in the order given. Omit to emit every one. */
23
+ collectionIds?: string[];
24
+ /** Service title, used when the collections document declares none. */
25
+ title?: string;
26
+ }
27
+ /** Where a Collection's features are fetched from. */
28
+ export interface OgcFeaturesCollectionSource {
29
+ kind: 'features';
30
+ itemsUrl: string;
31
+ collectionId: string;
32
+ }
33
+ /** Where a Collection's pre-rendered images are fetched from. */
34
+ export interface OgcTilesCollectionSource {
35
+ kind: 'tiles';
36
+ /** URL template with `{z}`, `{x}` and `{y}`. */
37
+ tilesUrl: string;
38
+ collectionId: string;
39
+ }
40
+ export type OgcCollectionSource = OgcFeaturesCollectionSource | OgcTilesCollectionSource;
41
+ export declare function generateStacCatalogueFromOgcCollections(collectionsUrl: string, collections: OgcCollection[], options?: OgcFeaturesStacCatalogueOptions): StacCatalog;
42
+ /**
43
+ * Where a generated Collection's data comes from — its items endpoint, or its
44
+ * tile template — and null for one that declares neither.
45
+ *
46
+ * Features come first. A collection publishing both is read as features, which
47
+ * is the one of the two that can be selected, filtered and inspected.
48
+ */
49
+ export declare function resolveOgcCollectionSource(collection: StacCollection): OgcCollectionSource | null;
@@ -0,0 +1,207 @@
1
+ import { generateStacFromNormalized, slugify } from "./normalizedProject.js";
2
+ import { GEOJSON_MEDIA_TYPE } from "../util/catalogueFileFormats.js";
3
+ export function generateStacCatalogueFromOgcCollections(collectionsUrl, collections, options = {}) {
4
+ return generateStacFromNormalized(ogcCollectionsToNormalized(collectionsUrl, collections, options));
5
+ }
6
+ /**
7
+ * Where a generated Collection's data comes from — its items endpoint, or its
8
+ * tile template — and null for one that declares neither.
9
+ *
10
+ * Features come first. A collection publishing both is read as features, which
11
+ * is the one of the two that can be selected, filtered and inspected.
12
+ */
13
+ export function resolveOgcCollectionSource(collection) {
14
+ const collectionId = collection['ogcapi:collection_id'];
15
+ if (typeof collectionId !== 'string')
16
+ return null;
17
+ const itemsUrl = collection['ogcapi:items_url'];
18
+ if (typeof itemsUrl === 'string')
19
+ return { kind: 'features', itemsUrl, collectionId };
20
+ const tilesUrl = collection['ogcapi:tiles_url'];
21
+ if (typeof tilesUrl === 'string')
22
+ return { kind: 'tiles', tilesUrl, collectionId };
23
+ return null;
24
+ }
25
+ function ogcCollectionsToNormalized(collectionsUrl, collections, options) {
26
+ const selected = selectCollections(collections, options.collectionIds);
27
+ const title = options.title?.trim() || '';
28
+ return {
29
+ id: slugify(title || 'ogc-api-features') || 'ogc-api-features',
30
+ title,
31
+ description: title
32
+ ? `STAC catalogue generated from the OGC API - Features service "${title}".`
33
+ : 'STAC catalogue generated from an OGC API - Features collections document.',
34
+ bbox: unionBbox(selected),
35
+ vendorFields: { 'ogcapi:collections_url': collectionsUrl },
36
+ nodes: selected.map((collection) => ogcCollectionToNormalized(collectionsUrl, collection))
37
+ };
38
+ }
39
+ /** Resolves the requested ids against the published list, preserving the caller's order. */
40
+ function selectCollections(collections, collectionIds) {
41
+ if (!collectionIds)
42
+ return collections;
43
+ const byId = new Map(collections.map((collection) => [collection.id, collection]));
44
+ return collectionIds
45
+ .map((id) => byId.get(id))
46
+ .filter((collection) => Boolean(collection));
47
+ }
48
+ function ogcCollectionToNormalized(collectionsUrl, collection) {
49
+ const title = collection.title || collection.id;
50
+ const itemsUrl = readItemsUrl(collection, collectionsUrl);
51
+ const tilesUrl = readTilesTemplate(collection, collectionsUrl);
52
+ const vendorFields = {
53
+ 'ogcapi:collections_url': collectionsUrl,
54
+ 'ogcapi:collection_id': collection.id
55
+ };
56
+ if (itemsUrl)
57
+ vendorFields['ogcapi:items_url'] = itemsUrl;
58
+ if (tilesUrl)
59
+ vendorFields['ogcapi:tiles_url'] = tilesUrl;
60
+ if (collection.itemType)
61
+ vendorFields['ogcapi:item_type'] = collection.itemType;
62
+ return {
63
+ kind: 'layer',
64
+ // The collection id is the service's own handle for the layer, and the half
65
+ // of the layer's identity that the connection's endpoint completes.
66
+ id: collection.id,
67
+ title,
68
+ description: collection.description?.trim()
69
+ || `Layer "${title}" from a map server.`,
70
+ bbox: readBbox(collection),
71
+ temporalInterval: readTemporalInterval(collection),
72
+ // The collections document declares no geometry type; it is read off the
73
+ // features once they load.
74
+ geometryType: null,
75
+ tableColumns: [],
76
+ assets: buildAssets(itemsUrl, tilesUrl, title),
77
+ ...(collection.keywords ? { keywords: readKeywords(collection) } : {}),
78
+ displayField: null,
79
+ visibilityChecked: null,
80
+ editable: null,
81
+ vendorFields
82
+ };
83
+ }
84
+ function buildAssets(itemsUrl, tilesUrl, title) {
85
+ const assets = {};
86
+ if (itemsUrl) {
87
+ assets.data = {
88
+ href: itemsUrl,
89
+ type: GEOJSON_MEDIA_TYPE,
90
+ title: `OGC API - Features items: ${title}`,
91
+ roles: ['data']
92
+ };
93
+ }
94
+ if (tilesUrl) {
95
+ // Under its own key rather than `data`: the template is not a file that can
96
+ // be fetched, and every reader of a `data` asset here expects one it can.
97
+ assets.tiles = {
98
+ href: tilesUrl,
99
+ title: `Tiles: ${title}`,
100
+ roles: ['overview']
101
+ };
102
+ }
103
+ return assets;
104
+ }
105
+ /**
106
+ * The collection's tile template, absolute, or null where it publishes none
107
+ * this package reads.
108
+ *
109
+ * Only a `{z}`/`{x}`/`{y}` template counts. A `tiles` link is also how a
110
+ * service points at an OGC API - Tiles tileset document, which describes its
111
+ * tiles rather than addressing them; that is a document to be fetched and read,
112
+ * not a template to substitute into, so it is left alone here.
113
+ */
114
+ function readTilesTemplate(collection, collectionsUrl) {
115
+ const candidates = (collection.links ?? [])
116
+ .filter((link) => link.rel === 'tiles' || link.rel === 'item')
117
+ .map((link) => link.href);
118
+ for (const href of candidates) {
119
+ if (typeof href !== 'string')
120
+ continue;
121
+ if (!href.includes('{z}') || !href.includes('{x}') || !href.includes('{y}'))
122
+ continue;
123
+ try {
124
+ // `new URL` percent-encodes the braces, which the tile source would then
125
+ // request literally, so the template is resolved and put back.
126
+ return decodeTileBraces(new URL(href, collectionsUrl).toString());
127
+ }
128
+ catch {
129
+ // The next candidate, not the end of the scan: a collection may publish
130
+ // more than one tiles link, and one that will not resolve says nothing
131
+ // about the rest.
132
+ continue;
133
+ }
134
+ }
135
+ return null;
136
+ }
137
+ function decodeTileBraces(url) {
138
+ return url.replace(/%7B/g, '{').replace(/%7D/g, '}');
139
+ }
140
+ function readItemsUrl(collection, collectionsUrl) {
141
+ const link = collection.links?.find((entry) => entry.rel === 'items' && typeof entry.href === 'string');
142
+ if (!link)
143
+ return null;
144
+ try {
145
+ return new URL(link.href, collectionsUrl).toString();
146
+ }
147
+ catch {
148
+ return null;
149
+ }
150
+ }
151
+ function readKeywords(collection) {
152
+ const keywords = collection.keywords;
153
+ if (!Array.isArray(keywords))
154
+ return [];
155
+ return keywords.filter((keyword) => typeof keyword === 'string');
156
+ }
157
+ /** The collection's overall period, the first of `extent.temporal.interval`, or null where it declares none. */
158
+ function readTemporalInterval(collection) {
159
+ const interval = collection.extent?.temporal?.interval?.[0];
160
+ if (!Array.isArray(interval))
161
+ return null;
162
+ const [start, end] = interval;
163
+ const text = (value) => (typeof value === 'string' && value ? value : null);
164
+ return text(start) || text(end) ? [text(start), text(end)] : null;
165
+ }
166
+ /**
167
+ * The collection's overall extent. `extent.spatial.bbox` lists the overall box
168
+ * first and any disjoint parts after it, in CRS84 — longitude/latitude — unless
169
+ * the collection declares another CRS, in which case nothing here can read it and
170
+ * the box is left off. A six-number box has elevation in the middle pair.
171
+ */
172
+ function readBbox(collection) {
173
+ const spatial = collection.extent?.spatial;
174
+ const box = spatial?.bbox?.[0];
175
+ if (!Array.isArray(box))
176
+ return null;
177
+ if (spatial?.crs && !isCrs84(spatial.crs))
178
+ return null;
179
+ const values = box.filter((value) => typeof value === 'number' && Number.isFinite(value));
180
+ if (values.length === 4) {
181
+ return { xmin: values[0], ymin: values[1], xmax: values[2], ymax: values[3] };
182
+ }
183
+ if (values.length === 6) {
184
+ return { xmin: values[0], ymin: values[1], xmax: values[3], ymax: values[4] };
185
+ }
186
+ return null;
187
+ }
188
+ function isCrs84(crs) {
189
+ return crs.includes('CRS84') || crs.includes('EPSG:4326') || crs.endsWith('/4326');
190
+ }
191
+ function unionBbox(collections) {
192
+ let union = null;
193
+ for (const collection of collections) {
194
+ const box = readBbox(collection);
195
+ if (!box)
196
+ continue;
197
+ union = union
198
+ ? {
199
+ xmin: Math.min(union.xmin, box.xmin),
200
+ ymin: Math.min(union.ymin, box.ymin),
201
+ xmax: Math.max(union.xmax, box.xmax),
202
+ ymax: Math.max(union.ymax, box.ymax)
203
+ }
204
+ : box;
205
+ }
206
+ return union;
207
+ }
@@ -0,0 +1,17 @@
1
+ import type { QgsProject } from '../model/QgsProject.ts';
2
+ /**
3
+ * Wraps a layer's inline <renderer-v2> subtree into the standalone QML
4
+ * envelope (<qgis> root) that geostyler-qgis-parser expects.
5
+ *
6
+ * Phase 1's parseStyle.ts captures only the renderer-v2 subtree; this
7
+ * function reconstitutes the standalone QML form so the GeoStyler QGIS
8
+ * parser can consume it.
9
+ *
10
+ * `styleIndex` selects which named style (some layers have multiple, e.g.
11
+ * "Asset Owner" + "Priority") to render. Defaults to the active style.
12
+ *
13
+ * Returns null if the layer doesn't exist, the style index is out of range,
14
+ * or the chosen style has no inline renderer — callers should treat null
15
+ * as "fall back to default styling".
16
+ */
17
+ export declare function qmlForLayer(project: QgsProject, layerId: string, styleIndex?: number): string | null;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Wraps a layer's inline <renderer-v2> subtree into the standalone QML
3
+ * envelope (<qgis> root) that geostyler-qgis-parser expects.
4
+ *
5
+ * Phase 1's parseStyle.ts captures only the renderer-v2 subtree; this
6
+ * function reconstitutes the standalone QML form so the GeoStyler QGIS
7
+ * parser can consume it.
8
+ *
9
+ * `styleIndex` selects which named style (some layers have multiple, e.g.
10
+ * "Asset Owner" + "Priority") to render. Defaults to the active style.
11
+ *
12
+ * Returns null if the layer doesn't exist, the style index is out of range,
13
+ * or the chosen style has no inline renderer — callers should treat null
14
+ * as "fall back to default styling".
15
+ */
16
+ export function qmlForLayer(project, layerId, styleIndex) {
17
+ const layer = project.layers.find((entry) => entry.id === layerId);
18
+ if (!layer)
19
+ return null;
20
+ const idx = styleIndex ?? layer.activeStyleIndex;
21
+ const style = layer.styles[idx];
22
+ if (!style || !style.rendererV2RawXml)
23
+ return null;
24
+ const version = project.qgisVersion ?? '3.44.0';
25
+ // The DOCTYPE matches what QGIS Desktop writes for standalone .qml files
26
+ // (see "Save Style → QML File"), giving the parser the same input shape.
27
+ return [
28
+ '<!DOCTYPE qgis PUBLIC \'http://mrcc.com/qgis.dtd\' \'SYSTEM\'>',
29
+ `<qgis version="${escapeAttr(version)}" styleCategories="Symbology">`,
30
+ style.rendererV2RawXml,
31
+ '</qgis>'
32
+ ].join('\n');
33
+ }
34
+ function escapeAttr(value) {
35
+ return value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');
36
+ }
@@ -0,0 +1,44 @@
1
+ import type { QgsProject } from '../model/QgsProject.ts';
2
+ /** A project's layer tree as QGIS Server publishes it (`serverLayerTree`). */
3
+ export interface ServerLayerTree {
4
+ /** **Use layer ids as names** is ticked, so each layer's WMS name is its layer id. */
5
+ useLayerIds: boolean;
6
+ children: ServerLayerTreeNode[];
7
+ }
8
+ export type ServerLayerTreeNode = ServerLayerTreeGroup | ServerLayerTreeLayer;
9
+ export interface ServerLayerTreeGroup {
10
+ kind: 'group';
11
+ name: string;
12
+ /** False where the project leaves the group out of WMS, which leaves out every layer inside it. */
13
+ wmsPublished: boolean;
14
+ children: ServerLayerTreeNode[];
15
+ }
16
+ export interface ServerLayerTreeLayer {
17
+ kind: 'layer';
18
+ /** The QGIS layer id. */
19
+ id: string;
20
+ /** The layer's name in the project. */
21
+ name: string;
22
+ /** The name QGIS Server lists the layer under in WMS; null where the project leaves it out of WMS. */
23
+ wmsName: string | null;
24
+ /** The type name QGIS Server gives the layer in WFS; null where the project does not publish it for WFS. */
25
+ wfsTypeName: string | null;
26
+ /** The fields the project hides from each service. */
27
+ hiddenFields: {
28
+ wms: string[];
29
+ wfs: string[];
30
+ };
31
+ }
32
+ /**
33
+ * The layer tree QGIS Server reads from a project: each layer's WMS name and
34
+ * WFS type name, and the fields the project hides from each service. It is
35
+ * what the QUAC plugin's reading spike returns in Python, so that the two
36
+ * languages are compared on the fixtures.
37
+ *
38
+ * A layer's names are `qgisServerNamesOf`'s, except that a layer inside a
39
+ * group the project leaves out of WMS has no WMS name. A tree entry whose layer
40
+ * the project does not hold is left out.
41
+ */
42
+ export declare function serverLayerTree(project: QgsProject): ServerLayerTree;
43
+ /** The ids of the layers the project publishes over WMS. */
44
+ export declare function wmsPublishedLayerIds(tree: ServerLayerTree): Set<string>;
@@ -0,0 +1,50 @@
1
+ import { qgisServerNamesOf } from "./stacCatalogue.js";
2
+ /**
3
+ * The layer tree QGIS Server reads from a project: each layer's WMS name and
4
+ * WFS type name, and the fields the project hides from each service. It is
5
+ * what the QUAC plugin's reading spike returns in Python, so that the two
6
+ * languages are compared on the fixtures.
7
+ *
8
+ * A layer's names are `qgisServerNamesOf`'s, except that a layer inside a
9
+ * group the project leaves out of WMS has no WMS name. A tree entry whose layer
10
+ * the project does not hold is left out.
11
+ */
12
+ export function serverLayerTree(project) {
13
+ const layersById = new Map(project.layers.map((layer) => [layer.id, layer]));
14
+ const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
15
+ const context = { wmsPublishing: project.wmsPublishing ?? null, wfsTransactionLayers: project.wfsTransactionLayers ?? null };
16
+ const readGroup = (group, wmsPublished) => group.children.flatMap((node) => {
17
+ if (node.kind === 'group') {
18
+ const published = wmsPublished && !restricted.has(node.name);
19
+ return [{ kind: 'group', name: node.name, wmsPublished: published, children: readGroup(node, published) }];
20
+ }
21
+ const layer = layersById.get(node.layerId);
22
+ return layer ? [serverLayer(layer, wmsPublished, context)] : [];
23
+ });
24
+ return { useLayerIds: project.wmsPublishing?.useLayerIds ?? false, children: readGroup(project.layerTree, true) };
25
+ }
26
+ function serverLayer(layer, inPublishedGroup, context) {
27
+ const names = qgisServerNamesOf(layer, context);
28
+ return {
29
+ kind: 'layer',
30
+ id: layer.id,
31
+ name: layer.name,
32
+ wmsName: inPublishedGroup ? names.wmsName : null,
33
+ wfsTypeName: names.wfsTypeName,
34
+ hiddenFields: { wms: layer.serverHiddenFields?.wms ?? [], wfs: layer.serverHiddenFields?.wfs ?? [] }
35
+ };
36
+ }
37
+ /** The ids of the layers the project publishes over WMS. */
38
+ export function wmsPublishedLayerIds(tree) {
39
+ const ids = new Set();
40
+ const walk = (nodes) => {
41
+ for (const node of nodes) {
42
+ if (node.kind === 'group')
43
+ walk(node.children);
44
+ else if (node.wmsName !== null)
45
+ ids.add(node.id);
46
+ }
47
+ };
48
+ walk(tree.children);
49
+ return ids;
50
+ }
@@ -0,0 +1,84 @@
1
+ import type { BoundingBox, QgsProject } from '../model/QgsProject.ts';
2
+ import type { StacCatalog } from '../model/Stac.ts';
3
+ /**
4
+ * The catalogue a QGIS Server would serve for a project: the QUAC plugin's
5
+ * route, as a pure function of the project's text and the server's address, so
6
+ * that the plugin's Python port has one function to agree with.
7
+ *
8
+ * It starts from the catalogue a project file gives (`generateStacCatalogue`)
9
+ * and applies the project's own QGIS Server settings, as GetProjectSettings
10
+ * does:
11
+ *
12
+ * - A layer or group whose name the project leaves out of WMS
13
+ * (`WMSRestrictedLayers`) is left out, with every layer inside the group. A
14
+ * layer published for WFS but left out of WMS is left out too, because a
15
+ * server's Collection id is the WMS name (D1). A file the project splits into
16
+ * a layer per shape is left out: the project route writes it as one
17
+ * Collection, and QGIS Server names each of its layers separately.
18
+ * - Each Collection's id is the layer's WMS name, and every reference to
19
+ * another Collection is rewritten to that id or, where that Collection is not
20
+ * served, dropped.
21
+ * - Its data is reached through the server only: a WFS GetFeature data asset
22
+ * where the project publishes the layer for WFS, and a WMS link always, in
23
+ * the CRS `chooseWmsCrs` picks from `serverWmsCrsList`. No
24
+ * file path, style asset, `via` link or detail of the layer's own data source
25
+ * is written, nor an Attachment widget's default folder.
26
+ * - A field the project hides from WMS or from WFS is left out of
27
+ * `table:columns`, and every mention of it is dropped: from the form order,
28
+ * the preset filters, the display field, a relation's join, and any
29
+ * expression that uses it, except that a lock's expression becomes `true`
30
+ * and a field editable only while an expression holds becomes read-only, so
31
+ * that hiding a field never unlocks an edit.
32
+ *
33
+ * - The top-level Catalog's extent covers the served layers only, so a layer the
34
+ * project keeps off the web does not widen it.
35
+ *
36
+ * Two inputs come from QGIS Server rather than the project's text, which does
37
+ * not hold them: each field's type, as GetProjectSettings reports it, which
38
+ * gives the column its `type`; and the WGS84 box of a layer whose project saves
39
+ * no `<wgs84extent>`. A field or layer left out of them has none.
40
+ *
41
+ * The access answers of the person asking are not applied; the plugin applies
42
+ * them to this function's result.
43
+ *
44
+ * Throws for a server address that `serverWmsEndpoint` refuses: one that is not
45
+ * an `http` or `https` address, has no host, holds a space or a control
46
+ * character, or holds a user name or password, which every served data address
47
+ * would repeat.
48
+ */
49
+ export declare function generateServerStacCatalogue(project: QgsProject, options: ServerCatalogueOptions): StacCatalog;
50
+ /**
51
+ * The address a served layer's WMS link names: the server's address as
52
+ * written, its scheme lower-cased, less its fragment and any query parameter a
53
+ * WMS request sets, such as `SERVICE` or `REQUEST`. Other parameters, such as
54
+ * `MAP`, are kept as written. The rule is spelled out rather than left to the
55
+ * `URL` class, so that the plugin's Python gives the same address.
56
+ * Null for an address that is not
57
+ * `http` or `https`, has no host, holds a user name or password, or holds a
58
+ * space or a control character. A query holding `@` or the word `password`,
59
+ * in any case and escaped or not, is refused too: it may hold a project's
60
+ * database connection, such as `MAP=postgresql://user:secret@db/…`, which every
61
+ * served address would repeat.
62
+ */
63
+ export declare function serverWmsEndpoint(serverAddress: string): string | null;
64
+ /** A field's type as GetProjectSettings reports it: its Qt type name, such as `qlonglong`, and its provider's type name. */
65
+ export interface QgisFieldType {
66
+ type: string;
67
+ typeName: string;
68
+ }
69
+ export interface ServerCatalogueOptions {
70
+ /** The address QGIS Server serves the project from, as its own `wmsServiceUrl` gives it. */
71
+ serverAddress: string;
72
+ /** Each layer's field types, by layer id and then field name. */
73
+ fieldTypes?: Record<string, Record<string, QgisFieldType>>;
74
+ /** The WGS84 box of a layer whose project saves no `<wgs84extent>`, by layer id. */
75
+ layerWgs84Extents?: Record<string, BoundingBox>;
76
+ }
77
+ /**
78
+ * The CRSs QGIS Server offers a project's WMS layers in: the project's
79
+ * restriction where it saves one, else the project's own CRS, EPSG:4326 and
80
+ * EPSG:3857 (`QgsServerProjectUtils::wmsOutputCrsList`,
81
+ * `src/server/qgsserverprojectutils.cpp`, `qgis/QGIS@master`, read
82
+ * 2026-11-07). The list is the same for every layer.
83
+ */
84
+ export declare function serverWmsCrsList(project: QgsProject): string[];