@arki/dot 0.1.0 → 0.1.2
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 +10 -4
- package/src/cli/discover.ts +223 -0
- package/src/cli/error-codes.ts +74 -0
- package/src/cli/files.ts +120 -0
- package/src/cli/index.ts +539 -0
- package/src/cli/json.ts +49 -0
- package/src/cli/new.ts +420 -0
- package/src/cli/observability-probe.ts +51 -0
- package/src/cli/render-doctor.ts +199 -0
- package/src/cli/render-explain.ts +161 -0
- package/src/define-app.ts +310 -0
- package/src/diagnostics.ts +91 -0
- package/src/index.ts +89 -0
- package/src/kernel/app-instance.ts +1341 -0
- package/src/kernel/otel.ts +265 -0
- package/src/lifecycle-observer.ts +100 -0
- package/src/lifecycle.ts +121 -0
- package/src/manifest.ts +94 -0
- package/src/pip-contract.ts +477 -0
- package/src/pip.ts +84 -0
- package/src/test-harness.ts +72 -0
- package/src/timeline.ts +137 -0
- package/templates/app-minimal/AGENTS.md.tmpl +2 -2
package/README.md
CHANGED
|
@@ -59,35 +59,34 @@ bun add @arki/dot
|
|
|
59
59
|
## Quick start
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
|
-
import { defineApp,
|
|
62
|
+
import { defineApp, pip, service } from '@arki/dot';
|
|
63
63
|
|
|
64
|
-
const billingPip =
|
|
64
|
+
const billingPip = pip({
|
|
65
65
|
name: 'billing',
|
|
66
66
|
version: '1.0.0',
|
|
67
|
+
needs: { db: service<Db>() }, // typed injection — destructure in hooks
|
|
67
68
|
configure(ctx) {
|
|
68
69
|
// Validate config, register schemas, no I/O.
|
|
69
70
|
},
|
|
70
|
-
async boot(
|
|
71
|
-
// Open connections
|
|
72
|
-
return { stripe: makeStripeClient() };
|
|
71
|
+
async boot({ db }) {
|
|
72
|
+
// Open connections. The return value IS what this pip provides.
|
|
73
|
+
return { stripe: makeStripeClient(db) };
|
|
73
74
|
},
|
|
74
|
-
async start(
|
|
75
|
+
async start({ stripe }) {
|
|
75
76
|
// Begin processing — workers, subscriptions, schedulers.
|
|
76
77
|
},
|
|
77
|
-
async stop() {
|
|
78
|
+
async stop({ stripe }) {
|
|
78
79
|
// Stop processing — drain workers, unsubscribe.
|
|
79
80
|
},
|
|
80
|
-
async dispose() {
|
|
81
|
+
async dispose({ stripe }) {
|
|
81
82
|
// Close connections, free resources.
|
|
82
83
|
},
|
|
83
84
|
});
|
|
84
85
|
|
|
85
|
-
const app = defineApp('acme')
|
|
86
|
-
.use(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
await app.boot();
|
|
90
|
-
await app.start();
|
|
86
|
+
const app = await defineApp('acme')
|
|
87
|
+
.use(dbPip) // providers before consumers — enforced at compile time
|
|
88
|
+
.use(billingPip)
|
|
89
|
+
.start();
|
|
91
90
|
|
|
92
91
|
// app.manifest, app.diagnostics — agent-friendly envelopes.
|
|
93
92
|
|
|
@@ -97,20 +96,26 @@ await app.dispose();
|
|
|
97
96
|
|
|
98
97
|
## Pip authoring
|
|
99
98
|
|
|
100
|
-
`
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
| `
|
|
109
|
-
| `
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
`pip(config)` accepts a `needs` shape plus five lifecycle hooks. Hook
|
|
100
|
+
contexts carry the needed services (typed, under your local aliases) and
|
|
101
|
+
`$`-prefixed kernel keys (`$app`, `$pip`, `$config`):
|
|
102
|
+
|
|
103
|
+
| Hook | Purpose |
|
|
104
|
+
| ----------- | ------------------------------------------------------------------- |
|
|
105
|
+
| `configure` | Validate static config; declare schemas, routes, services. No I/O. |
|
|
106
|
+
| `boot` | Open connections; the returned record is what the pip provides. |
|
|
107
|
+
| `start` | Begin processing (workers, subscribers, schedulers). |
|
|
108
|
+
| `stop` | Stop processing in reverse declaration order. |
|
|
109
|
+
| `dispose` | Free resources after `stop`. |
|
|
110
|
+
|
|
111
|
+
Wiring is compile-time checked: `.use(pip)` fails to typecheck when the
|
|
112
|
+
pip's needs aren't satisfied by earlier `.use()` calls, or when its
|
|
113
|
+
provides collide with an existing wire key. `rename(pip, { db: 'reportsDb' })`
|
|
114
|
+
mounts a second instance of an adapter without collision; `token<T>()('key')`
|
|
115
|
+
shares a service contract across packages; `lazy(() => open(), { dispose })`
|
|
116
|
+
defers an expensive open until first `get()` — never-touched services never
|
|
117
|
+
initialize, and the kernel auto-disposes initialized ones. Declaration
|
|
118
|
+
order is boot order — same input, same order, every time.
|
|
114
119
|
|
|
115
120
|
## Lifecycle
|
|
116
121
|
|
|
@@ -124,9 +129,9 @@ defined ──configure()──▶ configured ──boot()──▶ booted ─
|
|
|
124
129
|
```
|
|
125
130
|
|
|
126
131
|
`boot()` runs `configure()` implicitly if you skipped it. `start()` runs
|
|
127
|
-
`boot()` implicitly. `stop()` and `dispose()` always run in reverse
|
|
128
|
-
order, even when an earlier hook failed — failure isolation is
|
|
129
|
-
contract.
|
|
132
|
+
`boot()` implicitly. `stop()` and `dispose()` always run in reverse
|
|
133
|
+
declaration order, even when an earlier hook failed — failure isolation is
|
|
134
|
+
part of the contract.
|
|
130
135
|
|
|
131
136
|
## CLI
|
|
132
137
|
|
package/dist/define-app.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public entry point for the
|
|
2
|
+
* Public entry point for the DOT kernel (v2).
|
|
3
3
|
*
|
|
4
4
|
* `defineApp(name)` returns a `DotAppBuilder` that accumulates pips via
|
|
5
5
|
* `.use(pip)`, then transitions through the 5-hook lifecycle:
|
|
6
6
|
*
|
|
7
7
|
* defineApp -> use* -> configure() -> boot() -> start() -> stop() -> dispose()
|
|
8
8
|
*
|
|
9
|
+
* `.use()` is compile-time guarded: a pip whose `needs` are not satisfied
|
|
10
|
+
* by services provided so far — or whose provides collide with existing
|
|
11
|
+
* wire keys — fails to typecheck at the call site ("Expected 2 arguments,
|
|
12
|
+
* but got 1", with the diagnostic embedded in the expected second
|
|
13
|
+
* argument's type). Declaration order IS boot order.
|
|
14
|
+
*
|
|
9
15
|
* Most callers don't need to call `configure()` explicitly — `boot()` runs it
|
|
10
16
|
* implicitly. `boot()` is also implicit when starting from `defined` via
|
|
11
17
|
* `start()`.
|
|
@@ -16,18 +22,49 @@ import type { DotDiagnosticsSnapshot } from './diagnostics.js';
|
|
|
16
22
|
import type { DotLifecycleObserver } from './lifecycle-observer.js';
|
|
17
23
|
import type { DotLifecycleState } from './lifecycle.js';
|
|
18
24
|
import type { DotAppManifest } from './manifest.js';
|
|
19
|
-
import type {
|
|
25
|
+
import type { EmptyShape, Pip, ServiceRecord } from './pip-contract.js';
|
|
26
|
+
type MissingKeys<TAvail, TNeeds> = {
|
|
27
|
+
readonly [K in Exclude<keyof TNeeds, keyof TAvail>]: TNeeds[K];
|
|
28
|
+
};
|
|
29
|
+
type MismatchedKeys<TAvail, TNeeds> = {
|
|
30
|
+
readonly [K in keyof TAvail & keyof TNeeds as TAvail[K] extends TNeeds[K] ? never : K]: {
|
|
31
|
+
readonly provided: TAvail[K];
|
|
32
|
+
readonly needed: TNeeds[K];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
type NeedsError<TAvail extends ServiceRecord, TNeeds extends ServiceRecord> = {
|
|
36
|
+
readonly 'DOT: pip needs services no earlier .use() provides': {
|
|
37
|
+
readonly missing: MissingKeys<TAvail, TNeeds>;
|
|
38
|
+
readonly mismatched: MismatchedKeys<TAvail, TNeeds>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
type CollisionError<TAvail, TProvides> = {
|
|
42
|
+
readonly 'DOT: pip provides wire keys already provided (use rename())': keyof TAvail & keyof TProvides;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* A pip whose `boot` always throws infers `TProvides = never`, which would
|
|
46
|
+
* poison both the collision check (`keyof never` matches everything) and
|
|
47
|
+
* the accumulated record (`TAvail & never` = `never`). Such a pip provides
|
|
48
|
+
* nothing — normalize to the empty shape.
|
|
49
|
+
*/
|
|
50
|
+
type NormalizeProvides<TP extends ServiceRecord> = [TP] extends [never] ? EmptyShape : TP;
|
|
51
|
+
/**
|
|
52
|
+
* Rest-tuple guard. Satisfied → `[]` (call `.use(pip)` with one argument).
|
|
53
|
+
* Violated → a required second argument of an unconstructible error type,
|
|
54
|
+
* so the call site fails with the diagnostic embedded in the expected type.
|
|
55
|
+
*/
|
|
56
|
+
export type UseGuard<TAvail extends ServiceRecord, TNeeds extends ServiceRecord, TProvides extends ServiceRecord> = [TAvail] extends [TNeeds] ? [keyof TAvail & keyof TProvides] extends [never] ? [] : [error: CollisionError<TAvail, TProvides>] : [error: NeedsError<TAvail, TNeeds>];
|
|
20
57
|
/**
|
|
21
58
|
* Public DotApp surface. The internal `DotAppImpl` implements this; consumers
|
|
22
59
|
* see only these members.
|
|
23
60
|
*/
|
|
24
|
-
export type DotApp<TServices extends
|
|
61
|
+
export type DotApp<TServices extends ServiceRecord> = {
|
|
25
62
|
/** App name (passed to `defineApp`). */
|
|
26
63
|
readonly name: string;
|
|
27
64
|
/** Current lifecycle state. */
|
|
28
65
|
readonly state: DotLifecycleState;
|
|
29
66
|
/**
|
|
30
|
-
* Services published by booted pips,
|
|
67
|
+
* Services published by booted pips, keyed by wire key.
|
|
31
68
|
* Empty before `boot()` succeeds.
|
|
32
69
|
*/
|
|
33
70
|
readonly services: TServices;
|
|
@@ -68,7 +105,7 @@ export type DotApp<TServices extends Record<string, unknown>> = {
|
|
|
68
105
|
* Intermediate type after `configure()` but before `boot()`.
|
|
69
106
|
* Exposes the manifest and diagnostics already, but no `services` yet.
|
|
70
107
|
*/
|
|
71
|
-
export type DotAppConfigured<TServices extends
|
|
108
|
+
export type DotAppConfigured<TServices extends ServiceRecord> = {
|
|
72
109
|
readonly name: string;
|
|
73
110
|
readonly state: DotLifecycleState;
|
|
74
111
|
readonly manifest: DotAppManifest;
|
|
@@ -84,18 +121,22 @@ export type DotAppConfigured<TServices extends Record<string, unknown>> = {
|
|
|
84
121
|
/**
|
|
85
122
|
* Builder produced by `defineApp(name)`.
|
|
86
123
|
*
|
|
87
|
-
* `.use(pip)` is type-tracking
|
|
88
|
-
*
|
|
124
|
+
* `.use(pip)` is type-tracking in both directions: the pip's `needs` must
|
|
125
|
+
* be satisfied by the services accumulated so far, and its `provides`
|
|
126
|
+
* merge into the accumulated record for the next `.use()`.
|
|
89
127
|
*/
|
|
90
|
-
export type DotAppBuilder<
|
|
91
|
-
/**
|
|
92
|
-
|
|
128
|
+
export type DotAppBuilder<TAvail extends ServiceRecord> = {
|
|
129
|
+
/**
|
|
130
|
+
* Register a pip. Compile error when the pip's needs are unsatisfied
|
|
131
|
+
* or its provides collide with existing wire keys.
|
|
132
|
+
*/
|
|
133
|
+
use<TNeeds extends ServiceRecord, TProvides extends ServiceRecord>(pip: Pip<TNeeds, TProvides>, ...guard: UseGuard<TAvail, TNeeds, NormalizeProvides<TProvides>>): DotAppBuilder<TAvail & NormalizeProvides<TProvides>>;
|
|
93
134
|
/** Run the configure phase synchronously. Throws on configure failure. */
|
|
94
|
-
configure(): DotAppConfigured<
|
|
135
|
+
configure(): DotAppConfigured<TAvail>;
|
|
95
136
|
/** Run configure + boot. Throws on configure or boot failure. */
|
|
96
|
-
boot(): Promise<DotApp<
|
|
137
|
+
boot(): Promise<DotApp<TAvail>>;
|
|
97
138
|
/** Convenience: configure + boot + start. */
|
|
98
|
-
start(): Promise<DotApp<
|
|
139
|
+
start(): Promise<DotApp<TAvail>>;
|
|
99
140
|
};
|
|
100
141
|
/**
|
|
101
142
|
* Create a new DOT app builder.
|
|
@@ -103,7 +144,7 @@ export type DotAppBuilder<TServices extends Record<string, unknown>> = {
|
|
|
103
144
|
* @example
|
|
104
145
|
* const app = await defineApp('my-app')
|
|
105
146
|
* .use(dbPip)
|
|
106
|
-
* .use(
|
|
147
|
+
* .use(billingPip) // billing's needs must be satisfied by now
|
|
107
148
|
* .boot();
|
|
108
149
|
*
|
|
109
150
|
* await app.start();
|
|
@@ -111,7 +152,7 @@ export type DotAppBuilder<TServices extends Record<string, unknown>> = {
|
|
|
111
152
|
* // ...
|
|
112
153
|
* await app.dispose();
|
|
113
154
|
*/
|
|
114
|
-
export declare function defineApp
|
|
155
|
+
export declare function defineApp(name: string, options?: {
|
|
115
156
|
version?: string;
|
|
116
157
|
config?: Readonly<Record<string, unknown>>;
|
|
117
158
|
/**
|
|
@@ -121,5 +162,6 @@ export declare function defineApp<TServices extends Record<string, unknown> = Re
|
|
|
121
162
|
* `configured.subscribe(...)` or `app.subscribe(...)`.
|
|
122
163
|
*/
|
|
123
164
|
observers?: readonly DotLifecycleObserver[];
|
|
124
|
-
}): DotAppBuilder<
|
|
165
|
+
}): DotAppBuilder<EmptyShape>;
|
|
166
|
+
export {};
|
|
125
167
|
//# sourceMappingURL=define-app.d.ts.map
|
package/dist/define-app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-app.d.ts","sourceRoot":"","sources":["../src/define-app.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define-app.d.ts","sourceRoot":"","sources":["../src/define-app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAU,UAAU,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQhF,KAAK,WAAW,CAAC,MAAM,EAAE,MAAM,IAAI;IACjC,QAAQ,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,MAAM,EAAE,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;CAC/D,CAAC;AAEF,KAAK,cAAc,CAAC,MAAM,EAAE,MAAM,IAAI;IACpC,QAAQ,EAAE,CAAC,IAAI,MAAM,MAAM,GAAG,MAAM,MAAM,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,GAAG;QACtF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;KAC5B;CACF,CAAC;AAEF,KAAK,UAAU,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,aAAa,IAAI;IAC5E,QAAQ,CAAC,oDAAoD,EAAE;QAC7D,QAAQ,CA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C;IACtC,iEAAiE;IACjE,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAChC,6CAA6C;IAC7C,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;CAClC,CAAC;AAUF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C;;;;;OAKG;IACH,SAAS,CAAC,EAAE,SAAS,oBAAoB,EAAE,CAAC;CACxC,GACL,aAAa,CAAC,UAAU,CAAC,CAS3B"}
|
package/dist/define-app.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Public entry point for the
|
|
2
|
+
* Public entry point for the DOT kernel (v2).
|
|
3
3
|
*
|
|
4
4
|
* `defineApp(name)` returns a `DotAppBuilder` that accumulates pips via
|
|
5
5
|
* `.use(pip)`, then transitions through the 5-hook lifecycle:
|
|
6
6
|
*
|
|
7
7
|
* defineApp -> use* -> configure() -> boot() -> start() -> stop() -> dispose()
|
|
8
8
|
*
|
|
9
|
+
* `.use()` is compile-time guarded: a pip whose `needs` are not satisfied
|
|
10
|
+
* by services provided so far — or whose provides collide with existing
|
|
11
|
+
* wire keys — fails to typecheck at the call site ("Expected 2 arguments,
|
|
12
|
+
* but got 1", with the diagnostic embedded in the expected second
|
|
13
|
+
* argument's type). Declaration order IS boot order.
|
|
14
|
+
*
|
|
9
15
|
* Most callers don't need to call `configure()` explicitly — `boot()` runs it
|
|
10
16
|
* implicitly. `boot()` is also implicit when starting from `defined` via
|
|
11
17
|
* `start()`.
|
|
@@ -20,7 +26,7 @@ import { renderTimeline } from './timeline.js';
|
|
|
20
26
|
* @example
|
|
21
27
|
* const app = await defineApp('my-app')
|
|
22
28
|
* .use(dbPip)
|
|
23
|
-
* .use(
|
|
29
|
+
* .use(billingPip) // billing's needs must be satisfied by now
|
|
24
30
|
* .boot();
|
|
25
31
|
*
|
|
26
32
|
* await app.start();
|
|
@@ -48,8 +54,11 @@ function buildImpl(state) {
|
|
|
48
54
|
});
|
|
49
55
|
}
|
|
50
56
|
function makeBuilder(state) {
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
// The `use` implementation is signature-erased (the guard exists purely
|
|
58
|
+
// at the type level); the single cast below is the same kernel boundary
|
|
59
|
+
// v1 crossed in its wrapApp helper.
|
|
60
|
+
const impl = {
|
|
61
|
+
use(pip, ..._guard) {
|
|
53
62
|
const nextState = {
|
|
54
63
|
...state,
|
|
55
64
|
pips: [...state.pips, pip],
|
|
@@ -57,21 +66,22 @@ function makeBuilder(state) {
|
|
|
57
66
|
return makeBuilder(nextState);
|
|
58
67
|
},
|
|
59
68
|
configure() {
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
return wrapConfigured(
|
|
69
|
+
const appImpl = buildImpl(state);
|
|
70
|
+
appImpl.runConfigure();
|
|
71
|
+
return wrapConfigured(appImpl);
|
|
63
72
|
},
|
|
64
73
|
async boot() {
|
|
65
|
-
const
|
|
66
|
-
await
|
|
67
|
-
return wrapApp(
|
|
74
|
+
const appImpl = buildImpl(state);
|
|
75
|
+
await appImpl.boot();
|
|
76
|
+
return wrapApp(appImpl);
|
|
68
77
|
},
|
|
69
78
|
async start() {
|
|
70
|
-
const
|
|
71
|
-
await
|
|
72
|
-
return wrapApp(
|
|
79
|
+
const appImpl = buildImpl(state);
|
|
80
|
+
await appImpl.start();
|
|
81
|
+
return wrapApp(appImpl);
|
|
73
82
|
},
|
|
74
83
|
};
|
|
84
|
+
return impl;
|
|
75
85
|
}
|
|
76
86
|
function wrapApp(impl) {
|
|
77
87
|
return {
|
package/dist/define-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-app.js","sourceRoot":"","sources":["../src/define-app.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"define-app.js","sourceRoot":"","sources":["../src/define-app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAOH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAyJ/C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,UAUI,EAAE;IAEN,MAAM,KAAK,GAAiB;QAC1B,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,OAAO,CAAC,OAAO;QAC3B,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC;IACF,OAAO,WAAW,CAAa,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,SAAS,CAAC,KAAmB;IACpC,OAAO,IAAI,UAAU,CAAC;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAA+B,KAAmB;IACpE,wEAAwE;IACxE,wEAAwE;IACxE,oCAAoC;IACpC,MAAM,IAAI,GAAG;QACX,GAAG,CAAC,GAAW,EAAE,GAAG,MAA0B;YAC5C,MAAM,SAAS,GAAiB;gBAC9B,GAAG,KAAK;gBACR,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC;aAC3B,CAAC;YACF,OAAO,WAAW,CAAgB,SAAS,CAAC,CAAC;QAC/C,CAAC;QACD,SAAS;YACP,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,C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S,cAAc,CAAkC,IAAgB;IACvE,OAAO;QACL,IAAI,IAAI;YACN,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;QACD,IAAI,KAAK;YACP,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QACD,IAAI,QAAQ;YACV,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;QACD,IAAI,WAAW;YACb,OAAO,IAAI,CAAC,WAAW,CAAC;QAC1B,CAAC;QACD,KAAK,CAAC,IAAI;YACR,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,OAAO,OAAO,CAAY,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,KAAK,CAAC,KAAK;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YACnB,OAAO,OAAO,CAAY,IAAI,CAAC,CAAC;QAClC,CAAC;QACD,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;QAC/C,QAAQ,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC;KACjD,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
* @arki/dot — TypeScript-first application composition framework
|
|
3
3
|
*
|
|
4
4
|
* Public surface:
|
|
5
|
-
* - `defineApp(name)` — the
|
|
6
|
-
* - `
|
|
5
|
+
* - `defineApp(name)` — the entry point for composing applications.
|
|
6
|
+
* - `pip(config)` — author lifecycle-aware pips with typed needs/provides.
|
|
7
|
+
* - `service<T>()` / `token<T>()(key)` — service witnesses for DI wiring.
|
|
8
|
+
* - `rename(pip, map)` — mount-time multi-instance primitive.
|
|
7
9
|
* - Lifecycle / manifest / diagnostics types.
|
|
8
10
|
* - `testApp` / `bootTestApp` — test harnesses for pip authors.
|
|
9
11
|
*/
|
|
10
12
|
export { defineApp } from './define-app.js';
|
|
11
|
-
export type { DotApp, DotAppBuilder, DotAppConfigured } from './define-app.js';
|
|
12
|
-
export {
|
|
13
|
-
export type {
|
|
13
|
+
export type { DotApp, DotAppBuilder, DotAppConfigured, UseGuard } from './define-app.js';
|
|
14
|
+
export { isLazy, lazy, lazyOf, pip, provide, rename, service, token, DotPipError } from './pip-contract.js';
|
|
15
|
+
export type { AnyPip, CtxOf, DotConfigureContext, EmptyShape, KernelCtx, Lazy, LazyService, NeedsShape, Pip, PipNeeds, PipProvides, RenamedProvides, Service, ServiceRecord, Token, WireNeeds, } from './pip-contract.js';
|
|
14
16
|
export { DotLifecycleError, DotLifecycleErrorCode, DOT_LIFECYCLE_HOOKS, } from './lifecycle.js';
|
|
15
17
|
export type { DotLifecycleHook, DotLifecycleState, DotLifecyclePipFailure, DotLifecycleErrorCodeValue, } from './lifecycle.js';
|
|
16
18
|
export type { DotAppManifest, PipManifest, RouteManifest, ServiceManifest, LifecycleManifest, DependencyEdge, DependencyEdgeKind, ServiceKind, RouteTransport, } from './manifest.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEzF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5G,YAAY,EACV,MAAM,EACN,KAAK,EACL,mBAAmB,EACnB,UAAU,EACV,SAAS,EACT,IAAI,EACJ,WAAW,EACX,UAAU,EACV,GAAG,EACH,QAAQ,EACR,WAAW,EACX,eAAe,EACf,OAAO,EACP,aAAa,EACb,KAAK,EACL,SAAS,GACV,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,sBAAsB,EACtB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,sBAAsB,EACtB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzD,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAIxD,YAAY,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
* @arki/dot — TypeScript-first application composition framework
|
|
3
3
|
*
|
|
4
4
|
* Public surface:
|
|
5
|
-
* - `defineApp(name)` — the
|
|
6
|
-
* - `
|
|
5
|
+
* - `defineApp(name)` — the entry point for composing applications.
|
|
6
|
+
* - `pip(config)` — author lifecycle-aware pips with typed needs/provides.
|
|
7
|
+
* - `service<T>()` / `token<T>()(key)` — service witnesses for DI wiring.
|
|
8
|
+
* - `rename(pip, map)` — mount-time multi-instance primitive.
|
|
7
9
|
* - Lifecycle / manifest / diagnostics types.
|
|
8
10
|
* - `testApp` / `bootTestApp` — test harnesses for pip authors.
|
|
9
11
|
*/
|
|
10
|
-
// #region
|
|
12
|
+
// #region Kernel — public surface
|
|
11
13
|
export { defineApp } from './define-app.js';
|
|
12
|
-
export {
|
|
14
|
+
export { isLazy, lazy, lazyOf, pip, provide, rename, service, token, DotPipError } from './pip-contract.js';
|
|
13
15
|
export { DotLifecycleError, DotLifecycleErrorCode, DOT_LIFECYCLE_HOOKS, } from './lifecycle.js';
|
|
14
16
|
export { renderTimeline } from './timeline.js';
|
|
15
17
|
export { testApp, bootTestApp } from './test-harness.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,kCAAkC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAoB5G,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,gBAAgB,CAAC;AAuCxB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMzD,aAAa"}
|
|
@@ -8,11 +8,11 @@ import type { DotDiagnosticsSnapshot } from '../diagnostics.js';
|
|
|
8
8
|
import type { DotLifecycleObserver } from '../lifecycle-observer.js';
|
|
9
9
|
import type { DotLifecycleState } from '../lifecycle.js';
|
|
10
10
|
import type { DotAppManifest } from '../manifest.js';
|
|
11
|
-
import type {
|
|
11
|
+
import type { AnyPip } from '../pip-contract.js';
|
|
12
12
|
export type DotAppInternalConfig = {
|
|
13
13
|
appName: string;
|
|
14
14
|
appVersion?: string;
|
|
15
|
-
pips: readonly
|
|
15
|
+
pips: readonly AnyPip[];
|
|
16
16
|
/** Runtime config bag passed to every `boot` hook. */
|
|
17
17
|
config?: Readonly<Record<string, unknown>>;
|
|
18
18
|
/**
|
|
@@ -58,5 +58,5 @@ export declare class DotAppImpl {
|
|
|
58
58
|
}
|
|
59
59
|
/** Re-export `ServiceKind` and `RouteTransport` for the kernel's internal use. */
|
|
60
60
|
export { type RouteTransport, type ServiceKind } from '../manifest.js';
|
|
61
|
-
export { type
|
|
61
|
+
export { type Pip } from '../pip-contract.js';
|
|
62
62
|
//# sourceMappingURL=app-instance.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-instance.d.ts","sourceRoot":"","sources":["../../src/kernel/app-instance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAEV,sBAAsB,EAKvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAqB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,KAAK,EAA4C,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"app-instance.d.ts","sourceRoot":"","sources":["../../src/kernel/app-instance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAEV,sBAAsB,EAKvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAqB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,KAAK,EAA4C,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,KAAK,EAEV,cAAc,EAKf,M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