67 lines
2.6 KiB
TypeScript
67 lines
2.6 KiB
TypeScript
// The port the archive module's use cases are written against: the platform's Archive service, in this
|
|
// module's own words. adapters/service.ts is the one place that knows `@conusai-sdk/archive` exists, and
|
|
// it turns every refusal into the kit's typed app error (`businessAppError`) before core sees it.
|
|
|
|
import { token } from "@conusai-kit/core"
|
|
import type { DocumentReceipt, DocumentView, RetentionClassView, VersionFacts, VersionView } from "../contract/index.js"
|
|
|
|
export interface Page<T> {
|
|
readonly rows: T[]
|
|
readonly after?: string
|
|
}
|
|
|
|
/** What a `read` procedure may ask the service: nothing that changes a row. */
|
|
export interface ArchiveReads {
|
|
listDocuments(query: { q?: string; after?: string; limit: number }): Promise<Page<DocumentView>>
|
|
getDocument(documentId: string): Promise<DocumentView>
|
|
listVersions(documentId: string, query: { after?: string; limit: number }): Promise<Page<VersionView>>
|
|
listRetentionClasses(query: { after?: string; limit: number }): Promise<Page<RetentionClassView>>
|
|
listDisposalDue(query: { after?: string; limit: number }): Promise<Page<DocumentView>>
|
|
}
|
|
|
|
export interface ArchiveService extends ArchiveReads {
|
|
registerDocument(input: {
|
|
title: string
|
|
kind?: string
|
|
retentionClass: string
|
|
version: VersionFacts
|
|
key: string
|
|
}): Promise<DocumentReceipt>
|
|
addVersion(input: {
|
|
documentId: string
|
|
revision: string
|
|
version: VersionFacts
|
|
key: string
|
|
}): Promise<DocumentReceipt>
|
|
setLegalHold(input: {
|
|
documentId: string
|
|
revision: string
|
|
legalHold: boolean
|
|
key: string
|
|
}): Promise<DocumentReceipt>
|
|
disposeDocument(input: { documentId: string; revision: string; key: string }): Promise<DocumentReceipt>
|
|
createRetentionClass(input: {
|
|
code: string
|
|
keepFor: string
|
|
from: RetentionClassView["from"]
|
|
key: string
|
|
}): Promise<void>
|
|
}
|
|
|
|
/** The read view a `read` or `write` handler receives: the kind is a capability, not a label. */
|
|
export const archiveReadsOf = (service: ArchiveReads): ArchiveReads => ({
|
|
listDocuments: (query) => service.listDocuments(query),
|
|
getDocument: (documentId) => service.getDocument(documentId),
|
|
listVersions: (documentId, query) => service.listVersions(documentId, query),
|
|
listRetentionClasses: (query) => service.listRetentionClasses(query),
|
|
listDisposalDue: (query) => service.listDisposalDue(query),
|
|
})
|
|
|
|
/**
|
|
* Bound by a composition root or a test that brings its own client (another organization, the
|
|
* business-services fake). With nothing bound, the module calls this deployment's service.
|
|
*/
|
|
export const ARCHIVE_SERVICE = token<ArchiveService>("archive.service", {
|
|
views: { read: archiveReadsOf, write: archiveReadsOf },
|
|
})
|