@arki/dot 0.1.0 → 0.1.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.
- package/README.md +36 -31
- package/dist/define-app.d.ts +58 -16
- package/dist/define-app.d.ts.map +1 -1
- package/dist/define-app.js +23 -13
- package/dist/define-app.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/kernel/app-instance.d.ts +3 -3
- package/dist/kernel/app-instance.d.ts.map +1 -1
- package/dist/kernel/app-instance.js +265 -159
- package/dist/kernel/app-instance.js.map +1 -1
- package/dist/lifecycle.d.ts +11 -9
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +15 -9
- package/dist/lifecycle.js.map +1 -1
- package/dist/pip-contract.d.ts +254 -149
- package/dist/pip-contract.d.ts.map +1 -1
- package/dist/pip-contract.js +185 -41
- package/dist/pip-contract.js.map +1 -1
- package/dist/pip.d.ts +9 -12
- package/dist/pip.d.ts.map +1 -1
- package/dist/pip.js +8 -11
- package/dist/pip.js.map +1 -1
- package/dist/test-harness.d.ts +13 -10
- package/dist/test-harness.d.ts.map +1 -1
- package/dist/test-harness.js +12 -12
- package/dist/test-harness.js.map +1 -1
- package/package.json +1 -1
- package/templates/app-minimal/AGENTS.md.tmpl +2 -2
package/dist/pip-contract.d.ts
CHANGED
|
@@ -1,63 +1,192 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public pip contract for the DOT kernel.
|
|
2
|
+
* Public pip contract for the DOT kernel (v2).
|
|
3
3
|
*
|
|
4
|
-
* A
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A pip declares what it **needs** as a shape of type witnesses and
|
|
5
|
+
* publishes what it **provides** from its `boot` hook. The kernel wires
|
|
6
|
+
* services by key, injects them into hook contexts under the pip's local
|
|
7
|
+
* aliases, and fails loudly (coded errors) on unsatisfied needs or key
|
|
8
|
+
* collisions.
|
|
7
9
|
*
|
|
8
10
|
* Design constraints:
|
|
9
11
|
*
|
|
10
|
-
* - `configure` is SYNC. Returning a Promise is an error — the kernel
|
|
11
|
-
*
|
|
12
|
-
* -
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import type {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/** Services this pip publishes. */
|
|
27
|
-
services?: readonly {
|
|
28
|
-
name: string;
|
|
29
|
-
kind: ServiceKind;
|
|
30
|
-
}[];
|
|
31
|
-
/** Routes this pip exposes. */
|
|
32
|
-
routes?: readonly {
|
|
33
|
-
id: string;
|
|
34
|
-
method?: string;
|
|
35
|
-
path?: string;
|
|
36
|
-
transport: RouteTransport;
|
|
37
|
-
}[];
|
|
38
|
-
/** Additional `provides` capability strings (joined with the pip's `provides`). */
|
|
39
|
-
provides?: readonly string[];
|
|
40
|
-
/** Additional dependency edges. */
|
|
41
|
-
dependencies?: readonly {
|
|
42
|
-
to: string;
|
|
43
|
-
kind?: DependencyEdgeKind;
|
|
44
|
-
}[];
|
|
12
|
+
* - `configure` is SYNC. Returning a Promise is an error — the kernel
|
|
13
|
+
* throws {@link DotLifecycleError} with code `DOT_LIFECYCLE_E001`.
|
|
14
|
+
* - Declaration order IS boot order. The app builder's type-level guard
|
|
15
|
+
* makes out-of-order composition a compile error; the kernel re-validates
|
|
16
|
+
* at runtime for erased/dynamic composition.
|
|
17
|
+
* - `stop` and `dispose` run in reverse declaration order and continue
|
|
18
|
+
* through individual pip failures, reporting an aggregate error.
|
|
19
|
+
*/
|
|
20
|
+
import type { RouteTransport, ServiceKind } from './manifest.js';
|
|
21
|
+
declare const TypeOf: unique symbol;
|
|
22
|
+
/**
|
|
23
|
+
* Phantom type witness for a service. Carries `T` at the type level only —
|
|
24
|
+
* the runtime value is an empty object.
|
|
25
|
+
*/
|
|
26
|
+
export type Service<T> = {
|
|
27
|
+
readonly [TypeOf]?: T;
|
|
45
28
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
29
|
+
declare const LazyInner: unique symbol;
|
|
30
|
+
/**
|
|
31
|
+
* A lazy-lifting witness (create via {@link service.lazy}). The consumer
|
|
32
|
+
* always receives a `Lazy<T>` handle, regardless of whether the provider
|
|
33
|
+
* published a plain `T` (the kernel lifts it into a pre-initialized
|
|
34
|
+
* handle) or a `Lazy<T>` (passed through). This decouples consumers from
|
|
35
|
+
* the provider's eager-vs-lazy strategy.
|
|
36
|
+
*
|
|
37
|
+
* The phantom `Service<T | Lazy<T>>` base is what the wiring guard checks
|
|
38
|
+
* against — either provider shape satisfies it structurally.
|
|
39
|
+
*/
|
|
40
|
+
export type LazyService<T> = Service<T | Lazy<T>> & {
|
|
41
|
+
readonly lazy: true;
|
|
42
|
+
readonly [LazyInner]?: T;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Create an app-local (anonymous) service witness for a `needs` shape.
|
|
46
|
+
*
|
|
47
|
+
* `service.lazy<T>()` creates a lifting witness instead — the hook context
|
|
48
|
+
* delivers a `Lazy<T>` handle whether the provider is eager or lazy.
|
|
49
|
+
*/
|
|
50
|
+
export declare const service: (<T>() => Service<T>) & {
|
|
51
|
+
readonly lazy: <T>() => LazyService<T>;
|
|
52
|
+
};
|
|
53
|
+
/** Internal (kernel) check: is this witness a lazy-lifting one? */
|
|
54
|
+
export declare function isLazyWitness(witness: object): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Shared, named witness — a cross-package service contract. The `key` is
|
|
57
|
+
* the wire name used for satisfaction checks and runtime lookup; the local
|
|
58
|
+
* property name in a `needs` shape becomes a free-choice alias.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* // packages/db owns the contract:
|
|
63
|
+
* export const Db = token<NodePgDatabase<Schema>>()('arki.db');
|
|
64
|
+
*
|
|
65
|
+
* // any consumer, any local alias:
|
|
66
|
+
* const reports = pip({
|
|
67
|
+
* name: 'reports',
|
|
68
|
+
* needs: { db: Db },
|
|
69
|
+
* async boot({ db }) { ... },
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export type Token<T, K extends string = string> = Service<T> & {
|
|
74
|
+
readonly key: K;
|
|
75
|
+
/** Derive a token for an additional instance of the same contract. */
|
|
76
|
+
instance<N extends string>(name: N): Token<T, `${K}#${N}`>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Create a token. Curried so `T` is explicit while `K` is inferred as a
|
|
80
|
+
* literal: `const Db = token<DbHandle>()('arki.db')`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function token<T>(): <K extends string>(key: K) => Token<T, K>;
|
|
83
|
+
/**
|
|
84
|
+
* Publish a value under a token's wire key. Returns a record typed by the
|
|
85
|
+
* token's literal key, so `boot: () => provide(Db, handle)` infers
|
|
86
|
+
* `TProvides = { 'arki.db': DbHandle }`.
|
|
87
|
+
*/
|
|
88
|
+
export declare function provide<T, K extends string>(tok: Token<T, K>, value: T): {
|
|
89
|
+
[P in K]: T;
|
|
51
90
|
};
|
|
52
|
-
/**
|
|
91
|
+
/** Record of wire-keyed services. */
|
|
92
|
+
export type ServiceRecord = Record<string, unknown>;
|
|
93
|
+
/** Runtime brand for lazy service handles (kernel detects these for auto-dispose). */
|
|
94
|
+
export declare const LazyTag: unique symbol;
|
|
95
|
+
/**
|
|
96
|
+
* A lazily-initialized service handle. Publish one from `boot` to defer an
|
|
97
|
+
* expensive open until first use:
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* boot: () => ({ db: lazy(() => openDb(), { dispose: db => db.close() }) })
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* Laziness is visible in the type — consumers declare
|
|
104
|
+
* `needs: { db: service<Lazy<Db>>() }` and call `await db.get()`. The
|
|
105
|
+
* kernel auto-disposes initialized handles in reverse declaration order
|
|
106
|
+
* during `dispose` (and boot rollback), even when the publishing pip has
|
|
107
|
+
* no `dispose` hook. A handle that was never `get()`ed never initializes
|
|
108
|
+
* and never runs cleanup.
|
|
109
|
+
*/
|
|
110
|
+
export type Lazy<T> = {
|
|
111
|
+
readonly [LazyTag]: true;
|
|
112
|
+
/**
|
|
113
|
+
* Initialize (once) and return the value. Concurrent callers share one
|
|
114
|
+
* attempt. A failed attempt is NOT cached — the next call retries.
|
|
115
|
+
* Throws if the handle has been disposed.
|
|
116
|
+
*/
|
|
117
|
+
get(): Promise<T>;
|
|
118
|
+
/** True once an initialization attempt has succeeded. */
|
|
119
|
+
readonly initialized: boolean;
|
|
120
|
+
/** The value if initialized, else `undefined`. Never triggers initialization. */
|
|
121
|
+
peek(): T | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Run cleanup if initialized (awaits an in-flight initialization first).
|
|
124
|
+
* Idempotent. Called automatically by the kernel for published handles.
|
|
125
|
+
*/
|
|
126
|
+
dispose(): Promise<void>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Create a lazy service handle. See {@link Lazy} for semantics.
|
|
130
|
+
*
|
|
131
|
+
* @param init - Opens the resource. Runs at most once concurrently; a
|
|
132
|
+
* rejected attempt is not cached, so a later `get()` retries.
|
|
133
|
+
* @param options.dispose - Cleanup for the initialized value. Skipped when
|
|
134
|
+
* the handle was never initialized.
|
|
135
|
+
*/
|
|
136
|
+
export declare function lazy<T>(init: () => Promise<T> | T, options?: {
|
|
137
|
+
readonly dispose?: (value: T) => Promise<void> | void;
|
|
138
|
+
}): Lazy<T>;
|
|
139
|
+
/** Type guard: is this published value a lazy service handle? */
|
|
140
|
+
export declare function isLazy(value: unknown): value is Lazy<unknown>;
|
|
141
|
+
/**
|
|
142
|
+
* Wrap an already-available value in a pre-initialized `Lazy<T>` handle.
|
|
143
|
+
* Used by the kernel to lift eager provides for `service.lazy` consumers;
|
|
144
|
+
* also handy for handing fakes to lazy-consuming pips in tests. The handle
|
|
145
|
+
* has no cleanup of its own — the underlying value's lifecycle belongs to
|
|
146
|
+
* whoever created it.
|
|
147
|
+
*/
|
|
148
|
+
export declare function lazyOf<T>(value: T): Lazy<T>;
|
|
149
|
+
/** A `needs` declaration: local alias → witness (anonymous or token). */
|
|
150
|
+
export type NeedsShape = Record<string, Service<unknown>>;
|
|
151
|
+
export type EmptyShape = {};
|
|
152
|
+
/**
|
|
153
|
+
* Local-alias view of a needs shape — what lifecycle hooks destructure.
|
|
154
|
+
* `{ cache: Token<KV, 'arki.kv'> }` → `{ cache: KV }`.
|
|
155
|
+
* `{ search: service.lazy<S>() }` → `{ search: Lazy<S> }`.
|
|
156
|
+
*/
|
|
157
|
+
export type CtxOf<S extends NeedsShape> = {
|
|
158
|
+
[K in keyof S]: S[K] extends LazyService<infer T> ? Lazy<T> : S[K] extends Service<infer T> ? T : never;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Wire-key view of a needs shape — what the app builder checks
|
|
162
|
+
* satisfaction against. Tokens contribute their owned key; anonymous
|
|
163
|
+
* witnesses contribute the property name.
|
|
164
|
+
* `{ cache: Token<KV, 'arki.kv'> }` → `{ 'arki.kv': KV }`.
|
|
165
|
+
*/
|
|
166
|
+
export type WireNeeds<S extends NeedsShape> = {
|
|
167
|
+
[K in keyof S as S[K] extends Token<unknown, infer WK> ? WK : K]: S[K] extends Service<infer T> ? T : never;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Kernel-supplied context keys, present in every service-carrying hook
|
|
171
|
+
* context. `$`-prefixed so they can never collide with service aliases.
|
|
172
|
+
*/
|
|
173
|
+
export type KernelCtx = {
|
|
174
|
+
/** App name (passed to `defineApp`). */
|
|
175
|
+
readonly $app: string;
|
|
176
|
+
/** This pip's name. */
|
|
177
|
+
readonly $pip: string;
|
|
178
|
+
/** Read-only runtime config bag from `defineApp(name, { config })`. */
|
|
179
|
+
readonly $config: Readonly<Record<string, unknown>>;
|
|
180
|
+
};
|
|
181
|
+
/** Context provided to a `configure` hook (sync registration only). */
|
|
53
182
|
export type DotConfigureContext = {
|
|
54
183
|
pipName: string;
|
|
55
184
|
/** App name. */
|
|
56
185
|
appName: string;
|
|
57
186
|
/**
|
|
58
|
-
* Register a service this pip publishes
|
|
59
|
-
* Registration is metadata-only — the actual service instance
|
|
60
|
-
* from the `boot` hook
|
|
187
|
+
* Register a service this pip publishes, for manifest/diagnostics
|
|
188
|
+
* purposes. Registration is metadata-only — the actual service instance
|
|
189
|
+
* is returned from the `boot` hook.
|
|
61
190
|
*/
|
|
62
191
|
registerService(name: string, kind: ServiceKind): void;
|
|
63
192
|
/** Register a route this pip exposes. */
|
|
@@ -68,108 +197,98 @@ export type DotConfigureContext = {
|
|
|
68
197
|
transport: RouteTransport;
|
|
69
198
|
}): void;
|
|
70
199
|
/** Mark the pip as participating in a lifecycle hook. */
|
|
71
|
-
registerLifecycleHook(hook:
|
|
72
|
-
/** Append `provides` capability strings. */
|
|
200
|
+
registerLifecycleHook(hook: 'configure' | 'boot' | 'start' | 'stop' | 'dispose'): void;
|
|
201
|
+
/** Append `provides` capability strings (informational, manifest-only). */
|
|
73
202
|
declareProvides(...capabilities: string[]): void;
|
|
74
|
-
/** Append an extra dependency edge (alongside `pip.dependencies`). */
|
|
75
|
-
declareDependency(to: string, kind?: DependencyEdgeKind): void;
|
|
76
|
-
};
|
|
77
|
-
/** Context provided to a `boot` hook. */
|
|
78
|
-
export type DotBootContext = {
|
|
79
|
-
pipName: string;
|
|
80
|
-
appName: string;
|
|
81
|
-
/**
|
|
82
|
-
* Services published by prior-booted pips, keyed by service name.
|
|
83
|
-
* Use this for dependency injection between pips.
|
|
84
|
-
*/
|
|
85
|
-
services: ReadonlyMap<string, unknown>;
|
|
86
|
-
/** Read-only configuration bag. */
|
|
87
|
-
config: Readonly<Record<string, unknown>>;
|
|
88
|
-
};
|
|
89
|
-
/** Context provided to a `start` hook. */
|
|
90
|
-
export type DotStartContext<TServices extends Record<string, unknown>> = {
|
|
91
|
-
pipName: string;
|
|
92
|
-
appName: string;
|
|
93
|
-
services: TServices;
|
|
94
|
-
};
|
|
95
|
-
/** Context provided to a `stop` hook. */
|
|
96
|
-
export type DotStopContext<TServices extends Record<string, unknown>> = {
|
|
97
|
-
pipName: string;
|
|
98
|
-
appName: string;
|
|
99
|
-
services: TServices;
|
|
100
|
-
};
|
|
101
|
-
/** Context provided to a `dispose` hook. */
|
|
102
|
-
export type DotDisposeContext<TServices extends Record<string, unknown>> = {
|
|
103
|
-
pipName: string;
|
|
104
|
-
appName: string;
|
|
105
|
-
services: TServices;
|
|
106
|
-
};
|
|
107
|
-
/** Return value of a `boot` hook. */
|
|
108
|
-
export type DotBootResult<TServices extends Record<string, unknown>> = {
|
|
109
|
-
/** Services this pip publishes — added to `app.services` and visible to dependent pips. */
|
|
110
|
-
services?: TServices;
|
|
111
203
|
};
|
|
204
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
205
|
+
declare const NeedsSym: unique symbol;
|
|
206
|
+
declare const ProvidesSym: unique symbol;
|
|
112
207
|
/**
|
|
113
|
-
* The DOT pip
|
|
208
|
+
* The DOT pip (v2). Author through {@link pip} — never construct directly.
|
|
114
209
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
210
|
+
* Hook signatures are type-erased here (`ctx: never`): the typed view
|
|
211
|
+
* lives on `pip()`'s parameter, and `(ctx: Typed) => R` is assignable to
|
|
212
|
+
* `(ctx: never) => R` without casts (parameter contravariance from the
|
|
213
|
+
* bottom type). The kernel crosses the erasure boundary at the call site.
|
|
214
|
+
*
|
|
215
|
+
* The phantom symbol properties carry `TNeeds` / `TProvides` for the app
|
|
216
|
+
* builder's compile-time wiring check; they never exist at runtime.
|
|
118
217
|
*/
|
|
119
|
-
export type
|
|
218
|
+
export type Pip<TNeeds extends ServiceRecord = ServiceRecord, TProvides extends ServiceRecord = ServiceRecord> = {
|
|
120
219
|
/** Unique identifier for this pip within the app. */
|
|
121
|
-
name: string;
|
|
220
|
+
readonly name: string;
|
|
122
221
|
/** Optional semantic version string. */
|
|
123
|
-
version?: string;
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* SYNC registration hook. Declare metadata, register routes/services/jobs.
|
|
139
|
-
* MUST NOT perform IO, MUST NOT return a Promise.
|
|
140
|
-
*/
|
|
141
|
-
configure?: (ctx: DotConfigureContext) => void;
|
|
142
|
-
/** Async open-resources hook. Returns published services for DI. */
|
|
143
|
-
boot?: (ctx: DotBootContext) => Promise<DotBootResult<TServices>> | DotBootResult<TServices>;
|
|
144
|
-
/** Async begin-active-work hook. Runs after every pip's `boot` succeeds. */
|
|
145
|
-
start?: (ctx: DotStartContext<TServices>) => Promise<void> | void;
|
|
146
|
-
/** Async halt-active-work hook. Runs in reverse-topological order. */
|
|
147
|
-
stop?: (ctx: DotStopContext<TServices>) => Promise<void> | void;
|
|
148
|
-
/** Async release-resources hook. Runs in reverse-topological order. */
|
|
149
|
-
dispose?: (ctx: DotDisposeContext<TServices>) => Promise<void> | void;
|
|
222
|
+
readonly version?: string;
|
|
223
|
+
/** Runtime needs shape (local alias → witness). */
|
|
224
|
+
readonly needs: NeedsShape;
|
|
225
|
+
/** Mount-time renames: publish key → new wire key (see {@link rename}). */
|
|
226
|
+
readonly renames: Readonly<Record<string, string>>;
|
|
227
|
+
readonly hooks: {
|
|
228
|
+
readonly configure?: (ctx: DotConfigureContext) => void;
|
|
229
|
+
readonly boot?: (ctx: never) => MaybePromise<ServiceRecord | void>;
|
|
230
|
+
readonly start?: (ctx: never) => MaybePromise<void>;
|
|
231
|
+
readonly stop?: (ctx: never) => MaybePromise<void>;
|
|
232
|
+
readonly dispose?: (ctx: never) => MaybePromise<void>;
|
|
233
|
+
};
|
|
234
|
+
readonly [NeedsSym]?: TNeeds;
|
|
235
|
+
readonly [ProvidesSym]?: TProvides;
|
|
150
236
|
};
|
|
237
|
+
/** Extract a pip's (wire-keyed) needs record. */
|
|
238
|
+
export type PipNeeds<P> = P extends Pip<infer N, ServiceRecord> ? N : never;
|
|
239
|
+
/** Extract a pip's (wire-keyed) provides record. */
|
|
240
|
+
export type PipProvides<P> = P extends Pip<ServiceRecord, infer Pr> ? Pr : never;
|
|
241
|
+
/** Internal type alias used by the kernel to erase pip service generics. */
|
|
242
|
+
export type AnyPip = Pip<ServiceRecord, ServiceRecord>;
|
|
151
243
|
/**
|
|
152
|
-
*
|
|
244
|
+
* Author a DOT pip.
|
|
245
|
+
*
|
|
246
|
+
* - `TShape` is inferred from the `needs` object literal.
|
|
247
|
+
* - `TProvides` is inferred from `boot`'s return type — no generic argument.
|
|
248
|
+
* - `boot({ db, log, $app })` destructures typed services under the local
|
|
249
|
+
* aliases declared in `needs`, plus the `$`-prefixed kernel keys.
|
|
250
|
+
* - `start` / `stop` / `dispose` additionally receive the pip's own
|
|
251
|
+
* provides. Reverse-order teardown guarantees needs are still alive in
|
|
252
|
+
* `dispose`.
|
|
153
253
|
*
|
|
154
254
|
* @example
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
255
|
+
* ```ts
|
|
256
|
+
* export const billing = pip({
|
|
257
|
+
* name: 'billing',
|
|
258
|
+
* needs: { db: service<Db>(), log: service<Logger>() },
|
|
259
|
+
* async boot({ db, log }) {
|
|
260
|
+
* return { billing: new BillingService(db, log) };
|
|
160
261
|
* },
|
|
161
|
-
* async dispose({
|
|
162
|
-
* await
|
|
262
|
+
* async dispose({ billing }) {
|
|
263
|
+
* await billing.flush();
|
|
163
264
|
* },
|
|
164
265
|
* });
|
|
266
|
+
* ```
|
|
165
267
|
*/
|
|
166
|
-
export declare function
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
268
|
+
export declare function pip<TShape extends NeedsShape = EmptyShape, TProvides extends ServiceRecord = EmptyShape>(def: {
|
|
269
|
+
readonly name: string;
|
|
270
|
+
readonly version?: string;
|
|
271
|
+
readonly needs?: TShape;
|
|
272
|
+
readonly configure?: (ctx: DotConfigureContext) => void;
|
|
273
|
+
readonly boot?: (ctx: CtxOf<TShape> & KernelCtx) => MaybePromise<TProvides | void>;
|
|
274
|
+
readonly start?: (ctx: CtxOf<TShape> & TProvides & KernelCtx) => MaybePromise<void>;
|
|
275
|
+
readonly stop?: (ctx: CtxOf<TShape> & TProvides & KernelCtx) => MaybePromise<void>;
|
|
276
|
+
readonly dispose?: (ctx: CtxOf<TShape> & TProvides & KernelCtx) => MaybePromise<void>;
|
|
277
|
+
}): Pip<WireNeeds<TShape>, TProvides>;
|
|
278
|
+
/** Rename a pip's published wire keys — the multi-instance primitive. */
|
|
279
|
+
export type RenamedProvides<TP, M> = {
|
|
280
|
+
[K in keyof TP as K extends keyof M ? (M[K] extends string ? M[K] : K) : K]: TP[K];
|
|
281
|
+
};
|
|
282
|
+
/**
|
|
283
|
+
* Mount-time rename. `rename(dbPip, { db: 'reportsDb' }, 'reports-db')`
|
|
284
|
+
* publishes the same service under a different wire key, retyped
|
|
285
|
+
* accordingly — the way to mount a second instance of an adapter without
|
|
286
|
+
* a key collision. Renames compose: renaming an already-renamed key
|
|
287
|
+
* rewrites the earlier entry.
|
|
288
|
+
*/
|
|
289
|
+
export declare function rename<TN extends ServiceRecord, TP extends ServiceRecord, const M extends {
|
|
290
|
+
readonly [K in keyof TP]?: string;
|
|
291
|
+
}>(p: Pip<TN, TP>, map: M, newName?: string): Pip<TN, RenamedProvides<TP, M>>;
|
|
173
292
|
/**
|
|
174
293
|
* Stable error thrown by DOT pip adapters.
|
|
175
294
|
*
|
|
@@ -185,20 +304,6 @@ export declare function pipDependencies(pip: AnyDotPip): readonly string[];
|
|
|
185
304
|
*
|
|
186
305
|
* @see packages/dot/docs/principles.md — principle 1.3 ("errors are part
|
|
187
306
|
* of the API") and principle 4 ("agent-discoverable everywhere").
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* import { DotPipError } from '@arki/dot/pip';
|
|
192
|
-
*
|
|
193
|
-
* const KV_PIP_ERROR_CODES = { urlNotConfigured: 'KV_PIP_E001' } as const;
|
|
194
|
-
*
|
|
195
|
-
* throw new DotPipError({
|
|
196
|
-
* code: KV_PIP_ERROR_CODES.urlNotConfigured,
|
|
197
|
-
* message: '[kv] KV URL is not configured.',
|
|
198
|
-
* remediation: 'Pass options.url to kv(...) or set KV_URL in the environment.',
|
|
199
|
-
* docsUrl: 'https://arki.dev/dot/errors/kv-pip-e001',
|
|
200
|
-
* });
|
|
201
|
-
* ```
|
|
202
307
|
*/
|
|
203
308
|
export declare class DotPipError extends Error {
|
|
204
309
|
/** Stable error code, e.g. `KV_PIP_E001`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pip-contract.d.ts","sourceRoot":"","sources":["../src/pip-contract.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pip-contract.d.ts","sourceRoot":"","sources":["../src/pip-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjE,OAAO,CAAC,MAAM,MAAM,EAAE,OAAO,MAAM,CAAC;AAEpC;;;GAGG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEnD,OAAO,CAAC,MAAM,SAAS,EAAE,OAAO,MAAM,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IA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