@pritzlaff/nano-core 0.4.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/op.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Ops: an action (input → output) or an event (data out, its `output`). An op is a signature, unnamed: the interface
3
3
  * names it by key, and its coordinate (hash of name and schemas) is computed there.
4
4
  *
5
- * const api = Interface.define('acme/db', { get: Op.action(Key, Value) }) // api.ops.get.name: 'get'
5
+ * const api = Interface.define('acme.Db', { get: Op.action(Key, Value) }) // api.ops.get.name: 'get'
6
6
  * fits(Op.event(Num), Op.action(Num, Nothing)) // true
7
7
  */
8
8
  import type { TSchema } from 'typebox';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pritzlaff/nano-core",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "The nano model: schemas, ops, interfaces, pods, runtimes, deployments and the one live Application.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/plain.d.ts CHANGED
@@ -9,7 +9,7 @@ import { type Handlers, type Provided } from './implementation.js';
9
9
  import { type Interface } from './iface.js';
10
10
  import type { Op } from './op.js';
11
11
  import { type Fail, type NanoResult } from './result.js';
12
- /** Each action of `i` calls the method of the same name: its value is `success` (nothing is `null`), a throw is `threw`. */
12
+ /** Each action of `i` calls the method of the same name (with the invocation context): its value is `success` (nothing is `null`), a throw is `threw`. */
13
13
  export declare function handlers<I extends Interface>(i: I, obj: object): Handlers<I>;
14
14
  /** What `plain` reads at each use: the client's calls, and its emissions of an op (`on`, or the host's `subscribe`). */
15
15
  type Reached = {
package/pod.d.ts CHANGED
@@ -11,7 +11,7 @@ export type Pod = {
11
11
  config?: unknown;
12
12
  eager: boolean;
13
13
  /** Where it runs; absent means `host`. */
14
- isolation?: 'host' | 'sandbox' | 'isolated-sandbox';
14
+ isolation?: 'host' | 'sandbox' | 'isolated-sandbox' | 'home-origin';
15
15
  };
16
16
  export declare const Pod: {
17
17
  lazy: (impl: Implementation, opts?: {
package/policy.d.ts CHANGED
@@ -15,7 +15,7 @@ export type Verdict = {
15
15
  /** What a policy is asked: a message's envelope. `outside` is true when `from` is not placed in `runtime` (the host, or another runtime's pod). */
16
16
  export type Ask = {
17
17
  runtime: string;
18
- kind: 'call' | 'pipe' | 'on' | 'subscribe' | 'unsubscribe' | 'lifecycle';
18
+ kind: 'call' | 'pipe' | 'on' | 'subscribe' | 'unsubscribe' | 'lifecycle' | 'start';
19
19
  from: string;
20
20
  to: string;
21
21
  port?: string;
@@ -40,14 +40,14 @@ export declare const Rule: Type.TUnion<[Type.TObject<{
40
40
  toInterface: Type.TOptional<Type.TString>;
41
41
  toPort: Type.TOptional<Type.TString>;
42
42
  outside: Type.TOptional<Type.TBoolean>;
43
- allow: Type.TUnion<[Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"*">]>, Type.TArray<Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"*">]>>]>;
43
+ allow: Type.TUnion<[Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"start">, Type.TLiteral<"*">]>, Type.TArray<Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"start">, Type.TLiteral<"*">]>>]>;
44
44
  }>, Type.TObject<{
45
45
  from: Type.TOptional<Type.TString>;
46
46
  toPod: Type.TOptional<Type.TString>;
47
47
  toInterface: Type.TOptional<Type.TString>;
48
48
  toPort: Type.TOptional<Type.TString>;
49
49
  outside: Type.TOptional<Type.TBoolean>;
50
- deny: Type.TUnion<[Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"*">]>, Type.TArray<Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"*">]>>]>;
50
+ deny: Type.TUnion<[Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"start">, Type.TLiteral<"*">]>, Type.TArray<Type.TUnion<[Type.TLiteral<"call">, Type.TLiteral<"pipe">, Type.TLiteral<"on">, Type.TLiteral<"subscribe">, Type.TLiteral<"unsubscribe">, Type.TLiteral<"lifecycle">, Type.TLiteral<"start">, Type.TLiteral<"*">]>>]>;
51
51
  }>]>;
52
52
  export type Rule = Static<typeof Rule>;
53
53
  /**
package/provider.d.ts CHANGED
@@ -37,18 +37,21 @@ declare function namespace(name: string): Readonly<{
37
37
  /** Layer 1's `Coord`, its `namespace` also building interfaces and providers. */
38
38
  export declare const Coord: {
39
39
  port: (i: import("./coord.js").InterfaceCoord, op: string) => import("./coord.js").PortCoord;
40
- pod: (implementation: import("./coord.js").ImplCoord, runtime: string, name: string) => import("./coord.js").PodCoord;
40
+ runtime: (id: string) => import("./coord.js").RuntimeCoord;
41
+ pod: (implementation: import("./coord.js").ImplCoord, runtime: import("./coord.js").RuntimeCoord, name: string) => import("./coord.js").PodCoord;
41
42
  parse: <K extends keyof {
42
43
  namespace: Namespace;
43
44
  interface: import("./coord.js").InterfaceCoord;
44
45
  implementation: import("./coord.js").ImplCoord;
45
46
  port: import("./coord.js").PortCoord;
47
+ runtime: import("./coord.js").RuntimeCoord;
46
48
  pod: import("./coord.js").PodCoord;
47
49
  }>(kind: K, s: string) => {
48
50
  namespace: Namespace;
49
51
  interface: import("./coord.js").InterfaceCoord;
50
52
  implementation: import("./coord.js").ImplCoord;
51
53
  port: import("./coord.js").PortCoord;
54
+ runtime: import("./coord.js").RuntimeCoord;
52
55
  pod: import("./coord.js").PodCoord;
53
56
  }[K];
54
57
  namespace: typeof namespace;
package/registry.d.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * const r = Registry.create()
5
5
  * r.add(mem) // NanoResult<void>; fails `invalid-input` on a clash
6
- * r.implementationsOf('acme/db') // [memDb]
6
+ * r.implementationsOf('acme.Db') // [memDb]
7
7
  */
8
8
  import type { Interface } from './iface.js';
9
9
  import type { Implementation } from './implementation.js';
@@ -16,10 +16,13 @@ export type Manifest = {
16
16
  coord: string;
17
17
  implementations: string[];
18
18
  }[];
19
+ /** Each dependency's selector written out: every coordinate as its string. */
19
20
  implementations: {
20
21
  coord: string;
21
22
  provides: string[];
22
- dependencies: Record<string, SelectorData>;
23
+ dependencies: Record<string, {
24
+ [K in keyof SelectorData]: K extends 'tags' ? string[] : string;
25
+ }>;
23
26
  }[];
24
27
  interfaces: {
25
28
  coord: string;
@@ -42,8 +45,19 @@ export type Registry = {
42
45
  op(coord: string): Op | undefined;
43
46
  };
44
47
  declare function create(): Registry;
45
- /** `Registry.create()`. */
48
+ /**
49
+ * `Registry.load(modules, base)`: import each module (a URL relative to `base`), add its default `Provider` to a new
50
+ * registry, and return each module's namespace under its key. The first failure is the result, never a throw:
51
+ * `not-found` (the import failed), `invalid-input` (no default Provider, or the registry refused it).
52
+ * The modules are code that will run: load only trusted ones.
53
+ */
54
+ declare function load(modules: Record<string, string>, base: string | URL): Promise<NanoResult<{
55
+ registry: Registry;
56
+ exports: Record<string, Record<string, unknown>>;
57
+ }>>;
58
+ /** `Registry.create()`; `Registry.load(modules, base)`. */
46
59
  export declare const Registry: {
47
60
  create: typeof create;
61
+ load: typeof load;
48
62
  };
49
63
  export {};
package/runtime.d.ts CHANGED
@@ -7,6 +7,10 @@ export type Subscription = {
7
7
  kind: 'call';
8
8
  from: string;
9
9
  to: string;
10
+ ops?: {
11
+ source: string;
12
+ target: string;
13
+ }[];
10
14
  } | {
11
15
  kind: 'pipe';
12
16
  from: string;
package/selector.d.ts CHANGED
@@ -2,17 +2,20 @@
2
2
  * Selectors: which call subscriptions a call may use — an interface, or data narrowing by tags, implementation,
3
3
  * provider, or the runtime the subscription is in.
4
4
  *
5
- * selectorData(DB) // { implements: 'acme/db' }
6
- * matches({ implements: 'acme/db', tags: ['primary'] }, target)
7
- * Selector.of(DB, { runtime: 'v2' }) // still DB (typed clients survive), plus implements and runtime
5
+ * selectorData(DB) // its `implements` is DB's InterfaceCoord, acme.DB
6
+ * matches({ implements: acme.interfaceId('DB'), tags: ['primary'] }, target)
7
+ * Selector.of(DB, { runtime: Coord.runtime('v2') }) // still DB (typed clients survive), plus implements and runtime
8
+ *
9
+ * The fields are coordinates; written out (JSON, the registry manifest) each is its string.
8
10
  */
11
+ import { type ImplCoord, type InterfaceCoord, type Namespace, type RuntimeCoord } from './coord.js';
9
12
  import type { Interface } from './iface.js';
10
13
  export type SelectorData = {
11
- implements?: string;
14
+ implements?: InterfaceCoord;
12
15
  tags?: string[];
13
- implementation?: string;
14
- provider?: string;
15
- runtime?: string;
16
+ implementation?: ImplCoord;
17
+ provider?: Namespace;
18
+ runtime?: RuntimeCoord;
16
19
  };
17
20
  export type Selector = Interface | SelectorData;
18
21
  /** A pod as reached over one call subscription: its name, the runtime of that subscription, and what it is. */