Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
workerbee
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
workerbee
Commits
e0c9ad3f
Verified
Commit
e0c9ad3f
authored
5 months ago
by
Mateusz Tyszczak
Browse files
Options
Downloads
Patches
Plain Diff
Improve WorkerBee events typization
parent
b2c9f993
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/bot.ts
+26
-1
26 additions, 1 deletion
src/bot.ts
src/errors.ts
+1
-1
1 addition, 1 deletion
src/errors.ts
src/wax/index.ts
+1
-1
1 addition, 1 deletion
src/wax/index.ts
with
28 additions
and
3 deletions
src/bot.ts
+
26
−
1
View file @
e0c9ad3f
...
@@ -40,6 +40,31 @@ export const DEFAULT_WORKERBEE_OPTIONS = {
...
@@ -40,6 +40,31 @@ export const DEFAULT_WORKERBEE_OPTIONS = {
export
const
DEFAULT_BLOCK_INTERVAL_TIMEOUT
=
1500
;
export
const
DEFAULT_BLOCK_INTERVAL_TIMEOUT
=
1500
;
interface
IWorkerBeeEvents
{
"
stop
"
:
()
=>
void
|
Promise
<
void
>
;
"
start
"
:
()
=>
void
|
Promise
<
void
>
;
"
block
"
:
(
blockData
:
IBlockData
)
=>
void
|
Promise
<
void
>
;
"
transaction
"
:
(
transactionData
:
ITransactionData
)
=>
void
|
Promise
<
void
>
;
"
error
"
:
(
error
:
WorkerBeeError
)
=>
void
|
Promise
<
void
>
;
}
/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
export
declare
interface
WorkerBee
{
on
<
U
extends
keyof
IWorkerBeeEvents
>
(
event
:
U
,
listener
:
IWorkerBeeEvents
[
U
]
):
this
;
once
<
U
extends
keyof
IWorkerBeeEvents
>
(
event
:
U
,
listener
:
IWorkerBeeEvents
[
U
]
):
this
;
off
<
U
extends
keyof
IWorkerBeeEvents
>
(
event
:
U
,
listener
:
IWorkerBeeEvents
[
U
]
):
this
;
}
/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
export
class
WorkerBee
extends
EventEmitter
implements
IWorkerBee
{
export
class
WorkerBee
extends
EventEmitter
implements
IWorkerBee
{
public
running
:
boolean
=
false
;
public
running
:
boolean
=
false
;
...
@@ -150,7 +175,7 @@ export class WorkerBee extends EventEmitter implements IWorkerBee {
...
@@ -150,7 +175,7 @@ export class WorkerBee extends EventEmitter implements IWorkerBee {
}
// Else -> no new block
}
// Else -> no new block
}
catch
(
error
)
{
}
catch
(
error
)
{
// Ensure we are emitting the Error instance
// Ensure we are emitting the Error instance
super
.
emit
(
"
error
"
,
error
instanceof
Error
?
error
:
new
Error
(
`Unknown e
rror occurred during automation:
${
String
(
error
)}
`
));
super
.
emit
(
"
error
"
,
new
WorkerBeeError
(
`E
rror occurred during automation:
${
String
(
error
)}
`
,
error
));
// Wait before any next operation is performed to reduce spamming the API
// Wait before any next operation is performed to reduce spamming the API
await
new
Promise
(
res
=>
{
setTimeout
(
res
,
DEFAULT_BLOCK_INTERVAL_TIMEOUT
);
});
await
new
Promise
(
res
=>
{
setTimeout
(
res
,
DEFAULT_BLOCK_INTERVAL_TIMEOUT
);
});
...
...
This diff is collapsed.
Click to expand it.
src/errors.ts
+
1
−
1
View file @
e0c9ad3f
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @internal
* @internal
*/
*/
export
class
WorkerBeeError
extends
Error
{
export
class
WorkerBeeError
extends
Error
{
public
constructor
(
message
:
string
)
{
public
constructor
(
message
:
string
,
public
readonly
originator
?:
Error
|
any
)
{
super
(
message
);
super
(
message
);
this
.
name
=
"
WorkerBeeError
"
;
this
.
name
=
"
WorkerBeeError
"
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/wax/index.ts
+
1
−
1
View file @
e0c9ad3f
...
@@ -2,7 +2,7 @@ import { createHiveChain, IHiveChainInterface, IWaxOptionsChain, TWaxExtended }
...
@@ -2,7 +2,7 @@ import { createHiveChain, IHiveChainInterface, IWaxOptionsChain, TWaxExtended }
export
const
WaxExtendTypes
=
{};
export
const
WaxExtendTypes
=
{};
export
const
getWax
=
async
(
explicitHiveChain
?:
IHiveChainInterface
,
options
?:
Partial
<
IWaxOptionsChain
>
):
Promise
<
TWaxExtended
<
typeof
WaxExtendTypes
>>
=>
{
export
const
getWax
=
async
(
explicitHiveChain
?:
IHiveChainInterface
,
options
?:
Partial
<
IWaxOptionsChain
>
):
Promise
<
TWaxExtended
<
typeof
WaxExtendTypes
>>
=>
{
if
(
explicitHiveChain
===
undefined
)
if
(
explicitHiveChain
===
undefined
)
explicitHiveChain
=
await
createHiveChain
(
options
);
explicitHiveChain
=
await
createHiveChain
(
options
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment