@adhd/apigen-runtime 0.1.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/README.md +45 -0
- package/index.d.ts +19 -0
- package/index.js +31420 -0
- package/index.mjs +384978 -0
- package/lib/api-package.d.ts +4 -0
- package/lib/apigen-runtime.d.ts +1 -0
- package/lib/build-context.d.ts +4 -0
- package/lib/define-middleware.d.ts +5 -0
- package/lib/describe-params.d.ts +18 -0
- package/lib/dispatch.d.ts +11 -0
- package/lib/event-bus.d.ts +8 -0
- package/lib/fn-table.d.ts +16 -0
- package/lib/instance-registry.d.ts +104 -0
- package/lib/invoke.d.ts +112 -0
- package/lib/logger.d.ts +29 -0
- package/lib/stream.d.ts +88 -0
- package/lib/types.d.ts +29 -0
- package/lib/validate-layer.d.ts +54 -0
- package/package.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @adhd/apigen-runtime
|
|
2
|
+
|
|
3
|
+
The apigen **dispatch runtime** — the single canonical call path every plugin and every
|
|
4
|
+
generated server uses to turn an inbound request into a function call. Pure TypeScript,
|
|
5
|
+
**platform: shared**.
|
|
6
|
+
|
|
7
|
+
Part of [apigen](../README.md). For end-to-end usage see [`../cli`](../cli).
|
|
8
|
+
|
|
9
|
+
## Public API
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import {
|
|
13
|
+
dispatch, buildFnTable, describeParams,
|
|
14
|
+
needsEnvelopeField, dataParamNames,
|
|
15
|
+
createLogger, defineMiddleware, createApiPackage,
|
|
16
|
+
EventBus, wireObservers, buildContext,
|
|
17
|
+
} from '@adhd/apigen-runtime'
|
|
18
|
+
import type { Logger, LogFormat, CreateLoggerOptions, ParamInfo, AnyFn } from '@adhd/apigen-runtime'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- **`dispatch(fns, ctx, schema, fnName, envelope, data)`** — the one dispatch path. No plugin
|
|
22
|
+
inlines this; all import it here.
|
|
23
|
+
- **`buildFnTable(mod)`** — normalize an imported module into a callable table, recursively
|
|
24
|
+
unwrapping `default` / CommonJS `module.exports` layers and keying functions by their
|
|
25
|
+
`.name` so default- and CJS-wrapped exports resolve (closes ledger finding F28).
|
|
26
|
+
- **`describeParams(schema)` → `ParamInfo[]`** — extract the parameter list for route/tool
|
|
27
|
+
logging and CLI flag generation.
|
|
28
|
+
- **`needsEnvelopeField` / `dataParamNames`** — envelope + param helpers (single source).
|
|
29
|
+
- **`createLogger({ level, format, destination })`** — pino-based logger; defaults to
|
|
30
|
+
**stderr** so MCP stdio stdout stays protocol-clean. `format: 'json' | 'pretty'`.
|
|
31
|
+
- **`defineMiddleware` / `createApiPackage` / `EventBus` / `wireObservers` / `buildContext`**
|
|
32
|
+
— middleware + observer wiring.
|
|
33
|
+
|
|
34
|
+
## Request envelope
|
|
35
|
+
|
|
36
|
+
Inbound payloads are wrapped: `{ "data": { ...params }, ...envelope }`. `dispatch` validates
|
|
37
|
+
the envelope fields a function requires (e.g. a `session` added by middleware) and passes
|
|
38
|
+
`data` to the function.
|
|
39
|
+
|
|
40
|
+
## Develop
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx nx build apigen-runtime
|
|
44
|
+
npx nx test apigen-runtime
|
|
45
|
+
```
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { createInvoker } from './lib/invoke';
|
|
2
|
+
export type { Layer, LayerResult, Next, Call, LayerContext, InvokeOptions, InvokeFn, } from './lib/invoke';
|
|
3
|
+
export { defineMiddleware } from './lib/define-middleware';
|
|
4
|
+
export { EventBus, wireObservers } from './lib/event-bus';
|
|
5
|
+
export { buildContext } from './lib/build-context';
|
|
6
|
+
export { assertNoSelfSubscription, createApiPackage } from './lib/api-package';
|
|
7
|
+
export type { MiddlewareDef, MiddlewareEvent, ApiPackageOptions, ApiPackageResult, ConfigurationError, GeneratedSchemas, ComposedSchemas, } from './lib/types';
|
|
8
|
+
export { needsEnvelopeField, dataParamNames, dispatch } from './lib/dispatch';
|
|
9
|
+
export { createLogger } from './lib/logger';
|
|
10
|
+
export type { Logger, LogFormat, CreateLoggerOptions } from './lib/logger';
|
|
11
|
+
export { describeParams } from './lib/describe-params';
|
|
12
|
+
export type { ParamInfo } from './lib/describe-params';
|
|
13
|
+
export { buildFnTable } from './lib/fn-table';
|
|
14
|
+
export type { AnyFn } from './lib/fn-table';
|
|
15
|
+
export { validateLayer, makeValidateLayer, ValidateSchemasToken } from './lib/validate-layer';
|
|
16
|
+
export { InstanceRegistry } from './lib/instance-registry';
|
|
17
|
+
export type { InstanceRegistryOptions, CreateResult, AnyConstructor } from './lib/instance-registry';
|
|
18
|
+
export { createStream, drainStream, collectWithPhase, isApiStream } from './lib/stream';
|
|
19
|
+
export type { ApiStream, CreateStreamOptions, CollectResult } from './lib/stream';
|