@pritzlaff/nano-core 0.2.0 → 0.5.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/data.d.ts DELETED
@@ -1,72 +0,0 @@
1
- import type { TSchema } from 'typebox';
2
- type S = TSchema | undefined;
3
- /** A named operation a component offers. With input and output it is an action, output only a source, input only a sink. */
4
- export type Op<I extends S = S, O extends S = S> = {
5
- ns: string;
6
- name: string;
7
- input?: I;
8
- output?: O;
9
- };
10
- /** A value as JSON with sorted keys: equal data gives equal strings (schemas included). */
11
- export declare const canonical: (value: unknown) => string;
12
- /** Makes ops and names them. */
13
- export declare const Ops: {
14
- action: <I extends TSchema, O extends TSchema>(ns: string, name: string, input: I, output: O) => Op<I, O>;
15
- source: <O extends TSchema>(ns: string, name: string, output: O) => Op<undefined, O>;
16
- sink: <I extends TSchema>(ns: string, name: string, input: I) => Op<I, undefined>;
17
- /** The op's coordinate, used wherever an op is referred to by name. */
18
- key: (op: Pick<Op, 'ns' | 'name'>) => string;
19
- /** Can what `from` outputs be given to `to`? Its input takes anything, or is the same type, name included. */
20
- fits: (from: Op, to: Op) => boolean;
21
- };
22
- /** Where an instance lives: a registry and an instance id within it. */
23
- export type Coord = {
24
- registry: string;
25
- instance: string;
26
- };
27
- /** The outcome of anything that can fail: a value, or an error message. */
28
- export type Result<A = unknown> = {
29
- value: A;
30
- detail?: unknown;
31
- } | {
32
- error: string;
33
- detail?: unknown;
34
- };
35
- /** A success. */
36
- export declare const ok: <A>(value: A, detail?: unknown) => Result<A>;
37
- /** A failure, with a message. */
38
- export declare const err: (error: string, detail?: unknown) => Result<never>;
39
- /** Whether a Result is a success. */
40
- export declare const isOk: <A>(r: Result<A>) => r is {
41
- value: A;
42
- detail?: unknown;
43
- };
44
- /** Something an instance published: who, which op (by key), and the data. */
45
- export type Event = {
46
- from: Coord;
47
- op: string;
48
- data: unknown;
49
- correlation?: string;
50
- };
51
- /** A named connection: when `source` (or any, '*') publishes `op`, call `listener`'s `target` action with the data. */
52
- export type Subscription = {
53
- id: string;
54
- source: string;
55
- op: string;
56
- listener: string;
57
- target: string;
58
- };
59
- /** A change to a registry, published from the registry itself. */
60
- export type Delta = {
61
- type: 'instance-added' | 'instance-removed';
62
- instance: string;
63
- ops: string[];
64
- } | {
65
- type: 'op-added' | 'op-removed';
66
- instance: string;
67
- op: string;
68
- } | {
69
- type: 'subscription-opened' | 'subscription-closed';
70
- subscription: Subscription;
71
- };
72
- export {};
package/env.d.ts DELETED
@@ -1,25 +0,0 @@
1
- import type { Action } from './component.js';
2
- import { type Coord, type Op, type Result } from './data.js';
3
- /** One registry as seen by an instance in it: its coordinate there, and how to publish and call. */
4
- export type Handle = {
5
- coord: Coord;
6
- notify(op: Op, data: unknown, correlation?: string): Promise<Result<Result[]>>;
7
- call(target: string, op: Op, arg: unknown): Promise<Result>;
8
- };
9
- /** Tells a registry that the instance's ops changed. */
10
- export type Announce = (type: 'op-added' | 'op-removed', op: Op) => void;
11
- /** All the registries an instance is in. It publishes to each, and lets the instance add or drop its own ops. */
12
- export type Environment = {
13
- handles(): Handle[];
14
- added(h: Handle, announce: Announce): void;
15
- removed(coord: Coord): void;
16
- notify(op: Op, data: unknown, correlation?: string): Promise<Result<Result[]>[]>;
17
- register(op: Op, run?: Action<any>['run'], opts?: {
18
- emits?: Op[];
19
- }): 'added' | 'replaced';
20
- unregister(op: Op): boolean;
21
- };
22
- /** Makes the environment over an instance's action map. */
23
- export declare const Environments: {
24
- create(actions: Map<string, Action<any>>): Environment;
25
- };