Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ts types #1186

Closed
wants to merge 14 commits into from
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bracketSpacing": true
}
4 changes: 3 additions & 1 deletion src/Credentials.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { ICredentials } from './internal/type.ts'

export class Credentials {
public accessKey: string
public secretKey: string
public sessionToken?: string

constructor({ accessKey, secretKey, sessionToken }: { accessKey: string; secretKey: string; sessionToken?: string }) {
constructor({ accessKey, secretKey, sessionToken }: ICredentials) {
this.accessKey = accessKey
this.secretKey = secretKey
this.sessionToken = sessionToken
Expand Down
9 changes: 3 additions & 6 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
BucketItemFromList,
BucketItemStat,
IRequest,
RemoveOptions,
RequestHeaders,
ResponseHeader,
StatObjectOpts,
Expand All @@ -50,6 +51,8 @@ import type {
import type { UploadedPart } from './xml-parser.ts'
import * as xmlParsers from './xml-parser.ts'

export type { RemoveOptions }

// will be replaced by bundler.
const Package = { version: process.env.MINIO_JS_PACKAGE_VERSION || 'development' }

Expand Down Expand Up @@ -100,12 +103,6 @@ export type RequestOption = Partial<IRequest> & {

export type NoResultCallback = (error: unknown) => void

export interface RemoveOptions {
versionId?: string
governanceBypass?: boolean
forceDelete?: boolean
}

export class TypedClient {
protected transport: Transport
protected host: string
Expand Down
198 changes: 188 additions & 10 deletions src/internal/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export enum LEGAL_HOLD_STATUS {

export type Transport = Pick<typeof http, 'request'>

export interface UploadedObjectInfo {
etag: string
versionId: string | null
}

export interface IRequest {
protocol: string
port?: number | string
Expand All @@ -58,12 +63,26 @@ export interface IRequest {

export type ICanonicalRequest = string

export interface IncompleteUploadedBucketItem {
key: string
uploadId: string
size: number
export interface ICredentials {
accessKey: string
secretKey: string
sessionToken?: string
}

export type UploadID = string
export type LegalHoldStatus = 'ON' | 'OFF'
export type NoResultCallback = (error: unknown | null) => void
export type ResultCallback<T> = (error: unknown | null, result: T) => void
export type TagList = Record<string, string>
export type EmptyObject = Record<string, never>
export type VersionIdentification = { versionId?: string }
export type Lifecycle = LifecycleConfig | null | ''
export type Lock = LockConfig | EmptyObject
export type Retention = RetentionOptions | EmptyObject
export type IsoDate = string
export type GetObjectOpts = {
versionId?: string
}
export interface MetadataItem {
Key: string
Value: string
Expand Down Expand Up @@ -104,25 +123,184 @@ export type BucketItemWithMetadata = BucketItem & {
metadata?: ItemBucketMetadata | ItemBucketMetadataList
}

export type S3ListObject =
| { prefix: string; size: number }
| { name: string; size: number } // sometime api return this, not sure if it's valid
| {
name: string
lastModified: Date
etag: string
size: number
isDeleteMarker?: boolean
isLatest?: boolean
}

export type ListObjectsOpts = {
MaxKeys?: number
IncludeVersion?: boolean
}

export type StatObjectOpts = {
versionId?: string
}

export type RemoveObjectList = Array<
| string
| {
name: string
versionId?: string
}
>

export interface BucketItemStat {
size: number
etag: string
lastModified: Date
metaData: ItemBucketMetadata
// version id of the object if available
versionId: string | null
}

export interface IncompleteUploadedBucketItem {
key: string
uploadId: string
size: number
}

export interface BucketStream<T> extends ReadableStream {
on(event: 'data', listener: (item: T) => void): this

on(event: 'end' | 'pause' | 'readable' | 'resume' | 'close', listener: () => void): this

on(event: 'error', listener: (err: Error) => void): this

// eslint-disable-next-line @typescript-eslint/no-explicit-any
on(event: string | symbol, listener: (...args: any[]) => void): this
}

export interface BucketItemStat {
export interface PostPolicyResult {
postURL: string
formData: {
[key: string]: any
}
}

export interface Tag {
Key: string
Value: string
}

export interface LifecycleConfig {
Rule: LifecycleRule[]
}

export interface LifecycleRule {
[key: string]: any
}

export interface LockConfig {
objectLockEnabled?: 'Enabled'
mode: LEGAL_HOLD_STATUS
unit: RETENTION_VALIDITY_UNITS
validity: number
}

export interface EncryptionConfig {
Rule?: EncryptionRule[]
}

export interface EncryptionRule {
[key: string]: any
}

export interface ReplicationConfig {
role: string
rules: []
}

export interface ReplicationConfig {
[key: string]: any
}

export interface RetentionOptions {
versionId: string
mode?: RETENTION_MODES
retainUntilDate?: IsoDate
governanceBypass?: boolean
}

export interface LegalHoldOptions {
versionId?: string
status: LEGAL_HOLD_STATUS
}

export interface InputSerialization {
CompressionType?: 'NONE' | 'GZIP' | 'BZIP2'
CSV?: {
AllowQuotedRecordDelimiter?: boolean
Comments?: string
FieldDelimiter?: string
FileHeaderInfo?: 'NONE' | 'IGNORE' | 'USE'
QuoteCharacter?: string
QuoteEscapeCharacter?: string
RecordDelimiter?: string
}
JSON?: {
Type: 'DOCUMENT' | 'LINES'
}
Parquet?: EmptyObject
}

export interface OutputSerialization {
CSV?: {
FieldDelimiter?: string
QuoteCharacter?: string
QuoteEscapeCharacter?: string
QuoteFields?: string
RecordDelimiter?: string
}
JSON?: {
RecordDelimiter?: string
}
}

export interface SelectOptions {
expression: string
expressionType?: string
inputSerialization: InputSerialization
outputSerialization: OutputSerialization
requestProgress?: { Enabled: boolean }
scanRange?: { Start: number; End: number }
}

export interface SourceObjectStats {
size: number
metaData: string
lastModicied: Date
versionId: string
etag: string
lastModified: Date
metaData: ItemBucketMetadata
versionId?: string | null
}

export type StatObjectOpts = {
export interface MakeBucketOpt {
ObjectLocking?: boolean
}

export interface RemoveOptions {
versionId?: string
forceDelete?: boolean
governanceBypass?: boolean
}

export type VersioningConfig = Record<string | number | symbol, unknown>

export interface VersionConfigInput {
Status?: string
MfaDelete?: string

[key: string]: any
}

export type ListObjectV1Opt = {
Delimiter?: string
MaxKeys?: number
IncludeVersion?: boolean
}
Loading