refactor(recipes)!: runtime이 있는 port는 src port를 다시 내보낸다 (0929/05-03)
문제: `recipes/frontend-capabilities/`가 `src/application/ports/`와
같은 이름의 타입 34개를 따로 정의한다(`DurableObjectStorePort`,
`FilePickerPort`, `StorageDurabilityPort`, `TransferProgress`,
`PublicCacheInspection` 등). 7월 이후 runtime port가 바뀌어도(0929
05-01~05-14) recipe 복사본은 한 번도 따라오지 않았다. catalog는 이
복사본을 구현한 fake를 runtime의 fake로 안내해서, 그 fake로 쓴 테스트는
runtime에 없는 resume·quarantine을 전제했다.
고른 방법 (리뷰의 (c)):
- runtime이 있는 port와 그 표면의 타입은 recipe 정의를 지우고
`src/application/ports`의 것을 같은 이름으로 다시 내보낸다. 옛 recipe
port에만 쓰이던 `DurableObjectDataClass`, `DurableObjectIntegrity`,
`DurableObjectRead`, `ObjectStoreRecoverySummary`도 지운다. src에 없는
`DurableObjectId`·`ObjectGeneration` 브랜드와 `as*` 헬퍼는 남긴다(src
port가 그대로 받는다).
- fake는 src port를 `implements`한다.
- 파일 picker·content·preview·download fake와 storage durability fake:
결과를 `BrowserDataResult`(`error`, 닫힌 코드, operation)로 바꿨다.
`PROVIDER_UNAVAILABLE`은 src 코드 `UNAVAILABLE`이 된다.
- `MemoryDurableObjectStore`: src OPFS port에 맞춰 다시 썼다. 생성자는
scope·storagePolicy·maxObjectBytes를 받는다. 멈춘 put의 행은
reconcile이 rollback만 한다(resume·quarantine 없음, runtime과 같다).
LOGOUT·ACCOUNT_DELETION만 지원하고 나머지 reason은 `UNSUPPORTED`다.
- 고칠 수 없는 fake: `MemoryStructuredOfflineStore`는
`IndexedDbRepositoryPort`와 설계가 달라(배치 commit·idempotency 대
CAS·lifecycle batch) catalog offline-indexeddb 행의 fake 칸에서 뺐다.
recipe 전용 `StructuredOfflineStore`의 fake로는 남는다.
- recipe 전용 port 두 곳:
- `PublicResponseCacheAdmin.inspect`는 runtime의 `PublicCacheInspection`
모양으로 보고한다. `MemoryPublicResponseCache`가 그 모양을 만든다.
- `FileTransferPort`(runtime 없음)의 progress는 `FileTransferProgress`로
나눴다. `TransferProgress`라는 이름은 recipe barrel에서 src 타입으로
계속 나간다. 일반 recipe인 `contracts.ts`가 선택형 runtime port를
import하지 않게 하려는 것이다.
- 다시 갈라지지 않게 `optional-capability-contracts.test.ts`에 검사를
더했다. recipes/가 src/application/ports/에 있는 이름으로 타입을
정의하면 실패한다(다시 내보내기는 허용).
- runtime 제거 fixture(`test-browser-file-storage-runtime-removal.ts`)는
이 runtime의 port를 다시 내보내는 recipe 두 파일과 그 테스트를 함께
지우고, recipe barrel에서 두 export 줄을 먼저 뺀다.
버린 대안: 현상 유지(변경 누락 계속), 이름만 바꿔 `*Sketch`로 표시(중복
유지비가 남음), 두 벌을 비교하는 타입 테스트(두 벌을 계속 유지).
위험·한계:
- recipe에서 위 타입·fake를 쓰던 다운스트림은 컴파일 오류로 드러난다
(조용히 깨지지 않는다). 같은 이름 타입의 모양, `MemoryDurableObjectStore`
생성자·메서드, 파일 fake의 실패 결과(`failure` → `error`), 지운 타입
4개가 바뀌었다. 두 제품 repo의 사용 여부는 확인하지 않았다.
- `MemoryDurableObjectStore`의 integrity digest는 runtime의 tree digest가
아니다(주석에 적음). worker·Web Lock·authority·GC는 흉내내지 않는다.
- `test:browser-file-storage-removal`은 pnpm이 필요해 돌리지 못했다.
barrel 줄 제거와 경로 추가는 코드로만 확인했다.
검증:
- RED: 새 검사를 수정 전 recipe 소스로 돌리면 실패한다.
`expected [ 'LocalFileRef', …(33) ] to deeply equal []` (34개).
- GREEN: `node scripts/run-vitest.ts run tests/unit tests/recipes
tests/contract` 180 files 2,548건 통과. `tsc` app·recipes·test·node
통과, 바꾼 파일 eslint 통과, `check-registries` PASS(재승인 불필요),
`verify-documentation-readiness` PASS_SCOPED.
`check-optional-recipes`(source)는 0929/05-01의 offline-indexeddb 예산
초과(37,327 > 36,900)만 실패하고 catalog·source 검사는 통과했다.
이 커밋은 그 번들 크기를 바꾸지 않는다(recipes/는 sourceRoots 밖).
BREAKING CHANGE: recipes/frontend-capabilities의 browser-file·OPFS·
storage durability·public cache 타입 중 src/application/ports와 이름이
같은 것은 이제 그 src 타입이다. file·durability·OPFS fake는 src port를
구현하고 BrowserDataResult를 돌려준다(`result.failure.code` →
`result.error.code`). `MemoryDurableObjectStore`는 `{ scope, storagePolicy,
maxObjectBytes }`로 만든다. `FileTransferPort`의 progress 타입은
`FileTransferProgress`다. `DurableObjectDataClass`·`DurableObjectIntegrity`
·`DurableObjectRead`·`ObjectStoreRecoverySummary`는 없어졌다.
Refs: docs/reviews/2026-09-29-maturity-review/05-adapters-storage-kernel.md 05-03
This commit is contained in:
@@ -104,7 +104,7 @@
|
|||||||
"forbiddenWhen": ["The data contains credentials.", "The browser would connect directly to a server database or object store.", "A normal HTTP cache is sufficient.", "Partition, retention, quota and recovery ownership are undefined."],
|
"forbiddenWhen": ["The data contains credentials.", "The browser would connect directly to a server database or object store.", "A normal HTTP cache is sufficient.", "Partition, retention, quota and recovery ownership are undefined."],
|
||||||
"boundary": "feature-specific async repository with registry-issued opaque dataset scope and immutable full-policy binding, plus an OPFS large-object sidecar whose logical commit authority and bidirectional scope binding are owned by an IndexedDB journal",
|
"boundary": "feature-specific async repository with registry-issued opaque dataset scope and immutable full-policy binding, plus an OPFS large-object sidecar whose logical commit authority and bidirectional scope binding are owned by an IndexedDB journal",
|
||||||
"port": "IndexedDbRepositoryPort / IndexedDbMaintenancePort / DurableObjectStorePort / DurableObjectMaintenancePort / StorageDurabilityPort",
|
"port": "IndexedDbRepositoryPort / IndexedDbMaintenancePort / DurableObjectStorePort / DurableObjectMaintenancePort / StorageDurabilityPort",
|
||||||
"fake": "MemoryStructuredOfflineStore / MemoryDurableObjectStore / MemoryStorageDurabilityAdapter",
|
"fake": "MemoryDurableObjectStore / MemoryStorageDurabilityAdapter (no recipe fake implements IndexedDbRepositoryPort; run the reference runtime on tests/helpers/memory-indexeddb.ts)",
|
||||||
"failureKinds": ["open-blocked", "versionchange", "quota", "corruption", "migration-rollback", "revision-conflict", "storage-eviction", "partial-object-write", "dataset-binding-mismatch", "dataset-budget-exceeded", "lifecycle-authorization-denied", "expired-resource"],
|
"failureKinds": ["open-blocked", "versionchange", "quota", "corruption", "migration-rollback", "revision-conflict", "storage-eviction", "partial-object-write", "dataset-binding-mismatch", "dataset-budget-exceeded", "lifecycle-authorization-denied", "expired-resource"],
|
||||||
"lifecycleMethods": ["close", "cancel-via-AbortSignal", "enforce-bounded-lifecycle-batch", "prune-expired-receipts", "reconcile", "enforcePolicies-with-composition-authority"],
|
"lifecycleMethods": ["close", "cancel-via-AbortSignal", "enforce-bounded-lifecycle-batch", "prune-expired-receipts", "reconcile", "enforcePolicies-with-composition-authority"],
|
||||||
"owner": "project-owner-required",
|
"owner": "project-owner-required",
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ production readiness를 뜻하지 않는다.
|
|||||||
| TypeScript port | `recipes/frontend-capabilities/contracts.ts` | 아니오 |
|
| TypeScript port | `recipes/frontend-capabilities/contracts.ts` | 아니오 |
|
||||||
| fake/unavailable | `recipes/frontend-capabilities/fake-adapters.ts` | 아니오 |
|
| fake/unavailable | `recipes/frontend-capabilities/fake-adapters.ts` | 아니오 |
|
||||||
| contract test | `tests/recipes/optional-capability-contracts.test.ts` | 아니오 |
|
| contract test | `tests/recipes/optional-capability-contracts.test.ts` | 아니오 |
|
||||||
| file/IndexedDB/OPFS/Cache 심층 계약 | `recipes/frontend-capabilities/browser-file-storage-contracts.ts` | 아니오 |
|
| file/IndexedDB/OPFS/Cache 심층 계약. reference runtime이 있는 port는 복사하지 않고 `src/application/ports`의 port를 다시 내보낸다([0929] 05-03) | `recipes/frontend-capabilities/browser-file-storage-contracts.ts` | 아니오 |
|
||||||
| 심층 deterministic fake | `recipes/frontend-capabilities/browser-file-storage-fakes.ts` | 아니오 |
|
| 심층 deterministic fake. file·storage durability·OPFS fake는 `src` port를 `implements`한다 | `recipes/frontend-capabilities/browser-file-storage-fakes.ts` | 아니오 |
|
||||||
| 심층 contract test | `tests/recipes/browser-file-storage-contracts.test.ts` | 아니오 |
|
| 심층 contract test | `tests/recipes/browser-file-storage-contracts.test.ts` | 아니오 |
|
||||||
| browser data current-status ledger | `docs/architecture/browser-data-capability-completion-ledger.md` | 문서만 |
|
| browser data current-status ledger | `docs/architecture/browser-data-capability-completion-ledger.md` | 문서만 |
|
||||||
| 심층 설계/ADR | `docs/architecture/browser-file-and-origin-storage.md`, `decisions/VD-11-browser-file-and-origin-storage.md` | 문서만 |
|
| 심층 설계/ADR | `docs/architecture/browser-file-and-origin-storage.md`, `decisions/VD-11-browser-file-and-origin-storage.md` | 문서만 |
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
|
import type { CapabilityResult } from "./contracts.ts";
|
||||||
import type {
|
import type {
|
||||||
CapabilityResult,
|
DownloadDeliveryPort,
|
||||||
Cleanup,
|
DownloadStrategy,
|
||||||
TransferProgress,
|
DurableObjectMaintenancePort,
|
||||||
} from "./contracts.ts";
|
DurableObjectStorePort,
|
||||||
|
FileContentPort,
|
||||||
|
FilePickerPort,
|
||||||
|
FilePolicyReference,
|
||||||
|
PersistableDataClass,
|
||||||
|
PublicCacheInspection,
|
||||||
|
StorageDurabilityPort,
|
||||||
|
TransientPreviewPort,
|
||||||
|
} from "../../src/application/ports/browser-file-storage/index.ts";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deep opt-in contracts for browser file and origin-storage capabilities.
|
* Deep opt-in contracts for browser file and origin-storage capabilities.
|
||||||
@@ -12,14 +21,54 @@ import type {
|
|||||||
* copies and narrows only the ports that its product actually owns.
|
* copies and narrows only the ports that its product actually owns.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [0929] 05-03. A port that has a reference runtime under `src/` is not
|
||||||
|
* copied here. The copies kept their July shape while the runtime ports moved
|
||||||
|
* on, so a fake written against a recipe copy promised behaviour the runtime
|
||||||
|
* does not have. These names are the `src/application/ports` types themselves.
|
||||||
|
* Removing that runtime removes this file and its fakes with it
|
||||||
|
* (`scripts/test-browser-file-storage-runtime-removal.ts`).
|
||||||
|
*/
|
||||||
|
export type {
|
||||||
|
BrowserManagedDownloadCapability,
|
||||||
|
BrowserManagedDownloadCapabilityReceipt,
|
||||||
|
BrowserManagedDownloadCapabilityResolver,
|
||||||
|
DownloadDeliveryPort,
|
||||||
|
DownloadOutcome,
|
||||||
|
DownloadSource,
|
||||||
|
DownloadStrategy,
|
||||||
|
DurableObjectDescriptor,
|
||||||
|
DurableObjectMaintenancePort,
|
||||||
|
DurableObjectStorePort,
|
||||||
|
FileByteSource,
|
||||||
|
FileCandidate,
|
||||||
|
FileContentPort,
|
||||||
|
FileInspection,
|
||||||
|
FilePickerPort,
|
||||||
|
FilePickerSupport,
|
||||||
|
FilePolicyIntention,
|
||||||
|
FilePolicyKey,
|
||||||
|
FilePolicyReference,
|
||||||
|
FileSelectionLimitReduction,
|
||||||
|
FileSelectionOutcome,
|
||||||
|
FileSelectionSource,
|
||||||
|
FileSignatureResult,
|
||||||
|
FileVerificationReceipt,
|
||||||
|
LocalFileRef,
|
||||||
|
PersistableDataClass,
|
||||||
|
PreviewLease,
|
||||||
|
PublicCacheInspection,
|
||||||
|
StorageDurabilityPort,
|
||||||
|
StorageEstimate,
|
||||||
|
TransferProgress,
|
||||||
|
TransientPreviewPort,
|
||||||
|
} from "../../src/application/ports/browser-file-storage/index.ts";
|
||||||
|
export type {
|
||||||
|
AuthorizedDownloadCapability,
|
||||||
|
AuthorizedDownloadCapabilityReceipt,
|
||||||
|
} from "../../src/application/ports/browser-transfer/index.ts";
|
||||||
|
|
||||||
declare const byteCountBrand: unique symbol;
|
declare const byteCountBrand: unique symbol;
|
||||||
declare const localFileRefBrand: unique symbol;
|
|
||||||
declare const fileVerificationReceiptBrand: unique symbol;
|
|
||||||
declare const filePolicyKeyBrand: unique symbol;
|
|
||||||
declare const filePolicyIntentionBrand: unique symbol;
|
|
||||||
declare const browserManagedCapabilityReceiptBrand: unique symbol;
|
|
||||||
declare const authorizedDownloadCapabilityBrand: unique symbol;
|
|
||||||
declare const authorizedDownloadCapabilityReceiptBrand: unique symbol;
|
|
||||||
declare const objectIdBrand: unique symbol;
|
declare const objectIdBrand: unique symbol;
|
||||||
declare const objectGenerationBrand: unique symbol;
|
declare const objectGenerationBrand: unique symbol;
|
||||||
|
|
||||||
@@ -27,62 +76,10 @@ export type ByteCount = number & {
|
|||||||
readonly [byteCountBrand]: "ByteCount";
|
readonly [byteCountBrand]: "ByteCount";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type LocalFileRef = string & {
|
|
||||||
readonly [localFileRefBrand]: "LocalFileRef";
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FileVerificationReceipt = string & {
|
|
||||||
readonly [fileVerificationReceiptBrand]: "FileVerificationReceipt";
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FilePolicyKey = string & {
|
|
||||||
readonly [filePolicyKeyBrand]: "FilePolicyKey";
|
|
||||||
};
|
|
||||||
|
|
||||||
export type FilePolicyIntention = string & {
|
|
||||||
readonly [filePolicyIntentionBrand]: "FilePolicyIntention";
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Composition-issued capability selector. Implementations must resolve the
|
* Recipe-only brands for a durable object's id and generation. The runtime
|
||||||
* exact registered object identity, not merely an equal string pair.
|
* port takes plain values; a branded one is still accepted there.
|
||||||
*/
|
*/
|
||||||
export type FilePolicyReference = Readonly<{
|
|
||||||
policyKey: FilePolicyKey;
|
|
||||||
intention: FilePolicyIntention;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type BrowserManagedDownloadCapabilityReceipt = string & {
|
|
||||||
readonly [browserManagedCapabilityReceiptBrand]:
|
|
||||||
"BrowserManagedDownloadCapabilityReceipt";
|
|
||||||
};
|
|
||||||
|
|
||||||
export type AuthorizedDownloadCapabilityReceipt = string & {
|
|
||||||
readonly [authorizedDownloadCapabilityReceiptBrand]:
|
|
||||||
"AuthorizedDownloadCapabilityReceipt";
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* GET-only provider-issued handle. The corresponding URL, signed query and
|
|
||||||
* headers stay inside the selected transfer adapter's in-memory identity
|
|
||||||
* vault; a feature cannot replace them or supply its own digest.
|
|
||||||
*/
|
|
||||||
export type AuthorizedDownloadCapability = Readonly<{
|
|
||||||
capabilityReceipt: AuthorizedDownloadCapabilityReceipt;
|
|
||||||
method: "GET";
|
|
||||||
binding: Readonly<{
|
|
||||||
kind: "DOWNLOAD";
|
|
||||||
resourceId: string;
|
|
||||||
}>;
|
|
||||||
mediaType: string;
|
|
||||||
byteLength: ByteCount;
|
|
||||||
maxBytes: ByteCount;
|
|
||||||
expectedSha256: string;
|
|
||||||
expiresAtEpochMs: number;
|
|
||||||
readonly [authorizedDownloadCapabilityBrand]:
|
|
||||||
"AuthorizedDownloadCapability";
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type DurableObjectId = string & {
|
export type DurableObjectId = string & {
|
||||||
readonly [objectIdBrand]: "DurableObjectId";
|
readonly [objectIdBrand]: "DurableObjectId";
|
||||||
};
|
};
|
||||||
@@ -91,17 +88,6 @@ export type ObjectGeneration = number & {
|
|||||||
readonly [objectGenerationBrand]: "ObjectGeneration";
|
readonly [objectGenerationBrand]: "ObjectGeneration";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PersistableDataClass =
|
|
||||||
| "PUBLIC"
|
|
||||||
| "INTERNAL"
|
|
||||||
| "PERSONAL"
|
|
||||||
| "CONFIDENTIAL";
|
|
||||||
|
|
||||||
export type FileSelectionSource =
|
|
||||||
| "NATIVE_INPUT"
|
|
||||||
| "SYSTEM_PICKER"
|
|
||||||
| "DROP";
|
|
||||||
|
|
||||||
export type FileAcceptRule = Readonly<{
|
export type FileAcceptRule = Readonly<{
|
||||||
mediaType: string;
|
mediaType: string;
|
||||||
extensions: ReadonlyArray<string>;
|
extensions: ReadonlyArray<string>;
|
||||||
@@ -119,51 +105,6 @@ export type FileSelectionPolicy = Readonly<{
|
|||||||
accept: ReadonlyArray<FileAcceptRule>;
|
accept: ReadonlyArray<FileAcceptRule>;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type FileSelectionLimitReduction = Readonly<{
|
|
||||||
maxCount?: number;
|
|
||||||
maxFileBytes?: ByteCount;
|
|
||||||
maxTotalBytes?: ByteCount;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type FileCandidate = Readonly<{
|
|
||||||
ref: LocalFileRef;
|
|
||||||
displayName: string;
|
|
||||||
sizeBytes: ByteCount;
|
|
||||||
reportedMediaType: string | null;
|
|
||||||
lastModifiedEpochMs: number | null;
|
|
||||||
source: FileSelectionSource;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type FileSelectionOutcome =
|
|
||||||
| Readonly<{
|
|
||||||
kind: "SELECTED";
|
|
||||||
files: ReadonlyArray<FileCandidate>;
|
|
||||||
}>
|
|
||||||
| Readonly<{ kind: "DISMISSED" }>;
|
|
||||||
|
|
||||||
export type FilePickerSupport = Readonly<{
|
|
||||||
nativeInput: true;
|
|
||||||
systemOpenPicker: boolean;
|
|
||||||
systemSavePicker: boolean;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface FilePickerPort {
|
|
||||||
readonly support: FilePickerSupport;
|
|
||||||
|
|
||||||
select(input: {
|
|
||||||
policy: FilePolicyReference;
|
|
||||||
limits?: FileSelectionLimitReduction;
|
|
||||||
signal?: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<FileSelectionOutcome>>;
|
|
||||||
|
|
||||||
release(ref: LocalFileRef): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FileSignatureResult =
|
|
||||||
| "MATCHED"
|
|
||||||
| "MISMATCHED"
|
|
||||||
| "UNKNOWN";
|
|
||||||
|
|
||||||
export type FileBytePattern = Readonly<{
|
export type FileBytePattern = Readonly<{
|
||||||
offset: ByteCount;
|
offset: ByteCount;
|
||||||
bytes: ReadonlyArray<number>;
|
bytes: ReadonlyArray<number>;
|
||||||
@@ -182,67 +123,6 @@ export type FileInspectionPolicy = Readonly<{
|
|||||||
acceptedSignatures: ReadonlyArray<FileSignatureRule>;
|
acceptedSignatures: ReadonlyArray<FileSignatureRule>;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type FileInspection = Readonly<{
|
|
||||||
byteLength: ByteCount;
|
|
||||||
reportedMediaType: string | null;
|
|
||||||
detectedMediaType: string | null;
|
|
||||||
normalizedExtension: string | null;
|
|
||||||
signature: FileSignatureResult;
|
|
||||||
verificationReceipt: FileVerificationReceipt | null;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type FileByteSource = Readonly<{
|
|
||||||
byteLength: ByteCount | null;
|
|
||||||
stream(
|
|
||||||
signal: AbortSignal,
|
|
||||||
): AsyncIterable<CapabilityResult<Uint8Array>>;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface FileContentPort {
|
|
||||||
inspect(input: {
|
|
||||||
ref: LocalFileRef;
|
|
||||||
policy: FilePolicyReference;
|
|
||||||
maxInspectionBytes?: ByteCount;
|
|
||||||
signal: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<FileInspection>>;
|
|
||||||
|
|
||||||
readRange(input: {
|
|
||||||
ref: LocalFileRef;
|
|
||||||
offset: ByteCount;
|
|
||||||
length: ByteCount;
|
|
||||||
signal: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<Uint8Array>>;
|
|
||||||
|
|
||||||
openSource(input: {
|
|
||||||
ref: LocalFileRef;
|
|
||||||
signal: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<FileByteSource>>;
|
|
||||||
|
|
||||||
release(ref: LocalFileRef): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PreviewLease = Readonly<{
|
|
||||||
url: string;
|
|
||||||
mediaType: string;
|
|
||||||
release: Cleanup;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Presentation-local capability. The implementation owns object URL creation
|
|
||||||
* and must revoke each lease on replacement, load failure and unmount.
|
|
||||||
*/
|
|
||||||
export interface TransientPreviewPort {
|
|
||||||
create(input: {
|
|
||||||
ref: LocalFileRef;
|
|
||||||
verificationReceipt: FileVerificationReceipt;
|
|
||||||
policy: FilePolicyReference;
|
|
||||||
maxPreviewBytes?: ByteCount;
|
|
||||||
signal: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<PreviewLease>>;
|
|
||||||
|
|
||||||
dispose(): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature/backend workflow example, not a browser capability dependency.
|
* Feature/backend workflow example, not a browser capability dependency.
|
||||||
* Copy it only when the backend owns authorization, resumable-session expiry,
|
* Copy it only when the backend owns authorization, resumable-session expiry,
|
||||||
@@ -297,71 +177,6 @@ export interface ExampleQuarantinedUploadPort {
|
|||||||
): Promise<CapabilityResult<void>>;
|
): Promise<CapabilityResult<void>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DownloadSource =
|
|
||||||
| Readonly<{
|
|
||||||
kind: "BROWSER_MANAGED_RESOURCE";
|
|
||||||
resourceId: string;
|
|
||||||
capabilityReceipt: BrowserManagedDownloadCapabilityReceipt;
|
|
||||||
}>
|
|
||||||
| Readonly<{
|
|
||||||
kind: "AUTHORIZED_STREAM_RESOURCE";
|
|
||||||
resourceId: string;
|
|
||||||
capability: AuthorizedDownloadCapability;
|
|
||||||
}>
|
|
||||||
| Readonly<{
|
|
||||||
kind: "GENERATED";
|
|
||||||
bytes: FileByteSource;
|
|
||||||
expectedSha256?: string;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type DownloadStrategy =
|
|
||||||
| "BROWSER_MANAGED"
|
|
||||||
| "PROMPT_AND_STREAM"
|
|
||||||
| "BOUNDED_OBJECT_URL";
|
|
||||||
|
|
||||||
export type DownloadOutcome =
|
|
||||||
| Readonly<{
|
|
||||||
kind: "BROWSER_HANDOFF";
|
|
||||||
transferId: string;
|
|
||||||
}>
|
|
||||||
| Readonly<{
|
|
||||||
kind: "SAVED";
|
|
||||||
transferId: string;
|
|
||||||
bytesWritten: ByteCount;
|
|
||||||
integrity: "VERIFIED" | "NOT_PROVIDED";
|
|
||||||
}>
|
|
||||||
| Readonly<{ kind: "DISMISSED" }>;
|
|
||||||
|
|
||||||
export interface DownloadDeliveryPort {
|
|
||||||
deliver(input: {
|
|
||||||
policy: FilePolicyReference;
|
|
||||||
source: DownloadSource;
|
|
||||||
suggestedFileName: string;
|
|
||||||
maxTransferBytes?: ByteCount;
|
|
||||||
maxBufferedBytes?: ByteCount;
|
|
||||||
signal: AbortSignal;
|
|
||||||
onProgress(progress: TransferProgress): void;
|
|
||||||
}): Promise<CapabilityResult<DownloadOutcome>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type BrowserManagedDownloadCapability = Readonly<{
|
|
||||||
capabilityReceipt: BrowserManagedDownloadCapabilityReceipt;
|
|
||||||
href: string;
|
|
||||||
resourceId: string;
|
|
||||||
mediaType: string;
|
|
||||||
safeExtension: string;
|
|
||||||
maxBytes: ByteCount;
|
|
||||||
expectedSha256?: string;
|
|
||||||
expiresAtEpochMs: number;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface BrowserManagedDownloadCapabilityResolver {
|
|
||||||
resolve(input: Readonly<{
|
|
||||||
resourceId: string;
|
|
||||||
capabilityReceipt: BrowserManagedDownloadCapabilityReceipt;
|
|
||||||
}>): CapabilityResult<BrowserManagedDownloadCapability>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RegisteredPreviewPolicy = Readonly<{
|
export type RegisteredPreviewPolicy = Readonly<{
|
||||||
allowedMediaTypes: ReadonlyArray<string>;
|
allowedMediaTypes: ReadonlyArray<string>;
|
||||||
maxPreviewBytes: ByteCount;
|
maxPreviewBytes: ByteCount;
|
||||||
@@ -543,101 +358,6 @@ export interface OfflineStoreMaintenancePort {
|
|||||||
}): Promise<CapabilityResult<Readonly<{ purgedCount: number }>>>;
|
}): Promise<CapabilityResult<Readonly<{ purgedCount: number }>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StorageEstimate = Readonly<{
|
|
||||||
usageBytes: number | null;
|
|
||||||
quotaBytes: number | null;
|
|
||||||
persisted: boolean | null;
|
|
||||||
pressure: "UNKNOWN" | "NORMAL" | "PRESSURE" | "CRITICAL";
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface StorageDurabilityPort {
|
|
||||||
inspect(signal?: AbortSignal): Promise<CapabilityResult<StorageEstimate>>;
|
|
||||||
|
|
||||||
requestPersistence(input: {
|
|
||||||
reason: "PROTECT_UNSYNCED_USER_DATA";
|
|
||||||
userInitiated: true;
|
|
||||||
signal?: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<"GRANTED" | "DENIED">>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DurableObjectDataClass =
|
|
||||||
| "RECONSTRUCTABLE"
|
|
||||||
| "USER_CREATED_PRIVATE";
|
|
||||||
|
|
||||||
export type DurableObjectIntegrity = Readonly<{
|
|
||||||
algorithm: "SHA-256-TREE-V1";
|
|
||||||
rootDigest: string;
|
|
||||||
chunkSizeBytes: ByteCount;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type DurableObjectDescriptor = Readonly<{
|
|
||||||
id: DurableObjectId;
|
|
||||||
generation: ObjectGeneration;
|
|
||||||
byteLength: ByteCount;
|
|
||||||
mediaType: string | null;
|
|
||||||
integrity: DurableObjectIntegrity;
|
|
||||||
dataClass: DurableObjectDataClass;
|
|
||||||
retention:
|
|
||||||
| Readonly<{ kind: "EXPLICIT_DELETE" }>
|
|
||||||
| Readonly<{ kind: "EXPIRES"; expiresAt: string }>;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export type DurableObjectRead = Readonly<{
|
|
||||||
descriptor: DurableObjectDescriptor;
|
|
||||||
chunks: AsyncIterable<CapabilityResult<Uint8Array>>;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface DurableObjectStorePort {
|
|
||||||
capabilities(signal?: AbortSignal): Promise<
|
|
||||||
CapabilityResult<
|
|
||||||
Readonly<{
|
|
||||||
backend: "OPFS" | "INDEXEDDB_BLOB" | "NONE";
|
|
||||||
persistence: "BEST_EFFORT" | "PERSISTENT";
|
|
||||||
maxObjectBytes: ByteCount;
|
|
||||||
}>
|
|
||||||
>
|
|
||||||
>;
|
|
||||||
|
|
||||||
put(input: {
|
|
||||||
id: DurableObjectId;
|
|
||||||
expectedGeneration: ObjectGeneration | null;
|
|
||||||
source: AsyncIterable<CapabilityResult<Uint8Array>>;
|
|
||||||
declaredByteLength: ByteCount;
|
|
||||||
mediaType: string | null;
|
|
||||||
dataClass: DurableObjectDataClass;
|
|
||||||
retention: DurableObjectDescriptor["retention"];
|
|
||||||
signal: AbortSignal;
|
|
||||||
onProgress(progress: TransferProgress): void;
|
|
||||||
}): Promise<CapabilityResult<DurableObjectDescriptor>>;
|
|
||||||
|
|
||||||
open(
|
|
||||||
id: DurableObjectId,
|
|
||||||
signal?: AbortSignal,
|
|
||||||
): Promise<CapabilityResult<DurableObjectRead>>;
|
|
||||||
|
|
||||||
remove(input: {
|
|
||||||
id: DurableObjectId;
|
|
||||||
expectedGeneration: ObjectGeneration;
|
|
||||||
signal?: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<void>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ObjectStoreRecoverySummary = Readonly<{
|
|
||||||
resumedCount: number;
|
|
||||||
purgedCount: number;
|
|
||||||
quarantinedCount: number;
|
|
||||||
nextCursor: string | null;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export interface DurableObjectMaintenancePort {
|
|
||||||
reconcile(input: {
|
|
||||||
timeBudgetMs: number;
|
|
||||||
maxEntries: number;
|
|
||||||
cursor?: string;
|
|
||||||
signal?: AbortSignal;
|
|
||||||
}): Promise<CapabilityResult<ObjectStoreRecoverySummary>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PublicAssetEntry = Readonly<{
|
export type PublicAssetEntry = Readonly<{
|
||||||
url: string;
|
url: string;
|
||||||
byteLength: ByteCount;
|
byteLength: ByteCount;
|
||||||
@@ -662,13 +382,6 @@ export type PublicCacheLookup =
|
|||||||
| "POLICY_REJECTED";
|
| "POLICY_REJECTED";
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export type PublicCacheInspection = Readonly<{
|
|
||||||
activeReleaseId: string | null;
|
|
||||||
previousReleaseId: string | null;
|
|
||||||
candidateReleaseIds: ReadonlyArray<string>;
|
|
||||||
ownedBytes: number | null;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Platform-local Cache Storage policy facade. Raw Request/Response/Cache
|
* Platform-local Cache Storage policy facade. Raw Request/Response/Cache
|
||||||
* objects remain inside the adapter, and no application repository imports it.
|
* objects remain inside the adapter, and no application repository imports it.
|
||||||
@@ -695,6 +408,10 @@ export interface PublicResponseCacheAdmin {
|
|||||||
signal?: AbortSignal;
|
signal?: AbortSignal;
|
||||||
}): Promise<CapabilityResult<PublicCacheLookup>>;
|
}): Promise<CapabilityResult<PublicCacheLookup>>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [0929] 05-03. Reports in the runtime's `PublicCacheInspection` shape;
|
||||||
|
* the recipe kept a same-named copy with other fields.
|
||||||
|
*/
|
||||||
inspect(signal?: AbortSignal): Promise<
|
inspect(signal?: AbortSignal): Promise<
|
||||||
CapabilityResult<PublicCacheInspection>
|
CapabilityResult<PublicCacheInspection>
|
||||||
>;
|
>;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -90,7 +90,13 @@ export interface ServiceWorkerUpdatePort {
|
|||||||
unregister(): Promise<CapabilityResult<void>>;
|
unregister(): Promise<CapabilityResult<void>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TransferProgress = Readonly<{
|
/**
|
||||||
|
* [0929] 05-03. Progress of the recipe-only `FileTransferPort`. It is not the
|
||||||
|
* browser-file runtime's `TransferProgress` (whose `phase` is required), so it
|
||||||
|
* no longer shares that name; the runtime's type is re-exported from
|
||||||
|
* `browser-file-storage-contracts.ts`.
|
||||||
|
*/
|
||||||
|
export type FileTransferProgress = Readonly<{
|
||||||
phase?:
|
phase?:
|
||||||
| "VALIDATING"
|
| "VALIDATING"
|
||||||
| "PREPARING"
|
| "PREPARING"
|
||||||
@@ -115,12 +121,12 @@ export interface FileTransferPort {
|
|||||||
content: TransferByteSource;
|
content: TransferByteSource;
|
||||||
}>;
|
}>;
|
||||||
signal: AbortSignal;
|
signal: AbortSignal;
|
||||||
onProgress(progress: TransferProgress): void;
|
onProgress(progress: FileTransferProgress): void;
|
||||||
}): Promise<CapabilityResult<Readonly<{ resourceId: string }>>>;
|
}): Promise<CapabilityResult<Readonly<{ resourceId: string }>>>;
|
||||||
download(input: {
|
download(input: {
|
||||||
resourceId: string;
|
resourceId: string;
|
||||||
signal: AbortSignal;
|
signal: AbortSignal;
|
||||||
onProgress(progress: TransferProgress): void;
|
onProgress(progress: FileTransferProgress): void;
|
||||||
}): Promise<
|
}): Promise<
|
||||||
CapabilityResult<
|
CapabilityResult<
|
||||||
Readonly<{
|
Readonly<{
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ import {
|
|||||||
|
|
||||||
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
const pnpmCli = requireRemovalFixtureEnvironment("npm_execpath");
|
||||||
const fixtureRoot = await createRemovalFixtureRoot("browser-file-storage-runtime-removal");
|
const fixtureRoot = await createRemovalFixtureRoot("browser-file-storage-runtime-removal");
|
||||||
|
const RUNTIME_RECIPE_MODULES = [
|
||||||
|
"browser-file-storage-contracts.ts",
|
||||||
|
"browser-file-storage-fakes.ts",
|
||||||
|
] as const;
|
||||||
const runtimePaths = [
|
const runtimePaths = [
|
||||||
"src/application/ports/browser-file-storage",
|
"src/application/ports/browser-file-storage",
|
||||||
"src/application/ports/browser-transfer",
|
"src/application/ports/browser-transfer",
|
||||||
@@ -34,6 +38,12 @@ const runtimePaths = [
|
|||||||
"tests/fixtures/browser-file-storage-boundaries",
|
"tests/fixtures/browser-file-storage-boundaries",
|
||||||
// The composition example of this runtime goes with it.
|
// The composition example of this runtime goes with it.
|
||||||
"recipes/frontend-capabilities/indexeddb-feature-capability.ts",
|
"recipes/frontend-capabilities/indexeddb-feature-capability.ts",
|
||||||
|
// [0929] 05-03. These recipe contracts re-export this runtime's ports and
|
||||||
|
// their fakes implement them, so they go with it too, with their test.
|
||||||
|
...RUNTIME_RECIPE_MODULES.map(
|
||||||
|
(module) => `recipes/frontend-capabilities/${module}`,
|
||||||
|
),
|
||||||
|
"tests/recipes/browser-file-storage-contracts.test.ts",
|
||||||
] as const;
|
] as const;
|
||||||
const runtimeSourceRoots = runtimePaths.filter((entry) =>
|
const runtimeSourceRoots = runtimePaths.filter((entry) =>
|
||||||
entry.startsWith("src/"),
|
entry.startsWith("src/"),
|
||||||
@@ -57,6 +67,29 @@ let removedRuntimeTests: number;
|
|||||||
try {
|
try {
|
||||||
await prepareRemovalFixture(fixtureRoot);
|
await prepareRemovalFixture(fixtureRoot);
|
||||||
|
|
||||||
|
// The recipe barrel stops exporting the removed recipe modules first, so the
|
||||||
|
// import graph below does not count every other recipe test as dependent.
|
||||||
|
const recipeIndexPath = path.join(
|
||||||
|
fixtureRoot,
|
||||||
|
"recipes/frontend-capabilities/index.ts",
|
||||||
|
);
|
||||||
|
const recipeIndex = await readFile(recipeIndexPath, "utf8");
|
||||||
|
const keptRecipeExports = recipeIndex
|
||||||
|
.split("\n")
|
||||||
|
.filter(
|
||||||
|
(line) =>
|
||||||
|
!RUNTIME_RECIPE_MODULES.some((module) =>
|
||||||
|
line.includes(`"./${module}"`),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
keptRecipeExports.length !==
|
||||||
|
recipeIndex.split("\n").length - RUNTIME_RECIPE_MODULES.length
|
||||||
|
) {
|
||||||
|
throw new Error("Expected the recipe barrel to export each runtime recipe module once");
|
||||||
|
}
|
||||||
|
await writeFile(recipeIndexPath, keptRecipeExports.join("\n"));
|
||||||
|
|
||||||
removedRuntimeTests =
|
removedRuntimeTests =
|
||||||
await removeRuntimeDependentTests(fixtureRoot, runtimeSourceRoots);
|
await removeRuntimeDependentTests(fixtureRoot, runtimeSourceRoots);
|
||||||
for (const runtimePath of runtimePaths) {
|
for (const runtimePath of runtimePaths) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
asLocalFileRef,
|
asLocalFileRef,
|
||||||
asObjectGeneration,
|
asObjectGeneration,
|
||||||
browserFilePolicyReference,
|
browserFilePolicyReference,
|
||||||
failure,
|
|
||||||
sanitizeDownloadFileName,
|
sanitizeDownloadFileName,
|
||||||
} from "../../recipes/frontend-capabilities/index.ts";
|
} from "../../recipes/frontend-capabilities/index.ts";
|
||||||
import type {
|
import type {
|
||||||
@@ -28,6 +27,16 @@ import type {
|
|||||||
StorageDurabilityComposition,
|
StorageDurabilityComposition,
|
||||||
StructuredOfflineStorageComposition,
|
StructuredOfflineStorageComposition,
|
||||||
} from "../../recipes/frontend-capabilities/index.ts";
|
} from "../../recipes/frontend-capabilities/index.ts";
|
||||||
|
import type {
|
||||||
|
BrowserStoragePolicy,
|
||||||
|
DownloadDeliveryPort,
|
||||||
|
DurableObjectMaintenancePort,
|
||||||
|
DurableObjectStorePort,
|
||||||
|
FileContentPort,
|
||||||
|
FilePickerPort,
|
||||||
|
StorageDurabilityPort,
|
||||||
|
TransientPreviewPort,
|
||||||
|
} from "../../src/application/ports/browser-file-storage/index.ts";
|
||||||
|
|
||||||
async function* byteChunks(
|
async function* byteChunks(
|
||||||
...values: ReadonlyArray<string>
|
...values: ReadonlyArray<string>
|
||||||
@@ -41,11 +50,15 @@ async function* byteChunks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function* failedByteChunks() {
|
async function* failedByteChunks() {
|
||||||
yield failure(
|
yield {
|
||||||
"NOT_READABLE",
|
ok: false,
|
||||||
true,
|
error: {
|
||||||
"The fixture source became unreadable.",
|
code: "NOT_READABLE",
|
||||||
);
|
operation: "OBJECT_WRITE",
|
||||||
|
retryable: true,
|
||||||
|
recovery: "RETRY",
|
||||||
|
},
|
||||||
|
} as const;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("production browser file and storage recipe contracts", () => {
|
describe("production browser file and storage recipe contracts", () => {
|
||||||
@@ -123,7 +136,7 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
}),
|
}),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
failure: { code: "POLICY_REJECTED" },
|
error: { code: "POLICY_REJECTED", operation: "FILE_SELECT" },
|
||||||
});
|
});
|
||||||
const inspected = await adapter.inspect({
|
const inspected = await adapter.inspect({
|
||||||
ref,
|
ref,
|
||||||
@@ -178,7 +191,7 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
}),
|
}),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
failure: { code: "PROVIDER_UNAVAILABLE" },
|
error: { code: "UNAVAILABLE", operation: "PREVIEW" },
|
||||||
});
|
});
|
||||||
adapter.release(ref);
|
adapter.release(ref);
|
||||||
expect(
|
expect(
|
||||||
@@ -253,6 +266,20 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// [0929] 05-03. The fakes the catalog names for a runtime port implement
|
||||||
|
// that `src` port, not a recipe copy of it.
|
||||||
|
it("fakes the src runtime ports themselves", () => {
|
||||||
|
expectTypeOf<MemoryFileSelectionAdapter>().toMatchTypeOf<
|
||||||
|
FilePickerPort & FileContentPort
|
||||||
|
>();
|
||||||
|
expectTypeOf<MemoryTransientPreviewAdapter>().toMatchTypeOf<TransientPreviewPort>();
|
||||||
|
expectTypeOf<RecordingDownloadDeliveryAdapter>().toMatchTypeOf<DownloadDeliveryPort>();
|
||||||
|
expectTypeOf<MemoryStorageDurabilityAdapter>().toMatchTypeOf<StorageDurabilityPort>();
|
||||||
|
expectTypeOf<MemoryDurableObjectStore>().toMatchTypeOf<
|
||||||
|
DurableObjectStorePort & DurableObjectMaintenancePort
|
||||||
|
>();
|
||||||
|
});
|
||||||
|
|
||||||
it("keeps each browser technology independently composable", () => {
|
it("keeps each browser technology independently composable", () => {
|
||||||
expectTypeOf<keyof BrowserFileComposition>().toEqualTypeOf<
|
expectTypeOf<keyof BrowserFileComposition>().toEqualTypeOf<
|
||||||
"picker" | "content" | "previews" | "downloads"
|
"picker" | "content" | "previews" | "downloads"
|
||||||
@@ -379,7 +406,7 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
}),
|
}),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
failure: { code: "POLICY_REJECTED" },
|
error: { code: "POLICY_REJECTED", operation: "DOWNLOAD" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const saved = await adapter.deliver({
|
const saved = await adapter.deliver({
|
||||||
@@ -528,88 +555,121 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("keeps partially written OPFS objects invisible until logical commit", async () => {
|
it("keeps partially written OPFS objects invisible until logical commit", async () => {
|
||||||
const store = new MemoryDurableObjectStore(asByteCount(32));
|
const storagePolicy: BrowserStoragePolicy = {
|
||||||
const id = asDurableObjectId("opaque-object");
|
owner: "recipe-test",
|
||||||
store.failNextPutAfter("FILES_READY");
|
namespace: "durable-objects",
|
||||||
const failed = await store.put({
|
classification: "PERSONAL",
|
||||||
id,
|
authority: "LOCAL_FIRST",
|
||||||
expectedGeneration: null,
|
accountScope: "OPAQUE_PARTITION",
|
||||||
source: byteChunks("ab", "cd"),
|
retention: { kind: "EXPLICIT_DELETE" },
|
||||||
declaredByteLength: asByteCount(4),
|
softBudgetBytes: 32,
|
||||||
mediaType: "application/octet-stream",
|
hardBudgetBytes: 64,
|
||||||
dataClass: "RECONSTRUCTABLE",
|
evictionPriority: "USER_AUTHORED",
|
||||||
retention: { kind: "EXPIRES", expiresAt: "2026-08-01T00:00:00.000Z" },
|
logoutAction: "EXPORT_THEN_PURGE",
|
||||||
signal: new AbortController().signal,
|
accountDeletionAction: "PURGE_PARTITION",
|
||||||
onProgress() {},
|
pressureAction: "RETAIN",
|
||||||
|
unavailableFallback: "EXPORT_REQUIRED",
|
||||||
|
};
|
||||||
|
const store = new MemoryDurableObjectStore({
|
||||||
|
scope: {
|
||||||
|
namespace: "durable-objects",
|
||||||
|
authorityToken: "authority_12345678",
|
||||||
|
namespaceToken: "namespace_12345678",
|
||||||
|
partitionToken: "partition_12345678",
|
||||||
|
},
|
||||||
|
storagePolicy,
|
||||||
|
maxObjectBytes: 32,
|
||||||
});
|
});
|
||||||
expect(failed).toMatchObject({
|
// The recipe brands are still accepted by the runtime port.
|
||||||
ok: false,
|
const objectId = asDurableObjectId("object_opaque_0001");
|
||||||
failure: { code: "PROVIDER_UNAVAILABLE" },
|
const source = (...values: ReadonlyArray<string>) => ({
|
||||||
|
byteLength: values.join("").length,
|
||||||
|
stream: () => byteChunks(...values),
|
||||||
});
|
});
|
||||||
expect(await store.open(id)).toMatchObject({
|
|
||||||
ok: false,
|
|
||||||
failure: { code: "NOT_FOUND" },
|
|
||||||
});
|
|
||||||
expect(
|
|
||||||
await store.reconcile({ timeBudgetMs: 100, maxEntries: 10 }),
|
|
||||||
).toMatchObject({ ok: true, value: { purgedCount: 1 } });
|
|
||||||
|
|
||||||
|
store.failNextPutAfter("FILES_READY");
|
||||||
expect(
|
expect(
|
||||||
await store.put({
|
await store.put({
|
||||||
id,
|
objectId,
|
||||||
expectedGeneration: null,
|
expectedGeneration: null,
|
||||||
source: failedByteChunks(),
|
mediaType: "application/octet-stream",
|
||||||
declaredByteLength: asByteCount(4),
|
source: source("ab", "cd"),
|
||||||
mediaType: null,
|
|
||||||
dataClass: "RECONSTRUCTABLE",
|
|
||||||
retention: { kind: "EXPLICIT_DELETE" },
|
|
||||||
signal: new AbortController().signal,
|
|
||||||
onProgress() {},
|
|
||||||
}),
|
}),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
ok: false,
|
ok: false,
|
||||||
failure: { code: "NOT_READABLE" },
|
error: { code: "UNAVAILABLE", recovery: "RECONCILE" },
|
||||||
|
});
|
||||||
|
expect(await store.open({ objectId })).toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: { code: "NOT_FOUND" },
|
||||||
|
});
|
||||||
|
// Like the runtime, reconcile rolls a stopped put back; it never resumes.
|
||||||
|
expect(await store.reconcile()).toMatchObject({
|
||||||
|
ok: true,
|
||||||
|
value: { rolledBackTransactions: 1, moreTransactionsAvailable: false },
|
||||||
});
|
});
|
||||||
expect(
|
|
||||||
await store.reconcile({ timeBudgetMs: 100, maxEntries: 10 }),
|
|
||||||
).toMatchObject({ ok: true, value: { purgedCount: 1 } });
|
|
||||||
|
|
||||||
const committed = await store.put({
|
expect(
|
||||||
id,
|
await store.put({
|
||||||
expectedGeneration: null,
|
objectId,
|
||||||
source: byteChunks("abcd"),
|
expectedGeneration: null,
|
||||||
declaredByteLength: asByteCount(4),
|
mediaType: "application/octet-stream",
|
||||||
mediaType: null,
|
source: { byteLength: 4, stream: failedByteChunks },
|
||||||
dataClass: "RECONSTRUCTABLE",
|
}),
|
||||||
retention: { kind: "EXPLICIT_DELETE" },
|
).toMatchObject({
|
||||||
signal: new AbortController().signal,
|
ok: false,
|
||||||
onProgress() {},
|
error: { code: "NOT_READABLE", operation: "OBJECT_WRITE" },
|
||||||
});
|
});
|
||||||
expect(committed).toMatchObject({
|
// A put that fails on its own compensates, so nothing is left behind.
|
||||||
|
expect(await store.reconcile()).toMatchObject({
|
||||||
|
ok: true,
|
||||||
|
value: { rolledBackTransactions: 0 },
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await store.put({
|
||||||
|
objectId,
|
||||||
|
expectedGeneration: null,
|
||||||
|
mediaType: "application/octet-stream",
|
||||||
|
source: source("abcd"),
|
||||||
|
}),
|
||||||
|
).toMatchObject({
|
||||||
ok: true,
|
ok: true,
|
||||||
value: {
|
value: {
|
||||||
|
objectId,
|
||||||
generation: 1,
|
generation: 1,
|
||||||
|
byteLength: 4,
|
||||||
integrity: { algorithm: "SHA-256-TREE-V1" },
|
integrity: { algorithm: "SHA-256-TREE-V1" },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const opened = await store.open(id);
|
const opened = await store.open({ objectId });
|
||||||
expect(opened.ok).toBe(true);
|
expect(opened.ok).toBe(true);
|
||||||
if (opened.ok) {
|
if (opened.ok) {
|
||||||
const chunks: number[] = [];
|
const bytes: number[] = [];
|
||||||
for await (const chunkResult of opened.value.chunks) {
|
for await (const chunk of opened.value.source.stream(
|
||||||
expect(chunkResult.ok).toBe(true);
|
new AbortController().signal,
|
||||||
if (chunkResult.ok) chunks.push(...chunkResult.value);
|
)) {
|
||||||
|
expect(chunk.ok).toBe(true);
|
||||||
|
if (chunk.ok) bytes.push(...chunk.value);
|
||||||
}
|
}
|
||||||
expect(new TextDecoder().decode(new Uint8Array(chunks))).toBe(
|
expect(new TextDecoder().decode(new Uint8Array(bytes))).toBe("abcd");
|
||||||
"abcd",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
expect(
|
expect(
|
||||||
await store.remove({
|
await store.remove({
|
||||||
id,
|
objectId,
|
||||||
expectedGeneration: asObjectGeneration(2),
|
expectedGeneration: asObjectGeneration(2),
|
||||||
}),
|
}),
|
||||||
).toMatchObject({ ok: false, failure: { code: "CONFLICT" } });
|
).toMatchObject({ ok: false, error: { code: "CONFLICT" } });
|
||||||
|
expect(
|
||||||
|
await store.enforcePolicies({ reason: "ACCOUNT_DELETION" }),
|
||||||
|
).toMatchObject({
|
||||||
|
ok: true,
|
||||||
|
value: { removedObjects: 1, chunkSweep: "COMPLETED" },
|
||||||
|
});
|
||||||
|
expect(await store.open({ objectId })).toMatchObject({
|
||||||
|
ok: false,
|
||||||
|
error: { code: "NOT_FOUND" },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("stages and activates only exact public Cache Storage representations", async () => {
|
it("stages and activates only exact public Cache Storage representations", async () => {
|
||||||
@@ -669,5 +729,15 @@ describe("production browser file and storage recipe contracts", () => {
|
|||||||
ok: false,
|
ok: false,
|
||||||
failure: { code: "POLICY_REJECTED" },
|
failure: { code: "POLICY_REJECTED" },
|
||||||
});
|
});
|
||||||
|
// [0929] 05-03. Reported in the runtime's `PublicCacheInspection` shape.
|
||||||
|
expect(await cache.inspect()).toEqual({
|
||||||
|
ok: true,
|
||||||
|
value: {
|
||||||
|
activeReleaseRegistryId: "release-1",
|
||||||
|
ownedCacheCount: 1,
|
||||||
|
unreadableOwnedCacheCount: 0,
|
||||||
|
releaseCandidates: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { readdir, readFile } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -287,4 +290,35 @@ describe("optional capability recipes", () => {
|
|||||||
adapters.largeDataUi.window({ offset: 0, limit: 1, generation: 1 }).ok,
|
adapters.largeDataUi.window({ offset: 0, limit: 1, generation: 1 }).ok,
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// [0929] 05-03. A recipe that defines its own type under the name of an
|
||||||
|
// application port drifts from it: the recipe copies of the browser-file
|
||||||
|
// and OPFS ports missed every runtime change for months. A recipe may
|
||||||
|
// re-export a port, never define a second one with the same name.
|
||||||
|
it("defines no type under the name of an application port", async () => {
|
||||||
|
const definedNames = async (root: string): Promise<Set<string>> => {
|
||||||
|
const names = new Set<string>();
|
||||||
|
const entries = await readdir(root, {
|
||||||
|
recursive: true,
|
||||||
|
withFileTypes: true,
|
||||||
|
});
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.isFile() || !entry.name.endsWith(".ts")) continue;
|
||||||
|
const source = await readFile(
|
||||||
|
path.join(entry.parentPath, entry.name),
|
||||||
|
"utf8",
|
||||||
|
);
|
||||||
|
for (const match of source.matchAll(
|
||||||
|
/^export (?:declare |async )?(?:interface|type|class|enum|function|const) ([A-Za-z0-9_]+)/gmu,
|
||||||
|
)) {
|
||||||
|
names.add(match[1]!);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
};
|
||||||
|
const portNames = await definedNames("src/application/ports");
|
||||||
|
const recipeNames = await definedNames("recipes");
|
||||||
|
|
||||||
|
expect([...recipeNames].filter((name) => portNames.has(name))).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user