@vectoriahq/quac 0.4.0-next.1 → 0.5.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 +35 -4
- package/dist/generate/arcgisStacCatalogue.js +1 -1
- package/dist/generate/normalizedProject.d.ts +1 -1
- package/dist/generate/normalizedProject.js +25 -16
- package/dist/generate/serverStacCatalogue.js +6 -4
- package/dist/generate/stacCatalogue.js +1 -1
- package/dist/model/Stac.d.ts +1 -1
- package/dist/model/quacExtension.d.ts +1 -1
- package/dist/model/quacExtension.js +1 -1
- package/dist/model/stacTreeWalk.d.ts +12 -2
- package/dist/model/stacTreeWalk.js +42 -8
- package/dist/parse/parseQgsXml.d.ts +2 -1
- package/dist/parse/parseQgsXml.js +8 -1
- package/package.json +1 -2
- package/src/schema/quac.schema.json +28 -1
package/README.md
CHANGED
|
@@ -10,16 +10,47 @@ The package writes QUAC catalogues from QGIS projects and other sources, and rea
|
|
|
10
10
|
npm install @vectoriahq/quac
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Read a Collection
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Each `readCollection…` function takes one Collection and returns one kind of setting, keyed by field name where it is a field's. It needs nothing else from the catalogue, so an application can read a Collection as it opens it. This reads the trees layer of [the demo catalogue](https://vectoriahq.github.io/quac/demo/catalog.json):
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import {
|
|
19
|
+
readCollectionFieldAliases,
|
|
20
|
+
readCollectionFieldEditRules,
|
|
21
|
+
readCollectionFieldValues,
|
|
22
|
+
readCollectionFormLayout
|
|
23
|
+
} from '@vectoriahq/quac'
|
|
24
|
+
|
|
25
|
+
const response = await fetch('https://vectoriahq.github.io/quac/demo/collections/trees.json')
|
|
26
|
+
const trees = await response.json()
|
|
27
|
+
|
|
28
|
+
readCollectionFieldAliases(trees).height
|
|
29
|
+
// 'Height'
|
|
30
|
+
readCollectionFieldEditRules(trees).height
|
|
31
|
+
// { range: { min: 0, max: 40, step: 0.5, precision: 1, suffix: ' m' },
|
|
32
|
+
// constraintExpression: { expression: '"height" < 40', description: 'Taller than any tree on this street', strength: 'warn' },
|
|
33
|
+
// readOnly: false, notNull: null, … }
|
|
34
|
+
readCollectionFieldValues(trees).condition
|
|
35
|
+
// [{ value: 'G', label: 'Good' }, { value: 'F', label: 'Fair' }, …]
|
|
36
|
+
readCollectionFormLayout(trees).fields.at(-1)
|
|
37
|
+
// { name: 'removal_reason', visibleWhen: ['"condition" = \'D\''] }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A Value Relation names the Collection its choices come from (`readCollectionFieldValueRelations`), and a child layer names its parent (`readCollectionRelatedTo`). Reading those choices or records means reading that Collection's data too.
|
|
41
|
+
|
|
42
|
+
## Build a catalogue
|
|
43
|
+
|
|
44
|
+
Build a catalogue from a QGIS project file. The parsers use the standard `DOMParser` and `XMLSerializer`, which a browser provides. In Node, supply both, such as [jsdom](https://www.npmjs.com/package/jsdom)'s:
|
|
16
45
|
|
|
17
46
|
```js
|
|
18
47
|
import { readFile } from 'node:fs/promises'
|
|
19
|
-
import {
|
|
48
|
+
import { JSDOM } from 'jsdom'
|
|
20
49
|
import { parseQgsXml, generateStacCatalogue } from '@vectoriahq/quac'
|
|
21
50
|
|
|
22
|
-
|
|
51
|
+
const { window } = new JSDOM()
|
|
52
|
+
globalThis.DOMParser = window.DOMParser
|
|
53
|
+
globalThis.XMLSerializer = window.XMLSerializer
|
|
23
54
|
|
|
24
55
|
const project = parseQgsXml(await readFile('survey/project.qgs', 'utf8'))
|
|
25
56
|
const catalogue = generateStacCatalogue(project, [], {
|
|
@@ -165,7 +165,7 @@ function fieldToColumn(field) {
|
|
|
165
165
|
if (field.type && Object.hasOwn(ESRI_COLUMN_TYPES, field.type))
|
|
166
166
|
column.type = ESRI_COLUMN_TYPES[field.type];
|
|
167
167
|
if (field.codedValues)
|
|
168
|
-
column
|
|
168
|
+
column['quac:values'] = field.codedValues.map(({ code, name }) => ({ value: code, label: name }));
|
|
169
169
|
// A range on a date field is in epoch milliseconds, which is no number a form could limit.
|
|
170
170
|
if (field.range && (column.type === 'int' || column.type === 'long' || column.type === 'double')) {
|
|
171
171
|
column['quac:range'] = { min: field.range.min, max: field.range.max };
|
|
@@ -313,7 +313,7 @@ export declare function readCollectionFieldNames(collection: StacCollection): st
|
|
|
313
313
|
/** Each declared column `type`, keyed by field name. A column with no `type` is absent. */
|
|
314
314
|
export declare function readCollectionFieldTypes(collection: StacCollection): Record<string, string>;
|
|
315
315
|
/**
|
|
316
|
-
* Each column's `values` picklist, keyed by field name. A value is returned as
|
|
316
|
+
* Each column's `quac:values` picklist, keyed by field name. A value is returned as
|
|
317
317
|
* stored, string or number. An entry with no label, or with a value of any
|
|
318
318
|
* other kind, is dropped, and a column left with no entries is absent.
|
|
319
319
|
*/
|
|
@@ -106,7 +106,7 @@ export function withSelfLink(catalogue, selfHref) {
|
|
|
106
106
|
* layer nodes → Collections
|
|
107
107
|
*/
|
|
108
108
|
export function generateStacFromNormalized(project) {
|
|
109
|
-
const { collections, catalogs, links } = walkNodes(project.nodes, project.providers ?? []);
|
|
109
|
+
const { collections, catalogs, links } = walkNodes(project.nodes, project.providers ?? [], './');
|
|
110
110
|
const catalog = {
|
|
111
111
|
type: 'Catalog',
|
|
112
112
|
stac_version: STAC_VERSION,
|
|
@@ -139,23 +139,31 @@ export function generateStacFromNormalized(project) {
|
|
|
139
139
|
}
|
|
140
140
|
return declareQuacExtension(catalog);
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Every relative href in the catalogue starts from the top-level document, the
|
|
144
|
+
* one document that holds the whole tree. `folder` is where the Catalog
|
|
145
|
+
* holding `nodes` would sit as a file of its own, relative to that document:
|
|
146
|
+
* `./` for the top level and `./catalogs/<id>/` for a group, nested group by
|
|
147
|
+
* group.
|
|
148
|
+
*/
|
|
149
|
+
function walkNodes(nodes, defaultProviders, folder) {
|
|
143
150
|
const collections = [];
|
|
144
151
|
const catalogs = [];
|
|
145
152
|
const links = [];
|
|
146
153
|
for (const node of nodes) {
|
|
147
154
|
if (node.kind === 'layer') {
|
|
148
|
-
const collection = buildCollection(node, defaultProviders);
|
|
155
|
+
const collection = buildCollection(node, defaultProviders, folder);
|
|
149
156
|
collections.push(collection);
|
|
150
157
|
links.push({
|
|
151
158
|
rel: 'child',
|
|
152
|
-
href:
|
|
159
|
+
href: `${folder}collections/${collection.id}.json`,
|
|
153
160
|
type: 'application/json',
|
|
154
161
|
title: collection.title
|
|
155
162
|
});
|
|
156
163
|
}
|
|
157
164
|
else {
|
|
158
|
-
const
|
|
165
|
+
const groupFolder = `${folder}catalogs/${node.id}/`;
|
|
166
|
+
const sub = walkNodes(node.children, defaultProviders, groupFolder);
|
|
159
167
|
const subCatalog = {
|
|
160
168
|
type: 'Catalog',
|
|
161
169
|
stac_version: STAC_VERSION,
|
|
@@ -163,9 +171,9 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
163
171
|
title: node.title || undefined,
|
|
164
172
|
description: node.description,
|
|
165
173
|
links: [
|
|
166
|
-
{ rel: 'self', href:
|
|
167
|
-
{ rel: 'parent', href:
|
|
168
|
-
{ rel: 'root', href: '
|
|
174
|
+
{ rel: 'self', href: `${groupFolder}catalog.json` },
|
|
175
|
+
{ rel: 'parent', href: `${folder}catalog.json` },
|
|
176
|
+
{ rel: 'root', href: './catalog.json' },
|
|
169
177
|
...sub.links
|
|
170
178
|
]
|
|
171
179
|
};
|
|
@@ -178,7 +186,7 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
178
186
|
catalogs.push(subCatalog);
|
|
179
187
|
links.push({
|
|
180
188
|
rel: 'child',
|
|
181
|
-
href:
|
|
189
|
+
href: `${groupFolder}catalog.json`,
|
|
182
190
|
type: 'application/json',
|
|
183
191
|
title: node.title
|
|
184
192
|
});
|
|
@@ -186,7 +194,7 @@ function walkNodes(nodes, defaultProviders) {
|
|
|
186
194
|
}
|
|
187
195
|
return { collections, catalogs, links };
|
|
188
196
|
}
|
|
189
|
-
function buildCollection(layer, defaultProviders) {
|
|
197
|
+
function buildCollection(layer, defaultProviders, folder) {
|
|
190
198
|
const stacExtensions = [...(layer.extensions ?? [])];
|
|
191
199
|
if (layer.tableColumns.length > 0) {
|
|
192
200
|
stacExtensions.push(TABLE_EXTENSION);
|
|
@@ -212,9 +220,9 @@ function buildCollection(layer, defaultProviders) {
|
|
|
212
220
|
summaries: Object.keys(summaries).length > 0 ? summaries : undefined,
|
|
213
221
|
assets: layer.assets,
|
|
214
222
|
links: [
|
|
215
|
-
{ rel: 'self', href:
|
|
216
|
-
{ rel: 'parent', href:
|
|
217
|
-
{ rel: 'root', href: '
|
|
223
|
+
{ rel: 'self', href: `${folder}collections/${layer.id}.json` },
|
|
224
|
+
{ rel: 'parent', href: `${folder}catalog.json` },
|
|
225
|
+
{ rel: 'root', href: './catalog.json' },
|
|
218
226
|
...(layer.links ?? [])
|
|
219
227
|
]
|
|
220
228
|
};
|
|
@@ -409,17 +417,18 @@ export function readCollectionFieldTypes(collection) {
|
|
|
409
417
|
return types;
|
|
410
418
|
}
|
|
411
419
|
/**
|
|
412
|
-
* Each column's `values` picklist, keyed by field name. A value is returned as
|
|
420
|
+
* Each column's `quac:values` picklist, keyed by field name. A value is returned as
|
|
413
421
|
* stored, string or number. An entry with no label, or with a value of any
|
|
414
422
|
* other kind, is dropped, and a column left with no entries is absent.
|
|
415
423
|
*/
|
|
416
424
|
export function readCollectionFieldValues(collection) {
|
|
417
425
|
const picklists = {};
|
|
418
426
|
for (const [name, column] of declaredColumns(collection)) {
|
|
419
|
-
|
|
427
|
+
const declared = column['quac:values'];
|
|
428
|
+
if (!Array.isArray(declared))
|
|
420
429
|
continue;
|
|
421
430
|
const entries = [];
|
|
422
|
-
for (const entry of
|
|
431
|
+
for (const entry of declared) {
|
|
423
432
|
if (!entry || typeof entry !== 'object')
|
|
424
433
|
continue;
|
|
425
434
|
const { value, label, icon } = entry;
|
|
@@ -5,6 +5,7 @@ import { wfsGetFeatureAsset } from "./wfsStacCatalogue.js";
|
|
|
5
5
|
import { mapQtTypeToStacTableType } from "./wmsStacCatalogue.js";
|
|
6
6
|
import { declareQuacExtension, QUAC_SCHEMA_URL } from "../model/quacExtension.js";
|
|
7
7
|
import { PROJECTION_EXTENSION } from "../model/stacProjection.js";
|
|
8
|
+
import { catalogueFolder } from "../model/stacTreeWalk.js";
|
|
8
9
|
import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, WMS_REQUEST_PARAMETERS } from "../model/stacWms.js";
|
|
9
10
|
/**
|
|
10
11
|
* The catalogue a QGIS Server would serve for a project: the QUAC plugin's
|
|
@@ -85,7 +86,7 @@ export function generateServerStacCatalogue(project, options) {
|
|
|
85
86
|
const serveCatalog = (node) => {
|
|
86
87
|
const collections = (node.collections ?? []).filter((collection) => servedIds.has(collection.id)).map((collection) => serveCollection(collection, context));
|
|
87
88
|
const catalogs = (node.catalogs ?? []).filter((child) => !restricted.has(child.title ?? '')).map(serveCatalog);
|
|
88
|
-
const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(collections, catalogs)] };
|
|
89
|
+
const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(catalogueFolder(node) ?? './', collections, catalogs)] };
|
|
89
90
|
delete served.collections;
|
|
90
91
|
delete served.catalogs;
|
|
91
92
|
delete served.stac_extensions;
|
|
@@ -154,10 +155,11 @@ export function serverWmsCrsList(project) {
|
|
|
154
155
|
crsList.push('EPSG:3857');
|
|
155
156
|
return crsList;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
/** A served Catalog's child links, from the top-level document as every relative href is: `folder` is the Catalog's own. */
|
|
159
|
+
function childLinks(folder, collections, catalogs) {
|
|
158
160
|
return [
|
|
159
|
-
...collections.map((collection) => ({ rel: 'child', href:
|
|
160
|
-
...catalogs.map((catalog) => ({ rel: 'child', href:
|
|
161
|
+
...collections.map((collection) => ({ rel: 'child', href: `${folder}collections/${encodeURIComponent(collection.id)}.json`, type: 'application/json', title: collection.title })),
|
|
162
|
+
...catalogs.map((catalog) => ({ rel: 'child', href: `${folder}catalogs/${encodeURIComponent(catalog.id)}/catalog.json`, type: 'application/json', title: catalog.title }))
|
|
161
163
|
];
|
|
162
164
|
}
|
|
163
165
|
/** The fields of a layer QGIS Server hides from either service. */
|
|
@@ -765,7 +765,7 @@ function deriveTableColumns(geojson, fieldNames, fieldAliases, fieldValueMaps =
|
|
|
765
765
|
column.title = alias;
|
|
766
766
|
const values = fieldValueMaps[name];
|
|
767
767
|
if (values)
|
|
768
|
-
column
|
|
768
|
+
column['quac:values'] = values;
|
|
769
769
|
const valueRelation = fieldValueRelations[name];
|
|
770
770
|
if (valueRelation)
|
|
771
771
|
column['quac:value_relation'] = valueRelation;
|
package/dist/model/Stac.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ export interface TableColumn {
|
|
|
143
143
|
data_type?: TableColumnDataType;
|
|
144
144
|
description?: string;
|
|
145
145
|
/** The values the source restricts the field to: a QGIS ValueMap widget or an ArcGIS coded-value domain. */
|
|
146
|
-
values?: TableColumnValue[];
|
|
146
|
+
'quac:values'?: TableColumnValue[];
|
|
147
147
|
/** Declares that the column holds a file's path rather than a value of its own. */
|
|
148
148
|
'quac:attachment'?: TableColumnAttachment;
|
|
149
149
|
/** Declares that the column's choices are the records of another Collection of the same catalogue. */
|
|
@@ -4,7 +4,7 @@ import type { StacCatalog, StacCollection } from './Stac.ts';
|
|
|
4
4
|
* `stac_extensions` to say which QUAC it follows. Written from this one
|
|
5
5
|
* constant, so the address changes in one place when the schema moves.
|
|
6
6
|
*/
|
|
7
|
-
export declare const QUAC_SCHEMA_URL = "https://vectoriahq.github.io/quac/v0.
|
|
7
|
+
export declare const QUAC_SCHEMA_URL = "https://vectoriahq.github.io/quac/v0.3.0/schema.json";
|
|
8
8
|
/**
|
|
9
9
|
* The QUAC version a document declares, such as `0.1.0`, read from the QUAC
|
|
10
10
|
* schema address in its `stac_extensions`. Null where it lists none.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* `stac_extensions` to say which QUAC it follows. Written from this one
|
|
4
4
|
* constant, so the address changes in one place when the schema moves.
|
|
5
5
|
*/
|
|
6
|
-
export const QUAC_SCHEMA_URL = 'https://vectoriahq.github.io/quac/v0.
|
|
6
|
+
export const QUAC_SCHEMA_URL = 'https://vectoriahq.github.io/quac/v0.3.0/schema.json';
|
|
7
7
|
// A QUAC schema address is a folder named for its version, holding the
|
|
8
8
|
// schema file `QUAC_SCHEMA_URL` names. Only the path is matched, not the host.
|
|
9
9
|
const QUAC_SCHEMA_FILE = QUAC_SCHEMA_URL.slice(QUAC_SCHEMA_URL.lastIndexOf('/'));
|
|
@@ -6,8 +6,10 @@ import type { StacCatalog, StacCollection } from './Stac.ts';
|
|
|
6
6
|
*
|
|
7
7
|
* A Catalog holds its child Collections and child Catalogs in two separate
|
|
8
8
|
* arrays, so the interleaving is read back from the `rel: "child"` links,
|
|
9
|
-
* which the generator writes in source order
|
|
10
|
-
*
|
|
9
|
+
* which the generator writes in source order, from the top-level document:
|
|
10
|
+
* `{folder}collections/{id}.json` for a Collection and
|
|
11
|
+
* `{folder}catalogs/{id}/catalog.json` for a group, where `{folder}` is the
|
|
12
|
+
* Catalog's own, as `catalogueFolder` reads it. A child whose link
|
|
11
13
|
* cannot be matched — an external document with its own link shapes — is
|
|
12
14
|
* appended after the linked ones, so nothing is dropped and external
|
|
13
15
|
* catalogues degrade to "Collections first, then groups" order.
|
|
@@ -34,3 +36,11 @@ export type CatalogueChild = {
|
|
|
34
36
|
* describes. The basemap picker offers these as its choices.
|
|
35
37
|
*/
|
|
36
38
|
export declare function listCatalogueChildren(catalog: StacCatalog): CatalogueChild[];
|
|
39
|
+
/**
|
|
40
|
+
* Where a Catalog would sit as a file of its own, relative to the top-level
|
|
41
|
+
* document, read from its `self` link: `./` for `./catalog.json`, and
|
|
42
|
+
* `./catalogs/roads/` for `./catalogs/roads/catalog.json`. Null where the
|
|
43
|
+
* `self` link is absent or names some other file, such as a catalogue another
|
|
44
|
+
* application published.
|
|
45
|
+
*/
|
|
46
|
+
export declare function catalogueFolder(catalog: StacCatalog): string | null;
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* A Catalog holds its child Collections and child Catalogs in two separate
|
|
7
7
|
* arrays, so the interleaving is read back from the `rel: "child"` links,
|
|
8
|
-
* which the generator writes in source order
|
|
9
|
-
*
|
|
8
|
+
* which the generator writes in source order, from the top-level document:
|
|
9
|
+
* `{folder}collections/{id}.json` for a Collection and
|
|
10
|
+
* `{folder}catalogs/{id}/catalog.json` for a group, where `{folder}` is the
|
|
11
|
+
* Catalog's own, as `catalogueFolder` reads it. A child whose link
|
|
10
12
|
* cannot be matched — an external document with its own link shapes — is
|
|
11
13
|
* appended after the linked ones, so nothing is dropped and external
|
|
12
14
|
* catalogues degrade to "Collections first, then groups" order.
|
|
@@ -29,12 +31,13 @@ export function collectCatalogueCollections(catalog) {
|
|
|
29
31
|
export function listCatalogueChildren(catalog) {
|
|
30
32
|
const collections = catalog.collections ?? [];
|
|
31
33
|
const catalogs = catalog.catalogs ?? [];
|
|
34
|
+
const folder = catalogueFolder(catalog);
|
|
32
35
|
const visited = new Set();
|
|
33
36
|
const out = [];
|
|
34
37
|
for (const link of catalog.links ?? []) {
|
|
35
38
|
if (link.rel !== 'child')
|
|
36
39
|
continue;
|
|
37
|
-
const collectionId =
|
|
40
|
+
const collectionId = matchChildId(link.href, folder, 'collections/', '.json');
|
|
38
41
|
if (collectionId !== null) {
|
|
39
42
|
const collection = firstUnvisited(collections, collectionId, visited);
|
|
40
43
|
if (collection) {
|
|
@@ -43,7 +46,7 @@ export function listCatalogueChildren(catalog) {
|
|
|
43
46
|
continue;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
const catalogId =
|
|
49
|
+
const catalogId = matchChildId(link.href, folder, 'catalogs/', '/catalog.json');
|
|
47
50
|
if (catalogId !== null) {
|
|
48
51
|
const child = firstUnvisited(catalogs, catalogId, visited);
|
|
49
52
|
if (child) {
|
|
@@ -69,8 +72,39 @@ function firstUnvisited(items, id, visited) {
|
|
|
69
72
|
}
|
|
70
73
|
return null;
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Where a Catalog would sit as a file of its own, relative to the top-level
|
|
77
|
+
* document, read from its `self` link: `./` for `./catalog.json`, and
|
|
78
|
+
* `./catalogs/roads/` for `./catalogs/roads/catalog.json`. Null where the
|
|
79
|
+
* `self` link is absent or names some other file, such as a catalogue another
|
|
80
|
+
* application published.
|
|
81
|
+
*/
|
|
82
|
+
export function catalogueFolder(catalog) {
|
|
83
|
+
const self = (catalog.links ?? []).find((link) => link.rel === 'self')?.href;
|
|
84
|
+
if (!self || (self !== 'catalog.json' && !self.endsWith('/catalog.json')))
|
|
85
|
+
return null;
|
|
86
|
+
return self.slice(0, self.length - 'catalog.json'.length);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The id in a child link written as `{folder}{prefix}{id}{suffix}`. Ids are
|
|
90
|
+
* written into hrefs verbatim, and an id can hold a `/`, such as a folder
|
|
91
|
+
* source's path, so the id is what lies between the Catalog's own folder and
|
|
92
|
+
* the suffix. An href outside that folder, such as another application's, is
|
|
93
|
+
* matched from its first `/{prefix}` instead.
|
|
94
|
+
*/
|
|
95
|
+
function matchChildId(href, folder, prefix, suffix) {
|
|
96
|
+
if (!href.endsWith(suffix))
|
|
97
|
+
return null;
|
|
98
|
+
let start;
|
|
99
|
+
if (folder !== null && href.startsWith(`${folder}${prefix}`)) {
|
|
100
|
+
start = folder.length + prefix.length;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const at = href.indexOf(`/${prefix}`);
|
|
104
|
+
if (at < 0)
|
|
105
|
+
return null;
|
|
106
|
+
start = at + 1 + prefix.length;
|
|
107
|
+
}
|
|
108
|
+
const id = href.slice(start, href.length - suffix.length);
|
|
109
|
+
return start <= href.length - suffix.length && id ? id : null;
|
|
76
110
|
}
|
|
@@ -9,7 +9,8 @@ import type { QgsProject } from '../model/QgsProject.ts';
|
|
|
9
9
|
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
10
10
|
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
11
11
|
*
|
|
12
|
-
* Throws only when
|
|
12
|
+
* Throws only when `XMLSerializer` is missing, or the XML itself is
|
|
13
|
+
* unparseable or has no <qgis> root.
|
|
13
14
|
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
14
15
|
*/
|
|
15
16
|
export declare function parseQgsXml(xmlText: string): QgsProject;
|
|
@@ -21,10 +21,17 @@ import { devLog } from "../util/devLog.js";
|
|
|
21
21
|
* 3. Each sub-parser handles one concern and isolates its own failures —
|
|
22
22
|
* a malformed legend tree shouldn't take down the layer list, etc.
|
|
23
23
|
*
|
|
24
|
-
* Throws only when
|
|
24
|
+
* Throws only when `XMLSerializer` is missing, or the XML itself is
|
|
25
|
+
* unparseable or has no <qgis> root.
|
|
25
26
|
* Sub-parser failures yield empty / null fields rather than exceptions.
|
|
26
27
|
*/
|
|
27
28
|
export function parseQgsXml(xmlText) {
|
|
29
|
+
// Each layer keeps its own XML through `XMLSerializer`. Without one, every
|
|
30
|
+
// layer would fail on its own and be skipped, leaving a project with no
|
|
31
|
+
// layers and no error.
|
|
32
|
+
if (typeof XMLSerializer === 'undefined') {
|
|
33
|
+
throw new Error('parseQgsXml needs XMLSerializer as well as DOMParser. A browser provides both; in Node, supply both from one library, such as jsdom.');
|
|
34
|
+
}
|
|
28
35
|
const parser = new DOMParser();
|
|
29
36
|
const doc = parser.parseFromString(xmlText, 'text/xml');
|
|
30
37
|
// DOMParser surfaces XML errors as a <parsererror> node in the document.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectoriahq/quac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.",
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@cfworker/json-schema": "4.1.1",
|
|
51
51
|
"jsdom": "30.1.3",
|
|
52
|
-
"linkedom": "0.18.13",
|
|
53
52
|
"typescript": "5.9.3",
|
|
54
53
|
"vite": "8.3.4",
|
|
55
54
|
"vitest": "5.0.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"$id": "https://vectoriahq.github.io/quac/v0.
|
|
3
|
+
"$id": "https://vectoriahq.github.io/quac/v0.3.0/schema.json",
|
|
4
4
|
"title": "QUAC: Quite Useful Additions for Catalogs",
|
|
5
5
|
"description": "The fields of QUAC (Quite Useful Additions for Catalogs): the fields a STAC catalogue carries under the quac: prefix to say how a layer is drawn, edited and set up, as a source such as a QGIS project declares it. Validates a Catalog with its inlined collections and catalogs, or a single Collection. Only quac: fields are checked: any other field passes, and a quac: field this schema does not define fails. A field is written only when the source declares it, so an absent field means the source said nothing.",
|
|
6
6
|
"type": "object",
|
|
@@ -578,6 +578,33 @@
|
|
|
578
578
|
"dropdown"
|
|
579
579
|
]
|
|
580
580
|
},
|
|
581
|
+
"quac:values": {
|
|
582
|
+
"description": "The values the field takes, each with the label a form shows for it, in the source's order. Written from a QGIS Value Map widget or an ArcGIS coded-value domain.",
|
|
583
|
+
"type": "array",
|
|
584
|
+
"minItems": 1,
|
|
585
|
+
"items": {
|
|
586
|
+
"type": "object",
|
|
587
|
+
"required": [
|
|
588
|
+
"value",
|
|
589
|
+
"label"
|
|
590
|
+
],
|
|
591
|
+
"properties": {
|
|
592
|
+
"value": {
|
|
593
|
+
"description": "The value the field stores. An empty string is QGIS's blank choice.",
|
|
594
|
+
"type": [
|
|
595
|
+
"string",
|
|
596
|
+
"number"
|
|
597
|
+
]
|
|
598
|
+
},
|
|
599
|
+
"label": {
|
|
600
|
+
"description": "The label shown for the value.",
|
|
601
|
+
"type": "string",
|
|
602
|
+
"minLength": 1
|
|
603
|
+
}
|
|
604
|
+
},
|
|
605
|
+
"additionalProperties": false
|
|
606
|
+
}
|
|
607
|
+
},
|
|
581
608
|
"quac:value_relation": {
|
|
582
609
|
"$ref": "#/definitions/value_relation"
|
|
583
610
|
},
|