@canonical/pragma-cli 0.33.0 → 0.34.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 +7 -7
- package/dist/pragma +0 -0
- package/package.json +18 -15
- package/pragma.conf.ts +664 -0
- package/src/bin.ts +13 -4
- package/src/capabilities/block.parity.test.ts +250 -0
- package/src/capabilities/capabilities/capabilities.render.ts +3 -2
- package/src/capabilities/capabilities/capabilities.verb.ts +31 -13
- package/src/capabilities/capabilities/catalog.ts +18 -10
- package/src/capabilities/capabilities/hints.ts +13 -19
- package/src/capabilities/colophon/collectColophon.ts +34 -19
- package/src/capabilities/colophon/colophon.verb.ts +8 -4
- package/src/capabilities/colophon/types.ts +16 -7
- package/src/capabilities/config/collectConfigShow.test.ts +57 -0
- package/src/capabilities/config/collectConfigShow.ts +41 -4
- package/src/capabilities/config/fields.ts +0 -27
- package/src/capabilities/config/set.verb.ts +7 -3
- package/src/capabilities/config/show.render.test.ts +77 -5
- package/src/capabilities/config/show.render.ts +7 -12
- package/src/capabilities/config/show.verb.ts +4 -3
- package/src/capabilities/config/types.ts +8 -0
- package/src/capabilities/create/byteEquality.test.ts +78 -100
- package/src/capabilities/create/compiledCreate.subprocess.test.ts +52 -15
- package/src/capabilities/create/constants.ts +75 -0
- package/src/capabilities/create/create.mcp.test.ts +2 -2
- package/src/capabilities/create/create.test.ts +162 -15
- package/src/capabilities/create/create.verb.ts +140 -69
- package/src/capabilities/create/index.ts +2 -10
- package/src/capabilities/create/pickGenerator.ts +34 -28
- package/src/capabilities/create/templates.embedded.generated.ts +4 -29
- package/src/capabilities/create/types.ts +10 -6
- package/src/capabilities/{standard/parity.test.ts → distribution.parity.test.ts} +24 -14
- package/src/capabilities/distribution.test.ts +120 -0
- package/src/capabilities/distribution.ts +59 -0
- package/src/capabilities/doctor/checks/checkConfigFile.ts +6 -5
- package/src/capabilities/doctor/checks/checkKeStore.ts +2 -2
- package/src/capabilities/doctor/checks/checkMcpConfigured.ts +7 -6
- package/src/capabilities/doctor/checks/checkPackageRefs.ts +79 -45
- package/src/capabilities/doctor/checks/checkPragmaVersion.ts +3 -2
- package/src/capabilities/doctor/checks/checkShellCompletions.test.ts +61 -11
- package/src/capabilities/doctor/checks/checkShellCompletions.ts +63 -23
- package/src/capabilities/doctor/checks/checkSkillsSymlinked.ts +3 -2
- package/src/capabilities/doctor/doctor.render.test.ts +6 -6
- package/src/capabilities/doctor/doctor.render.ts +2 -1
- package/src/capabilities/doctor/doctor.test.ts +37 -8
- package/src/capabilities/doctor/doctor.verb.ts +6 -2
- package/src/capabilities/doctor/runChecks.ts +5 -5
- package/src/capabilities/doctor/types.ts +1 -1
- package/src/capabilities/emptyRecovery.test.ts +32 -15
- package/src/capabilities/graph/inspect.verb.ts +3 -2
- package/src/capabilities/graph/query.verb.ts +3 -2
- package/src/capabilities/graph/runQuery.ts +8 -5
- package/src/capabilities/index.ts +22 -18
- package/src/capabilities/info/collectInfo.ts +10 -6
- package/src/capabilities/info/info.render.ts +3 -2
- package/src/capabilities/info/info.verb.ts +3 -2
- package/src/capabilities/lazy.test.ts +93 -2
- package/src/capabilities/ontology/verbs.ts +21 -21
- package/src/capabilities/prompt/prompt.test.ts +12 -6
- package/src/capabilities/prompt/verbs.ts +24 -11
- package/src/capabilities/resources/provider.ts +30 -11
- package/src/capabilities/resources/resources.test.ts +85 -29
- package/src/capabilities/setup/operations/setupGenerator.ts +16 -9
- package/src/capabilities/setup/operations/setupMcp.ts +2 -2
- package/src/capabilities/setup/operations/setupSkills.ts +3 -3
- package/src/capabilities/setup/setup.verb.ts +12 -5
- package/src/capabilities/setup/shell.ts +29 -3
- package/src/capabilities/skill/discover.ts +11 -5
- package/src/capabilities/skill/render.ts +4 -5
- package/src/capabilities/skill/verbs.ts +7 -7
- package/src/capabilities/sources/collectStatus.ts +55 -50
- package/src/capabilities/sources/index.ts +1 -1
- package/src/capabilities/sources/installSkills.ts +2 -2
- package/src/capabilities/sources/runUpdate.ts +113 -122
- package/src/capabilities/sources/sources.test.ts +111 -117
- package/src/capabilities/sources/status.render.test.ts +53 -24
- package/src/capabilities/sources/status.render.ts +24 -29
- package/src/capabilities/sources/status.verb.ts +15 -8
- package/src/capabilities/sources/types.ts +18 -25
- package/src/capabilities/sources/update.render.ts +9 -2
- package/src/capabilities/sources/update.verb.ts +12 -23
- package/src/capabilities/surface.test.ts +33 -10
- package/src/capabilities/tier.parity.test.ts +144 -0
- package/src/capabilities/upgrade/upgrade.verb.ts +7 -3
- package/src/constants.test.ts +8 -6
- package/src/constants.ts +47 -21
- package/src/identity.test.ts +333 -0
- package/src/index.ts +2 -2
- package/src/kernel/completion/__snapshots__/emitScripts.test.ts.snap +5 -2
- package/src/kernel/completion/emitScripts.test.ts +1 -1
- package/src/kernel/completion/emitScripts.ts +4 -2
- package/src/kernel/completion/entitySource.test.ts +185 -41
- package/src/kernel/completion/entitySource.ts +117 -107
- package/src/kernel/completion/model.test.ts +1 -1
- package/src/kernel/completion/model.ts +11 -0
- package/src/kernel/completion/safety.test.ts +82 -36
- package/src/kernel/completion/shellDrive.test.ts +592 -0
- package/src/kernel/completion/templates/fish.ts +28 -6
- package/src/kernel/completion/types.ts +3 -3
- package/src/kernel/config/__snapshots__/firstRun.test.ts.snap +1 -1
- package/src/kernel/config/defaults.test.ts +85 -0
- package/src/kernel/config/defaults.ts +12 -23
- package/src/kernel/config/evaluateProjectConfig.ts +2 -3
- package/src/kernel/config/findProjectConfig.ts +4 -3
- package/src/kernel/config/firstRun.ts +12 -5
- package/src/kernel/config/globalConfig.ts +2 -2
- package/src/kernel/config/index.ts +4 -5
- package/src/kernel/config/paths.ts +17 -17
- package/src/kernel/config/readConfig.test.ts +242 -6
- package/src/kernel/config/readConfig.ts +8 -8
- package/src/kernel/config/schema.test.ts +50 -0
- package/src/kernel/config/schema.ts +97 -10
- package/src/kernel/config/types.ts +73 -19
- package/src/kernel/copy.test.ts +453 -0
- package/src/kernel/error/PragmaError.test.ts +1 -1
- package/src/kernel/error/constants.ts +3 -2
- package/src/kernel/error/index.ts +1 -1
- package/src/kernel/error/recovery.test.ts +22 -45
- package/src/kernel/error/recovery.ts +22 -27
- package/src/kernel/error/types.ts +5 -4
- package/src/kernel/packs/collect.test.ts +195 -11
- package/src/kernel/packs/collect.ts +213 -58
- package/src/kernel/packs/compile.test.ts +163 -7
- package/src/kernel/packs/compile.ts +15 -12
- package/src/kernel/packs/disclosure.test.ts +5 -2
- package/src/kernel/packs/graphql/fetchGraphqlLookup.ts +11 -10
- package/src/kernel/packs/graphqlSource.test.ts +6 -3
- package/src/kernel/packs/iri.ts +5 -7
- package/src/kernel/packs/renderPack.ts +5 -3
- package/src/kernel/packs/resolveEntity.ts +21 -17
- package/src/kernel/packs/runBodies.ts +15 -14
- package/src/kernel/packs/schema.ts +96 -10
- package/src/kernel/packs/sparql/runSelect.test.ts +104 -10
- package/src/kernel/packs/sparql/runSelect.ts +73 -34
- package/src/kernel/packs/toolDescription.test.ts +10 -2
- package/src/kernel/packs/types.ts +39 -4
- package/src/kernel/packs/uniqueness.ts +4 -4
- package/src/kernel/project/cli/buildProgram.test.ts +9 -4
- package/src/kernel/project/cli/dispatch.test.ts +67 -0
- package/src/kernel/project/cli/dispatch.ts +34 -12
- package/src/kernel/project/cli/helpFormat.ts +1 -1
- package/src/kernel/project/cli/rootHelp.ts +105 -105
- package/src/kernel/project/mcp/buildServer.ts +11 -6
- package/src/kernel/project/mcp/instructions.ts +11 -6
- package/src/kernel/project/mcp/parity.test.ts +39 -1
- package/src/kernel/project/mcp/prompts/prompts.test.ts +120 -5
- package/src/kernel/project/mcp/prompts/provider.ts +22 -8
- package/src/kernel/project/mcp/prompts/source.ts +68 -67
- package/src/kernel/project/mcp/registerVerb.ts +25 -6
- package/src/kernel/project/mcp/serve.ts +11 -3
- package/src/kernel/project/mcp/toolDescriptions.test.ts +6 -2
- package/src/kernel/render/disclosure.ts +4 -2
- package/src/kernel/render/prefixes.test.ts +36 -0
- package/src/kernel/render/prefixes.ts +40 -13
- package/src/kernel/render/renderers.test.ts +1 -1
- package/src/kernel/runtime/graphpack/build.ts +29 -3
- package/src/kernel/runtime/graphpack/buildIndex.test.ts +46 -0
- package/src/kernel/runtime/graphpack/buildIndex.ts +52 -17
- package/src/kernel/runtime/graphpack/embedded/pack.generated.ts +5 -5
- package/src/kernel/runtime/graphpack/embedded/pack.index.generated.ts +3 -3
- package/src/kernel/runtime/graphpack/embedded/pack.stories.generated.ts +3 -0
- package/src/kernel/runtime/graphpack/embedded.ts +37 -11
- package/src/kernel/runtime/graphpack/graphpack.test.ts +205 -5
- package/src/kernel/runtime/graphpack/hash.ts +3 -2
- package/src/kernel/runtime/graphpack/index.ts +1 -1
- package/src/kernel/runtime/graphpack/manifest.ts +114 -12
- package/src/kernel/runtime/graphpack/read.ts +4 -9
- package/src/kernel/runtime/graphpack/schemas.ts +74 -0
- package/src/kernel/runtime/graphpack/stories.ts +84 -0
- package/src/kernel/runtime/graphpack/types.ts +61 -48
- package/src/kernel/runtime/paths.ts +64 -15
- package/src/kernel/runtime/probe.test.ts +8 -4
- package/src/kernel/runtime/readEntity.ts +6 -5
- package/src/kernel/runtime/refs/gitOps.ts +1 -19
- package/src/kernel/runtime/refs/parseRef.ts +7 -7
- package/src/kernel/runtime/refs/resolve.ts +78 -62
- package/src/kernel/runtime/resolveSources.test.ts +63 -24
- package/src/kernel/runtime/resolveSources.ts +36 -25
- package/src/kernel/runtime/storeReadiness.ts +9 -8
- package/src/kernel/runtime/storeless.test.ts +1 -1
- package/src/kernel/runtime/wasmEmbed.test.ts +22 -19
- package/src/kernel/spec/emitReference.test.ts +3 -3
- package/src/kernel/spec/emitReference.ts +144 -11
- package/src/kernel/spec/emitSurface.ts +9 -5
- package/src/kernel/spec/surfaceConformance.test.ts +2 -2
- package/src/kernel/spec/surfaceConformance.ts +8 -0
- package/src/kernel/spec/types.ts +29 -9
- package/src/kernel/spec/validate.ts +2 -1
- package/src/kernel/vocabulary.test.ts +164 -0
- package/src/kernel/vocabulary.ts +146 -0
- package/src/testing/PARITY_GAPS.ts +8 -2
- package/src/testing/behavioral/README.md +3 -3
- package/src/testing/behavioral/completion.test.ts +19 -6
- package/src/testing/behavioral/errorMatrix.mcp.test.ts +4 -3
- package/src/testing/behavioral/errorMatrix.storeless.test.ts +1 -1
- package/src/testing/behavioral/exitCodes.e2e.test.ts +6 -5
- package/src/testing/behavioral/harness.foundation.test.ts +14 -5
- package/src/testing/behavioral/journeys.cli.test.ts +116 -75
- package/src/testing/behavioral/journeys.defaultPack.test.ts +82 -176
- package/src/testing/behavioral/journeys.firstInstall.test.ts +167 -0
- package/src/testing/behavioral/journeys.mcpLifecycle.mcp.test.ts +9 -6
- package/src/testing/behavioral/journeys.packageStories.test.ts +188 -0
- package/src/testing/behavioral/liveReadSurface.ts +4 -3
- package/src/testing/behavioral/mcpSurface.test.ts +9 -4
- package/src/testing/behavioral/staleCommands.test.ts +10 -0
- package/src/testing/eval/__snapshots__/eval.test.ts.snap +7 -7
- package/src/testing/eval/cases/assembly.ts +13 -6
- package/src/testing/eval/cases/effectful.ts +25 -13
- package/src/testing/eval/cases/readNouns.ts +22 -20
- package/src/testing/eval/cases/stable.ts +5 -1
- package/src/testing/eval/eval.test.ts +7 -1
- package/src/testing/fixtures/fixtureCapability.ts +45 -1
- package/src/testing/fixtures/graph/canonical.ts +6 -3
- package/src/testing/fixtures/graph/defaultPack.ts +6 -5
- package/src/testing/fixtures/graph/owlExport.ts +7 -5
- package/src/testing/helpers/fixtureGraph.ts +33 -16
- package/src/testing/helpers/packRuntime.ts +2 -3
- package/src/testing/helpers/projectCli.ts +2 -1
- package/src/testing/helpers/projectMcp.ts +6 -0
- package/src/testing/perf/budgets.test.ts +4 -0
- package/src/testing/perf/budgets.ts +22 -7
- package/src/testing/perf/globalSetup.ts +121 -6
- package/src/types.ts +2 -2
- package/src/capabilities/block/blockList.test.ts +0 -79
- package/src/capabilities/block/blockList.verb.ts +0 -163
- package/src/capabilities/block/index.ts +0 -25
- package/src/capabilities/block/pack.ts +0 -166
- package/src/capabilities/block/parity.test.ts +0 -187
- package/src/capabilities/block/tierChain.ts +0 -78
- package/src/capabilities/colophon/pragmaColophon.ts +0 -66
- package/src/capabilities/modifier/index.ts +0 -15
- package/src/capabilities/modifier/pack.ts +0 -64
- package/src/capabilities/standard/index.ts +0 -18
- package/src/capabilities/standard/pack.ts +0 -128
- package/src/capabilities/tier/index.ts +0 -19
- package/src/capabilities/tier/lookup.render.test.ts +0 -72
- package/src/capabilities/tier/lookup.render.ts +0 -59
- package/src/capabilities/tier/lookup.test.ts +0 -83
- package/src/capabilities/tier/lookup.verb.ts +0 -44
- package/src/capabilities/tier/pack.ts +0 -28
- package/src/capabilities/tier/runLookup.ts +0 -87
- package/src/capabilities/token/addConfig.render.ts +0 -27
- package/src/capabilities/token/addConfig.test.ts +0 -62
- package/src/capabilities/token/addConfig.verb.ts +0 -40
- package/src/capabilities/token/index.ts +0 -19
- package/src/capabilities/token/pack.ts +0 -58
- package/src/capabilities/token/runAddConfig.ts +0 -95
- package/src/kernel/completion/bashDrive.test.ts +0 -73
- package/src/kernel/runtime/graphpack/embedded/sample.ttl +0 -39
- package/src/kernel/runtime/lock.ts +0 -90
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
MANIFEST_FILE,
|
|
40
40
|
type Manifest,
|
|
41
41
|
SCHEMA_FILE,
|
|
42
|
+
STORIES_FILE,
|
|
42
43
|
} from "./types.js";
|
|
43
44
|
|
|
44
45
|
/** One RDF source to build into a pack. */
|
|
@@ -53,10 +54,17 @@ export interface BuildPackInput {
|
|
|
53
54
|
export interface BuildPackOptions {
|
|
54
55
|
readonly name: string;
|
|
55
56
|
readonly version: string;
|
|
56
|
-
/** The config `
|
|
57
|
+
/** The config `packs` ref (verbatim) or a label. */
|
|
57
58
|
readonly sourceRef: string;
|
|
58
59
|
/** Prefixes the store (and every query) is built with. */
|
|
59
60
|
readonly prefixes?: Readonly<Record<string, string>>;
|
|
61
|
+
/**
|
|
62
|
+
* The `stories/*.json` files the resolved packages ship, as raw text. Hash
|
|
63
|
+
* inputs like any other source — a story-only edit is a new pack, and a set
|
|
64
|
+
* of packages shipping none keeps the hash it had before stories existed, so
|
|
65
|
+
* no cached pack is invalidated by rehashing.
|
|
66
|
+
*/
|
|
67
|
+
readonly stories?: readonly BuildPackInput[];
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
/** The outcome of a pack build (or cache hit). */
|
|
@@ -72,7 +80,8 @@ export interface BuildPackResult {
|
|
|
72
80
|
* Build (or reuse) the pack for a set of source inputs.
|
|
73
81
|
*
|
|
74
82
|
* @param inputs - The RDF sources (path + content).
|
|
75
|
-
* @param options - Provenance
|
|
83
|
+
* @param options - Provenance, the prefixes to build with, and the packages'
|
|
84
|
+
* carried read stories.
|
|
76
85
|
* @returns The pack directory, its content hash, and whether it was reused.
|
|
77
86
|
* @note Impure — creates a store, compiles the schema, writes the pack.
|
|
78
87
|
*/
|
|
@@ -80,8 +89,12 @@ export async function buildPack(
|
|
|
80
89
|
inputs: readonly BuildPackInput[],
|
|
81
90
|
options: BuildPackOptions,
|
|
82
91
|
): Promise<BuildPackResult> {
|
|
92
|
+
const stories = options.stories ?? [];
|
|
83
93
|
const hash = await contentHash(
|
|
84
|
-
inputs.map((input) => ({
|
|
94
|
+
[...inputs, ...stories].map((input) => ({
|
|
95
|
+
path: input.path,
|
|
96
|
+
content: input.content,
|
|
97
|
+
})),
|
|
85
98
|
);
|
|
86
99
|
const dir = packDir(hash);
|
|
87
100
|
|
|
@@ -121,6 +134,19 @@ export async function buildPack(
|
|
|
121
134
|
const index = await buildIndex(store, store.prefixes, hash);
|
|
122
135
|
writeFileSync(join(temp, INDEX_FILE), JSON.stringify(index));
|
|
123
136
|
|
|
137
|
+
// Written UNCONDITIONALLY (`[]` when the packages ship none): the artifact
|
|
138
|
+
// set is FIVE AND ONLY FIVE, and `packIsComplete` gates on it, so a pack
|
|
139
|
+
// whose hash covers stories always holds them.
|
|
140
|
+
writeFileSync(
|
|
141
|
+
join(temp, STORIES_FILE),
|
|
142
|
+
JSON.stringify(
|
|
143
|
+
stories.map((story) => ({
|
|
144
|
+
source: story.path,
|
|
145
|
+
content: story.content,
|
|
146
|
+
})),
|
|
147
|
+
),
|
|
148
|
+
);
|
|
149
|
+
|
|
124
150
|
const tripleCount = await countTriples(store);
|
|
125
151
|
// Distinct abox subjects — the same figure `entityTotal` reports (A10),
|
|
126
152
|
// so `sources status` reads it from the manifest without parsing the
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
OWL_EXPORT_TTL,
|
|
7
7
|
} from "../../../testing/fixtures/graph/owlExport.js";
|
|
8
8
|
import { entityTotal } from "../../completion/entitySource.js";
|
|
9
|
+
import { VOCABULARY } from "../../vocabulary.js";
|
|
9
10
|
import { buildIndex } from "./buildIndex.js";
|
|
10
11
|
import type { PackIndex } from "./types.js";
|
|
11
12
|
|
|
@@ -101,3 +102,48 @@ describe("buildIndex — real-data counters/classifiers (backlog A)", () => {
|
|
|
101
102
|
);
|
|
102
103
|
});
|
|
103
104
|
});
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The alternative-name property is DECLARED by the distribution, so a pack whose
|
|
108
|
+
* prefix map does not bind its prefix is an ordinary case — a third-party pack
|
|
109
|
+
* outside that namespace — not an error. Resolving the term strictly would throw
|
|
110
|
+
* there and take the whole pack build down with it.
|
|
111
|
+
*/
|
|
112
|
+
describe("buildIndex — the declared alternative-name property", () => {
|
|
113
|
+
let store: Store;
|
|
114
|
+
|
|
115
|
+
beforeAll(async () => {
|
|
116
|
+
store = await createStore({
|
|
117
|
+
sources: [{ content: OWL_EXPORT_TTL, path: "owl-export.ttl" }],
|
|
118
|
+
prefixes: OWL_EXPORT_PREFIXES,
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
afterAll(() => {
|
|
123
|
+
store.dispose();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("projects it into altNames when the pack binds its prefix", async () => {
|
|
127
|
+
const index = await buildIndex(store, OWL_EXPORT_PREFIXES, "bound");
|
|
128
|
+
const named = index.entities.filter((entity) => entity.altNames);
|
|
129
|
+
expect(named.length).toBeGreaterThan(0);
|
|
130
|
+
expect(named.at(0)?.altNames?.length).toBeGreaterThan(0);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("still builds, carrying no altNames, when the pack binds no such prefix", async () => {
|
|
134
|
+
// Unbind the prefix the DECLARATION uses, whatever it is — the subject here
|
|
135
|
+
// is the declared property, so naming a prefix would couple this case to
|
|
136
|
+
// today's values and quietly stop testing anything if they moved.
|
|
137
|
+
const declared = VOCABULARY.altName.slice(
|
|
138
|
+
0,
|
|
139
|
+
VOCABULARY.altName.indexOf(":"),
|
|
140
|
+
);
|
|
141
|
+
const { [declared]: _unbound, ...withoutDomain } = OWL_EXPORT_PREFIXES;
|
|
142
|
+
const index = await buildIndex(store, withoutDomain, "unbound");
|
|
143
|
+
// The graph is unchanged, so every entity is still indexed…
|
|
144
|
+
expect(index.entities.length).toBeGreaterThan(0);
|
|
145
|
+
// …they simply carry no alternative names, exactly as a pack that never
|
|
146
|
+
// authored the property would.
|
|
147
|
+
expect(index.entities.filter((entity) => entity.altNames)).toEqual([]);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Build the storeless entity index (`index.json`) from a populated store.
|
|
3
3
|
*
|
|
4
|
-
* A lean port of the v1 `buildGraphIndex` (#856):
|
|
5
|
-
* types
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* A lean port of the v1 `buildGraphIndex` (#856): a few bulk SPARQL queries —
|
|
5
|
+
* types (which also yield the instance counts), labels, descriptions and
|
|
6
|
+
* alternative names — joined in memory, rather than a query per subject. Only
|
|
7
|
+
* the last names a DOMAIN property, and it is read from the distribution's
|
|
8
|
+
* declaration rather than spelled out here; see {@link resolveAltNamePredicate} for
|
|
9
|
+
* the pack that binds no such prefix.
|
|
10
|
+
*
|
|
11
|
+
* Only typed named-node subjects are indexed (untyped subjects and blank-node
|
|
12
|
+
* subjects are reachable via `graph query` but never listed). Each entity
|
|
13
|
+
* carries the FROZEN `{ name, type }` minimum plus the enrichment fields
|
|
9
14
|
* (`uri`, `prefixed`, `types`, `label`, `box`) the completion tier and reads
|
|
10
15
|
* use. The output is pure JSON — no store handle survives — so the completion
|
|
11
16
|
* tier reads it without ever booting oxigraph.
|
|
@@ -25,6 +30,7 @@
|
|
|
25
30
|
*/
|
|
26
31
|
|
|
27
32
|
import { compactUri } from "../../render/compactUri.js";
|
|
33
|
+
import { VOCABULARY } from "../../vocabulary.js";
|
|
28
34
|
import type { PackIndex, PackIndexEntity } from "./types.js";
|
|
29
35
|
|
|
30
36
|
type Store = import("@canonical/ke").Store;
|
|
@@ -75,14 +81,6 @@ const DESCRIPTION_PREDICATES = [
|
|
|
75
81
|
"http://schema.org/description",
|
|
76
82
|
];
|
|
77
83
|
|
|
78
|
-
/**
|
|
79
|
-
* Alternative-name predicates: `ds:name`, the property `tier lookup` (and other
|
|
80
|
-
* `ds:name`-addressed families) match on. Projected into `altNames` so the
|
|
81
|
-
* storeless name-completion sources can offer those tokens exactly, without a
|
|
82
|
-
* store boot. Distinct from the display `label` — a subject may carry both.
|
|
83
|
-
*/
|
|
84
|
-
const ALT_NAME_PREDICATES = ["https://ds.canonical.com/name"];
|
|
85
|
-
|
|
86
84
|
const isStdVocab = (uri: string): boolean =>
|
|
87
85
|
STD_VOCAB_PREFIXES.some((ns) => uri.startsWith(ns));
|
|
88
86
|
|
|
@@ -141,6 +139,37 @@ function classify(fullTypes: readonly string[]): Facet[] {
|
|
|
141
139
|
const valuesList = (uris: readonly string[]): string =>
|
|
142
140
|
uris.map((uri) => `<${uri}>`).join(" ");
|
|
143
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Expand the declared alternative-name property against a pack's prefix map.
|
|
144
|
+
*
|
|
145
|
+
* That property is what a family is addressed by, so the storeless completion
|
|
146
|
+
* sources can offer those tokens exactly and a bespoke lookup can match them,
|
|
147
|
+
* without a store boot. Distinct from the display `label`: a subject may carry
|
|
148
|
+
* both.
|
|
149
|
+
*
|
|
150
|
+
* The distribution DECLARES it as a prefixed name; this resolves it against the
|
|
151
|
+
* PACK's own prefixes, which are not the distribution's. A pack that binds no
|
|
152
|
+
* such prefix simply carries no alternative names — the normal case for a
|
|
153
|
+
* third-party pack outside the distribution's namespace. Expanding through
|
|
154
|
+
* `packs/iri.ts` instead would THROW on exactly that pack and take its whole
|
|
155
|
+
* build down, so this degrades and the caller skips the query.
|
|
156
|
+
*
|
|
157
|
+
* The split needs no guard: `kernel/vocabulary.ts` has already held the term to
|
|
158
|
+
* `prefix:local`, so the colon is there and both sides are non-empty.
|
|
159
|
+
*
|
|
160
|
+
* @param prefixes - The store's merged prefix map.
|
|
161
|
+
* @returns The full IRI to collect, or `undefined` when the prefix is unbound.
|
|
162
|
+
*/
|
|
163
|
+
function resolveAltNamePredicate(
|
|
164
|
+
prefixes: Readonly<Record<string, string>>,
|
|
165
|
+
): string | undefined {
|
|
166
|
+
const colon = VOCABULARY.altName.indexOf(":");
|
|
167
|
+
const namespace = prefixes[VOCABULARY.altName.slice(0, colon)];
|
|
168
|
+
return namespace === undefined
|
|
169
|
+
? undefined
|
|
170
|
+
: `${namespace}${VOCABULARY.altName.slice(colon + 1)}`;
|
|
171
|
+
}
|
|
172
|
+
|
|
144
173
|
/** Language rank for label selection: untagged (0) < `@en` (1) < any other (2). */
|
|
145
174
|
function rankLanguage(language: string): number {
|
|
146
175
|
if (language === "") return 0;
|
|
@@ -230,6 +259,7 @@ export async function buildIndex(
|
|
|
230
259
|
prefixes: Readonly<Record<string, string>>,
|
|
231
260
|
contentHash: string,
|
|
232
261
|
): Promise<PackIndex> {
|
|
262
|
+
const altNameUri = resolveAltNamePredicate(prefixes);
|
|
233
263
|
const [typesResult, labelResult, descResult, altNameResult] =
|
|
234
264
|
await Promise.all([
|
|
235
265
|
store.query(
|
|
@@ -241,9 +271,11 @@ export async function buildIndex(
|
|
|
241
271
|
store.query(
|
|
242
272
|
`SELECT ?s ?p ?desc WHERE { ?s ?p ?desc . VALUES ?p { ${valuesList(DESCRIPTION_PREDICATES)} } }` as never,
|
|
243
273
|
) as Promise<import("@canonical/ke").SelectResult>,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
274
|
+
altNameUri === undefined
|
|
275
|
+
? undefined
|
|
276
|
+
: (store.query(
|
|
277
|
+
`SELECT ?s ?p ?alt WHERE { ?s ?p ?alt . VALUES ?p { <${altNameUri}> } }` as never,
|
|
278
|
+
) as Promise<import("@canonical/ke").SelectResult>),
|
|
247
279
|
]);
|
|
248
280
|
|
|
249
281
|
const typesBySubject = new Map<string, string[]>();
|
|
@@ -273,7 +305,10 @@ export async function buildIndex(
|
|
|
273
305
|
"desc",
|
|
274
306
|
DESCRIPTION_PREDICATES,
|
|
275
307
|
);
|
|
276
|
-
const altNamesBySubject =
|
|
308
|
+
const altNamesBySubject =
|
|
309
|
+
altNameResult === undefined
|
|
310
|
+
? new Map<string, string[]>()
|
|
311
|
+
: allBySubject(altNameResult, "alt");
|
|
277
312
|
|
|
278
313
|
const entities: PackIndexEntity[] = [];
|
|
279
314
|
for (const [subject, fullTypes] of typesBySubject) {
|