Skip to content

@codesoul-co/hypha-core / contracts/artifact-store

模块用法

用于声明并运行时校验契约。Artifact store 模块公开 12 接口、1 类型。

从包入口导入

ts
import type {
  ArtifactByteRange,
  ArtifactContent,
  ArtifactCopyRequest,
  ArtifactDownloadAccess,
  ArtifactDownloadAccessRequest,
  ArtifactGetRequest,
  ArtifactObjectMetadata,
  ArtifactOperationOptions,
} from '@codesoul-co/hypha-core';

// 完整导出列表见下方。

使用要点

  • 13 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。

公共导出

Symbol种类签名说明
ArtifactByteRange接口interface ArtifactByteRangeArtifact Byte Range 接口,共包含 2 个公开字段或方法。
ArtifactContent接口interface ArtifactContentArtifact Content 接口,共包含 6 个公开字段或方法。
ArtifactCopyRequest接口interface ArtifactCopyRequestArtifact Copy Request 接口,共包含 4 个公开字段或方法。
ArtifactDownloadAccess接口interface ArtifactDownloadAccessArtifact Download Access 接口,共包含 4 个公开字段或方法。
ArtifactDownloadAccessRequest接口interface ArtifactDownloadAccessRequestArtifact Download Access Request 接口,共包含 4 个公开字段或方法。
ArtifactGetRequest接口interface ArtifactGetRequestArtifact Get Request 接口,共包含 3 个公开字段或方法。
ArtifactObjectMetadata接口interface ArtifactObjectMetadataArtifact Object Metadata 接口,共包含 6 个公开字段或方法。
ArtifactOperationOptions接口interface ArtifactOperationOptionsArtifact Operation Options 接口,共包含 1 个公开字段或方法。
ArtifactPutRequest接口interface ArtifactPutRequestArtifact Put Request 接口,共包含 8 个公开字段或方法。
ArtifactStoreCapabilities接口interface ArtifactStoreCapabilitiesArtifact Store Capabilities 接口,共包含 7 个公开字段或方法。
ArtifactStoreProvider接口interface ArtifactStoreProviderArtifact Store Provider 接口,共包含 11 个公开字段或方法。
ArtifactStoreProviderFactory接口interface ArtifactStoreProviderFactoryArtifact Store Provider Factory 接口,共包含 2 个公开字段或方法。
ArtifactByteSource类型type ArtifactByteSource = Uint8Array | AsyncIterable<Uint8Array>Artifact Byte Source 公共类型别名;完整类型表达式见声明。

ArtifactByteRange

Artifact Byte Range 接口,共包含 2 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactByteRange } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactByteRange {
    start: number;
    endInclusive?: number;
}

契约成员

成员种类签名说明
endInclusive属性endInclusive?: number公开属性;类型、只读和可选状态以签名列为准。
start属性start: number公开属性;类型、只读和可选状态以签名列为准。

ArtifactContent

Artifact Content 接口,共包含 6 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactContent } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactContent {
    stream: AsyncIterable<Uint8Array>;
    contentHash: string;
    sizeBytes: number;
    mimeType?: string;
    etag?: string;
    range?: ArtifactByteRange;
}

契约成员

成员种类签名说明
contentHash属性contentHash: string公开属性;类型、只读和可选状态以签名列为准。
etag属性etag?: string公开属性;类型、只读和可选状态以签名列为准。
mimeType属性mimeType?: string公开属性;类型、只读和可选状态以签名列为准。
range属性range?: ArtifactByteRange公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes: number公开属性;类型、只读和可选状态以签名列为准。
stream属性stream: AsyncIterable<Uint8Array<ArrayBufferLike>>公开属性;类型、只读和可选状态以签名列为准。

ArtifactCopyRequest

Artifact Copy Request 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactCopyRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactCopyRequest {
    operationId: string;
    source: ArtifactStorageRef;
    targetObjectKey: string;
    ifAbsent?: boolean;
}

契约成员

成员种类签名说明
ifAbsent属性ifAbsent?: boolean公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
source属性source: ArtifactStorageRef公开属性;类型、只读和可选状态以签名列为准。
targetObjectKey属性targetObjectKey: string公开属性;类型、只读和可选状态以签名列为准。

ArtifactDownloadAccess

Artifact Download Access 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactDownloadAccess } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactDownloadAccess {
    method: 'GET';
    url: string;
    expiresAt: string;
    headers?: Record<string, string>;
}

契约成员

成员种类签名说明
expiresAt属性expiresAt: string公开属性;类型、只读和可选状态以签名列为准。
headers属性headers?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
method属性method: "GET"公开属性;类型、只读和可选状态以签名列为准。
url属性url: string公开属性;类型、只读和可选状态以签名列为准。

ArtifactDownloadAccessRequest

Artifact Download Access Request 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactDownloadAccessRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactDownloadAccessRequest {
    ref: ArtifactStorageRef;
    expiresInSeconds: number;
    responseMimeType?: string;
    responseFilename?: string;
}

契约成员

成员种类签名说明
expiresInSeconds属性expiresInSeconds: number公开属性;类型、只读和可选状态以签名列为准。
ref属性ref: ArtifactStorageRef公开属性;类型、只读和可选状态以签名列为准。
responseFilename属性responseFilename?: string公开属性;类型、只读和可选状态以签名列为准。
responseMimeType属性responseMimeType?: string公开属性;类型、只读和可选状态以签名列为准。

ArtifactGetRequest

Artifact Get Request 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactGetRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactGetRequest {
    ref: ArtifactStorageRef;
    range?: ArtifactByteRange;
    expectedContentHash?: string;
}

契约成员

成员种类签名说明
expectedContentHash属性expectedContentHash?: string公开属性;类型、只读和可选状态以签名列为准。
range属性range?: ArtifactByteRange公开属性;类型、只读和可选状态以签名列为准。
ref属性ref: ArtifactStorageRef公开属性;类型、只读和可选状态以签名列为准。

ArtifactObjectMetadata

Artifact Object Metadata 接口,共包含 6 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactObjectMetadata } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactObjectMetadata {
    contentHash: string;
    sizeBytes: number;
    mimeType?: string;
    etag?: string;
    lastModifiedAt?: string;
    metadata?: Record<string, string>;
}

契约成员

成员种类签名说明
contentHash属性contentHash: string公开属性;类型、只读和可选状态以签名列为准。
etag属性etag?: string公开属性;类型、只读和可选状态以签名列为准。
lastModifiedAt属性lastModifiedAt?: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
mimeType属性mimeType?: string公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes: number公开属性;类型、只读和可选状态以签名列为准。

ArtifactOperationOptions

Artifact Operation Options 接口,共包含 1 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactOperationOptions } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactOperationOptions {
    abortSignal?: AbortSignal;
}

契约成员

成员种类签名说明
abortSignal属性abortSignal?: AbortSignal公开属性;类型、只读和可选状态以签名列为准。

ArtifactPutRequest

Artifact Put Request 接口,共包含 8 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactPutRequest } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactPutRequest {
    operationId: string;
    objectKey: string;
    content: ArtifactByteSource;
    expectedContentHash?: string;
    sizeBytes?: number;
    mimeType?: string;
    metadata?: Record<string, string>;
    ifAbsent?: boolean;
}

契约成员

成员种类签名说明
content属性content: ArtifactByteSource公开属性;类型、只读和可选状态以签名列为准。
expectedContentHash属性expectedContentHash?: string公开属性;类型、只读和可选状态以签名列为准。
ifAbsent属性ifAbsent?: boolean公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
mimeType属性mimeType?: string公开属性;类型、只读和可选状态以签名列为准。
objectKey属性objectKey: string公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes?: number公开属性;类型、只读和可选状态以签名列为准。

ArtifactStoreCapabilities

Artifact Store Capabilities 接口,共包含 7 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactStoreCapabilities } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactStoreCapabilities {
    versioning: boolean;
    rangeRead: boolean;
    signedAccess: boolean;
    serverSideCopy: boolean;
    encryption: boolean;
    multipartUpload: boolean;
    contentAddressing: boolean;
}

契约成员

成员种类签名说明
contentAddressing属性contentAddressing: boolean公开属性;类型、只读和可选状态以签名列为准。
encryption属性encryption: boolean公开属性;类型、只读和可选状态以签名列为准。
multipartUpload属性multipartUpload: boolean公开属性;类型、只读和可选状态以签名列为准。
rangeRead属性rangeRead: boolean公开属性;类型、只读和可选状态以签名列为准。
serverSideCopy属性serverSideCopy: boolean公开属性;类型、只读和可选状态以签名列为准。
signedAccess属性signedAccess: boolean公开属性;类型、只读和可选状态以签名列为准。
versioning属性versioning: boolean公开属性;类型、只读和可选状态以签名列为准。

ArtifactStoreProvider

Artifact Store Provider 接口,共包含 11 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactStoreProvider } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactStoreProvider {
    readonly id: string;
    capabilities(): Promise<ArtifactStoreCapabilities>;
    put(request: ArtifactPutRequest, options?: ArtifactOperationOptions): Promise<ArtifactStorageRef>;
    get(request: ArtifactGetRequest, options?: ArtifactOperationOptions): Promise<ArtifactContent>;
    head(ref: ArtifactStorageRef): Promise<ArtifactObjectMetadata | null>;
    exists(ref: ArtifactStorageRef): Promise<boolean>;
    delete(ref: ArtifactStorageRef): Promise<void>;
    copy(request: ArtifactCopyRequest): Promise<ArtifactStorageRef>;
    createDownloadAccess?(request: ArtifactDownloadAccessRequest): Promise<ArtifactDownloadAccess>;
    health(): Promise<ProviderHealth>;
    close?(): Promise<void>;
}

契约成员

成员种类签名说明
capabilities方法capabilities(): Promise<ArtifactStoreCapabilities>公开方法;参数与返回类型以签名列为准。
close方法close?(): Promise<void>公开方法;参数与返回类型以签名列为准。
copy方法copy(request: ArtifactCopyRequest): Promise<ArtifactStorageRef>公开方法;参数与返回类型以签名列为准。
createDownloadAccess方法createDownloadAccess?(request: ArtifactDownloadAccessRequest): Promise<ArtifactDownloadAccess>公开方法;参数与返回类型以签名列为准。
delete方法delete(ref: ArtifactStorageRef): Promise<void>公开方法;参数与返回类型以签名列为准。
exists方法exists(ref: ArtifactStorageRef): Promise<boolean>公开方法;参数与返回类型以签名列为准。
get方法get(request: ArtifactGetRequest, options?: ArtifactOperationOptions): Promise<ArtifactContent>公开方法;参数与返回类型以签名列为准。
head方法head(ref: ArtifactStorageRef): Promise<ArtifactObjectMetadata | null>公开方法;参数与返回类型以签名列为准。
health方法health(): Promise<ProviderHealth>公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
put方法put(request: ArtifactPutRequest, options?: ArtifactOperationOptions): Promise<ArtifactStorageRef>公开方法;参数与返回类型以签名列为准。

ArtifactStoreProviderFactory

Artifact Store Provider Factory 接口,共包含 2 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ArtifactStoreProviderFactory } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export interface ArtifactStoreProviderFactory {
    readonly providerId: string;
    create(): ArtifactStoreProvider | Promise<ArtifactStoreProvider>;
}

契约成员

成员种类签名说明
create方法create(): ArtifactStoreProvider | Promise<ArtifactStoreProvider>公开方法;参数与返回类型以签名列为准。
providerId属性readonly providerId: string公开属性;类型、只读和可选状态以签名列为准。

ArtifactByteSource

Artifact Byte Source 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ArtifactByteSource } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/artifact-store

声明

text
export type ArtifactByteSource = Uint8Array | AsyncIterable<Uint8Array>;