@fission-codes/homestar
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -56,2 +56,16 @@ /** | ||
/** | ||
* Subscribe to a network events | ||
* | ||
* @param {(data: MaybeResult<Schemas.EventNotification, Schemas.EventNotificationError>)=>void} [receiptCb] - Callback for network events | ||
*/ | ||
networkEvents(receiptCb?: ((data: MaybeResult<Schemas.EventNotification, Schemas.EventNotificationError>) => void) | undefined): Promise<{ | ||
result: string; | ||
unsub: () => void; | ||
error?: undefined; | ||
} | { | ||
error: Error; | ||
result?: undefined; | ||
unsub?: undefined; | ||
}>; | ||
/** | ||
* Close homestar channel and clean listeners | ||
@@ -58,0 +72,0 @@ */ |
@@ -12,2 +12,4 @@ export type Metrics = import('zod').z.infer<typeof Metrics>; | ||
* @typedef {import('./types.js').InferError<typeof WorkflowNotification>} WorkflowNotificationError | ||
* @typedef {import('zod').z.infer<typeof EventNotification>} EventNotification | ||
* @typedef {import('./types.js').InferError<typeof EventNotification>} EventNotificationError | ||
*/ | ||
@@ -379,6 +381,21 @@ export const Metrics: z.ZodEffects<z.ZodObject<{ | ||
}>; | ||
export type EventNotification = import('zod').z.infer<typeof EventNotification>; | ||
export const EventNotification: z.ZodObject<{ | ||
type: z.ZodString; | ||
timestamp: z.ZodNumber; | ||
data: z.ZodAny; | ||
}, "strip", z.ZodTypeAny, { | ||
type: string; | ||
timestamp: number; | ||
data?: any; | ||
}, { | ||
type: string; | ||
timestamp: number; | ||
data?: any; | ||
}>; | ||
export type MetricsError = import('./types.js').InferError<typeof Metrics>; | ||
export type HealthError = import('./types.js').InferError<typeof Health>; | ||
export type WorkflowNotificationError = import('./types.js').InferError<typeof WorkflowNotification>; | ||
export type EventNotificationError = import('./types.js').InferError<typeof EventNotification>; | ||
import { z } from 'zod'; | ||
//# sourceMappingURL=schemas.d.ts.map |
{ | ||
"name": "@fission-codes/homestar", | ||
"type": "module", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Homestart Client.", | ||
@@ -89,5 +89,10 @@ "author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)", | ||
"@types/object-path": "^0.11.4", | ||
"execa": "^8.0.1", | ||
"homestar-runtime": "^0.0.8", | ||
"iso-base": "^2.0.1", | ||
"kubo-rpc-client": "^3.0.1", | ||
"p-defer": "^4.0.0", | ||
"playwright-test": "^12.6.0", | ||
"playwright-test": "^13.0.0", | ||
"tempy": "^3.1.0", | ||
"testcontainers": "^10.2.2", | ||
"type-fest": "^4.7.1", | ||
@@ -118,3 +123,4 @@ "unws": "^0.2.4", | ||
"hd-scripts", | ||
"assert" | ||
"assert", | ||
"homestar-runtime" | ||
] | ||
@@ -121,0 +127,0 @@ }, |
@@ -42,32 +42,2 @@ # Homestar | ||
## TODO | ||
```rust | ||
/// Subscribe to network events. | ||
#[cfg(feature = "websocket-notify")] | ||
pub(crate) const SUBSCRIBE_NETWORK_EVENTS_ENDPOINT: &str = "subscribe_network_events"; | ||
/// Unsubscribe from network events. | ||
#[cfg(feature = "websocket-notify")] | ||
pub(crate) const UNSUBSCRIBE_NETWORK_EVENTS_ENDPOINT: &str = "unsubscribe_network_events"; | ||
package homestar-functions:test | ||
world test { | ||
export add-one: func(a: s32) -> s32 | ||
export append-string: func(a: string) -> string | ||
export join-strings: func(a: string, b: string) -> string | ||
export transpose: func(matrix: list<list<u16>>) -> list<list<u16>> | ||
export blur: func(data: list<u8>, sigma: float32) -> list<u8> | ||
export blur-base64: func(data: string, sigma: float32) -> list<u8> | ||
export crop: func(data: list<u8>, x: u32, y: u32, target-width: u32, target-height: u32) -> list<u8> | ||
export crop-base64: func(data: string, x: u32, y: u32, target-width: u32, target-height: u32) -> list<u8> | ||
export grayscale: func(data: list<u8>) -> list<u8> | ||
export grayscale-base64: func(data: string) -> list<u8> | ||
export rotate90: func(data: list<u8>) -> list<u8> | ||
export rotate90-base64: func(data: string) -> list<u8> | ||
} | ||
``` | ||
## Contributing | ||
@@ -74,0 +44,0 @@ |
@@ -153,2 +153,62 @@ import { decode } from '@ipld/dag-json' | ||
/** | ||
* Subscribe to a network events | ||
* | ||
* @param {(data: MaybeResult<Schemas.EventNotification, Schemas.EventNotificationError>)=>void} [receiptCb] - Callback for network events | ||
*/ | ||
async networkEvents(receiptCb) { | ||
const res = /** @type {MaybeResult<string, Error>} */ ( | ||
await this.#channel.request({ | ||
method: 'subscribe_network_events', | ||
}) | ||
) | ||
if (res.result !== undefined) { | ||
const subId = res.result | ||
/** @type {import('emittery').UnsubscribeFunction} */ | ||
let unsub | ||
if (receiptCb) { | ||
unsub = this.#channel.on( | ||
'notification', | ||
// @ts-ignore | ||
(/** @type {SubscriptionNotification} */ data) => { | ||
if (data.subscription === subId) { | ||
const decoded = decode(new Uint8Array(data.result)) | ||
const r = Schemas.EventNotification.safeParse(decoded) | ||
if (r.success === false) { | ||
receiptCb({ error: r.error }) | ||
} else { | ||
receiptCb({ result: r.data }) | ||
} | ||
} | ||
} | ||
) | ||
} | ||
return { | ||
result: subId, | ||
unsub: () => { | ||
unsub() | ||
this.#channel | ||
.request({ | ||
method: 'unsubscribe_network_events', | ||
params: [subId], | ||
}) | ||
.then( | ||
(res) => { | ||
if (res.error) { | ||
return this.emit('error', res.error) | ||
} | ||
}, | ||
(error) => { | ||
this.emit('error', error) | ||
} | ||
) | ||
}, | ||
} | ||
} | ||
return { error: res.error } | ||
} | ||
/** | ||
* Close homestar channel and clean listeners | ||
@@ -155,0 +215,0 @@ */ |
@@ -14,2 +14,4 @@ import { z } from 'zod' | ||
* @typedef {import('./types.js').InferError<typeof WorkflowNotification>} WorkflowNotificationError | ||
* @typedef {import('zod').z.infer<typeof EventNotification>} EventNotification | ||
* @typedef {import('./types.js').InferError<typeof EventNotification>} EventNotificationError | ||
*/ | ||
@@ -100,1 +102,7 @@ | ||
}) | ||
export const EventNotification = z.object({ | ||
type: z.string(), | ||
timestamp: z.number(), | ||
data: z.any(), | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69980
1913
16
68