@marlinjai/data-table-file-adapter-storage-brain 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +137 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +94 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
StorageBrainFileAdapter: () => StorageBrainFileAdapter
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/adapter.ts
|
|
28
|
+
var import_storage_brain_sdk = require("@marlinjai/storage-brain-sdk");
|
|
29
|
+
var StorageBrainFileAdapter = class {
|
|
30
|
+
client;
|
|
31
|
+
defaultContext;
|
|
32
|
+
constructor(config) {
|
|
33
|
+
const sdkConfig = {
|
|
34
|
+
apiKey: config.apiKey,
|
|
35
|
+
baseUrl: config.baseUrl,
|
|
36
|
+
timeout: config.timeout,
|
|
37
|
+
maxRetries: config.maxRetries
|
|
38
|
+
};
|
|
39
|
+
this.client = new import_storage_brain_sdk.StorageBrain(sdkConfig);
|
|
40
|
+
this.defaultContext = config.defaultContext ?? "default";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Upload a file to Storage Brain
|
|
44
|
+
*/
|
|
45
|
+
async upload(file, options) {
|
|
46
|
+
const context = options?.context ?? this.defaultContext;
|
|
47
|
+
const result = await this.client.upload(file, {
|
|
48
|
+
context,
|
|
49
|
+
onProgress: options?.onProgress,
|
|
50
|
+
signal: options?.signal,
|
|
51
|
+
tags: options?.metadata
|
|
52
|
+
});
|
|
53
|
+
return this.convertToUploadedFile(result);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Delete a file from Storage Brain
|
|
57
|
+
*/
|
|
58
|
+
async delete(fileId) {
|
|
59
|
+
await this.client.deleteFile(fileId);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get a URL for accessing the file
|
|
63
|
+
* For Storage Brain, the URL is already public and doesn't expire
|
|
64
|
+
*/
|
|
65
|
+
async getUrl(fileId) {
|
|
66
|
+
const file = await this.client.getFile(fileId);
|
|
67
|
+
return file.url;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get file metadata including OCR results
|
|
71
|
+
*/
|
|
72
|
+
async getMetadata(fileId) {
|
|
73
|
+
const file = await this.client.getFile(fileId);
|
|
74
|
+
return {
|
|
75
|
+
id: file.id,
|
|
76
|
+
mimeType: file.fileType,
|
|
77
|
+
sizeBytes: file.sizeBytes,
|
|
78
|
+
createdAt: new Date(file.createdAt),
|
|
79
|
+
processingStatus: this.mapProcessingStatus(file.processingStatus),
|
|
80
|
+
custom: {
|
|
81
|
+
context: file.context,
|
|
82
|
+
tags: file.tags,
|
|
83
|
+
thumbnailUrls: file.metadata?.thumbnailUrls,
|
|
84
|
+
ocrData: file.metadata?.ocrData,
|
|
85
|
+
imageInfo: file.metadata?.imageInfo
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get the underlying Storage Brain client for advanced operations
|
|
91
|
+
*/
|
|
92
|
+
getClient() {
|
|
93
|
+
return this.client;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert Storage Brain FileInfo to UploadedFile format
|
|
97
|
+
*/
|
|
98
|
+
convertToUploadedFile(file) {
|
|
99
|
+
return {
|
|
100
|
+
id: file.id,
|
|
101
|
+
url: file.url,
|
|
102
|
+
originalName: file.originalName,
|
|
103
|
+
mimeType: file.fileType,
|
|
104
|
+
sizeBytes: file.sizeBytes,
|
|
105
|
+
metadata: {
|
|
106
|
+
context: file.context,
|
|
107
|
+
processingStatus: file.processingStatus,
|
|
108
|
+
tags: file.tags,
|
|
109
|
+
thumbnailUrls: file.metadata?.thumbnailUrls,
|
|
110
|
+
ocrData: file.metadata?.ocrData,
|
|
111
|
+
imageInfo: file.metadata?.imageInfo
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Map Storage Brain processing status to adapter format
|
|
117
|
+
*/
|
|
118
|
+
mapProcessingStatus(status) {
|
|
119
|
+
switch (status) {
|
|
120
|
+
case "pending":
|
|
121
|
+
return "pending";
|
|
122
|
+
case "processing":
|
|
123
|
+
return "processing";
|
|
124
|
+
case "completed":
|
|
125
|
+
return "completed";
|
|
126
|
+
case "failed":
|
|
127
|
+
return "failed";
|
|
128
|
+
default:
|
|
129
|
+
return "pending";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
134
|
+
0 && (module.exports = {
|
|
135
|
+
StorageBrainFileAdapter
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/adapter.ts"],"sourcesContent":["/**\n * @marlinjai/data-table-file-adapter-storage-brain\n *\n * Storage Brain file adapter for the data table package.\n * Uses the Storage Brain SDK to handle file uploads, with support for\n * OCR processing, thumbnail generation, and more.\n */\n\nexport { StorageBrainFileAdapter } from './adapter';\nexport type { StorageBrainFileAdapterConfig } from './adapter';\n","import type {\n FileStorageAdapter,\n FileUploadOptions,\n UploadedFile,\n FileMetadata,\n} from '@marlinjai/data-table-core';\nimport {\n StorageBrain,\n type StorageBrainConfig,\n type ProcessingContext,\n type FileInfo,\n} from '@marlinjai/storage-brain-sdk';\n\n/**\n * Configuration for the Storage Brain file adapter\n */\nexport interface StorageBrainFileAdapterConfig {\n /**\n * Storage Brain API key\n */\n apiKey: string;\n\n /**\n * Base URL for the Storage Brain API (optional)\n */\n baseUrl?: string;\n\n /**\n * Default processing context for uploads (default: 'default')\n * - 'invoice' - Enables OCR text extraction\n * - 'framer-site' - Enables thumbnail generation\n * - 'newsletter' - Image validation and EXIF extraction\n * - 'default' - Basic validation only\n */\n defaultContext?: ProcessingContext;\n\n /**\n * Request timeout in milliseconds (default: 30000)\n */\n timeout?: number;\n\n /**\n * Number of retry attempts (default: 3)\n */\n maxRetries?: number;\n}\n\n/**\n * File storage adapter implementation using Storage Brain.\n *\n * Storage Brain is an edge-native file storage service that provides:\n * - File uploads with progress tracking\n * - OCR text extraction (via Google Cloud Vision)\n * - Automatic thumbnail generation\n * - Image validation and EXIF extraction\n *\n * @example\n * ```typescript\n * const fileAdapter = new StorageBrainFileAdapter({\n * apiKey: process.env.STORAGE_BRAIN_API_KEY,\n * defaultContext: 'invoice', // Enable OCR for receipts\n * });\n *\n * // Use with DataTableProvider\n * <DataTableProvider\n * dbAdapter={dbAdapter}\n * fileAdapter={fileAdapter}\n * workspaceId=\"my-workspace\"\n * >\n * ...\n * </DataTableProvider>\n * ```\n */\nexport class StorageBrainFileAdapter implements FileStorageAdapter {\n private client: StorageBrain;\n private defaultContext: ProcessingContext;\n\n constructor(config: StorageBrainFileAdapterConfig) {\n const sdkConfig: StorageBrainConfig = {\n apiKey: config.apiKey,\n baseUrl: config.baseUrl,\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n };\n\n this.client = new StorageBrain(sdkConfig);\n this.defaultContext = config.defaultContext ?? 'default';\n }\n\n /**\n * Upload a file to Storage Brain\n */\n async upload(\n file: File | Blob,\n options?: FileUploadOptions\n ): Promise<UploadedFile> {\n // Determine the context - allow override via options\n const context = (options?.context as ProcessingContext) ?? this.defaultContext;\n\n // Upload to Storage Brain\n const result = await this.client.upload(file, {\n context,\n onProgress: options?.onProgress,\n signal: options?.signal,\n tags: options?.metadata,\n });\n\n // Convert to UploadedFile format\n return this.convertToUploadedFile(result);\n }\n\n /**\n * Delete a file from Storage Brain\n */\n async delete(fileId: string): Promise<void> {\n await this.client.deleteFile(fileId);\n }\n\n /**\n * Get a URL for accessing the file\n * For Storage Brain, the URL is already public and doesn't expire\n */\n async getUrl(fileId: string): Promise<string> {\n const file = await this.client.getFile(fileId);\n return file.url;\n }\n\n /**\n * Get file metadata including OCR results\n */\n async getMetadata(fileId: string): Promise<FileMetadata> {\n const file = await this.client.getFile(fileId);\n\n return {\n id: file.id,\n mimeType: file.fileType,\n sizeBytes: file.sizeBytes,\n createdAt: new Date(file.createdAt),\n processingStatus: this.mapProcessingStatus(file.processingStatus),\n custom: {\n context: file.context,\n tags: file.tags,\n thumbnailUrls: file.metadata?.thumbnailUrls,\n ocrData: file.metadata?.ocrData,\n imageInfo: file.metadata?.imageInfo,\n },\n };\n }\n\n /**\n * Get the underlying Storage Brain client for advanced operations\n */\n getClient(): StorageBrain {\n return this.client;\n }\n\n /**\n * Convert Storage Brain FileInfo to UploadedFile format\n */\n private convertToUploadedFile(file: FileInfo): UploadedFile {\n return {\n id: file.id,\n url: file.url,\n originalName: file.originalName,\n mimeType: file.fileType,\n sizeBytes: file.sizeBytes,\n metadata: {\n context: file.context,\n processingStatus: file.processingStatus,\n tags: file.tags,\n thumbnailUrls: file.metadata?.thumbnailUrls,\n ocrData: file.metadata?.ocrData,\n imageInfo: file.metadata?.imageInfo,\n },\n };\n }\n\n /**\n * Map Storage Brain processing status to adapter format\n */\n private mapProcessingStatus(\n status: string\n ): 'pending' | 'processing' | 'completed' | 'failed' {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'processing':\n return 'processing';\n case 'completed':\n return 'completed';\n case 'failed':\n return 'failed';\n default:\n return 'pending';\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,+BAKO;AA8DA,IAAM,0BAAN,MAA4D;AAAA,EACzD;AAAA,EACA;AAAA,EAER,YAAY,QAAuC;AACjD,UAAM,YAAgC;AAAA,MACpC,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO;AAAA,MAChB,SAAS,OAAO;AAAA,MAChB,YAAY,OAAO;AAAA,IACrB;AAEA,SAAK,SAAS,IAAI,sCAAa,SAAS;AACxC,SAAK,iBAAiB,OAAO,kBAAkB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OACJ,MACA,SACuB;AAEvB,UAAM,UAAW,SAAS,WAAiC,KAAK;AAGhE,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,MAAM;AAAA,MAC5C;AAAA,MACA,YAAY,SAAS;AAAA,MACrB,QAAQ,SAAS;AAAA,MACjB,MAAM,SAAS;AAAA,IACjB,CAAC;AAGD,WAAO,KAAK,sBAAsB,MAAM;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,QAA+B;AAC1C,UAAM,KAAK,OAAO,WAAW,MAAM;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,QAAiC;AAC5C,U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.d.cts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FileStorageAdapter, FileUploadOptions, UploadedFile, FileMetadata } from '@marlinjai/data-table-core';
|
|
2
|
+
import { ProcessingContext, StorageBrain } from '@marlinjai/storage-brain-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the Storage Brain file adapter
|
|
6
|
+
*/
|
|
7
|
+
interface StorageBrainFileAdapterConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Storage Brain API key
|
|
10
|
+
*/
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/**
|
|
13
|
+
* Base URL for the Storage Brain API (optional)
|
|
14
|
+
*/
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Default processing context for uploads (default: 'default')
|
|
18
|
+
* - 'invoice' - Enables OCR text extraction
|
|
19
|
+
* - 'framer-site' - Enables thumbnail generation
|
|
20
|
+
* - 'newsletter' - Image validation and EXIF extraction
|
|
21
|
+
* - 'default' - Basic validation only
|
|
22
|
+
*/
|
|
23
|
+
defaultContext?: ProcessingContext;
|
|
24
|
+
/**
|
|
25
|
+
* Request timeout in milliseconds (default: 30000)
|
|
26
|
+
*/
|
|
27
|
+
timeout?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Number of retry attempts (default: 3)
|
|
30
|
+
*/
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* File storage adapter implementation using Storage Brain.
|
|
35
|
+
*
|
|
36
|
+
* Storage Brain is an edge-native file storage service that provides:
|
|
37
|
+
* - File uploads with progress tracking
|
|
38
|
+
* - OCR text extraction (via Google Cloud Vision)
|
|
39
|
+
* - Automatic thumbnail generation
|
|
40
|
+
* - Image validation and EXIF extraction
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const fileAdapter = new StorageBrainFileAdapter({
|
|
45
|
+
* apiKey: process.env.STORAGE_BRAIN_API_KEY,
|
|
46
|
+
* defaultContext: 'invoice', // Enable OCR for receipts
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Use with DataTableProvider
|
|
50
|
+
* <DataTableProvider
|
|
51
|
+
* dbAdapter={dbAdapter}
|
|
52
|
+
* fileAdapter={fileAdapter}
|
|
53
|
+
* workspaceId="my-workspace"
|
|
54
|
+
* >
|
|
55
|
+
* ...
|
|
56
|
+
* </DataTableProvider>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class StorageBrainFileAdapter implements FileStorageAdapter {
|
|
60
|
+
private client;
|
|
61
|
+
private defaultContext;
|
|
62
|
+
constructor(config: StorageBrainFileAdapterConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Upload a file to Storage Brain
|
|
65
|
+
*/
|
|
66
|
+
upload(file: File | Blob, options?: FileUploadOptions): Promise<UploadedFile>;
|
|
67
|
+
/**
|
|
68
|
+
* Delete a file from Storage Brain
|
|
69
|
+
*/
|
|
70
|
+
delete(fileId: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a URL for accessing the file
|
|
73
|
+
* For Storage Brain, the URL is already public and doesn't expire
|
|
74
|
+
*/
|
|
75
|
+
getUrl(fileId: string): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Get file metadata including OCR results
|
|
78
|
+
*/
|
|
79
|
+
getMetadata(fileId: string): Promise<FileMetadata>;
|
|
80
|
+
/**
|
|
81
|
+
* Get the underlying Storage Brain client for advanced operations
|
|
82
|
+
*/
|
|
83
|
+
getClient(): StorageBrain;
|
|
84
|
+
/**
|
|
85
|
+
* Convert Storage Brain FileInfo to UploadedFile format
|
|
86
|
+
*/
|
|
87
|
+
private convertToUploadedFile;
|
|
88
|
+
/**
|
|
89
|
+
* Map Storage Brain processing status to adapter format
|
|
90
|
+
*/
|
|
91
|
+
private mapProcessingStatus;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { StorageBrainFileAdapter, type StorageBrainFileAdapterConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FileStorageAdapter, FileUploadOptions, UploadedFile, FileMetadata } from '@marlinjai/data-table-core';
|
|
2
|
+
import { ProcessingContext, StorageBrain } from '@marlinjai/storage-brain-sdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Configuration for the Storage Brain file adapter
|
|
6
|
+
*/
|
|
7
|
+
interface StorageBrainFileAdapterConfig {
|
|
8
|
+
/**
|
|
9
|
+
* Storage Brain API key
|
|
10
|
+
*/
|
|
11
|
+
apiKey: string;
|
|
12
|
+
/**
|
|
13
|
+
* Base URL for the Storage Brain API (optional)
|
|
14
|
+
*/
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Default processing context for uploads (default: 'default')
|
|
18
|
+
* - 'invoice' - Enables OCR text extraction
|
|
19
|
+
* - 'framer-site' - Enables thumbnail generation
|
|
20
|
+
* - 'newsletter' - Image validation and EXIF extraction
|
|
21
|
+
* - 'default' - Basic validation only
|
|
22
|
+
*/
|
|
23
|
+
defaultContext?: ProcessingContext;
|
|
24
|
+
/**
|
|
25
|
+
* Request timeout in milliseconds (default: 30000)
|
|
26
|
+
*/
|
|
27
|
+
timeout?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Number of retry attempts (default: 3)
|
|
30
|
+
*/
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* File storage adapter implementation using Storage Brain.
|
|
35
|
+
*
|
|
36
|
+
* Storage Brain is an edge-native file storage service that provides:
|
|
37
|
+
* - File uploads with progress tracking
|
|
38
|
+
* - OCR text extraction (via Google Cloud Vision)
|
|
39
|
+
* - Automatic thumbnail generation
|
|
40
|
+
* - Image validation and EXIF extraction
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const fileAdapter = new StorageBrainFileAdapter({
|
|
45
|
+
* apiKey: process.env.STORAGE_BRAIN_API_KEY,
|
|
46
|
+
* defaultContext: 'invoice', // Enable OCR for receipts
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Use with DataTableProvider
|
|
50
|
+
* <DataTableProvider
|
|
51
|
+
* dbAdapter={dbAdapter}
|
|
52
|
+
* fileAdapter={fileAdapter}
|
|
53
|
+
* workspaceId="my-workspace"
|
|
54
|
+
* >
|
|
55
|
+
* ...
|
|
56
|
+
* </DataTableProvider>
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare class StorageBrainFileAdapter implements FileStorageAdapter {
|
|
60
|
+
private client;
|
|
61
|
+
private defaultContext;
|
|
62
|
+
constructor(config: StorageBrainFileAdapterConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Upload a file to Storage Brain
|
|
65
|
+
*/
|
|
66
|
+
upload(file: File | Blob, options?: FileUploadOptions): Promise<UploadedFile>;
|
|
67
|
+
/**
|
|
68
|
+
* Delete a file from Storage Brain
|
|
69
|
+
*/
|
|
70
|
+
delete(fileId: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a URL for accessing the file
|
|
73
|
+
* For Storage Brain, the URL is already public and doesn't expire
|
|
74
|
+
*/
|
|
75
|
+
getUrl(fileId: string): Promise<string>;
|
|
76
|
+
/**
|
|
77
|
+
* Get file metadata including OCR results
|
|
78
|
+
*/
|
|
79
|
+
getMetadata(fileId: string): Promise<FileMetadata>;
|
|
80
|
+
/**
|
|
81
|
+
* Get the underlying Storage Brain client for advanced operations
|
|
82
|
+
*/
|
|
83
|
+
getClient(): StorageBrain;
|
|
84
|
+
/**
|
|
85
|
+
* Convert Storage Brain FileInfo to UploadedFile format
|
|
86
|
+
*/
|
|
87
|
+
private convertToUploadedFile;
|
|
88
|
+
/**
|
|
89
|
+
* Map Storage Brain processing status to adapter format
|
|
90
|
+
*/
|
|
91
|
+
private mapProcessingStatus;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { StorageBrainFileAdapter, type StorageBrainFileAdapterConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/adapter.ts
|
|
2
|
+
import {
|
|
3
|
+
StorageBrain
|
|
4
|
+
} from "@marlinjai/storage-brain-sdk";
|
|
5
|
+
var StorageBrainFileAdapter = class {
|
|
6
|
+
client;
|
|
7
|
+
defaultContext;
|
|
8
|
+
constructor(config) {
|
|
9
|
+
const sdkConfig = {
|
|
10
|
+
apiKey: config.apiKey,
|
|
11
|
+
baseUrl: config.baseUrl,
|
|
12
|
+
timeout: config.timeout,
|
|
13
|
+
maxRetries: config.maxRetries
|
|
14
|
+
};
|
|
15
|
+
this.client = new StorageBrain(sdkConfig);
|
|
16
|
+
this.defaultContext = config.defaultContext ?? "default";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Upload a file to Storage Brain
|
|
20
|
+
*/
|
|
21
|
+
async upload(file, options) {
|
|
22
|
+
const context = options?.context ?? this.defaultContext;
|
|
23
|
+
const result = await this.client.upload(file, {
|
|
24
|
+
context,
|
|
25
|
+
onProgress: options?.onProgress,
|
|
26
|
+
signal: options?.signal,
|
|
27
|
+
tags: options?.metadata
|
|
28
|
+
});
|
|
29
|
+
return this.convertToUploadedFile(result);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Delete a file from Storage Brain
|
|
33
|
+
*/
|
|
34
|
+
async delete(fileId) {
|
|
35
|
+
await this.client.deleteFile(fileId);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get a URL for accessing the file
|
|
39
|
+
* For Storage Brain, the URL is already public and doesn't expire
|
|
40
|
+
*/
|
|
41
|
+
async getUrl(fileId) {
|
|
42
|
+
const file = await this.client.getFile(fileId);
|
|
43
|
+
return file.url;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get file metadata including OCR results
|
|
47
|
+
*/
|
|
48
|
+
async getMetadata(fileId) {
|
|
49
|
+
const file = await this.client.getFile(fileId);
|
|
50
|
+
return {
|
|
51
|
+
id: file.id,
|
|
52
|
+
mimeType: file.fileType,
|
|
53
|
+
sizeBytes: file.sizeBytes,
|
|
54
|
+
createdAt: new Date(file.createdAt),
|
|
55
|
+
processingStatus: this.mapProcessingStatus(file.processingStatus),
|
|
56
|
+
custom: {
|
|
57
|
+
context: file.context,
|
|
58
|
+
tags: file.tags,
|
|
59
|
+
thumbnailUrls: file.metadata?.thumbnailUrls,
|
|
60
|
+
ocrData: file.metadata?.ocrData,
|
|
61
|
+
imageInfo: file.metadata?.imageInfo
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the underlying Storage Brain client for advanced operations
|
|
67
|
+
*/
|
|
68
|
+
getClient() {
|
|
69
|
+
return this.client;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert Storage Brain FileInfo to UploadedFile format
|
|
73
|
+
*/
|
|
74
|
+
convertToUploadedFile(file) {
|
|
75
|
+
return {
|
|
76
|
+
id: file.id,
|
|
77
|
+
url: file.url,
|
|
78
|
+
originalName: file.originalName,
|
|
79
|
+
mimeType: file.fileType,
|
|
80
|
+
sizeBytes: file.sizeBytes,
|
|
81
|
+
metadata: {
|
|
82
|
+
context: file.context,
|
|
83
|
+
processingStatus: file.processingStatus,
|
|
84
|
+
tags: file.tags,
|
|
85
|
+
thumbnailUrls: file.metadata?.thumbnailUrls,
|
|
86
|
+
ocrData: file.metadata?.ocrData,
|
|
87
|
+
imageInfo: file.metadata?.imageInfo
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Map Storage Brain processing status to adapter format
|
|
93
|
+
*/
|
|
94
|
+
mapProcessingStatus(status) {
|
|
95
|
+
switch (status) {
|
|
96
|
+
case "pending":
|
|
97
|
+
return "pending";
|
|
98
|
+
case "processing":
|
|
99
|
+
return "processing";
|
|
100
|
+
case "completed":
|
|
101
|
+
return "completed";
|
|
102
|
+
case "failed":
|
|
103
|
+
return "failed";
|
|
104
|
+
default:
|
|
105
|
+
return "pending";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
export {
|
|
110
|
+
StorageBrainFileAdapter
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter.ts"],"sourcesContent":["import type {\n FileStorageAdapter,\n FileUploadOptions,\n UploadedFile,\n FileMetadata,\n} from '@marlinjai/data-table-core';\nimport {\n StorageBrain,\n type StorageBrainConfig,\n type ProcessingContext,\n type FileInfo,\n} from '@marlinjai/storage-brain-sdk';\n\n/**\n * Configuration for the Storage Brain file adapter\n */\nexport interface StorageBrainFileAdapterConfig {\n /**\n * Storage Brain API key\n */\n apiKey: string;\n\n /**\n * Base URL for the Storage Brain API (optional)\n */\n baseUrl?: string;\n\n /**\n * Default processing context for uploads (default: 'default')\n * - 'invoice' - Enables OCR text extraction\n * - 'framer-site' - Enables thumbnail generation\n * - 'newsletter' - Image validation and EXIF extraction\n * - 'default' - Basic validation only\n */\n defaultContext?: ProcessingContext;\n\n /**\n * Request timeout in milliseconds (default: 30000)\n */\n timeout?: number;\n\n /**\n * Number of retry attempts (default: 3)\n */\n maxRetries?: number;\n}\n\n/**\n * File storage adapter implementation using Storage Brain.\n *\n * Storage Brain is an edge-native file storage service that provides:\n * - File uploads with progress tracking\n * - OCR text extraction (via Google Cloud Vision)\n * - Automatic thumbnail generation\n * - Image validation and EXIF extraction\n *\n * @example\n * ```typescript\n * const fileAdapter = new StorageBrainFileAdapter({\n * apiKey: process.env.STORAGE_BRAIN_API_KEY,\n * defaultContext: 'invoice', // Enable OCR for receipts\n * });\n *\n * // Use with DataTableProvider\n * <DataTableProvider\n * dbAdapter={dbAdapter}\n * fileAdapter={fileAdapter}\n * workspaceId=\"my-workspace\"\n * >\n * ...\n * </DataTableProvider>\n * ```\n */\nexport class StorageBrainFileAdapter implements FileStorageAdapter {\n private client: StorageBrain;\n private defaultContext: ProcessingContext;\n\n constructor(config: StorageBrainFileAdapterConfig) {\n const sdkConfig: StorageBrainConfig = {\n apiKey: config.apiKey,\n baseUrl: config.baseUrl,\n timeout: config.timeout,\n maxRetries: config.maxRetries,\n };\n\n this.client = new StorageBrain(sdkConfig);\n this.defaultContext = config.defaultContext ?? 'default';\n }\n\n /**\n * Upload a file to Storage Brain\n */\n async upload(\n file: File | Blob,\n options?: FileUploadOptions\n ): Promise<UploadedFile> {\n // Determine the context - allow override via options\n const context = (options?.context as ProcessingContext) ?? this.defaultContext;\n\n // Upload to Storage Brain\n const result = await this.client.upload(file, {\n context,\n onProgress: options?.onProgress,\n signal: options?.signal,\n tags: options?.metadata,\n });\n\n // Convert to UploadedFile format\n return this.convertToUploadedFile(result);\n }\n\n /**\n * Delete a file from Storage Brain\n */\n async delete(fileId: string): Promise<void> {\n await this.client.deleteFile(fileId);\n }\n\n /**\n * Get a URL for accessing the file\n * For Storage Brain, the URL is already public and doesn't expire\n */\n async getUrl(fileId: string): Promise<string> {\n const file = await this.client.getFile(fileId);\n return file.url;\n }\n\n /**\n * Get file metadata including OCR results\n */\n async getMetadata(fileId: string): Promise<FileMetadata> {\n const file = await this.client.getFile(fileId);\n\n return {\n id: file.id,\n mimeType: file.fileType,\n sizeBytes: file.sizeBytes,\n createdAt: new Date(file.createdAt),\n processingStatus: this.mapProcessingStatus(file.processingStatus),\n custom: {\n context: file.context,\n tags: file.tags,\n thumbnailUrls: file.metadata?.thumbnailUrls,\n ocrData: file.metadata?.ocrData,\n imageInfo: file.metadata?.imageInfo,\n },\n };\n }\n\n /**\n * Get the underlying Storage Brain client for advanced operations\n */\n getClient(): StorageBrain {\n return this.client;\n }\n\n /**\n * Convert Storage Brain FileInfo to UploadedFile format\n */\n private convertToUploadedFile(file: FileInfo): UploadedFile {\n return {\n id: file.id,\n url: file.url,\n originalName: file.originalName,\n mimeType: file.fileType,\n sizeBytes: file.sizeBytes,\n metadata: {\n context: file.context,\n processingStatus: file.processingStatus,\n tags: file.tags,\n thumbnailUrls: file.metadata?.thumbnailUrls,\n ocrData: file.metadata?.ocrData,\n imageInfo: file.metadata?.imageInfo,\n },\n };\n }\n\n /**\n * Map Storage Brain processing status to adapter format\n */\n private mapProcessingStatus(\n status: string\n ): 'pending' | 'processing' | 'completed' | 'failed' {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'processing':\n return 'processing';\n case 'completed':\n return 'completed';\n case 'failed':\n return 'failed';\n default:\n return 'pending';\n }\n }\n}\n"],"mappings":";AAMA;AAAA,EACE;AAAA,OAIK;AA8DA,IAAM,0BAAN,MAA4D;AAAA,EACzD;AAAA,EACA;AAAA,EAER,YAAY,QAAuC;AACjD,UAAM,YAAgC;AAAA,MACpC,QAAQ,OAAO;AAAA,MACf,SAAS,OAAO;AAAA,MAChB,SAAS,OAAO;AAAA,MAChB,YAAY,OAAO;AAAA,IACrB;AAEA,SAAK,SAAS,IAAI,aAAa,SAAS;AACxC,SAAK,iBAAiB,OAAO,kBAAkB;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OACJ,MACA,SACuB;AAEvB,UAAM,UAAW,SAAS,WAAiC,KAAK;AAGhE,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,MAAM;AAAA,MAC5C;AAAA,MACA,YAAY,SAAS;AAAA,MACrB,QAAQ,SAAS;AAAA,MACjB,MAAM,SAAS;AAAA,IACjB,CAAC;AAGD,WAAO,KAAK,sBAAsB,MAAM;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,QAA+B;AAC1C,UAAM,KAAK,OAAO,WAAW,MAAM;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,QAAiC;AAC5C,UAAM,OAAO,MAAM,KAAK,OAAO,QAAQ,MAAM;AAC7C,WAAO,KAAK;AAAA,EACd;AAAA;AAA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storage-brain",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Storage Brain file adapter for @marlinjai/data-table",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"default": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsup",
|
|
26
|
+
"dev": "tsup --watch",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@marlinjai/data-table-core": "*",
|
|
31
|
+
"@marlinjai/storage-brain-sdk": "*"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"tsup": "^8.0.1",
|
|
35
|
+
"typescript": "^5.3.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@marlinjai/storage-brain-sdk": ">=0.1.0"
|
|
39
|
+
}
|
|
40
|
+
}
|