@covia/covia-sdk 1.0.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/LICENSE.md +21 -0
- package/README.md +99 -0
- package/dist/index.d.mts +343 -0
- package/dist/index.d.ts +343 -0
- package/dist/index.js +481 -0
- package/dist/index.mjs +463 -0
- package/package.json +63 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
declare class Job {
|
|
2
|
+
id: string;
|
|
3
|
+
venue: VenueInterface;
|
|
4
|
+
metadata: JobMetadata;
|
|
5
|
+
constructor(id: string, venue: VenueInterface, metadata: JobMetadata);
|
|
6
|
+
/**
|
|
7
|
+
* Cancels the execution of the job
|
|
8
|
+
* @returns {Promise<number>}
|
|
9
|
+
*/
|
|
10
|
+
cancelJob(): Promise<number>;
|
|
11
|
+
/**
|
|
12
|
+
* Delete the job
|
|
13
|
+
* @returns {Promise<number>}
|
|
14
|
+
*/
|
|
15
|
+
deleteJob(): Promise<number>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare abstract class Asset {
|
|
19
|
+
id: AssetID;
|
|
20
|
+
venue: VenueInterface;
|
|
21
|
+
metadata: AssetMetadata;
|
|
22
|
+
status?: RunStatus;
|
|
23
|
+
error?: string;
|
|
24
|
+
constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
|
|
25
|
+
/**
|
|
26
|
+
* Get asset metadata
|
|
27
|
+
* @returns {Promise<AssetMetadata>}
|
|
28
|
+
*/
|
|
29
|
+
getMetadata(): Promise<AssetMetadata>;
|
|
30
|
+
/**
|
|
31
|
+
* Read stream from asset
|
|
32
|
+
* @param reader - ReadableStreamDefaultReader
|
|
33
|
+
*/
|
|
34
|
+
readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Upload content to asset
|
|
37
|
+
* @param content - Content to upload
|
|
38
|
+
* @returns {Promise<ReadableStream<Uint8Array> | null>}
|
|
39
|
+
*/
|
|
40
|
+
uploadContent(content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Get asset content
|
|
43
|
+
* @returns {Promise<ReadableStream<Uint8Array> | null>}
|
|
44
|
+
*/
|
|
45
|
+
getContent(): Promise<ReadableStream<Uint8Array> | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the URL for downloading asset content
|
|
48
|
+
* @returns {string} The URL for downloading the asset content
|
|
49
|
+
*/
|
|
50
|
+
getContentURL(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Execute the operation
|
|
53
|
+
* @param input - Operation input parameters
|
|
54
|
+
* @returns {Promise<any>}
|
|
55
|
+
*/
|
|
56
|
+
run(input: any): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Execute the operation
|
|
59
|
+
* @param input - Operation input parameters
|
|
60
|
+
* @returns {Promise<any>}
|
|
61
|
+
*/
|
|
62
|
+
invoke(input: any): Promise<Job>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface Credentials {
|
|
66
|
+
venueId: string;
|
|
67
|
+
apiKey: string;
|
|
68
|
+
userId: string;
|
|
69
|
+
}
|
|
70
|
+
declare class CredentialsHTTP implements Credentials {
|
|
71
|
+
venueId: string;
|
|
72
|
+
apiKey: string;
|
|
73
|
+
userId: string;
|
|
74
|
+
constructor(venueId: string, apiKey: string, userId: string);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
declare class Venue implements VenueInterface {
|
|
78
|
+
baseUrl: string;
|
|
79
|
+
venueId: string;
|
|
80
|
+
credentials: Credentials;
|
|
81
|
+
metadata: VenueData;
|
|
82
|
+
constructor(options?: VenueOptions);
|
|
83
|
+
/**
|
|
84
|
+
* Static method to connect to a venue
|
|
85
|
+
* @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
|
|
86
|
+
* @param credentials - Optional credentials for venue authentication
|
|
87
|
+
* @returns {Promise<Venue>} A new Venue instance configured appropriately
|
|
88
|
+
*/
|
|
89
|
+
static connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
|
|
90
|
+
/**
|
|
91
|
+
* Create a new asset
|
|
92
|
+
* @param assetData - Asset configuration
|
|
93
|
+
* @returns {Promise<Asset>}
|
|
94
|
+
*/
|
|
95
|
+
createAsset(assetData: any): Promise<Asset>;
|
|
96
|
+
/**
|
|
97
|
+
* Read stream from asset
|
|
98
|
+
* @param reader - ReadableStreamDefaultReader
|
|
99
|
+
*/
|
|
100
|
+
readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Get asset by ID
|
|
103
|
+
* @param assetId - Asset identifier
|
|
104
|
+
* @returns {Promise<Asset>} Returns either an Operation or DataAsset based on the asset's metadata
|
|
105
|
+
*/
|
|
106
|
+
getAsset(assetId: AssetID): Promise<Asset>;
|
|
107
|
+
/**
|
|
108
|
+
* Get all assets
|
|
109
|
+
* @returns {Promise<Asset[]>}
|
|
110
|
+
*/
|
|
111
|
+
getAssets(): Promise<Asset[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Get all jobs
|
|
114
|
+
* @returns {Promise<string[]>}
|
|
115
|
+
*/
|
|
116
|
+
getJobs(): Promise<string[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Get job by ID
|
|
119
|
+
* @param jobId - Job identifier
|
|
120
|
+
* @returns {Promise<Job>}
|
|
121
|
+
*/
|
|
122
|
+
getJob(jobId: string): Promise<Job>;
|
|
123
|
+
/**
|
|
124
|
+
* Cancel job by ID
|
|
125
|
+
* @param jobId - Job identifier
|
|
126
|
+
* @returns {Promise<number>}
|
|
127
|
+
*/
|
|
128
|
+
cancelJob(jobId: string): Promise<number>;
|
|
129
|
+
/**
|
|
130
|
+
* Delete job by ID
|
|
131
|
+
* @param jobId - Job identifier
|
|
132
|
+
* @returns {Promise<number>}
|
|
133
|
+
*/
|
|
134
|
+
deleteJob(jobId: string): Promise<number>;
|
|
135
|
+
/**
|
|
136
|
+
* Get the DID (Decentralized Identifier) for this venue
|
|
137
|
+
* @returns {string} DID in the format did:web:domain
|
|
138
|
+
*/
|
|
139
|
+
getStats(): Promise<StatusData>;
|
|
140
|
+
/**
|
|
141
|
+
* Get asset metadata
|
|
142
|
+
* @returns {Promise<AssetMetadata>}
|
|
143
|
+
*/
|
|
144
|
+
getMetadata(assetId: string): Promise<AssetMetadata>;
|
|
145
|
+
/**
|
|
146
|
+
* Upload content to asset
|
|
147
|
+
* @param content - Content to upload
|
|
148
|
+
* @returns {Promise<ReadableStream<Uint8Array> | null>}
|
|
149
|
+
*/
|
|
150
|
+
uploadContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
|
|
151
|
+
/**
|
|
152
|
+
* Get asset content
|
|
153
|
+
* @returns {Promise<ReadableStream<Uint8Array> | null>}
|
|
154
|
+
*/
|
|
155
|
+
getContent(assetId: string): Promise<ReadableStream<Uint8Array> | null>;
|
|
156
|
+
/**
|
|
157
|
+
* Execute the operation
|
|
158
|
+
* @param input - Operation input parameters
|
|
159
|
+
* @returns {Promise<any>}
|
|
160
|
+
*/
|
|
161
|
+
run(assetId: string, input: any): Promise<any>;
|
|
162
|
+
/**
|
|
163
|
+
* Execute the operation
|
|
164
|
+
* @param input - Operation input parameters
|
|
165
|
+
* @returns {Promise<Job>}
|
|
166
|
+
*/
|
|
167
|
+
invoke(assetId: string, input: any): Promise<Job>;
|
|
168
|
+
private setCredentialsInHeader;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
interface VenueOptions {
|
|
172
|
+
baseUrl?: string;
|
|
173
|
+
venueId?: string;
|
|
174
|
+
name?: string;
|
|
175
|
+
description?: string;
|
|
176
|
+
credentials?: Credentials;
|
|
177
|
+
}
|
|
178
|
+
interface VenueConstructor {
|
|
179
|
+
new (): VenueInterface;
|
|
180
|
+
connect(venueId: string | Venue, credentials?: CredentialsHTTP): Promise<Venue>;
|
|
181
|
+
}
|
|
182
|
+
interface VenueInterface {
|
|
183
|
+
baseUrl: string;
|
|
184
|
+
venueId: string;
|
|
185
|
+
metadata: VenueData;
|
|
186
|
+
cancelJob(jobId: string): Promise<number>;
|
|
187
|
+
deleteJob(jobId: string): Promise<number>;
|
|
188
|
+
getStats(): Promise<StatusData>;
|
|
189
|
+
getJob(jobId: string): Promise<Job>;
|
|
190
|
+
getJobs(): Promise<string[]>;
|
|
191
|
+
getAsset(assetId: AssetID): Promise<Asset>;
|
|
192
|
+
createAsset(assetData: any, userEmail: string): Promise<Asset>;
|
|
193
|
+
getAssets(): Promise<Asset[]>;
|
|
194
|
+
getMetadata(assetId: string): Promise<AssetMetadata>;
|
|
195
|
+
readStream(reader: ReadableStreamDefaultReader<Uint8Array>): Promise<void>;
|
|
196
|
+
uploadContent(assetId: string, content: BodyInit): Promise<ReadableStream<Uint8Array> | null>;
|
|
197
|
+
getContent(assetId: string): Promise<ReadableStream<Uint8Array> | null>;
|
|
198
|
+
run(assetId: string, input: any): Promise<any>;
|
|
199
|
+
invoke(assetId: string, input: any): Promise<Job>;
|
|
200
|
+
}
|
|
201
|
+
type AssetID = string;
|
|
202
|
+
interface AssetMetadata {
|
|
203
|
+
[key: string]: any;
|
|
204
|
+
name?: string;
|
|
205
|
+
description?: string;
|
|
206
|
+
type?: string;
|
|
207
|
+
created?: string;
|
|
208
|
+
updated?: string;
|
|
209
|
+
operation?: OperationDetails;
|
|
210
|
+
content?: ContentDetails;
|
|
211
|
+
input?: any;
|
|
212
|
+
output?: any;
|
|
213
|
+
}
|
|
214
|
+
interface VenueData {
|
|
215
|
+
description?: string;
|
|
216
|
+
name?: string;
|
|
217
|
+
}
|
|
218
|
+
/** Type for metadata.operation */
|
|
219
|
+
interface OperationDetails {
|
|
220
|
+
[key: string]: any;
|
|
221
|
+
adapter?: string;
|
|
222
|
+
input?: any;
|
|
223
|
+
output?: any;
|
|
224
|
+
steps?: any[];
|
|
225
|
+
result?: any;
|
|
226
|
+
}
|
|
227
|
+
/** Type for metadata.content */
|
|
228
|
+
interface ContentDetails {
|
|
229
|
+
[key: string]: any;
|
|
230
|
+
}
|
|
231
|
+
interface OperationPayload {
|
|
232
|
+
[key: string]: any;
|
|
233
|
+
}
|
|
234
|
+
interface JobMetadata {
|
|
235
|
+
name?: string;
|
|
236
|
+
status?: RunStatus;
|
|
237
|
+
created?: string;
|
|
238
|
+
updated?: string;
|
|
239
|
+
input?: any;
|
|
240
|
+
output?: any;
|
|
241
|
+
op?: string;
|
|
242
|
+
[key: string]: any;
|
|
243
|
+
}
|
|
244
|
+
interface InvokePayload {
|
|
245
|
+
assetId: AssetID;
|
|
246
|
+
payload: OperationPayload;
|
|
247
|
+
}
|
|
248
|
+
declare enum RunStatus {
|
|
249
|
+
COMPLETE = "COMPLETE",
|
|
250
|
+
FAILED = "FAILED",
|
|
251
|
+
PENDING = "PENDING",
|
|
252
|
+
STARTED = "STARTED",
|
|
253
|
+
CANCELLED = "CANCELLED",
|
|
254
|
+
TIMEOUT = "TIMEOUT",
|
|
255
|
+
REJECTED = "REJECTED",
|
|
256
|
+
INPUT_REQUIRED = "INPUT_REQUIRED",
|
|
257
|
+
AUTH_REQUIRED = "AUTH_REQUIRED",
|
|
258
|
+
PAUSED = "PAUSED"
|
|
259
|
+
}
|
|
260
|
+
interface StatusData {
|
|
261
|
+
url?: string;
|
|
262
|
+
ts?: string;
|
|
263
|
+
status?: string;
|
|
264
|
+
did?: string;
|
|
265
|
+
name?: string;
|
|
266
|
+
stats?: StatsData;
|
|
267
|
+
}
|
|
268
|
+
interface StatsData {
|
|
269
|
+
assets?: number;
|
|
270
|
+
users?: number;
|
|
271
|
+
ops?: number;
|
|
272
|
+
jobs?: number;
|
|
273
|
+
}
|
|
274
|
+
declare class CoviaError extends Error {
|
|
275
|
+
code: number | null;
|
|
276
|
+
constructor(message: string, code?: number | null);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Utility function to handle API calls with consistent error handling
|
|
281
|
+
* @param url - The URL to fetch
|
|
282
|
+
* @param options - Fetch options
|
|
283
|
+
* @returns {Promise<T>} The response data
|
|
284
|
+
*/
|
|
285
|
+
declare function fetchWithError<T>(url: string, options?: RequestInit): Promise<T>;
|
|
286
|
+
/**
|
|
287
|
+
* Utility function to handle fetch requests that return streams
|
|
288
|
+
* @param url - The URL to fetch
|
|
289
|
+
* @param options - Fetch options
|
|
290
|
+
* @returns {Promise<Response>} The fetch response
|
|
291
|
+
*/
|
|
292
|
+
declare function fetchStreamWithError(url: string, options?: RequestInit): Promise<Response>;
|
|
293
|
+
/**
|
|
294
|
+
* Utility function to check if job is considered completed
|
|
295
|
+
* @param jobStatus - The status of the job
|
|
296
|
+
* @returns {boolean} - Returns false if job is not completed , else returns true
|
|
297
|
+
*/
|
|
298
|
+
declare function isJobComplete(jobStatus: RunStatus): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Utility function to check if job is considered paused
|
|
301
|
+
* @param jobStatus - The status of the job
|
|
302
|
+
* @returns {boolean} - Returns false if job is not paused , else returns true
|
|
303
|
+
*/
|
|
304
|
+
declare function isJobPaused(jobStatus: RunStatus): boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Utility function to check if job is considered finished
|
|
307
|
+
* @param jobStatus - The status of the job
|
|
308
|
+
* @returns {boolean} - Returns false if job is not finished , else returns true
|
|
309
|
+
*/
|
|
310
|
+
declare function isJobFinished(jobStatus: RunStatus): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Utility function to parse the asset hex from the compelte assetId
|
|
313
|
+
* @param assetId - The complete assetId
|
|
314
|
+
* @returns {string} - Returns the parsed hexIdof the asset
|
|
315
|
+
*/
|
|
316
|
+
declare function getParsedAssetId(assetId: string): string;
|
|
317
|
+
/**
|
|
318
|
+
* Utility function to return complete assetId from hex and path
|
|
319
|
+
* @param assetHex - The asset hex
|
|
320
|
+
* @param assetPath - The asset path
|
|
321
|
+
* @returns {string} - Returns the complete assetId
|
|
322
|
+
*/
|
|
323
|
+
declare function getAssetIdFromPath(assetHex: string, assetPath: string): string;
|
|
324
|
+
declare function getAssetIdFromVenueId(assetHex: string, venueId: string): string;
|
|
325
|
+
|
|
326
|
+
declare class Grid {
|
|
327
|
+
/**
|
|
328
|
+
* Static method to connect to a venue
|
|
329
|
+
* @param venueId - Can be a HTTP base URL, DNS name, or existing Venue instance
|
|
330
|
+
* @returns {Promise<Venue>} A new Venue instance configured appropriately
|
|
331
|
+
*/
|
|
332
|
+
static connect(venueId: string, credentials?: CredentialsHTTP): Promise<Venue>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
declare class Operation extends Asset {
|
|
336
|
+
constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class DataAsset extends Asset {
|
|
340
|
+
constructor(id: AssetID, venue: VenueInterface, metadata?: AssetMetadata);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { Asset, type AssetID, type AssetMetadata, type ContentDetails, CoviaError, type Credentials, CredentialsHTTP, DataAsset, Grid, type InvokePayload, Job, type JobMetadata, Operation, type OperationDetails, type OperationPayload, RunStatus, type StatsData, type StatusData, Venue, type VenueConstructor, type VenueData, type VenueInterface, type VenueOptions, fetchStreamWithError, fetchWithError, getAssetIdFromPath, getAssetIdFromVenueId, getParsedAssetId, isJobComplete, isJobFinished, isJobPaused };
|