@ankhorage/contracts 25.1.0 → 25.2.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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/dist/storage.d.ts +611 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +173 -1
- package/dist/storage.js.map +1 -1
- package/dist/structure/generated.d.ts +2 -2
- package/dist/structure/generated.js +2 -2
- package/dist/structure/generated.js.map +1 -1
- package/package.json +3 -3
- package/src/storage-schemas.test.ts +86 -0
- package/src/storage.ts +197 -0
- package/src/structure/generated.ts +2 -2
package/src/storage.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { DataSchema } from './data/schemas.js';
|
|
2
|
+
|
|
1
3
|
export interface StorageAdapterError {
|
|
2
4
|
code: string;
|
|
3
5
|
message: string;
|
|
@@ -154,3 +156,198 @@ export interface StorageResolveAdapter {
|
|
|
154
156
|
*/
|
|
155
157
|
export interface MediaStorageAdapter
|
|
156
158
|
extends StorageAdapter, StorageListAdapter, StorageResolveAdapter {}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Portable schema sources for provider-neutral storage values and operations.
|
|
162
|
+
*
|
|
163
|
+
* Upload bytes use a standard Base64 string. The source `StorageUploadInput` remains a
|
|
164
|
+
* `Uint8Array` at the adapter boundary; catalogs serialize its `body` with this schema and
|
|
165
|
+
* reconstruct the bytes before invoking an adapter.
|
|
166
|
+
*/
|
|
167
|
+
export const STORAGE_BYTES_SCHEMA = {
|
|
168
|
+
type: 'string',
|
|
169
|
+
format: 'base64',
|
|
170
|
+
} as const satisfies DataSchema;
|
|
171
|
+
|
|
172
|
+
export const STORAGE_IDENTITY_SCHEMA = {
|
|
173
|
+
type: 'object',
|
|
174
|
+
required: ['bucket', 'path'],
|
|
175
|
+
properties: {
|
|
176
|
+
storageId: { type: 'string' },
|
|
177
|
+
bucket: { type: 'string' },
|
|
178
|
+
path: { type: 'string' },
|
|
179
|
+
},
|
|
180
|
+
} as const satisfies DataSchema;
|
|
181
|
+
|
|
182
|
+
export const STORAGE_ASSET_REFERENCE_SCHEMA = {
|
|
183
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
184
|
+
properties: {
|
|
185
|
+
...STORAGE_IDENTITY_SCHEMA.properties,
|
|
186
|
+
publicUrl: { type: 'string' },
|
|
187
|
+
},
|
|
188
|
+
} as const satisfies DataSchema;
|
|
189
|
+
|
|
190
|
+
export const STORAGE_OBJECT_METADATA_SCHEMA = {
|
|
191
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
192
|
+
properties: {
|
|
193
|
+
...STORAGE_IDENTITY_SCHEMA.properties,
|
|
194
|
+
contentType: { type: 'string' },
|
|
195
|
+
sizeBytes: { type: 'integer' },
|
|
196
|
+
createdAt: { type: 'string' },
|
|
197
|
+
updatedAt: { type: 'string' },
|
|
198
|
+
etag: { type: 'string' },
|
|
199
|
+
},
|
|
200
|
+
} as const satisfies DataSchema;
|
|
201
|
+
|
|
202
|
+
export const STORAGE_UPLOAD_INPUT_SCHEMA = {
|
|
203
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
204
|
+
required: ['bucket', 'path', 'body'],
|
|
205
|
+
properties: {
|
|
206
|
+
...STORAGE_IDENTITY_SCHEMA.properties,
|
|
207
|
+
body: STORAGE_BYTES_SCHEMA,
|
|
208
|
+
contentType: { type: 'string' },
|
|
209
|
+
cacheControl: { type: 'string' },
|
|
210
|
+
upsert: { type: 'boolean' },
|
|
211
|
+
},
|
|
212
|
+
} as const satisfies DataSchema;
|
|
213
|
+
|
|
214
|
+
export const STORAGE_UPLOAD_RESULT_SCHEMA = {
|
|
215
|
+
type: 'object',
|
|
216
|
+
required: ['asset'],
|
|
217
|
+
properties: { asset: STORAGE_ASSET_REFERENCE_SCHEMA },
|
|
218
|
+
} as const satisfies DataSchema;
|
|
219
|
+
|
|
220
|
+
export const STORAGE_REMOVE_INPUT_SCHEMA = {
|
|
221
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
222
|
+
description: 'Identifies the stored object to remove.',
|
|
223
|
+
} as const satisfies DataSchema;
|
|
224
|
+
|
|
225
|
+
export const STORAGE_PUBLIC_URL_INPUT_SCHEMA = {
|
|
226
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
227
|
+
description: 'Identifies the stored object whose public URL is requested.',
|
|
228
|
+
} as const satisfies DataSchema;
|
|
229
|
+
|
|
230
|
+
export const STORAGE_PUBLIC_URL_RESULT_SCHEMA = {
|
|
231
|
+
type: 'object',
|
|
232
|
+
required: ['publicUrl'],
|
|
233
|
+
properties: { publicUrl: { type: 'string' } },
|
|
234
|
+
} as const satisfies DataSchema;
|
|
235
|
+
|
|
236
|
+
export const STORAGE_LIST_INPUT_SCHEMA = {
|
|
237
|
+
type: 'object',
|
|
238
|
+
required: ['bucket'],
|
|
239
|
+
properties: {
|
|
240
|
+
storageId: { type: 'string' },
|
|
241
|
+
bucket: { type: 'string' },
|
|
242
|
+
prefix: { type: 'string' },
|
|
243
|
+
cursor: { type: 'string' },
|
|
244
|
+
limit: { type: 'integer' },
|
|
245
|
+
},
|
|
246
|
+
} as const satisfies DataSchema;
|
|
247
|
+
|
|
248
|
+
export const STORAGE_LIST_RESULT_SCHEMA = {
|
|
249
|
+
type: 'object',
|
|
250
|
+
required: ['objects'],
|
|
251
|
+
properties: {
|
|
252
|
+
objects: { type: 'array', items: STORAGE_OBJECT_METADATA_SCHEMA },
|
|
253
|
+
nextCursor: { type: 'string' },
|
|
254
|
+
},
|
|
255
|
+
} as const satisfies DataSchema;
|
|
256
|
+
|
|
257
|
+
export const STORAGE_RESOLVE_INPUT_SCHEMA = {
|
|
258
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
259
|
+
properties: {
|
|
260
|
+
...STORAGE_IDENTITY_SCHEMA.properties,
|
|
261
|
+
access: { type: 'string', enum: ['public', 'signed'] },
|
|
262
|
+
expiresInSeconds: { type: 'integer' },
|
|
263
|
+
},
|
|
264
|
+
} as const satisfies DataSchema;
|
|
265
|
+
|
|
266
|
+
export const STORAGE_RESOLVED_ASSET_SCHEMA = {
|
|
267
|
+
...STORAGE_IDENTITY_SCHEMA,
|
|
268
|
+
required: ['bucket', 'path', 'url', 'access'],
|
|
269
|
+
properties: {
|
|
270
|
+
...STORAGE_IDENTITY_SCHEMA.properties,
|
|
271
|
+
url: { type: 'string' },
|
|
272
|
+
access: { type: 'string', enum: ['public', 'signed'] },
|
|
273
|
+
expiresAt: { type: 'string' },
|
|
274
|
+
},
|
|
275
|
+
} as const satisfies DataSchema;
|
|
276
|
+
|
|
277
|
+
export const STORAGE_RESOLVE_RESULT_SCHEMA = {
|
|
278
|
+
type: 'object',
|
|
279
|
+
required: ['asset'],
|
|
280
|
+
properties: { asset: STORAGE_RESOLVED_ASSET_SCHEMA },
|
|
281
|
+
} as const satisfies DataSchema;
|
|
282
|
+
|
|
283
|
+
export const STORAGE_ADAPTER_ERROR_SCHEMA = {
|
|
284
|
+
type: 'object',
|
|
285
|
+
required: ['code', 'message'],
|
|
286
|
+
properties: {
|
|
287
|
+
code: { type: 'string' },
|
|
288
|
+
message: { type: 'string' },
|
|
289
|
+
},
|
|
290
|
+
} as const satisfies DataSchema;
|
|
291
|
+
|
|
292
|
+
export const STORAGE_SUCCESS_SCHEMA = {
|
|
293
|
+
type: 'object',
|
|
294
|
+
required: ['ok'],
|
|
295
|
+
properties: { ok: { const: true } },
|
|
296
|
+
} as const satisfies DataSchema;
|
|
297
|
+
|
|
298
|
+
export const STORAGE_ERROR_RESULT_SCHEMA = {
|
|
299
|
+
type: 'object',
|
|
300
|
+
required: ['ok', 'error'],
|
|
301
|
+
properties: {
|
|
302
|
+
ok: { const: false },
|
|
303
|
+
error: STORAGE_ADAPTER_ERROR_SCHEMA,
|
|
304
|
+
},
|
|
305
|
+
} as const satisfies DataSchema;
|
|
306
|
+
|
|
307
|
+
export const STORAGE_VOID_RESULT_SCHEMA = {
|
|
308
|
+
oneOf: [STORAGE_SUCCESS_SCHEMA, STORAGE_ERROR_RESULT_SCHEMA],
|
|
309
|
+
} as const satisfies DataSchema;
|
|
310
|
+
|
|
311
|
+
export const STORAGE_UPLOAD_OPERATION_RESULT_SCHEMA = {
|
|
312
|
+
oneOf: [
|
|
313
|
+
{
|
|
314
|
+
...STORAGE_SUCCESS_SCHEMA,
|
|
315
|
+
required: ['ok', 'data'],
|
|
316
|
+
properties: { ...STORAGE_SUCCESS_SCHEMA.properties, data: STORAGE_UPLOAD_RESULT_SCHEMA },
|
|
317
|
+
},
|
|
318
|
+
STORAGE_ERROR_RESULT_SCHEMA,
|
|
319
|
+
],
|
|
320
|
+
} as const satisfies DataSchema;
|
|
321
|
+
|
|
322
|
+
export const STORAGE_PUBLIC_URL_OPERATION_RESULT_SCHEMA = {
|
|
323
|
+
oneOf: [
|
|
324
|
+
{
|
|
325
|
+
...STORAGE_SUCCESS_SCHEMA,
|
|
326
|
+
required: ['ok', 'data'],
|
|
327
|
+
properties: { ...STORAGE_SUCCESS_SCHEMA.properties, data: STORAGE_PUBLIC_URL_RESULT_SCHEMA },
|
|
328
|
+
},
|
|
329
|
+
STORAGE_ERROR_RESULT_SCHEMA,
|
|
330
|
+
],
|
|
331
|
+
} as const satisfies DataSchema;
|
|
332
|
+
|
|
333
|
+
export const STORAGE_LIST_OPERATION_RESULT_SCHEMA = {
|
|
334
|
+
oneOf: [
|
|
335
|
+
{
|
|
336
|
+
...STORAGE_SUCCESS_SCHEMA,
|
|
337
|
+
required: ['ok', 'data'],
|
|
338
|
+
properties: { ...STORAGE_SUCCESS_SCHEMA.properties, data: STORAGE_LIST_RESULT_SCHEMA },
|
|
339
|
+
},
|
|
340
|
+
STORAGE_ERROR_RESULT_SCHEMA,
|
|
341
|
+
],
|
|
342
|
+
} as const satisfies DataSchema;
|
|
343
|
+
|
|
344
|
+
export const STORAGE_RESOLVE_OPERATION_RESULT_SCHEMA = {
|
|
345
|
+
oneOf: [
|
|
346
|
+
{
|
|
347
|
+
...STORAGE_SUCCESS_SCHEMA,
|
|
348
|
+
required: ['ok', 'data'],
|
|
349
|
+
properties: { ...STORAGE_SUCCESS_SCHEMA.properties, data: STORAGE_RESOLVE_RESULT_SCHEMA },
|
|
350
|
+
},
|
|
351
|
+
STORAGE_ERROR_RESULT_SCHEMA,
|
|
352
|
+
],
|
|
353
|
+
} as const satisfies DataSchema;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import type { StructureDescriptorDocument } from '@ankhorage/contracts/structure';
|
|
3
3
|
|
|
4
4
|
export const STRUCTURE_DESCRIPTOR_COMPILER_VERSION = '6.0.3';
|
|
5
|
-
export const STRUCTURE_DESCRIPTOR_FINGERPRINT = 'sha256:
|
|
5
|
+
export const STRUCTURE_DESCRIPTOR_FINGERPRINT = 'sha256:e6117f029e0a0fde13ed1d08fe1a39d7e06a9f83a0d32198865446501875e27d';
|
|
6
6
|
|
|
7
7
|
export const STRUCTURE_DESCRIPTOR = {
|
|
8
8
|
"protocolVersion": 1,
|
|
9
9
|
"packageName": "@ankhorage/contracts",
|
|
10
|
-
"packageVersion": "25.
|
|
10
|
+
"packageVersion": "25.2.0",
|
|
11
11
|
"roots": {
|
|
12
12
|
"auth-flow": "AuthFlowConfig",
|
|
13
13
|
"auth-profile": "AuthProfileSpec",
|