@jsm-mit/rabbit-motoko-package 0.1.21 → 0.1.23

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.
@@ -9,27 +9,27 @@ export declare class RabbitMotokoActor {
9
9
  private initActor;
10
10
  private setupAgent;
11
11
  private checkError;
12
- sync(): Promise<void>;
12
+ syncTimeAsync(throwError: boolean): Promise<void>;
13
13
  /**
14
14
  * Adds a new task to the queue.
15
15
  */
16
- addTask(args: AddTaskArgs): Promise<bigint>;
16
+ addTaskAsync(args: AddTaskArgs, throwError: boolean): Promise<bigint>;
17
17
  /**
18
18
  * Claims a task for a specific worker.
19
19
  */
20
- claimTask(args: ClaimTaskArgs): Promise<[] | [Task]>;
20
+ claimTaskAsync(args: ClaimTaskArgs, throwError: boolean): Promise<[] | [Task]>;
21
21
  /**
22
22
  * Completes a previously claimed task.
23
23
  */
24
- completeTask(args: CompleteTaskArgs): Promise<boolean>;
24
+ completeTaskAsync(args: CompleteTaskArgs, throwError: boolean): Promise<boolean>;
25
25
  /**
26
26
  * Fetches IDs of tasks available in a specific channel.
27
27
  */
28
- getAvailableTaskIds(channel: string): Promise<bigint[]>;
28
+ getAvailableTaskIdsAsync(channel: string, throwError: boolean): Promise<bigint[]>;
29
29
  /**
30
30
  * Returns a list of all tasks.
31
31
  */
32
- getTasks(): Promise<Task[]>;
33
- whoAmI(): Promise<string>;
32
+ getTasksAsync(throwError: boolean): Promise<Task[]>;
33
+ whoAmIAsync(throwError: boolean): Promise<string>;
34
34
  }
35
35
  //# sourceMappingURL=rabbit-motoko-actor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rabbit-motoko-actor.d.ts","sourceRoot":"","sources":["../src/rabbit-motoko-actor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAExE,OAAO,EAAY,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,oEAA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AC,EAAE,oBAAoB;IAehF,OAAO,CAAC,SAAS;YAOH,UAAU;YAWV,UAAU;IAQX,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAa9D;;OAEG;IACU,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBlF;;OAEG;IACU,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAgB3F;;OAEG;IACU,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAgB7F;;OAEG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB9F;;OAEG;IACU,aAAa,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAgBnD,WAAW,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;CAgBjE"}
@@ -7,6 +7,7 @@ export class RabbitMotokoActor {
7
7
  // 1. Tworzymy agenta
8
8
  this.agent = HttpAgent.createSync({
9
9
  host: this.host,
10
+ ingressExpiryInMinutes: 1,
10
11
  identity,
11
12
  });
12
13
  // 2. Inicjalizujemy aktora
@@ -32,86 +33,119 @@ export class RabbitMotokoActor {
32
33
  }
33
34
  async checkError(error) {
34
35
  const errorMsg = error?.toString() || "";
35
- if (errorMsg.includes("certificate") || errorMsg.includes("TrustError")) {
36
+ if (errorMsg.includes("certificate") || errorMsg.includes("TrustError") || errorMsg.includes("ingress_expiry")) {
36
37
  console.warn("⚠️ Wykryto problem z zaufaniem/czasem. Próbuję synchronizacji...");
37
- await this.sync();
38
+ await this.syncTimeAsync(false);
38
39
  }
39
40
  }
40
- async sync() {
41
+ async syncTimeAsync(throwError) {
41
42
  try {
42
43
  await this.agent.syncTime();
43
44
  console.log("🔄 Czas agenta został zsynchronizowany ponownie.");
44
45
  }
45
46
  catch (err) {
46
47
  console.error("❌ Nie udało się zsynchronizować czasu:", err);
48
+ if (throwError) {
49
+ throw err;
50
+ }
47
51
  }
48
52
  }
49
53
  /**
50
54
  * Adds a new task to the queue.
51
55
  */
52
- async addTask(args) {
56
+ async addTaskAsync(args, throwError) {
53
57
  try {
58
+ await this.syncTimeAsync(true);
54
59
  return await this.actor.addTask(args);
55
60
  }
56
61
  catch (error) {
57
62
  await this.checkError(error);
58
63
  console.error(`❌ Błąd podczas dodawania zadania:`, error);
59
- throw error;
64
+ if (throwError) {
65
+ throw error;
66
+ }
67
+ else {
68
+ return BigInt(0);
69
+ }
60
70
  }
61
71
  }
62
72
  /**
63
73
  * Claims a task for a specific worker.
64
74
  */
65
- async claimTask(args) {
75
+ async claimTaskAsync(args, throwError) {
66
76
  try {
77
+ await this.syncTimeAsync(true);
67
78
  return await this.actor.claimTask(args);
68
79
  }
69
80
  catch (error) {
70
81
  await this.checkError(error);
71
82
  console.error(`❌ Błąd podczas pobierania zadania (claimTask):`, error);
72
- throw error;
83
+ if (throwError) {
84
+ throw error;
85
+ }
86
+ else {
87
+ return [];
88
+ }
73
89
  }
74
90
  }
75
91
  /**
76
92
  * Completes a previously claimed task.
77
93
  */
78
- async completeTask(args) {
94
+ async completeTaskAsync(args, throwError) {
79
95
  try {
96
+ await this.syncTimeAsync(true);
80
97
  return await this.actor.completeTask(args);
81
98
  }
82
99
  catch (error) {
83
100
  await this.checkError(error);
84
101
  console.error(`❌ Błąd podczas zakończenia zadania:`, error);
85
- throw error;
102
+ if (throwError) {
103
+ throw error;
104
+ }
105
+ else {
106
+ return false;
107
+ }
86
108
  }
87
109
  }
88
110
  /**
89
111
  * Fetches IDs of tasks available in a specific channel.
90
112
  */
91
- async getAvailableTaskIds(channel) {
113
+ async getAvailableTaskIdsAsync(channel, throwError) {
92
114
  try {
115
+ await this.syncTimeAsync(true);
93
116
  return await this.actor.getAvailableTaskIds(channel);
94
117
  }
95
118
  catch (error) {
96
119
  await this.checkError(error);
97
120
  console.error(`❌ Błąd podczas pobierania ID zadań (Kanał: ${channel}):`, error);
98
- throw error;
121
+ if (throwError) {
122
+ throw error;
123
+ }
124
+ else {
125
+ return [];
126
+ }
99
127
  }
100
128
  }
101
129
  /**
102
130
  * Returns a list of all tasks.
103
131
  */
104
- async getTasks() {
132
+ async getTasksAsync(throwError) {
105
133
  try {
134
+ await this.syncTimeAsync(true);
106
135
  return await this.actor.getTasks();
107
136
  }
108
137
  catch (error) {
109
138
  await this.checkError(error);
110
139
  console.error(`❌ Błąd podczas pobierania wszystkich zadań (getTasks):`, error);
111
- throw error;
140
+ if (throwError) {
141
+ throw error;
142
+ }
143
+ else {
144
+ return [];
145
+ }
112
146
  }
113
147
  }
114
- async whoAmI() {
148
+ async whoAmIAsync(throwError) {
115
149
  try {
116
150
  const x = await this.actor.whoAmI();
117
151
  return x.toString();
@@ -119,7 +153,12 @@ export class RabbitMotokoActor {
119
153
  catch (error) {
120
154
  await this.checkError(error);
121
155
  console.error(`❌ Błąd podczas pobierania informacji o użytkowniku (whoAmI):`, error);
122
- throw error;
156
+ if (throwError) {
157
+ throw error;
158
+ }
159
+ else {
160
+ return "";
161
+ }
123
162
  }
124
163
  }
125
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/rabbit-motoko-package",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Wrapper TypeScript package for Rabbit Motoko Canister.",
5
5
  "license": "ISC",
6
6
  "author": "",