@canonical/design-system 0.2.1 → 0.2.3
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/bun.lock +1 -0
- package/data/concept/Foundations-Grid.ttl +9 -0
- package/data/concept/How-to-differentiate-components-variantsinheritance.ttl +9 -0
- package/data/concept/Indicating-required-fields-in-forms.ttl +9 -0
- package/data/concept/Question-mark-vs-information-icon.ttl +9 -0
- package/data/concepttype/Decision-guide.ttl +5 -0
- package/data/concepttype/Explanation.ttl +5 -0
- package/data/concepttype/How-to-guide.ttl +5 -0
- package/data/concepttype/Mental-model.ttl +5 -0
- package/data/concepttype/Reference.ttl +5 -0
- package/data/concepttype/Tutorial.ttl +5 -0
- package/definitions/ontology.ttl +35 -0
- package/package.json +2 -1
- package/skills/adoption-a1-styles/SKILL.md +54 -1
- package/skills/adoption-a2-components/SKILL.md +48 -1
- package/skills/adoption-a3-forms/SKILL.md +48 -1
- package/skills/anatomy-author/SKILL.md +41 -1
- package/skills/design-auditor/SKILL.md +41 -1
- package/skills/implement-component/SKILL.md +28 -1
- package/skills/specify-component/SKILL.md +38 -1
- package/skills/specify-pattern/SKILL.md +40 -1
- package/source.json +36 -1
- package/src/collect/generateTurtle.tests.ts +148 -0
- package/src/collect/generateTurtle.ts +71 -22
- package/src/collect/types.ts +20 -0
- package/src/config/source.schema.json +27 -0
- package/src/config/types.ts +25 -0
- package/src/transform/rowFilter.tests.ts +100 -0
- package/src/transform/rowFilter.ts +55 -0
- package/src/transform/transform.ts +7 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: specify-component
|
|
3
|
-
description: Specify a new design-system component with the knowledge graph, from graph search to a sync-safe spec file
|
|
3
|
+
description: Specify a new design-system component with the knowledge graph, from graph search to a sync-safe spec file; also runs as a guided tutorial on a worked example
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Specify Component
|
|
@@ -55,6 +55,43 @@ Decision gates — in collaboration, pause at each and resolve it WITH the perso
|
|
|
55
55
|
- Specifying a pattern (a recurring arrangement of components) — use `specify-pattern`
|
|
56
56
|
- Writing only the anatomy for an existing block — use `anatomy-author`
|
|
57
57
|
|
|
58
|
+
## Opening move: ask, or offer the tutorial
|
|
59
|
+
|
|
60
|
+
Activation is an opening, not a starting gun. Unless the first message already names
|
|
61
|
+
the work, ask for the starting point — as a suggestion carrying an example, not as a
|
|
62
|
+
form to fill in:
|
|
63
|
+
|
|
64
|
+
> To get started, tell me the component you'd like to work on — a name if it has one,
|
|
65
|
+
> or just the idea, like "it should let someone pick a date".
|
|
66
|
+
|
|
67
|
+
Rough is fine, and often better: step 1 turns an idea into a graph search, and the
|
|
68
|
+
search regularly renames the thing. Ask again only for what the next step genuinely
|
|
69
|
+
blocks on.
|
|
70
|
+
|
|
71
|
+
If the activation message already carries the starting point, do not re-ask — say what
|
|
72
|
+
you took it to be, and go.
|
|
73
|
+
|
|
74
|
+
Offer the tutorial in the same breath, because this skill doubles as one:
|
|
75
|
+
|
|
76
|
+
> Or if you'd rather see the flow first, I can run it as a tutorial: I'll take a
|
|
77
|
+
> plausible example — a date picker, say — and walk you through the eight steps on it.
|
|
78
|
+
|
|
79
|
+
Tutorial mode runs the real flow on the example, narrated: name each step before
|
|
80
|
+
running it, show what came back and what it means, and reason each decision gate out
|
|
81
|
+
loud before checking the person is with you. Stop short of anything that lands — no
|
|
82
|
+
spec file written, no proposal filed — unless they ask to keep what you built.
|
|
83
|
+
|
|
84
|
+
## The spec falls under standards too
|
|
85
|
+
|
|
86
|
+
A spec is Turtle, and Turtle has standards — the `turtle` category, with `ui-blocks`
|
|
87
|
+
governing how blocks are modelled (take the actual set from
|
|
88
|
+
`pragma standard categories`, not from this list). Pull them before writing and hold
|
|
89
|
+
the Do/Don't pairs open; a spec that contradicts a pulled standard carries a DECLARED
|
|
90
|
+
deviation in the proposal, ideally also filed as an issue. The standards apply
|
|
91
|
+
independent of any package dependency and are open to contribution: a missing or
|
|
92
|
+
wrong modelling rule is something to propose a change for, not to silently work
|
|
93
|
+
around.
|
|
94
|
+
|
|
58
95
|
## The eight steps
|
|
59
96
|
|
|
60
97
|
### 1. Search the graph
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: specify-pattern
|
|
3
|
-
description: Specify a new design-system pattern from the repeatable user context it serves
|
|
3
|
+
description: Specify a new design-system pattern from the repeatable user context it serves; also runs as a guided tutorial on a worked example
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Specify Pattern
|
|
@@ -57,6 +57,45 @@ Decision gates — in collaboration, pause at each and resolve it WITH the perso
|
|
|
57
57
|
- Implementing an already-specified block — use `implement-component`
|
|
58
58
|
- Writing only the anatomy — use `anatomy-author`
|
|
59
59
|
|
|
60
|
+
## Opening move: ask, or offer the tutorial
|
|
61
|
+
|
|
62
|
+
Activation is an opening, not a starting gun. Unless the first message already names
|
|
63
|
+
the work, ask for the starting point — as a suggestion carrying an example, not as a
|
|
64
|
+
form to fill in:
|
|
65
|
+
|
|
66
|
+
> To get started, tell me the pattern you'd like to work on — a name if it has one, or
|
|
67
|
+
> just the situation behind it, like "people keep having to confirm before something
|
|
68
|
+
> destructive happens".
|
|
69
|
+
|
|
70
|
+
The situation is the better of the two starts: this skill defines a pattern by the
|
|
71
|
+
context it serves, so what recurs matters more than what it is called. Ask again only
|
|
72
|
+
for what the next step genuinely blocks on.
|
|
73
|
+
|
|
74
|
+
If the activation message already carries the starting point, do not re-ask — say what
|
|
75
|
+
you took it to be, and go.
|
|
76
|
+
|
|
77
|
+
Offer the tutorial in the same breath, because this skill doubles as one:
|
|
78
|
+
|
|
79
|
+
> Or if you'd rather see the flow first, I can run it as a tutorial: I'll take a
|
|
80
|
+
> plausible example — confirming a destructive action, say — and walk you through the
|
|
81
|
+
> eight steps on it.
|
|
82
|
+
|
|
83
|
+
Tutorial mode runs the real flow on the example, narrated: name each step before
|
|
84
|
+
running it, show what came back and what it means, and reason each decision gate out
|
|
85
|
+
loud before checking the person is with you. Stop short of anything that lands — no
|
|
86
|
+
spec file written, no proposal filed — unless they ask to keep what you built.
|
|
87
|
+
|
|
88
|
+
## The spec falls under standards too
|
|
89
|
+
|
|
90
|
+
A pattern spec is Turtle, and Turtle has standards — the `turtle` category, with
|
|
91
|
+
`ui-blocks` governing how blocks and their parts are modelled (take the actual set
|
|
92
|
+
from `pragma standard categories`, not from this list). Pull them before writing and
|
|
93
|
+
hold the Do/Don't pairs open; a spec that contradicts a pulled standard carries a
|
|
94
|
+
RECORDED deviation in the proposal, ideally also filed as an issue. The standards
|
|
95
|
+
apply independent of any package dependency and are open to contribution: a missing
|
|
96
|
+
or wrong modelling rule is something to propose a change for, not to silently work
|
|
97
|
+
around.
|
|
98
|
+
|
|
60
99
|
## The eight steps
|
|
61
100
|
|
|
62
101
|
### 1. Search the graph — patterns AND their parts
|
package/source.json
CHANGED
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"properties": "grid-20chnVyhaz",
|
|
14
14
|
"tags": "grid-lWjILO8uln",
|
|
15
15
|
"tagCategories": "grid-FhqOiepLOs",
|
|
16
|
-
"changeLog": "grid-909bbtNGDK"
|
|
16
|
+
"changeLog": "grid-909bbtNGDK",
|
|
17
|
+
"concepts": "grid-GnfOU3MM-3",
|
|
18
|
+
"conceptTypes": "grid-NN2EoogWeA"
|
|
17
19
|
}
|
|
18
20
|
},
|
|
19
21
|
"transform": {
|
|
@@ -134,6 +136,31 @@
|
|
|
134
136
|
},
|
|
135
137
|
"class": "ds:TagCategory",
|
|
136
138
|
"uriTemplate": "ds:tagcategory.{Category}"
|
|
139
|
+
},
|
|
140
|
+
"concepts": {
|
|
141
|
+
"@context": {
|
|
142
|
+
"ds": "https://ds.canonical.com/",
|
|
143
|
+
"name": "ds:name",
|
|
144
|
+
"summary": "ds:summary",
|
|
145
|
+
"content": "ds:content",
|
|
146
|
+
"known edge cases": "ds:knownEdgeCases",
|
|
147
|
+
"type": { "@id": "ds:conceptType", "@type": "@id" },
|
|
148
|
+
"tier": { "@id": "ds:tier", "@type": "@id" }
|
|
149
|
+
},
|
|
150
|
+
"class": "ds:Concept",
|
|
151
|
+
"uriTemplate": "ds:concept.{name}",
|
|
152
|
+
"rowFilter": {
|
|
153
|
+
"nonEmpty": [{ "column": "content", "minLength": 20 }]
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
"conceptTypes": {
|
|
157
|
+
"@context": {
|
|
158
|
+
"ds": "https://ds.canonical.com/",
|
|
159
|
+
"Name": "ds:name",
|
|
160
|
+
"Notes": "ds:summary"
|
|
161
|
+
},
|
|
162
|
+
"class": "ds:ConceptType",
|
|
163
|
+
"uriTemplate": "ds:concepttype.{Name}"
|
|
137
164
|
}
|
|
138
165
|
},
|
|
139
166
|
"references": {
|
|
@@ -164,6 +191,14 @@
|
|
|
164
191
|
"tagCategories": {
|
|
165
192
|
"uriTemplate": "ds:tagcategory.{Category}",
|
|
166
193
|
"keyColumn": "Category"
|
|
194
|
+
},
|
|
195
|
+
"concepts": {
|
|
196
|
+
"uriTemplate": "ds:concept.{name}",
|
|
197
|
+
"keyColumn": "name"
|
|
198
|
+
},
|
|
199
|
+
"conceptTypes": {
|
|
200
|
+
"uriTemplate": "ds:concepttype.{Name}",
|
|
201
|
+
"keyColumn": "Name"
|
|
167
202
|
}
|
|
168
203
|
}
|
|
169
204
|
}
|
|
@@ -43,6 +43,18 @@ describe("generateLibraryTurtle", () => {
|
|
|
43
43
|
expect(ttl).toContain("ds:libraryTier ds:global");
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
it("should strip the npm scope when slugifying package names", async () => {
|
|
47
|
+
const config: CollectConfig = {
|
|
48
|
+
...minimalConfig,
|
|
49
|
+
name: "@canonical/react-ds-global",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const ttl = await generateLibraryTurtle(config);
|
|
53
|
+
|
|
54
|
+
expect(ttl).toContain("ds:implementation.library.react-ds-global");
|
|
55
|
+
expect(ttl).not.toContain("canonical-react-ds-global");
|
|
56
|
+
});
|
|
57
|
+
|
|
46
58
|
it("should slugify library name for URI", async () => {
|
|
47
59
|
const config: CollectConfig = {
|
|
48
60
|
...minimalConfig,
|
|
@@ -186,3 +198,139 @@ describe("generateObjectsTurtle", () => {
|
|
|
186
198
|
expect(ttl).toContain('ds:headLink "src/deep/nested/Component.tsx"');
|
|
187
199
|
});
|
|
188
200
|
});
|
|
201
|
+
|
|
202
|
+
describe("generateLibraryTurtle with release version", () => {
|
|
203
|
+
const config: CollectConfig = {
|
|
204
|
+
name: "Test Library",
|
|
205
|
+
platform: "react",
|
|
206
|
+
link: "https://github.com/example/test",
|
|
207
|
+
prefix: {
|
|
208
|
+
short: "ds",
|
|
209
|
+
namespace: "https://ds.canonical.com/",
|
|
210
|
+
},
|
|
211
|
+
pattern: "src/**/*.tsx",
|
|
212
|
+
version: "0.35.0",
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
it("should emit ds:version when a release version is configured", async () => {
|
|
216
|
+
const ttl = await generateLibraryTurtle(config);
|
|
217
|
+
|
|
218
|
+
expect(ttl).toContain('ds:version "0.35.0"');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should not emit ds:version without a release version", async () => {
|
|
222
|
+
const ttl = await generateLibraryTurtle({ ...config, version: undefined });
|
|
223
|
+
|
|
224
|
+
expect(ttl).not.toContain("ds:version");
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe("generateObjectsTurtle named IRIs and links", () => {
|
|
229
|
+
const config: CollectConfig = {
|
|
230
|
+
name: "React DS Global",
|
|
231
|
+
platform: "react",
|
|
232
|
+
link: "https://github.com/canonical/pragma/tree/main/packages/react/ds-global",
|
|
233
|
+
prefix: {
|
|
234
|
+
short: "ds",
|
|
235
|
+
namespace: "https://ds.canonical.com/",
|
|
236
|
+
},
|
|
237
|
+
pattern: "src/**/*.tsx",
|
|
238
|
+
repository: "https://github.com/canonical/pragma",
|
|
239
|
+
sourcePath: "packages/react/ds-global",
|
|
240
|
+
version: "0.35.0",
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const annotations: ImplementsAnnotation[] = [
|
|
244
|
+
{
|
|
245
|
+
filePath: "/base/src/lib/component/Chip/Chip.tsx",
|
|
246
|
+
blockUri: "ds:global.component.chip",
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
|
|
250
|
+
it("should emit named IRIs instead of blank nodes", async () => {
|
|
251
|
+
const ttl = await generateObjectsTurtle(config, annotations, "/base");
|
|
252
|
+
|
|
253
|
+
expect(ttl).toContain(
|
|
254
|
+
"ds:implementation.react-ds-global.global.component.chip",
|
|
255
|
+
);
|
|
256
|
+
expect(ttl).not.toContain("_:");
|
|
257
|
+
expect(ttl).not.toContain("[");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("should link the library to the named implementation", async () => {
|
|
261
|
+
const ttl = await generateObjectsTurtle(config, annotations, "/base");
|
|
262
|
+
|
|
263
|
+
expect(ttl).toContain("ds:implementation.library.react-ds-global");
|
|
264
|
+
expect(ttl).toContain("ds:hasImplementation");
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("should emit full blob URLs for headLink when repository is set", async () => {
|
|
268
|
+
const ttl = await generateObjectsTurtle(config, annotations, "/base");
|
|
269
|
+
|
|
270
|
+
expect(ttl).toContain(
|
|
271
|
+
'ds:headLink "https://github.com/canonical/pragma/blob/main/packages/react/ds-global/src/lib/component/Chip/Chip.tsx"',
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("should emit versionedLink pinned to the release tag", async () => {
|
|
276
|
+
const ttl = await generateObjectsTurtle(config, annotations, "/base");
|
|
277
|
+
|
|
278
|
+
expect(ttl).toContain(
|
|
279
|
+
'ds:versionedLink "https://github.com/canonical/pragma/blob/v0.35.0/packages/react/ds-global/src/lib/component/Chip/Chip.tsx"',
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("should not emit versionedLink without a release version", async () => {
|
|
284
|
+
const ttl = await generateObjectsTurtle(
|
|
285
|
+
{ ...config, version: undefined },
|
|
286
|
+
annotations,
|
|
287
|
+
"/base",
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
expect(ttl).not.toContain("ds:versionedLink");
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("should disambiguate duplicate block implementations with a file slug", async () => {
|
|
294
|
+
const duplicated: ImplementsAnnotation[] = [
|
|
295
|
+
{
|
|
296
|
+
filePath: "/base/src/lib/component/Chip/Chip.tsx",
|
|
297
|
+
blockUri: "ds:global.component.chip",
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
filePath: "/base/src/lib/component/Chip/variants/Dense.tsx",
|
|
301
|
+
blockUri: "ds:global.component.chip",
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
|
|
305
|
+
const ttl = await generateObjectsTurtle(config, duplicated, "/base");
|
|
306
|
+
|
|
307
|
+
expect(ttl).toContain(
|
|
308
|
+
"ds:implementation.react-ds-global.global.component.chip a ds:ImplementationObject",
|
|
309
|
+
);
|
|
310
|
+
expect(ttl).toContain(
|
|
311
|
+
"ds:implementation.react-ds-global.global.component.chip.component-dense a ds:ImplementationObject",
|
|
312
|
+
);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("should produce deterministic output regardless of annotation order", async () => {
|
|
316
|
+
const shuffled: ImplementsAnnotation[] = [
|
|
317
|
+
{
|
|
318
|
+
filePath: "/base/src/lib/Modal.tsx",
|
|
319
|
+
blockUri: "ds:global.pattern.modal",
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
filePath: "/base/src/lib/component/Chip/Chip.tsx",
|
|
323
|
+
blockUri: "ds:global.component.chip",
|
|
324
|
+
},
|
|
325
|
+
];
|
|
326
|
+
|
|
327
|
+
const forward = await generateObjectsTurtle(config, shuffled, "/base");
|
|
328
|
+
const reversed = await generateObjectsTurtle(
|
|
329
|
+
config,
|
|
330
|
+
[...shuffled].reverse(),
|
|
331
|
+
"/base",
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
expect(forward).toBe(reversed);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
@@ -21,6 +21,7 @@ const RESERVED_PREFIXES = new Set(["rdf", "rdfs", "xsd", "owl"]);
|
|
|
21
21
|
function slugify(name: string): string {
|
|
22
22
|
return name
|
|
23
23
|
.toLowerCase()
|
|
24
|
+
.replace(/^@[^/]+\//, "") // Remove npm scope
|
|
24
25
|
.replace(/[^a-z0-9]+/g, "-")
|
|
25
26
|
.replace(/^-|-$/g, "");
|
|
26
27
|
}
|
|
@@ -32,7 +33,7 @@ function slugify(name: string): string {
|
|
|
32
33
|
* e.g., "src/lib/Tile/common/Header/Header.tsx" -> "tile-header"
|
|
33
34
|
* e.g., "src/lib/Accordion/common/Item/Item.tsx" -> "accordion-item"
|
|
34
35
|
*/
|
|
35
|
-
function
|
|
36
|
+
function filePathSlug(filePath: string): string {
|
|
36
37
|
// Remove extension and get path parts
|
|
37
38
|
const withoutExt = filePath.replace(/\.[^.]+$/, "");
|
|
38
39
|
const parts = withoutExt.split("/").filter(Boolean);
|
|
@@ -158,12 +159,40 @@ export function generateLibraryTurtle(config: CollectConfig): Promise<string> {
|
|
|
158
159
|
);
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
if (config.version) {
|
|
163
|
+
store.addLiteral(
|
|
164
|
+
libraryUri,
|
|
165
|
+
prefixes.expand(`${p}:version`),
|
|
166
|
+
config.version,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
161
170
|
return serializeToTurtle(store, { prefixes });
|
|
162
171
|
}
|
|
163
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Build the source link for an implementation file.
|
|
175
|
+
* With a repository configured, returns a full blob URL pinned to the given
|
|
176
|
+
* ref; otherwise falls back to the repo-relative path.
|
|
177
|
+
*/
|
|
178
|
+
function buildSourceLink(
|
|
179
|
+
config: CollectConfig,
|
|
180
|
+
ref: string,
|
|
181
|
+
relativePath: string,
|
|
182
|
+
): string {
|
|
183
|
+
if (!config.repository) {
|
|
184
|
+
return relativePath;
|
|
185
|
+
}
|
|
186
|
+
const repo = config.repository.replace(/\/$/, "");
|
|
187
|
+
const prefix = config.sourcePath ? `${config.sourcePath}/` : "";
|
|
188
|
+
return `${repo}/blob/${ref}/${prefix}${relativePath}`;
|
|
189
|
+
}
|
|
190
|
+
|
|
164
191
|
/**
|
|
165
192
|
* Generate the ImplementationObject .ttl content from annotations
|
|
166
|
-
* ImplementationObjects are
|
|
193
|
+
* ImplementationObjects are named IRIs (ds:implementation.{librarySlug}.{blockLocalName})
|
|
194
|
+
* attached to the library, so they keep a stable identity across releases
|
|
195
|
+
* when ingested into a knowledge graph.
|
|
167
196
|
*/
|
|
168
197
|
export function generateObjectsTurtle(
|
|
169
198
|
config: CollectConfig,
|
|
@@ -181,44 +210,68 @@ export function generateObjectsTurtle(
|
|
|
181
210
|
const librarySlug = slugify(config.name);
|
|
182
211
|
const libraryUri = `${config.prefix.namespace}implementation.library.${librarySlug}`;
|
|
183
212
|
|
|
184
|
-
for
|
|
213
|
+
// Sort for deterministic output so regenerated files diff cleanly
|
|
214
|
+
const sorted = [...annotations].sort((a, b) => {
|
|
215
|
+
const byBlock = a.blockUri.localeCompare(b.blockUri);
|
|
216
|
+
return byBlock !== 0 ? byBlock : a.filePath.localeCompare(b.filePath);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// Track emitted IRIs so a second implementation of the same block in the
|
|
220
|
+
// same library gets a file-path discriminator instead of merging silently
|
|
221
|
+
const seen = new Set<string>();
|
|
222
|
+
|
|
223
|
+
for (const annotation of sorted) {
|
|
185
224
|
const relativePath = relative(basePath, annotation.filePath);
|
|
186
225
|
|
|
187
|
-
//
|
|
188
|
-
const
|
|
226
|
+
// Named IRI: ds:implementation.{librarySlug}.{blockLocalName}
|
|
227
|
+
const blockLocalName = annotation.blockUri.replace(/^[^:]+:/, "");
|
|
228
|
+
let implUri = `${config.prefix.namespace}implementation.${librarySlug}.${blockLocalName}`;
|
|
229
|
+
if (seen.has(implUri)) {
|
|
230
|
+
implUri = `${implUri}.${filePathSlug(relativePath)}`;
|
|
231
|
+
}
|
|
232
|
+
seen.add(implUri);
|
|
189
233
|
|
|
190
234
|
// Link library to implementation object
|
|
191
|
-
store.
|
|
235
|
+
store.addQuad(
|
|
192
236
|
libraryUri,
|
|
193
237
|
prefixes.expand(`${p}:hasImplementation`),
|
|
194
|
-
|
|
238
|
+
implUri,
|
|
195
239
|
);
|
|
196
240
|
|
|
197
241
|
// Add type
|
|
198
|
-
store.
|
|
199
|
-
|
|
242
|
+
store.addQuad(
|
|
243
|
+
implUri,
|
|
200
244
|
prefixes.expand("rdf:type"),
|
|
201
245
|
prefixes.expand(`${p}:ImplementationObject`),
|
|
202
246
|
);
|
|
203
247
|
|
|
204
248
|
// Add implements block reference
|
|
205
|
-
store.
|
|
206
|
-
|
|
249
|
+
store.addQuad(
|
|
250
|
+
implUri,
|
|
207
251
|
prefixes.expand(`${p}:implementsBlock`),
|
|
208
252
|
prefixes.expand(annotation.blockUri),
|
|
209
253
|
);
|
|
210
254
|
|
|
211
|
-
// Add head link (
|
|
212
|
-
store.
|
|
213
|
-
|
|
255
|
+
// Add head link (source file at the repository head)
|
|
256
|
+
store.addLiteral(
|
|
257
|
+
implUri,
|
|
214
258
|
prefixes.expand(`${p}:headLink`),
|
|
215
|
-
relativePath,
|
|
259
|
+
buildSourceLink(config, "main", relativePath),
|
|
216
260
|
);
|
|
217
261
|
|
|
262
|
+
// Add versioned link (source file pinned to the release tag)
|
|
263
|
+
if (config.repository && config.version) {
|
|
264
|
+
store.addLiteral(
|
|
265
|
+
implUri,
|
|
266
|
+
prefixes.expand(`${p}:versionedLink`),
|
|
267
|
+
buildSourceLink(config, `v${config.version}`, relativePath),
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
|
|
218
271
|
// Add version if specified
|
|
219
272
|
if (annotation.version) {
|
|
220
|
-
store.
|
|
221
|
-
|
|
273
|
+
store.addLiteral(
|
|
274
|
+
implUri,
|
|
222
275
|
prefixes.expand(`${p}:implementationVersion`),
|
|
223
276
|
annotation.version,
|
|
224
277
|
);
|
|
@@ -226,11 +279,7 @@ export function generateObjectsTurtle(
|
|
|
226
279
|
|
|
227
280
|
// Add draft status if true
|
|
228
281
|
if (annotation.isDraft) {
|
|
229
|
-
store.
|
|
230
|
-
implNode,
|
|
231
|
-
prefixes.expand(`${p}:isDraft`),
|
|
232
|
-
"true",
|
|
233
|
-
);
|
|
282
|
+
store.addLiteral(implUri, prefixes.expand(`${p}:isDraft`), "true");
|
|
234
283
|
}
|
|
235
284
|
}
|
|
236
285
|
|
package/src/collect/types.ts
CHANGED
|
@@ -35,6 +35,26 @@ export interface CollectConfig {
|
|
|
35
35
|
|
|
36
36
|
/** Output directory for generated .ttl files (default: "data") */
|
|
37
37
|
outputDir?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Release version of the library (e.g., "0.35.0").
|
|
41
|
+
* When set, emits ds:version on the library and enables versionedLink
|
|
42
|
+
* generation for implementation objects.
|
|
43
|
+
*/
|
|
44
|
+
version?: string;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Base URL of the source repository (e.g., "https://github.com/canonical/pragma").
|
|
48
|
+
* When set, headLink/versionedLink are emitted as full blob URLs instead of
|
|
49
|
+
* repo-relative paths.
|
|
50
|
+
*/
|
|
51
|
+
repository?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Path of the library within the repository (e.g., "packages/react/ds-global").
|
|
55
|
+
* Prepended to file paths when building full blob URLs.
|
|
56
|
+
*/
|
|
57
|
+
sourcePath?: string;
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
/**
|
|
@@ -98,6 +98,33 @@
|
|
|
98
98
|
"description": "Column→predicate literal mappings for this class"
|
|
99
99
|
},
|
|
100
100
|
"description": "Additional literal column→predicate mappings applied only when the resolved class matches the key (prefixed form, e.g. 'ds:Layout')"
|
|
101
|
+
},
|
|
102
|
+
"rowFilter": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"description": "Optional include-filter: emit only rows matching every condition. Absent → emit every row.",
|
|
105
|
+
"properties": {
|
|
106
|
+
"nameIn": {
|
|
107
|
+
"type": "object",
|
|
108
|
+
"required": ["column", "values"],
|
|
109
|
+
"properties": {
|
|
110
|
+
"column": { "type": "string" },
|
|
111
|
+
"values": { "type": "array", "items": { "type": "string" } }
|
|
112
|
+
},
|
|
113
|
+
"description": "Keep only rows whose column equals one of these values (case-insensitive)"
|
|
114
|
+
},
|
|
115
|
+
"nonEmpty": {
|
|
116
|
+
"type": "array",
|
|
117
|
+
"items": {
|
|
118
|
+
"type": "object",
|
|
119
|
+
"required": ["column"],
|
|
120
|
+
"properties": {
|
|
121
|
+
"column": { "type": "string" },
|
|
122
|
+
"minLength": { "type": "number" }
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"description": "Keep only rows whose named column(s) are non-empty (trimmed length ≥ minLength, default 1)"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
101
128
|
}
|
|
102
129
|
}
|
|
103
130
|
},
|
package/src/config/types.ts
CHANGED
|
@@ -48,6 +48,26 @@ export type JsonLdContext = {
|
|
|
48
48
|
[columnName: string]: ContextValue | undefined;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Row-level include filter for a table transform. A row is emitted only when it
|
|
53
|
+
* satisfies EVERY declared condition (logical AND). Absent → every row is
|
|
54
|
+
* emitted (the historical behaviour). Use this to ingest only a named,
|
|
55
|
+
* non-empty subset of a large-but-mostly-stub table (e.g. Concepts, where most
|
|
56
|
+
* rows carry no `content` body yet).
|
|
57
|
+
*/
|
|
58
|
+
export interface RowFilter {
|
|
59
|
+
/**
|
|
60
|
+
* Keep only rows whose `column` (case-insensitively, after trimming) equals
|
|
61
|
+
* one of these values. The column is typically the name/title column.
|
|
62
|
+
*/
|
|
63
|
+
nameIn?: { column: string; values: string[] };
|
|
64
|
+
/**
|
|
65
|
+
* Keep only rows whose named column is non-empty (a trimmed length ≥
|
|
66
|
+
* `minLength`, default 1). Repeatable across columns — ALL must be non-empty.
|
|
67
|
+
*/
|
|
68
|
+
nonEmpty?: { column: string; minLength?: number }[];
|
|
69
|
+
}
|
|
70
|
+
|
|
51
71
|
/**
|
|
52
72
|
* Table transformation configuration
|
|
53
73
|
* Note: Column names in @context ARE the Coda column names
|
|
@@ -63,6 +83,11 @@ export interface TableTransform {
|
|
|
63
83
|
* treated as plain string literals (same semantics as a bare string in @context).
|
|
64
84
|
*/
|
|
65
85
|
classProperties?: Record<string, Record<string, string>>;
|
|
86
|
+
/**
|
|
87
|
+
* Optional include-filter: emit only the rows matching every condition.
|
|
88
|
+
* Absent → emit every row.
|
|
89
|
+
*/
|
|
90
|
+
rowFilter?: RowFilter;
|
|
66
91
|
}
|
|
67
92
|
|
|
68
93
|
/**
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import type { RowFilter } from "../config/types.js";
|
|
3
|
+
import { rowPassesFilter } from "./rowFilter.js";
|
|
4
|
+
|
|
5
|
+
describe("rowPassesFilter", () => {
|
|
6
|
+
describe("nonEmpty", () => {
|
|
7
|
+
const filter: RowFilter = {
|
|
8
|
+
nonEmpty: [{ column: "content", minLength: 20 }],
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
it("keeps a row whose column meets the minimum length", () => {
|
|
12
|
+
const row = { name: "Foundations: Grid", content: "x".repeat(20) };
|
|
13
|
+
expect(rowPassesFilter(row, filter)).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("drops a row whose column is empty", () => {
|
|
17
|
+
const row = { name: "A stub concept", content: "" };
|
|
18
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("drops a row whose column is shorter than minLength", () => {
|
|
22
|
+
const row = { name: "Tiny", content: "too short" };
|
|
23
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("drops a row whose column is missing", () => {
|
|
27
|
+
const row = { name: "No content column at all" };
|
|
28
|
+
expect(rowPassesFilter(row, filter)).toBe(false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("defaults minLength to 1 (any non-empty value passes)", () => {
|
|
32
|
+
const row = { content: "a" };
|
|
33
|
+
expect(rowPassesFilter(row, { nonEmpty: [{ column: "content" }] })).toBe(
|
|
34
|
+
true,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("requires EVERY listed column to be non-empty (logical AND)", () => {
|
|
39
|
+
const both: RowFilter = {
|
|
40
|
+
nonEmpty: [{ column: "content" }, { column: "summary" }],
|
|
41
|
+
};
|
|
42
|
+
expect(rowPassesFilter({ content: "yes", summary: "" }, both)).toBe(
|
|
43
|
+
false,
|
|
44
|
+
);
|
|
45
|
+
expect(rowPassesFilter({ content: "yes", summary: "also" }, both)).toBe(
|
|
46
|
+
true,
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("nameIn", () => {
|
|
52
|
+
const filter: RowFilter = {
|
|
53
|
+
nameIn: {
|
|
54
|
+
column: "name",
|
|
55
|
+
values: ["Foundations: Grid", "SkeletonLoading"],
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
it("keeps a named row (case-insensitive, trimmed)", () => {
|
|
60
|
+
expect(rowPassesFilter({ name: " foundations: grid " }, filter)).toBe(
|
|
61
|
+
true,
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("drops a row not in the name list", () => {
|
|
66
|
+
expect(rowPassesFilter({ name: "Something else" }, filter)).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("lookup-object cells", () => {
|
|
71
|
+
it("reads a { id, name } lookup cell by its name", () => {
|
|
72
|
+
const filter: RowFilter = {
|
|
73
|
+
nameIn: { column: "type", values: ["Decision guide"] },
|
|
74
|
+
};
|
|
75
|
+
const row = { type: { id: "i-abc", name: "Decision guide" } };
|
|
76
|
+
expect(rowPassesFilter(row, filter)).toBe(true);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("combines nameIn AND nonEmpty (both must hold)", () => {
|
|
81
|
+
const filter: RowFilter = {
|
|
82
|
+
nameIn: { column: "name", values: ["Foundations: Grid"] },
|
|
83
|
+
nonEmpty: [{ column: "content", minLength: 20 }],
|
|
84
|
+
};
|
|
85
|
+
expect(
|
|
86
|
+
rowPassesFilter(
|
|
87
|
+
{ name: "Foundations: Grid", content: "x".repeat(20) },
|
|
88
|
+
filter,
|
|
89
|
+
),
|
|
90
|
+
).toBe(true);
|
|
91
|
+
// Right name, empty content → dropped.
|
|
92
|
+
expect(
|
|
93
|
+
rowPassesFilter({ name: "Foundations: Grid", content: "" }, filter),
|
|
94
|
+
).toBe(false);
|
|
95
|
+
// Non-empty content, wrong name → dropped.
|
|
96
|
+
expect(
|
|
97
|
+
rowPassesFilter({ name: "Other", content: "x".repeat(20) }, filter),
|
|
98
|
+
).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|