@pritzlaff/nano-core 0.4.0 → 0.5.1

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.
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * The context a pod's factory gets, for pod `name`: it reads the deployment as it is at each call, over the call
3
3
  * subscriptions from `name` in every runtime that lists one (placed there or not), each a `Selection`. `onClose` adds a listener to the
4
- * build this context belongs to; the `on` subscriptions this build made are dropped through it.
4
+ * build this context belongs to; the `on` subscriptions this build made are dropped through it. With `invoked` it is a
5
+ * handler invocation's: `callingOp` is its port, and its calls and publishes continue that message's chain
6
+ * (`correlation`, `cause` = its id); `on` and listeners stay the build's.
5
7
  *
6
8
  * const ctx = contextFor(live, 'send', fn => …)
7
9
  * ctx.one(KV) // success(the one KV wired from send, in whichever runtime), or not-found / not-unique
@@ -10,4 +12,8 @@
10
12
  */
11
13
  import type { NanoContext } from '../context.js';
12
14
  import { type Live } from './messages.js';
13
- export declare function contextFor(live: Live, name: string, onClose: NanoContext['addOnCloseListener']): Omit<NanoContext, 'deps'>;
15
+ export declare function contextFor(live: Live, name: string, onClose: NanoContext['addOnCloseListener'], invoked?: {
16
+ id: string;
17
+ correlation: string;
18
+ port: string;
19
+ }): Omit<NanoContext, 'deps'>;
@@ -13,7 +13,7 @@ type Chain = {
13
13
  export declare function emit(live: Live, from: string, port: string, e: Parameters<On['fn']>[0], chain?: Chain, travelled?: string): Promise<unknown>;
14
14
  /**
15
15
  * A client by op name from `from` to `to` in `runtime`. `gone()` is asked at each call, before anything is sent: a
16
- * Fail it gives is the call's result.
16
+ * Fail it gives is the call's result. With `chain` each call continues it (its `correlation`, `cause`).
17
17
  */
18
- export declare function client(live: Live, runtime: string, from: string, to: string, gone: () => NanoResult<never> | undefined): Record<string, (input: unknown) => Promise<NanoResult<unknown>>>;
18
+ export declare function client(live: Live, runtime: string, from: string, to: string, gone: () => NanoResult<never> | undefined, chain?: Chain): Record<string, (input: unknown) => Promise<NanoResult<unknown>>>;
19
19
  export {};
@@ -15,12 +15,15 @@ import { AppDeployment } from '../deployment.js';
15
15
  import type { Implementation } from '../implementation.js';
16
16
  import type { Pod } from '../pod.js';
17
17
  import type { Policy } from '../policy.js';
18
+ import { type DeploymentPolicy } from '../deployment-policy.js';
18
19
  import { type NanoResult } from '../result.js';
19
20
  import type { Runtime } from '../runtime.js';
20
21
  import { type RuntimeView } from './resolve.js';
21
22
  import { type AppEvent } from './stream.js';
22
23
  export type { AppEvent } from './stream.js';
23
24
  export type { Resolution } from './resolve.js';
25
+ export type { PodStatus } from './instances.js';
26
+ export { lookup, type Lookup } from './lookup.js';
24
27
  export type Application = {
25
28
  /** The runtime `id` as the host sees it; `resolve`, `get`, `call` and `subscribe` below are those of the one runtime (else `not-unique`). */
26
29
  runtime(id: string): RuntimeView;
@@ -29,7 +32,10 @@ export type Application = {
29
32
  get: RuntimeView['get'];
30
33
  resolve: RuntimeView['resolve'];
31
34
  subscribe: RuntimeView['subscribe'];
32
- apply(next: AppDeployment): Promise<NanoResult<void>>;
35
+ /** `caller` (default `'host'`) is asked of the deployment policy and recorded on `applied`. */
36
+ apply(next: AppDeployment, opts?: {
37
+ caller?: string;
38
+ }): Promise<NanoResult<void>>;
33
39
  restart(pod: string): Promise<NanoResult<void>>;
34
40
  deployment(): AppDeployment;
35
41
  listen(fn: (e: AppEvent) => void): () => void;
@@ -38,6 +44,7 @@ export type Application = {
38
44
  /** `isolate` gives the host's stand-in for a pod whose isolation isn't 'host' (same coord); without it such a pod fails. */
39
45
  type Opts = {
40
46
  policies?: Record<string, Policy>;
47
+ deploymentPolicy?: DeploymentPolicy;
41
48
  timeoutMs?: number;
42
49
  isolate?: (name: string, pod: Pod) => Implementation;
43
50
  };
@@ -9,15 +9,19 @@
9
9
  * await pods.get('db') // NanoResult<{ implementation, handlers by port }>: built now, or the build already made or under way
10
10
  * await pods.forget('db', 'restarted') // its listeners have run; the next get builds a fresh closure; calls in flight keep the old one
11
11
  * await pods.close() // every build closed (`closed`); every later get is not-found
12
+ * pods.status('db') // 'running', 'not started', 'stopped' or 'failed'
12
13
  */
13
14
  import type { NanoContext } from '../context.js';
14
15
  import { type Live } from './messages.js';
15
16
  type Made = ReturnType<Live['instance']>;
16
17
  type OnClose = Parameters<NanoContext['addOnCloseListener']>[0];
17
18
  type Reason = Parameters<OnClose>[0]['reason'];
19
+ /** A placed pod's lifecycle now: built, never built (or forgotten since), closed with the application, or its last build failed. */
20
+ export type PodStatus = 'running' | 'not started' | 'stopped' | 'failed';
18
21
  export declare function instances(live: Live): {
19
22
  get(name: string): Made;
20
23
  forget: (name: string, why: Reason) => Promise<void>;
24
+ status: (name: string) => PodStatus;
21
25
  close(): Promise<void>;
22
26
  };
23
27
  export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * What a message needs to know about a deployment, found once per deployment object rather than scanned per message:
3
3
  * where each pod is placed, the call edges and pipes from each pod, and each runtime's compiled policy. `apply` makes a
4
- * new deployment object, so the cache follows it.
4
+ * new deployment object, so the cache follows it. It caches by object identity: treat `d` as immutable once looked up.
5
5
  *
6
6
  * lookup(d).placed.get('backend')?.has('store') // placed there?
7
7
  * lookup(d).pipes.get(`${pod} ${port}`) // the pipes carrying that emission, runtimes then subscriptions in order
@@ -21,10 +21,11 @@ export type Live = {
21
21
  readonly policies: Record<string, Policy>;
22
22
  readonly timeoutMs: number;
23
23
  readonly trace: ReturnType<typeof stream>;
24
- /** A build: the handlers by port, and the implementation they were made from. */
24
+ /** A build: the handlers by port, the implementation they were made from, and its `addOnCloseListener`. */
25
25
  instance(pod: string): Promise<NanoResult<{
26
26
  implementation: Implementation;
27
27
  handlers: ReadonlyMap<string, Handler>;
28
+ onClose: NanoContext['addOnCloseListener'];
28
29
  }>>;
29
30
  /** The live listeners, in the order made: `on` subscriptions (a pod's, or the host's; `heard` the same by `${from} ${port}`, what `emit` reads) and pod-change listeners (`ctx.addOnPodChangeListener`). */
30
31
  readonly listeners: {
@@ -12,6 +12,7 @@ import type { Op } from '../op.js';
12
12
  import { type Fail, type NanoResult } from '../result.js';
13
13
  import type { AppEvent } from './stream.js';
14
14
  import { type Live } from './messages.js';
15
+ import type { PodStatus } from './instances.js';
15
16
  type Reason = 'not-found' | 'not-unique' | 'denied';
16
17
  export type Resolution<T> = {
17
18
  readonly ok: true;
@@ -67,6 +68,15 @@ export type RuntimeView = {
67
68
  }>;
68
69
  /** The application's one stream, filtered to this runtime: its messages and their outcomes, `applied`, and the lifecycle of its pods; gives an unsubscribe. */
69
70
  listen(fn: (e: AppEvent) => void): () => void;
71
+ /** `pod`'s lifecycle now (`running`, `not started`, `stopped`, `failed`); `not-found` if it is not placed here. */
72
+ status(pod: string): NanoResult<PodStatus>;
73
+ /** Build `pod`, placed here and not running, by a `start` message from the host (ADR-0031): `not-found`, `invalid-input` "already running", `denied`, or the build's `Fail`. */
74
+ start(pod: string): Promise<NanoResult<void>>;
75
+ /** `pod` running, reused (`started: false`) or started now (`true`), with `call(pod)`'s client; or `start`'s `Fail`. */
76
+ getOrCreate(pod: string): Promise<NanoResult<{
77
+ started: boolean;
78
+ pod: Client;
79
+ }>>;
70
80
  };
71
81
  type DataOf<S> = S extends TSchema ? Static<S> : unknown;
72
82
  type In<O> = O extends Op<infer I, any> ? DataOf<I> : unknown;
@@ -76,7 +86,7 @@ export declare function placement(live: Live, runtime: string, api: Interface, w
76
86
  /**
77
87
  * Runtime `id` (or, absent, the application's one runtime) as the host sees it, looked up again at each use, so one
78
88
  * added later by `apply` works and a missing one is `not-found`.
79
- * Its plain objects resolve again at each call, so a rewired placement is followed.
89
+ * Its plain objects resolve again at each call, so a rewired placement is followed. `status` is the instances'; `start` and `getOrCreate` are `start.ts`'s.
80
90
  */
81
- export declare function runtimeView(live: Live, id?: string): RuntimeView;
91
+ export declare function runtimeView(live: Live, status: (pod: string) => PodStatus, id?: string): RuntimeView;
82
92
  export {};
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A pod started explicitly, in one runtime (ADR-0031). `start(pod)` is a message of kind `start` from the host, with no
3
+ * port: `sent`, asked of the runtime's policy, then `delivered` with the build's result (or `denied`). It builds through
4
+ * `live.instance`, the one build per pod however many ask. `getOrCreate(pod)` reuses a running pod, or starts it, and
5
+ * gives `call(pod)`'s client. Of callers racing on one pod in one runtime, one starts it; the rest find it started once it settles.
6
+ *
7
+ * const s = starter(live, at, status, call)
8
+ * await s.start('db') // NanoResult<void>: not-found, invalid-input "already running", denied, or the build's Fail
9
+ * await s.getOrCreate('db') // NanoResult<{ started, pod }>
10
+ */
11
+ import { type Fail, type NanoResult } from '../result.js';
12
+ import type { client } from './emit.js';
13
+ import type { PodStatus } from './instances.js';
14
+ import { type Live } from './messages.js';
15
+ type Client = ReturnType<typeof client>;
16
+ type At = () => {
17
+ ok: true;
18
+ value: string;
19
+ } | {
20
+ ok: false;
21
+ fail: Fail;
22
+ };
23
+ export declare function starter(live: Live, at: At, status: (pod: string) => PodStatus, call: (pod: string) => Client): {
24
+ start(pod: string): Promise<NanoResult<void>>;
25
+ getOrCreate(pod: string): Promise<NanoResult<{
26
+ started: boolean;
27
+ pod: Client;
28
+ }>>;
29
+ };
30
+ export {};
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The application's one stream: builds, closes, restarts, changes, messages (`sent`, then `delivered` or `denied`) and problems,
3
- * in order, synchronously. A `sent` names its kind and its chain: `correlation` is the first message's id, `cause` the
3
+ * in order, synchronously. A `sent` names its kind and its chain (a `start` has no port, ADR-0031): `correlation` is the first message's id, `cause` the
4
4
  * message that led to it. A throwing listener is swallowed.
5
5
  *
6
6
  * const s = stream()
@@ -22,6 +22,7 @@ export type AppEvent = {
22
22
  pod: string;
23
23
  } | {
24
24
  type: 'applied';
25
+ caller: string;
25
26
  added: string[];
26
27
  removed: string[];
27
28
  changed: string[];
@@ -36,6 +37,18 @@ export type AppEvent = {
36
37
  port: string;
37
38
  correlation: string;
38
39
  cause?: string;
40
+ input?: unknown;
41
+ } | {
42
+ type: 'sent';
43
+ id: string;
44
+ runtime: string;
45
+ kind: 'start';
46
+ from: 'host';
47
+ to: string;
48
+ correlation: string;
49
+ port?: never;
50
+ cause?: never;
51
+ input?: never;
39
52
  } | {
40
53
  type: 'delivered';
41
54
  id: string;
package/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The context a pod's factory gets. It belongs to the pod, not to a call: `one` and `all` read the deployment as it is
2
+ * The context a pod's factory gets, and (with `callingOp`) each handler invocation gets: `one` and `all` read the deployment as it is
3
3
  * now, over the call subscriptions from `self` in every runtime the pod is placed in, each a `Selection`.
4
4
  *
5
5
  * const kv = ctx.one(KeyValueStore) // NanoResult<Selection>: a Fail (not-found, not-unique) unless exactly one is wired
@@ -49,6 +49,8 @@ export type Selection<I extends Interface> = {
49
49
  };
50
50
  export type NanoContext<D extends Record<string, Selector> = Record<string, Selector>> = {
51
51
  readonly self: string;
52
+ /** In a handler's context, the port it is handling (its calls and publishes continue that message's chain); absent in the factory's. */
53
+ readonly callingOp?: string;
52
54
  readonly runtimes: readonly string[];
53
55
  /** One plain object per declared dependency role, typed from its interface. */
54
56
  readonly deps: {
package/coord.d.ts CHANGED
@@ -6,7 +6,8 @@
6
6
  * const store = kv.interfaceId('KeyValueStore') // example.kv.KeyValueStore
7
7
  * const mem = kv.implementationId('memory') // example.kv/memory
8
8
  * Coord.port(store, 'get') // example.kv.KeyValueStore/get
9
- * Coord.pod(mem, 'main', 'store') // example.kv/memory@main/store
9
+ * const main = Coord.runtime('main') // main
10
+ * Coord.pod(mem, main, 'store') // example.kv/memory@main/store
10
11
  */
11
12
  export type Namespace = {
12
13
  readonly kind: 'namespace';
@@ -29,10 +30,15 @@ export type PortCoord = {
29
30
  readonly interface: InterfaceCoord;
30
31
  readonly op: string;
31
32
  };
33
+ /** A runtime, by its id: the same id `runtimes` keys and events carry as a plain string. */
34
+ export type RuntimeCoord = {
35
+ readonly kind: 'runtime';
36
+ readonly id: string;
37
+ };
32
38
  export type PodCoord = {
33
39
  readonly kind: 'pod';
34
40
  readonly implementation: ImplCoord;
35
- readonly runtime: string;
41
+ readonly runtime: RuntimeCoord;
36
42
  readonly pod: string;
37
43
  };
38
44
  type Kinds = {
@@ -40,16 +46,19 @@ type Kinds = {
40
46
  interface: InterfaceCoord;
41
47
  implementation: ImplCoord;
42
48
  port: PortCoord;
49
+ runtime: RuntimeCoord;
43
50
  pod: PodCoord;
44
51
  };
45
52
  declare function namespace(name: string): Namespace;
46
53
  declare function port(i: InterfaceCoord, op: string): PortCoord;
47
- declare function pod(implementation: ImplCoord, runtime: string, name: string): PodCoord;
54
+ declare function runtime(id: string): RuntimeCoord;
55
+ declare function pod(implementation: ImplCoord, runtime: RuntimeCoord, name: string): PodCoord;
48
56
  declare function read<K extends keyof Kinds>(kind: K, s: string): Kinds[K];
49
- /** Layer 1's coordinates (the package's `Coord` adds a namespace's building methods, in provider.ts): `Coord.namespace(ns)`, `Coord.port(interface, op)`, `Coord.pod(implementation, runtime, pod)`, `Coord.parse(kind, s)`. */
57
+ /** Layer 1's coordinates (the package's `Coord` adds a namespace's building methods, in provider.ts): `Coord.namespace(ns)`, `Coord.port(interface, op)`, `Coord.runtime(id)`, `Coord.pod(implementation, runtime, pod)`, `Coord.parse(kind, s)`. */
50
58
  export declare const Coord: {
51
59
  namespace: typeof namespace;
52
60
  port: typeof port;
61
+ runtime: typeof runtime;
53
62
  pod: typeof pod;
54
63
  parse: typeof read;
55
64
  };
@@ -8,6 +8,9 @@
8
8
  * kvs.create(todosKv, { pod: 'todos', in: 'frontend' }) // pod; edge todos→store in backend; a rule letting it in
9
9
  * await app.apply(d.deployment())
10
10
  *
11
+ * `pipe(runtime, { from, source, to, target })` appends that pipe to the runtime (both pods placed there; an equal pipe
12
+ * is `invalid-input`); `unpipe(runtime, same)` removes it (`not-found` when there is none).
13
+ *
11
14
  * `create` records a call edge in the resolved pod's runtime and, when that runtime's policy is `rules`, prepends
12
15
  * `{ allow: ['call', 'subscribe'], from, outside, toInterface }` (the first match wins: the operator asked for this edge).
13
16
  */
@@ -20,6 +23,12 @@ type Where = {
20
23
  in: string;
21
24
  eager?: boolean;
22
25
  };
26
+ type PipeEnds = {
27
+ from: string;
28
+ source: string;
29
+ to: string;
30
+ target: string;
31
+ };
23
32
  type Handle = {
24
33
  readonly runtime: string;
25
34
  readonly pod: string;
@@ -29,6 +38,8 @@ type Handle = {
29
38
  export declare function edit(base: AppDeployment, registry: Registry): {
30
39
  place: (impl: Implementation, w: Where) => void;
31
40
  resolve: (at: string, api: Interface) => Handle;
41
+ pipe: (at: string, p: PipeEnds) => undefined;
42
+ unpipe: (at: string, p: PipeEnds) => undefined;
32
43
  deployment: () => AppDeployment;
33
44
  };
34
45
  export {};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * DeploymentPolicy: the yes/no check the application makes before `apply` changes its deployment, like `Policy` for a message.
3
+ *
4
+ * const p = DeploymentPolicies.allowAll()
5
+ * await p.isAllowed({ caller: 'host', deployment }) // { approved: true }
6
+ */
7
+ import type { AppDeployment } from './deployment.js';
8
+ import type { Verdict } from './policy.js';
9
+ /** What it is asked: who applies (`'host'` or a pod name) and the deployment they want. */
10
+ export type DeploymentAsk = {
11
+ caller: string;
12
+ deployment: AppDeployment;
13
+ };
14
+ export type DeploymentPolicy = {
15
+ isAllowed(ask: DeploymentAsk): Verdict | Promise<Verdict>;
16
+ };
17
+ export declare const DeploymentPolicies: {
18
+ allowAll: () => DeploymentPolicy;
19
+ };
package/deployment.d.ts CHANGED
@@ -15,9 +15,11 @@ export type AppDeployment = {
15
15
  pods: PodDeployment;
16
16
  runtimes: Record<string, RuntimeDeployment>;
17
17
  tags?: Record<string, string[]>;
18
- /** Host-owned: nano shape-checks these and otherwise ignores them. */
18
+ /** Host-owned: nano shape-checks these and otherwise ignores them. `frames`: each provider's own page, for its
19
+ * `home-origin` pods. */
19
20
  modules?: Record<string, string>;
20
21
  views?: Record<string, string>;
22
+ frames?: Record<string, string>;
21
23
  /** The deployer's choice, a plain object: nano shape-checks it and otherwise ignores it; `deployment()` omits it. */
22
24
  layout?: Record<string, unknown>;
23
25
  };
package/iface.d.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  * Interfaces: a coordinate plus a set of ops, each named by its key (its coordinate the hash of that name and its
3
3
  * schemas), indexed by name and by op coord. A port is one op as offered by one interface, written readably.
4
4
  *
5
- * const db = Interface.define('acme/db', { get: Op.action(Key, Value) })
6
- * port(db, db.ops.get) // 'acme/db/get'
5
+ * const db = Interface.define('acme.Db', { get: Op.action(Key, Value) })
6
+ * port(db, db.ops.get) // 'acme.Db/get'
7
7
  *
8
8
  * An implementation starts from the contract it provides: `api.impl(coord)` is a builder (`needs`, `config`, each
9
9
  * optional, each typing the next step; `description(text)` too; `make` at every step; `create` all at once; `satisfies` for another interface
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import type { Static, TSchema } from 'typebox';
15
15
  import type { NanoContext } from './context.js';
16
- import type { ImplCoord, InterfaceCoord } from './coord.js';
16
+ import { type ImplCoord, type InterfaceCoord } from './coord.js';
17
17
  import { Implementation } from './implementation.js';
18
18
  import type { Op } from './op.js';
19
19
  import type { NanoResult } from './result.js';
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Implementations: code that provides whole interfaces. Its factory `make(ctx, config)` runs once per build and returns
3
- * the handlers by port; state is whatever the factory closes over, and handlers take only their input.
3
+ * the handlers by port; state is whatever the factory closes over. A handler takes its input and the invocation's
4
+ * context (`ctx.callingOp`, `ctx.deps`): calls through it continue the invoking message's chain.
4
5
  *
5
6
  * const memDb = Implementation.define('acme/mem/db', {
6
7
  * provides: [DB],
@@ -16,9 +17,12 @@ import type { Op } from './op.js';
16
17
  import type { NanoResult } from './result.js';
17
18
  import type { SchemaDef } from './schema.js';
18
19
  import { type Selector, type SelectorData } from './selector.js';
19
- export type Handler = (input: unknown) => Promise<NanoResult<unknown>>;
20
- /** One handler per action, typed as the Client's call. Events have none: they are published. */
21
- export type Handlers<I extends Interface> = Client<I>;
20
+ /** A handler: its input, and the invocation's context (`callingOp`; its calls continue the invoking message's chain). */
21
+ export type Handler = (input: unknown, ctx: Omit<NanoContext, 'deps'>) => Promise<NanoResult<unknown>>;
22
+ /** One handler per action, typed as the Client's call, with the invocation's context. Events have none: they are published. */
23
+ export type Handlers<I extends Interface> = {
24
+ [K in keyof Client<I>]: (input: Parameters<Client<I>[K]>[0], ctx: NanoContext) => ReturnType<Client<I>[K]>;
25
+ };
22
26
  /** A source: an event's method on a plain object, which the application runs once per build (`application/sources.ts`). */
23
27
  export type Source = {
24
28
  readonly op: Op;
@@ -38,6 +42,8 @@ export type Implementation = {
38
42
  readonly dependencies: Readonly<Record<string, SelectorData>>;
39
43
  readonly config?: SchemaDef;
40
44
  readonly description?: string;
45
+ /** Declared calls: an op of a provided interface, by name, to the `'role.op'` dependency ops it may call. */
46
+ readonly calls: Readonly<Record<string, readonly string[]>>;
41
47
  /** `ctx` without `deps`: they are made here from `dependencies`. It gives the build's handlers (by port) and its
42
48
  * sources (by port), which the application starts, publishes, stops at close, and traces when they throw. */
43
49
  make(ctx: Omit<NanoContext, 'deps'>, config: unknown): Promise<{
@@ -46,19 +52,27 @@ export type Implementation = {
46
52
  }>;
47
53
  };
48
54
  /** A plain object for `I`: its event (source) methods are optional, as an event may be published through `ctx`. */
49
- type Plain<I extends Interface, T = Interface.Type<I>> = {
50
- [K in keyof T as I['ops'][K & string]['kind'] extends 'event' ? never : K]: T[K];
55
+ type Plain<I extends Interface, D extends Record<string, Selector>, T = Interface.Type<I>> = {
56
+ [K in keyof T as I['ops'][K & string]['kind'] extends 'event' ? never : K]: T[K] extends (...a: infer A) => infer R ? (input: A extends [infer X] ? X : null, ctx: NanoContext<D>) => R : never;
51
57
  } & {
52
58
  [K in keyof T as I['ops'][K & string]['kind'] extends 'event' ? K : never]?: T[K];
53
59
  };
54
60
  /** `provide(...)` parts, or for a single interface its plain object (lifted by `handlers`; sources published). */
55
- type Made<P> = Provided[] | (P extends readonly [infer One extends Interface] ? Plain<One> : never);
61
+ type Made<P, D extends Record<string, Selector>> = Provided[] | (P extends readonly [infer One extends Interface] ? Plain<One, D> : never);
62
+ type OpName<I> = I extends Interface ? keyof I['ops'] & string : never;
63
+ /** A role's ops: its interface's, or any `Op` when the role is selector data. */
64
+ type OpOf<S> = S extends Interface ? S['ops'][keyof S['ops']] : Op;
56
65
  type Spec<P extends readonly Interface[], D extends Record<string, Selector>> = {
57
66
  provides: [...P];
58
67
  dependencies?: D;
59
68
  config?: SchemaDef;
60
69
  description?: string;
61
- make(ctx: NanoContext<D>, config: any): Made<P> | Promise<Made<P>>;
70
+ calls?: {
71
+ [K in OpName<P[number]>]?: {
72
+ [R in keyof D]?: OpOf<D[R]>[];
73
+ };
74
+ };
75
+ make(ctx: NanoContext<D>, config: any): Made<P, D> | Promise<Made<P, D>>;
62
76
  };
63
77
  declare function define<const P extends readonly Interface[], D extends Record<string, Selector> = {}>(at: string | ImplCoord, spec: Spec<P, D>): Implementation;
64
78
  /** `Implementation.define(coord, spec)`. */
package/index.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  * pods, runtimes and deployments (checked values), the context a pod's factory gets, and the one live `Application`.
4
4
  *
5
5
  * const Key = Schema.define(Type.String(), 'Key')
6
- * const db = Interface.define('acme/db', { get: Op.action(Key, Key) })
6
+ * const db = Interface.define('acme.Db', { get: Op.action(Key, Key) })
7
7
  * AppDeployment.assemble({ pods: {}, runtimes: {} }, Registry.create()) // success({})
8
8
  */
9
- export type { Namespace, InterfaceCoord, ImplCoord, PortCoord, PodCoord } from './coord.js';
9
+ export type { Namespace, InterfaceCoord, ImplCoord, PortCoord, RuntimeCoord, PodCoord } from './coord.js';
10
10
  export * from './schema.js';
11
11
  export * from './op.js';
12
12
  export * from './iface.js';
@@ -17,6 +17,7 @@ export * from './implementation.js';
17
17
  export * from './provider.js';
18
18
  export * from './registry.js';
19
19
  export * from './policy.js';
20
+ export * from './deployment-policy.js';
20
21
  export * from './pod.js';
21
22
  export { Pods, type PodDeployment } from './pods.js';
22
23
  export { Runtime, type RuntimeDeployment, type Subscription } from './runtime.js';