@vectoriahq/quac 0.2.0 → 0.3.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/README.md CHANGED
@@ -21,10 +21,17 @@ import { parseQgsXml, generateStacCatalogue } from '@vectoriahq/quac'
21
21
 
22
22
  globalThis.DOMParser = DOMParser
23
23
 
24
- const project = parseQgsXml(await readFile('project.qgs', 'utf8'))
25
- const catalogue = generateStacCatalogue(project)
24
+ const project = parseQgsXml(await readFile('survey/project.qgs', 'utf8'))
25
+ const catalogue = generateStacCatalogue(project, [], {
26
+ selfHref: 'https://data.example.test/survey/',
27
+ projectPath: 'project.qgs'
28
+ })
26
29
  ```
27
30
 
31
+ `selfHref` is the address of the folder the project is published in, and `projectPath` is the project file's path inside that folder. A layer's data files and styles are addressed relative to them, so a catalogue to be published or saved apart from the project needs both. Without `projectPath`, each style's address names no file, and only an application already holding the project can read it; without `selfHref`, the catalogue's relative addresses have no folder to start from.
32
+
33
+ `project.notes` lists the project's settings that the catalogue does not carry, such as a widget it does not read or an expression it cannot read. Each note gives the layer, the field where there is one, a reason code and the setting's own text where it helps; the `ProjectNoteReason` type lists the codes and what each means. The notes are not written into the catalogue.
34
+
28
35
  The JSON Schema that checks a catalogue's `quac:` fields is exported as `@vectoriahq/quac/schema`.
29
36
 
30
37
  ## Documentation
@@ -29,7 +29,8 @@ export interface LinkedFileCollectionOptions {
29
29
  * Generates the Collection for one dropped file: a `data` asset naming the file
30
30
  * and its media type, `created` set to the drop time, and the world extent, which
31
31
  * a Collection with no declared box takes. The file is not opened, so nothing
32
- * here describes its contents, and it declares no title of its own.
32
+ * here describes its contents: it declares no title of its own, and its
33
+ * description is `fileLayerDescription`'s, which says only the file's name.
33
34
  *
34
35
  * Pure function — no side effects, no I/O.
35
36
  */
@@ -1,3 +1,4 @@
1
+ import { fileLayerDescription } from "./folderStacCatalogue.js";
1
2
  import { generateStacFromNormalized, slugify } from "./normalizedProject.js";
2
3
  import { QUAC_LAYER_NAME } from "./stacCatalogue.js";
3
4
  import { encodeAssetPath } from "../model/stacHref.js";
@@ -6,7 +7,8 @@ import { declaredMediaTypeForFile, GEOJSON_MEDIA_TYPE } from "../util/catalogueF
6
7
  * Generates the Collection for one dropped file: a `data` asset naming the file
7
8
  * and its media type, `created` set to the drop time, and the world extent, which
8
9
  * a Collection with no declared box takes. The file is not opened, so nothing
9
- * here describes its contents, and it declares no title of its own.
10
+ * here describes its contents: it declares no title of its own, and its
11
+ * description is `fileLayerDescription`'s, which says only the file's name.
10
12
  *
11
13
  * Pure function — no side effects, no I/O.
12
14
  */
@@ -47,7 +49,7 @@ function buildFileCollection(file) {
47
49
  kind: 'layer',
48
50
  id: file.collectionId,
49
51
  title: file.name,
50
- description: '',
52
+ description: fileLayerDescription(file.name),
51
53
  bbox: null,
52
54
  geometryType: null,
53
55
  tableColumns: [],
@@ -46,3 +46,9 @@ export interface FolderStacCatalogueOptions {
46
46
  selfHref?: string;
47
47
  }
48
48
  export declare function generateStacCatalogueFromFolder(files: FolderCatalogueFile[], options: FolderStacCatalogueOptions): StacCatalog;
49
+ /**
50
+ * The description of a Collection made from one data file, which says nothing
51
+ * of itself: `Layer from roads.geojson.`. The folder's files and a single
52
+ * dropped or linked file share it.
53
+ */
54
+ export declare function fileLayerDescription(fileName: string): string;
@@ -54,7 +54,7 @@ function fileToNormalized(file) {
54
54
  kind: 'layer',
55
55
  id: file.relPath,
56
56
  title: file.layerName,
57
- description: `Layer from ${file.name}.`,
57
+ description: fileLayerDescription(file.name),
58
58
  // Both read from the file at load time, not from the listing.
59
59
  bbox: null,
60
60
  geometryType: null,
@@ -67,3 +67,11 @@ function fileToNormalized(file) {
67
67
  editable: null
68
68
  };
69
69
  }
70
+ /**
71
+ * The description of a Collection made from one data file, which says nothing
72
+ * of itself: `Layer from roads.geojson.`. The folder's files and a single
73
+ * dropped or linked file share it.
74
+ */
75
+ export function fileLayerDescription(fileName) {
76
+ return `Layer from ${fileName}.`;
77
+ }
@@ -10,6 +10,7 @@ import { buildWmsLink, WEB_MAP_LINKS_EXTENSION } from "../model/stacWms.js";
10
10
  import { buildWmtsLink } from "../model/stacWmts.js";
11
11
  import { buildXyzLink } from "../model/stacXyz.js";
12
12
  import { findGeometrySiblings, readSiblingShapes, siblingCollectionId } from "../parse/geometrySiblings.js";
13
+ import { findValueRelationLookup, isFilterInProject, isRelationInProject } from "../parse/projectNotes.js";
13
14
  import { declaredMediaTypeForFile, isLayerFileOfFormat, PROJECT_DATA_ROLES, QML_STYLE_MEDIA_TYPE } from "../util/catalogueFileFormats.js";
14
15
  /**
15
16
  * Generates a STAC Catalog tree from a parsed QgsProject.
@@ -37,7 +38,9 @@ export function generateStacCatalogue(project, companions = [], options = {}) {
37
38
  // the layers' style assets address into — a path, not an href, so the
38
39
  // generator is the one place that escapes it. A caller that doesn't know
39
40
  // where the project file sits leaves it off, and the style assets fall back
40
- // to a bare fragment — see `buildStyleAssets`.
41
+ // to a bare fragment — see `buildStyleAssets` — which only a reader already
42
+ // holding the project can follow. A catalogue to be published or saved apart
43
+ // from the project needs both `selfHref` and `projectPath`.
41
44
  //
42
45
  // `projectFileName` is the project file's name for each layer's `via` link
43
46
  // alone, where the caller knows it but leaves `projectPath` off, as the drop
@@ -163,9 +166,10 @@ function qgsProjectToNormalized(project, companions, projectPath, projectFileNam
163
166
  */
164
167
  function collectFiltersByCollectionId(filters, layersById, collectionIdOf) {
165
168
  const byCollectionId = new Map();
166
- for (const { layerId, field, name } of filters) {
167
- if (!layersById.get(layerId)?.fieldNames.includes(field))
169
+ for (const filter of filters) {
170
+ if (!isFilterInProject(filter, layersById))
168
171
  continue;
172
+ const { layerId, field, name } = filter;
169
173
  const collectionId = collectionIdOf(layerId);
170
174
  byCollectionId.set(collectionId, [...(byCollectionId.get(collectionId) ?? []), { field, name }]);
171
175
  }
@@ -183,7 +187,7 @@ function collectFiltersByCollectionId(filters, layersById, collectionIdOf) {
183
187
  function collectRelationsByChildLayerId(relations, layersById, collectionIdOf) {
184
188
  const byChildLayerId = new Map();
185
189
  for (const relation of relations) {
186
- if (!layersById.has(relation.parentLayerId) || !layersById.has(relation.childLayerId))
190
+ if (!isRelationInProject(relation, layersById))
187
191
  continue;
188
192
  const childCollectionId = collectionIdOf(relation.childLayerId);
189
193
  const forChild = byChildLayerId.get(childCollectionId) ?? [];
@@ -199,10 +203,8 @@ function collectRelationsByChildLayerId(relations, layersById, collectionIdOf) {
199
203
  }
200
204
  /**
201
205
  * Each layer's Value Relation widgets as `quac:value_relation` writes
202
- * them, keyed by layer id and then field name. The lookup is found by layer id
203
- * and then by layer name, as QGIS finds it
204
- * (`QgsVectorLayerRef::resolveByIdOrNameOnly`, `src/core/qgsvectorlayerref.cpp`,
205
- * `qgis/QGIS@master`); its Collection id is its layer id. A widget naming a
206
+ * them, keyed by layer id and then field name. The lookup is found as
207
+ * `findValueRelationLookup` finds it; its Collection id is its layer id. A widget naming a
206
208
  * layer the project does not hold writes nothing, since it would point at a
207
209
  * Collection this catalogue has no entry for.
208
210
  */
@@ -211,7 +213,7 @@ function collectValueRelationsByLayerId(layers, layersById, collectionIdOf) {
211
213
  for (const layer of layers) {
212
214
  const relations = {};
213
215
  for (const [field, widget] of Object.entries(layer.fieldValueRelations)) {
214
- const lookup = layersById.get(widget.layerId) ?? layers.find((candidate) => candidate.name === widget.layerName);
216
+ const lookup = findValueRelationLookup(widget, layers, layersById);
215
217
  if (lookup)
216
218
  relations[field] = valueRelationToJson(collectionIdOf(lookup.id), widget);
217
219
  }
@@ -546,16 +548,11 @@ function buildAssets(layer, geometryFilter) {
546
548
  }
547
549
  };
548
550
  }
549
- // Unsupported source: a placeholder asset naming the provider. The data
550
- // source itself is not written, because a database connection string can
551
- // hold a user name and password.
552
- return {
553
- data: {
554
- href: '',
555
- title: `Unsupported source: ${ds.hint ?? 'unknown'}`,
556
- roles: ['data']
557
- }
558
- };
551
+ // A source the catalogue cannot address, such as a database, has no data
552
+ // asset: STAC requires an asset's href, and the source's own address is not
553
+ // written because a database connection string can hold a user name and
554
+ // password. The project's `source` note names the provider.
555
+ return {};
559
556
  }
560
557
  /**
561
558
  * Declares a layer's named styles as `style` assets, one per style the project
@@ -1,7 +1,6 @@
1
1
  import { slugify, generateStacFromNormalized } from "./normalizedProject.js";
2
2
  import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
3
3
  import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, wmsEndpoint } from "../model/stacWms.js";
4
- import { GEOJSON_MEDIA_TYPE } from "../util/catalogueFileFormats.js";
5
4
  export function generateStacCatalogueFromWms(project, options = {}) {
6
5
  return generateStacFromNormalized(wmsProjectToNormalized(project, options));
7
6
  }
@@ -42,10 +41,10 @@ function walkWmsNodes(nodes, context) {
42
41
  const out = [];
43
42
  for (const node of nodes) {
44
43
  if (node.kind === 'layer') {
45
- const wmsLink = context.wmsEndpoint && !context.wfsPublished.has(node.name)
46
- ? buildQgisServerWmsLink(context.wmsEndpoint, node)
44
+ const wmsLinks = context.wmsEndpoint && !context.wfsPublished.has(node.name)
45
+ ? buildQgisServerWmsLinks(context.wmsEndpoint, node)
47
46
  : null;
48
- out.push(wmsLink ? wmsOnlyLayerToNormalized(node, wmsLink) : wmsLayerToNormalized(node, context.resolveWfsSource(node)));
47
+ out.push(wmsLinks ? wmsOnlyLayerToNormalized(node, wmsLinks) : wmsLayerToNormalized(node, context.resolveWfsSource(node)));
49
48
  }
50
49
  else {
51
50
  const subId = slugify(node.title || node.name || 'group') || 'group';
@@ -85,27 +84,38 @@ function wmsLayerToNormalized(layer, wfsSource) {
85
84
  };
86
85
  }
87
86
  /**
88
- * A GetMap link for a layer QGIS Server publishes only over WMS. The style is
89
- * left empty, which asks the server for the layer's default style. No version
90
- * is stated, so an application reading the catalogue asks the server for one
87
+ * The GetMap links for a layer QGIS Server publishes only over WMS. The first
88
+ * leaves the style empty, which draws the layer's current style
89
+ * (`QgsRenderer::setLayerStyle`, `src/server/services/wms/qgswmsrenderer.cpp`,
90
+ * `qgis/QGIS@master`, read 2026-11-15). Where the layer has more than one
91
+ * named style, one link follows for each, titled with the style's title.
92
+ * GetProjectSettings lists the styles in name order and does not say which is
93
+ * current (`QgsMapLayerStyleManager::styles`, `src/core/qgsmaplayerstylemanager.cpp`,
94
+ * and `appendLayerStyles`, `src/server/services/wms/qgswmsgetcapabilities.cpp`,
95
+ * same revision), so the current one is also among them. No version is
96
+ * stated, so an application reading the catalogue asks the server for one
91
97
  * when the layer is first shown.
92
98
  */
93
- function buildQgisServerWmsLink(endpoint, layer) {
94
- return {
99
+ function buildQgisServerWmsLinks(endpoint, layer) {
100
+ const link = (style) => ({
95
101
  rel: 'wms',
96
102
  href: endpoint,
97
103
  type: 'image/png',
98
104
  'wms:layers': [layer.name],
99
- 'wms:styles': [''],
105
+ 'wms:styles': [style],
100
106
  'wms:transparent': true,
101
107
  'quac:wms_crs': chooseWmsCrs(layer.crsList)
102
- };
108
+ });
109
+ const named = layer.styles.length > 1
110
+ ? layer.styles.map((style) => ({ ...link(style.name), title: style.title || style.name }))
111
+ : [];
112
+ return [link(''), ...named];
103
113
  }
104
114
  /**
105
115
  * A layer QGIS Server publishes only over WMS: an image layer, so it has no data
106
116
  * asset, fields or editing, as a QGIS project's WMS layer has none.
107
117
  */
108
- function wmsOnlyLayerToNormalized(layer, wmsLink) {
118
+ function wmsOnlyLayerToNormalized(layer, wmsLinks) {
109
119
  return {
110
120
  kind: 'layer',
111
121
  id: layer.name,
@@ -124,7 +134,7 @@ function wmsOnlyLayerToNormalized(layer, wmsLink) {
124
134
  scaleRange: layer.scaleRange,
125
135
  opacity: layer.opacity,
126
136
  vendorFields: {},
127
- links: [wmsLink],
137
+ links: wmsLinks,
128
138
  extensions: [WEB_MAP_LINKS_EXTENSION]
129
139
  };
130
140
  }
@@ -145,20 +155,9 @@ function wmsBboxToNormalized(bbox) {
145
155
  };
146
156
  }
147
157
  function buildAssets(layer, wfsSource) {
148
- if (wfsSource?.typeName)
149
- return { data: wfsGetFeatureAsset(wfsSource.endpoint, wfsSource.typeName, layer.name) };
150
- // Without a resolved type the href is left empty: the live URL is
151
- // server-specific and is constructed by the QgisServerAdapter at fetch
152
- // time, so the asset entry only documents that the data is available.
153
- return {
154
- data: {
155
- href: '',
156
- type: GEOJSON_MEDIA_TYPE,
157
- // Text written into the catalogue document, which carries the project's own name.
158
- title: `WFS GetFeature: ${layer.name}`,
159
- roles: ['data']
160
- }
161
- };
158
+ // A layer with no WFS type name has no address to fetch its features from,
159
+ // and STAC requires an asset's href, so it has no data asset.
160
+ return wfsSource?.typeName ? { data: wfsGetFeatureAsset(wfsSource.endpoint, wfsSource.typeName, layer.name) } : {};
162
161
  }
163
162
  /**
164
163
  * Maps QGIS Qt types from GetProjectSettings into STAC Table extension
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * The package's public API: everything an application imports from
3
3
  * `@vectoriahq/quac`.
4
4
  */
5
- export type { QgsProject, ProjectMetadata, MapExtent, BoundingBox, LayerEntry, EditLock, LayerLocks, LockedEdit, ProjectMeasurement, LayerStyle, LayerResourceMetadata, LayerScaleRange, LayerContact, LayerAttribution, FieldAttachment, FieldCheckbox, FieldConstraintExpression, FieldDefaultExpression, FieldDefaultValue, FieldEditRule, FormLayoutField, LayerFormLayout, FieldFixedValue, FieldRange, FieldUuidFormat, FieldValueMapEntry, DataSource, FileDataSource, WfsDataSource, WmsDataSource, UnsupportedDataSource, LayerTreeNode, LayerGroup, LayerTreeLeaf, QgsRelation, QgsRelationFieldPair } from './model/QgsProject.ts';
5
+ export type { QgsProject, ProjectMetadata, MapExtent, BoundingBox, LayerEntry, EditLock, LayerLocks, LockedEdit, ProjectMeasurement, LayerStyle, LayerResourceMetadata, LayerScaleRange, LayerContact, LayerAttribution, FieldAttachment, FieldCheckbox, FieldConstraintExpression, FieldDefaultExpression, FieldDefaultValue, FieldEditRule, FormLayoutField, LayerFormLayout, FieldFixedValue, FieldRange, FieldUuidFormat, FieldValueMapEntry, DataSource, FileDataSource, WfsDataSource, WmsDataSource, UnsupportedDataSource, LayerTreeNode, LayerGroup, LayerTreeLeaf, QgsRelation, QgsRelationFieldPair, ProjectNote, ProjectNoteReason } from './model/QgsProject.ts';
6
6
  export type { StacCatalog, StacCollection, StacItem, StacAsset, StacExtent, StacLink, StacObject, StacProvider, TableColumn, TableColumnType, TableColumnValue, TableColumnValueRelation, TableColumnAttachment, TableColumnCheckbox, TableColumnRange } from './model/Stac.ts';
7
7
  export { STAC_VERSION } from './model/Stac.ts';
8
8
  export { isIconLibraryAddress, resolveFieldIconAddress } from './model/fieldIconAddress.ts';
@@ -59,7 +59,7 @@ export type { StacWmtsSource } from './model/stacWmts.ts';
59
59
  export { VECTOR_TILE_MEDIA_TYPE, buildXyzLink, readCollectionXyzLink, readCollectionXyzTemplate } from './model/stacXyz.ts';
60
60
  export type { ActiveWfsLayer, WfsCapabilities, WfsDescribeFeatureTypeSchema, WfsFeatureTypeOperationsSupport, WfsFeatureTypeSummary, WfsFieldKind, WfsFieldSchema, WfsOperationName, WfsTransactionOperation, WfsTransactionResult, WfsValidationError, WfsWgs84BoundingBox } from './model/wfs.ts';
61
61
  export { parseProjectMeasurement } from './parse/parseMeasurement.ts';
62
- export { GEOMETRY_VALUES, LAYER_LOOKUP, QGIS_CONDITION, expressionToGeoStylerFunction, expressionToTemplate, isQgisConditionFilter, qgisConditionToFilter, readCurrentValueFields, readLayerLookups, readQgisExpression } from './parse/qgisExpression.ts';
62
+ export { EXPRESSION_VARIABLE, GEOMETRY_VALUES, LAYER_LOOKUP, QGIS_CONDITION, expressionToGeoStylerFunction, expressionToTemplate, isQgisConditionFilter, qgisConditionToFilter, readCurrentValueFields, readLayerLookups, readQgisExpression } from './parse/qgisExpression.ts';
63
63
  export type { ExpressionNode, LayerLookup } from './parse/qgisExpression.ts';
64
64
  export { formatQtDateTime, qtDatePart, readQtDateTime, splitQtDatePattern } from './parse/qtDateFormat.ts';
65
65
  export { compileQtRegex, replaceQtRegex } from './parse/qtRegex.ts';
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ export { WEB_MAP_LINKS_EXTENSION, buildWmsLink, readCollectionWms, wmsEndpoint }
38
38
  export { readCollectionWmts, wmtsCapabilitiesUrl } from "./model/stacWmts.js";
39
39
  export { VECTOR_TILE_MEDIA_TYPE, buildXyzLink, readCollectionXyzLink, readCollectionXyzTemplate } from "./model/stacXyz.js";
40
40
  export { parseProjectMeasurement } from "./parse/parseMeasurement.js";
41
- export { GEOMETRY_VALUES, LAYER_LOOKUP, QGIS_CONDITION, expressionToGeoStylerFunction, expressionToTemplate, isQgisConditionFilter, qgisConditionToFilter, readCurrentValueFields, readLayerLookups, readQgisExpression } from "./parse/qgisExpression.js";
41
+ export { EXPRESSION_VARIABLE, GEOMETRY_VALUES, LAYER_LOOKUP, QGIS_CONDITION, expressionToGeoStylerFunction, expressionToTemplate, isQgisConditionFilter, qgisConditionToFilter, readCurrentValueFields, readLayerLookups, readQgisExpression } from "./parse/qgisExpression.js";
42
42
  export { formatQtDateTime, qtDatePart, readQtDateTime, splitQtDatePattern } from "./parse/qtDateFormat.js";
43
43
  export { compileQtRegex, replaceQtRegex } from "./parse/qtRegex.js";
44
44
  export { cloneCatalogShallow, collectAllCollections, resolveDocumentHrefs, withSelfLink } from "./sources/stacDocuments.js";
@@ -60,9 +60,52 @@ export interface QgsProject {
60
60
  * (`parseMerginFilters`); absent or empty where it sets none.
61
61
  */
62
62
  merginFilters?: PresetFilter[];
63
+ /**
64
+ * The project's settings that `generateStacCatalogue` does not carry into the
65
+ * catalogue (`ProjectNote`); absent or empty where it carries them all. The
66
+ * notes are not written into the catalogue.
67
+ */
68
+ notes?: ProjectNote[];
63
69
  /** Original full QGS XML, retained so future parsers can re-mine without re-loading. */
64
70
  rawXml: string | null;
65
71
  }
72
+ /**
73
+ * Why a project's setting is not in its catalogue:
74
+ *
75
+ * - `widget`: a field's edit widget is not read, by its type, or is read but
76
+ * holds nothing the catalogue can carry: an Attachment that picks a folder or
77
+ * several files, or a Value Relation lacking its lookup layer, key or value.
78
+ * - `default`: a field's default value expression is not read.
79
+ * - `constraint`: a field's constraint expression is not read.
80
+ * - `value-relation`: a field's Value Relation names a lookup layer the
81
+ * project does not hold.
82
+ * - `source`: a layer's data source is not one the catalogue can address,
83
+ * such as a database or a service that needs a login. The layer's
84
+ * Collection has no data asset.
85
+ * - `relation`: a relation names a layer the project does not hold.
86
+ * - `filter`: a Mergin Maps filter is a `Text` filter, or names a layer the
87
+ * project does not hold or a field its layer does not have.
88
+ * - `layer`: a layer could not be read at all, and has no Collection.
89
+ */
90
+ export type ProjectNoteReason = 'widget' | 'default' | 'constraint' | 'value-relation' | 'source' | 'relation' | 'filter' | 'layer';
91
+ /** One setting of a project that its catalogue does not carry. */
92
+ export interface ProjectNote {
93
+ /** The id of the layer the setting belongs to: a relation's child layer, a filter's layer. */
94
+ layerId: string;
95
+ /** That layer's name; empty where the project holds no layer with the id. */
96
+ layerName: string;
97
+ /** The field the setting belongs to; null for a setting of the layer. */
98
+ field: string | null;
99
+ reason: ProjectNoteReason;
100
+ /**
101
+ * The setting's own text, where it says what was not carried: the widget's
102
+ * type, the expression, the lookup layer's name, the source's provider, the
103
+ * relation's name or the filter's type. Null otherwise. A data source's
104
+ * address is never given, because a database connection can hold a user name
105
+ * and password.
106
+ */
107
+ text: string | null;
108
+ }
66
109
  /**
67
110
  * The parts of QGIS's project-level `<projectMetadata>` this package reads.
68
111
  * QGIS's own dialog (Project Properties > Metadata) writes the element on
@@ -38,8 +38,8 @@ export declare function isRelativeHref(href: string): boolean;
38
38
  * — the counterpart of the data asset both the QGIS project and the folder
39
39
  * generators write.
40
40
  *
41
- * Returns null for an asset that is not a relative path: a WFS GetFeature URL,
42
- * the empty href an unsupported source gets, or any absolute address. Those are
41
+ * Returns null where there is no data asset, or its href is not a relative
42
+ * path: a WFS GetFeature URL or any other absolute address. Those are
43
43
  * not files in the folder, so there is nothing here to look up.
44
44
  */
45
45
  export declare function readCollectionDataPath(collection: StacCollection): string | null;
@@ -47,8 +47,8 @@ export function isRelativeHref(href) {
47
47
  * — the counterpart of the data asset both the QGIS project and the folder
48
48
  * generators write.
49
49
  *
50
- * Returns null for an asset that is not a relative path: a WFS GetFeature URL,
51
- * the empty href an unsupported source gets, or any absolute address. Those are
50
+ * Returns null where there is no data asset, or its href is not a relative
51
+ * path: a WFS GetFeature URL or any other absolute address. Those are
52
52
  * not files in the folder, so there is nothing here to look up.
53
53
  */
54
54
  export function readCollectionDataPath(collection) {
@@ -1,4 +1,4 @@
1
- import type { LayerEntry } from '../model/QgsProject.ts';
1
+ import type { LayerEntry, ProjectNote } from '../model/QgsProject.ts';
2
2
  /**
3
3
  * Parses the <projectlayers> block into a list of LayerEntry. Annotation
4
4
  * layers (<main-annotation-layer>) are filtered out — they're QGIS's drawing
@@ -19,5 +19,8 @@ import type { LayerEntry } from '../model/QgsProject.ts';
19
19
  *
20
20
  * On any per-layer failure the layer is skipped (logged via devLog) so a
21
21
  * single bad layer doesn't take down the whole project.
22
+ *
23
+ * Each setting a layer holds that its Collection will not carry is added to
24
+ * `notes` (`ProjectNote`), as is each layer skipped.
22
25
  */
23
- export declare function parseProjectLayers(qgisRoot: Element): LayerEntry[];
26
+ export declare function parseProjectLayers(qgisRoot: Element, notes?: ProjectNote[]): LayerEntry[];
@@ -26,8 +26,11 @@ import { devLog } from "../util/devLog.js";
26
26
  *
27
27
  * On any per-layer failure the layer is skipped (logged via devLog) so a
28
28
  * single bad layer doesn't take down the whole project.
29
+ *
30
+ * Each setting a layer holds that its Collection will not carry is added to
31
+ * `notes` (`ProjectNote`), as is each layer skipped.
29
32
  */
30
- export function parseProjectLayers(qgisRoot) {
33
+ export function parseProjectLayers(qgisRoot, notes = []) {
31
34
  const projectLayers = qgisRoot.querySelector('projectlayers');
32
35
  if (!projectLayers)
33
36
  return [];
@@ -36,11 +39,18 @@ export function parseProjectLayers(qgisRoot) {
36
39
  if (node.tagName !== 'maplayer')
37
40
  continue;
38
41
  try {
39
- const layer = parseMapLayer(node);
42
+ const layer = parseMapLayer(node, notes);
40
43
  if (layer)
41
44
  layers.push(layer);
42
45
  }
43
46
  catch (err) {
47
+ notes.push({
48
+ layerId: node.querySelector('id')?.textContent?.trim() ?? '',
49
+ layerName: node.querySelector('layername')?.textContent?.trim() ?? '',
50
+ field: null,
51
+ reason: 'layer',
52
+ text: null
53
+ });
44
54
  devLog('qgs/parseLayers', 'failed to parse a maplayer; skipping', {
45
55
  error: String(err),
46
56
  id: node.querySelector('id')?.textContent ?? '<unknown>'
@@ -49,11 +59,13 @@ export function parseProjectLayers(qgisRoot) {
49
59
  }
50
60
  return layers;
51
61
  }
52
- function parseMapLayer(maplayer) {
62
+ function parseMapLayer(maplayer, notes) {
53
63
  const id = maplayer.querySelector('id')?.textContent?.trim();
54
64
  const name = maplayer.querySelector('layername')?.textContent?.trim() ?? '';
55
65
  if (!id)
56
66
  return null;
67
+ const layerNotes = [];
68
+ const note = (reason, field, text) => layerNotes.push({ layerId: id, layerName: name, field, reason, text });
57
69
  const type = maplayer.getAttribute('type') ?? '';
58
70
  const geometryType = maplayer.getAttribute('geometry') || null;
59
71
  const wkbType = maplayer.getAttribute('wkbType') || null;
@@ -66,7 +78,12 @@ function parseMapLayer(maplayer) {
66
78
  const fieldNames = parseFieldNames(maplayer);
67
79
  const fieldAliases = parseFieldAliases(maplayer);
68
80
  const { styles, activeIndex } = parseLayerStyles(maplayer);
69
- return {
81
+ const fieldValueRelations = parseFieldValueRelations(maplayer);
82
+ const fieldAttachments = parseFieldAttachments(maplayer);
83
+ if (dataSource.kind === 'unsupported')
84
+ note('source', null, dataSource.hint);
85
+ noteUnreadWidgets(maplayer, { fieldValueRelations, fieldAttachments }, note);
86
+ const layer = {
70
87
  id,
71
88
  name,
72
89
  type,
@@ -95,9 +112,9 @@ function parseMapLayer(maplayer) {
95
112
  fieldValueMaps: parseFieldValueMaps(maplayer),
96
113
  isPrivate: parsePrivate(maplayer),
97
114
  legendImage: parseLegendImage(maplayer),
98
- fieldValueRelations: parseFieldValueRelations(maplayer),
99
- fieldAttachments: parseFieldAttachments(maplayer),
100
- fieldEditRules: parseFieldEditRules(maplayer),
115
+ fieldValueRelations,
116
+ fieldAttachments,
117
+ fieldEditRules: parseFieldEditRules(maplayer, note),
101
118
  icon: parseLayerIcon(maplayer),
102
119
  fieldIcons: parseFieldIcons(maplayer),
103
120
  fieldControls: parseFieldControls(maplayer),
@@ -106,6 +123,33 @@ function parseMapLayer(maplayer) {
106
123
  locks: parseQfieldSyncLocks(maplayer),
107
124
  rawXml: new XMLSerializer().serializeToString(maplayer)
108
125
  };
126
+ // Added once the layer is read whole, so a layer that fails part way leaves one `layer` note.
127
+ notes.push(...layerNotes);
128
+ return layer;
129
+ }
130
+ /**
131
+ * The edit widgets whose settings a Collection carries, by the type QGIS saves
132
+ * in `<editWidget type>`. `TextEdit` is QGIS's plain text box, which needs
133
+ * nothing carried. An empty type is a field with no widget set.
134
+ */
135
+ const READ_WIDGET_TYPES = new Set(['', 'TextEdit', 'ValueMap', 'ValueRelation', 'ExternalResource', 'Hidden', 'Color', 'CheckBox', 'Range', 'DateTime', 'UuidGenerator']);
136
+ /**
137
+ * Notes each field's widget the Collection does not carry: one of a type not
138
+ * in `READ_WIDGET_TYPES`, and a Value Relation or Attachment widget its reader
139
+ * above passed over.
140
+ */
141
+ function noteUnreadWidgets(maplayer, read, note) {
142
+ const seen = new Set();
143
+ for (const [name, editWidget] of layerEditWidgets(maplayer)) {
144
+ if (seen.has(name) || !editWidget)
145
+ continue;
146
+ seen.add(name);
147
+ const type = editWidget.getAttribute('type') ?? '';
148
+ const passedOver = (type === 'ValueRelation' && !read.fieldValueRelations[name]) ||
149
+ (type === 'ExternalResource' && !read.fieldAttachments[name]);
150
+ if (!READ_WIDGET_TYPES.has(type) || passedOver)
151
+ note('widget', name, type);
152
+ }
109
153
  }
110
154
  /**
111
155
  * The fields QGIS Server hides from WMS and from WFS. QGIS saves each field's
@@ -452,7 +496,7 @@ const NOW_EXPRESSIONS = new Set(['now()', '$now', 'to_date(now())', 'to_datetime
452
496
  * `<editable>` block does not list is editable. A field with none of these
453
497
  * settings is absent from the returned map.
454
498
  */
455
- function parseFieldEditRules(maplayer) {
499
+ function parseFieldEditRules(maplayer, note) {
456
500
  const result = {};
457
501
  const ruleFor = (name) => {
458
502
  result[name] ??= { readOnly: false, defaultValue: null, notNull: null, unique: null, hidden: false, reuseLastValue: false, duplicatePolicy: null };
@@ -471,8 +515,10 @@ function parseFieldEditRules(maplayer) {
471
515
  const defaultValue = parseDefaultExpression(expression, onUpdate);
472
516
  if (defaultValue)
473
517
  ruleFor(name).defaultValue = defaultValue;
474
- else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true }))
518
+ else if (readQgisExpression(expression, { geometry: true, aggregates: true, lookups: true, variables: true }))
475
519
  ruleFor(name).defaultExpression = { expression: expression.trim(), onUpdate };
520
+ else
521
+ note('default', name, expression.trim());
476
522
  }
477
523
  // The UUID Generator widget disables its line edit and fills a null field
478
524
  // with `QUuid::createUuid().toString()`, which has braces
@@ -540,14 +586,16 @@ function parseFieldEditRules(maplayer) {
540
586
  ruleFor(name).unique = unique;
541
587
  }
542
588
  const written = constraintExpressions.get(name);
543
- if (constraints & 4 && written && readQgisExpression(written.expression, { geometry: true })) {
544
- const strength = constraintStrength(node.getAttribute('exp_strength'));
545
- if (strength) {
589
+ const strength = constraintStrength(node.getAttribute('exp_strength'));
590
+ if (constraints & 4 && written && strength) {
591
+ if (readQgisExpression(written.expression, { geometry: true })) {
546
592
  const expression = { expression: written.expression, strength };
547
593
  if (written.description)
548
594
  expression.description = written.description;
549
595
  ruleFor(name).constraintExpression = expression;
550
596
  }
597
+ else
598
+ note('constraint', name, written.expression);
551
599
  }
552
600
  }
553
601
  // A Range with Allow NULL off, or a Date/Time with it off, is a required
@@ -13,7 +13,7 @@ import type { PresetFilter } from '../model/QgsProject.ts';
13
13
  * `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
14
14
  * does. `sql_expression`, a template for the data source's own SQL, is not
15
15
  * read beyond that: the filter row filters the field itself. A `Text` filter
16
- * is left out. Empty where the project sets none, or the list does not read
17
- * as JSON.
16
+ * is left out, and added to `textFilters`. Empty where the project sets none,
17
+ * or the list does not read as JSON.
18
18
  */
19
- export declare function parseMerginFilters(qgisRoot: Element): PresetFilter[];
19
+ export declare function parseMerginFilters(qgisRoot: Element, textFilters?: PresetFilter[]): PresetFilter[];
@@ -16,10 +16,10 @@ const READ_FILTER_TYPES = new Set(['Number', 'Date', 'Checkbox', 'Single select'
16
16
  * `app/filter/filtercontroller.cpp`, `MerginMaps/mobile@779434d`), as this
17
17
  * does. `sql_expression`, a template for the data source's own SQL, is not
18
18
  * read beyond that: the filter row filters the field itself. A `Text` filter
19
- * is left out. Empty where the project sets none, or the list does not read
20
- * as JSON.
19
+ * is left out, and added to `textFilters`. Empty where the project sets none,
20
+ * or the list does not read as JSON.
21
21
  */
22
- export function parseMerginFilters(qgisRoot) {
22
+ export function parseMerginFilters(qgisRoot, textFilters = []) {
23
23
  const block = readPropertyBlock(qgisRoot, 'Mergin');
24
24
  const filtering = block ? propertyChild(block, 'Filtering') : null;
25
25
  if (!filtering || !isTrueValue(propertyText(filtering, 'Enabled')))
@@ -44,8 +44,11 @@ export function parseMerginFilters(qgisRoot) {
44
44
  const layerId = text(filter, 'layer_id');
45
45
  const field = text(filter, 'field_name');
46
46
  const type = text(filter, 'filter_type');
47
- if (!layerId || !field || !text(filter, 'sql_expression') || !type || !READ_FILTER_TYPES.has(type))
47
+ if (!layerId || !field || !text(filter, 'sql_expression') || !type)
48
48
  return [];
49
- return [{ layerId, field, name: text(filter, 'filter_name')?.trim() ?? null }];
49
+ const preset = { layerId, field, name: text(filter, 'filter_name')?.trim() ?? null };
50
+ if (type === 'Text')
51
+ textFilters.push(preset);
52
+ return READ_FILTER_TYPES.has(type) ? [preset] : [];
50
53
  });
51
54
  }
@@ -8,6 +8,7 @@ import { parseMerginFilters } from "./parseMergin.js";
8
8
  import { parseProjectVariables } from "./parseProjectVariables.js";
9
9
  import { parseInitialActiveLayerId, parseWfsTransactionLayers } from "./parseQfieldSync.js";
10
10
  import { parseProjectRelations } from "./parseRelations.js";
11
+ import { crossLayerNotes } from "./projectNotes.js";
11
12
  import { parseWmsCrsList, parseWmsPublishing } from "./parseWmsPublishing.js";
12
13
  import { devLog } from "../util/devLog.js";
13
14
  /**
@@ -39,9 +40,13 @@ export function parseQgsXml(xmlText) {
39
40
  const title = qgisRoot.querySelector(':scope > title')?.textContent?.trim() ?? '';
40
41
  const projectCrs = readProjectCrs(qgisRoot);
41
42
  const mapExtent = parseMapExtent(qgisRoot, projectCrs);
42
- const rawLayers = parseProjectLayers(qgisRoot);
43
+ const notes = [];
44
+ const rawLayers = parseProjectLayers(qgisRoot, notes);
43
45
  const layerTree = parseLegendTree(qgisRoot);
44
46
  const relations = parseProjectRelations(qgisRoot);
47
+ const textFilters = [];
48
+ const merginFilters = parseMerginFilters(qgisRoot, textFilters);
49
+ notes.push(...crossLayerNotes(rawLayers, relations, merginFilters, textFilters));
45
50
  // Visibility flows from the layer tree (where checked state is stored), not
46
51
  // from the maplayer itself. Walk the tree once, build a layerId →
47
52
  // effective visibility map, and apply it to each LayerEntry.
@@ -55,7 +60,8 @@ export function parseQgsXml(xmlText) {
55
60
  title,
56
61
  projectCrs,
57
62
  layerCount: layers.length,
58
- relationCount: relations.length
63
+ relationCount: relations.length,
64
+ noteCount: notes.length
59
65
  });
60
66
  return {
61
67
  qgisVersion,
@@ -73,7 +79,8 @@ export function parseQgsXml(xmlText) {
73
79
  wfsTransactionLayers: parseWfsTransactionLayers(qgisRoot),
74
80
  wmsPublishing: parseWmsPublishing(qgisRoot),
75
81
  wmsCrsList: parseWmsCrsList(qgisRoot),
76
- merginFilters: parseMerginFilters(qgisRoot),
82
+ merginFilters,
83
+ notes,
77
84
  rawXml: xmlText
78
85
  };
79
86
  }
@@ -0,0 +1,26 @@
1
+ import type { FieldValueRelation, LayerEntry, PresetFilter, ProjectNote, QgsRelation } from '../model/QgsProject.ts';
2
+ /**
3
+ * The rules that decide whether a setting naming another layer reaches the
4
+ * catalogue, and the notes for those that do not. `generateStacCatalogue`
5
+ * applies the same rules through these functions, so a note and the catalogue
6
+ * cannot disagree.
7
+ */
8
+ /**
9
+ * The layer a Value Relation widget reads its choices from: the layer whose
10
+ * id the widget names, and where none has it the first layer with the name it
11
+ * names, as QGIS finds it (`QgsVectorLayerRef::resolveByIdOrNameOnly`,
12
+ * `src/core/qgsvectorlayerref.cpp`, `qgis/QGIS@master`). Undefined where the
13
+ * project holds neither.
14
+ */
15
+ export declare function findValueRelationLookup(widget: FieldValueRelation, layers: readonly LayerEntry[], layersById: ReadonlyMap<string, LayerEntry>): LayerEntry | undefined;
16
+ /** Whether the project holds both of a relation's layers. */
17
+ export declare function isRelationInProject(relation: QgsRelation, layersById: ReadonlyMap<string, LayerEntry>): boolean;
18
+ /** Whether the project holds a filter's layer and that layer has its field. */
19
+ export declare function isFilterInProject(filter: PresetFilter, layersById: ReadonlyMap<string, LayerEntry>): boolean;
20
+ /**
21
+ * The notes for the settings that name another layer and do not reach the
22
+ * catalogue: Value Relations, relations and filters, in that order, and each
23
+ * in the project's order. `textFilters` are the Mergin Maps `Text` filters
24
+ * `parseMerginFilters` passes over.
25
+ */
26
+ export declare function crossLayerNotes(layers: readonly LayerEntry[], relations: readonly QgsRelation[], filters: readonly PresetFilter[], textFilters: readonly PresetFilter[]): ProjectNote[];
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The rules that decide whether a setting naming another layer reaches the
3
+ * catalogue, and the notes for those that do not. `generateStacCatalogue`
4
+ * applies the same rules through these functions, so a note and the catalogue
5
+ * cannot disagree.
6
+ */
7
+ /**
8
+ * The layer a Value Relation widget reads its choices from: the layer whose
9
+ * id the widget names, and where none has it the first layer with the name it
10
+ * names, as QGIS finds it (`QgsVectorLayerRef::resolveByIdOrNameOnly`,
11
+ * `src/core/qgsvectorlayerref.cpp`, `qgis/QGIS@master`). Undefined where the
12
+ * project holds neither.
13
+ */
14
+ export function findValueRelationLookup(widget, layers, layersById) {
15
+ return layersById.get(widget.layerId) ?? layers.find((candidate) => candidate.name === widget.layerName);
16
+ }
17
+ /** Whether the project holds both of a relation's layers. */
18
+ export function isRelationInProject(relation, layersById) {
19
+ return layersById.has(relation.parentLayerId) && layersById.has(relation.childLayerId);
20
+ }
21
+ /** Whether the project holds a filter's layer and that layer has its field. */
22
+ export function isFilterInProject(filter, layersById) {
23
+ return layersById.get(filter.layerId)?.fieldNames.includes(filter.field) ?? false;
24
+ }
25
+ /**
26
+ * The notes for the settings that name another layer and do not reach the
27
+ * catalogue: Value Relations, relations and filters, in that order, and each
28
+ * in the project's order. `textFilters` are the Mergin Maps `Text` filters
29
+ * `parseMerginFilters` passes over.
30
+ */
31
+ export function crossLayerNotes(layers, relations, filters, textFilters) {
32
+ const layersById = new Map(layers.map((layer) => [layer.id, layer]));
33
+ const noteFor = (layerId, field, reason, text) => ({ layerId, layerName: layersById.get(layerId)?.name ?? '', field, reason, text });
34
+ const notes = [];
35
+ for (const layer of layers) {
36
+ for (const [field, widget] of Object.entries(layer.fieldValueRelations)) {
37
+ if (!findValueRelationLookup(widget, layers, layersById))
38
+ notes.push(noteFor(layer.id, field, 'value-relation', widget.layerName || widget.layerId));
39
+ }
40
+ }
41
+ for (const relation of relations) {
42
+ if (!isRelationInProject(relation, layersById))
43
+ notes.push(noteFor(relation.childLayerId, null, 'relation', relation.name || relation.id));
44
+ }
45
+ for (const filter of filters) {
46
+ if (!isFilterInProject(filter, layersById))
47
+ notes.push(noteFor(filter.layerId, filter.field, 'filter', null));
48
+ }
49
+ for (const filter of textFilters)
50
+ notes.push(noteFor(filter.layerId, filter.field, 'filter', 'Text'));
51
+ return notes;
52
+ }
@@ -54,6 +54,14 @@ export type ExpressionNode = {
54
54
  }>;
55
55
  otherwise: ExpressionNode | null;
56
56
  };
57
+ /**
58
+ * The `fnName` of the GeoStyler `custom` function that stands for a variable,
59
+ * such as `@cloud_useremail`. Its first argument is the variable's name with
60
+ * no `@`; a second, `x`, `y` or `z`, is the coordinate of the point the
61
+ * variable holds, read from `x(@position_coordinate)` and the like. The
62
+ * evaluator is handed the values before it starts.
63
+ */
64
+ export declare const EXPRESSION_VARIABLE = "expression_variable";
57
65
  /** The `aggregate` kinds this reader takes, which the caller works out (`QgsAggregateCalculator::aggregates`). */
58
66
  export declare const LOOKUP_AGGREGATES: readonly ["count", "min", "max", "concatenate"];
59
67
  /**
@@ -139,12 +147,19 @@ export declare function isQgisConditionFilter(filter: unknown): filter is {
139
147
  * `now()`, or `$now`, is read only as the date of `format_date` or of a
140
148
  * function that takes a part of a date, such as `year`: anywhere else it would
141
149
  * be compared or added as a date, which the evaluator does not do.
150
+ *
151
+ * A variable other than `@parent`, such as `@cloud_useremail`, is read only
152
+ * where the caller says `variables`: the caller then supplies each one's value
153
+ * (`EXPRESSION_VARIABLE`) as a record is created or saved (a default value).
154
+ * `x`, `y` and `z` are read only with a variable as their point, as in
155
+ * `x(@position_coordinate)`. A read of another layer cannot use a variable.
142
156
  */
143
157
  export declare function readQgisExpression(expression: string, options?: {
144
158
  currentValue?: boolean;
145
159
  geometry?: true | MeasureFactors;
146
160
  aggregates?: boolean;
147
161
  lookups?: boolean;
162
+ variables?: boolean;
148
163
  }): ExpressionNode | null;
149
164
  /**
150
165
  * A QGIS rule's condition as a GeoStyler filter: the condition's GeoStyler
@@ -62,8 +62,32 @@ const QGIS_ONLY_FUNCTIONS = {
62
62
  overlay_intersects: [1, 5],
63
63
  aggregate: [3, 6],
64
64
  geometry: [1, 1],
65
- intersects: [2, 2]
65
+ intersects: [2, 2],
66
+ x: [1, 1],
67
+ y: [1, 1],
68
+ z: [1, 1]
66
69
  };
70
+ /** The functions that take a coordinate of a point, read only with a variable as their point (`EXPRESSION_VARIABLE`). */
71
+ const POINT_PARTS = ['x', 'y', 'z'];
72
+ /**
73
+ * The `fnName` of the GeoStyler `custom` function that stands for a variable,
74
+ * such as `@cloud_useremail`. Its first argument is the variable's name with
75
+ * no `@`; a second, `x`, `y` or `z`, is the coordinate of the point the
76
+ * variable holds, read from `x(@position_coordinate)` and the like. The
77
+ * evaluator is handed the values before it starts.
78
+ */
79
+ export const EXPRESSION_VARIABLE = 'expression_variable';
80
+ /** The name of the variable a node is, with no `@`, or null for any other node and for `@parent`. */
81
+ function variableName(node) {
82
+ return node?.kind === 'call' && node.name.startsWith('@') && node.name !== '@parent' ? node.name.slice(1) : null;
83
+ }
84
+ function isVariable(node) {
85
+ return variableName(node) !== null;
86
+ }
87
+ /** The variables at or under a node, other than `@parent`. */
88
+ function findVariables(node) {
89
+ return [...(isVariable(node) ? [node] : []), ...childNodes(node).flatMap(findVariables)];
90
+ }
67
91
  /** The functions whose second argument is a regular expression, which QGIS compiles with Unicode properties. */
68
92
  const REGEXP_FUNCTIONS = ['regexp_match', 'regexp_replace', 'regexp_substr'];
69
93
  /**
@@ -185,6 +209,12 @@ export function isQgisConditionFilter(filter) {
185
209
  * `now()`, or `$now`, is read only as the date of `format_date` or of a
186
210
  * function that takes a part of a date, such as `year`: anywhere else it would
187
211
  * be compared or added as a date, which the evaluator does not do.
212
+ *
213
+ * A variable other than `@parent`, such as `@cloud_useremail`, is read only
214
+ * where the caller says `variables`: the caller then supplies each one's value
215
+ * (`EXPRESSION_VARIABLE`) as a record is created or saved (a default value).
216
+ * `x`, `y` and `z` are read only with a variable as their point, as in
217
+ * `x(@position_coordinate)`. A read of another layer cannot use a variable.
188
218
  */
189
219
  export function readQgisExpression(expression, options = {}) {
190
220
  const tokens = tokenizeExpression(expression);
@@ -195,6 +225,10 @@ export function readQgisExpression(expression, options = {}) {
195
225
  return null;
196
226
  if (!options.currentValue && findCalls(parsed.node, 'current_value').length > 0)
197
227
  return null;
228
+ if (!options.variables && findVariables(parsed.node).length > 0)
229
+ return null;
230
+ if (!findCalls(parsed.node, ...POINT_PARTS).every((call) => isVariable(call.args[0])))
231
+ return null;
198
232
  const aggregateCalls = findCalls(parsed.node, ...AGGREGATES);
199
233
  if (aggregateCalls.length > 0 && !options.aggregates)
200
234
  return null;
@@ -509,9 +543,13 @@ function readTerm(tokens, index) {
509
543
  return { node: { kind: 'call', name: 'now', args: [] }, next: index + 1 };
510
544
  return Object.hasOwn(GEOMETRY_VALUES, word) || word === '$geometry' ? { node: { kind: 'call', name: word, args: [] }, next: index + 1 } : null;
511
545
  }
512
- // A variable: `@parent` alone is read, inside an `aggregate` filter.
546
+ // `@parent` is read inside an `aggregate` filter, and any other variable
547
+ // where the caller says `variables`. A variable keeps its spelling, since
548
+ // QGIS looks one up by its exact name.
549
+ if (word === '@parent')
550
+ return { node: { kind: 'call', name: word, args: [] }, next: index + 1 };
513
551
  if (word.startsWith('@'))
514
- return word === '@parent' ? { node: { kind: 'call', name: word, args: [] }, next: index + 1 } : null;
552
+ return { node: { kind: 'call', name: token.value, args: [] }, next: index + 1 };
515
553
  if (word === 'true' || word === 'false')
516
554
  return { node: { kind: 'boolean', value: word === 'true' }, next: index + 1 };
517
555
  if (word === 'null')
@@ -675,9 +713,10 @@ function lookupArguments(call) {
675
713
  const names = NAMED_PARAMETERS[call.name].names;
676
714
  return Object.fromEntries(names.map((name, position) => [name, call.args[position] ?? { kind: 'null' }]));
677
715
  }
678
- /** An expression over the target's own fields: no read of another layer, form or shape. */
716
+ /** An expression over the target's own fields: no read of another layer, form, shape or variable. */
679
717
  function readsTargetFieldsOnly(node) {
680
- return findCalls(node, ...LOOKUPS, ...PARENT_GEOMETRY_CALLS, 'array_first', 'array_get', 'current_value', ...AGGREGATES, ...Object.keys(GEOMETRY_VALUES)).length === 0;
718
+ return findCalls(node, ...LOOKUPS, ...PARENT_GEOMETRY_CALLS, 'array_first', 'array_get', 'current_value', ...AGGREGATES, ...Object.keys(GEOMETRY_VALUES)).length === 0
719
+ && findVariables(node).length === 0;
681
720
  }
682
721
  function isParentIntersectsFilter(node) {
683
722
  if (node.kind !== 'call' || node.name !== 'intersects')
@@ -830,6 +869,12 @@ export function expressionToGeoStylerFunction(node) {
830
869
  ]
831
870
  };
832
871
  case 'call': {
872
+ const variable = variableName(node);
873
+ if (variable !== null)
874
+ return { name: 'custom', fnName: EXPRESSION_VARIABLE, args: [variable] };
875
+ const point = variableName(node.args[0]);
876
+ if (POINT_PARTS.includes(node.name) && point !== null)
877
+ return { name: 'custom', fnName: EXPRESSION_VARIABLE, args: [point, node.name] };
833
878
  const args = node.args.map(expressionToGeoStylerFunction);
834
879
  if (node.name === 'concat')
835
880
  return { name: 'strConcat', args };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriahq/quac",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "description": "Writes and reads QUAC, which adds map layer settings to STAC catalogues.",