@vectoriahq/quac 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +35 -2
- package/dist/generate/arcgisStacCatalogue.d.ts +46 -0
- package/dist/generate/arcgisStacCatalogue.js +189 -0
- package/dist/generate/externalStacCatalogue.d.ts +53 -0
- package/dist/generate/externalStacCatalogue.js +143 -0
- package/dist/generate/fileLayerCollection.d.ts +44 -0
- package/dist/generate/fileLayerCollection.js +72 -0
- package/dist/generate/folderStacCatalogue.d.ts +48 -0
- package/dist/generate/folderStacCatalogue.js +69 -0
- package/dist/generate/normalizedProject.d.ts +452 -0
- package/dist/generate/normalizedProject.js +877 -0
- package/dist/generate/ogcFeaturesStacCatalogue.d.ts +49 -0
- package/dist/generate/ogcFeaturesStacCatalogue.js +207 -0
- package/dist/generate/qmlForLayer.d.ts +17 -0
- package/dist/generate/qmlForLayer.js +36 -0
- package/dist/generate/serverLayerTree.d.ts +44 -0
- package/dist/generate/serverLayerTree.js +50 -0
- package/dist/generate/serverStacCatalogue.d.ts +84 -0
- package/dist/generate/serverStacCatalogue.js +327 -0
- package/dist/generate/stacCatalogue.d.ts +110 -0
- package/dist/generate/stacCatalogue.js +887 -0
- package/dist/generate/wfsStacCatalogue.d.ts +37 -0
- package/dist/generate/wfsStacCatalogue.js +127 -0
- package/dist/generate/wmsStacCatalogue.d.ts +46 -0
- package/dist/generate/wmsStacCatalogue.js +229 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +52 -0
- package/dist/model/QgsProject.d.ts +724 -0
- package/dist/model/QgsProject.js +15 -0
- package/dist/model/Stac.d.ts +322 -0
- package/dist/model/Stac.js +16 -0
- package/dist/model/WmsProject.d.ts +105 -0
- package/dist/model/WmsProject.js +1 -0
- package/dist/model/arcgis.d.ts +134 -0
- package/dist/model/arcgis.js +1 -0
- package/dist/model/delimitedText.d.ts +38 -0
- package/dist/model/delimitedText.js +46 -0
- package/dist/model/featureFilter.d.ts +41 -0
- package/dist/model/featureFilter.js +24 -0
- package/dist/model/fieldIconAddress.d.ts +27 -0
- package/dist/model/fieldIconAddress.js +93 -0
- package/dist/model/ogcFeatures.d.ts +40 -0
- package/dist/model/ogcFeatures.js +6 -0
- package/dist/model/quacExtension.d.ts +28 -0
- package/dist/model/quacExtension.js +75 -0
- package/dist/model/stacAssetRoles.d.ts +33 -0
- package/dist/model/stacAssetRoles.js +44 -0
- package/dist/model/stacCollectionNotes.d.ts +21 -0
- package/dist/model/stacCollectionNotes.js +44 -0
- package/dist/model/stacHref.d.ts +56 -0
- package/dist/model/stacHref.js +93 -0
- package/dist/model/stacPmtiles.d.ts +38 -0
- package/dist/model/stacPmtiles.js +69 -0
- package/dist/model/stacSizeAndCount.d.ts +14 -0
- package/dist/model/stacSizeAndCount.js +20 -0
- package/dist/model/stacStyles.d.ts +93 -0
- package/dist/model/stacStyles.js +87 -0
- package/dist/model/stacTreeWalk.d.ts +36 -0
- package/dist/model/stacTreeWalk.js +76 -0
- package/dist/model/stacWms.d.ts +18 -0
- package/dist/model/stacWms.js +73 -0
- package/dist/model/stacWmts.d.ts +34 -0
- package/dist/model/stacWmts.js +90 -0
- package/dist/model/stacXyz.d.ts +24 -0
- package/dist/model/stacXyz.js +46 -0
- package/dist/model/wfs.d.ts +136 -0
- package/dist/model/wfs.js +1 -0
- package/dist/parse/collectLayerVisibility.d.ts +10 -0
- package/dist/parse/collectLayerVisibility.js +22 -0
- package/dist/parse/customProperties.d.ts +18 -0
- package/dist/parse/customProperties.js +43 -0
- package/dist/parse/geometrySiblings.d.ts +25 -0
- package/dist/parse/geometrySiblings.js +83 -0
- package/dist/parse/parseBrandColour.d.ts +14 -0
- package/dist/parse/parseBrandColour.js +25 -0
- package/dist/parse/parseDataDefinedEditable.d.ts +38 -0
- package/dist/parse/parseDataDefinedEditable.js +76 -0
- package/dist/parse/parseDataSource.d.ts +53 -0
- package/dist/parse/parseDataSource.js +484 -0
- package/dist/parse/parseExtent.d.ts +17 -0
- package/dist/parse/parseExtent.js +49 -0
- package/dist/parse/parseFormLayout.d.ts +26 -0
- package/dist/parse/parseFormLayout.js +60 -0
- package/dist/parse/parseGetProjectSettings.d.ts +15 -0
- package/dist/parse/parseGetProjectSettings.js +172 -0
- package/dist/parse/parseLayers.d.ts +23 -0
- package/dist/parse/parseLayers.js +1125 -0
- package/dist/parse/parseLegendTree.d.ts +20 -0
- package/dist/parse/parseLegendTree.js +66 -0
- package/dist/parse/parseMeasurement.d.ts +20 -0
- package/dist/parse/parseMeasurement.js +66 -0
- package/dist/parse/parseMergin.d.ts +19 -0
- package/dist/parse/parseMergin.js +51 -0
- package/dist/parse/parseProjectVariables.d.ts +9 -0
- package/dist/parse/parseProjectVariables.js +19 -0
- package/dist/parse/parseQfieldSync.d.ts +47 -0
- package/dist/parse/parseQfieldSync.js +95 -0
- package/dist/parse/parseQgsXml.d.ts +15 -0
- package/dist/parse/parseQgsXml.js +100 -0
- package/dist/parse/parseRelations.d.ts +19 -0
- package/dist/parse/parseRelations.js +64 -0
- package/dist/parse/parseStyle.d.ts +33 -0
- package/dist/parse/parseStyle.js +128 -0
- package/dist/parse/parseWmsPublishing.d.ts +21 -0
- package/dist/parse/parseWmsPublishing.js +38 -0
- package/dist/parse/projectProperties.d.ts +15 -0
- package/dist/parse/projectProperties.js +27 -0
- package/dist/parse/qgisExpression.d.ts +194 -0
- package/dist/parse/qgisExpression.js +859 -0
- package/dist/parse/qtDateFormat.d.ts +74 -0
- package/dist/parse/qtDateFormat.js +324 -0
- package/dist/parse/qtRegex.d.ts +67 -0
- package/dist/parse/qtRegex.js +397 -0
- package/dist/parse/readProjectFile.d.ts +7 -0
- package/dist/parse/readProjectFile.js +27 -0
- package/dist/sources/qgisServerUrl.d.ts +6 -0
- package/dist/sources/qgisServerUrl.js +17 -0
- package/dist/sources/stacDocuments.d.ts +40 -0
- package/dist/sources/stacDocuments.js +85 -0
- package/dist/sources/stacItems.d.ts +109 -0
- package/dist/sources/stacItems.js +287 -0
- package/dist/util/catalogueFileFormats.d.ts +58 -0
- package/dist/util/catalogueFileFormats.js +64 -0
- package/dist/util/devLog.d.ts +10 -0
- package/dist/util/devLog.js +22 -0
- package/dist/util/fileName.d.ts +18 -0
- package/dist/util/fileName.js +45 -0
- package/dist/util/nonBlankText.d.ts +2 -0
- package/dist/util/nonBlankText.js +4 -0
- package/dist/util/wfsVersions.d.ts +9 -0
- package/dist/util/wfsVersions.js +13 -0
- package/package.json +55 -4
- package/src/schema/quac.schema.json +939 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QGIS hands a regular expression to Qt's `QRegularExpression`, which is PCRE2;
|
|
3
|
+
* this package runs it as a JavaScript `RegExp`. The two engines differ in many
|
|
4
|
+
* corners (`pcre2pattern`, PCRE2 10.4x, read 2026-10-27), so this file reads
|
|
5
|
+
* only the forms listed here, written so that both give the same answer, and
|
|
6
|
+
* gives null for any other pattern, so the expression is not read rather than
|
|
7
|
+
* worked out differently.
|
|
8
|
+
*
|
|
9
|
+
* - A character, a backslash before one that is not a letter or digit, `\n`,
|
|
10
|
+
* `\r`, `\t`, `\f`, `\xhh` and `\x{…}`.
|
|
11
|
+
* - `.`, which matches anything but a line feed, `^`, and `$`, which also
|
|
12
|
+
* matches before a final line feed, as PCRE2 does by default.
|
|
13
|
+
* - `\d`, `\w`, `\s`, `\b` and their capitals. With `unicode` (QGIS's
|
|
14
|
+
* `regexp_` functions pass `UseUnicodePropertiesOption`,
|
|
15
|
+
* `src/core/expression/qgsexpressionfunction.cpp`; its `~` operator does
|
|
16
|
+
* not, `qgsexpressionnodeimpl.cpp`, `qgis/QGIS@16eddb2`, read 2026-10-26),
|
|
17
|
+
* they take in every script's digits, letters and spaces, as PCRE2's `UCP`
|
|
18
|
+
* does: `\w` is `\p{L}`, `\p{N}` and `_`, and `\s` is `\p{Z}` with the tab,
|
|
19
|
+
* line and vertical spaces. Without it they are the ASCII ones. That `\w`
|
|
20
|
+
* is PCRE2's before 10.43, which widens it to `\p{Mn}` and `\p{Pc}`; the
|
|
21
|
+
* two differ only on a combining mark or a joining mark such as ‿, where
|
|
22
|
+
* QGIS builds differ too, and Vectoria chose to keep the earlier one
|
|
23
|
+
* (2026-10-27, no reason given).
|
|
24
|
+
* - A class such as `[A-Z_]` or `[^\d,]`.
|
|
25
|
+
* - A group, `(…)` or `(?:…)`, and `|`.
|
|
26
|
+
* - `*`, `+`, `?`, `{n}`, `{n,}` and `{n,m}`, each also lazy with a `?` after it.
|
|
27
|
+
* - A lookahead, `(?=…)` or `(?!…)`, or a lookbehind, `(?<=…)` or `(?<!…)`,
|
|
28
|
+
* that holds no group.
|
|
29
|
+
* - A leading `(?i)`.
|
|
30
|
+
*
|
|
31
|
+
* Within those, these are not read either, because the engines give
|
|
32
|
+
* different answers:
|
|
33
|
+
* - a quantifier after an assertion, such as `\b?`, which PCRE2 refuses;
|
|
34
|
+
* - a quantifier that can repeat a group that captures, or holds a group that
|
|
35
|
+
* does, or a group that can match the empty text: JavaScript clears the
|
|
36
|
+
* inner groups at each repeat and refuses an empty pass of any group whose
|
|
37
|
+
* minimum is 0, and PCRE2 does neither;
|
|
38
|
+
* - a quantifier that can repeat a group holding a `|` or a quantifier whose
|
|
39
|
+
* count can vary, such as `(?:[A-Za-z]+ ?)*`: on text it fails to match,
|
|
40
|
+
* JavaScript can try every way to split it, where PCRE2 stops at its match
|
|
41
|
+
* limit and reports no match. In Node, `^(?:[A-Za-z]+ ?)*$` took 3 s on 26
|
|
42
|
+
* letters and a `!`, and twice as long for each letter more (2026-10-27);
|
|
43
|
+
* - in a lookbehind, a quantifier other than `{n}`, as PCRE2 before 10.43
|
|
44
|
+
* needs a lookbehind of a set length;
|
|
45
|
+
* - inside a class, `\b`, `\S`, and with `unicode` `\D` and `\W`, which have
|
|
46
|
+
* no JavaScript form there, and a `-` beside a class escape, which PCRE2
|
|
47
|
+
* refuses and JavaScript reads as a range;
|
|
48
|
+
* - for `~` with `(?i)`, `\w`, `\W`, `\b` and `\B`, which JavaScript widens
|
|
49
|
+
* to ſ and the Kelvin sign.
|
|
50
|
+
*/
|
|
51
|
+
const UNICODE_WORD = '\\p{L}\\p{N}_';
|
|
52
|
+
const UNICODE_SPACE = '\\t\\n\\v\\f\\r\\x85\\u180E\\p{Z}';
|
|
53
|
+
const ASCII_SPACE = '\\t\\n\\v\\f\\r ';
|
|
54
|
+
/** The escapes that stand for a set of characters, which PCRE2 will not take as the end of a range. */
|
|
55
|
+
const CLASS_TYPES = new Set(['d', 'D', 'w', 'W', 's', 'S']);
|
|
56
|
+
const SYNTAX = new Set(['^', '$', '\\', '.', '*', '+', '?', '(', ')', '[', ']', '{', '}', '|', '/']);
|
|
57
|
+
// A lookahead rather than a group, so that a quantifier after it fails to compile, as PCRE2 refuses `\b?`.
|
|
58
|
+
const wordBoundary = (word, negate) => (negate
|
|
59
|
+
? `(?=(?<=[${word}])(?=[${word}])|(?<![${word}])(?![${word}]))`
|
|
60
|
+
: `(?=(?<=[${word}])(?![${word}])|(?<![${word}])(?=[${word}]))`);
|
|
61
|
+
/** A character that stands for itself, escaped where JavaScript's Unicode mode needs it to be. */
|
|
62
|
+
function literal(char, inClass) {
|
|
63
|
+
if (char === '-')
|
|
64
|
+
return inClass ? '\\-' : '-';
|
|
65
|
+
return SYNTAX.has(char) ? `\\${char}` : char;
|
|
66
|
+
}
|
|
67
|
+
const atomOf = (source) => ({ source, captures: false, assertion: false, empty: false, chooses: false });
|
|
68
|
+
const assertionOf = (source) => ({ source, captures: false, assertion: true, empty: true, chooses: false });
|
|
69
|
+
/** The JavaScript source for one PCRE2 pattern, and whether it ignores case, or null where it is not on the list above. */
|
|
70
|
+
function translate(pattern, unicode) {
|
|
71
|
+
let index = 0;
|
|
72
|
+
let ignoreCase = false;
|
|
73
|
+
if (pattern.startsWith('(?i)')) {
|
|
74
|
+
ignoreCase = true;
|
|
75
|
+
index = 4;
|
|
76
|
+
}
|
|
77
|
+
/** One `\` escape at `index`, which points at the backslash; the JavaScript for it, or null. */
|
|
78
|
+
const escape = (inClass) => {
|
|
79
|
+
const char = pattern[index + 1];
|
|
80
|
+
if (char === undefined)
|
|
81
|
+
return null;
|
|
82
|
+
index += 2;
|
|
83
|
+
switch (char) {
|
|
84
|
+
case 'd': return unicode ? '\\p{Nd}' : '\\d';
|
|
85
|
+
case 'D': return unicode ? (inClass ? null : '\\P{Nd}') : '\\D';
|
|
86
|
+
case 'w': return unicode ? (inClass ? UNICODE_WORD : `[${UNICODE_WORD}]`) : (ignoreCase ? null : '\\w');
|
|
87
|
+
case 'W': return unicode ? (inClass ? null : `[^${UNICODE_WORD}]`) : (ignoreCase ? null : '\\W');
|
|
88
|
+
case 's': {
|
|
89
|
+
const space = unicode ? UNICODE_SPACE : ASCII_SPACE;
|
|
90
|
+
return inClass ? space : `[${space}]`;
|
|
91
|
+
}
|
|
92
|
+
case 'S': return inClass ? null : `[^${unicode ? UNICODE_SPACE : ASCII_SPACE}]`;
|
|
93
|
+
case 'b': return inClass ? null : (unicode ? wordBoundary(UNICODE_WORD, false) : (ignoreCase ? null : '\\b'));
|
|
94
|
+
case 'B': return inClass ? null : (unicode ? wordBoundary(UNICODE_WORD, true) : (ignoreCase ? null : '\\B'));
|
|
95
|
+
case 'n':
|
|
96
|
+
case 'r':
|
|
97
|
+
case 't':
|
|
98
|
+
case 'f': return `\\${char}`;
|
|
99
|
+
case 'x': {
|
|
100
|
+
const braced = /^\{([0-9A-Fa-f]{1,6})\}/.exec(pattern.slice(index));
|
|
101
|
+
if (braced) {
|
|
102
|
+
// PCRE2 in UTF mode refuses a surrogate, and JavaScript takes one.
|
|
103
|
+
const code = parseInt(braced[1], 16);
|
|
104
|
+
if (code >= 0xD800 && code <= 0xDFFF)
|
|
105
|
+
return null;
|
|
106
|
+
index += braced[0].length;
|
|
107
|
+
return `\\u{${braced[1]}}`;
|
|
108
|
+
}
|
|
109
|
+
const hex = /^[0-9A-Fa-f]{2}/.exec(pattern.slice(index));
|
|
110
|
+
if (!hex)
|
|
111
|
+
return null;
|
|
112
|
+
index += 2;
|
|
113
|
+
return `\\x${hex[0]}`;
|
|
114
|
+
}
|
|
115
|
+
default:
|
|
116
|
+
if (/[A-Za-z0-9]/.test(char))
|
|
117
|
+
return null;
|
|
118
|
+
return literal(char, inClass);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
/** A class at `index`, which points at its `[`. */
|
|
122
|
+
const readClass = () => {
|
|
123
|
+
let out = '[';
|
|
124
|
+
index += 1;
|
|
125
|
+
if (pattern[index] === '^') {
|
|
126
|
+
out += '^';
|
|
127
|
+
index += 1;
|
|
128
|
+
}
|
|
129
|
+
const classStart = index;
|
|
130
|
+
// A `]` straight after the opening bracket is a member of the class in PCRE2.
|
|
131
|
+
if (pattern[index] === ']') {
|
|
132
|
+
out += '\\]';
|
|
133
|
+
index += 1;
|
|
134
|
+
}
|
|
135
|
+
while (index < pattern.length) {
|
|
136
|
+
const char = pattern[index];
|
|
137
|
+
if (char === ']') {
|
|
138
|
+
index += 1;
|
|
139
|
+
return `${out}]`;
|
|
140
|
+
}
|
|
141
|
+
if (char === '\\') {
|
|
142
|
+
const start = index;
|
|
143
|
+
const part = escape(true);
|
|
144
|
+
if (part === null)
|
|
145
|
+
return null;
|
|
146
|
+
if (CLASS_TYPES.has(pattern[start + 1])) {
|
|
147
|
+
const hyphenBefore = pattern[start - 1] === '-' && start - 1 > classStart && pattern[start - 2] !== '\\';
|
|
148
|
+
const hyphenAfter = pattern[index] === '-' && pattern[index + 1] !== ']';
|
|
149
|
+
if (hyphenBefore || hyphenAfter)
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
out += part;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
// `[:`, `[=` and `[.` start a POSIX class in PCRE2.
|
|
156
|
+
if (char === '[' && /[:=.]/.test(pattern[index + 1] ?? ''))
|
|
157
|
+
return null;
|
|
158
|
+
out += char === '-' ? '-' : literal(char, true);
|
|
159
|
+
index += 1;
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
};
|
|
163
|
+
/** A quantifier at `index`, with the least and most times it repeats, or null where there is none. */
|
|
164
|
+
const readQuantifier = () => {
|
|
165
|
+
const found = /^(?:([*+?])|\{(\d+)(?:(,)(\d*))?\})(\??)/.exec(pattern.slice(index));
|
|
166
|
+
if (!found)
|
|
167
|
+
return null;
|
|
168
|
+
const lazy = found[5] === '?';
|
|
169
|
+
if (found[1]) {
|
|
170
|
+
index += found[0].length;
|
|
171
|
+
return { text: found[0], min: found[1] === '+' ? 1 : 0, max: found[1] === '?' ? 1 : Infinity, lazy };
|
|
172
|
+
}
|
|
173
|
+
const min = Number(found[2]);
|
|
174
|
+
const max = found[3] ? (found[4] ? Number(found[4]) : Infinity) : min;
|
|
175
|
+
// PCRE2 refuses a count above 65535, and JavaScript takes it; left in place, the `{` is not read as text either.
|
|
176
|
+
if (min > 65535 || (max > 65535 && max !== Infinity))
|
|
177
|
+
return null;
|
|
178
|
+
index += found[0].length;
|
|
179
|
+
return { text: found[0], min, max, lazy };
|
|
180
|
+
};
|
|
181
|
+
/** A group at `index`, which points at its `(`. */
|
|
182
|
+
const readGroup = (context) => {
|
|
183
|
+
if (context.lookaround)
|
|
184
|
+
return null;
|
|
185
|
+
const rest = pattern.slice(index + 1);
|
|
186
|
+
const kind = rest.startsWith('?') ? ['?:', '?=', '?!', '?<=', '?<!'].find((start) => rest.startsWith(start)) : '';
|
|
187
|
+
if (kind === undefined)
|
|
188
|
+
return null;
|
|
189
|
+
const open = `(${kind}`;
|
|
190
|
+
index += open.length;
|
|
191
|
+
const lookbehind = kind === '?<=' || kind === '?<!';
|
|
192
|
+
const lookaround = lookbehind || kind === '?=' || kind === '?!';
|
|
193
|
+
const inner = readAlternatives({ lookaround, lookbehind });
|
|
194
|
+
if (!inner || pattern[index] !== ')')
|
|
195
|
+
return null;
|
|
196
|
+
index += 1;
|
|
197
|
+
return { source: `${open}${inner.source})`, captures: kind === '' || inner.captures, assertion: lookaround, empty: lookaround || inner.empty, chooses: inner.chooses };
|
|
198
|
+
};
|
|
199
|
+
const readAtom = (context) => {
|
|
200
|
+
const char = pattern[index];
|
|
201
|
+
switch (char) {
|
|
202
|
+
case '(': return readGroup(context);
|
|
203
|
+
case '[': {
|
|
204
|
+
const source = readClass();
|
|
205
|
+
return source === null ? null : atomOf(source);
|
|
206
|
+
}
|
|
207
|
+
case '\\': {
|
|
208
|
+
const escaped = pattern[index + 1];
|
|
209
|
+
const source = escape(false);
|
|
210
|
+
if (source === null)
|
|
211
|
+
return null;
|
|
212
|
+
return escaped === 'b' || escaped === 'B' ? assertionOf(source) : atomOf(source);
|
|
213
|
+
}
|
|
214
|
+
case '.':
|
|
215
|
+
index += 1;
|
|
216
|
+
return atomOf('[^\\n]');
|
|
217
|
+
case '^':
|
|
218
|
+
index += 1;
|
|
219
|
+
return assertionOf('^');
|
|
220
|
+
case '$':
|
|
221
|
+
index += 1;
|
|
222
|
+
return assertionOf('(?=\\n?$)');
|
|
223
|
+
// A quantifier with nothing to repeat, or one after another, which makes it possessive.
|
|
224
|
+
case '*':
|
|
225
|
+
case '+':
|
|
226
|
+
case '?':
|
|
227
|
+
return null;
|
|
228
|
+
case '{':
|
|
229
|
+
// PCRE2 10.43 reads `{,n}`, and a count with spaces or tabs inside the braces, as a quantifier, and earlier versions as text.
|
|
230
|
+
if (/^\{[ \t]*(?:\d+[ \t]*(?:,[ \t]*\d*[ \t]*)?\}|,)/.test(pattern.slice(index)))
|
|
231
|
+
return null;
|
|
232
|
+
index += 1;
|
|
233
|
+
return atomOf('\\{');
|
|
234
|
+
default:
|
|
235
|
+
index += 1;
|
|
236
|
+
return atomOf(literal(char, false));
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
/** The branches up to a `)` or the end, whether a group in them captures, whether one of them can match the empty text, and whether they hold a `|` or a quantifier whose count can vary. */
|
|
240
|
+
function readAlternatives(context) {
|
|
241
|
+
let out = '';
|
|
242
|
+
let captures = false;
|
|
243
|
+
let empty = false;
|
|
244
|
+
let branchEmpty = true;
|
|
245
|
+
let chooses = false;
|
|
246
|
+
while (index < pattern.length && pattern[index] !== ')') {
|
|
247
|
+
if (pattern[index] === '|') {
|
|
248
|
+
chooses = true;
|
|
249
|
+
empty ||= branchEmpty;
|
|
250
|
+
branchEmpty = true;
|
|
251
|
+
out += '|';
|
|
252
|
+
index += 1;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const atom = readAtom(context);
|
|
256
|
+
if (!atom)
|
|
257
|
+
return null;
|
|
258
|
+
captures ||= atom.captures;
|
|
259
|
+
chooses ||= atom.chooses;
|
|
260
|
+
const quantifier = readQuantifier();
|
|
261
|
+
branchEmpty &&= atom.empty || (quantifier !== null && quantifier.min === 0);
|
|
262
|
+
if (!quantifier) {
|
|
263
|
+
out += atom.source;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (atom.assertion)
|
|
267
|
+
return null;
|
|
268
|
+
if (context.lookbehind && quantifier.min !== quantifier.max)
|
|
269
|
+
return null;
|
|
270
|
+
chooses ||= quantifier.min !== quantifier.max;
|
|
271
|
+
// JavaScript has no match limit, so a repeat of a group that can split the same text more than one way can run for hours where PCRE2 gives up.
|
|
272
|
+
if (atom.chooses && quantifier.max > 1)
|
|
273
|
+
return null;
|
|
274
|
+
// A quantifier with a minimum of 0 or a maximum above 1 runs differently on a group that captures or can match the empty text:
|
|
275
|
+
// JavaScript clears the inner groups at each pass and refuses a pass that matches the empty text, and PCRE2 does neither.
|
|
276
|
+
// So such a group may repeat at most once, and an optional one is written as a choice with the empty text, which JavaScript
|
|
277
|
+
// tries in the same order as PCRE2: `(X)?` as `(?:(X)|)`, and `(X)??` as `(?:|(X))`.
|
|
278
|
+
const differs = atom.captures || atom.empty;
|
|
279
|
+
if (differs && quantifier.max > 1)
|
|
280
|
+
return null;
|
|
281
|
+
if (differs && quantifier.min === 0 && quantifier.max === 1) {
|
|
282
|
+
out += quantifier.lazy ? `(?:|${atom.source})` : `(?:${atom.source}|)`;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
out += atom.source + quantifier.text;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return { source: out, captures, empty: empty || branchEmpty, chooses };
|
|
289
|
+
}
|
|
290
|
+
const translated = readAlternatives({ lookaround: false, lookbehind: false });
|
|
291
|
+
// A `)` that no group opened stops the reading early.
|
|
292
|
+
if (!translated || index < pattern.length)
|
|
293
|
+
return null;
|
|
294
|
+
return { source: translated.source, ignoreCase };
|
|
295
|
+
}
|
|
296
|
+
const COMPILED = new Map();
|
|
297
|
+
/**
|
|
298
|
+
* A PCRE2 pattern as a JavaScript `RegExp` that matches what QGIS matches, or
|
|
299
|
+
* null where this package cannot translate it, or where the result does not
|
|
300
|
+
* compile. `unicode` is QGIS's `UseUnicodePropertiesOption`: on for the
|
|
301
|
+
* `regexp_` functions, off for `~`. The `RegExp` is shared, so a caller that
|
|
302
|
+
* matches globally makes its own from its `source` and `flags`.
|
|
303
|
+
*/
|
|
304
|
+
export function compileQtRegex(pattern, unicode) {
|
|
305
|
+
const key = `${unicode ? 'u' : 'a'}|${pattern}`;
|
|
306
|
+
if (!COMPILED.has(key)) {
|
|
307
|
+
const translated = translate(pattern, unicode);
|
|
308
|
+
let regex = null;
|
|
309
|
+
if (translated) {
|
|
310
|
+
try {
|
|
311
|
+
regex = new RegExp(translated.source, translated.ignoreCase ? 'ui' : 'u');
|
|
312
|
+
}
|
|
313
|
+
catch {
|
|
314
|
+
regex = null;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
COMPILED.set(key, regex);
|
|
318
|
+
}
|
|
319
|
+
return COMPILED.get(key);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Every match in the text, as `QRegularExpression::globalMatch` finds them
|
|
323
|
+
* (`src/corelib/text/qregularexpression.cpp`, `qt/qtbase@3a00b02`, read
|
|
324
|
+
* 2026-10-27): after an empty match it tries again at the same place for one
|
|
325
|
+
* that is not empty (`PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED`), and only then
|
|
326
|
+
* moves on one character. So `.*?` over `ab` matches the empty text, `a`, the
|
|
327
|
+
* empty text, `b` and the empty text, where JavaScript's `matchAll` skips `a`
|
|
328
|
+
* and `b`. The retry asks that the match not end where it began, with a
|
|
329
|
+
* lookbehind that counts the characters before that place.
|
|
330
|
+
*/
|
|
331
|
+
function* qtGlobalMatches(text, regex) {
|
|
332
|
+
const global = new RegExp(regex.source, `${regex.flags}g`);
|
|
333
|
+
let position = 0;
|
|
334
|
+
let retryAt = -1;
|
|
335
|
+
while (position <= text.length) {
|
|
336
|
+
let match;
|
|
337
|
+
if (retryAt === position) {
|
|
338
|
+
const before = [...text.slice(0, position)].length;
|
|
339
|
+
const notEmpty = new RegExp(`(?:${regex.source})(?<!^[\\s\\S]{${before}})`, `${regex.flags}y`);
|
|
340
|
+
notEmpty.lastIndex = position;
|
|
341
|
+
match = notEmpty.exec(text);
|
|
342
|
+
if (!match) {
|
|
343
|
+
position += text.codePointAt(position) > 0xFFFF ? 2 : 1;
|
|
344
|
+
retryAt = -1;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
global.lastIndex = position;
|
|
350
|
+
match = global.exec(text);
|
|
351
|
+
if (!match)
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
yield match;
|
|
355
|
+
position = match.index + match[0].length;
|
|
356
|
+
retryAt = match[0] === '' ? position : -1;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* `QString::replace` with a pattern (`src/corelib/text/qstring.cpp`,
|
|
361
|
+
* `qt/qtbase@3a00b02`, read 2026-10-26), which `regexp_replace` calls: every
|
|
362
|
+
* match is replaced, and in the replacement `\1` to `\99` stand for that group
|
|
363
|
+
* where the pattern has it, taking a second digit only where the pattern has
|
|
364
|
+
* that many groups. Any other backslash stays as written, and a group that
|
|
365
|
+
* took no part gives nothing.
|
|
366
|
+
*/
|
|
367
|
+
export function replaceQtRegex(text, regex, after) {
|
|
368
|
+
const groups = new RegExp(`${regex.source}|`, regex.flags).exec('').length - 1;
|
|
369
|
+
const references = [];
|
|
370
|
+
for (let at = 0; at < after.length - 1; at++) {
|
|
371
|
+
if (after[at] !== '\\')
|
|
372
|
+
continue;
|
|
373
|
+
let group = Number(after[at + 1]);
|
|
374
|
+
if (!(/\d/.test(after[at + 1]) && group > 0 && group <= groups))
|
|
375
|
+
continue;
|
|
376
|
+
let length = 2;
|
|
377
|
+
const second = after[at + 2];
|
|
378
|
+
if (second !== undefined && /\d/.test(second) && group * 10 + Number(second) <= groups) {
|
|
379
|
+
group = group * 10 + Number(second);
|
|
380
|
+
length = 3;
|
|
381
|
+
}
|
|
382
|
+
references.push({ at, length, group });
|
|
383
|
+
}
|
|
384
|
+
let result = '';
|
|
385
|
+
let lastEnd = 0;
|
|
386
|
+
for (const match of qtGlobalMatches(text, regex)) {
|
|
387
|
+
result += text.slice(lastEnd, match.index);
|
|
388
|
+
let afterEnd = 0;
|
|
389
|
+
for (const { at, length, group } of references) {
|
|
390
|
+
result += after.slice(afterEnd, at) + (match[group] ?? '');
|
|
391
|
+
afterEnd = at + length;
|
|
392
|
+
}
|
|
393
|
+
result += after.slice(afterEnd);
|
|
394
|
+
lastEnd = match.index + match[0].length;
|
|
395
|
+
}
|
|
396
|
+
return result + text.slice(lastEnd);
|
|
397
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a QGIS project file's XML, ready for `parseQgsXml`.
|
|
3
|
+
*
|
|
4
|
+
* A `.qgz` is a zip holding the `.qgs`. Its other entries — the `.qgd` auxiliary
|
|
5
|
+
* data and any files attached to the project — are not read.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readProjectXml(fileName: string, body: Blob | Response): Promise<string>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { strFromU8, unzipSync } from 'fflate';
|
|
2
|
+
import { getLowerCaseExtension } from "../util/fileName.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns a QGIS project file's XML, ready for `parseQgsXml`.
|
|
5
|
+
*
|
|
6
|
+
* A `.qgz` is a zip holding the `.qgs`. Its other entries — the `.qgd` auxiliary
|
|
7
|
+
* data and any files attached to the project — are not read.
|
|
8
|
+
*/
|
|
9
|
+
export async function readProjectXml(fileName, body) {
|
|
10
|
+
if (getLowerCaseExtension(fileName) !== 'qgz')
|
|
11
|
+
return body.text();
|
|
12
|
+
const bytes = new Uint8Array(await body.arrayBuffer());
|
|
13
|
+
let entries;
|
|
14
|
+
try {
|
|
15
|
+
entries = unzipSync(bytes, {
|
|
16
|
+
filter: (entry) => entry.name.toLowerCase().endsWith('.qgs')
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw new Error('The .qgz file is not a valid zip file.', { cause: error });
|
|
21
|
+
}
|
|
22
|
+
const projectEntry = Object.values(entries)[0];
|
|
23
|
+
if (!projectEntry) {
|
|
24
|
+
throw new Error('The .qgz file holds no .qgs project.');
|
|
25
|
+
}
|
|
26
|
+
return strFromU8(projectEntry);
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a copy of the URL with all query parameters stripped except the
|
|
3
|
+
* named `keep` set. Used to derive a clean WFS endpoint from a WMS base
|
|
4
|
+
* URL (we keep MAP because QGIS Server needs it to identify the project).
|
|
5
|
+
*/
|
|
6
|
+
export declare function stripQgisServerQuery(rawUrl: string, keep: string[]): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a copy of the URL with all query parameters stripped except the
|
|
3
|
+
* named `keep` set. Used to derive a clean WFS endpoint from a WMS base
|
|
4
|
+
* URL (we keep MAP because QGIS Server needs it to identify the project).
|
|
5
|
+
*/
|
|
6
|
+
export function stripQgisServerQuery(rawUrl, keep) {
|
|
7
|
+
const url = new URL(rawUrl);
|
|
8
|
+
const keepSet = new Set(keep.map((k) => k.toLowerCase()));
|
|
9
|
+
const drop = [];
|
|
10
|
+
url.searchParams.forEach((_, key) => {
|
|
11
|
+
if (!keepSet.has(key.toLowerCase()))
|
|
12
|
+
drop.push(key);
|
|
13
|
+
});
|
|
14
|
+
for (const key of drop)
|
|
15
|
+
url.searchParams.delete(key);
|
|
16
|
+
return url.toString();
|
|
17
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { StacCatalog, StacCollection } from '../model/Stac.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Pure helpers over a fetched STAC document, used by `StacEndpointAdapter` as
|
|
4
|
+
* it reads and inlines a catalogue. None of them makes a request.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Walks a Catalog and collects every Collection it holds, recursing into
|
|
8
|
+
* nested Catalogs. A Collection at the endpoint root is passed here already
|
|
9
|
+
* wrapped in a synthetic Catalog by the normaliser, and every child linked
|
|
10
|
+
* as a separate document has already been inlined by `inlineChildLinks`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectAllCollections(root: StacCatalog): StacCollection[];
|
|
13
|
+
/**
|
|
14
|
+
* Rewrites a fetched document's asset and link hrefs to absolute addresses,
|
|
15
|
+
* against the URL the document itself came from.
|
|
16
|
+
*
|
|
17
|
+
* A published catalogue gives each Collection its own document and addresses
|
|
18
|
+
* that Collection's files relative to it — `./roads.parquet` beside
|
|
19
|
+
* `collections/roads.json`. Inlining puts the Collection under a Catalog
|
|
20
|
+
* fetched from somewhere else entirely, so the document it was relative *to* is
|
|
21
|
+
* gone by the time anything reads the href. Resolving here, while that URL is
|
|
22
|
+
* still in hand, is what makes every href in the inlined tree fetchable on its
|
|
23
|
+
* own.
|
|
24
|
+
*
|
|
25
|
+
* An href that is already absolute passes through unchanged; one that cannot be
|
|
26
|
+
* resolved at all is left exactly as it stands, so nothing is lost by trying.
|
|
27
|
+
* A tile template's placeholders (`{z}`, `{quadkey}`) are kept as written:
|
|
28
|
+
* `URL` escapes their braces, after which the href no longer reads as a template.
|
|
29
|
+
* A new document is built rather than the fetched one edited, matching the
|
|
30
|
+
* immutable style of `StacEndpointAdapter.ts`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveDocumentHrefs<T extends StacCatalog | StacCollection>(document: T, url: string): T;
|
|
33
|
+
/**
|
|
34
|
+
* The document with a `self` link to the address it was fetched from, where it
|
|
35
|
+
* declares none. Inlining loses that address, and a `latest-version` link on an
|
|
36
|
+
* outdated Collection names its replacement by it (`readCollectionSelfHref`).
|
|
37
|
+
*/
|
|
38
|
+
export declare function withSelfLink<T extends StacCatalog | StacCollection>(document: T, url: string): T;
|
|
39
|
+
/** Shallow-copies a Catalog, along with its own `collections` / `catalogs` arrays, so appending children never mutates the fetched document. */
|
|
40
|
+
export declare function cloneCatalogShallow(catalog: StacCatalog): StacCatalog;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers over a fetched STAC document, used by `StacEndpointAdapter` as
|
|
3
|
+
* it reads and inlines a catalogue. None of them makes a request.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Walks a Catalog and collects every Collection it holds, recursing into
|
|
7
|
+
* nested Catalogs. A Collection at the endpoint root is passed here already
|
|
8
|
+
* wrapped in a synthetic Catalog by the normaliser, and every child linked
|
|
9
|
+
* as a separate document has already been inlined by `inlineChildLinks`.
|
|
10
|
+
*/
|
|
11
|
+
export function collectAllCollections(root) {
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const c of root.collections ?? [])
|
|
14
|
+
out.push(c);
|
|
15
|
+
for (const child of root.catalogs ?? [])
|
|
16
|
+
out.push(...collectAllCollections(child));
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Rewrites a fetched document's asset and link hrefs to absolute addresses,
|
|
21
|
+
* against the URL the document itself came from.
|
|
22
|
+
*
|
|
23
|
+
* A published catalogue gives each Collection its own document and addresses
|
|
24
|
+
* that Collection's files relative to it — `./roads.parquet` beside
|
|
25
|
+
* `collections/roads.json`. Inlining puts the Collection under a Catalog
|
|
26
|
+
* fetched from somewhere else entirely, so the document it was relative *to* is
|
|
27
|
+
* gone by the time anything reads the href. Resolving here, while that URL is
|
|
28
|
+
* still in hand, is what makes every href in the inlined tree fetchable on its
|
|
29
|
+
* own.
|
|
30
|
+
*
|
|
31
|
+
* An href that is already absolute passes through unchanged; one that cannot be
|
|
32
|
+
* resolved at all is left exactly as it stands, so nothing is lost by trying.
|
|
33
|
+
* A tile template's placeholders (`{z}`, `{quadkey}`) are kept as written:
|
|
34
|
+
* `URL` escapes their braces, after which the href no longer reads as a template.
|
|
35
|
+
* A new document is built rather than the fetched one edited, matching the
|
|
36
|
+
* immutable style of `StacEndpointAdapter.ts`.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveDocumentHrefs(document, url) {
|
|
39
|
+
const absolute = (href) => {
|
|
40
|
+
if (!href || href.startsWith('#'))
|
|
41
|
+
return href;
|
|
42
|
+
try {
|
|
43
|
+
return new URL(href, url).toString().replace(/%7B(\w+)%7D/g, '{$1}');
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return href;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// STAC 1.1 allows assets on a Catalog as well as a Collection, and only the
|
|
50
|
+
// Collection type here declares the field.
|
|
51
|
+
const assets = document.assets;
|
|
52
|
+
const catalogs = document.catalogs;
|
|
53
|
+
const collections = document.collections;
|
|
54
|
+
return {
|
|
55
|
+
...document,
|
|
56
|
+
...(document.links ? { links: document.links.map((link) => ({ ...link, href: absolute(link.href) })) } : {}),
|
|
57
|
+
...(assets
|
|
58
|
+
? {
|
|
59
|
+
assets: Object.fromEntries(Object.entries(assets).map(([key, asset]) => [key, { ...asset, href: absolute(asset.href) }]))
|
|
60
|
+
}
|
|
61
|
+
: {}),
|
|
62
|
+
// A document that inlines its children addresses their files relative to
|
|
63
|
+
// itself as well, so the whole subtree resolves against this one URL.
|
|
64
|
+
...(collections ? { collections: collections.map((child) => resolveDocumentHrefs(child, url)) } : {}),
|
|
65
|
+
...(catalogs ? { catalogs: catalogs.map((child) => resolveDocumentHrefs(child, url)) } : {})
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The document with a `self` link to the address it was fetched from, where it
|
|
70
|
+
* declares none. Inlining loses that address, and a `latest-version` link on an
|
|
71
|
+
* outdated Collection names its replacement by it (`readCollectionSelfHref`).
|
|
72
|
+
*/
|
|
73
|
+
export function withSelfLink(document, url) {
|
|
74
|
+
if ((document.links ?? []).some((link) => link.rel === 'self'))
|
|
75
|
+
return document;
|
|
76
|
+
return { ...document, links: [...(document.links ?? []), { rel: 'self', href: url, type: 'application/json' }] };
|
|
77
|
+
}
|
|
78
|
+
/** Shallow-copies a Catalog, along with its own `collections` / `catalogs` arrays, so appending children never mutates the fetched document. */
|
|
79
|
+
export function cloneCatalogShallow(catalog) {
|
|
80
|
+
return {
|
|
81
|
+
...catalog,
|
|
82
|
+
collections: catalog.collections ? [...catalog.collections] : catalog.collections,
|
|
83
|
+
catalogs: catalog.catalogs ? [...catalog.catalogs] : catalog.catalogs
|
|
84
|
+
};
|
|
85
|
+
}
|