@lde/search 0.7.1 → 0.8.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/dist/physical-name.d.ts +11 -2
- package/dist/physical-name.d.ts.map +1 -1
- package/dist/physical-name.js +33 -5
- package/package.json +1 -1
package/dist/physical-name.d.ts
CHANGED
|
@@ -24,8 +24,17 @@ import type { SearchType } from './schema.js';
|
|
|
24
24
|
* rules produce (`serieses`, `analysises`). An already-plural name is
|
|
25
25
|
* idempotent (`People` → `people`).
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* **Throws rather than name the wrong container.** Dropping what it cannot
|
|
28
|
+
* match is what lets `creative_work` tokenize like `CreativeWork`, but it would
|
|
29
|
+
* just as quietly turn `Café` into `['cafs']` and `Musée` into `['mus', 'es']`
|
|
30
|
+
* – a perfectly legal name for a container nobody meant. So a name is spellable
|
|
31
|
+
* only when it is ASCII words and word separators, and only when it leaves at
|
|
32
|
+
* least one word to name anything after; anything else throws here. This guard
|
|
33
|
+
* lives with the split it protects, not in each adapter: an adapter cannot
|
|
34
|
+
* derive a name without going through this function, so it cannot forget to
|
|
35
|
+
* check – and `SearchType.name` is otherwise unvalidated
|
|
36
|
+
* ({@link validateSearchType} rules on field names only). A deployment whose
|
|
37
|
+
* type name this cannot spell passes its adapter an explicit name instead.
|
|
29
38
|
*/
|
|
30
39
|
export declare function physicalNameTokens(searchType: SearchType): readonly string[];
|
|
31
40
|
//# sourceMappingURL=physical-name.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physical-name.d.ts","sourceRoot":"","sources":["../src/physical-name.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C
|
|
1
|
+
{"version":3,"file":"physical-name.d.ts","sourceRoot":"","sources":["../src/physical-name.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE,CAiB5E"}
|
package/dist/physical-name.js
CHANGED
|
@@ -24,15 +24,43 @@ import { pluralize } from 'inflection';
|
|
|
24
24
|
* rules produce (`serieses`, `analysises`). An already-plural name is
|
|
25
25
|
* idempotent (`People` → `people`).
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
27
|
+
* **Throws rather than name the wrong container.** Dropping what it cannot
|
|
28
|
+
* match is what lets `creative_work` tokenize like `CreativeWork`, but it would
|
|
29
|
+
* just as quietly turn `Café` into `['cafs']` and `Musée` into `['mus', 'es']`
|
|
30
|
+
* – a perfectly legal name for a container nobody meant. So a name is spellable
|
|
31
|
+
* only when it is ASCII words and word separators, and only when it leaves at
|
|
32
|
+
* least one word to name anything after; anything else throws here. This guard
|
|
33
|
+
* lives with the split it protects, not in each adapter: an adapter cannot
|
|
34
|
+
* derive a name without going through this function, so it cannot forget to
|
|
35
|
+
* check – and `SearchType.name` is otherwise unvalidated
|
|
36
|
+
* ({@link validateSearchType} rules on field names only). A deployment whose
|
|
37
|
+
* type name this cannot spell passes its adapter an explicit name instead.
|
|
29
38
|
*/
|
|
30
39
|
export function physicalNameTokens(searchType) {
|
|
31
|
-
const
|
|
32
|
-
|
|
40
|
+
const { name } = searchType;
|
|
41
|
+
if (!SPELLABLE_NAME.test(name)) {
|
|
42
|
+
throw new Error(`Cannot name search type “${name}”: a physical name is derived from the type’s name, and this one carries characters outside ASCII words and word separators – deriving would silently drop them and name the wrong container. Rename the type, or give the adapter an explicit name.`);
|
|
43
|
+
}
|
|
44
|
+
const tokens = (name.match(NAME_WORD_PATTERN) ?? []).map((word) => word.toLowerCase());
|
|
33
45
|
const last = tokens.at(-1);
|
|
34
|
-
|
|
46
|
+
if (last === undefined) {
|
|
47
|
+
throw new Error(`Cannot name search type “${name}”: its name carries no word to name a container after. Rename the type, or give the adapter an explicit name.`);
|
|
48
|
+
}
|
|
49
|
+
return [...tokens.slice(0, -1), pluralize(last)];
|
|
35
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A name the split can spell without losing part of it: ASCII letters and
|
|
53
|
+
* digits, plus the separators a name may already be written with (`creative
|
|
54
|
+
* work`, `creative_work`, `creative-work` all tokenize like `CreativeWork`).
|
|
55
|
+
* Deliberately narrower than what {@link NAME_WORD_PATTERN} would tolerate –
|
|
56
|
+
* that one skips anything it does not match, which is precisely the silent
|
|
57
|
+
* mangling this rejects.
|
|
58
|
+
*
|
|
59
|
+
* Matches the empty name too, on purpose: nothing about it is *unspellable*,
|
|
60
|
+
* there is simply nothing to spell, which the no-word check below reports far
|
|
61
|
+
* better than a complaint about characters it does not carry.
|
|
62
|
+
*/
|
|
63
|
+
const SPELLABLE_NAME = /^[A-Za-z0-9 _-]*$/;
|
|
36
64
|
/**
|
|
37
65
|
* One word of a PascalCase/camelCase name, in precedence order: a run of
|
|
38
66
|
* capitals not followed by a lowercase letter (an acronym – `DCAT` in
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/search",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Engine- and domain-agnostic core for RDF-backed search: a unified declarative field model (SearchField/SearchType/SearchSchema), a neutral query IR, the SearchEngine port with logical result types, and a streaming CONSTRUCT-to-document projection. Bakes in no engine, protocol, or domain.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/ldelements/lde.git",
|