@vectoriahq/quac 0.12.0 → 0.15.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
@@ -61,6 +61,18 @@ const catalogue = generateStacCatalogue(project, [], {
61
61
 
62
62
  `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.
63
63
 
64
+ `generateStacCatalogue` returns one document, with each Catalog carrying its Collections and nested Catalogs inline. `splitCatalogue` gives the same catalogue as separate documents, each with the path to save it at, for a STAC client that follows `child` links:
65
+
66
+ ```js
67
+ import { splitCatalogue } from '@vectoriahq/quac'
68
+
69
+ for (const { path, document } of splitCatalogue(catalogue, { rootFileName: 'survey.json', childrenFolder: 'survey' })) {
70
+ // path: 'survey.json', 'survey/collections/roads_3f2a….json', …
71
+ }
72
+ ```
73
+
74
+ Each path is relative to the folder the root document is saved in, and every relative address inside a document is rewritten from that document's own path, so a layer's data file keeps its place. Without options, the root is `catalog.json` and the other documents sit beside it. The field reference's [§ The document](https://github.com/vectoriahq/quac/tree/main/packages/quac/spec#the-document) says how the documents are named.
75
+
64
76
  `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.
65
77
 
66
78
  The JSON Schema that checks a catalogue's `quac:` fields is exported as `@vectoriahq/quac/schema`.
@@ -53,6 +53,11 @@ export declare const QUAC_LEGEND_IMAGE_FIELD = "quac:legend_image";
53
53
  * address, the same form as a column's `quac:icon`.
54
54
  */
55
55
  export declare const QUAC_ICON_FIELD = "quac:icon";
56
+ /**
57
+ * The key a Collection takes for the message shown once a feature is added to
58
+ * it: text that may hold HTML markup.
59
+ */
60
+ export declare const QUAC_ADDED_MESSAGE_FIELD = "quac:added_message";
56
61
  /**
57
62
  * The key a Collection takes for the area and distance units its source gives
58
63
  * `$area`, `$length` and `$perimeter` in: `{ area_unit, distance_unit }`, each
@@ -208,6 +213,8 @@ export interface NormalizedLayer {
208
213
  legendImage?: string | null;
209
214
  /** Emitted as `quac:icon`: the `https://` address of the icon drawn beside the layer's name. */
210
215
  icon?: string | null;
216
+ /** Emitted as `quac:added_message`: the message shown once a feature is added, as the source wrote it. */
217
+ addedMessage?: string | null;
211
218
  /** Emitted as `quac:locks` where it locks an edit. */
212
219
  locks?: LayerLocks;
213
220
  /** Emitted as `quac:filters` where the source sets one up. */
@@ -344,6 +351,13 @@ export declare function readCollectionMeasurement(collection: StacCollection | n
344
351
  export declare function readCollectionLegendImage(collection: StacCollection | null | undefined): string | null;
345
352
  /** The icon drawn beside a Collection's name (`quac:icon`), or null where it names no `https://` address. */
346
353
  export declare function readCollectionIcon(collection: StacCollection | null | undefined): string | null;
354
+ /**
355
+ * The message shown once a feature is added to a Collection
356
+ * (`quac:added_message`), as the source wrote it, or null where it names none.
357
+ * It may hold HTML markup, which the application shows only as far as it
358
+ * judges safe.
359
+ */
360
+ export declare function readCollectionAddedMessage(collection: StacCollection | null | undefined): string | null;
347
361
  /**
348
362
  * Reads `quac:locks` back off a Collection: the edits it locks, each `true` or
349
363
  * `{ expression }`. A member that is neither, or an expression that is blank,
@@ -57,6 +57,11 @@ export const QUAC_LEGEND_IMAGE_FIELD = 'quac:legend_image';
57
57
  * address, the same form as a column's `quac:icon`.
58
58
  */
59
59
  export const QUAC_ICON_FIELD = 'quac:icon';
60
+ /**
61
+ * The key a Collection takes for the message shown once a feature is added to
62
+ * it: text that may hold HTML markup.
63
+ */
64
+ export const QUAC_ADDED_MESSAGE_FIELD = 'quac:added_message';
60
65
  /**
61
66
  * The key a Collection takes for the area and distance units its source gives
62
67
  * `$area`, `$length` and `$perimeter` in: `{ area_unit, distance_unit }`, each
@@ -265,6 +270,8 @@ function buildCollection(layer, defaultProviders, folder) {
265
270
  collection[QUAC_LEGEND_IMAGE_FIELD] = layer.legendImage;
266
271
  if (layer.icon)
267
272
  collection[QUAC_ICON_FIELD] = layer.icon;
273
+ if (layer.addedMessage)
274
+ collection[QUAC_ADDED_MESSAGE_FIELD] = layer.addedMessage;
268
275
  if (layer.formOrder)
269
276
  collection[QUAC_FORM_ORDER_FIELD] = layer.formOrder;
270
277
  // Source-declaring vendor fields (`quac:wfs_*`), copied verbatim so a consumer reads the source structurally rather than by
@@ -509,6 +516,16 @@ export function readCollectionLegendImage(collection) {
509
516
  export function readCollectionIcon(collection) {
510
517
  return readHttpsAddress(collection?.[QUAC_ICON_FIELD]);
511
518
  }
519
+ /**
520
+ * The message shown once a feature is added to a Collection
521
+ * (`quac:added_message`), as the source wrote it, or null where it names none.
522
+ * It may hold HTML markup, which the application shows only as far as it
523
+ * judges safe.
524
+ */
525
+ export function readCollectionAddedMessage(collection) {
526
+ const message = collection?.[QUAC_ADDED_MESSAGE_FIELD];
527
+ return typeof message === 'string' && message.trim() !== '' ? message : null;
528
+ }
512
529
  const LOCKED_EDITS = ['add', 'attributes', 'geometry', 'delete'];
513
530
  /**
514
531
  * Reads `quac:locks` back off a Collection: the edits it locks, each `true` or
@@ -35,9 +35,10 @@ export interface ServerLayerTreeLayer {
35
35
  * what the QUAC plugin's reading spike returns in Python, so that the two
36
36
  * languages are compared on the fixtures.
37
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.
38
+ * A layer's names are `qgisServerNamesOf`'s, except that a layer the project
39
+ * leaves out of WMS (`wmsExcludedLayerIds`), such as one inside a group it
40
+ * leaves out, has no WMS name. A tree entry whose layer the project does not
41
+ * hold is left out.
41
42
  */
42
43
  export declare function serverLayerTree(project: QgsProject): ServerLayerTree;
43
44
  /** The ids of the layers the project publishes over WMS. */
@@ -1,17 +1,19 @@
1
- import { qgisServerNamesOf } from "./stacCatalogue.js";
1
+ import { qgisServerNamesOf, wmsExcludedLayerIds } from "./stacCatalogue.js";
2
2
  /**
3
3
  * The layer tree QGIS Server reads from a project: each layer's WMS name and
4
4
  * WFS type name, and the fields the project hides from each service. It is
5
5
  * what the QUAC plugin's reading spike returns in Python, so that the two
6
6
  * languages are compared on the fixtures.
7
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.
8
+ * A layer's names are `qgisServerNamesOf`'s, except that a layer the project
9
+ * leaves out of WMS (`wmsExcludedLayerIds`), such as one inside a group it
10
+ * leaves out, has no WMS name. A tree entry whose layer the project does not
11
+ * hold is left out.
11
12
  */
12
13
  export function serverLayerTree(project) {
13
14
  const layersById = new Map(project.layers.map((layer) => [layer.id, layer]));
14
15
  const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
16
+ const excluded = wmsExcludedLayerIds(project);
15
17
  const context = { wmsPublishing: project.wmsPublishing ?? null, wfsTransactionLayers: project.wfsTransactionLayers ?? null };
16
18
  const readGroup = (group, wmsPublished) => group.children.flatMap((node) => {
17
19
  if (node.kind === 'group') {
@@ -19,17 +21,17 @@ export function serverLayerTree(project) {
19
21
  return [{ kind: 'group', name: node.name, wmsPublished: published, children: readGroup(node, published) }];
20
22
  }
21
23
  const layer = layersById.get(node.layerId);
22
- return layer ? [serverLayer(layer, wmsPublished, context)] : [];
24
+ return layer ? [serverLayer(layer, !excluded.has(layer.id), context)] : [];
23
25
  });
24
26
  return { useLayerIds: project.wmsPublishing?.useLayerIds ?? false, children: readGroup(project.layerTree, true) };
25
27
  }
26
- function serverLayer(layer, inPublishedGroup, context) {
28
+ function serverLayer(layer, wmsPublished, context) {
27
29
  const names = qgisServerNamesOf(layer, context);
28
30
  return {
29
31
  kind: 'layer',
30
32
  id: layer.id,
31
33
  name: layer.name,
32
- wmsName: inPublishedGroup ? names.wmsName : null,
34
+ wmsName: wmsPublished ? names.wmsName : null,
33
35
  wfsTypeName: names.wfsTypeName,
34
36
  hiddenFields: { wms: layer.serverHiddenFields?.wms ?? [], wfs: layer.serverHiddenFields?.wfs ?? [] }
35
37
  };
@@ -10,7 +10,8 @@ import type { StacCatalog, StacCollection } from '../model/Stac.ts';
10
10
  * does:
11
11
  *
12
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
13
+ * (`WMSRestrictedLayers`) is left out, with every layer inside the group, as
14
+ * `generateStacCatalogue` already leaves it out. A
14
15
  * layer published for WFS but left out of WMS is left out too, because a
15
16
  * server's Collection id is the WMS name (D1). A file the project splits into
16
17
  * a layer per shape is left out: the project route writes it as one
@@ -17,7 +17,8 @@ import { chooseWmsCrs, WEB_MAP_LINKS_EXTENSION, WMS_REQUEST_PARAMETERS } from ".
17
17
  * does:
18
18
  *
19
19
  * - A layer or group whose name the project leaves out of WMS
20
- * (`WMSRestrictedLayers`) is left out, with every layer inside the group. A
20
+ * (`WMSRestrictedLayers`) is left out, with every layer inside the group, as
21
+ * `generateStacCatalogue` already leaves it out. A
21
22
  * layer published for WFS but left out of WMS is left out too, because a
22
23
  * server's Collection id is the WMS name (D1). A file the project splits into
23
24
  * a layer per shape is left out: the project route writes it as one
@@ -60,7 +61,6 @@ export function generateServerStacCatalogue(project, options) {
60
61
  const layerWgs84Extents = options.layerWgs84Extents ?? {};
61
62
  const catalogue = generateStacCatalogue(project, [], { layerWgs84Extents: new Map(Object.entries(layerWgs84Extents)) });
62
63
  const layersById = new Map(project.layers.map((layer) => [layer.id, layer]));
63
- const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
64
64
  const servedLayerIds = wmsPublishedLayerIds(serverLayerTree(project));
65
65
  const wfsPublished = new Set(project.wfsTransactionLayers?.published ?? []);
66
66
  const servedIds = new Map();
@@ -85,7 +85,7 @@ export function generateServerStacCatalogue(project, options) {
85
85
  };
86
86
  const serveCatalog = (node) => {
87
87
  const collections = (node.collections ?? []).filter((collection) => servedIds.has(collection.id)).map((collection) => serveCollection(collection, context));
88
- const catalogs = (node.catalogs ?? []).filter((child) => !restricted.has(child.title ?? '')).map(serveCatalog);
88
+ const catalogs = (node.catalogs ?? []).map(serveCatalog);
89
89
  const served = { ...node, links: [...node.links.filter((link) => link.rel !== 'child'), ...childLinks(catalogueFolder(node) ?? './', collections, catalogs)] };
90
90
  delete served.collections;
91
91
  delete served.catalogs;
@@ -0,0 +1,54 @@
1
+ import type { StacCatalog, StacCollection } from '../model/Stac.ts';
2
+ /**
3
+ * Writes a catalogue as separate documents: the root Catalog, each nested
4
+ * Catalog and each Collection in a document of its own, linked by `child`,
5
+ * `parent` and `root` links, with no `collections` or `catalogs` arrays
6
+ * (`packages/quac/spec/README.md` § "The document").
7
+ */
8
+ /** Where the documents go. */
9
+ export interface SplitCatalogueOptions {
10
+ /**
11
+ * The root Catalog's file name: one file name ending in `.json`, such as
12
+ * `catalog.json` or `Parks.json`. `catalog.json` where it is left off.
13
+ */
14
+ rootFileName?: string;
15
+ /**
16
+ * The folder every other document goes in, relative to the root document's
17
+ * folder, such as `Parks`. Empty, the default, puts them beside the root
18
+ * document.
19
+ */
20
+ childrenFolder?: string;
21
+ }
22
+ /** One document of a catalogue written as separate documents. */
23
+ export interface CatalogueDocument {
24
+ /**
25
+ * Where the document is saved, relative to the root document's folder: file
26
+ * and folder names joined by `/`, not escaped. Always inside that folder.
27
+ */
28
+ path: string;
29
+ document: StacCatalog | StacCollection;
30
+ }
31
+ /**
32
+ * The catalogue `catalogue` holds, one document holding the whole tree, as
33
+ * separate documents, the root first and then each child after its parent, in
34
+ * the order the parent's `child` links list them.
35
+ *
36
+ * A Catalog's Collections go in a `collections` folder beside it and its
37
+ * nested Catalogs in a `catalogs` folder, each in a folder of its own holding
38
+ * its `catalog.json`. The root's go in `childrenFolder`. A document's file or
39
+ * folder name is its id, made safe as a file name on any system (`safeName`),
40
+ * and where two in one folder would take the same name, in any case, the later
41
+ * one is given `-2`, `-3` and so on.
42
+ *
43
+ * Every relative href, in each link and asset, is rewritten from the
44
+ * document's own path. A `self`, `root` or `parent` link names that document's
45
+ * new path, and a `child` link whose href is a child's own `self` href names
46
+ * the child's. Every other relative href is resolved against the root
47
+ * document's folder, as the one document's hrefs are, so a data file keeps its
48
+ * place, even one outside that folder. An absolute href, one starting with `/`,
49
+ * and one holding only a query or a fragment are left as they are. A child that
50
+ * no `child` link names is given one.
51
+ *
52
+ * Throws where `rootFileName` or `childrenFolder` is not a safe relative path.
53
+ */
54
+ export declare function splitCatalogue(catalogue: StacCatalog, options?: SplitCatalogueOptions): CatalogueDocument[];
@@ -0,0 +1,202 @@
1
+ const DEFAULT_ROOT_FILE_NAME = 'catalog.json';
2
+ /**
3
+ * The catalogue `catalogue` holds, one document holding the whole tree, as
4
+ * separate documents, the root first and then each child after its parent, in
5
+ * the order the parent's `child` links list them.
6
+ *
7
+ * A Catalog's Collections go in a `collections` folder beside it and its
8
+ * nested Catalogs in a `catalogs` folder, each in a folder of its own holding
9
+ * its `catalog.json`. The root's go in `childrenFolder`. A document's file or
10
+ * folder name is its id, made safe as a file name on any system (`safeName`),
11
+ * and where two in one folder would take the same name, in any case, the later
12
+ * one is given `-2`, `-3` and so on.
13
+ *
14
+ * Every relative href, in each link and asset, is rewritten from the
15
+ * document's own path. A `self`, `root` or `parent` link names that document's
16
+ * new path, and a `child` link whose href is a child's own `self` href names
17
+ * the child's. Every other relative href is resolved against the root
18
+ * document's folder, as the one document's hrefs are, so a data file keeps its
19
+ * place, even one outside that folder. An absolute href, one starting with `/`,
20
+ * and one holding only a query or a fragment are left as they are. A child that
21
+ * no `child` link names is given one.
22
+ *
23
+ * Throws where `rootFileName` or `childrenFolder` is not a safe relative path.
24
+ */
25
+ export function splitCatalogue(catalogue, options = {}) {
26
+ const rootFileName = options.rootFileName ?? DEFAULT_ROOT_FILE_NAME;
27
+ if (!isSafeName(rootFileName) || !/\.json$/i.test(rootFileName)) {
28
+ throw new Error(`The root document's file name must be one safe file name ending in .json: ${JSON.stringify(rootFileName)}`);
29
+ }
30
+ const childrenFolder = (options.childrenFolder ?? '').replace(/\/$/, '');
31
+ const folderNames = childrenFolder ? childrenFolder.split('/') : [];
32
+ if (!folderNames.every(isSafeName) || folderNames[0]?.toLowerCase() === rootFileName.toLowerCase()) {
33
+ throw new Error(`The children's folder must be a relative path of safe folder names, apart from the root document: ${JSON.stringify(options.childrenFolder)}`);
34
+ }
35
+ const root = placeCatalog(catalogue, rootFileName, folderNames);
36
+ const documents = [];
37
+ writeDocuments(root, null, root, documents);
38
+ return documents;
39
+ }
40
+ /**
41
+ * Places a Catalog at `path` and its children in `folder`, so every path is
42
+ * known before any href is written.
43
+ */
44
+ function placeCatalog(catalog, path, folder) {
45
+ const candidates = [...(catalog.collections ?? []), ...(catalog.catalogs ?? [])];
46
+ const claimed = new Set();
47
+ const ordered = [];
48
+ catalog.links.forEach((link, linkIndex) => {
49
+ if (link.rel !== 'child')
50
+ return;
51
+ const node = candidates.find((candidate) => !claimed.has(candidate) && selfHrefOf(candidate) === link.href);
52
+ if (!node)
53
+ return;
54
+ claimed.add(node);
55
+ ordered.push({ node, linkIndex });
56
+ });
57
+ for (const node of candidates) {
58
+ if (!claimed.has(node))
59
+ ordered.push({ node, linkIndex: -1 });
60
+ }
61
+ const fileNames = new Set();
62
+ const folderNames = new Set();
63
+ const children = ordered.map(({ node, linkIndex }) => {
64
+ if (node.type === 'Collection') {
65
+ const fileName = unclaimedName(safeName(node.id), '.json', fileNames);
66
+ return { placed: { node, path: [...folder, 'collections', fileName].join('/'), children: [] }, linkIndex };
67
+ }
68
+ const childFolder = [...folder, 'catalogs', unclaimedName(safeName(node.id), '', folderNames)];
69
+ return { placed: placeCatalog(node, [...childFolder, 'catalog.json'].join('/'), childFolder), linkIndex };
70
+ });
71
+ return { node: catalog, path, children };
72
+ }
73
+ function writeDocuments(placed, parent, root, into) {
74
+ const folder = placed.path.split('/').slice(0, -1).map(encodeURIComponent);
75
+ const hrefTo = (other) => relativeHref(folder, { ups: 0, segments: other.path.split('/').map(encodeURIComponent) });
76
+ const childAt = new Map(placed.children.filter((child) => child.linkIndex >= 0).map((child) => [child.linkIndex, child.placed]));
77
+ const links = placed.node.links.map((link, index) => {
78
+ if (!isPathHref(link.href))
79
+ return { ...link };
80
+ const child = childAt.get(index);
81
+ if (child)
82
+ return { ...link, href: hrefTo(child) };
83
+ if (link.rel === 'self')
84
+ return { ...link, href: hrefTo(placed) };
85
+ if (link.rel === 'root')
86
+ return { ...link, href: hrefTo(root) };
87
+ if (link.rel === 'parent' && parent)
88
+ return { ...link, href: hrefTo(parent) };
89
+ return { ...link, href: rewriteHref(link.href, folder) };
90
+ });
91
+ for (const child of placed.children) {
92
+ if (child.linkIndex >= 0)
93
+ continue;
94
+ const title = child.placed.node.title;
95
+ links.push({ rel: 'child', href: hrefTo(child.placed), type: 'application/json', ...(title === undefined ? {} : { title }) });
96
+ }
97
+ const document = {};
98
+ for (const [key, value] of Object.entries(placed.node)) {
99
+ if (key === 'collections' || key === 'catalogs')
100
+ continue;
101
+ if (key === 'links')
102
+ document[key] = links;
103
+ else if (key === 'assets' && value && typeof value === 'object')
104
+ document[key] = rewriteAssets(value, folder);
105
+ else
106
+ document[key] = value;
107
+ }
108
+ into.push({ path: placed.path, document: document });
109
+ for (const child of placed.children)
110
+ writeDocuments(child.placed, placed, root, into);
111
+ }
112
+ function rewriteAssets(assets, folder) {
113
+ return Object.fromEntries(Object.entries(assets).map(([key, asset]) => ([key, typeof asset?.href === 'string' ? { ...asset, href: rewriteHref(asset.href, folder) } : asset])));
114
+ }
115
+ function selfHrefOf(node) {
116
+ return node.links.find((link) => link.rel === 'self')?.href;
117
+ }
118
+ /**
119
+ * Whether an href is a relative path, which moves with the document holding
120
+ * it: not an absolute address, not one starting with `/`, and not one holding
121
+ * only a query or a fragment, which names the document it is in.
122
+ */
123
+ function isPathHref(href) {
124
+ return typeof href === 'string' && href !== '' && !/^[a-z][a-z0-9+.-]*:/i.test(href) && !/^[/?#]/.test(href);
125
+ }
126
+ /** A relative href, which resolves against the root document's folder, rewritten from `folder`, a folder inside it. */
127
+ function rewriteHref(href, folder) {
128
+ if (!isPathHref(href))
129
+ return href;
130
+ const cut = href.search(/[?#]/);
131
+ const path = cut < 0 ? href : href.slice(0, cut);
132
+ const rest = cut < 0 ? '' : href.slice(cut);
133
+ return relativeHref(folder, resolvePath(path)) + rest;
134
+ }
135
+ /** A relative path resolved against the root document's folder, its `.` and `..` segments taken out. */
136
+ function resolvePath(path) {
137
+ const segments = [];
138
+ let ups = 0;
139
+ const parts = path.split('/');
140
+ parts.forEach((part, index) => {
141
+ const last = index === parts.length - 1;
142
+ if (part === '.' || part === '..') {
143
+ if (part === '..') {
144
+ if (segments.length > 0)
145
+ segments.pop();
146
+ else
147
+ ups += 1;
148
+ }
149
+ // A path ending in `.` or `..` names a folder.
150
+ if (last)
151
+ segments.push('');
152
+ return;
153
+ }
154
+ segments.push(part);
155
+ });
156
+ return { ups, segments };
157
+ }
158
+ /** The href naming `target` from `folder`, both from the root document's folder. */
159
+ function relativeHref(folder, target) {
160
+ if (target.ups > 0)
161
+ return '../'.repeat(folder.length + target.ups) + target.segments.join('/');
162
+ const targetFolder = target.segments.slice(0, -1);
163
+ let shared = 0;
164
+ while (shared < folder.length && shared < targetFolder.length && folder[shared] === targetFolder[shared])
165
+ shared += 1;
166
+ const rest = target.segments.slice(shared).join('/');
167
+ const ups = folder.length - shared;
168
+ return ups > 0 ? '../'.repeat(ups) + rest : `./${rest}`;
169
+ }
170
+ /** Characters no file name may hold on Windows, macOS or Linux: controls, `/`, and those Windows refuses. */
171
+ const UNSAFE_CHARACTERS = /[\u0000-\u001f\u007f"*/:<>?\\|]/g;
172
+ /** The names Windows keeps for devices, with or without an extension. */
173
+ const RESERVED_NAME = /^(con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(\.|$)/i;
174
+ /**
175
+ * An id made a file or folder name that is safe on any system: each character
176
+ * a name may not hold, `/` among them, becomes `_`, as does each `.` or space
177
+ * at its end, which Windows drops; an empty name is `_`; and a name Windows
178
+ * keeps for a device, such as `con`, is given a leading `_`. So no name is
179
+ * empty, `.` or `..`.
180
+ */
181
+ function safeName(id) {
182
+ let name = id.replace(UNSAFE_CHARACTERS, '_');
183
+ // Counted from the end, not matched with /[. ]+$/, which takes time growing with the square of a run of spaces that does not end the id.
184
+ let kept = name.length;
185
+ while (kept > 0 && (name[kept - 1] === '.' || name[kept - 1] === ' '))
186
+ kept -= 1;
187
+ name = name.slice(0, kept) + '_'.repeat(name.length - kept);
188
+ if (name === '')
189
+ name = '_';
190
+ return RESERVED_NAME.test(name) ? `_${name}` : name;
191
+ }
192
+ function isSafeName(name) {
193
+ return safeName(name) === name;
194
+ }
195
+ /** `name` and `suffix`, or with `-2`, `-3` and so on before the suffix, whichever is first not in `taken`, compared in lower case. */
196
+ function unclaimedName(name, suffix, taken) {
197
+ let candidate = `${name}${suffix}`;
198
+ for (let count = 2; taken.has(candidate.toLowerCase()); count += 1)
199
+ candidate = `${name}-${count}${suffix}`;
200
+ taken.add(candidate.toLowerCase());
201
+ return candidate;
202
+ }
@@ -29,6 +29,11 @@ export interface StacCompanionData {
29
29
  * This is a thin wrapper: `qgsProjectToNormalized` resolves the QGS-specific
30
30
  * wording, assets and columns into the shared `NormalizedProject`, and
31
31
  * `generateStacFromNormalized` (see normalizedProject.ts) builds the catalogue.
32
+ *
33
+ * A layer or group the project leaves out of WMS (**Exclude layers**) is left
34
+ * out, as `generateServerStacCatalogue` leaves it out: the catalogue is built
35
+ * as if the project did not hold it, so a relation, Value Relation, filter or
36
+ * initial active layer naming it is dropped too (`wmsExcludedLayerIds`).
32
37
  */
33
38
  export declare function generateStacCatalogue(project: QgsProject, companions?: StacCompanionData[], options?: {
34
39
  selfHref?: string;
@@ -75,6 +80,13 @@ export declare function qgisServerNamesOf(layer: LayerEntry, context: {
75
80
  wmsPublishing: WmsPublishing | null;
76
81
  wfsTransactionLayers: WfsTransactionLayers | null;
77
82
  }): QgisServerNames;
83
+ /**
84
+ * The layers a project leaves out of WMS under **Exclude layers**
85
+ * (`WMSRestrictedLayers`): each layer whose name it lists, wherever the layer
86
+ * sits, and every layer inside a group whose name it lists. Neither route's
87
+ * catalogue holds them.
88
+ */
89
+ export declare function wmsExcludedLayerIds(project: QgsProject): Set<string>;
78
90
  /** The title of the `via` link to the QGIS project a layer's Collection was written from. */
79
91
  export declare const QGIS_PROJECT_LINK_TITLE = "QGIS project";
80
92
  /**
@@ -30,6 +30,11 @@ import { declaredMediaTypeForFile, isLayerFileOfFormat, PROJECT_DATA_ROLES, QML_
30
30
  * This is a thin wrapper: `qgsProjectToNormalized` resolves the QGS-specific
31
31
  * wording, assets and columns into the shared `NormalizedProject`, and
32
32
  * `generateStacFromNormalized` (see normalizedProject.ts) builds the catalogue.
33
+ *
34
+ * A layer or group the project leaves out of WMS (**Exclude layers**) is left
35
+ * out, as `generateServerStacCatalogue` leaves it out: the catalogue is built
36
+ * as if the project did not hold it, so a relation, Value Relation, filter or
37
+ * initial active layer naming it is dropped too (`wmsExcludedLayerIds`).
33
38
  */
34
39
  export function generateStacCatalogue(project, companions = [], options = {}) {
35
40
  // `selfHref` is the folder the project was published from, for a project
@@ -59,7 +64,7 @@ export function generateStacCatalogue(project, companions = [], options = {}) {
59
64
  // reproject the canvas. `resolveLayerWgs84Extents` in the same file builds
60
65
  // this map; a layer left out of it (or a caller that leaves the option off
61
66
  // entirely) has no box of its own.
62
- return withSelfLink(generateStacFromNormalized(qgsProjectToNormalized(project, companions, options.projectPath, options.projectPath ?? options.projectFileName, options.initialView ?? null, options.layerWgs84Extents)), options.selfHref);
67
+ return withSelfLink(generateStacFromNormalized(qgsProjectToNormalized(withoutWmsExcludedLayers(project), companions, options.projectPath, options.projectPath ?? options.projectFileName, options.initialView ?? null, options.layerWgs84Extents)), options.selfHref);
63
68
  }
64
69
  /**
65
70
  * The key a style asset takes for the field its renderer classifies by, when
@@ -333,6 +338,48 @@ export function qgisServerNamesOf(layer, context) {
333
338
  const wfsTypeName = wfsPublished ? ownName.replace(/ /g, '_').replace(/[:\u2014]/g, '-') : null;
334
339
  return { wmsName: wmsName || null, wfsTypeName: wfsTypeName || null };
335
340
  }
341
+ /**
342
+ * The layers a project leaves out of WMS under **Exclude layers**
343
+ * (`WMSRestrictedLayers`): each layer whose name it lists, wherever the layer
344
+ * sits, and every layer inside a group whose name it lists. Neither route's
345
+ * catalogue holds them.
346
+ */
347
+ export function wmsExcludedLayerIds(project) {
348
+ const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
349
+ const excluded = new Set();
350
+ if (restricted.size === 0)
351
+ return excluded;
352
+ for (const layer of project.layers) {
353
+ if (restricted.has(layer.name))
354
+ excluded.add(layer.id);
355
+ }
356
+ const walk = (group, inExcludedGroup) => {
357
+ for (const node of group.children) {
358
+ if (node.kind === 'group')
359
+ walk(node, inExcludedGroup || restricted.has(node.name));
360
+ else if (inExcludedGroup)
361
+ excluded.add(node.layerId);
362
+ }
363
+ };
364
+ walk(project.layerTree, false);
365
+ return excluded;
366
+ }
367
+ /** The project less the layers and groups it leaves out of WMS (`wmsExcludedLayerIds`). */
368
+ function withoutWmsExcludedLayers(project) {
369
+ const excluded = wmsExcludedLayerIds(project);
370
+ if (excluded.size === 0)
371
+ return project;
372
+ const restricted = new Set(project.wmsPublishing?.restrictedLayers ?? []);
373
+ const prune = (group) => ({
374
+ ...group,
375
+ children: group.children.flatMap((node) => {
376
+ if (node.kind === 'group')
377
+ return restricted.has(node.name) ? [] : [prune(node)];
378
+ return excluded.has(node.layerId) ? [] : [node];
379
+ })
380
+ });
381
+ return { ...project, layers: project.layers.filter((layer) => !excluded.has(layer.id)), layerTree: prune(project.layerTree) };
382
+ }
336
383
  /** The shape a file layer's own `|geometrytype=` keeps, as the list `quac:geometry_filter` holds. */
337
384
  function geometryFilterOf(layer) {
338
385
  const shapes = readSiblingShapes([layer]);
@@ -377,6 +424,7 @@ function qgsLayerToNormalized(layer, context, geometryFilter = geometryFilterOf(
377
424
  isPrivate: layer.isPrivate,
378
425
  legendImage: layer.legendImage,
379
426
  icon: layer.icon,
427
+ addedMessage: layer.addedMessage,
380
428
  locks: combineLocks(layer.locks ?? {}, wfsTransactionLocks(layer.id, context.wfsTransactionLayers)),
381
429
  filters: context.filtersByCollectionId.get(layer.id),
382
430
  vendorFields: buildVendorFields(layer, context.measurement),
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ export { FILE_EXTENSION, FILE_SIZE_FIELD, TABLE_ROW_COUNT_FIELD, readCollectionR
34
34
  export { PMTILES_MEDIA_TYPE, VISUAL_ROLE, readCollectionPmtiles } from './model/stacPmtiles.ts';
35
35
  export type { StacPmtilesSource } from './model/stacPmtiles.ts';
36
36
  export type { StacCompanionData } from './generate/stacCatalogue.ts';
37
- export { QUAC_ACTIVE_COLLECTION_FIELD, QUAC_FILTERS_FIELD, QUAC_FORM_ORDER_FIELD, QUAC_LOCKS_FIELD, QUAC_MUTUALLY_EXCLUSIVE_FIELD, QUAC_PRIVATE_FIELD, readCatalogueActiveCollection, readCatalogueInitialView, readCollectionDisplayField, readCollectionEditable, readCollectionFieldAliases, readCollectionFieldComments, readCollectionFieldAttachments, readCollectionFieldEditRules, readCollectionFieldNames, readCollectionFieldTypes, readCollectionFieldValueRelations, readCollectionFieldValues, readCollectionFormLayout, readCollectionGeometryType, readCollectionIdentifiable, readCollectionMeasurement, readCollectionOpacity, readCollectionIcon, readCollectionLegendImage, readCollectionFilters, readCollectionLocks, readCollectionPrivate, readCollectionRelatedTo, readCollectionScaleRange, readCollectionVisibility, statedOpacity } from './generate/normalizedProject.ts';
37
+ export { QUAC_ACTIVE_COLLECTION_FIELD, QUAC_FILTERS_FIELD, QUAC_FORM_ORDER_FIELD, QUAC_LOCKS_FIELD, QUAC_MUTUALLY_EXCLUSIVE_FIELD, QUAC_PRIVATE_FIELD, readCatalogueActiveCollection, readCatalogueInitialView, readCollectionDisplayField, readCollectionEditable, readCollectionFieldAliases, readCollectionFieldComments, readCollectionFieldAttachments, readCollectionFieldEditRules, readCollectionFieldNames, readCollectionFieldTypes, readCollectionFieldValueRelations, readCollectionFieldValues, readCollectionFormLayout, readCollectionGeometryType, readCollectionIdentifiable, readCollectionMeasurement, readCollectionOpacity, readCollectionIcon, readCollectionAddedMessage, readCollectionLegendImage, readCollectionFilters, readCollectionLocks, readCollectionPrivate, readCollectionRelatedTo, readCollectionScaleRange, readCollectionVisibility, statedOpacity } from './generate/normalizedProject.ts';
38
38
  export type { CollectionFilter, CollectionFormLayout, CollectionRelation, CollectionRelationField } from './generate/normalizedProject.ts';
39
39
  export { generateStacCatalogueFromWfsCapabilities } from './generate/wfsStacCatalogue.ts';
40
40
  export type { WfsStacCatalogueOptions } from './generate/wfsStacCatalogue.ts';
@@ -82,4 +82,6 @@ export { generateServerStacCatalogue, withoutHiddenFields } from './generate/ser
82
82
  export type { HiddenFieldContext } from './generate/serverStacCatalogue.ts';
83
83
  export { serverLayerTree } from './generate/serverLayerTree.ts';
84
84
  export type { ServerLayerTree, ServerLayerTreeGroup, ServerLayerTreeLayer, ServerLayerTreeNode } from './generate/serverLayerTree.ts';
85
+ export { splitCatalogue } from './generate/splitCatalogue.ts';
86
+ export type { CatalogueDocument, SplitCatalogueOptions } from './generate/splitCatalogue.ts';
85
87
  export { PROJ_CODE, PROJECTION_EXTENSION, readCollectionCrs } from './model/stacProjection.ts';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export { DATA_ROLE, findAssetByRole, readDataAsset } from "./model/stacAssetRole
23
23
  export { THUMBNAIL_ROLE, readCollectionAttribution, readCollectionDeprecation, readCollectionSelfHref, readCollectionThumbnail } from "./model/stacCollectionNotes.js";
24
24
  export { FILE_EXTENSION, FILE_SIZE_FIELD, TABLE_ROW_COUNT_FIELD, readCollectionRowCount, readDataAssetFileSize } from "./model/stacSizeAndCount.js";
25
25
  export { PMTILES_MEDIA_TYPE, VISUAL_ROLE, readCollectionPmtiles } from "./model/stacPmtiles.js";
26
- export { QUAC_ACTIVE_COLLECTION_FIELD, QUAC_FILTERS_FIELD, QUAC_FORM_ORDER_FIELD, QUAC_LOCKS_FIELD, QUAC_MUTUALLY_EXCLUSIVE_FIELD, QUAC_PRIVATE_FIELD, readCatalogueActiveCollection, readCatalogueInitialView, readCollectionDisplayField, readCollectionEditable, readCollectionFieldAliases, readCollectionFieldComments, readCollectionFieldAttachments, readCollectionFieldEditRules, readCollectionFieldNames, readCollectionFieldTypes, readCollectionFieldValueRelations, readCollectionFieldValues, readCollectionFormLayout, readCollectionGeometryType, readCollectionIdentifiable, readCollectionMeasurement, readCollectionOpacity, readCollectionIcon, readCollectionLegendImage, readCollectionFilters, readCollectionLocks, readCollectionPrivate, readCollectionRelatedTo, readCollectionScaleRange, readCollectionVisibility, statedOpacity } from "./generate/normalizedProject.js";
26
+ export { QUAC_ACTIVE_COLLECTION_FIELD, QUAC_FILTERS_FIELD, QUAC_FORM_ORDER_FIELD, QUAC_LOCKS_FIELD, QUAC_MUTUALLY_EXCLUSIVE_FIELD, QUAC_PRIVATE_FIELD, readCatalogueActiveCollection, readCatalogueInitialView, readCollectionDisplayField, readCollectionEditable, readCollectionFieldAliases, readCollectionFieldComments, readCollectionFieldAttachments, readCollectionFieldEditRules, readCollectionFieldNames, readCollectionFieldTypes, readCollectionFieldValueRelations, readCollectionFieldValues, readCollectionFormLayout, readCollectionGeometryType, readCollectionIdentifiable, readCollectionMeasurement, readCollectionOpacity, readCollectionIcon, readCollectionAddedMessage, readCollectionLegendImage, readCollectionFilters, readCollectionLocks, readCollectionPrivate, readCollectionRelatedTo, readCollectionScaleRange, readCollectionVisibility, statedOpacity } from "./generate/normalizedProject.js";
27
27
  export { generateStacCatalogueFromWfsCapabilities } from "./generate/wfsStacCatalogue.js";
28
28
  export { generateStacCatalogueFromFolder } from "./generate/folderStacCatalogue.js";
29
29
  export { generateCollectionForDroppedFile, generateCollectionForLinkedFile } from "./generate/fileLayerCollection.js";
@@ -53,4 +53,5 @@ export { DEFAULT_WFS_VERSION, SPOKEN_WFS_VERSIONS, WFS_CAPABILITIES_VERSION, WFS
53
53
  export { QUAC_SCHEMA_URL, declareQuacExtension, isNewerQuacMajor, listQuacExtension, readQuacVersion } from "./model/quacExtension.js";
54
54
  export { generateServerStacCatalogue, withoutHiddenFields } from "./generate/serverStacCatalogue.js";
55
55
  export { serverLayerTree } from "./generate/serverLayerTree.js";
56
+ export { splitCatalogue } from "./generate/splitCatalogue.js";
56
57
  export { PROJ_CODE, PROJECTION_EXTENSION, readCollectionCrs } from "./model/stacProjection.js";
@@ -289,6 +289,12 @@ export interface LayerEntry {
289
289
  * or absent where it sets none.
290
290
  */
291
291
  icon?: string | null;
292
+ /**
293
+ * The message shown once a feature is added to the layer, from its
294
+ * `quac_added_message` variable, as written. Null or absent where it sets
295
+ * none.
296
+ */
297
+ addedMessage?: string | null;
292
298
  /**
293
299
  * The address of each field's icon, from the layer's `quac_icon_<field>`
294
300
  * variables. Fields with none are absent.
@@ -117,6 +117,7 @@ function parseMapLayer(maplayer, notes) {
117
117
  fieldAttachments,
118
118
  fieldEditRules: parseFieldEditRules(maplayer, note),
119
119
  icon: parseLayerIcon(maplayer),
120
+ addedMessage: parseAddedMessage(maplayer),
120
121
  fieldIcons: parseFieldIcons(maplayer),
121
122
  fieldControls: parseFieldControls(maplayer),
122
123
  formLayout: parseFormLayout(maplayer),
@@ -991,19 +992,38 @@ function parseFieldIcons(maplayer) {
991
992
  }
992
993
  /** The name of the layer variable that sets the layer's own icon. */
993
994
  const LAYER_ICON_VARIABLE = 'quac_icon';
995
+ /** The name of the layer variable that holds the message shown once a feature is added. */
996
+ const ADDED_MESSAGE_VARIABLE = 'quac_added_message';
994
997
  /**
995
- * Reads the icon the layer's `quac_icon` variable sets, as an address
996
- * (`resolveFieldIconAddress`), held in the same lists as the field icons.
997
- * Null where the layer has no such variable or its value names no icon.
998
+ * The value of the layer variable of this name, held in the layer's
999
+ * `variableNames` and `variableValues` custom properties. Null where the layer
1000
+ * has no such variable.
998
1001
  */
999
- function parseLayerIcon(maplayer) {
1002
+ function readLayerVariable(maplayer, variable) {
1000
1003
  const properties = directChild(maplayer, 'customproperties');
1001
1004
  if (!properties)
1002
1005
  return null;
1003
1006
  const names = readCustomPropertyList(properties, 'variableNames');
1004
1007
  const values = readCustomPropertyList(properties, 'variableValues');
1005
- const index = names.indexOf(LAYER_ICON_VARIABLE);
1006
- return index === -1 || index >= values.length ? null : resolveFieldIconAddress(values[index]);
1008
+ const index = names.indexOf(variable);
1009
+ return index === -1 || index >= values.length ? null : values[index];
1010
+ }
1011
+ /**
1012
+ * Reads the icon the layer's `quac_icon` variable sets, as an address
1013
+ * (`resolveFieldIconAddress`). Null where the layer has no such variable or
1014
+ * its value names no icon.
1015
+ */
1016
+ function parseLayerIcon(maplayer) {
1017
+ const value = readLayerVariable(maplayer, LAYER_ICON_VARIABLE);
1018
+ return value === null ? null : resolveFieldIconAddress(value);
1019
+ }
1020
+ /**
1021
+ * Reads the message the layer's `quac_added_message` variable holds, as
1022
+ * written. Null where the layer has no such variable or its value is blank.
1023
+ */
1024
+ function parseAddedMessage(maplayer) {
1025
+ const value = readLayerVariable(maplayer, ADDED_MESSAGE_VARIABLE);
1026
+ return value === null || value.trim() === '' ? null : value;
1007
1027
  }
1008
1028
  /** The start of the name of a layer variable that chooses a field's control: `quac_control_condition`. */
1009
1029
  const FIELD_CONTROL_VARIABLE_PREFIX = 'quac_control_';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectoriahq/quac",
3
- "version": "0.12.0",
3
+ "version": "0.15.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.",
@@ -253,6 +253,11 @@
253
253
  "type": "string",
254
254
  "pattern": "^https://"
255
255
  },
256
+ "quac:added_message": {
257
+ "description": "The message shown once a feature is added to this Collection, which may hold HTML markup. Written from the layer variable named quac_added_message.",
258
+ "type": "string",
259
+ "minLength": 1
260
+ },
256
261
  "quac:form_order": {
257
262
  "description": "The names of the fields the source's form layout places, in its order. A column not listed is left out of the form. Written from a QGIS layer's Drag and Drop Designer form.",
258
263
  "type": "array",