src/features/local-draft-feature는 기능이 아니라 IndexedDB recipe의 소비자다. 시험 5개와 recipe가 쓰고, 그래서 생성기에 NOT_A_FEATURE 예외가 있었다(S4 3.1절 S-3). 코드를 tests/fixtures/indexeddb-consumer/로 옮기고 import만 고쳤다. NOT_A_FEATURE 표식은 이 폴더만 썼고 다운스트림 둘에도 없어 생성기에서 지웠다. 선언 없는 폴더는 밖으로 옮기라는 메시지로 실패한다. 매뉴얼 오류표, README, starter-experience, capability-consumer-experience, patterns를 고쳤다. 위험: fixture는 기능 폴더 밖이라 기능 계층 규칙(dependency-cruiser)이 걸리지 않는다. recipe가 tests/ 아래 파일을 type import한다. 검증(desktop): test:contract, test:recipes, test:browser-capabilities, test:unit 통과.
86 lines
2.5 KiB
TypeScript
86 lines
2.5 KiB
TypeScript
import { createFailure } from "../../../../src/contracts/errors.ts";
|
|
import type { Result } from "../../../../src/contracts/result.ts";
|
|
import type {} from "../../../../src/application/ports/in/application-api.ts";
|
|
import { createLocalDraft, type LocalDraft } from "../domain/local-draft.ts";
|
|
|
|
export type LocalDraftRecord = Readonly<{
|
|
draft: LocalDraft;
|
|
revision: number;
|
|
}>;
|
|
|
|
export type SaveLocalDraftCommand = Readonly<{
|
|
draft: LocalDraft;
|
|
/** Only unambiguous while draft ids are never reused (see LocalDraft.draftId). */
|
|
expectedRevision: number | null;
|
|
idempotencyKey: string;
|
|
}>;
|
|
|
|
export type RemoveLocalDraftCommand = Readonly<{
|
|
draftId: string;
|
|
expectedRevision: number;
|
|
idempotencyKey: string;
|
|
}>;
|
|
|
|
export type LocalDraftStore = Readonly<{
|
|
save(
|
|
command: SaveLocalDraftCommand,
|
|
signal?: AbortSignal,
|
|
): Promise<Result<Readonly<{ revision: number }>>>;
|
|
find(
|
|
draftId: string,
|
|
signal?: AbortSignal,
|
|
): Promise<Result<LocalDraftRecord | null>>;
|
|
remove(
|
|
command: RemoveLocalDraftCommand,
|
|
signal?: AbortSignal,
|
|
): Promise<Result<void>>;
|
|
}>;
|
|
|
|
export type LocalDraftFeatureInput = Readonly<{
|
|
saveDraft(
|
|
command: SaveLocalDraftCommand,
|
|
context?: Readonly<{ signal?: AbortSignal }>,
|
|
): Promise<Result<Readonly<{ revision: number }>>>;
|
|
findDraft(
|
|
draftId: string,
|
|
context?: Readonly<{ signal?: AbortSignal }>,
|
|
): Promise<Result<LocalDraftRecord | null>>;
|
|
removeDraft(
|
|
command: RemoveLocalDraftCommand,
|
|
context?: Readonly<{ signal?: AbortSignal }>,
|
|
): Promise<Result<void>>;
|
|
}>;
|
|
|
|
declare module "../../../../src/application/ports/in/application-api.ts" {
|
|
interface ApplicationFeatureInputs {
|
|
"local-draft": LocalDraftFeatureInput;
|
|
}
|
|
}
|
|
|
|
export function createLocalDraftFeatureInput(
|
|
store: LocalDraftStore,
|
|
): LocalDraftFeatureInput {
|
|
return Object.freeze({
|
|
// 09-06. The domain rules (trimmed non-blank id and title, bounded
|
|
// lengths) are applied here; the store never sees an unchecked draft.
|
|
async saveDraft(command, context) {
|
|
let draft: LocalDraft;
|
|
try {
|
|
draft = createLocalDraft(command.draft);
|
|
} catch {
|
|
return Object.freeze({
|
|
ok: false as const,
|
|
error: createFailure("VALIDATION_REJECTED", "LOCAL_DRAFT_SAVE", 0),
|
|
});
|
|
}
|
|
return store.save(Object.freeze({ ...command, draft }), context?.signal);
|
|
},
|
|
findDraft(draftId, context) {
|
|
return store.find(draftId, context?.signal);
|
|
},
|
|
removeDraft(command, context) {
|
|
return store.remove(command, context?.signal);
|
|
},
|
|
});
|
|
}
|