@spotto/semantic-query 1.0.70-alpha.38 → 1.0.70-alpha.40

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.
@@ -1,91 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveName = void 0;
4
- /**
5
- * Resolve a NAME to the ids it means — the one place a human word becomes a
6
- * record reference.
7
- *
8
- * The ladder is exact → case-insensitive → unique partial, and it is
9
- * deliberately conservative at every rung:
10
- *
11
- * - An EXACT match wins outright, even if partials also exist. "Bob" must not
12
- * become ambiguous just because "Bobby" is also on staff.
13
- * - Several records sharing one exact name resolve to ALL of them. Two people
14
- * genuinely called "Sam Lee" is a data fact, not a question to ask; both are
15
- * matched and the answer covers the name as asked.
16
- * - A partial match is accepted ONLY when it is unique. "Bri" matching both
17
- * "Brian" and "Brisbane Bob" is refused, with both named, because picking
18
- * one would answer a different question and look exactly like an answer.
19
- * - No match is refused with the nearest candidates offered.
20
- *
21
- * The failure modes are what make this safe to expose to a model. A regex
22
- * fallback — which is what the prototype did for assets — would match whatever
23
- * it happened to match, silently.
24
- */
25
- /**
26
- * How many candidates an ambiguity message names. Enough to disambiguate a
27
- * genuine near-miss, few enough that the error is not a directory listing.
28
- */
29
- const AMBIGUITY_EXAMPLES = 3;
30
- /** Up to three nearest candidates by simple containment, for a suggestion. */
31
- function nearest(catalogue, want) {
32
- const needle = want.trim().toLowerCase();
33
- if (!needle)
34
- return undefined;
35
- const hits = catalogue
36
- .filter((r) => {
37
- const n = r.name.toLowerCase();
38
- return n.includes(needle.slice(0, 3)) || needle.includes(n.slice(0, 3));
39
- })
40
- .slice(0, 3)
41
- .map((r) => { var _a; return (_a = r.label) !== null && _a !== void 0 ? _a : r.name; });
42
- return hits.length ? `Did you mean: ${hits.join(', ')}?` : undefined;
43
- }
44
- function resolveName(catalogue, rawName, opts) {
45
- const want = typeof rawName === 'string' ? rawName.trim() : '';
46
- if (!want) {
47
- return {
48
- ids: [],
49
- issue: {
50
- code: 'BAD_SHAPE',
51
- path: opts.path,
52
- message: `${opts.noun} needs a name`,
53
- },
54
- };
55
- }
56
- const all = catalogue !== null && catalogue !== void 0 ? catalogue : [];
57
- const lower = want.toLowerCase();
58
- const exact = all.filter((r) => r.name.toLowerCase() === lower);
59
- const partial = all.filter((r) => r.name.toLowerCase().includes(lower));
60
- // Exact wins outright — a longer name that merely CONTAINS this one must not
61
- // make an exact match ambiguous.
62
- const hit = exact.length ? exact : partial;
63
- if (!hit.length) {
64
- return {
65
- ids: [],
66
- issue: Object.assign({ code: 'UNKNOWN_NAME', path: opts.path, message: `No ${opts.noun} called '${want}' in this organisation` }, (nearest(all, want) ? { suggestion: nearest(all, want) } : {})),
67
- };
68
- }
69
- if (!exact.length && partial.length > 1) {
70
- // NAMED, NOT ENUMERATED. Listing every match turns this message into a
71
- // directory: the catalogue is org-scoped but not user-group scoped, and
72
- // these endpoints are gated on `assets:view` rather than `users:view` — so
73
- // an unbounded list let a confined field worker recover the whole staff
74
- // roster one letter at a time. A handful of examples is what makes the
75
- // error actionable; the rest is only useful to someone fishing.
76
- const shown = partial.slice(0, AMBIGUITY_EXAMPLES).map((r) => { var _a; return (_a = r.label) !== null && _a !== void 0 ? _a : r.name; });
77
- const rest = partial.length - shown.length;
78
- return {
79
- ids: [],
80
- issue: {
81
- code: 'AMBIGUOUS_NAME',
82
- path: opts.path,
83
- message: `'${want}' matches ${partial.length} ${opts.noun}s ` +
84
- `(${shown.join(', ')}${rest > 0 ? `, and ${rest} more` : ''}) — be more specific`,
85
- },
86
- };
87
- }
88
- return { ids: [...new Set(hit.map((r) => r.id))] };
89
- }
90
- exports.resolveName = resolveName;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveName = void 0;
4
+ /**
5
+ * Resolve a NAME to the ids it means — the one place a human word becomes a
6
+ * record reference.
7
+ *
8
+ * The ladder is exact → case-insensitive → unique partial, and it is
9
+ * deliberately conservative at every rung:
10
+ *
11
+ * - An EXACT match wins outright, even if partials also exist. "Bob" must not
12
+ * become ambiguous just because "Bobby" is also on staff.
13
+ * - Several records sharing one exact name resolve to ALL of them. Two people
14
+ * genuinely called "Sam Lee" is a data fact, not a question to ask; both are
15
+ * matched and the answer covers the name as asked.
16
+ * - A partial match is accepted ONLY when it is unique. "Bri" matching both
17
+ * "Brian" and "Brisbane Bob" is refused, with both named, because picking
18
+ * one would answer a different question and look exactly like an answer.
19
+ * - No match is refused with the nearest candidates offered.
20
+ *
21
+ * The failure modes are what make this safe to expose to a model. A regex
22
+ * fallback — which is what the prototype did for assets — would match whatever
23
+ * it happened to match, silently.
24
+ */
25
+ /**
26
+ * How many candidates an ambiguity message names. Enough to disambiguate a
27
+ * genuine near-miss, few enough that the error is not a directory listing.
28
+ */
29
+ const AMBIGUITY_EXAMPLES = 3;
30
+ /** Up to three nearest candidates by simple containment, for a suggestion. */
31
+ function nearest(catalogue, want) {
32
+ const needle = want.trim().toLowerCase();
33
+ if (!needle)
34
+ return undefined;
35
+ const hits = catalogue
36
+ .filter((r) => {
37
+ const n = r.name.toLowerCase();
38
+ return n.includes(needle.slice(0, 3)) || needle.includes(n.slice(0, 3));
39
+ })
40
+ .slice(0, 3)
41
+ .map((r) => { var _a; return (_a = r.label) !== null && _a !== void 0 ? _a : r.name; });
42
+ return hits.length ? `Did you mean: ${hits.join(', ')}?` : undefined;
43
+ }
44
+ function resolveName(catalogue, rawName, opts) {
45
+ const want = typeof rawName === 'string' ? rawName.trim() : '';
46
+ if (!want) {
47
+ return {
48
+ ids: [],
49
+ issue: {
50
+ code: 'BAD_SHAPE',
51
+ path: opts.path,
52
+ message: `${opts.noun} needs a name`,
53
+ },
54
+ };
55
+ }
56
+ const all = catalogue !== null && catalogue !== void 0 ? catalogue : [];
57
+ const lower = want.toLowerCase();
58
+ const exact = all.filter((r) => r.name.toLowerCase() === lower);
59
+ const partial = all.filter((r) => r.name.toLowerCase().includes(lower));
60
+ // Exact wins outright — a longer name that merely CONTAINS this one must not
61
+ // make an exact match ambiguous.
62
+ const hit = exact.length ? exact : partial;
63
+ if (!hit.length) {
64
+ return {
65
+ ids: [],
66
+ issue: Object.assign({ code: 'UNKNOWN_NAME', path: opts.path, message: `No ${opts.noun} called '${want}' in this organisation` }, (nearest(all, want) ? { suggestion: nearest(all, want) } : {})),
67
+ };
68
+ }
69
+ if (!exact.length && partial.length > 1) {
70
+ // NAMED, NOT ENUMERATED. Listing every match turns this message into a
71
+ // directory: the catalogue is org-scoped but not user-group scoped, and
72
+ // these endpoints are gated on `assets:view` rather than `users:view` — so
73
+ // an unbounded list let a confined field worker recover the whole staff
74
+ // roster one letter at a time. A handful of examples is what makes the
75
+ // error actionable; the rest is only useful to someone fishing.
76
+ const shown = partial.slice(0, AMBIGUITY_EXAMPLES).map((r) => { var _a; return (_a = r.label) !== null && _a !== void 0 ? _a : r.name; });
77
+ const rest = partial.length - shown.length;
78
+ return {
79
+ ids: [],
80
+ issue: {
81
+ code: 'AMBIGUOUS_NAME',
82
+ path: opts.path,
83
+ message: `'${want}' matches ${partial.length} ${opts.noun}s ` +
84
+ `(${shown.join(', ')}${rest > 0 ? `, and ${rest} more` : ''}) — be more specific`,
85
+ },
86
+ };
87
+ }
88
+ return { ids: [...new Set(hit.map((r) => r.id))] };
89
+ }
90
+ exports.resolveName = resolveName;
91
91
  //# sourceMappingURL=resolve-name.js.map