fix(features): keep local-draft off the removable storage runtime (00-02)
The two local-draft adapters imported the IndexedDB port that the browser file/storage removal deletes, so that removal gate failed. The feature now declares the repository slice it calls and receives it through the indexedDb capability; the runtime satisfies it structurally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bc7c46b2d5
commit
1b38659fce
@@ -1,6 +1,3 @@
|
||||
import type {
|
||||
IndexedDbRepositoryPort,
|
||||
} from "../../../application/ports/browser-file-storage/index.ts";
|
||||
import {
|
||||
defineFeatureAdapterContribution,
|
||||
} from "../../feature-adapter-contribution.ts";
|
||||
@@ -8,22 +5,24 @@ import type {} from "../../feature-adapter-contribution.ts";
|
||||
import {
|
||||
createLocalDraftFeatureInput,
|
||||
} from "../application/local-draft-api.ts";
|
||||
import type { LocalDraft } from "../domain/local-draft.ts";
|
||||
import {
|
||||
LOCAL_DRAFT_FEATURE_ID,
|
||||
LOCAL_DRAFT_REPOSITORY_ID,
|
||||
} from "../contracts/local-draft-contract.ts";
|
||||
import { createLocalDraftStore } from "./local-draft-indexeddb-store.ts";
|
||||
import {
|
||||
createLocalDraftStore,
|
||||
type LocalDraftRepository,
|
||||
} from "./local-draft-indexeddb-store.ts";
|
||||
|
||||
declare module "../../feature-adapter-contribution.ts" {
|
||||
interface FeatureIndexedDbRepositories {
|
||||
"local-draft": IndexedDbRepositoryPort<LocalDraft, never>;
|
||||
"local-draft": LocalDraftRepository;
|
||||
}
|
||||
}
|
||||
|
||||
export function createLocalDraftFeatureInstalledInput(context: Readonly<{
|
||||
indexedDb: Readonly<{
|
||||
get(repositoryId: "local-draft"): IndexedDbRepositoryPort<LocalDraft, never>;
|
||||
get(repositoryId: "local-draft"): LocalDraftRepository;
|
||||
}>;
|
||||
}>) {
|
||||
const repository = context.indexedDb.get(LOCAL_DRAFT_REPOSITORY_ID);
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
import type {
|
||||
BrowserDataFailure,
|
||||
IndexedDbRepositoryPort,
|
||||
} from "../../../application/ports/browser-file-storage/index.ts";
|
||||
import {
|
||||
createFailure,
|
||||
type AppFailure,
|
||||
@@ -16,7 +12,43 @@ import type {
|
||||
} from "../application/local-draft-api.ts";
|
||||
import type { LocalDraft } from "../domain/local-draft.ts";
|
||||
|
||||
function failureKind(failure: BrowserDataFailure): FailureKind {
|
||||
type RepositoryFailure = Readonly<{ code: string }>;
|
||||
type RepositoryResult<Value> = Result<Value, RepositoryFailure>;
|
||||
|
||||
/**
|
||||
* 00-02. The part of the `indexedDb` capability this feature calls. The host
|
||||
* hands in the reusable runtime (`IndexedDbRepositoryPort<LocalDraft, never>`),
|
||||
* which satisfies this shape structurally (the recipe and the browser spec
|
||||
* compile that assignment). Importing the port instead tied the feature to the
|
||||
* browser storage runtime, which a product may remove.
|
||||
*/
|
||||
export type LocalDraftRepository = Readonly<{
|
||||
read(
|
||||
key: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<
|
||||
RepositoryResult<Readonly<{ value: LocalDraft; revision: number }> | null>
|
||||
>;
|
||||
compareAndSwap(
|
||||
input: Readonly<{
|
||||
key: string;
|
||||
value: LocalDraft;
|
||||
expectedRevision: number | null;
|
||||
idempotencyKey: string;
|
||||
signal?: AbortSignal;
|
||||
}>,
|
||||
): Promise<RepositoryResult<Readonly<{ revision: number }>>>;
|
||||
remove(
|
||||
input: Readonly<{
|
||||
key: string;
|
||||
expectedRevision: number;
|
||||
idempotencyKey: string;
|
||||
signal?: AbortSignal;
|
||||
}>,
|
||||
): Promise<RepositoryResult<unknown>>;
|
||||
}>;
|
||||
|
||||
function failureKind(failure: RepositoryFailure): FailureKind {
|
||||
if (failure.code === "QUOTA_EXCEEDED") return "STORAGE_QUOTA_EXCEEDED";
|
||||
if (failure.code === "CONFLICT") return "CONFLICT";
|
||||
if (failure.code === "ABORTED") return "REQUEST_ABORTED";
|
||||
@@ -24,7 +56,7 @@ function failureKind(failure: BrowserDataFailure): FailureKind {
|
||||
}
|
||||
|
||||
function mapFailure(
|
||||
failure: BrowserDataFailure,
|
||||
failure: RepositoryFailure,
|
||||
operationId: string,
|
||||
): AppFailure {
|
||||
return createFailure(failureKind(failure), operationId, 0, {
|
||||
@@ -33,7 +65,7 @@ function mapFailure(
|
||||
}
|
||||
|
||||
function failed<Value>(
|
||||
failure: BrowserDataFailure,
|
||||
failure: RepositoryFailure,
|
||||
operationId: string,
|
||||
): Result<Value> {
|
||||
return Object.freeze({
|
||||
@@ -48,7 +80,7 @@ function failed<Value>(
|
||||
* cross this file.
|
||||
*/
|
||||
export function createLocalDraftStore(
|
||||
repository: IndexedDbRepositoryPort<LocalDraft, never>,
|
||||
repository: LocalDraftRepository,
|
||||
): LocalDraftStore {
|
||||
return Object.freeze({
|
||||
async save(command: SaveLocalDraftCommand, signal?: AbortSignal) {
|
||||
|
||||
Reference in New Issue
Block a user