feat(web): add workspace-aware session flow

This commit is contained in:
imccyu
2026-07-25 16:04:48 +08:00
parent 755e2a8c51
commit 9eb9c70a8a
170 changed files with 7573 additions and 3006 deletions

View File

@@ -15,6 +15,18 @@ export type { StorageErrorCode } from './error.ts'
export { UNIT_NAME_RE } from './backend.ts'
export type { StorageBackend, KvFacet, KvUnit, KvUnitDescriptor } from './backend.ts'
/**
* Derive the Cordis lifecycle service that one named backend plugin provides.
* Domain-form providers inject these keys so activation cannot race backend
* registration even though callers continue resolving backends through the
* storage registry.
* @param name - Backend registry name.
* @returns the corresponding lifecycle-only service key.
*/
export function storageBackendServiceKey(name: string): string {
return `storage.backend.${name}`
}
declare module 'cordis' {
interface Context {
storage: Storage

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { Context } from 'cordis'
import Storage, { BackendRegistry } from '../src/index.ts'
import Storage, { BackendRegistry, storageBackendServiceKey } from '../src/index.ts'
import type { StorageBackend } from '../src/index.ts'
const fakeBackend = (): StorageBackend => ({ close: async () => {} })
@@ -25,6 +25,11 @@ describe('BackendRegistry', () => {
})
describe('Storage service', () => {
it('derives stable lifecycle service keys for named backends', () => {
expect(storageBackendServiceKey('json')).toBe('storage.backend.json')
expect(storageBackendServiceKey('tenant-a')).toBe('storage.backend.tenant-a')
})
it('mounts on the context and exposes registry plus form mounting', async () => {
const ctx = new Context()
await ctx.plugin(Storage)