alepha 0.10.6 → 0.11.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/api/files.d.ts CHANGED
@@ -2,245 +2,406 @@ import { BucketDescriptor } from "alepha/bucket";
2
2
  import * as _alepha_core1 from "alepha";
3
3
  import { Alepha, FileLike, Static } from "alepha";
4
4
  import "alepha/server/security";
5
- import * as _alepha_postgres83 from "alepha/postgres";
5
+ import * as _alepha_postgres65 from "alepha/postgres";
6
6
  import { Page } from "alepha/postgres";
7
7
  import * as _alepha_server0 from "alepha/server";
8
8
  import { Ok } from "alepha/server";
9
- import { DateTimeProvider, DurationLike } from "alepha/datetime";
9
+ import { DateTime, DateTimeProvider, DurationLike } from "alepha/datetime";
10
10
  import * as _alepha_logger0 from "alepha/logger";
11
11
  import { UserAccountToken } from "alepha/security";
12
- import * as typebox144 from "typebox";
12
+ import * as typebox188 from "typebox";
13
+ import * as dayjs15 from "dayjs";
13
14
 
14
15
  //#region src/entities/files.d.ts
15
- declare const files: _alepha_postgres83.PgTableWithColumnsAndSchema<_alepha_postgres83.PgTableConfig<"files", typebox144.TObject<{
16
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
17
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
18
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
19
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
20
- blobId: typebox144.TString;
21
- creator: typebox144.TOptional<typebox144.TString>;
22
- creatorRealm: typebox144.TOptional<typebox144.TString>;
23
- creatorName: typebox144.TOptional<typebox144.TString>;
24
- bucket: typebox144.TString;
25
- expirationDate: typebox144.TOptional<typebox144.TString>;
26
- name: typebox144.TString;
27
- size: typebox144.TNumber;
28
- mimeType: typebox144.TString;
29
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
30
- checksum: typebox144.TOptional<typebox144.TString>;
31
- }>, _alepha_postgres83.FromSchema<typebox144.TObject<{
32
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
33
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
34
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
35
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
36
- blobId: typebox144.TString;
37
- creator: typebox144.TOptional<typebox144.TString>;
38
- creatorRealm: typebox144.TOptional<typebox144.TString>;
39
- creatorName: typebox144.TOptional<typebox144.TString>;
40
- bucket: typebox144.TString;
41
- expirationDate: typebox144.TOptional<typebox144.TString>;
42
- name: typebox144.TString;
43
- size: typebox144.TNumber;
44
- mimeType: typebox144.TString;
45
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
46
- checksum: typebox144.TOptional<typebox144.TString>;
47
- }>>>, typebox144.TObject<{
48
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
49
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
50
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
51
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
52
- blobId: typebox144.TString;
53
- creator: typebox144.TOptional<typebox144.TString>;
54
- creatorRealm: typebox144.TOptional<typebox144.TString>;
55
- creatorName: typebox144.TOptional<typebox144.TString>;
56
- bucket: typebox144.TString;
57
- expirationDate: typebox144.TOptional<typebox144.TString>;
58
- name: typebox144.TString;
59
- size: typebox144.TNumber;
60
- mimeType: typebox144.TString;
61
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
62
- checksum: typebox144.TOptional<typebox144.TString>;
16
+ declare const files: _alepha_postgres65.EntityDescriptor<typebox188.TObject<{
17
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
18
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
19
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
20
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
21
+ blobId: typebox188.TString;
22
+ creator: typebox188.TOptional<typebox188.TString>;
23
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
24
+ creatorName: typebox188.TOptional<typebox188.TString>;
25
+ bucket: typebox188.TString;
26
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
27
+ name: typebox188.TString;
28
+ size: typebox188.TNumber;
29
+ mimeType: typebox188.TString;
30
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
31
+ checksum: typebox188.TOptional<typebox188.TString>;
63
32
  }>>;
64
- type FileEntity = Static<typeof files.$schema>;
33
+ type FileEntity = Static<typeof files.schema>;
65
34
  //#endregion
66
35
  //#region src/schemas/fileQuerySchema.d.ts
67
- declare const fileQuerySchema: typebox144.TObject<{
68
- page: typebox144.TOptional<typebox144.TInteger>;
69
- size: typebox144.TOptional<typebox144.TInteger>;
70
- sort: typebox144.TOptional<typebox144.TString>;
71
- bucket: typebox144.TOptional<typebox144.TString>;
72
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
36
+ declare const fileQuerySchema: typebox188.TObject<{
37
+ page: typebox188.TOptional<typebox188.TInteger>;
38
+ size: typebox188.TOptional<typebox188.TInteger>;
39
+ sort: typebox188.TOptional<typebox188.TString>;
40
+ bucket: typebox188.TOptional<typebox188.TString>;
41
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
42
+ name: typebox188.TOptional<typebox188.TString>;
43
+ mimeType: typebox188.TOptional<typebox188.TString>;
44
+ creator: typebox188.TOptional<typebox188.TString>;
45
+ createdAfter: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
46
+ createdBefore: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
73
47
  }>;
74
48
  type FileQuery = Static<typeof fileQuerySchema>;
75
49
  //#endregion
76
50
  //#region src/schemas/fileResourceSchema.d.ts
77
- declare const fileResourceSchema: typebox144.TObject<{
78
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
79
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
80
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
81
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
82
- blobId: typebox144.TString;
83
- creator: typebox144.TOptional<typebox144.TString>;
84
- creatorRealm: typebox144.TOptional<typebox144.TString>;
85
- creatorName: typebox144.TOptional<typebox144.TString>;
86
- bucket: typebox144.TString;
87
- expirationDate: typebox144.TOptional<typebox144.TString>;
88
- name: typebox144.TString;
89
- size: typebox144.TNumber;
90
- mimeType: typebox144.TString;
91
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
92
- checksum: typebox144.TOptional<typebox144.TString>;
51
+ declare const fileResourceSchema: typebox188.TObject<{
52
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
53
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
54
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
55
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
56
+ blobId: typebox188.TString;
57
+ creator: typebox188.TOptional<typebox188.TString>;
58
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
59
+ creatorName: typebox188.TOptional<typebox188.TString>;
60
+ bucket: typebox188.TString;
61
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
62
+ name: typebox188.TString;
63
+ size: typebox188.TNumber;
64
+ mimeType: typebox188.TString;
65
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
66
+ checksum: typebox188.TOptional<typebox188.TString>;
93
67
  }>;
94
68
  type FileResource = Static<typeof fileResourceSchema>;
95
69
  //#endregion
70
+ //#region src/schemas/storageStatsSchema.d.ts
71
+ declare const bucketStatsSchema: typebox188.TObject<{
72
+ bucket: typebox188.TString;
73
+ totalSize: typebox188.TNumber;
74
+ fileCount: typebox188.TNumber;
75
+ }>;
76
+ declare const mimeTypeStatsSchema: typebox188.TObject<{
77
+ mimeType: typebox188.TString;
78
+ fileCount: typebox188.TNumber;
79
+ }>;
80
+ declare const storageStatsSchema: typebox188.TObject<{
81
+ totalSize: typebox188.TNumber;
82
+ totalFiles: typebox188.TNumber;
83
+ byBucket: typebox188.TArray<typebox188.TObject<{
84
+ bucket: typebox188.TString;
85
+ totalSize: typebox188.TNumber;
86
+ fileCount: typebox188.TNumber;
87
+ }>>;
88
+ byMimeType: typebox188.TArray<typebox188.TObject<{
89
+ mimeType: typebox188.TString;
90
+ fileCount: typebox188.TNumber;
91
+ }>>;
92
+ }>;
93
+ type BucketStats = Static<typeof bucketStatsSchema>;
94
+ type MimeTypeStats = Static<typeof mimeTypeStatsSchema>;
95
+ type StorageStats = Static<typeof storageStatsSchema>;
96
+ //#endregion
96
97
  //#region src/services/FileService.d.ts
97
98
  declare class FileService {
98
99
  protected readonly alepha: Alepha;
99
100
  protected readonly log: _alepha_logger0.Logger;
100
- protected readonly fileRepository: _alepha_postgres83.RepositoryDescriptor<_alepha_postgres83.PgTableConfig<"files", typebox144.TObject<{
101
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
102
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
103
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
104
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
105
- blobId: typebox144.TString;
106
- creator: typebox144.TOptional<typebox144.TString>;
107
- creatorRealm: typebox144.TOptional<typebox144.TString>;
108
- creatorName: typebox144.TOptional<typebox144.TString>;
109
- bucket: typebox144.TString;
110
- expirationDate: typebox144.TOptional<typebox144.TString>;
111
- name: typebox144.TString;
112
- size: typebox144.TNumber;
113
- mimeType: typebox144.TString;
114
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
115
- checksum: typebox144.TOptional<typebox144.TString>;
116
- }>, _alepha_postgres83.FromSchema<typebox144.TObject<{
117
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
118
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
119
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
120
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
121
- blobId: typebox144.TString;
122
- creator: typebox144.TOptional<typebox144.TString>;
123
- creatorRealm: typebox144.TOptional<typebox144.TString>;
124
- creatorName: typebox144.TOptional<typebox144.TString>;
125
- bucket: typebox144.TString;
126
- expirationDate: typebox144.TOptional<typebox144.TString>;
127
- name: typebox144.TString;
128
- size: typebox144.TNumber;
129
- mimeType: typebox144.TString;
130
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
131
- checksum: typebox144.TOptional<typebox144.TString>;
132
- }>>>, typebox144.TObject<{
133
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
134
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
135
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
136
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
137
- blobId: typebox144.TString;
138
- creator: typebox144.TOptional<typebox144.TString>;
139
- creatorRealm: typebox144.TOptional<typebox144.TString>;
140
- creatorName: typebox144.TOptional<typebox144.TString>;
141
- bucket: typebox144.TString;
142
- expirationDate: typebox144.TOptional<typebox144.TString>;
143
- name: typebox144.TString;
144
- size: typebox144.TNumber;
145
- mimeType: typebox144.TString;
146
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
147
- checksum: typebox144.TOptional<typebox144.TString>;
101
+ protected readonly fileRepository: _alepha_postgres65.RepositoryDescriptor<typebox188.TObject<{
102
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
103
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
104
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
105
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
106
+ blobId: typebox188.TString;
107
+ creator: typebox188.TOptional<typebox188.TString>;
108
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
109
+ creatorName: typebox188.TOptional<typebox188.TString>;
110
+ bucket: typebox188.TString;
111
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
112
+ name: typebox188.TString;
113
+ size: typebox188.TNumber;
114
+ mimeType: typebox188.TString;
115
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
116
+ checksum: typebox188.TOptional<typebox188.TString>;
148
117
  }>>;
149
118
  protected readonly dateTimeProvider: DateTimeProvider;
150
119
  protected readonly defaultBucket: BucketDescriptor;
151
120
  protected onUploadFile: _alepha_core1.HookDescriptor<"bucket:file:uploaded">;
152
121
  protected onDeleteBucketFile: _alepha_core1.HookDescriptor<"bucket:file:deleted">;
122
+ /**
123
+ * Calculates SHA-256 checksum of a file.
124
+ *
125
+ * @param file - The file to calculate checksum for
126
+ * @returns Hexadecimal string representation of the SHA-256 hash
127
+ * @protected
128
+ */
129
+ protected calculateChecksum(file: FileLike): Promise<string>;
130
+ /**
131
+ * Gets a bucket descriptor by name.
132
+ *
133
+ * @param bucketName - The name of the bucket to retrieve (defaults to "default")
134
+ * @returns The bucket descriptor
135
+ * @throws {NotFoundError} If the bucket is not found
136
+ */
153
137
  bucket(bucketName?: string): BucketDescriptor;
138
+ /**
139
+ * Finds files matching the given query criteria with pagination support.
140
+ * Supports filtering by bucket, tags, name, mimeType, creator, and date range.
141
+ *
142
+ * @param q - Query parameters including bucket, tags, name, mimeType, creator, date range, pagination, and sorting
143
+ * @returns Paginated list of file entities
144
+ */
154
145
  findFiles(q?: FileQuery): Promise<Page<FileEntity>>;
146
+ /**
147
+ * Finds files that have expired based on their expiration date.
148
+ * Limited to 1000 files per call to prevent memory issues.
149
+ *
150
+ * @returns Array of expired file entities
151
+ */
155
152
  findExpiredFiles(): Promise<FileEntity[]>;
156
- protected getExpirationDate(ttl?: DurationLike): string | undefined;
153
+ /**
154
+ * Calculates an expiration date based on a TTL (time to live) duration.
155
+ *
156
+ * @param ttl - Duration like "1 day", "2 hours", etc.
157
+ * @returns DateTime representation of the expiration date, or undefined if no TTL provided
158
+ * @protected
159
+ */
160
+ protected getExpirationDate(ttl?: DurationLike): DateTime | undefined;
161
+ /**
162
+ * Uploads a file to a bucket and creates a database record with metadata.
163
+ * Automatically calculates and stores the file checksum (SHA-256).
164
+ *
165
+ * @param file - The file to upload
166
+ * @param options - Upload options including bucket, expiration, user, and tags
167
+ * @param options.bucket - Target bucket name (defaults to "default")
168
+ * @param options.expirationDate - When the file should expire
169
+ * @param options.user - User performing the upload (for audit trail)
170
+ * @param options.tags - Tags to associate with the file
171
+ * @returns The created file entity with all metadata
172
+ * @throws {NotFoundError} If the specified bucket doesn't exist
173
+ */
157
174
  uploadFile(file: FileLike, options?: {
158
- expirationDate?: string | Date;
175
+ expirationDate?: string | DateTime;
159
176
  bucket?: string;
160
177
  user?: UserAccountToken;
161
178
  tags?: string[];
162
179
  }): Promise<FileEntity>;
180
+ /**
181
+ * Streams a file from storage by its database ID.
182
+ *
183
+ * @param id - The database ID (UUID) of the file to stream
184
+ * @returns The file object ready for streaming/downloading
185
+ * @throws {NotFoundError} If the file doesn't exist in the database
186
+ * @throws {FileNotFoundError} If the file exists in database but not in storage
187
+ */
163
188
  streamFile(id: string): Promise<FileLike>;
189
+ /**
190
+ * Updates file metadata (name, tags, expiration date).
191
+ * Does not modify the actual file content in storage.
192
+ *
193
+ * @param id - The database ID (UUID) of the file to update
194
+ * @param data - Partial file data to update
195
+ * @param data.name - New file name
196
+ * @param data.tags - New tags array
197
+ * @param data.expirationDate - New expiration date
198
+ * @returns The updated file entity
199
+ * @throws {NotFoundError} If the file doesn't exist in the database
200
+ */
201
+ updateFile(id: string, data: {
202
+ name?: string;
203
+ tags?: string[];
204
+ expirationDate?: DateTime;
205
+ }): Promise<FileEntity>;
206
+ /**
207
+ * Deletes a file from both storage and database.
208
+ * Handles cases where file is already deleted from storage gracefully.
209
+ * Always ensures database record is removed even if storage deletion fails.
210
+ *
211
+ * @param id - The database ID (UUID) of the file to delete
212
+ * @returns Success response with the deleted file ID
213
+ * @throws {NotFoundError} If the file doesn't exist in the database
214
+ */
164
215
  deleteFile(id: string): Promise<Ok>;
216
+ /**
217
+ * Retrieves a file entity by its ID.
218
+ * If already an entity object, returns it as-is (convenience method).
219
+ *
220
+ * @param id - Either a UUID string or an existing FileEntity object
221
+ * @returns The file entity
222
+ * @throws {NotFoundError} If the file doesn't exist in the database
223
+ */
165
224
  getFileById(id: string | FileEntity): Promise<FileEntity>;
225
+ /**
226
+ * Gets storage statistics including total size, file count, and breakdowns by bucket and MIME type.
227
+ *
228
+ * @returns Storage statistics with aggregated data
229
+ */
230
+ getStorageStats(): Promise<StorageStats>;
231
+ /**
232
+ * Converts a file entity to a file resource (API response format).
233
+ * Currently a pass-through, but allows for future transformation logic.
234
+ *
235
+ * @param entity - The file entity to convert
236
+ * @returns The file resource for API responses
237
+ */
166
238
  entityToResource(entity: FileEntity): FileResource;
167
239
  }
168
240
  //#endregion
169
241
  //#region src/controllers/FileController.d.ts
242
+ /**
243
+ * REST API controller for file management operations.
244
+ * Provides endpoints for uploading, downloading, listing, and deleting files.
245
+ */
170
246
  declare class FileController {
171
247
  protected readonly url = "/files";
172
248
  protected readonly group = "files";
173
249
  protected readonly fileService: FileService;
250
+ /**
251
+ * GET /files - Lists files with optional filtering and pagination.
252
+ * Supports filtering by bucket and tags.
253
+ */
174
254
  readonly findFiles: _alepha_server0.ActionDescriptorFn<{
175
- query: typebox144.TObject<{
176
- page: typebox144.TOptional<typebox144.TInteger>;
177
- size: typebox144.TOptional<typebox144.TInteger>;
178
- sort: typebox144.TOptional<typebox144.TString>;
179
- bucket: typebox144.TOptional<typebox144.TString>;
180
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
255
+ query: typebox188.TObject<{
256
+ page: typebox188.TOptional<typebox188.TInteger>;
257
+ size: typebox188.TOptional<typebox188.TInteger>;
258
+ sort: typebox188.TOptional<typebox188.TString>;
259
+ bucket: typebox188.TOptional<typebox188.TString>;
260
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
261
+ name: typebox188.TOptional<typebox188.TString>;
262
+ mimeType: typebox188.TOptional<typebox188.TString>;
263
+ creator: typebox188.TOptional<typebox188.TString>;
264
+ createdAfter: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
265
+ createdBefore: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
181
266
  }>;
182
- response: _alepha_postgres83.TPage<typebox144.TObject<{
183
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
184
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
185
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
186
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
187
- blobId: typebox144.TString;
188
- creator: typebox144.TOptional<typebox144.TString>;
189
- creatorRealm: typebox144.TOptional<typebox144.TString>;
190
- creatorName: typebox144.TOptional<typebox144.TString>;
191
- bucket: typebox144.TString;
192
- expirationDate: typebox144.TOptional<typebox144.TString>;
193
- name: typebox144.TString;
194
- size: typebox144.TNumber;
195
- mimeType: typebox144.TString;
196
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
197
- checksum: typebox144.TOptional<typebox144.TString>;
267
+ response: _alepha_postgres65.TPage<typebox188.TObject<{
268
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
269
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
270
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
271
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
272
+ blobId: typebox188.TString;
273
+ creator: typebox188.TOptional<typebox188.TString>;
274
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
275
+ creatorName: typebox188.TOptional<typebox188.TString>;
276
+ bucket: typebox188.TString;
277
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
278
+ name: typebox188.TString;
279
+ size: typebox188.TNumber;
280
+ mimeType: typebox188.TString;
281
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
282
+ checksum: typebox188.TOptional<typebox188.TString>;
198
283
  }>>;
199
284
  }>;
285
+ /**
286
+ * DELETE /files/:id - Deletes a file from both storage and database.
287
+ * Removes the file from the bucket and cleans up the database record.
288
+ */
200
289
  readonly deleteFile: _alepha_server0.ActionDescriptorFn<{
201
- params: typebox144.TObject<{
202
- id: typebox144.TString;
290
+ params: typebox188.TObject<{
291
+ id: typebox188.TString;
203
292
  }>;
204
- response: typebox144.TObject<{
205
- ok: typebox144.TBoolean;
206
- id: typebox144.TOptional<typebox144.TUnion<[typebox144.TString, typebox144.TInteger]>>;
207
- count: typebox144.TOptional<typebox144.TNumber>;
293
+ response: typebox188.TObject<{
294
+ ok: typebox188.TBoolean;
295
+ id: typebox188.TOptional<typebox188.TUnion<[typebox188.TString, typebox188.TInteger]>>;
296
+ count: typebox188.TOptional<typebox188.TNumber>;
208
297
  }>;
209
298
  }>;
299
+ /**
300
+ * POST /files - Uploads a new file to storage.
301
+ * Creates a database record with metadata and calculates checksum.
302
+ * Optionally specify bucket and expiration date.
303
+ */
210
304
  readonly uploadFile: _alepha_server0.ActionDescriptorFn<{
211
- body: typebox144.TObject<{
305
+ body: typebox188.TObject<{
212
306
  file: _alepha_core1.TFile;
213
307
  }>;
214
- query: typebox144.TObject<{
215
- expirationDate: typebox144.TOptional<typebox144.TString>;
216
- bucket: typebox144.TOptional<typebox144.TString>;
308
+ query: typebox188.TObject<{
309
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
310
+ bucket: typebox188.TOptional<typebox188.TString>;
311
+ }>;
312
+ response: typebox188.TObject<{
313
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
314
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
315
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
316
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
317
+ blobId: typebox188.TString;
318
+ creator: typebox188.TOptional<typebox188.TString>;
319
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
320
+ creatorName: typebox188.TOptional<typebox188.TString>;
321
+ bucket: typebox188.TString;
322
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
323
+ name: typebox188.TString;
324
+ size: typebox188.TNumber;
325
+ mimeType: typebox188.TString;
326
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
327
+ checksum: typebox188.TOptional<typebox188.TString>;
217
328
  }>;
218
- response: typebox144.TObject<{
219
- id: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_PRIMARY_KEY>, typeof _alepha_postgres83.PG_DEFAULT>;
220
- version: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TInteger, typeof _alepha_postgres83.PG_VERSION>, typeof _alepha_postgres83.PG_DEFAULT>;
221
- createdAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_CREATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
222
- updatedAt: _alepha_postgres83.PgAttr<_alepha_postgres83.PgAttr<typebox144.TString, typeof _alepha_postgres83.PG_UPDATED_AT>, typeof _alepha_postgres83.PG_DEFAULT>;
223
- blobId: typebox144.TString;
224
- creator: typebox144.TOptional<typebox144.TString>;
225
- creatorRealm: typebox144.TOptional<typebox144.TString>;
226
- creatorName: typebox144.TOptional<typebox144.TString>;
227
- bucket: typebox144.TString;
228
- expirationDate: typebox144.TOptional<typebox144.TString>;
229
- name: typebox144.TString;
230
- size: typebox144.TNumber;
231
- mimeType: typebox144.TString;
232
- tags: typebox144.TOptional<typebox144.TArray<typebox144.TString>>;
233
- checksum: typebox144.TOptional<typebox144.TString>;
329
+ }>;
330
+ /**
331
+ * PATCH /files/:id - Updates file metadata.
332
+ * Allows updating name, tags, and expiration date without modifying file content.
333
+ */
334
+ readonly updateFile: _alepha_server0.ActionDescriptorFn<{
335
+ params: typebox188.TObject<{
336
+ id: typebox188.TString;
337
+ }>;
338
+ body: typebox188.TObject<{
339
+ name: typebox188.TOptional<typebox188.TString>;
340
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
341
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
342
+ }>;
343
+ response: typebox188.TObject<{
344
+ id: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TString, typeof _alepha_postgres65.PG_PRIMARY_KEY>, typeof _alepha_postgres65.PG_DEFAULT>;
345
+ version: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TInteger, typeof _alepha_postgres65.PG_VERSION>, typeof _alepha_postgres65.PG_DEFAULT>;
346
+ createdAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_CREATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
347
+ updatedAt: _alepha_postgres65.PgAttr<_alepha_postgres65.PgAttr<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>, typeof _alepha_postgres65.PG_UPDATED_AT>, typeof _alepha_postgres65.PG_DEFAULT>;
348
+ blobId: typebox188.TString;
349
+ creator: typebox188.TOptional<typebox188.TString>;
350
+ creatorRealm: typebox188.TOptional<typebox188.TString>;
351
+ creatorName: typebox188.TOptional<typebox188.TString>;
352
+ bucket: typebox188.TString;
353
+ expirationDate: typebox188.TOptional<typebox188.TCodec<typebox188.TString, dayjs15.Dayjs>>;
354
+ name: typebox188.TString;
355
+ size: typebox188.TNumber;
356
+ mimeType: typebox188.TString;
357
+ tags: typebox188.TOptional<typebox188.TArray<typebox188.TString>>;
358
+ checksum: typebox188.TOptional<typebox188.TString>;
234
359
  }>;
235
360
  }>;
361
+ /**
362
+ * GET /files/:id - Streams/downloads a file by its ID.
363
+ * Returns the file content with appropriate Content-Type header.
364
+ * Cached with ETag support for 1 year (immutable).
365
+ */
236
366
  readonly streamFile: _alepha_server0.ActionDescriptorFn<{
237
- params: typebox144.TObject<{
238
- id: typebox144.TString;
367
+ params: typebox188.TObject<{
368
+ id: typebox188.TString;
239
369
  }>;
240
370
  response: _alepha_core1.TFile;
241
371
  }>;
242
372
  }
243
373
  //#endregion
374
+ //#region src/controllers/StorageStatsController.d.ts
375
+ /**
376
+ * REST API controller for storage analytics and statistics.
377
+ * Provides endpoints for viewing storage usage metrics.
378
+ */
379
+ declare class StorageStatsController {
380
+ protected readonly url = "/files/stats";
381
+ protected readonly group = "files";
382
+ protected readonly fileService: FileService;
383
+ /**
384
+ * GET /files/stats - Gets storage statistics.
385
+ * Returns aggregated data including total size, file count,
386
+ * and breakdowns by bucket and MIME type.
387
+ */
388
+ readonly getStats: _alepha_server0.ActionDescriptorFn<{
389
+ response: typebox188.TObject<{
390
+ totalSize: typebox188.TNumber;
391
+ totalFiles: typebox188.TNumber;
392
+ byBucket: typebox188.TArray<typebox188.TObject<{
393
+ bucket: typebox188.TString;
394
+ totalSize: typebox188.TNumber;
395
+ fileCount: typebox188.TNumber;
396
+ }>>;
397
+ byMimeType: typebox188.TArray<typebox188.TObject<{
398
+ mimeType: typebox188.TString;
399
+ fileCount: typebox188.TNumber;
400
+ }>>;
401
+ }>;
402
+ }>;
403
+ }
404
+ //#endregion
244
405
  //#region src/index.d.ts
245
406
  declare module "alepha/bucket" {
246
407
  interface BucketFileOptions {
@@ -274,5 +435,5 @@ declare module "alepha/bucket" {
274
435
  */
275
436
  declare const AlephaApiFiles: _alepha_core1.Service<_alepha_core1.Module<{}>>;
276
437
  //#endregion
277
- export { AlephaApiFiles, FileController, FileEntity, FileService, files };
438
+ export { AlephaApiFiles, BucketStats, FileController, FileEntity, FileService, MimeTypeStats, StorageStats, StorageStatsController, bucketStatsSchema, files, mimeTypeStatsSchema, storageStatsSchema };
278
439
  //# sourceMappingURL=index.d.ts.map