@seed-hypermedia/client 0.0.124 → 0.0.125
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/dist/explore-query.mjs +27 -9
- package/package.json +1 -1
package/dist/explore-query.mjs
CHANGED
|
@@ -130,7 +130,10 @@ function parseScalar(value) {
|
|
|
130
130
|
return value;
|
|
131
131
|
}
|
|
132
132
|
function quoteExploreValue(value) {
|
|
133
|
-
return /[\s()"=<>~^]/.test(value) ? `"${value.replace(/"/g, '\\"')}"` : value;
|
|
133
|
+
return value === "" || /[\s()"=<>~^]/.test(value) || typeof parseScalar(value) !== "string" ? `"${value.replace(/"/g, '\\"')}"` : value;
|
|
134
|
+
}
|
|
135
|
+
function quoteExploreKey(key) {
|
|
136
|
+
return /[\s()"=<>~^:!]/.test(key) ? `"${key.replace(/"/g, '\\"')}"` : key;
|
|
134
137
|
}
|
|
135
138
|
function flatten(kind, children) {
|
|
136
139
|
const flattened = children.flatMap((child) => child.kind === kind ? child.children : [child]);
|
|
@@ -206,7 +209,7 @@ var ExploreParser = class {
|
|
|
206
209
|
return this.parsePrimary();
|
|
207
210
|
}
|
|
208
211
|
parsePrimary() {
|
|
209
|
-
var _a;
|
|
212
|
+
var _a, _b;
|
|
210
213
|
const token = this.current();
|
|
211
214
|
if (!token) return null;
|
|
212
215
|
if (token.kind === "lparen") {
|
|
@@ -222,7 +225,8 @@ var ExploreParser = class {
|
|
|
222
225
|
return null;
|
|
223
226
|
}
|
|
224
227
|
this.index++;
|
|
225
|
-
if (token.kind === "quoted")
|
|
228
|
+
if (token.kind === "quoted" && ((_b = this.current()) == null ? void 0 : _b.kind) !== "operator")
|
|
229
|
+
return { kind: "text", value: token.value, phrase: true };
|
|
226
230
|
const operator = this.current();
|
|
227
231
|
if ((operator == null ? void 0 : operator.kind) !== "operator") return { kind: "text", value: token.value, phrase: false };
|
|
228
232
|
this.index++;
|
|
@@ -271,7 +275,19 @@ var ExploreParser = class {
|
|
|
271
275
|
);
|
|
272
276
|
return { kind: "text", value: `${token.value}${operator.value}${value}`, phrase: false };
|
|
273
277
|
}
|
|
274
|
-
if (
|
|
278
|
+
if (token.kind === "word" && token.value === "empty" && operator.value === ":") {
|
|
279
|
+
return {
|
|
280
|
+
kind: "or",
|
|
281
|
+
children: [
|
|
282
|
+
{ kind: "predicate", predicate: { kind: "attribute", key: value, operator: "missing" } },
|
|
283
|
+
{
|
|
284
|
+
kind: "predicate",
|
|
285
|
+
predicate: { kind: "attribute", key: value, operator: "comparison", comparison: "=", value: "" }
|
|
286
|
+
}
|
|
287
|
+
]
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
if (token.kind === "word" && (token.value === "has" || token.value === "missing") && operator.value === ":") {
|
|
275
291
|
return {
|
|
276
292
|
kind: "predicate",
|
|
277
293
|
predicate: { kind: "attribute", key: value, operator: token.value === "has" ? "exists" : "missing" }
|
|
@@ -296,7 +312,8 @@ var ExploreParser = class {
|
|
|
296
312
|
key: token.value,
|
|
297
313
|
operator: "comparison",
|
|
298
314
|
comparison: operator.value,
|
|
299
|
-
value:
|
|
315
|
+
// A quoted value is a string even when it looks like a number: `version="3"`.
|
|
316
|
+
value: valueToken.kind === "quoted" ? value : parseScalar(value)
|
|
300
317
|
}
|
|
301
318
|
};
|
|
302
319
|
}
|
|
@@ -324,11 +341,12 @@ function serializePredicate(predicate) {
|
|
|
324
341
|
return `path:${pathPredicate.value}${pathPredicate.prefix ? "/*" : ""}`;
|
|
325
342
|
}
|
|
326
343
|
if (predicate.operator === "exists" || predicate.operator === "missing")
|
|
327
|
-
return `${predicate.operator === "exists" ? "has" : "missing"}:${predicate.key}`;
|
|
328
|
-
if (predicate.operator === "contains")
|
|
329
|
-
|
|
344
|
+
return `${predicate.operator === "exists" ? "has" : "missing"}:${quoteExploreKey(predicate.key)}`;
|
|
345
|
+
if (predicate.operator === "contains")
|
|
346
|
+
return `${quoteExploreKey(predicate.key)}:${quoteExploreValue(predicate.value)}`;
|
|
347
|
+
if (predicate.operator === "prefix") return `${quoteExploreKey(predicate.key)}^${quoteExploreValue(predicate.value)}`;
|
|
330
348
|
const comparison = predicate;
|
|
331
|
-
return `${comparison.key}${comparison.comparison}${typeof comparison.value === "string" ? quoteExploreValue(comparison.value) : String(comparison.value)}`;
|
|
349
|
+
return `${quoteExploreKey(comparison.key)}${comparison.comparison}${typeof comparison.value === "string" ? quoteExploreValue(comparison.value) : String(comparison.value)}`;
|
|
332
350
|
}
|
|
333
351
|
function serializeNode(node, parentPrecedence = 0) {
|
|
334
352
|
let value;
|