added file domain logic, updated drizzle package
This commit is contained in:
154
packages/objectstorage/src/data.ts
Normal file
154
packages/objectstorage/src/data.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
import * as v from "valibot";
|
||||
|
||||
// File Upload Configuration Schema
|
||||
export const fileUploadConfigSchema = v.object({
|
||||
bucketName: v.string(),
|
||||
region: v.string(),
|
||||
endpoint: v.string(),
|
||||
accessKey: v.string(),
|
||||
secretKey: v.string(),
|
||||
publicUrl: v.optional(v.string()),
|
||||
maxFileSize: v.pipe(v.number(), v.integer()), // in bytes
|
||||
allowedMimeTypes: v.array(v.string()),
|
||||
allowedExtensions: v.array(v.string()),
|
||||
});
|
||||
export type FileUploadConfig = v.InferOutput<typeof fileUploadConfigSchema>;
|
||||
|
||||
// File Visibility Schema
|
||||
export const fileVisibilitySchema = v.picklist([
|
||||
"public",
|
||||
"private",
|
||||
"restricted",
|
||||
]);
|
||||
export type FileVisibility = v.InferOutput<typeof fileVisibilitySchema>;
|
||||
|
||||
// File Metadata Schema
|
||||
export const fileMetadataSchema = v.object({
|
||||
id: v.string(),
|
||||
filename: v.string(),
|
||||
originalName: v.string(),
|
||||
mimeType: v.string(),
|
||||
size: v.pipe(v.number(), v.integer()),
|
||||
hash: v.string(),
|
||||
bucketName: v.string(),
|
||||
objectKey: v.string(),
|
||||
r2Url: v.string(),
|
||||
visibility: fileVisibilitySchema,
|
||||
userId: v.string(),
|
||||
metadata: v.optional(v.record(v.string(), v.any())),
|
||||
tags: v.optional(v.array(v.string())),
|
||||
uploadedAt: v.date(),
|
||||
expiresAt: v.optional(v.date()),
|
||||
});
|
||||
export type FileMetadata = v.InferOutput<typeof fileMetadataSchema>;
|
||||
|
||||
// Upload Result Schema
|
||||
export const uploadResultSchema = v.object({
|
||||
success: v.boolean(),
|
||||
file: v.optional(fileMetadataSchema),
|
||||
error: v.optional(v.string()),
|
||||
uploadId: v.optional(v.string()),
|
||||
});
|
||||
export type UploadResult = v.InferOutput<typeof uploadResultSchema>;
|
||||
|
||||
// Presigned URL Result Schema
|
||||
export const presignedUrlResultSchema = v.object({
|
||||
uploadUrl: v.string(),
|
||||
downloadUrl: v.optional(v.string()),
|
||||
expiresIn: v.pipe(v.number(), v.integer()),
|
||||
fields: v.optional(v.record(v.string(), v.any())),
|
||||
});
|
||||
export type PresignedUrlResult = v.InferOutput<typeof presignedUrlResultSchema>;
|
||||
|
||||
// File Validation Result Schema
|
||||
export const fileValidationResultSchema = v.object({
|
||||
isValid: v.boolean(),
|
||||
errors: v.array(v.string()),
|
||||
warnings: v.array(v.string()),
|
||||
});
|
||||
export type FileValidationResult = v.InferOutput<
|
||||
typeof fileValidationResultSchema
|
||||
>;
|
||||
|
||||
// Image Resize Options Schema
|
||||
export const imageResizeOptionsSchema = v.object({
|
||||
width: v.optional(v.pipe(v.number(), v.integer())),
|
||||
height: v.optional(v.pipe(v.number(), v.integer())),
|
||||
fit: v.optional(
|
||||
v.picklist(["cover", "contain", "fill", "inside", "outside"]),
|
||||
),
|
||||
});
|
||||
export type ImageResizeOptions = v.InferOutput<typeof imageResizeOptionsSchema>;
|
||||
|
||||
// Thumbnail Size Schema
|
||||
export const thumbnailSizeSchema = v.object({
|
||||
width: v.pipe(v.number(), v.integer()),
|
||||
height: v.pipe(v.number(), v.integer()),
|
||||
});
|
||||
export type ThumbnailSize = v.InferOutput<typeof thumbnailSizeSchema>;
|
||||
|
||||
// Image Processing Options Schema
|
||||
export const imageProcessingOptionsSchema = v.object({
|
||||
resize: v.optional(imageResizeOptionsSchema),
|
||||
format: v.optional(v.picklist(["jpeg", "png", "webp", "avif"])),
|
||||
quality: v.optional(v.pipe(v.number(), v.integer())),
|
||||
generateThumbnail: v.optional(v.boolean()),
|
||||
thumbnailSize: v.optional(thumbnailSizeSchema),
|
||||
});
|
||||
export type ImageProcessingOptions = v.InferOutput<
|
||||
typeof imageProcessingOptionsSchema
|
||||
>;
|
||||
|
||||
// File Processing Result Schema
|
||||
export const fileProcessingResultSchema = v.object({
|
||||
processed: v.boolean(),
|
||||
originalFile: v.optional(v.instance(Uint8Array)), // Buffer equivalent
|
||||
processedFile: v.optional(v.instance(Uint8Array)), // Buffer equivalent
|
||||
thumbnail: v.optional(v.instance(Uint8Array)), // Buffer equivalent
|
||||
metadata: v.optional(v.record(v.string(), v.any())),
|
||||
error: v.optional(v.string()),
|
||||
});
|
||||
export type FileProcessingResult = v.InferOutput<
|
||||
typeof fileProcessingResultSchema
|
||||
>;
|
||||
|
||||
// File Security Result Schema (from utils.ts)
|
||||
export const fileSecurityResultSchema = v.object({
|
||||
isSecure: v.boolean(),
|
||||
issues: v.array(v.string()),
|
||||
warnings: v.array(v.string()),
|
||||
});
|
||||
export type FileSecurityResult = v.InferOutput<typeof fileSecurityResultSchema>;
|
||||
|
||||
// Document Processing Options Schema
|
||||
export const documentProcessingOptionsSchema = v.object({
|
||||
extractText: v.optional(v.boolean()),
|
||||
generatePreview: v.optional(v.boolean()),
|
||||
extractMetadata: v.optional(v.boolean()),
|
||||
validateStructure: v.optional(v.boolean()),
|
||||
});
|
||||
export type DocumentProcessingOptions = v.InferOutput<
|
||||
typeof documentProcessingOptionsSchema
|
||||
>;
|
||||
|
||||
// Video Processing Options Schema
|
||||
export const videoProcessingOptionsSchema = v.object({
|
||||
generateThumbnail: v.optional(v.boolean()),
|
||||
extractMetadata: v.optional(v.boolean()),
|
||||
thumbnailTimestamp: v.optional(v.number()), // Seconds into video for thumbnail
|
||||
thumbnailSize: v.optional(thumbnailSizeSchema),
|
||||
});
|
||||
export type VideoProcessingOptions = v.InferOutput<
|
||||
typeof videoProcessingOptionsSchema
|
||||
>;
|
||||
|
||||
// Upload Options Schema (used in client.ts)
|
||||
export const uploadOptionsSchema = v.object({
|
||||
visibility: v.optional(fileVisibilitySchema),
|
||||
metadata: v.optional(v.record(v.string(), v.any())),
|
||||
tags: v.optional(v.array(v.string())),
|
||||
processImage: v.optional(v.boolean()),
|
||||
processDocument: v.optional(v.boolean()),
|
||||
processVideo: v.optional(v.boolean()),
|
||||
});
|
||||
export type UploadOptions = v.InferOutput<typeof uploadOptionsSchema>;
|
||||
Reference in New Issue
Block a user