@jsm-mit/rabbit-motoko-package 0.1.9 → 0.1.11
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/README.md +118 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/rabbit-motoko-actor.d.ts +2 -1
- package/dist/rabbit-motoko-actor.d.ts.map +1 -1
- package/dist/rabbit-motoko-actor.js +2 -3
- package/package.json +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Rabbit Motoko Package
|
|
2
|
+
|
|
3
|
+
A TypeScript library for interacting with the Rabbit Motoko actor on the Internet Computer (IC) platform. Simplifies interaction with the Rabbit task queuing system through a convenient wrapper around @dfinity/agent.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jsm-mit/rabbit-motoko-package
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialization
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { RabbitMotokoActor } from '@jsm-mit/rabbit-motoko-package';
|
|
17
|
+
|
|
18
|
+
const canisterId = 'your-canister-id';
|
|
19
|
+
const rabbitActor = new RabbitMotokoActor(canisterId);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Adding a task
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const taskId = await rabbitActor.addTask({
|
|
26
|
+
channel: 'my-channel',
|
|
27
|
+
taskType: 'process-data',
|
|
28
|
+
payload: 'task payload data'
|
|
29
|
+
});
|
|
30
|
+
console.log('Task added with ID:', taskId);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Getting available tasks
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
const availableTaskIds = await rabbitActor.getAvailableTaskIds('my-channel');
|
|
37
|
+
console.log('Available tasks:', availableTaskIds);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Claiming a task
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const task = await rabbitActor.claimTask({
|
|
44
|
+
taskId: 123n,
|
|
45
|
+
workerId: 'worker-1'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (task.length > 0) {
|
|
49
|
+
console.log('Task claimed:', task[0]);
|
|
50
|
+
} else {
|
|
51
|
+
console.log('Task not available');
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Completing a task
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const success = await rabbitActor.completeTask({
|
|
59
|
+
taskId: 123n,
|
|
60
|
+
result: 'task completed successfully'
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (success) {
|
|
64
|
+
console.log('Task completed successfully');
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Getting all tasks
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
const allTasks = await rabbitActor.getTasks();
|
|
72
|
+
console.log('All tasks:', allTasks);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Agent synchronization
|
|
76
|
+
|
|
77
|
+
In case of time/certificate issues:
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
await rabbitActor.sync();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## API
|
|
84
|
+
|
|
85
|
+
### `RabbitMotokoActor` Class
|
|
86
|
+
|
|
87
|
+
#### Constructor
|
|
88
|
+
- `new RabbitMotokoActor(canisterId: string)` - Creates a new instance with the provided canister ID
|
|
89
|
+
|
|
90
|
+
#### Public Methods
|
|
91
|
+
|
|
92
|
+
- `sync(): Promise<void>` - Synchronizes the agent time with the IC network
|
|
93
|
+
- `addTask(args: AddTaskArgs): Promise<bigint>` - Adds a new task to the queue
|
|
94
|
+
- `claimTask(args: ClaimTaskArgs): Promise<[] | [Task]>` - Claims a task for a worker
|
|
95
|
+
- `completeTask(args: CompleteTaskArgs): Promise<boolean>` - Completes a claimed task
|
|
96
|
+
- `getAvailableTaskIds(channel: string): Promise<bigint[]>` - Gets IDs of available tasks in a channel
|
|
97
|
+
- `getTasks(): Promise<Task[]>` - Gets a list of all tasks
|
|
98
|
+
|
|
99
|
+
## Types
|
|
100
|
+
|
|
101
|
+
The library uses types generated from the Rabbit Motoko canister:
|
|
102
|
+
- `AddTaskArgs` - Arguments for adding a task
|
|
103
|
+
- `ClaimTaskArgs` - Arguments for claiming a task
|
|
104
|
+
- `CompleteTaskArgs` - Arguments for completing a task
|
|
105
|
+
- `Task` - Task structure
|
|
106
|
+
|
|
107
|
+
## Requirements
|
|
108
|
+
|
|
109
|
+
- Node.js 16+
|
|
110
|
+
- TypeScript 4.5+
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
ISC
|
|
115
|
+
|
|
116
|
+
## Author
|
|
117
|
+
|
|
118
|
+
@jsm-mit
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAAoE,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Identity } from "@icp-sdk/core/agent";
|
|
1
2
|
import { AddTaskArgs, ClaimTaskArgs, CompleteTaskArgs, Task } from "../declarations/rabbit-motoko-backend/rabbit-motoko-backend.did.js";
|
|
2
3
|
export declare class RabbitMotokoActor {
|
|
3
4
|
private readonly canisterId;
|
|
4
5
|
private readonly host;
|
|
5
6
|
private actor;
|
|
6
7
|
private agent;
|
|
7
|
-
constructor(canisterId: string);
|
|
8
|
+
constructor(canisterId: string, identity?: Identity);
|
|
8
9
|
private initActor;
|
|
9
10
|
private setupAgent;
|
|
10
11
|
private checkError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAAoE,CAAC;AAGlJ,qBAAa,iBAAiB;IAKd,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJvC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA6B;IAClD,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,KAAK,CAAY;gBAEI,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,QAAQ;IAcpE,OAAO,CAAC,SAAS;YAOH,UAAU;YAWV,UAAU;IAQX,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IASlC;;OAEG;IACU,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAUxD;;OAEG;IACU,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAUjE;;OAEG;IACU,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAUnE;;OAEG;IACU,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpE;;OAEG;IACU,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;CAS3C"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Actor, HttpAgent } from "@icp-sdk/core/agent";
|
|
2
2
|
import { idlFactory } from "../declarations/rabbit-motoko-backend/index.js";
|
|
3
3
|
export class RabbitMotokoActor {
|
|
4
|
-
constructor(canisterId) {
|
|
4
|
+
constructor(canisterId, identity) {
|
|
5
5
|
this.canisterId = canisterId;
|
|
6
6
|
this.host = "https://icp0.io";
|
|
7
7
|
// 1. Tworzymy agenta
|
|
8
8
|
this.agent = new HttpAgent({
|
|
9
9
|
host: this.host,
|
|
10
|
-
|
|
11
|
-
// ale syncTime() jest skuteczniejszym rozwiązaniem.
|
|
10
|
+
identity,
|
|
12
11
|
});
|
|
13
12
|
// 2. Inicjalizujemy aktora
|
|
14
13
|
this.initActor();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsm-mit/rabbit-motoko-package",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Wrapper TypeScript package for Rabbit Motoko IC actor using @dfinity/agent.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"build": "tsc --build",
|
|
22
22
|
"clean": "rm -rf dist",
|
|
23
23
|
"prepare": "npm run build",
|
|
24
|
+
"publish": "npm publish --access public",
|
|
24
25
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|