nebula-cms 0.1.3 → 0.1.4
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 +2 -0
- package/dist/astro/index.d.ts +43 -0
- package/dist/astro/index.d.ts.map +1 -0
- package/dist/astro/index.js +223 -0
- package/dist/client/Admin.svelte.d.ts +11 -0
- package/dist/client/Admin.svelte.d.ts.map +1 -0
- package/dist/client/components/BackendPicker.svelte.d.ts +4 -0
- package/dist/client/components/BackendPicker.svelte.d.ts.map +1 -0
- package/dist/client/components/DraftChip.svelte.d.ts +10 -0
- package/dist/client/components/DraftChip.svelte.d.ts.map +1 -0
- package/dist/client/components/MetadataForm.svelte.d.ts +12 -0
- package/dist/client/components/MetadataForm.svelte.d.ts.map +1 -0
- package/dist/client/components/ThemeToggle.svelte.d.ts +19 -0
- package/dist/client/components/ThemeToggle.svelte.d.ts.map +1 -0
- package/dist/client/components/dialogs/DeleteDraftDialog.svelte.d.ts +11 -0
- package/dist/client/components/dialogs/DeleteDraftDialog.svelte.d.ts.map +1 -0
- package/dist/client/components/dialogs/FilenameDialog.svelte.d.ts +13 -0
- package/dist/client/components/dialogs/FilenameDialog.svelte.d.ts.map +1 -0
- package/dist/client/components/editor/EditorPane.svelte.d.ts +4 -0
- package/dist/client/components/editor/EditorPane.svelte.d.ts.map +1 -0
- package/dist/client/components/editor/EditorTabs.svelte.d.ts +8 -0
- package/dist/client/components/editor/EditorTabs.svelte.d.ts.map +1 -0
- package/dist/client/components/editor/EditorToolbar.svelte.d.ts +4 -0
- package/dist/client/components/editor/EditorToolbar.svelte.d.ts.map +1 -0
- package/dist/client/components/editor/FormatSelector.svelte.d.ts +4 -0
- package/dist/client/components/editor/FormatSelector.svelte.d.ts.map +1 -0
- package/dist/client/components/editor/Toolbar.svelte.d.ts +19 -0
- package/dist/client/components/editor/Toolbar.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/ArrayField.svelte.d.ts +15 -0
- package/dist/client/components/fields/ArrayField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/ArrayItem.svelte.d.ts +28 -0
- package/dist/client/components/fields/ArrayItem.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/BooleanField.svelte.d.ts +16 -0
- package/dist/client/components/fields/BooleanField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/DateField.svelte.d.ts +16 -0
- package/dist/client/components/fields/DateField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/EnumField.svelte.d.ts +17 -0
- package/dist/client/components/fields/EnumField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/FieldWrapper.svelte.d.ts +18 -0
- package/dist/client/components/fields/FieldWrapper.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/NumberField.svelte.d.ts +16 -0
- package/dist/client/components/fields/NumberField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/ObjectField.svelte.d.ts +16 -0
- package/dist/client/components/fields/ObjectField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/SchemaField.svelte.d.ts +16 -0
- package/dist/client/components/fields/SchemaField.svelte.d.ts.map +1 -0
- package/dist/client/components/fields/StringField.svelte.d.ts +16 -0
- package/dist/client/components/fields/StringField.svelte.d.ts.map +1 -0
- package/dist/client/components/sidebar/AdminSidebar.svelte.d.ts +19 -0
- package/dist/client/components/sidebar/AdminSidebar.svelte.d.ts.map +1 -0
- package/dist/client/components/sidebar/AdminSidebarSort.svelte.d.ts +12 -0
- package/dist/client/components/sidebar/AdminSidebarSort.svelte.d.ts.map +1 -0
- package/dist/client/css/icons.css +29 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/js/drafts/merge.svelte.d.ts +24 -0
- package/dist/client/js/drafts/merge.svelte.d.ts.map +1 -0
- package/dist/client/js/drafts/merge.svelte.js +106 -0
- package/dist/client/js/drafts/ops.svelte.d.ts +31 -0
- package/dist/client/js/drafts/ops.svelte.d.ts.map +1 -0
- package/dist/client/js/drafts/ops.svelte.js +182 -0
- package/dist/client/js/drafts/storage.d.ts +45 -0
- package/dist/client/js/drafts/storage.d.ts.map +1 -0
- package/dist/client/js/drafts/storage.js +76 -0
- package/dist/client/js/drafts/workers/diff.d.ts +2 -0
- package/dist/client/js/drafts/workers/diff.d.ts.map +1 -0
- package/dist/client/js/drafts/workers/diff.js +20 -0
- package/dist/client/js/editor/editor.svelte.d.ts +124 -0
- package/dist/client/js/editor/editor.svelte.d.ts.map +1 -0
- package/dist/client/js/editor/editor.svelte.js +294 -0
- package/dist/client/js/editor/languages.d.ts +11 -0
- package/dist/client/js/editor/languages.d.ts.map +1 -0
- package/dist/client/js/editor/languages.js +93 -0
- package/dist/client/js/editor/link-wrap.d.ts +6 -0
- package/dist/client/js/editor/link-wrap.d.ts.map +1 -0
- package/{src/client/js/editor/link-wrap.ts → dist/client/js/editor/link-wrap.js} +17 -24
- package/dist/client/js/editor/markdown-shortcuts.d.ts +4 -0
- package/dist/client/js/editor/markdown-shortcuts.d.ts.map +1 -0
- package/dist/client/js/editor/markdown-shortcuts.js +219 -0
- package/dist/client/js/handlers/admin.d.ts +64 -0
- package/dist/client/js/handlers/admin.d.ts.map +1 -0
- package/dist/client/js/handlers/admin.js +186 -0
- package/dist/client/js/state/dialogs.svelte.d.ts +16 -0
- package/dist/client/js/state/dialogs.svelte.d.ts.map +1 -0
- package/dist/client/js/state/dialogs.svelte.js +28 -0
- package/dist/client/js/state/router.svelte.d.ts +44 -0
- package/dist/client/js/state/router.svelte.d.ts.map +1 -0
- package/dist/client/js/state/router.svelte.js +135 -0
- package/dist/client/js/state/schema.svelte.d.ts +51 -0
- package/dist/client/js/state/schema.svelte.d.ts.map +1 -0
- package/{src/client/js/state/schema.svelte.ts → dist/client/js/state/schema.svelte.js} +55 -70
- package/dist/client/js/state/state.svelte.d.ts +68 -0
- package/dist/client/js/state/state.svelte.d.ts.map +1 -0
- package/dist/client/js/state/state.svelte.js +291 -0
- package/dist/client/js/state/theme.svelte.d.ts +24 -0
- package/dist/client/js/state/theme.svelte.d.ts.map +1 -0
- package/{src/client/js/state/theme.svelte.ts → dist/client/js/state/theme.svelte.js} +54 -91
- package/dist/client/js/storage/adapter.d.ts +130 -0
- package/dist/client/js/storage/adapter.d.ts.map +1 -0
- package/dist/client/js/storage/adapter.js +5 -0
- package/dist/client/js/storage/client.d.ts +72 -0
- package/dist/client/js/storage/client.d.ts.map +1 -0
- package/dist/client/js/storage/client.js +121 -0
- package/dist/client/js/storage/db.d.ts +8 -0
- package/dist/client/js/storage/db.d.ts.map +1 -0
- package/dist/client/js/storage/db.js +35 -0
- package/dist/client/js/storage/fsa.d.ts +51 -0
- package/dist/client/js/storage/fsa.d.ts.map +1 -0
- package/dist/client/js/storage/fsa.js +91 -0
- package/dist/client/js/storage/github.d.ts +62 -0
- package/dist/client/js/storage/github.d.ts.map +1 -0
- package/dist/client/js/storage/github.js +216 -0
- package/dist/client/js/storage/storage.d.ts +32 -0
- package/dist/client/js/storage/storage.d.ts.map +1 -0
- package/dist/client/js/storage/storage.js +68 -0
- package/dist/client/js/storage/workers/frontmatter.d.ts +2 -0
- package/dist/client/js/storage/workers/frontmatter.d.ts.map +1 -0
- package/dist/client/js/storage/workers/frontmatter.js +253 -0
- package/dist/client/js/storage/workers/storage.d.ts +2 -0
- package/dist/client/js/storage/workers/storage.d.ts.map +1 -0
- package/dist/client/js/storage/workers/storage.js +167 -0
- package/dist/client/js/storage/workers/toml-parser.d.ts +2 -0
- package/dist/client/js/storage/workers/toml-parser.d.ts.map +1 -0
- package/dist/client/js/storage/workers/toml-parser.js +75 -0
- package/dist/client/js/storage/workers/yaml-parser.d.ts +2 -0
- package/dist/client/js/storage/workers/yaml-parser.d.ts.map +1 -0
- package/dist/client/js/storage/workers/yaml-parser.js +100 -0
- package/dist/client/js/utils/file-types.d.ts +58 -0
- package/dist/client/js/utils/file-types.d.ts.map +1 -0
- package/{src/client/js/utils/file-types.ts → dist/client/js/utils/file-types.js} +75 -107
- package/dist/client/js/utils/format.d.ts +8 -0
- package/dist/client/js/utils/format.d.ts.map +1 -0
- package/{src/client/js/utils/format.ts → dist/client/js/utils/format.js} +5 -6
- package/dist/client/js/utils/frontmatter.d.ts +12 -0
- package/dist/client/js/utils/frontmatter.d.ts.map +1 -0
- package/dist/client/js/utils/frontmatter.js +29 -0
- package/dist/client/js/utils/schema-utils.d.ts +110 -0
- package/dist/client/js/utils/schema-utils.d.ts.map +1 -0
- package/dist/client/js/utils/schema-utils.js +242 -0
- package/dist/client/js/utils/slug.d.ts +8 -0
- package/dist/client/js/utils/slug.d.ts.map +1 -0
- package/{src/client/js/utils/slug.ts → dist/client/js/utils/slug.js} +6 -7
- package/dist/client/js/utils/sort.d.ts +41 -0
- package/dist/client/js/utils/sort.d.ts.map +1 -0
- package/dist/client/js/utils/sort.js +65 -0
- package/dist/client/js/utils/stable-stringify.d.ts +8 -0
- package/dist/client/js/utils/stable-stringify.d.ts.map +1 -0
- package/dist/client/js/utils/stable-stringify.js +23 -0
- package/dist/client/js/utils/url-utils.d.ts +11 -0
- package/dist/client/js/utils/url-utils.d.ts.map +1 -0
- package/{src/client/js/utils/url-utils.ts → dist/client/js/utils/url-utils.js} +22 -23
- package/dist/types.d.ts +22 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +4 -1
- package/.github/workflows/ci.yml +0 -27
- package/.github/workflows/publish.yml +0 -34
- package/.mcp.json +0 -12
- package/.prettierignore +0 -5
- package/.prettierrc.cjs +0 -22
- package/AGENTS.md +0 -183
- package/playground/astro.config.mjs +0 -7
- package/playground/node_modules/.bin/astro +0 -21
- package/playground/node_modules/.vite/deps/@astrojs_svelte_client__js.js +0 -85
- package/playground/node_modules/.vite/deps/@astrojs_svelte_client__js.js.map +0 -7
- package/playground/node_modules/.vite/deps/_metadata.json +0 -184
- package/playground/node_modules/.vite/deps/astro___aria-query.js +0 -6776
- package/playground/node_modules/.vite/deps/astro___aria-query.js.map +0 -7
- package/playground/node_modules/.vite/deps/astro___axobject-query.js +0 -3754
- package/playground/node_modules/.vite/deps/astro___axobject-query.js.map +0 -7
- package/playground/node_modules/.vite/deps/astro___html-escaper.js +0 -34
- package/playground/node_modules/.vite/deps/astro___html-escaper.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-AJXJMYAF.js +0 -0
- package/playground/node_modules/.vite/deps/chunk-AJXJMYAF.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-BUSYA2B4.js +0 -8
- package/playground/node_modules/.vite/deps/chunk-BUSYA2B4.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-CNYJBM5F.js +0 -21
- package/playground/node_modules/.vite/deps/chunk-CNYJBM5F.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-DBPNBGEI.js +0 -223
- package/playground/node_modules/.vite/deps/chunk-DBPNBGEI.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-FPEUJ7DG.js +0 -27
- package/playground/node_modules/.vite/deps/chunk-FPEUJ7DG.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-MHDZ3SK7.js +0 -1005
- package/playground/node_modules/.vite/deps/chunk-MHDZ3SK7.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-RBDTDTPY.js +0 -204
- package/playground/node_modules/.vite/deps/chunk-RBDTDTPY.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-RJGEXL5C.js +0 -688
- package/playground/node_modules/.vite/deps/chunk-RJGEXL5C.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-YL4MIWGJ.js +0 -5099
- package/playground/node_modules/.vite/deps/chunk-YL4MIWGJ.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-ZOV3DWEJ.js +0 -4376
- package/playground/node_modules/.vite/deps/chunk-ZOV3DWEJ.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-ZP4UNCSN.js +0 -23
- package/playground/node_modules/.vite/deps/chunk-ZP4UNCSN.js.map +0 -7
- package/playground/node_modules/.vite/deps/chunk-ZREFNRZZ.js +0 -148
- package/playground/node_modules/.vite/deps/chunk-ZREFNRZZ.js.map +0 -7
- package/playground/node_modules/.vite/deps/package.json +0 -3
- package/playground/node_modules/.vite/deps/smol-toml.js +0 -843
- package/playground/node_modules/.vite/deps/smol-toml.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte.js +0 -55
- package/playground/node_modules/.vite/deps/svelte.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte___clsx.js +0 -9
- package/playground/node_modules/.vite/deps/svelte___clsx.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_animate.js +0 -57
- package/playground/node_modules/.vite/deps/svelte_animate.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_attachments.js +0 -15
- package/playground/node_modules/.vite/deps/svelte_attachments.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_easing.js +0 -67
- package/playground/node_modules/.vite/deps/svelte_easing.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_events.js +0 -11
- package/playground/node_modules/.vite/deps/svelte_events.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal.js +0 -5
- package/playground/node_modules/.vite/deps/svelte_internal.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal_client.js +0 -402
- package/playground/node_modules/.vite/deps/svelte_internal_client.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal_disclose-version.js +0 -10
- package/playground/node_modules/.vite/deps/svelte_internal_disclose-version.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal_flags_async.js +0 -8
- package/playground/node_modules/.vite/deps/svelte_internal_flags_async.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal_flags_legacy.js +0 -8
- package/playground/node_modules/.vite/deps/svelte_internal_flags_legacy.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_internal_flags_tracing.js +0 -8
- package/playground/node_modules/.vite/deps/svelte_internal_flags_tracing.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_legacy.js +0 -35
- package/playground/node_modules/.vite/deps/svelte_legacy.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_motion.js +0 -545
- package/playground/node_modules/.vite/deps/svelte_motion.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_reactivity.js +0 -29
- package/playground/node_modules/.vite/deps/svelte_reactivity.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_reactivity_window.js +0 -127
- package/playground/node_modules/.vite/deps/svelte_reactivity_window.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_store.js +0 -103
- package/playground/node_modules/.vite/deps/svelte_store.js.map +0 -7
- package/playground/node_modules/.vite/deps/svelte_transition.js +0 -208
- package/playground/node_modules/.vite/deps/svelte_transition.js.map +0 -7
- package/playground/package.json +0 -16
- package/playground/pnpm-lock.yaml +0 -3167
- package/playground/src/content/authors/jane-doe.json +0 -8
- package/playground/src/content/config/build.toml +0 -2
- package/playground/src/content/courses/web-fundamentals.json +0 -29
- package/playground/src/content/docs/advanced.mdx +0 -6
- package/playground/src/content/docs/intro.md +0 -6
- package/playground/src/content/guides/getting-started.mdx +0 -6
- package/playground/src/content/posts/hello-world.md +0 -7
- package/playground/src/content/products/t-shirt.json +0 -16
- package/playground/src/content/recipes/pancakes.mdoc +0 -8
- package/playground/src/content/settings/site.yml +0 -2
- package/playground/src/content.config.ts +0 -198
- package/playground/src/env.d.ts +0 -1
- package/playground/src/pages/index.astro +0 -11
- package/playground/src/pages/nebula.astro +0 -14
- package/pnpm-workspace.yaml +0 -2
- package/scripts/subset-icons.mjs +0 -178
- package/src/astro/index.ts +0 -295
- package/src/client/js/drafts/merge.svelte.ts +0 -121
- package/src/client/js/drafts/ops.svelte.ts +0 -227
- package/src/client/js/drafts/storage.ts +0 -108
- package/src/client/js/drafts/workers/diff.ts +0 -40
- package/src/client/js/editor/editor.svelte.ts +0 -343
- package/src/client/js/editor/languages.ts +0 -98
- package/src/client/js/editor/markdown-shortcuts.ts +0 -261
- package/src/client/js/handlers/admin.ts +0 -246
- package/src/client/js/state/dialogs.svelte.ts +0 -35
- package/src/client/js/state/router.svelte.ts +0 -156
- package/src/client/js/state/state.svelte.ts +0 -334
- package/src/client/js/storage/adapter.ts +0 -102
- package/src/client/js/storage/client.ts +0 -150
- package/src/client/js/storage/db.ts +0 -36
- package/src/client/js/storage/fsa.ts +0 -110
- package/src/client/js/storage/github.ts +0 -297
- package/src/client/js/storage/storage.ts +0 -83
- package/src/client/js/storage/workers/frontmatter.ts +0 -320
- package/src/client/js/storage/workers/storage.ts +0 -177
- package/src/client/js/storage/workers/toml-parser.ts +0 -106
- package/src/client/js/storage/workers/yaml-parser.ts +0 -132
- package/src/client/js/utils/frontmatter.ts +0 -38
- package/src/client/js/utils/schema-utils.ts +0 -295
- package/src/client/js/utils/sort.ts +0 -84
- package/src/client/js/utils/stable-stringify.ts +0 -27
- package/src/types.ts +0 -25
- package/svelte.config.js +0 -4
- package/tests/astro/build.test.ts +0 -63
- package/tests/astro/index.test.ts +0 -689
- package/tests/client/components/Admin.test.ts +0 -446
- package/tests/client/components/BackendPicker.test.ts +0 -239
- package/tests/client/components/DraftChip.test.ts +0 -53
- package/tests/client/components/MetadataForm.test.ts +0 -164
- package/tests/client/components/dialogs/DeleteDraftDialog.test.ts +0 -91
- package/tests/client/components/dialogs/FilenameDialog.test.ts +0 -209
- package/tests/client/components/dialogs/dialog-stubs.ts +0 -19
- package/tests/client/components/editor/EditorPane.test.ts +0 -100
- package/tests/client/components/editor/EditorTabs.test.ts +0 -253
- package/tests/client/components/editor/EditorToolbar.test.ts +0 -252
- package/tests/client/components/editor/fixtures.ts +0 -31
- package/tests/client/components/fields/ArrayField.test.ts +0 -197
- package/tests/client/components/fields/BooleanField.test.ts +0 -206
- package/tests/client/components/fields/DateField.test.ts +0 -210
- package/tests/client/components/fields/EnumField.test.ts +0 -246
- package/tests/client/components/fields/NumberField.test.ts +0 -240
- package/tests/client/components/fields/ObjectField.test.ts +0 -157
- package/tests/client/components/fields/SchemaField.test.ts +0 -190
- package/tests/client/components/fields/StringField.test.ts +0 -223
- package/tests/client/components/sidebar/AdminSidebar.test.ts +0 -285
- package/tests/client/components/sidebar/AdminSidebarSort.test.ts +0 -135
- package/tests/client/components/sidebar/sort-mock.ts +0 -23
- package/tests/client/js/drafts/fixtures.ts +0 -22
- package/tests/client/js/drafts/merge.test.ts +0 -282
- package/tests/client/js/drafts/ops.test.ts +0 -658
- package/tests/client/js/drafts/storage.test.ts +0 -200
- package/tests/client/js/drafts/workers/diff.test.ts +0 -165
- package/tests/client/js/editor/editor.test.ts +0 -616
- package/tests/client/js/editor/link-wrap.test.ts +0 -225
- package/tests/client/js/editor/markdown-shortcuts.test.ts +0 -370
- package/tests/client/js/handlers/admin.test.ts +0 -467
- package/tests/client/js/state/router.test.ts +0 -619
- package/tests/client/js/state/schema.test.ts +0 -266
- package/tests/client/js/state/state.test.ts +0 -328
- package/tests/client/js/storage/adapter.test.ts +0 -115
- package/tests/client/js/storage/client.test.ts +0 -250
- package/tests/client/js/storage/db.test.ts +0 -59
- package/tests/client/js/storage/fsa.test.ts +0 -284
- package/tests/client/js/storage/github.test.ts +0 -349
- package/tests/client/js/storage/mock-port.ts +0 -95
- package/tests/client/js/storage/storage.test.ts +0 -77
- package/tests/client/js/storage/workers/frontmatter.test.ts +0 -479
- package/tests/client/js/storage/workers/storage.test.ts +0 -299
- package/tests/client/js/storage/workers/toml-parser.test.ts +0 -169
- package/tests/client/js/storage/workers/yaml-parser.test.ts +0 -168
- package/tests/client/js/utils/file-types.test.ts +0 -268
- package/tests/client/js/utils/frontmatter.test.ts +0 -87
- package/tests/client/js/utils/schema-utils.test.ts +0 -318
- package/tests/client/js/utils/slug.test.ts +0 -58
- package/tests/client/js/utils/sort.test.ts +0 -276
- package/tests/client/js/utils/stable-stringify.test.ts +0 -68
- package/tests/client/js/utils/url-utils.test.ts +0 -70
- package/tests/e2e/backend-connection.test.ts +0 -301
- package/tests/e2e/draft-lifecycle.test.ts +0 -388
- package/tests/e2e/editing.test.ts +0 -355
- package/tests/e2e/github-adapter.test.ts +0 -330
- package/tests/e2e/helpers/mock-adapter.ts +0 -166
- package/tests/e2e/helpers/test-app.ts +0 -155
- package/tests/e2e/navigation.test.ts +0 -358
- package/tests/e2e/publishing.test.ts +0 -345
- package/tests/e2e/unsaved-changes.test.ts +0 -317
- package/tests/setup.ts +0 -2
- package/tests/stubs/codemirror.ts +0 -197
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -178
- /package/{src → dist}/client/Admin.svelte +0 -0
- /package/{src → dist}/client/components/BackendPicker.svelte +0 -0
- /package/{src → dist}/client/components/DraftChip.svelte +0 -0
- /package/{src → dist}/client/components/MetadataForm.svelte +0 -0
- /package/{src → dist}/client/components/ThemeToggle.svelte +0 -0
- /package/{src → dist}/client/components/dialogs/DeleteDraftDialog.svelte +0 -0
- /package/{src → dist}/client/components/dialogs/FilenameDialog.svelte +0 -0
- /package/{src → dist}/client/components/editor/EditorPane.svelte +0 -0
- /package/{src → dist}/client/components/editor/EditorTabs.svelte +0 -0
- /package/{src → dist}/client/components/editor/EditorToolbar.svelte +0 -0
- /package/{src → dist}/client/components/editor/FormatSelector.svelte +0 -0
- /package/{src → dist}/client/components/editor/Toolbar.svelte +0 -0
- /package/{src → dist}/client/components/fields/ArrayField.svelte +0 -0
- /package/{src → dist}/client/components/fields/ArrayItem.svelte +0 -0
- /package/{src → dist}/client/components/fields/BooleanField.svelte +0 -0
- /package/{src → dist}/client/components/fields/DateField.svelte +0 -0
- /package/{src → dist}/client/components/fields/EnumField.svelte +0 -0
- /package/{src → dist}/client/components/fields/FieldWrapper.svelte +0 -0
- /package/{src → dist}/client/components/fields/NumberField.svelte +0 -0
- /package/{src → dist}/client/components/fields/ObjectField.svelte +0 -0
- /package/{src → dist}/client/components/fields/SchemaField.svelte +0 -0
- /package/{src → dist}/client/components/fields/StringField.svelte +0 -0
- /package/{src → dist}/client/components/sidebar/AdminSidebar.svelte +0 -0
- /package/{src → dist}/client/components/sidebar/AdminSidebarSort.svelte +0 -0
- /package/{src → dist}/client/css/a11y.css +0 -0
- /package/{src → dist}/client/css/btn.css +0 -0
- /package/{src → dist}/client/css/dialog.css +0 -0
- /package/{src → dist}/client/css/field-input.css +0 -0
- /package/{src → dist}/client/css/reset.css +0 -0
- /package/{src → dist}/client/css/theme.css +0 -0
- /package/{src/client/index.ts → dist/client/index.js} +0 -0
- /package/{src → dist}/virtual.d.ts +0 -0
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Storage adapter backed by the File System Access API.
|
|
3
|
-
* Traverses from a project root handle through src/content/{collection}/ for all operations.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { StorageAdapter, FileEntry, FileWrite } from './adapter';
|
|
7
|
-
|
|
8
|
-
// FSA adapter implementation
|
|
9
|
-
export class FsaAdapter implements StorageAdapter {
|
|
10
|
-
/**
|
|
11
|
-
* Creates an FSA adapter rooted at the given directory handle.
|
|
12
|
-
* @param {FileSystemDirectoryHandle} root - The project root directory handle
|
|
13
|
-
*/
|
|
14
|
-
constructor(private root: FileSystemDirectoryHandle) {}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Traverses root → src → content → {collection}.
|
|
18
|
-
* @param {string} collection - The collection name
|
|
19
|
-
* @return {Promise<FileSystemDirectoryHandle>} The collection directory handle
|
|
20
|
-
*/
|
|
21
|
-
private async getCollectionDir(
|
|
22
|
-
collection: string,
|
|
23
|
-
): Promise<FileSystemDirectoryHandle> {
|
|
24
|
-
const src = await this.root.getDirectoryHandle('src');
|
|
25
|
-
const content = await src.getDirectoryHandle('content');
|
|
26
|
-
return content.getDirectoryHandle(collection);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Lists files in the collection matching the given extensions, with their content.
|
|
31
|
-
* @param {string} collection - The collection name
|
|
32
|
-
* @param {string[]} extensions - File extensions to include (e.g. ['.md', '.mdx'])
|
|
33
|
-
* @return {Promise<FileEntry[]>} Array of filename + content pairs
|
|
34
|
-
*/
|
|
35
|
-
async listFiles(
|
|
36
|
-
collection: string,
|
|
37
|
-
extensions: string[],
|
|
38
|
-
): Promise<FileEntry[]> {
|
|
39
|
-
const dir = await this.getCollectionDir(collection);
|
|
40
|
-
const entries: FileEntry[] = [];
|
|
41
|
-
|
|
42
|
-
for await (const [name, entry] of dir.entries()) {
|
|
43
|
-
if (
|
|
44
|
-
entry.kind !== 'file' ||
|
|
45
|
-
!extensions.some((ext) => name.endsWith(ext))
|
|
46
|
-
) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const file = await entry.getFile();
|
|
50
|
-
const content = await file.text();
|
|
51
|
-
entries.push({ filename: name, content });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return entries;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Deletes a file from the collection directory.
|
|
59
|
-
* @param {string} collection - The collection name
|
|
60
|
-
* @param {string} filename - The filename to delete
|
|
61
|
-
* @return {Promise<void>}
|
|
62
|
-
*/
|
|
63
|
-
async deleteFile(collection: string, filename: string): Promise<void> {
|
|
64
|
-
const dir = await this.getCollectionDir(collection);
|
|
65
|
-
await dir.removeEntry(filename);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reads a single file's content from the collection.
|
|
70
|
-
* @param {string} collection - The collection name
|
|
71
|
-
* @param {string} filename - The filename
|
|
72
|
-
* @return {Promise<string>} The file content
|
|
73
|
-
*/
|
|
74
|
-
async readFile(collection: string, filename: string): Promise<string> {
|
|
75
|
-
const dir = await this.getCollectionDir(collection);
|
|
76
|
-
const fileHandle = await dir.getFileHandle(filename);
|
|
77
|
-
const file = await fileHandle.getFile();
|
|
78
|
-
return file.text();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Writes content to a file, creating it if necessary.
|
|
83
|
-
* @param {string} collection - The collection name
|
|
84
|
-
* @param {string} filename - The filename
|
|
85
|
-
* @param {string} content - The content to write
|
|
86
|
-
* @return {Promise<void>}
|
|
87
|
-
*/
|
|
88
|
-
async writeFile(
|
|
89
|
-
collection: string,
|
|
90
|
-
filename: string,
|
|
91
|
-
content: string,
|
|
92
|
-
): Promise<void> {
|
|
93
|
-
const dir = await this.getCollectionDir(collection);
|
|
94
|
-
const fileHandle = await dir.getFileHandle(filename, { create: true });
|
|
95
|
-
const writable = await fileHandle.createWritable();
|
|
96
|
-
await writable.write(content);
|
|
97
|
-
await writable.close();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Writes multiple files sequentially (FSA has no atomic multi-file write).
|
|
102
|
-
* @param {FileWrite[]} files - Array of files to write
|
|
103
|
-
* @return {Promise<void>}
|
|
104
|
-
*/
|
|
105
|
-
async writeFiles(files: FileWrite[]): Promise<void> {
|
|
106
|
-
for (const f of files) {
|
|
107
|
-
await this.writeFile(f.collection, f.filename, f.content);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Storage adapter backed by the GitHub REST API.
|
|
3
|
-
* Uses a Personal Access Token for authentication. All file operations
|
|
4
|
-
* target src/content/{collection}/ within the repository.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { StorageAdapter, FileEntry, FileWrite } from './adapter';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Encodes a Uint8Array to a base64 string without using deprecated unescape().
|
|
11
|
-
* @param {Uint8Array} bytes - The bytes to encode
|
|
12
|
-
* @return {string} Base64-encoded string
|
|
13
|
-
*/
|
|
14
|
-
function uint8ToBase64(bytes: Uint8Array): string {
|
|
15
|
-
let binary = '';
|
|
16
|
-
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
17
|
-
return btoa(binary);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class GitHubAdapter implements StorageAdapter {
|
|
21
|
-
private token: string;
|
|
22
|
-
private owner: string;
|
|
23
|
-
private repo: string;
|
|
24
|
-
// Cached on validate(); defaults to 'main' before validation
|
|
25
|
-
private defaultBranch: string = 'main';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} token - GitHub Personal Access Token
|
|
29
|
-
* @param {string} repoSlug - Repository in "owner/repo" format
|
|
30
|
-
*/
|
|
31
|
-
constructor(token: string, repoSlug: string) {
|
|
32
|
-
this.token = token;
|
|
33
|
-
const [owner, repo] = repoSlug.split('/');
|
|
34
|
-
this.owner = owner;
|
|
35
|
-
this.repo = repo;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Validates credentials by fetching repo metadata and caches the default branch.
|
|
40
|
-
* @return {Promise<void>}
|
|
41
|
-
*/
|
|
42
|
-
async validate(): Promise<void> {
|
|
43
|
-
const res = await this.request('GET', `/repos/${this.owner}/${this.repo}`);
|
|
44
|
-
if (!res.ok) {
|
|
45
|
-
const status = res.status;
|
|
46
|
-
if (status === 401) throw new Error('Invalid or expired token');
|
|
47
|
-
if (status === 403) throw new Error('Token lacks repository access');
|
|
48
|
-
if (status === 404)
|
|
49
|
-
throw new Error(`Repository "${this.owner}/${this.repo}" not found`);
|
|
50
|
-
throw new Error(`GitHub API error: ${status}`);
|
|
51
|
-
}
|
|
52
|
-
const data = await res.json();
|
|
53
|
-
this.defaultBranch = data.default_branch;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Lists files in a collection matching the given extensions, with their raw content.
|
|
58
|
-
* @param {string} collection - The collection name
|
|
59
|
-
* @param {string[]} extensions - File extensions to include (e.g. ['.md', '.mdx'])
|
|
60
|
-
* @return {Promise<FileEntry[]>} Array of filename + content pairs
|
|
61
|
-
*/
|
|
62
|
-
async listFiles(
|
|
63
|
-
collection: string,
|
|
64
|
-
extensions: string[],
|
|
65
|
-
): Promise<FileEntry[]> {
|
|
66
|
-
const path = `src/content/${collection}`;
|
|
67
|
-
// Get directory listing
|
|
68
|
-
const listRes = await this.request(
|
|
69
|
-
'GET',
|
|
70
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}?ref=${this.defaultBranch}`,
|
|
71
|
-
);
|
|
72
|
-
if (!listRes.ok) {
|
|
73
|
-
if (listRes.status === 404) return [];
|
|
74
|
-
throw new Error(`Failed to list files: ${listRes.status}`);
|
|
75
|
-
}
|
|
76
|
-
const listing: Array<{ name: string; download_url: string }> =
|
|
77
|
-
await listRes.json();
|
|
78
|
-
|
|
79
|
-
// Filter to requested extensions and fetch all files in parallel
|
|
80
|
-
const filtered = listing.filter((f) =>
|
|
81
|
-
extensions.some((ext) => f.name.endsWith(ext)),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return Promise.all(
|
|
85
|
-
filtered.map(async (file) => ({
|
|
86
|
-
filename: file.name,
|
|
87
|
-
content: await this.readFile(collection, file.name),
|
|
88
|
-
})),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Deletes a file from the repository via the Contents API.
|
|
94
|
-
* @param {string} collection - The collection name
|
|
95
|
-
* @param {string} filename - The filename to delete
|
|
96
|
-
* @return {Promise<void>}
|
|
97
|
-
*/
|
|
98
|
-
async deleteFile(collection: string, filename: string): Promise<void> {
|
|
99
|
-
const path = `src/content/${collection}/${filename}`;
|
|
100
|
-
// Get the current SHA (required by the GitHub Contents API for deletion)
|
|
101
|
-
const existing = await this.request(
|
|
102
|
-
'GET',
|
|
103
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}?ref=${this.defaultBranch}`,
|
|
104
|
-
);
|
|
105
|
-
if (!existing.ok) throw new Error(`File not found for deletion: ${path}`);
|
|
106
|
-
const data = await existing.json();
|
|
107
|
-
|
|
108
|
-
const res = await this.request(
|
|
109
|
-
'DELETE',
|
|
110
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}`,
|
|
111
|
-
undefined,
|
|
112
|
-
{
|
|
113
|
-
message: `Delete ${path}`,
|
|
114
|
-
sha: data.sha,
|
|
115
|
-
branch: this.defaultBranch,
|
|
116
|
-
},
|
|
117
|
-
);
|
|
118
|
-
if (!res.ok) throw new Error(`Failed to delete ${path}: ${res.status}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Reads a single file's raw content via the raw+json Accept header.
|
|
123
|
-
* @param {string} collection - The collection name
|
|
124
|
-
* @param {string} filename - The filename
|
|
125
|
-
* @return {Promise<string>} The file content
|
|
126
|
-
*/
|
|
127
|
-
async readFile(collection: string, filename: string): Promise<string> {
|
|
128
|
-
const path = `src/content/${collection}/${filename}`;
|
|
129
|
-
const res = await this.request(
|
|
130
|
-
'GET',
|
|
131
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}?ref=${this.defaultBranch}`,
|
|
132
|
-
{ Accept: 'application/vnd.github.raw+json' },
|
|
133
|
-
);
|
|
134
|
-
if (!res.ok) {
|
|
135
|
-
throw new Error(`Failed to read ${path}: ${res.status}`);
|
|
136
|
-
}
|
|
137
|
-
return res.text();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Writes a single file via the Contents API. Fetches the current SHA for updates.
|
|
142
|
-
* @param {string} collection - The collection name
|
|
143
|
-
* @param {string} filename - The filename
|
|
144
|
-
* @param {string} content - The content to write
|
|
145
|
-
* @return {Promise<void>}
|
|
146
|
-
*/
|
|
147
|
-
async writeFile(
|
|
148
|
-
collection: string,
|
|
149
|
-
filename: string,
|
|
150
|
-
content: string,
|
|
151
|
-
): Promise<void> {
|
|
152
|
-
const path = `src/content/${collection}/${filename}`;
|
|
153
|
-
// Get current SHA if file exists (required by GitHub API for updates)
|
|
154
|
-
let sha: string | undefined;
|
|
155
|
-
const existing = await this.request(
|
|
156
|
-
'GET',
|
|
157
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}?ref=${this.defaultBranch}`,
|
|
158
|
-
);
|
|
159
|
-
if (existing.ok) {
|
|
160
|
-
const data = await existing.json();
|
|
161
|
-
sha = data.sha;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const body: Record<string, string> = {
|
|
165
|
-
message: `Update ${path}`,
|
|
166
|
-
content: uint8ToBase64(new TextEncoder().encode(content)),
|
|
167
|
-
branch: this.defaultBranch,
|
|
168
|
-
};
|
|
169
|
-
if (sha) body.sha = sha;
|
|
170
|
-
|
|
171
|
-
const res = await this.request(
|
|
172
|
-
'PUT',
|
|
173
|
-
`/repos/${this.owner}/${this.repo}/contents/${path}`,
|
|
174
|
-
undefined,
|
|
175
|
-
body,
|
|
176
|
-
);
|
|
177
|
-
if (!res.ok) {
|
|
178
|
-
const errText = await res.text();
|
|
179
|
-
throw new Error(`Failed to write ${path}: ${res.status} ${errText}`);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Writes multiple files in a single atomic commit using the Git Trees + Commits API.
|
|
185
|
-
* @param {FileWrite[]} files - Array of files to write
|
|
186
|
-
* @return {Promise<void>}
|
|
187
|
-
*/
|
|
188
|
-
async writeFiles(files: FileWrite[]): Promise<void> {
|
|
189
|
-
if (files.length === 0) return;
|
|
190
|
-
if (files.length === 1) {
|
|
191
|
-
await this.writeFile(
|
|
192
|
-
files[0].collection,
|
|
193
|
-
files[0].filename,
|
|
194
|
-
files[0].content,
|
|
195
|
-
);
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// 1. Get current commit SHA for the default branch
|
|
200
|
-
const refRes = await this.request(
|
|
201
|
-
'GET',
|
|
202
|
-
`/repos/${this.owner}/${this.repo}/git/ref/heads/${this.defaultBranch}`,
|
|
203
|
-
);
|
|
204
|
-
if (!refRes.ok)
|
|
205
|
-
throw new Error(`Failed to get branch ref: ${refRes.status}`);
|
|
206
|
-
const refData = await refRes.json();
|
|
207
|
-
const baseCommitSHA = refData.object.sha;
|
|
208
|
-
|
|
209
|
-
// Get the base tree SHA from the current commit
|
|
210
|
-
const commitRes = await this.request(
|
|
211
|
-
'GET',
|
|
212
|
-
`/repos/${this.owner}/${this.repo}/git/commits/${baseCommitSHA}`,
|
|
213
|
-
);
|
|
214
|
-
if (!commitRes.ok)
|
|
215
|
-
throw new Error(`Failed to get commit: ${commitRes.status}`);
|
|
216
|
-
const commitData = await commitRes.json();
|
|
217
|
-
const baseTreeSHA = commitData.tree.sha;
|
|
218
|
-
|
|
219
|
-
// 2. Create a new tree containing all file changes
|
|
220
|
-
const tree = files.map((f) => ({
|
|
221
|
-
path: `src/content/${f.collection}/${f.filename}`,
|
|
222
|
-
mode: '100644' as const,
|
|
223
|
-
type: 'blob' as const,
|
|
224
|
-
content: f.content,
|
|
225
|
-
}));
|
|
226
|
-
|
|
227
|
-
const treeRes = await this.request(
|
|
228
|
-
'POST',
|
|
229
|
-
`/repos/${this.owner}/${this.repo}/git/trees`,
|
|
230
|
-
undefined,
|
|
231
|
-
{ base_tree: baseTreeSHA, tree },
|
|
232
|
-
);
|
|
233
|
-
if (!treeRes.ok)
|
|
234
|
-
throw new Error(`Failed to create tree: ${treeRes.status}`);
|
|
235
|
-
const treeData = await treeRes.json();
|
|
236
|
-
|
|
237
|
-
// 3. Create a new commit pointing at the new tree
|
|
238
|
-
const paths = files.map((f) => `${f.collection}/${f.filename}`).join(', ');
|
|
239
|
-
const newCommitRes = await this.request(
|
|
240
|
-
'POST',
|
|
241
|
-
`/repos/${this.owner}/${this.repo}/git/commits`,
|
|
242
|
-
undefined,
|
|
243
|
-
{
|
|
244
|
-
message: `Update ${paths}`,
|
|
245
|
-
tree: treeData.sha,
|
|
246
|
-
parents: [baseCommitSHA],
|
|
247
|
-
},
|
|
248
|
-
);
|
|
249
|
-
if (!newCommitRes.ok)
|
|
250
|
-
throw new Error(`Failed to create commit: ${newCommitRes.status}`);
|
|
251
|
-
const newCommitData = await newCommitRes.json();
|
|
252
|
-
|
|
253
|
-
// 4. Advance the branch ref to the new commit
|
|
254
|
-
const updateRefRes = await this.request(
|
|
255
|
-
'PATCH',
|
|
256
|
-
`/repos/${this.owner}/${this.repo}/git/refs/heads/${this.defaultBranch}`,
|
|
257
|
-
undefined,
|
|
258
|
-
{ sha: newCommitData.sha },
|
|
259
|
-
);
|
|
260
|
-
if (!updateRefRes.ok)
|
|
261
|
-
throw new Error(`Failed to update ref: ${updateRefRes.status}`);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Makes an authenticated request to the GitHub API.
|
|
266
|
-
* @param {string} method - HTTP method
|
|
267
|
-
* @param {string} path - API path (appended to https://api.github.com)
|
|
268
|
-
* @param {Record<string, string>} [extraHeaders] - Additional headers to merge
|
|
269
|
-
* @param {unknown} [body] - JSON body to send
|
|
270
|
-
* @return {Promise<Response>} The fetch response
|
|
271
|
-
*/
|
|
272
|
-
private async request(
|
|
273
|
-
method: string,
|
|
274
|
-
path: string,
|
|
275
|
-
extraHeaders?: Record<string, string>,
|
|
276
|
-
body?: unknown,
|
|
277
|
-
): Promise<Response> {
|
|
278
|
-
const headers: Record<string, string> = {
|
|
279
|
-
Authorization: `Bearer ${this.token}`,
|
|
280
|
-
'X-GitHub-Api-Version': '2026-03-10',
|
|
281
|
-
// Default to JSON so the browser cache distinguishes from raw content requests
|
|
282
|
-
Accept: 'application/vnd.github+json',
|
|
283
|
-
...extraHeaders,
|
|
284
|
-
};
|
|
285
|
-
if (body) {
|
|
286
|
-
headers['Content-Type'] = 'application/json';
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return fetch(`https://api.github.com${path}`, {
|
|
290
|
-
method,
|
|
291
|
-
headers,
|
|
292
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
293
|
-
// API responses must never be served from browser cache
|
|
294
|
-
cache: 'no-store',
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Backend configuration persistence using IndexedDB.
|
|
3
|
-
* Stores and retrieves the active storage backend (FSA or GitHub).
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { openDB } from './db';
|
|
7
|
-
|
|
8
|
-
// Fixed key for the backend config
|
|
9
|
-
const BACKEND_KEY = 'backend';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Backend configuration stored in IndexedDB. Tagged union discriminated on `type`.
|
|
13
|
-
* Security note: the GitHub token is stored in plaintext in IndexedDB. This is a
|
|
14
|
-
* deliberate trade-off for a client-only app with no server to proxy through.
|
|
15
|
-
* Same-origin policy protects it from other sites, but any XSS vulnerability
|
|
16
|
-
* would expose the token.
|
|
17
|
-
*/
|
|
18
|
-
export type BackendConfig =
|
|
19
|
-
| { type: 'fsa'; handle: FileSystemDirectoryHandle }
|
|
20
|
-
| { type: 'github'; token: string; repo: string };
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Stores backend configuration in IndexedDB for persistence across sessions.
|
|
24
|
-
* @param {BackendConfig} config - The backend config to store
|
|
25
|
-
* @return {Promise<void>}
|
|
26
|
-
*/
|
|
27
|
-
export async function saveBackend(config: BackendConfig): Promise<void> {
|
|
28
|
-
const db = await openDB();
|
|
29
|
-
return new Promise((resolve, reject) => {
|
|
30
|
-
const tx = db.transaction('handles', 'readwrite');
|
|
31
|
-
tx.objectStore('handles').put(config, BACKEND_KEY);
|
|
32
|
-
tx.oncomplete = () => resolve();
|
|
33
|
-
tx.onerror = () => reject(tx.error);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves stored backend configuration from IndexedDB. Handles migration from the old format where a bare FileSystemDirectoryHandle was stored.
|
|
39
|
-
* @return {Promise<BackendConfig | null>} The stored config, or null if none exists
|
|
40
|
-
*/
|
|
41
|
-
export async function loadBackend(): Promise<BackendConfig | null> {
|
|
42
|
-
const db = await openDB();
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
const tx = db.transaction('handles', 'readonly');
|
|
45
|
-
const request = tx.objectStore('handles').get(BACKEND_KEY);
|
|
46
|
-
request.onsuccess = () => {
|
|
47
|
-
const result = request.result;
|
|
48
|
-
if (!result) {
|
|
49
|
-
// Check for old-format handle stored under the legacy key
|
|
50
|
-
const legacyRequest = tx.objectStore('handles').get('projectRoot');
|
|
51
|
-
legacyRequest.onsuccess = () => {
|
|
52
|
-
const legacy = legacyRequest.result;
|
|
53
|
-
if (legacy && legacy instanceof FileSystemDirectoryHandle) {
|
|
54
|
-
resolve({ type: 'fsa', handle: legacy });
|
|
55
|
-
} else {
|
|
56
|
-
resolve(null);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
legacyRequest.onerror = () => resolve(null);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
resolve(result as BackendConfig);
|
|
63
|
-
};
|
|
64
|
-
request.onerror = () => reject(request.error);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Removes the stored backend configuration from IndexedDB. Also clears the legacy key if present.
|
|
70
|
-
* @return {Promise<void>}
|
|
71
|
-
*/
|
|
72
|
-
export async function clearBackend(): Promise<void> {
|
|
73
|
-
const db = await openDB();
|
|
74
|
-
return new Promise((resolve, reject) => {
|
|
75
|
-
const tx = db.transaction('handles', 'readwrite');
|
|
76
|
-
const store = tx.objectStore('handles');
|
|
77
|
-
store.delete(BACKEND_KEY);
|
|
78
|
-
// Clean up legacy key if present
|
|
79
|
-
store.delete('projectRoot');
|
|
80
|
-
tx.oncomplete = () => resolve();
|
|
81
|
-
tx.onerror = () => reject(tx.error);
|
|
82
|
-
});
|
|
83
|
-
}
|