@canonical/design-system 0.1.0 → 0.1.2

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.
Files changed (313) hide show
  1. package/.github/ISSUE_TEMPLATE/propose-changes-to-existing-ui-block.md +14 -0
  2. package/.github/ISSUE_TEMPLATE/propose-new-ui-block.md +26 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +13 -0
  4. package/.github/workflows/ci.yml +39 -0
  5. package/.github/workflows/sync-coda-manual.yml +12 -0
  6. package/.github/workflows/sync-coda-scheduled.yml +13 -0
  7. package/.github/workflows/sync-coda.yml +38 -0
  8. package/.mcp.json +6 -2
  9. package/GEMINI.md +2 -0
  10. package/README.md +71 -51
  11. package/biome.json +1 -1
  12. package/bun.lock +38 -35
  13. package/data/apps/component/file_tree.ttl +6 -7
  14. package/data/apps/component/key_value_pair.ttl +6 -7
  15. package/data/apps/component/navigation.ttl +6 -7
  16. package/data/apps/component/notification.ttl +7 -0
  17. package/data/apps/component/skeleton_loading.ttl +6 -7
  18. package/data/apps/component/status_bar.ttl +6 -7
  19. package/data/apps/component/toolbar.ttl +6 -7
  20. package/data/apps/group/notifications.ttl +7 -0
  21. package/data/apps/layout/application_layout.ttl +8 -7
  22. package/data/apps/layout/content_layout.ttl +9 -0
  23. package/data/apps/layout/empty_layout.ttl +6 -7
  24. package/data/apps/layout/list_page_layout.ttl +6 -7
  25. package/data/apps/layout/settings_page_layout.ttl +6 -7
  26. package/data/apps/layout/view_layout.ttl +9 -0
  27. package/data/apps/pattern/code_diff.ttl +6 -7
  28. package/data/apps/pattern/data_table.ttl +6 -7
  29. package/data/apps/pattern/destructive_modal.ttl +6 -7
  30. package/data/apps/pattern/key_value_summary.ttl +6 -7
  31. package/data/apps/pattern/keyboard_shortcuts.ttl +6 -7
  32. package/data/apps/pattern/notification_center.ttl +6 -7
  33. package/data/apps/pattern/side_panel.ttl +6 -7
  34. package/data/apps/pattern/sidepanel_stacked.ttl +6 -7
  35. package/data/apps/subcomponent/file_tree-node.ttl +7 -0
  36. package/data/apps.ttl +3 -4
  37. package/data/apps_anbox/component/copy_to_clipboard.ttl +7 -0
  38. package/data/apps_anbox/pattern/side_menu.ttl +13 -0
  39. package/data/apps_anbox.ttl +4 -0
  40. package/data/apps_juju/pattern/single_select_multi_layered.ttl +7 -0
  41. package/data/apps_juju.ttl +4 -0
  42. package/data/apps_landscape/component/password_constraints.ttl +32 -0
  43. package/data/apps_landscape.ttl +4 -0
  44. package/data/apps_launchpad/component/badge.ttl +23 -0
  45. package/data/apps_launchpad/component/breadcrumbs.ttl +14 -0
  46. package/data/apps_launchpad/component/button.ttl +35 -0
  47. package/data/apps_launchpad/component/checkbox.ttl +28 -0
  48. package/data/apps_launchpad/component/chip.ttl +42 -0
  49. package/data/apps_launchpad/component/combobox.ttl +52 -0
  50. package/data/apps_launchpad/component/description_list.ttl +13 -0
  51. package/data/apps_launchpad/component/radio.ttl +34 -0
  52. package/data/apps_launchpad/component/select.ttl +34 -0
  53. package/data/apps_launchpad/component/switch.ttl +21 -0
  54. package/data/apps_launchpad/component/text_input.ttl +36 -0
  55. package/data/apps_launchpad/component/textarea.ttl +35 -0
  56. package/data/apps_launchpad/component/tooltip.ttl +28 -0
  57. package/data/apps_launchpad/component/user_avatar.ttl +25 -0
  58. package/data/apps_launchpad/subcomponent/combobox-checkbox_option.ttl +29 -0
  59. package/data/apps_launchpad/subcomponent/combobox-footer.ttl +13 -0
  60. package/data/apps_launchpad/subcomponent/combobox-group.ttl +20 -0
  61. package/data/apps_launchpad/subcomponent/combobox-helper.ttl +19 -0
  62. package/data/apps_launchpad/subcomponent/combobox-loading.ttl +13 -0
  63. package/data/apps_launchpad/subcomponent/combobox-no_results.ttl +13 -0
  64. package/data/apps_launchpad/subcomponent/combobox-radio_option.ttl +29 -0
  65. package/data/apps_launchpad/subcomponent/combobox-search.ttl +22 -0
  66. package/data/apps_launchpad/subcomponent/description_list-item.ttl +19 -0
  67. package/data/apps_launchpad.ttl +4 -0
  68. package/data/apps_lxd/component/confirmation_checkbox.ttl +7 -0
  69. package/data/apps_lxd/component/copy_to_clipboard.ttl +7 -0
  70. package/data/apps_lxd/view/network_topology.ttl +7 -0
  71. package/data/apps_lxd.ttl +4 -0
  72. package/data/apps_portal/component/badge.ttl +7 -0
  73. package/data/apps_portal.ttl +4 -0
  74. package/data/apps_workplace/component/label-highlight.ttl +7 -0
  75. package/data/apps_workplace.ttl +4 -0
  76. package/data/apps_wpe.ttl +3 -4
  77. package/data/documentation/layout/documentation_layout.ttl +6 -7
  78. package/data/documentation/pattern/library_side_navigation.ttl +7 -0
  79. package/data/documentation.ttl +3 -4
  80. package/data/global/component/accordion.ttl +11 -12
  81. package/data/global/component/announcement.ttl +6 -7
  82. package/data/global/component/badge.ttl +7 -8
  83. package/data/global/component/breadcrumbs.ttl +13 -0
  84. package/data/global/component/button.ttl +29 -17
  85. package/data/global/component/button_link.ttl +7 -0
  86. package/data/global/component/card.ttl +6 -7
  87. package/data/global/component/chip.ttl +6 -7
  88. package/data/global/component/code.ttl +7 -0
  89. package/data/global/component/code_snippet-content.ttl +7 -0
  90. package/data/global/component/code_snippet-header.ttl +7 -0
  91. package/data/global/component/code_snippet.ttl +6 -7
  92. package/data/global/component/contextual_menu.ttl +6 -7
  93. package/data/global/component/heading.ttl +12 -12
  94. package/data/global/component/icon.ttl +12 -12
  95. package/data/global/component/icon_in_container.ttl +6 -7
  96. package/data/global/component/keyboard_key.ttl +6 -7
  97. package/data/global/component/label.ttl +12 -13
  98. package/data/global/component/notification_inline.ttl +6 -7
  99. package/data/global/component/notification_toast.ttl +6 -7
  100. package/data/global/component/pagination.ttl +6 -7
  101. package/data/global/component/popover.ttl +6 -7
  102. package/data/global/component/rich_text_editor.ttl +6 -7
  103. package/data/global/component/search_bar.ttl +6 -7
  104. package/data/global/component/table.ttl +6 -7
  105. package/data/global/component/tabs.ttl +6 -7
  106. package/data/global/component/theme_switcher.ttl +6 -7
  107. package/data/global/component/tile.ttl +11 -12
  108. package/data/global/component/tooltip.ttl +201 -7
  109. package/data/global/group/buttons.ttl +6 -7
  110. package/data/global/group/cards.ttl +6 -7
  111. package/data/global/group/code_snippets.ttl +7 -0
  112. package/data/global/group/keyboard_keys.ttl +7 -0
  113. package/data/global/group/tiles.ttl +6 -7
  114. package/data/global/layout/error_layout.ttl +6 -7
  115. package/data/global/layout/form_layout.ttl +6 -7
  116. package/data/global/layout/identity_page_form.ttl +6 -7
  117. package/data/global/modifier/alpha.ttl +5 -5
  118. package/data/global/modifier/beta.ttl +5 -5
  119. package/data/global/modifier/caution.ttl +5 -5
  120. package/data/global/modifier/comfortable.ttl +5 -5
  121. package/data/global/modifier/completed.ttl +5 -5
  122. package/data/global/modifier/constructive.ttl +5 -5
  123. package/data/global/modifier/dark.ttl +5 -5
  124. package/data/global/modifier/dense.ttl +5 -5
  125. package/data/global/modifier/destructive.ttl +5 -5
  126. package/data/global/modifier/editable.ttl +5 -5
  127. package/data/global/modifier/elevated.ttl +5 -5
  128. package/data/global/modifier/error.ttl +5 -5
  129. package/data/global/modifier/experimental.ttl +5 -5
  130. package/data/global/modifier/failed.ttl +5 -5
  131. package/data/global/modifier/focused.ttl +5 -5
  132. package/data/global/modifier/highlighted.ttl +5 -5
  133. package/data/global/modifier/in_progress.ttl +5 -5
  134. package/data/global/modifier/information.ttl +5 -5
  135. package/data/global/modifier/light.ttl +5 -5
  136. package/data/global/modifier/loading.ttl +5 -5
  137. package/data/global/modifier/muted.ttl +5 -5
  138. package/data/global/modifier/paper.ttl +5 -5
  139. package/data/global/modifier/planned.ttl +5 -5
  140. package/data/global/modifier/primary.ttl +5 -5
  141. package/data/global/modifier/secondary.ttl +5 -5
  142. package/data/global/modifier/stable.ttl +5 -5
  143. package/data/global/modifier/success.ttl +5 -5
  144. package/data/global/modifier/tertiary.ttl +5 -5
  145. package/data/global/modifier/warning.ttl +5 -5
  146. package/data/global/modifier/wireframe.ttl +5 -5
  147. package/data/global/modifier_family/_color_luminosity.ttl +5 -6
  148. package/data/global/modifier_family/_emphasis.ttl +5 -6
  149. package/data/global/modifier_family/_other.ttl +5 -6
  150. package/data/global/modifier_family/anticipation.ttl +5 -6
  151. package/data/global/modifier_family/criticality.ttl +5 -6
  152. package/data/global/modifier_family/density.ttl +5 -6
  153. package/data/global/modifier_family/importance.ttl +5 -6
  154. package/data/global/modifier_family/lifecycle.ttl +5 -6
  155. package/data/global/modifier_family/release.ttl +5 -6
  156. package/data/global/pattern/dropdown_button.ttl +7 -0
  157. package/data/global/pattern/info_table.ttl +6 -7
  158. package/data/global/pattern/modal.ttl +6 -7
  159. package/data/global/pattern/navigation.ttl +6 -7
  160. package/data/global/pattern/stepper.ttl +6 -7
  161. package/data/global/pattern/table_of_contents.ttl +6 -7
  162. package/data/global/pattern/timeline.ttl +64 -12
  163. package/data/global/subcomponent/accordion-item.ttl +15 -16
  164. package/data/global/subcomponent/breadcrumbs-item.ttl +15 -16
  165. package/data/global/subcomponent/card-content.ttl +11 -12
  166. package/data/global/subcomponent/card-header.ttl +11 -12
  167. package/data/global/subcomponent/card-image.ttl +16 -17
  168. package/data/global/subcomponent/card-thumbnail.ttl +7 -0
  169. package/data/global/subcomponent/divider.ttl +6 -7
  170. package/data/global/subcomponent/modal-content.ttl +6 -7
  171. package/data/global/subcomponent/modal-footer.ttl +6 -7
  172. package/data/global/subcomponent/modal-header.ttl +6 -7
  173. package/data/global/subcomponent/spinner.ttl +6 -7
  174. package/data/global/subcomponent/table-cell.ttl +6 -7
  175. package/data/global/subcomponent/table-row.ttl +6 -7
  176. package/data/global/subcomponent/tile-content.ttl +11 -12
  177. package/data/global/subcomponent/tile-header.ttl +11 -12
  178. package/data/global/subcomponent/timeline-content.ttl +11 -12
  179. package/data/global/subcomponent/timeline-event.ttl +42 -27
  180. package/data/global/subcomponent/timeline-expansion_indicator.ttl +7 -0
  181. package/data/global/subcomponent/timeline-header.ttl +6 -7
  182. package/data/global/view/settings_view.ttl +7 -0
  183. package/data/global.ttl +3 -4
  184. package/data/global_form/component/checkbox_input.ttl +6 -7
  185. package/data/global_form/component/choices_input.ttl +6 -7
  186. package/data/global_form/component/combobox_input.ttl +6 -7
  187. package/data/global_form/component/custom_choices_input.ttl +6 -7
  188. package/data/global_form/component/datepicker_input.ttl +6 -7
  189. package/data/global_form/component/rating_input.ttl +6 -7
  190. package/data/global_form/component/rich_text_input.ttl +7 -0
  191. package/data/global_form/component/segmented_control_input.ttl +6 -7
  192. package/data/global_form/component/slider_input.ttl +6 -7
  193. package/data/global_form/component/switch_input.ttl +6 -7
  194. package/data/global_form/component/text_input.ttl +6 -7
  195. package/data/global_form/component/textarea_input.ttl +6 -7
  196. package/data/global_form/component/wysiwginput.ttl +6 -7
  197. package/data/global_form/pattern/field.ttl +6 -7
  198. package/data/global_form/pattern/form.ttl +6 -7
  199. package/data/global_form/subcomponent/field-description.ttl +6 -7
  200. package/data/global_form/subcomponent/field-label.ttl +6 -7
  201. package/data/global_form.ttl +3 -4
  202. package/data/site/component/blog_card.ttl +7 -0
  203. package/data/site/component/quote.ttl +6 -7
  204. package/data/site/component/rule.ttl +6 -7
  205. package/data/site/component/section.ttl +6 -7
  206. package/data/site/group/blog_cards.ttl +7 -0
  207. package/data/site/layout/blog_page_layout.ttl +7 -0
  208. package/data/site/layout/case_study_layout.ttl +7 -0
  209. package/data/site/layout/site_layout.ttl +6 -7
  210. package/data/site/pattern/hero-github.ttl +6 -7
  211. package/data/site/pattern/hero.ttl +6 -7
  212. package/data/site/pattern/info_table.ttl +6 -7
  213. package/data/site/pattern/pricing_section.ttl +7 -0
  214. package/data/site/pattern/pricing_table.ttl +7 -0
  215. package/data/site/pattern/read_more_section.ttl +7 -0
  216. package/data/site/pattern/skip_link.ttl +6 -7
  217. package/data/site.ttl +3 -4
  218. package/data/sites_webcomponentsprototype/component/blog_cards.ttl +7 -0
  219. package/data/sites_webcomponentsprototype/component/ctablock.ttl +7 -0
  220. package/data/sites_webcomponentsprototype/component/list.ttl +7 -0
  221. package/data/sites_webcomponentsprototype/component/tabs.ttl +7 -0
  222. package/data/sites_webcomponentsprototype/layout/site_layout.ttl +8 -0
  223. package/data/sites_webcomponentsprototype/pattern/basic_section.ttl +7 -0
  224. package/data/sites_webcomponentsprototype/pattern/blog_section.ttl +7 -0
  225. package/data/sites_webcomponentsprototype/pattern/ctasection.ttl +7 -0
  226. package/data/sites_webcomponentsprototype/pattern/equal_heights.ttl +7 -0
  227. package/data/sites_webcomponentsprototype/pattern/hero.ttl +7 -0
  228. package/data/sites_webcomponentsprototype/pattern/logo_section.ttl +7 -0
  229. package/data/sites_webcomponentsprototype/pattern/quote_wrapper.ttl +7 -0
  230. package/data/sites_webcomponentsprototype/pattern/tiered_list.ttl +7 -0
  231. package/data/sites_webcomponentsprototype.ttl +4 -0
  232. package/data/stores.ttl +3 -4
  233. package/definitions/ontology.ttl +132 -171
  234. package/package.json +8 -8
  235. package/skills/anatomy-author/SKILL.md +14 -9
  236. package/skills/component-specifier/SKILL.md +84 -85
  237. package/skills/design-auditor/SKILL.md +50 -45
  238. package/source.json +40 -33
  239. package/src/cli.ts +33 -33
  240. package/src/collect/generateTurtle.tests.ts +181 -193
  241. package/src/collect/generateTurtle.ts +189 -138
  242. package/src/collect/index.ts +5 -2
  243. package/src/collect/scanAnnotations.tests.ts +116 -110
  244. package/src/collect/scanAnnotations.ts +35 -33
  245. package/src/collect/types.ts +34 -33
  246. package/src/collect/validateCollectConfig.tests.ts +135 -112
  247. package/src/collect/validateCollectConfig.ts +60 -54
  248. package/src/collect-implementations.ts +101 -88
  249. package/src/commands/extract.tests.ts +31 -32
  250. package/src/commands/extract.ts +29 -27
  251. package/src/commands/index.ts +1 -1
  252. package/src/commands/list.tests.ts +13 -14
  253. package/src/commands/list.ts +9 -9
  254. package/src/commands/transform.tests.ts +21 -21
  255. package/src/commands/transform.ts +127 -99
  256. package/src/config/source.schema.json +9 -0
  257. package/src/config/types.ts +40 -33
  258. package/src/config/validateConfig.tests.ts +31 -31
  259. package/src/config/validateConfig.ts +9 -9
  260. package/src/constants.ts +7 -9
  261. package/src/graph/GraphStore.tests.ts +111 -111
  262. package/src/graph/GraphStore.ts +205 -189
  263. package/src/graph/PrefixMap.tests.ts +124 -122
  264. package/src/graph/PrefixMap.ts +77 -77
  265. package/src/graph/buildUri.tests.ts +119 -106
  266. package/src/graph/buildUri.ts +47 -35
  267. package/src/graph/index.ts +2 -2
  268. package/src/graph/types.ts +3 -3
  269. package/src/providers/CodaProvider.tests.ts +233 -233
  270. package/src/providers/CodaProvider.ts +145 -145
  271. package/src/providers/CodaProvider.types.generated.ts +12484 -12123
  272. package/src/providers/index.ts +13 -13
  273. package/src/serializers/JSONSerializer.tests.ts +65 -68
  274. package/src/serializers/JSONSerializer.ts +51 -51
  275. package/src/serializers/TTLSerializer.tests.ts +46 -48
  276. package/src/serializers/TTLSerializer.ts +66 -59
  277. package/src/serializers/index.ts +4 -1
  278. package/src/serializers/types.ts +3 -3
  279. package/src/transform/resolveReferences.tests.ts +47 -43
  280. package/src/transform/resolveReferences.ts +18 -18
  281. package/src/transform/resolveValue.tests.ts +55 -49
  282. package/src/transform/resolveValue.ts +48 -48
  283. package/src/transform/transform.tests.ts +90 -79
  284. package/src/transform/transform.ts +77 -75
  285. package/src/transform/transformRow.tests.ts +373 -258
  286. package/src/transform/transformRow.ts +228 -173
  287. package/src/transform/types.ts +4 -4
  288. package/tsconfig.json +2 -1
  289. package/data/global/component/link.ttl +0 -8
  290. package/data/global/pattern/breadcrumbs.ttl +0 -14
  291. package/data/global/pattern/select_button.ttl +0 -8
  292. package/data/global/subcomponent/timeline-footer.ttl +0 -8
  293. package/session/A.DSL.md +0 -429
  294. package/session/B.NOTES.md +0 -84
  295. package/session/global.component.accordion.yaml +0 -13
  296. package/session/global.component.button.yaml +0 -26
  297. package/session/global.component.card.yaml +0 -24
  298. package/session/global.component.icon.yaml +0 -7
  299. package/session/global.component.label.yaml +0 -7
  300. package/session/global.component.tile.yaml +0 -21
  301. package/session/global.component.timeline.yaml +0 -20
  302. package/session/global.pattern.breadcrumbs.yaml +0 -13
  303. package/session/global.subcomponent.accordion-item.yaml +0 -37
  304. package/session/global.subcomponent.breadcrumbs-item.yaml +0 -21
  305. package/session/global.subcomponent.card-content.yaml +0 -7
  306. package/session/global.subcomponent.card-header.yaml +0 -22
  307. package/session/global.subcomponent.card-image.yaml +0 -7
  308. package/session/global.subcomponent.tile-content.yaml +0 -7
  309. package/session/global.subcomponent.tile-header.yaml +0 -8
  310. package/session/global.subcomponent.timeline-content.yaml +0 -13
  311. package/session/global.subcomponent.timeline-event.yaml +0 -20
  312. package/session/global.subcomponent.timeline-footer.yaml +0 -9
  313. package/session/global.subcomponent.timeline-header.yaml +0 -18
@@ -1,18 +1,18 @@
1
- export { default as CodaProvider } from "./CodaProvider.js";
2
1
  export type {
3
- TableMetadata,
4
- ColumnMetadata,
5
- TableRow,
6
- // Generated Coda API types
7
- CodaTable,
8
- CodaTableReference,
9
- CodaTableList,
10
- CodaRow,
11
- CodaRowList,
12
- CodaColumn,
13
- CodaColumnList,
14
- CodaCellValue,
2
+ CodaCellValue,
3
+ CodaColumn,
4
+ CodaColumnList,
5
+ CodaRow,
6
+ CodaRowList,
7
+ // Generated Coda API types
8
+ CodaTable,
9
+ CodaTableList,
10
+ CodaTableReference,
11
+ ColumnMetadata,
12
+ TableMetadata,
13
+ TableRow,
15
14
  } from "./CodaProvider.js";
15
+ export { default as CodaProvider } from "./CodaProvider.js";
16
16
 
17
17
  // Re-export full generated types for advanced usage
18
18
  export type * from "./CodaProvider.types.generated.js";
@@ -6,74 +6,71 @@ import serializeToJsonLd from "./JSONSerializer.js";
6
6
  // Use realistic dot-separated URIs like the actual system
7
7
  const buttonUri = `${NAMESPACES.ds}global.component.button`;
8
8
  const inputUri = `${NAMESPACES.ds}global.component.input`;
9
- const componentType = `${NAMESPACES.dso}Component`;
9
+ const componentType = `${NAMESPACES.ds}Component`;
10
10
 
11
11
  describe("serializeToJsonLd", () => {
12
- it("should serialize a single subject to JSON-LD with compact URIs", async () => {
13
- const store = new GraphStore();
14
- store.addQuad(buttonUri, PREDICATES.type, componentType);
15
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
16
-
17
- const prefixes = new PrefixMap();
18
- prefixes.add("ds", NAMESPACES.ds);
19
- prefixes.add("dso", NAMESPACES.dso);
20
-
21
- const doc = await serializeToJsonLd(store, {
22
- prefixes,
23
- subject: buttonUri,
24
- });
25
-
26
- // JSON-LD compact uses prefixed URIs
27
- expect(doc["@id"]).toBe("ds:global.component.button");
28
- // @type can be a string or array in JSON-LD
29
- const type = doc["@type"];
30
- expect(Array.isArray(type) ? type[0] : type).toBe("dso:Component");
31
- });
32
-
33
- it("should include context from prefixes", async () => {
34
- const store = new GraphStore();
35
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
36
-
37
- const prefixes = new PrefixMap();
38
- prefixes.add("ds", NAMESPACES.ds);
39
- prefixes.add("dso", NAMESPACES.dso);
40
-
41
- const doc = await serializeToJsonLd(store, {
42
- prefixes,
43
- subject: buttonUri,
44
- });
45
-
46
- expect(doc["@context"]).toBeDefined();
47
- expect((doc["@context"] as Record<string, string>)["ds"]).toBe(NAMESPACES.ds);
48
- });
49
-
50
- it("should return empty object for unknown subject", async () => {
51
- const store = new GraphStore();
52
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
53
-
54
- const prefixes = new PrefixMap();
55
- const unknownUri = `${NAMESPACES.ds}global.component.unknown`;
56
-
57
- const doc = await serializeToJsonLd(store, {
58
- prefixes,
59
- subject: unknownUri,
60
- });
61
-
62
- // Unknown subject returns full URI since no data to compact
63
- expect(doc["@id"]).toBe(unknownUri);
64
- });
65
-
66
- it("should serialize all subjects when no subject specified", async () => {
67
- const store = new GraphStore();
68
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
69
- store.addLiteral(inputUri, PREDICATES.name, "Input");
70
-
71
- const prefixes = new PrefixMap();
72
- prefixes.add("ds", NAMESPACES.ds);
73
- prefixes.add("dso", NAMESPACES.dso);
74
-
75
- const docs = await serializeToJsonLd(store, { prefixes });
76
-
77
- expect(Array.isArray(docs) || docs["@graph"]).toBeTruthy();
78
- });
12
+ it("should serialize a single subject to JSON-LD with compact URIs", async () => {
13
+ const store = new GraphStore();
14
+ store.addQuad(buttonUri, PREDICATES.type, componentType);
15
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
16
+
17
+ const prefixes = new PrefixMap();
18
+ prefixes.add("ds", NAMESPACES.ds);
19
+
20
+ const doc = await serializeToJsonLd(store, {
21
+ prefixes,
22
+ subject: buttonUri,
23
+ });
24
+
25
+ // JSON-LD compact uses prefixed URIs
26
+ expect(doc["@id"]).toBe("ds:global.component.button");
27
+ // @type can be a string or array in JSON-LD
28
+ const type = doc["@type"];
29
+ expect(Array.isArray(type) ? type[0] : type).toBe("ds:Component");
30
+ });
31
+
32
+ it("should include context from prefixes", async () => {
33
+ const store = new GraphStore();
34
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
35
+
36
+ const prefixes = new PrefixMap();
37
+ prefixes.add("ds", NAMESPACES.ds);
38
+
39
+ const doc = await serializeToJsonLd(store, {
40
+ prefixes,
41
+ subject: buttonUri,
42
+ });
43
+
44
+ expect(doc["@context"]).toBeDefined();
45
+ expect((doc["@context"] as Record<string, string>).ds).toBe(NAMESPACES.ds);
46
+ });
47
+
48
+ it("should return empty object for unknown subject", async () => {
49
+ const store = new GraphStore();
50
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
51
+
52
+ const prefixes = new PrefixMap();
53
+ const unknownUri = `${NAMESPACES.ds}global.component.unknown`;
54
+
55
+ const doc = await serializeToJsonLd(store, {
56
+ prefixes,
57
+ subject: unknownUri,
58
+ });
59
+
60
+ // Unknown subject returns full URI since no data to compact
61
+ expect(doc["@id"]).toBe(unknownUri);
62
+ });
63
+
64
+ it("should serialize all subjects when no subject specified", async () => {
65
+ const store = new GraphStore();
66
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
67
+ store.addLiteral(inputUri, PREDICATES.name, "Input");
68
+
69
+ const prefixes = new PrefixMap();
70
+ prefixes.add("ds", NAMESPACES.ds);
71
+
72
+ const docs = await serializeToJsonLd(store, { prefixes });
73
+
74
+ expect(Array.isArray(docs) || docs["@graph"]).toBeTruthy();
75
+ });
79
76
  });
@@ -6,8 +6,8 @@ import type { GraphStore, PrefixMap } from "../graph/index.js";
6
6
  * Options for JSON-LD serialization
7
7
  */
8
8
  export interface JsonLdSerializeOptions {
9
- prefixes: PrefixMap;
10
- subject?: string;
9
+ prefixes: PrefixMap;
10
+ subject?: string;
11
11
  }
12
12
 
13
13
  /**
@@ -17,71 +17,71 @@ export interface JsonLdSerializeOptions {
17
17
  * Otherwise, returns all subjects as a graph.
18
18
  */
19
19
  export default async function serializeToJsonLd(
20
- store: GraphStore,
21
- options: JsonLdSerializeOptions,
20
+ store: GraphStore,
21
+ options: JsonLdSerializeOptions,
22
22
  ): Promise<Record<string, unknown>> {
23
- const quads = options.subject
24
- ? store.getQuadsForSubject(options.subject)
25
- : store.getQuads();
23
+ const quads = options.subject
24
+ ? store.getQuadsForSubject(options.subject)
25
+ : store.getQuads();
26
26
 
27
- // Convert quads to N-Quads string format for jsonld.fromRDF
28
- const nquads = await quadsToNQuads(quads);
27
+ // Convert quads to N-Quads string format for jsonld.fromRDF
28
+ const nquads = await quadsToNQuads(quads);
29
29
 
30
- if (!nquads.trim()) {
31
- // No quads found, return minimal document
32
- const context = options.prefixes.toRecord();
33
- return {
34
- "@context": context,
35
- "@id": options.subject || "",
36
- };
37
- }
30
+ if (!nquads.trim()) {
31
+ // No quads found, return minimal document
32
+ const context = options.prefixes.toRecord();
33
+ return {
34
+ "@context": context,
35
+ "@id": options.subject || "",
36
+ };
37
+ }
38
38
 
39
- // Convert N-Quads to JSON-LD
40
- const jsonldDoc = await jsonld.fromRDF(nquads, {
41
- format: "application/n-quads",
42
- });
39
+ // Convert N-Quads to JSON-LD
40
+ const jsonldDoc = await jsonld.fromRDF(nquads, {
41
+ format: "application/n-quads",
42
+ });
43
43
 
44
- // Build context from prefixes
45
- const context = options.prefixes.toRecord();
44
+ // Build context from prefixes
45
+ const context = options.prefixes.toRecord();
46
46
 
47
- // Frame the document to embed blank nodes inline
48
- if (options.subject) {
49
- const framed = await jsonld.frame(jsonldDoc, {
50
- "@context": context,
51
- "@id": options.subject,
52
- "@embed": "@always",
53
- });
47
+ // Frame the document to embed blank nodes inline
48
+ if (options.subject) {
49
+ const framed = await jsonld.frame(jsonldDoc, {
50
+ "@context": context,
51
+ "@id": options.subject,
52
+ "@embed": "@always",
53
+ });
54
54
 
55
- // Compact to use prefixed URIs
56
- const compacted = await jsonld.compact(framed, context);
57
- return compacted as Record<string, unknown>;
58
- }
55
+ // Compact to use prefixed URIs
56
+ const compacted = await jsonld.compact(framed, context);
57
+ return compacted as Record<string, unknown>;
58
+ }
59
59
 
60
- // Compact the full document
61
- const compacted = await jsonld.compact(
62
- { "@context": context, "@graph": jsonldDoc },
63
- context,
64
- );
60
+ // Compact the full document
61
+ const compacted = await jsonld.compact(
62
+ { "@context": context, "@graph": jsonldDoc },
63
+ context,
64
+ );
65
65
 
66
- return compacted as Record<string, unknown>;
66
+ return compacted as Record<string, unknown>;
67
67
  }
68
68
 
69
69
  /**
70
70
  * Convert n3 quads to N-Quads string format
71
71
  */
72
72
  function quadsToNQuads(
73
- quads: ReturnType<GraphStore["getQuads"]>,
73
+ quads: ReturnType<GraphStore["getQuads"]>,
74
74
  ): Promise<string> {
75
- return new Promise((resolve, reject) => {
76
- const writer = new Writer({ format: "N-Quads" });
75
+ return new Promise((resolve, reject) => {
76
+ const writer = new Writer({ format: "N-Quads" });
77
77
 
78
- for (const quad of quads) {
79
- writer.addQuad(quad);
80
- }
78
+ for (const quad of quads) {
79
+ writer.addQuad(quad);
80
+ }
81
81
 
82
- writer.end((error, result) => {
83
- if (error) reject(error);
84
- else resolve(result);
85
- });
86
- });
82
+ writer.end((error, result) => {
83
+ if (error) reject(error);
84
+ else resolve(result);
85
+ });
86
+ });
87
87
  }
@@ -5,71 +5,69 @@ import serializeToTurtle from "./TTLSerializer.js";
5
5
 
6
6
  const buttonUri = `${NAMESPACES.ds}button`;
7
7
  const globalUri = `${NAMESPACES.ds}global`;
8
- const componentType = `${NAMESPACES.dso}Component`;
8
+ const componentType = `${NAMESPACES.ds}Component`;
9
9
 
10
10
  function createPrefixMap(): PrefixMap {
11
- const prefixes = new PrefixMap();
12
- prefixes.add("ds", NAMESPACES.ds);
13
- prefixes.add("dso", NAMESPACES.dso);
14
- prefixes.add("rdf", NAMESPACES.rdf);
15
- return prefixes;
11
+ const prefixes = new PrefixMap();
12
+ prefixes.add("ds", NAMESPACES.ds);
13
+ prefixes.add("rdf", NAMESPACES.rdf);
14
+ return prefixes;
16
15
  }
17
16
 
18
17
  describe("serializeToTurtle", () => {
19
- it("should serialize empty store", async () => {
20
- const store = new GraphStore();
21
- const prefixes = new PrefixMap();
18
+ it("should serialize empty store", async () => {
19
+ const store = new GraphStore();
20
+ const prefixes = new PrefixMap();
22
21
 
23
- const ttl = await serializeToTurtle(store, { prefixes });
22
+ const ttl = await serializeToTurtle(store, { prefixes });
24
23
 
25
- expect(ttl).toBe("");
26
- });
24
+ expect(ttl).toBe("");
25
+ });
27
26
 
28
- it("should include prefix declarations", async () => {
29
- const store = new GraphStore();
30
- store.addQuad(buttonUri, PREDICATES.type, componentType);
27
+ it("should include prefix declarations", async () => {
28
+ const store = new GraphStore();
29
+ store.addQuad(buttonUri, PREDICATES.type, componentType);
31
30
 
32
- const prefixes = createPrefixMap();
33
- const ttl = await serializeToTurtle(store, { prefixes });
31
+ const prefixes = createPrefixMap();
32
+ const ttl = await serializeToTurtle(store, { prefixes });
34
33
 
35
- expect(ttl).toContain("@prefix ds:");
36
- expect(ttl).toContain("@prefix dso:");
37
- expect(ttl).toContain("@prefix rdf:");
38
- });
34
+ expect(ttl).toContain("@prefix ds:");
35
+ expect(ttl).toContain("@prefix rdf:");
36
+ });
39
37
 
40
- it("should serialize quads with URI objects", async () => {
41
- const store = new GraphStore();
42
- store.addQuad(buttonUri, PREDICATES.type, componentType);
43
- store.addQuad(buttonUri, PREDICATES.tier, globalUri);
38
+ it("should serialize quads with URI objects", async () => {
39
+ const store = new GraphStore();
40
+ store.addQuad(buttonUri, PREDICATES.type, componentType);
41
+ store.addQuad(buttonUri, PREDICATES.tier, globalUri);
44
42
 
45
- const prefixes = createPrefixMap();
46
- const ttl = await serializeToTurtle(store, { prefixes });
43
+ const prefixes = createPrefixMap();
44
+ const ttl = await serializeToTurtle(store, { prefixes });
47
45
 
48
- expect(ttl).toContain("ds:button");
49
- // n3 uses 'a' shorthand for rdf:type in Turtle
50
- expect(ttl).toMatch(/a |rdf:type/);
51
- expect(ttl).toContain("dso:Component");
52
- });
46
+ expect(ttl).toContain("ds:button");
47
+ // n3 uses 'a' shorthand for rdf:type in Turtle
48
+ expect(ttl).toMatch(/a |rdf:type/);
49
+ expect(ttl).toContain("ds:Component");
50
+ });
53
51
 
54
- it("should serialize quads with literal objects", async () => {
55
- const store = new GraphStore();
56
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
52
+ it("should serialize quads with literal objects", async () => {
53
+ const store = new GraphStore();
54
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
57
55
 
58
- const prefixes = createPrefixMap();
59
- const ttl = await serializeToTurtle(store, { prefixes });
56
+ const prefixes = createPrefixMap();
57
+ const ttl = await serializeToTurtle(store, { prefixes });
60
58
 
61
- expect(ttl).toContain('"Button"');
62
- });
59
+ expect(ttl).toContain('"Button"');
60
+ });
63
61
 
64
- it("should group statements by subject with semicolons", async () => {
65
- const store = new GraphStore();
66
- store.addQuad(buttonUri, PREDICATES.type, componentType);
67
- store.addLiteral(buttonUri, PREDICATES.name, "Button");
62
+ it("should group statements by subject with semicolons", async () => {
63
+ const store = new GraphStore();
64
+ store.addQuad(buttonUri, PREDICATES.type, componentType);
65
+ store.addLiteral(buttonUri, PREDICATES.name, "Button");
68
66
 
69
- const prefixes = createPrefixMap();
70
- const ttl = await serializeToTurtle(store, { prefixes });
67
+ const prefixes = createPrefixMap();
68
+ const ttl = await serializeToTurtle(store, { prefixes });
71
69
 
72
- // n3 Writer groups by subject and uses semicolons
73
- expect(ttl).toContain(";");
74
- });
70
+ // n3 Writer groups by subject and uses semicolons
71
+ expect(ttl).toContain(";");
72
+ });
75
73
  });
@@ -7,54 +7,61 @@ import type { SerializeOptions } from "./types.js";
7
7
  * Handles URIs with slashes that n3 won't auto-compact
8
8
  */
9
9
  function compactUris(turtle: string, prefixes: Record<string, string>): string {
10
- let result = turtle;
11
- for (const [prefix, namespace] of Object.entries(prefixes)) {
12
- // Replace <namespace...> with prefix:...
13
- const regex = new RegExp(`<${escapeRegex(namespace)}([^>]+)>`, "g");
14
- result = result.replace(regex, `${prefix}:$1`);
15
- }
16
- return result;
10
+ let result = turtle;
11
+ for (const [prefix, namespace] of Object.entries(prefixes)) {
12
+ // Replace <namespace...> with prefix:...
13
+ const regex = new RegExp(`<${escapeRegex(namespace)}([^>]+)>`, "g");
14
+ result = result.replace(regex, `${prefix}:$1`);
15
+ }
16
+ return result;
17
17
  }
18
18
 
19
19
  function escapeRegex(str: string): string {
20
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
20
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
21
21
  }
22
22
 
23
23
  /**
24
24
  * Convert named blank nodes to inline anonymous syntax
25
- * Transforms: `dso:hasProperty _:n3-0.` + `_:n3-0 a dso:Property; ...`
26
- * Into: `dso:hasProperty [ a dso:Property; ... ]`
25
+ * Transforms: `ds:hasProperty _:n3-0.` + `_:n3-0 a ds:Property; ...`
26
+ * Into: `ds:hasProperty [ a ds:Property; ... ]`
27
27
  */
28
28
  function inlineBlankNodes(turtle: string): string {
29
- // Find all blank node definitions (blocks starting with _:... and ending with .)
30
- // Pattern matches: _:id followed by content until a line ending with just "."
31
- const bnPattern = /^(_:[\w-]+)\s+([\s\S]*?)\.\n/gm;
32
- const blankNodes = new Map<string, string>();
29
+ // Find all blank node definitions (blocks starting with _:... and ending with .)
30
+ // Pattern matches: _:id followed by content until a line ending with just "."
31
+ const bnPattern = /^(_:[\w-]+)\s+([\s\S]*?)\.\n/gm;
32
+ const blankNodes = new Map<string, string>();
33
33
 
34
- let match;
35
- while ((match = bnPattern.exec(turtle)) !== null) {
36
- const bnId = match[1];
37
- const content = match[2].trim();
38
- // Format for inline: wrap in brackets with proper indentation
39
- const indentedContent = content.replace(/\n\s+/g, "\n ");
40
- blankNodes.set(bnId, `[\n ${indentedContent}\n ]`);
41
- }
34
+ let match: RegExpExecArray | null = bnPattern.exec(turtle);
35
+ while (match !== null) {
36
+ const bnId = match[1];
37
+ const content = match[2].trim();
38
+ // Format for inline: wrap in brackets with proper indentation
39
+ const indentedContent = content.replace(/\n\s+/g, "\n ");
40
+ blankNodes.set(bnId, `[\n ${indentedContent}\n ]`);
41
+ match = bnPattern.exec(turtle);
42
+ }
42
43
 
43
- if (blankNodes.size === 0) {
44
- return turtle;
45
- }
44
+ if (blankNodes.size === 0) {
45
+ return turtle;
46
+ }
46
47
 
47
- let result = turtle;
48
+ let result = turtle;
48
49
 
49
- // Replace references to blank nodes with inline syntax
50
- for (const [bnId, inlineContent] of blankNodes) {
51
- // Replace references like "_:n3-0" or "_:n3-0," or "_:n3-0."
52
- result = result.replace(new RegExp(`${escapeRegex(bnId)}([,.;])`, "g"), `${inlineContent}$1`);
53
- // Remove the standalone blank node definition block
54
- result = result.replace(new RegExp(`^${escapeRegex(bnId)}\\s+[\\s\\S]*?\\.\n`, "gm"), "");
55
- }
50
+ // Replace references to blank nodes with inline syntax
51
+ for (const [bnId, inlineContent] of blankNodes) {
52
+ // Replace references like "_:n3-0" or "_:n3-0," or "_:n3-0."
53
+ result = result.replace(
54
+ new RegExp(`${escapeRegex(bnId)}([,.;])`, "g"),
55
+ `${inlineContent}$1`,
56
+ );
57
+ // Remove the standalone blank node definition block
58
+ result = result.replace(
59
+ new RegExp(`^${escapeRegex(bnId)}\\s+[\\s\\S]*?\\.\n`, "gm"),
60
+ "",
61
+ );
62
+ }
56
63
 
57
- return result.trim() + "\n";
64
+ return `${result.trim()}\n`;
58
65
  }
59
66
 
60
67
  /**
@@ -66,34 +73,34 @@ function inlineBlankNodes(turtle: string): string {
66
73
  * - Proper indentation
67
74
  */
68
75
  export default function serializeToTurtle(
69
- store: GraphStore,
70
- options: SerializeOptions,
76
+ store: GraphStore,
77
+ options: SerializeOptions,
71
78
  ): Promise<string> {
72
- return new Promise((resolve, reject) => {
73
- const quads = store.getQuads();
79
+ return new Promise((resolve, reject) => {
80
+ const quads = store.getQuads();
74
81
 
75
- if (quads.length === 0) {
76
- resolve("");
77
- return;
78
- }
82
+ if (quads.length === 0) {
83
+ resolve("");
84
+ return;
85
+ }
79
86
 
80
- const writer = new Writer({
81
- prefixes: options.prefixes.toRecord(),
82
- });
87
+ const writer = new Writer({
88
+ prefixes: options.prefixes.toRecord(),
89
+ });
83
90
 
84
- for (const quad of quads) {
85
- writer.addQuad(quad);
86
- }
91
+ for (const quad of quads) {
92
+ writer.addQuad(quad);
93
+ }
87
94
 
88
- writer.end((error, result) => {
89
- if (error) {
90
- reject(error);
91
- } else {
92
- // Post-process: compact URIs and inline blank nodes
93
- let processed = compactUris(result, options.prefixes.toRecord());
94
- processed = inlineBlankNodes(processed);
95
- resolve(processed);
96
- }
97
- });
98
- });
95
+ writer.end((error, result) => {
96
+ if (error) {
97
+ reject(error);
98
+ } else {
99
+ // Post-process: compact URIs and inline blank nodes
100
+ let processed = compactUris(result, options.prefixes.toRecord());
101
+ processed = inlineBlankNodes(processed);
102
+ resolve(processed);
103
+ }
104
+ });
105
+ });
99
106
  }
@@ -1,3 +1,6 @@
1
+ export {
2
+ default as serializeToJsonLd,
3
+ type JsonLdSerializeOptions,
4
+ } from "./JSONSerializer.js";
1
5
  export { default as serializeToTurtle } from "./TTLSerializer.js";
2
- export { default as serializeToJsonLd, type JsonLdSerializeOptions } from "./JSONSerializer.js";
3
6
  export type { SerializeOptions, Serializer } from "./types.js";
@@ -4,13 +4,13 @@ import type { GraphStore, PrefixMap } from "../graph/index.js";
4
4
  * Options for serialization
5
5
  */
6
6
  export interface SerializeOptions {
7
- prefixes: PrefixMap;
7
+ prefixes: PrefixMap;
8
8
  }
9
9
 
10
10
  /**
11
11
  * Serializer function type
12
12
  */
13
13
  export type Serializer = (
14
- store: GraphStore,
15
- options: SerializeOptions,
14
+ store: GraphStore,
15
+ options: SerializeOptions,
16
16
  ) => Promise<string>;