@axium/storage 0.12.0 → 0.13.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.
@@ -1,5 +1,4 @@
1
1
  import type { StorageItemMetadata, StorageItemUpdate, UserStorage, UserStorageInfo } from '../common.js';
2
- export declare function parseItem(result: StorageItemMetadata): StorageItemMetadata;
3
2
  export interface UploadOptions {
4
3
  parentId?: string;
5
4
  name?: string;
@@ -7,9 +6,7 @@ export interface UploadOptions {
7
6
  export declare function uploadItem(file: Blob | File, opt?: UploadOptions): Promise<StorageItemMetadata>;
8
7
  export declare function updateItem(fileId: string, data: Blob): Promise<StorageItemMetadata>;
9
8
  export declare function getItemMetadata(fileId: string): Promise<StorageItemMetadata>;
10
- /**
11
- * Gets the metadata for all items in a directory.
12
- */
9
+ /** Gets the metadata for all items in a directory. */
13
10
  export declare function getDirectoryMetadata(parentId: string): Promise<StorageItemMetadata[]>;
14
11
  export declare function downloadItem(fileId: string): Promise<Blob>;
15
12
  export declare function updateItemMetadata(fileId: string, metadata: StorageItemUpdate): Promise<StorageItemMetadata>;
@@ -20,16 +20,8 @@ async function _upload(method, url, data, extraHeaders = {}) {
20
20
  const json = await response.json().catch(() => ({ message: 'Unknown server error (invalid JSON response)' }));
21
21
  if (!response.ok)
22
22
  throw new Error(json.message);
23
- json.modifiedAt = new Date(json.modifiedAt);
24
23
  return json;
25
24
  }
26
- export function parseItem(result) {
27
- result.createdAt = new Date(result.createdAt);
28
- result.modifiedAt = new Date(result.modifiedAt);
29
- if (result.trashedAt)
30
- result.trashedAt = new Date(result.trashedAt);
31
- return result;
32
- }
33
25
  function rawStorage(fileId) {
34
26
  const raw = '/raw/storage' + (fileId ? '/' + fileId : '');
35
27
  if (prefix[0] == '/')
@@ -44,23 +36,17 @@ export async function uploadItem(file, opt = {}) {
44
36
  headers['x-parent'] = opt.parentId;
45
37
  if (opt.name)
46
38
  headers['x-name'] = opt.name;
47
- return parseItem(await _upload('PUT', rawStorage(), file, headers));
39
+ return await _upload('PUT', rawStorage(), file, headers);
48
40
  }
49
41
  export async function updateItem(fileId, data) {
50
- return parseItem(await _upload('POST', rawStorage(fileId), data));
42
+ return await _upload('POST', rawStorage(fileId), data);
51
43
  }
52
44
  export async function getItemMetadata(fileId) {
53
- const result = await fetchAPI('GET', 'storage/item/:id', undefined, fileId);
54
- return parseItem(result);
45
+ return await fetchAPI('GET', 'storage/item/:id', undefined, fileId);
55
46
  }
56
- /**
57
- * Gets the metadata for all items in a directory.
58
- */
47
+ /** Gets the metadata for all items in a directory. */
59
48
  export async function getDirectoryMetadata(parentId) {
60
- const result = await fetchAPI('GET', 'storage/directory/:id', undefined, parentId);
61
- for (const item of result)
62
- parseItem(item);
63
- return result;
49
+ return await fetchAPI('GET', 'storage/directory/:id', undefined, parentId);
64
50
  }
65
51
  export async function downloadItem(fileId) {
66
52
  const response = await fetch(rawStorage(fileId), {
@@ -71,44 +57,23 @@ export async function downloadItem(fileId) {
71
57
  return await response.blob();
72
58
  }
73
59
  export async function updateItemMetadata(fileId, metadata) {
74
- const result = await fetchAPI('PATCH', 'storage/item/:id', metadata, fileId);
75
- return parseItem(result);
60
+ return await fetchAPI('PATCH', 'storage/item/:id', metadata, fileId);
76
61
  }
77
62
  export async function deleteItem(fileId) {
78
- const result = await fetchAPI('DELETE', 'storage/item/:id', undefined, fileId);
79
- return parseItem(result);
63
+ return await fetchAPI('DELETE', 'storage/item/:id', undefined, fileId);
80
64
  }
81
65
  export async function getUserStorage(userId) {
82
- const result = await fetchAPI('GET', 'users/:id/storage', undefined, userId);
83
- result.lastModified = new Date(result.lastModified);
84
- if (result.lastTrashed)
85
- result.lastTrashed = new Date(result.lastTrashed);
86
- for (const item of result.items)
87
- parseItem(item);
88
- return result;
66
+ return await fetchAPI('GET', 'users/:id/storage', undefined, userId);
89
67
  }
90
68
  export async function getUserStats(userId) {
91
- const result = await fetchAPI('OPTIONS', 'users/:id/storage', undefined, userId);
92
- result.lastModified = new Date(result.lastModified);
93
- if (result.lastTrashed)
94
- result.lastTrashed = new Date(result.lastTrashed);
95
- return result;
69
+ return await fetchAPI('OPTIONS', 'users/:id/storage', undefined, userId);
96
70
  }
97
71
  export async function getUserTrash(userId) {
98
- const result = await fetchAPI('GET', 'users/:id/storage/trash', undefined, userId);
99
- for (const item of result)
100
- parseItem(item);
101
- return result;
72
+ return await fetchAPI('GET', 'users/:id/storage/trash', undefined, userId);
102
73
  }
103
74
  export async function itemsSharedWith(userId) {
104
- const result = await fetchAPI('GET', 'users/:id/storage/shared', undefined, userId);
105
- for (const item of result)
106
- parseItem(item);
107
- return result;
75
+ return await fetchAPI('GET', 'users/:id/storage/shared', undefined, userId);
108
76
  }
109
77
  export async function getUserStorageRoot(userId) {
110
- const result = await fetchAPI('GET', 'users/:id/storage/root', undefined, userId);
111
- for (const item of result)
112
- parseItem(item);
113
- return result;
78
+ return await fetchAPI('GET', 'users/:id/storage/root', undefined, userId);
114
79
  }
@@ -23,14 +23,16 @@ declare const StorageCache: z.ZodObject<{
23
23
  id: z.ZodUUID;
24
24
  name: z.ZodString;
25
25
  email: z.ZodOptional<z.ZodEmail>;
26
- emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodDate>>>;
26
+ emailVerified: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodCoercedDate<unknown>>>>;
27
27
  image: z.ZodOptional<z.ZodNullable<z.ZodURL>>;
28
- preferences: z.ZodOptional<z.ZodObject<{
29
- debug: z.ZodBoolean;
30
- }, z.core.$strip>>;
28
+ preferences: z.ZodOptional<z.ZodLazy<z.ZodObject<{
29
+ debug: z.ZodDefault<z.ZodBoolean>;
30
+ }, z.core.$strip>>>;
31
31
  roles: z.ZodArray<z.ZodString>;
32
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
33
  registeredAt: z.ZodCoercedDate<unknown>;
33
34
  isAdmin: z.ZodOptional<z.ZodBoolean>;
35
+ isSuspended: z.ZodOptional<z.ZodBoolean>;
34
36
  }, z.core.$strip>>;
35
37
  }, z.core.$strip>;
36
38
  interface StorageCache extends z.infer<typeof StorageCache> {
package/dist/common.d.ts CHANGED
@@ -1,43 +1,4 @@
1
1
  import * as z from 'zod';
2
- declare module '@axium/core/api' {
3
- interface $API {
4
- 'users/:id/storage': {
5
- OPTIONS: UserStorageInfo;
6
- GET: UserStorage;
7
- };
8
- 'users/:id/storage/root': {
9
- GET: StorageItemMetadata[];
10
- };
11
- 'users/:id/storage/trash': {
12
- GET: StorageItemMetadata[];
13
- };
14
- 'users/:id/storage/shared': {
15
- GET: StorageItemMetadata[];
16
- };
17
- storage: {
18
- OPTIONS: StoragePublicConfig & {
19
- syncProtocolVersion: number;
20
- batchFormatVersion: number;
21
- };
22
- };
23
- 'storage/batch': {
24
- POST: [StorageBatchUpdate[], StorageItemMetadata[]];
25
- };
26
- 'storage/item/:id': {
27
- GET: StorageItemMetadata;
28
- DELETE: StorageItemMetadata;
29
- PATCH: [z.input<typeof StorageItemUpdate>, StorageItemMetadata];
30
- };
31
- 'storage/directory/:id': {
32
- GET: StorageItemMetadata[];
33
- };
34
- 'storage/directory/:id/recursive': {
35
- GET: (StorageItemMetadata & {
36
- path: string;
37
- })[];
38
- };
39
- }
40
- }
41
2
  export declare const StoragePublicConfig: z.ZodObject<{
42
3
  batch: z.ZodObject<{
43
4
  enabled: z.ZodBoolean;
@@ -50,26 +11,6 @@ export declare const StoragePublicConfig: z.ZodObject<{
50
11
  }, z.core.$strip>;
51
12
  export interface StoragePublicConfig extends z.infer<typeof StoragePublicConfig> {
52
13
  }
53
- export declare const syncProtocolVersion = 0;
54
- export declare const StorageLimits: z.ZodObject<{
55
- item_size: z.ZodNumber;
56
- user_items: z.ZodNumber;
57
- user_size: z.ZodNumber;
58
- }, z.core.$strip>;
59
- export interface StorageLimits extends z.infer<typeof StorageLimits> {
60
- }
61
- export interface StorageStats {
62
- usedBytes: number;
63
- itemCount: number;
64
- lastModified: Date;
65
- lastTrashed: Date | null;
66
- }
67
- export interface UserStorageInfo extends StorageStats {
68
- limits: StorageLimits;
69
- }
70
- export interface UserStorage extends UserStorageInfo {
71
- items: StorageItemMetadata[];
72
- }
73
14
  /**
74
15
  * An update to file metadata.
75
16
  */
@@ -97,6 +38,63 @@ export declare const StorageItemMetadata: z.ZodObject<{
97
38
  export interface StorageItemMetadata<T extends Record<string, unknown> = Record<string, unknown>> extends z.infer<typeof StorageItemMetadata> {
98
39
  metadata: T;
99
40
  }
41
+ export declare const syncProtocolVersion = 0;
42
+ export declare const StorageLimits: z.ZodObject<{
43
+ item_size: z.ZodNumber;
44
+ user_items: z.ZodNumber;
45
+ user_size: z.ZodNumber;
46
+ }, z.core.$strip>;
47
+ export interface StorageLimits extends z.infer<typeof StorageLimits> {
48
+ }
49
+ export declare const StorageStats: z.ZodObject<{
50
+ usedBytes: z.ZodNumber;
51
+ itemCount: z.ZodNumber;
52
+ lastModified: z.ZodCoercedDate<unknown>;
53
+ lastTrashed: z.ZodNullable<z.ZodCoercedDate<unknown>>;
54
+ }, z.core.$strip>;
55
+ export interface StorageStats extends z.infer<typeof StorageStats> {
56
+ }
57
+ export declare const UserStorageInfo: z.ZodObject<{
58
+ limits: z.ZodObject<{
59
+ item_size: z.ZodNumber;
60
+ user_items: z.ZodNumber;
61
+ user_size: z.ZodNumber;
62
+ }, z.core.$strip>;
63
+ usedBytes: z.ZodNumber;
64
+ itemCount: z.ZodNumber;
65
+ lastModified: z.ZodCoercedDate<unknown>;
66
+ lastTrashed: z.ZodNullable<z.ZodCoercedDate<unknown>>;
67
+ }, z.core.$strip>;
68
+ export interface UserStorageInfo extends z.infer<typeof UserStorageInfo> {
69
+ }
70
+ export declare const UserStorage: z.ZodObject<{
71
+ items: z.ZodArray<z.ZodObject<{
72
+ createdAt: z.ZodCoercedDate<unknown>;
73
+ dataURL: z.ZodString;
74
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
75
+ id: z.ZodUUID;
76
+ immutable: z.ZodBoolean;
77
+ modifiedAt: z.ZodCoercedDate<unknown>;
78
+ name: z.ZodString;
79
+ userId: z.ZodUUID;
80
+ parentId: z.ZodNullable<z.ZodUUID>;
81
+ size: z.ZodInt;
82
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
83
+ type: z.ZodString;
84
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
85
+ }, z.core.$strip>>;
86
+ limits: z.ZodObject<{
87
+ item_size: z.ZodNumber;
88
+ user_items: z.ZodNumber;
89
+ user_size: z.ZodNumber;
90
+ }, z.core.$strip>;
91
+ usedBytes: z.ZodNumber;
92
+ itemCount: z.ZodNumber;
93
+ lastModified: z.ZodCoercedDate<unknown>;
94
+ lastTrashed: z.ZodNullable<z.ZodCoercedDate<unknown>>;
95
+ }, z.core.$strip>;
96
+ export interface UserStorage extends z.infer<typeof UserStorage> {
97
+ }
100
98
  /**
101
99
  * Formats:
102
100
  *
@@ -124,3 +122,229 @@ export declare const StorageBatchUpdate: z.ZodObject<{
124
122
  }, z.core.$strip>;
125
123
  export interface StorageBatchUpdate extends z.infer<typeof StorageBatchUpdate> {
126
124
  }
125
+ declare const StorageAPI: {
126
+ readonly 'users/:id/storage': {
127
+ readonly OPTIONS: z.ZodObject<{
128
+ limits: z.ZodObject<{
129
+ item_size: z.ZodNumber;
130
+ user_items: z.ZodNumber;
131
+ user_size: z.ZodNumber;
132
+ }, z.core.$strip>;
133
+ usedBytes: z.ZodNumber;
134
+ itemCount: z.ZodNumber;
135
+ lastModified: z.ZodCoercedDate<unknown>;
136
+ lastTrashed: z.ZodNullable<z.ZodCoercedDate<unknown>>;
137
+ }, z.core.$strip>;
138
+ readonly GET: z.ZodObject<{
139
+ items: z.ZodArray<z.ZodObject<{
140
+ createdAt: z.ZodCoercedDate<unknown>;
141
+ dataURL: z.ZodString;
142
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
143
+ id: z.ZodUUID;
144
+ immutable: z.ZodBoolean;
145
+ modifiedAt: z.ZodCoercedDate<unknown>;
146
+ name: z.ZodString;
147
+ userId: z.ZodUUID;
148
+ parentId: z.ZodNullable<z.ZodUUID>;
149
+ size: z.ZodInt;
150
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
151
+ type: z.ZodString;
152
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
153
+ }, z.core.$strip>>;
154
+ limits: z.ZodObject<{
155
+ item_size: z.ZodNumber;
156
+ user_items: z.ZodNumber;
157
+ user_size: z.ZodNumber;
158
+ }, z.core.$strip>;
159
+ usedBytes: z.ZodNumber;
160
+ itemCount: z.ZodNumber;
161
+ lastModified: z.ZodCoercedDate<unknown>;
162
+ lastTrashed: z.ZodNullable<z.ZodCoercedDate<unknown>>;
163
+ }, z.core.$strip>;
164
+ };
165
+ readonly 'users/:id/storage/root': {
166
+ readonly GET: z.ZodArray<z.ZodObject<{
167
+ createdAt: z.ZodCoercedDate<unknown>;
168
+ dataURL: z.ZodString;
169
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
170
+ id: z.ZodUUID;
171
+ immutable: z.ZodBoolean;
172
+ modifiedAt: z.ZodCoercedDate<unknown>;
173
+ name: z.ZodString;
174
+ userId: z.ZodUUID;
175
+ parentId: z.ZodNullable<z.ZodUUID>;
176
+ size: z.ZodInt;
177
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
178
+ type: z.ZodString;
179
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
180
+ }, z.core.$strip>>;
181
+ };
182
+ readonly 'users/:id/storage/trash': {
183
+ readonly GET: z.ZodArray<z.ZodObject<{
184
+ createdAt: z.ZodCoercedDate<unknown>;
185
+ dataURL: z.ZodString;
186
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
187
+ id: z.ZodUUID;
188
+ immutable: z.ZodBoolean;
189
+ modifiedAt: z.ZodCoercedDate<unknown>;
190
+ name: z.ZodString;
191
+ userId: z.ZodUUID;
192
+ parentId: z.ZodNullable<z.ZodUUID>;
193
+ size: z.ZodInt;
194
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
195
+ type: z.ZodString;
196
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
197
+ }, z.core.$strip>>;
198
+ };
199
+ readonly 'users/:id/storage/shared': {
200
+ readonly GET: z.ZodArray<z.ZodObject<{
201
+ createdAt: z.ZodCoercedDate<unknown>;
202
+ dataURL: z.ZodString;
203
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
204
+ id: z.ZodUUID;
205
+ immutable: z.ZodBoolean;
206
+ modifiedAt: z.ZodCoercedDate<unknown>;
207
+ name: z.ZodString;
208
+ userId: z.ZodUUID;
209
+ parentId: z.ZodNullable<z.ZodUUID>;
210
+ size: z.ZodInt;
211
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
212
+ type: z.ZodString;
213
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
214
+ }, z.core.$strip>>;
215
+ };
216
+ readonly storage: {
217
+ readonly OPTIONS: z.ZodObject<{
218
+ batch: z.ZodObject<{
219
+ enabled: z.ZodBoolean;
220
+ max_items: z.ZodNumber;
221
+ max_item_size: z.ZodNumber;
222
+ }, z.core.$strip>;
223
+ chunk: z.ZodBoolean;
224
+ max_transfer_size: z.ZodNumber;
225
+ max_chunks: z.ZodNumber;
226
+ syncProtocolVersion: z.ZodNumber;
227
+ batchFormatVersion: z.ZodNumber;
228
+ }, z.core.$strip>;
229
+ };
230
+ readonly 'storage/batch': {
231
+ readonly POST: readonly [z.ZodArray<z.ZodObject<{
232
+ deleted: z.ZodArray<z.ZodUUID>;
233
+ metadata: z.ZodRecord<z.ZodUUID, z.ZodObject<{
234
+ name: z.ZodOptional<z.ZodString>;
235
+ owner: z.ZodOptional<z.ZodUUID>;
236
+ trash: z.ZodOptional<z.ZodBoolean>;
237
+ }, z.core.$strip>>;
238
+ content: z.ZodRecord<z.ZodUUID, z.ZodObject<{
239
+ offset: z.ZodInt;
240
+ size: z.ZodInt;
241
+ }, z.core.$strip>>;
242
+ }, z.core.$strip>>, z.ZodArray<z.ZodObject<{
243
+ createdAt: z.ZodCoercedDate<unknown>;
244
+ dataURL: z.ZodString;
245
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
246
+ id: z.ZodUUID;
247
+ immutable: z.ZodBoolean;
248
+ modifiedAt: z.ZodCoercedDate<unknown>;
249
+ name: z.ZodString;
250
+ userId: z.ZodUUID;
251
+ parentId: z.ZodNullable<z.ZodUUID>;
252
+ size: z.ZodInt;
253
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
254
+ type: z.ZodString;
255
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
256
+ }, z.core.$strip>>];
257
+ };
258
+ readonly 'storage/item/:id': {
259
+ readonly GET: z.ZodObject<{
260
+ createdAt: z.ZodCoercedDate<unknown>;
261
+ dataURL: z.ZodString;
262
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
263
+ id: z.ZodUUID;
264
+ immutable: z.ZodBoolean;
265
+ modifiedAt: z.ZodCoercedDate<unknown>;
266
+ name: z.ZodString;
267
+ userId: z.ZodUUID;
268
+ parentId: z.ZodNullable<z.ZodUUID>;
269
+ size: z.ZodInt;
270
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
271
+ type: z.ZodString;
272
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
273
+ }, z.core.$strip>;
274
+ readonly DELETE: z.ZodObject<{
275
+ createdAt: z.ZodCoercedDate<unknown>;
276
+ dataURL: z.ZodString;
277
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
278
+ id: z.ZodUUID;
279
+ immutable: z.ZodBoolean;
280
+ modifiedAt: z.ZodCoercedDate<unknown>;
281
+ name: z.ZodString;
282
+ userId: z.ZodUUID;
283
+ parentId: z.ZodNullable<z.ZodUUID>;
284
+ size: z.ZodInt;
285
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
286
+ type: z.ZodString;
287
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
288
+ }, z.core.$strip>;
289
+ readonly PATCH: readonly [z.ZodObject<{
290
+ name: z.ZodOptional<z.ZodString>;
291
+ owner: z.ZodOptional<z.ZodUUID>;
292
+ trash: z.ZodOptional<z.ZodBoolean>;
293
+ }, z.core.$strip>, z.ZodObject<{
294
+ createdAt: z.ZodCoercedDate<unknown>;
295
+ dataURL: z.ZodString;
296
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
297
+ id: z.ZodUUID;
298
+ immutable: z.ZodBoolean;
299
+ modifiedAt: z.ZodCoercedDate<unknown>;
300
+ name: z.ZodString;
301
+ userId: z.ZodUUID;
302
+ parentId: z.ZodNullable<z.ZodUUID>;
303
+ size: z.ZodInt;
304
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
305
+ type: z.ZodString;
306
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
307
+ }, z.core.$strip>];
308
+ };
309
+ readonly 'storage/directory/:id': {
310
+ readonly GET: z.ZodArray<z.ZodObject<{
311
+ createdAt: z.ZodCoercedDate<unknown>;
312
+ dataURL: z.ZodString;
313
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
314
+ id: z.ZodUUID;
315
+ immutable: z.ZodBoolean;
316
+ modifiedAt: z.ZodCoercedDate<unknown>;
317
+ name: z.ZodString;
318
+ userId: z.ZodUUID;
319
+ parentId: z.ZodNullable<z.ZodUUID>;
320
+ size: z.ZodInt;
321
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
322
+ type: z.ZodString;
323
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
324
+ }, z.core.$strip>>;
325
+ };
326
+ readonly 'storage/directory/:id/recursive': {
327
+ readonly GET: z.ZodArray<z.ZodObject<{
328
+ createdAt: z.ZodCoercedDate<unknown>;
329
+ dataURL: z.ZodString;
330
+ hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
331
+ id: z.ZodUUID;
332
+ immutable: z.ZodBoolean;
333
+ modifiedAt: z.ZodCoercedDate<unknown>;
334
+ name: z.ZodString;
335
+ userId: z.ZodUUID;
336
+ parentId: z.ZodNullable<z.ZodUUID>;
337
+ size: z.ZodInt;
338
+ trashedAt: z.ZodNullable<z.ZodCoercedDate<unknown>>;
339
+ type: z.ZodString;
340
+ metadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
341
+ path: z.ZodString;
342
+ }, z.core.$strip>>;
343
+ };
344
+ };
345
+ type StorageAPI = typeof StorageAPI;
346
+ declare module '@axium/core/api' {
347
+ interface $API extends StorageAPI {
348
+ }
349
+ }
350
+ export {};
package/dist/common.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { $API } from '@axium/core';
1
2
  import * as z from 'zod';
2
3
  export const StoragePublicConfig = z.object({
3
4
  /** Configuration for batch updates */
@@ -16,15 +17,6 @@ export const StoragePublicConfig = z.object({
16
17
  /** Maximum number of chunks */
17
18
  max_chunks: z.number(),
18
19
  });
19
- export const syncProtocolVersion = 0;
20
- export const StorageLimits = z.object({
21
- /** The maximum size per item in MB */
22
- item_size: z.number(),
23
- /** Maximum number of items per user */
24
- user_items: z.number(),
25
- /** The maximum storage size per user in MB */
26
- user_size: z.number(),
27
- });
28
20
  /**
29
21
  * An update to file metadata.
30
22
  */
@@ -51,6 +43,29 @@ export const StorageItemMetadata = z.object({
51
43
  type: z.string(),
52
44
  metadata: z.record(z.string(), z.unknown()),
53
45
  });
46
+ export const syncProtocolVersion = 0;
47
+ export const StorageLimits = z.object({
48
+ /** The maximum size per item in MB */
49
+ item_size: z.number(),
50
+ /** Maximum number of items per user */
51
+ user_items: z.number(),
52
+ /** The maximum storage size per user in MB */
53
+ user_size: z.number(),
54
+ });
55
+ export const StorageStats = z.object({
56
+ usedBytes: z.number().nonnegative(),
57
+ itemCount: z.number().nonnegative(),
58
+ lastModified: z.coerce.date(),
59
+ lastTrashed: z.coerce.date().nullable(),
60
+ });
61
+ export const UserStorageInfo = z.object({
62
+ ...StorageStats.shape,
63
+ limits: StorageLimits,
64
+ });
65
+ export const UserStorage = z.object({
66
+ ...UserStorageInfo.shape,
67
+ items: StorageItemMetadata.array(),
68
+ });
54
69
  /**
55
70
  * Formats:
56
71
  *
@@ -70,3 +85,39 @@ export const StorageBatchUpdate = z.object({
70
85
  metadata: z.record(z.uuid(), StorageItemUpdate),
71
86
  content: z.record(z.uuid(), BatchedContentChange),
72
87
  });
88
+ const StorageAPI = {
89
+ 'users/:id/storage': {
90
+ OPTIONS: UserStorageInfo,
91
+ GET: UserStorage,
92
+ },
93
+ 'users/:id/storage/root': {
94
+ GET: StorageItemMetadata.array(),
95
+ },
96
+ 'users/:id/storage/trash': {
97
+ GET: StorageItemMetadata.array(),
98
+ },
99
+ 'users/:id/storage/shared': {
100
+ GET: StorageItemMetadata.array(),
101
+ },
102
+ storage: {
103
+ OPTIONS: StoragePublicConfig.extend({
104
+ syncProtocolVersion: z.number(),
105
+ batchFormatVersion: z.number(),
106
+ }),
107
+ },
108
+ 'storage/batch': {
109
+ POST: [StorageBatchUpdate.array(), StorageItemMetadata.array()],
110
+ },
111
+ 'storage/item/:id': {
112
+ GET: StorageItemMetadata,
113
+ DELETE: StorageItemMetadata,
114
+ PATCH: [StorageItemUpdate, StorageItemMetadata],
115
+ },
116
+ 'storage/directory/:id': {
117
+ GET: StorageItemMetadata.array(),
118
+ },
119
+ 'storage/directory/:id/recursive': {
120
+ GET: StorageItemMetadata.extend({ path: z.string() }).array(),
121
+ },
122
+ };
123
+ Object.assign($API, StorageAPI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/storage",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "description": "User file storage for Axium",
6
6
  "funding": {
@@ -39,8 +39,8 @@
39
39
  "build": "tsc"
40
40
  },
41
41
  "peerDependencies": {
42
- "@axium/client": ">=0.9.0",
43
- "@axium/core": ">=0.15.0",
42
+ "@axium/client": ">=0.11.0",
43
+ "@axium/core": ">=0.17.0",
44
44
  "@axium/server": ">=0.30.0",
45
45
  "@sveltejs/kit": "^2.27.3",
46
46
  "utilium": "^2.3.8"
@@ -0,0 +1 @@
1
+ import '@axium/storage/common';