colonies-ts 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/LICENSE +21 -0
- package/README.md +341 -0
- package/dist/index.d.mts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +976 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +944 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate a new random private key
|
|
3
|
+
* @returns Hex-encoded private key (64 characters)
|
|
4
|
+
*/
|
|
5
|
+
declare function generatePrivateKey(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Derive the public ID from a private key
|
|
8
|
+
* Uses SHA3-256 hash of "04" + hex(publicKey)
|
|
9
|
+
* @param privateKey - Hex-encoded private key
|
|
10
|
+
* @returns Hex-encoded ID (64 characters)
|
|
11
|
+
*/
|
|
12
|
+
declare function deriveId(privateKey: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Sign a message with a private key
|
|
15
|
+
* @param message - Message to sign
|
|
16
|
+
* @param privateKey - Hex-encoded private key
|
|
17
|
+
* @returns Hex-encoded signature (130 characters: r + s + v)
|
|
18
|
+
*/
|
|
19
|
+
declare function sign(message: string, privateKey: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Crypto utility class for convenience
|
|
22
|
+
*/
|
|
23
|
+
declare class Crypto {
|
|
24
|
+
generatePrivateKey(): string;
|
|
25
|
+
id(privateKey: string): string;
|
|
26
|
+
sign(message: string, privateKey: string): string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* ColonyOS Client
|
|
31
|
+
* Ported from colonyspace/aila/src/lib/api/colony.ts
|
|
32
|
+
*/
|
|
33
|
+
interface ColoniesClientConfig {
|
|
34
|
+
host: string;
|
|
35
|
+
port: number;
|
|
36
|
+
tls?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RPCMessage {
|
|
39
|
+
payloadtype: string;
|
|
40
|
+
payload: string;
|
|
41
|
+
signature: string;
|
|
42
|
+
}
|
|
43
|
+
interface FunctionSpec {
|
|
44
|
+
nodename?: string;
|
|
45
|
+
funcname: string;
|
|
46
|
+
args?: any[];
|
|
47
|
+
kwargs?: Record<string, any>;
|
|
48
|
+
priority?: number;
|
|
49
|
+
maxwaittime?: number;
|
|
50
|
+
maxexectime?: number;
|
|
51
|
+
maxretries?: number;
|
|
52
|
+
conditions?: {
|
|
53
|
+
colonyname?: string;
|
|
54
|
+
executornames?: string[];
|
|
55
|
+
executortype?: string;
|
|
56
|
+
dependencies?: string[];
|
|
57
|
+
nodes?: number;
|
|
58
|
+
cpu?: string;
|
|
59
|
+
processes?: number;
|
|
60
|
+
processespernode?: number;
|
|
61
|
+
mem?: string;
|
|
62
|
+
storage?: string;
|
|
63
|
+
gpu?: {
|
|
64
|
+
name?: string;
|
|
65
|
+
mem?: string;
|
|
66
|
+
count?: number;
|
|
67
|
+
nodecount?: number;
|
|
68
|
+
};
|
|
69
|
+
walltime?: number;
|
|
70
|
+
};
|
|
71
|
+
label?: string;
|
|
72
|
+
fs?: any;
|
|
73
|
+
env?: Record<string, string>;
|
|
74
|
+
channels?: string[];
|
|
75
|
+
}
|
|
76
|
+
declare enum ProcessState {
|
|
77
|
+
WAITING = 0,
|
|
78
|
+
RUNNING = 1,
|
|
79
|
+
SUCCESS = 2,
|
|
80
|
+
FAILED = 3
|
|
81
|
+
}
|
|
82
|
+
declare class ColoniesClient {
|
|
83
|
+
private host;
|
|
84
|
+
private port;
|
|
85
|
+
private tls;
|
|
86
|
+
private crypto;
|
|
87
|
+
private privateKey;
|
|
88
|
+
constructor(config: ColoniesClientConfig);
|
|
89
|
+
setPrivateKey(privateKey: string): void;
|
|
90
|
+
private getBaseUrl;
|
|
91
|
+
private createRPCMsg;
|
|
92
|
+
private sendRPC;
|
|
93
|
+
getColonies(): Promise<any>;
|
|
94
|
+
getStatistics(): Promise<any>;
|
|
95
|
+
/**
|
|
96
|
+
* Add a new colony (requires server private key)
|
|
97
|
+
* @param colony - Colony object with colonyid and name
|
|
98
|
+
*/
|
|
99
|
+
addColony(colony: {
|
|
100
|
+
colonyid: string;
|
|
101
|
+
name: string;
|
|
102
|
+
}): Promise<any>;
|
|
103
|
+
/**
|
|
104
|
+
* Remove a colony (requires server private key)
|
|
105
|
+
* @param colonyName - Name of the colony to remove
|
|
106
|
+
*/
|
|
107
|
+
removeColony(colonyName: string): Promise<any>;
|
|
108
|
+
getExecutors(colonyName: string): Promise<any>;
|
|
109
|
+
getExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
110
|
+
addExecutor(executor: {
|
|
111
|
+
executorid: string;
|
|
112
|
+
executortype: string;
|
|
113
|
+
executorname: string;
|
|
114
|
+
colonyname: string;
|
|
115
|
+
}): Promise<any>;
|
|
116
|
+
approveExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
117
|
+
removeExecutor(colonyName: string, executorName: string): Promise<any>;
|
|
118
|
+
submitFunctionSpec(spec: FunctionSpec): Promise<any>;
|
|
119
|
+
getProcess(processId: string): Promise<any>;
|
|
120
|
+
getProcesses(colonyName: string, count: number, state: ProcessState): Promise<any>;
|
|
121
|
+
removeProcess(processId: string): Promise<any>;
|
|
122
|
+
removeAllProcesses(colonyName: string, state?: number): Promise<any>;
|
|
123
|
+
assign(colonyName: string, timeout: number, executorPrvKey: string): Promise<any>;
|
|
124
|
+
closeProcess(processId: string, output: string[]): Promise<any>;
|
|
125
|
+
failProcess(processId: string, errors: string[]): Promise<any>;
|
|
126
|
+
submitWorkflowSpec(workflowSpec: {
|
|
127
|
+
colonyname: string;
|
|
128
|
+
functionspecs: FunctionSpec[];
|
|
129
|
+
}): Promise<any>;
|
|
130
|
+
getProcessGraph(processGraphId: string): Promise<any>;
|
|
131
|
+
getProcessGraphs(colonyName: string, count: number, state?: ProcessState): Promise<any>;
|
|
132
|
+
removeProcessGraph(processGraphId: string): Promise<any>;
|
|
133
|
+
removeAllProcessGraphs(colonyName: string, state?: ProcessState): Promise<any>;
|
|
134
|
+
addLog(processId: string, message: string, executorPrvKey: string): Promise<any>;
|
|
135
|
+
getLogs(colonyName: string, processId: string, executorName: string, count?: number, since?: number): Promise<any>;
|
|
136
|
+
getFunctions(executorName: string, colonyName: string): Promise<any>;
|
|
137
|
+
getCrons(colonyName: string, count?: number): Promise<any>;
|
|
138
|
+
getCron(cronId: string): Promise<any>;
|
|
139
|
+
addCron(cronSpec: any): Promise<any>;
|
|
140
|
+
removeCron(cronId: string): Promise<any>;
|
|
141
|
+
getGenerators(colonyName: string, count?: number): Promise<any>;
|
|
142
|
+
getGenerator(generatorId: string): Promise<any>;
|
|
143
|
+
addGenerator(generatorSpec: any): Promise<any>;
|
|
144
|
+
getUsers(colonyName: string): Promise<any>;
|
|
145
|
+
addUser(user: {
|
|
146
|
+
colonyname: string;
|
|
147
|
+
userid: string;
|
|
148
|
+
name: string;
|
|
149
|
+
email: string;
|
|
150
|
+
phone: string;
|
|
151
|
+
}): Promise<any>;
|
|
152
|
+
removeUser(colonyName: string, name: string): Promise<any>;
|
|
153
|
+
getFileLabels(colonyName: string, name?: string, exact?: boolean): Promise<any>;
|
|
154
|
+
getFiles(colonyName: string, label: string): Promise<any>;
|
|
155
|
+
addAttribute(attribute: {
|
|
156
|
+
targetid: string;
|
|
157
|
+
targetcolonyname: string;
|
|
158
|
+
targetprocessgraphid: string;
|
|
159
|
+
attributetype: number;
|
|
160
|
+
key: string;
|
|
161
|
+
value: string;
|
|
162
|
+
}): Promise<any>;
|
|
163
|
+
getAttribute(attributeId: string): Promise<any>;
|
|
164
|
+
/**
|
|
165
|
+
* Append a message to a process channel
|
|
166
|
+
* @param processId - ID of the process
|
|
167
|
+
* @param channelName - Name of the channel
|
|
168
|
+
* @param sequence - Client-assigned sequence number
|
|
169
|
+
* @param inReplyTo - Sequence number this message is replying to (0 if not a reply)
|
|
170
|
+
* @param payload - Message content (string or Uint8Array)
|
|
171
|
+
*/
|
|
172
|
+
channelAppend(processId: string, channelName: string, sequence: number, inReplyTo: number, payload: string | Uint8Array): Promise<any>;
|
|
173
|
+
/**
|
|
174
|
+
* Read messages from a process channel
|
|
175
|
+
* @param processId - ID of the process
|
|
176
|
+
* @param channelName - Name of the channel
|
|
177
|
+
* @param afterSeq - Read messages after this sequence number (use 0 for all)
|
|
178
|
+
* @param limit - Maximum number of messages to return (0 for no limit)
|
|
179
|
+
*/
|
|
180
|
+
channelRead(processId: string, channelName: string, afterSeq: number, limit: number): Promise<any[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Subscribe to a channel using WebSocket for real-time updates
|
|
183
|
+
* @param processId - ID of the process
|
|
184
|
+
* @param channelName - Name of the channel
|
|
185
|
+
* @param afterSeq - Start reading after this sequence number
|
|
186
|
+
* @param timeout - Timeout in seconds for the subscription
|
|
187
|
+
* @param onMessage - Callback for new messages
|
|
188
|
+
* @param onError - Callback for errors
|
|
189
|
+
* @param onClose - Callback when connection closes
|
|
190
|
+
* @returns WebSocket instance for cleanup
|
|
191
|
+
*/
|
|
192
|
+
subscribeChannel(processId: string, channelName: string, afterSeq: number, timeout: number, onMessage: (entries: any[]) => void, onError: (error: Error) => void, onClose: () => void): WebSocket;
|
|
193
|
+
/**
|
|
194
|
+
* Add a blueprint definition
|
|
195
|
+
* @param definition - Blueprint definition object
|
|
196
|
+
*/
|
|
197
|
+
addBlueprintDefinition(definition: any): Promise<any>;
|
|
198
|
+
/**
|
|
199
|
+
* Get a blueprint definition by name
|
|
200
|
+
* @param colonyName - Name of the colony
|
|
201
|
+
* @param name - Name of the blueprint definition
|
|
202
|
+
*/
|
|
203
|
+
getBlueprintDefinition(colonyName: string, name: string): Promise<any>;
|
|
204
|
+
/**
|
|
205
|
+
* Get all blueprint definitions in a colony
|
|
206
|
+
* @param colonyName - Name of the colony
|
|
207
|
+
*/
|
|
208
|
+
getBlueprintDefinitions(colonyName: string): Promise<any[]>;
|
|
209
|
+
/**
|
|
210
|
+
* Remove a blueprint definition
|
|
211
|
+
* @param colonyName - Name of the colony (namespace)
|
|
212
|
+
* @param name - Name of the blueprint definition to remove
|
|
213
|
+
*/
|
|
214
|
+
removeBlueprintDefinition(colonyName: string, name: string): Promise<void>;
|
|
215
|
+
/**
|
|
216
|
+
* Add a blueprint instance
|
|
217
|
+
* @param blueprint - Blueprint object
|
|
218
|
+
*/
|
|
219
|
+
addBlueprint(blueprint: any): Promise<any>;
|
|
220
|
+
/**
|
|
221
|
+
* Get a blueprint by name
|
|
222
|
+
* @param colonyName - Name of the colony (namespace)
|
|
223
|
+
* @param name - Name of the blueprint
|
|
224
|
+
*/
|
|
225
|
+
getBlueprint(colonyName: string, name: string): Promise<any>;
|
|
226
|
+
/**
|
|
227
|
+
* Get blueprints in a colony, optionally filtered by kind and location
|
|
228
|
+
* @param colonyName - Name of the colony (namespace)
|
|
229
|
+
* @param kind - Optional kind filter
|
|
230
|
+
* @param location - Optional location filter
|
|
231
|
+
*/
|
|
232
|
+
getBlueprints(colonyName: string, kind?: string, location?: string): Promise<any[]>;
|
|
233
|
+
/**
|
|
234
|
+
* Update an existing blueprint
|
|
235
|
+
* @param blueprint - Updated blueprint object
|
|
236
|
+
* @param forceGeneration - Force generation bump even if spec unchanged
|
|
237
|
+
*/
|
|
238
|
+
updateBlueprint(blueprint: any, forceGeneration?: boolean): Promise<any>;
|
|
239
|
+
/**
|
|
240
|
+
* Remove a blueprint
|
|
241
|
+
* @param colonyName - Name of the colony (namespace)
|
|
242
|
+
* @param name - Name of the blueprint to remove
|
|
243
|
+
*/
|
|
244
|
+
removeBlueprint(colonyName: string, name: string): Promise<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Update blueprint status (current state)
|
|
247
|
+
* @param colonyName - Name of the colony
|
|
248
|
+
* @param name - Name of the blueprint
|
|
249
|
+
* @param status - Status object representing current state
|
|
250
|
+
*/
|
|
251
|
+
updateBlueprintStatus(colonyName: string, name: string, status: any): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Trigger reconciliation for a blueprint
|
|
254
|
+
* @param colonyName - Name of the colony (namespace)
|
|
255
|
+
* @param name - Name of the blueprint
|
|
256
|
+
* @param force - Force reconciliation even if no changes detected
|
|
257
|
+
*/
|
|
258
|
+
reconcileBlueprint(colonyName: string, name: string, force?: boolean): Promise<any>;
|
|
259
|
+
/**
|
|
260
|
+
* Subscribe to process state changes using WebSocket
|
|
261
|
+
* Use this to wait for a process to be assigned (RUNNING state) before subscribing to channels
|
|
262
|
+
* @param colonyName - Name of the colony
|
|
263
|
+
* @param processId - ID of the process to watch
|
|
264
|
+
* @param state - Target state to wait for (0=WAITING, 1=RUNNING, 2=SUCCESS, 3=FAILED)
|
|
265
|
+
* @param timeout - Timeout in seconds for the subscription
|
|
266
|
+
* @param onProcess - Callback when process reaches the target state
|
|
267
|
+
* @param onError - Callback for errors
|
|
268
|
+
* @param onClose - Callback when connection closes
|
|
269
|
+
* @returns WebSocket instance for cleanup
|
|
270
|
+
*/
|
|
271
|
+
subscribeProcess(colonyName: string, processId: string, state: number, timeout: number, onProcess: (process: any) => void, onError: (error: Error) => void, onClose: () => void): WebSocket;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { ColoniesClient, type ColoniesClientConfig, Crypto, type FunctionSpec, ProcessState, type RPCMessage, deriveId, generatePrivateKey, sign };
|