@astrale-os/sdk 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/dist/auth/authenticate.d.ts +24 -0
- package/dist/auth/authenticate.d.ts.map +1 -0
- package/dist/auth/authenticate.js +29 -0
- package/dist/auth/authenticate.js.map +1 -0
- package/dist/auth/check.d.ts +39 -0
- package/dist/auth/check.d.ts.map +1 -0
- package/dist/auth/check.js +54 -0
- package/dist/auth/check.js.map +1 -0
- package/dist/auth/compose.d.ts +22 -0
- package/dist/auth/compose.d.ts.map +1 -0
- package/dist/auth/compose.js +23 -0
- package/dist/auth/compose.js.map +1 -0
- package/dist/auth/errors.d.ts +16 -0
- package/dist/auth/errors.d.ts.map +1 -0
- package/dist/auth/errors.js +26 -0
- package/dist/auth/errors.js.map +1 -0
- package/dist/auth/identity.d.ts +16 -0
- package/dist/auth/identity.d.ts.map +1 -0
- package/dist/auth/identity.js +2 -0
- package/dist/auth/identity.js.map +1 -0
- package/dist/auth/index.d.ts +12 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/kernel-client.d.ts +28 -0
- package/dist/auth/kernel-client.d.ts.map +1 -0
- package/dist/auth/kernel-client.js +84 -0
- package/dist/auth/kernel-client.js.map +1 -0
- package/dist/auth/resolve.d.ts +19 -0
- package/dist/auth/resolve.d.ts.map +1 -0
- package/dist/auth/resolve.js +43 -0
- package/dist/auth/resolve.js.map +1 -0
- package/dist/auth/sign.d.ts +15 -0
- package/dist/auth/sign.d.ts.map +1 -0
- package/dist/auth/sign.js +24 -0
- package/dist/auth/sign.js.map +1 -0
- package/dist/auth/verify.d.ts +26 -0
- package/dist/auth/verify.d.ts.map +1 -0
- package/dist/auth/verify.js +96 -0
- package/dist/auth/verify.js.map +1 -0
- package/dist/define/index.d.ts +5 -0
- package/dist/define/index.d.ts.map +1 -0
- package/dist/define/index.js +3 -0
- package/dist/define/index.js.map +1 -0
- package/dist/define/remote-function.d.ts +86 -0
- package/dist/define/remote-function.d.ts.map +1 -0
- package/dist/define/remote-function.js +25 -0
- package/dist/define/remote-function.js.map +1 -0
- package/dist/define/view.d.ts +86 -0
- package/dist/define/view.d.ts.map +1 -0
- package/dist/define/view.js +28 -0
- package/dist/define/view.js.map +1 -0
- package/dist/deploy/check.d.ts +30 -0
- package/dist/deploy/check.d.ts.map +1 -0
- package/dist/deploy/check.js +82 -0
- package/dist/deploy/check.js.map +1 -0
- package/dist/deploy/hash-spec.d.ts +9 -0
- package/dist/deploy/hash-spec.d.ts.map +1 -0
- package/dist/deploy/hash-spec.js +29 -0
- package/dist/deploy/hash-spec.js.map +1 -0
- package/dist/deploy/index.d.ts +4 -0
- package/dist/deploy/index.d.ts.map +1 -0
- package/dist/deploy/index.js +4 -0
- package/dist/deploy/index.js.map +1 -0
- package/dist/deploy/meta.d.ts +18 -0
- package/dist/deploy/meta.d.ts.map +1 -0
- package/dist/deploy/meta.js +22 -0
- package/dist/deploy/meta.js.map +1 -0
- package/dist/dispatch/authorize.d.ts +14 -0
- package/dist/dispatch/authorize.d.ts.map +1 -0
- package/dist/dispatch/authorize.js +24 -0
- package/dist/dispatch/authorize.js.map +1 -0
- package/dist/dispatch/call-remote.d.ts +35 -0
- package/dist/dispatch/call-remote.d.ts.map +1 -0
- package/dist/dispatch/call-remote.js +37 -0
- package/dist/dispatch/call-remote.js.map +1 -0
- package/dist/dispatch/dispatcher.d.ts +60 -0
- package/dist/dispatch/dispatcher.d.ts.map +1 -0
- package/dist/dispatch/dispatcher.js +177 -0
- package/dist/dispatch/dispatcher.js.map +1 -0
- package/dist/dispatch/errors.d.ts +47 -0
- package/dist/dispatch/errors.d.ts.map +1 -0
- package/dist/dispatch/errors.js +76 -0
- package/dist/dispatch/errors.js.map +1 -0
- package/dist/dispatch/execute.d.ts +33 -0
- package/dist/dispatch/execute.d.ts.map +1 -0
- package/dist/dispatch/execute.js +24 -0
- package/dist/dispatch/execute.js.map +1 -0
- package/dist/dispatch/identity.d.ts +73 -0
- package/dist/dispatch/identity.d.ts.map +1 -0
- package/dist/dispatch/identity.js +106 -0
- package/dist/dispatch/identity.js.map +1 -0
- package/dist/dispatch/index.d.ts +8 -0
- package/dist/dispatch/index.d.ts.map +1 -0
- package/dist/dispatch/index.js +8 -0
- package/dist/dispatch/index.js.map +1 -0
- package/dist/dispatch/resolve.d.ts +27 -0
- package/dist/dispatch/resolve.d.ts.map +1 -0
- package/dist/dispatch/resolve.js +65 -0
- package/dist/dispatch/resolve.js.map +1 -0
- package/dist/dispatch/self.d.ts +27 -0
- package/dist/dispatch/self.d.ts.map +1 -0
- package/dist/dispatch/self.js +25 -0
- package/dist/dispatch/self.js.map +1 -0
- package/dist/dispatch/validate.d.ts +35 -0
- package/dist/dispatch/validate.d.ts.map +1 -0
- package/dist/dispatch/validate.js +27 -0
- package/dist/dispatch/validate.js.map +1 -0
- package/dist/domain/build-spec.d.ts +37 -0
- package/dist/domain/build-spec.d.ts.map +1 -0
- package/dist/domain/build-spec.js +95 -0
- package/dist/domain/build-spec.js.map +1 -0
- package/dist/domain/contract.d.ts +17 -0
- package/dist/domain/contract.d.ts.map +1 -0
- package/dist/domain/contract.js +26 -0
- package/dist/domain/contract.js.map +1 -0
- package/dist/domain/define.d.ts +82 -0
- package/dist/domain/define.d.ts.map +1 -0
- package/dist/domain/define.js +99 -0
- package/dist/domain/define.js.map +1 -0
- package/dist/domain/extend-core.d.ts +49 -0
- package/dist/domain/extend-core.d.ts.map +1 -0
- package/dist/domain/extend-core.js +182 -0
- package/dist/domain/extend-core.js.map +1 -0
- package/dist/domain/index.d.ts +5 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +4 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/method/class.d.ts +70 -0
- package/dist/method/class.d.ts.map +1 -0
- package/dist/method/class.js +26 -0
- package/dist/method/class.js.map +1 -0
- package/dist/method/context.d.ts +43 -0
- package/dist/method/context.d.ts.map +1 -0
- package/dist/method/context.js +10 -0
- package/dist/method/context.js.map +1 -0
- package/dist/method/index.d.ts +6 -0
- package/dist/method/index.d.ts.map +1 -0
- package/dist/method/index.js +3 -0
- package/dist/method/index.js.map +1 -0
- package/dist/method/single.d.ts +88 -0
- package/dist/method/single.d.ts.map +1 -0
- package/dist/method/single.js +18 -0
- package/dist/method/single.js.map +1 -0
- package/dist/server/auxiliary-routes.d.ts +44 -0
- package/dist/server/auxiliary-routes.d.ts.map +1 -0
- package/dist/server/auxiliary-routes.js +237 -0
- package/dist/server/auxiliary-routes.js.map +1 -0
- package/dist/server/config.d.ts +83 -0
- package/dist/server/config.d.ts.map +1 -0
- package/dist/server/config.js +8 -0
- package/dist/server/config.js.map +1 -0
- package/dist/server/create.d.ts +21 -0
- package/dist/server/create.d.ts.map +1 -0
- package/dist/server/create.js +210 -0
- package/dist/server/create.js.map +1 -0
- package/dist/server/handle.d.ts +35 -0
- package/dist/server/handle.d.ts.map +1 -0
- package/dist/server/handle.js +9 -0
- package/dist/server/handle.js.map +1 -0
- package/dist/server/index.d.ts +11 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +8 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/jwks.d.ts +11 -0
- package/dist/server/jwks.d.ts.map +1 -0
- package/dist/server/jwks.js +15 -0
- package/dist/server/jwks.js.map +1 -0
- package/dist/server/require-env.d.ts +15 -0
- package/dist/server/require-env.d.ts.map +1 -0
- package/dist/server/require-env.js +21 -0
- package/dist/server/require-env.js.map +1 -0
- package/dist/server/serving-url.d.ts +14 -0
- package/dist/server/serving-url.d.ts.map +1 -0
- package/dist/server/serving-url.js +28 -0
- package/dist/server/serving-url.js.map +1 -0
- package/dist/server/start.d.ts +11 -0
- package/dist/server/start.d.ts.map +1 -0
- package/dist/server/start.js +30 -0
- package/dist/server/start.js.map +1 -0
- package/dist/server/worker-entry.d.ts +60 -0
- package/dist/server/worker-entry.d.ts.map +1 -0
- package/dist/server/worker-entry.js +79 -0
- package/dist/server/worker-entry.js.map +1 -0
- package/dist/server/worker-meta.d.ts +6 -0
- package/dist/server/worker-meta.d.ts.map +1 -0
- package/dist/server/worker-meta.js +10 -0
- package/dist/server/worker-meta.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-callable identity — dispatcher runtime + install-time wiring.
|
|
3
|
+
*
|
|
4
|
+
* Two flavors of callable get an identity per the install-time identity
|
|
5
|
+
* binding: Methods on classes/interfaces (sub = MethodPath) and auto-
|
|
6
|
+
* materialized core function nodes — RemoteFunctions and Views (sub =
|
|
7
|
+
* AbsolutePath of the node under `core/{functions,views}/<slug>`).
|
|
8
|
+
*
|
|
9
|
+
* At server startup the method dispatcher and the View / RemoteFunction
|
|
10
|
+
* route mounter pre-compute, for every materialized callable, the
|
|
11
|
+
* `RemoteIdentityConfig` they sign outbound kernel calls with. The kernel
|
|
12
|
+
* then matches an existing function identity instead of provisioning a
|
|
13
|
+
* generic one.
|
|
14
|
+
*
|
|
15
|
+
* **Single source of truth:** every helper here is a thin lens over the
|
|
16
|
+
* canonical `resolveCallables` from `@astrale-os/kernel-core/domain`. The
|
|
17
|
+
* kernel validates install subs against the SAME function — drift = 0
|
|
18
|
+
* by construction. This closes the previous SDK-side gap where
|
|
19
|
+
* `collectMethodPaths` filtered to `own|override` and silently dropped
|
|
20
|
+
* `sealed`/`default` interface methods (which DO materialize as nodes).
|
|
21
|
+
*/
|
|
22
|
+
import { resolveCallables } from '@astrale-os/kernel-core/domain';
|
|
23
|
+
/**
|
|
24
|
+
* For each materialized method node, emit its `MethodPath` (semantic,
|
|
25
|
+
* layout-independent) keyed by the method's namespaced ref. Used to
|
|
26
|
+
* build the install `subs` claim and to look up runtime per-method
|
|
27
|
+
* subjects in `buildIdentityMap`.
|
|
28
|
+
*
|
|
29
|
+
* Includes every method node the kernel materializes — class own/override
|
|
30
|
+
* AND interface own (sealed/default/override). Inherited (non-overriding)
|
|
31
|
+
* class methods reuse the interface's node via a `method_of` edge and
|
|
32
|
+
* are correctly absent here.
|
|
33
|
+
*/
|
|
34
|
+
export function collectMethodPaths(compiled) {
|
|
35
|
+
const out = {};
|
|
36
|
+
for (const c of resolveCallables(compiled)) {
|
|
37
|
+
if (c.kind === 'method')
|
|
38
|
+
out[c.ref] = c.sub;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
export function collectAuxIdentityPaths(compiled) {
|
|
43
|
+
const views = {};
|
|
44
|
+
const remoteFunctions = {};
|
|
45
|
+
for (const c of resolveCallables(compiled)) {
|
|
46
|
+
if (c.kind !== 'core' || !c.slug)
|
|
47
|
+
continue;
|
|
48
|
+
if (c.className === 'View') {
|
|
49
|
+
views[c.slug] = c.sub;
|
|
50
|
+
}
|
|
51
|
+
else if (c.className === 'Function') {
|
|
52
|
+
// Standalone callables (the former `RemoteFunction`) materialize as the
|
|
53
|
+
// canonical kernel `Function` class.
|
|
54
|
+
remoteFunctions[c.slug] = c.sub;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new Error(`collectAuxIdentityPaths: unrecognised aux callable className "${c.className}" ` +
|
|
58
|
+
`at ${c.ref}. If you've added a new auto-materialized Function class to extendCore, ` +
|
|
59
|
+
`extend this collector + the kernel walker (resolveCallables) to handle it.`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { views, remoteFunctions };
|
|
63
|
+
}
|
|
64
|
+
export function buildAuxIdentityMap(compiled, privateKey, issuer) {
|
|
65
|
+
const paths = collectAuxIdentityPaths(compiled);
|
|
66
|
+
const views = {};
|
|
67
|
+
for (const [slug, subject] of Object.entries(paths.views)) {
|
|
68
|
+
views[slug] = { issuer, subject, privateKey };
|
|
69
|
+
}
|
|
70
|
+
const remoteFunctions = {};
|
|
71
|
+
for (const [slug, subject] of Object.entries(paths.remoteFunctions)) {
|
|
72
|
+
remoteFunctions[slug] = { issuer, subject, privateKey };
|
|
73
|
+
}
|
|
74
|
+
return { views, remoteFunctions };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Pre-resolve per-method identity configs. Lookup is by BoundMethod instance,
|
|
78
|
+
* so the dispatcher pays O(1) per call instead of re-constructing the config.
|
|
79
|
+
*
|
|
80
|
+
* `iss` = the worker's own **serving URL** (`issuer` arg, e.g.
|
|
81
|
+
* `https://crm.test.com`) — its cryptographic identity, DECOUPLED from the
|
|
82
|
+
* domain's addressing `origin` (a graph slug). The kernel stamps the same
|
|
83
|
+
* value on each function node at install (it pins `iss` to the URL it fetched
|
|
84
|
+
* the domain at) and verifies inbound credentials against that issuer's JWKS
|
|
85
|
+
* (OIDC discovery). The function `sub` stays the origin-addressed MethodPath —
|
|
86
|
+
* `sub` = which function, `iss` = who signs.
|
|
87
|
+
*/
|
|
88
|
+
export function buildIdentityMap(compiled, methods, privateKey, issuer) {
|
|
89
|
+
const paths = collectMethodPaths(compiled);
|
|
90
|
+
const out = new Map();
|
|
91
|
+
for (const bound of methods) {
|
|
92
|
+
const subject = paths[bound.ref];
|
|
93
|
+
if (!subject) {
|
|
94
|
+
// Under the "drift = 0" invariant every dispatched method's ref is a key
|
|
95
|
+
// in `paths`. A miss means an install/index drift — fail loudly at boot
|
|
96
|
+
// rather than signing with `bound.ref` (a namespaced ref, NOT a
|
|
97
|
+
// MethodPath sub), which would silently fail kernel identity matching at
|
|
98
|
+
// call time. Mirrors `identityFor` / `requireAuxIdentity`.
|
|
99
|
+
throw new Error(`buildIdentityMap: method "${bound.ref}" is in the dispatch index but absent ` +
|
|
100
|
+
`from resolveCallables(compiled) — no identity subject to sign with.`);
|
|
101
|
+
}
|
|
102
|
+
out.set(bound, { issuer, subject, privateKey });
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
//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AC3D,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,CAAC,GAAG,wCAAwC;gBAC5E,qEAAqE,CACxE,CAAA;QACH,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAA;IACjD,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { SdkDispatcher, type SdkDispatcherConfig } from './dispatcher';
|
|
2
|
+
export { resolveMethod, buildMethodIndex, type MethodIndex } from './resolve';
|
|
3
|
+
export { validateParams, validateResult, type ValidationResult, type ResultValidationResult, } from './validate';
|
|
4
|
+
export { resolveSelf, type SelfResult } from './self';
|
|
5
|
+
export { executeHandler, type ExecuteParams } from './execute';
|
|
6
|
+
export { makeCallRemote, type CallRemoteFn } from './call-remote';
|
|
7
|
+
export { AuthorizationDeniedError, MethodNotFoundError, SdkValidationError, SdkResultValidationError, } from './errors';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dispatch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAC7E,OAAO,EACL,cAAc,EACd,cAAc,EACd,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,GAC5B,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAA;AACjE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { SdkDispatcher } from './dispatcher';
|
|
2
|
+
export { resolveMethod, buildMethodIndex } from './resolve';
|
|
3
|
+
export { validateParams, validateResult, } from './validate';
|
|
4
|
+
export { resolveSelf } from './self';
|
|
5
|
+
export { executeHandler } from './execute';
|
|
6
|
+
export { makeCallRemote } from './call-remote';
|
|
7
|
+
export { AuthorizationDeniedError, MethodNotFoundError, SdkValidationError, SdkResultValidationError, } from './errors';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dispatch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA4B,MAAM,cAAc,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAoB,MAAM,WAAW,CAAA;AAC7E,OAAO,EACL,cAAc,EACd,cAAc,GAGf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAmB,MAAM,QAAQ,CAAA;AACrD,OAAO,EAAE,cAAc,EAAsB,MAAM,WAAW,CAAA;AAC9D,OAAO,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAA;AACjE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method resolution — the index the dispatcher queries on every call.
|
|
3
|
+
*
|
|
4
|
+
* Owns both the index's construction and its lookup contract:
|
|
5
|
+
* - `buildMethodIndex` is called once at server startup.
|
|
6
|
+
* - `resolveMethod` is called once per inbound call.
|
|
7
|
+
*
|
|
8
|
+
* Each method is indexed under its `BoundMethod.ref`
|
|
9
|
+
* (`namespace.Owner.method.name`) and under a short alias `Owner.name`.
|
|
10
|
+
* The short alias is only registered when it is unambiguous — two methods
|
|
11
|
+
* whose owners live in different namespaces (e.g. class vs interface) and
|
|
12
|
+
* share the same local name would collide, and we refuse to register the
|
|
13
|
+
* ambiguous key rather than silently overwriting.
|
|
14
|
+
*
|
|
15
|
+
* Inbound names may arrive as `Path`, full `ref`, short alias, a tree path
|
|
16
|
+
* `/<domain>/<namespace.Owner>/<method>`, or the typed colon-form MethodPath
|
|
17
|
+
* `/:<domain>:<namespace.Owner>:<method>` (what the kernel forwards when a
|
|
18
|
+
* caller addresses the method in `:`-delimited form). All shapes normalize to
|
|
19
|
+
* the same lookup key.
|
|
20
|
+
*/
|
|
21
|
+
import type { Path } from '@astrale-os/kernel-core';
|
|
22
|
+
import type { BoundMethod } from '@astrale-os/kernel-core/domain';
|
|
23
|
+
import type { AnyRemoteHandler } from '../method/single';
|
|
24
|
+
export type MethodIndex = Map<string, BoundMethod<AnyRemoteHandler>>;
|
|
25
|
+
export declare function buildMethodIndex(methods: BoundMethod<AnyRemoteHandler>[]): MethodIndex;
|
|
26
|
+
export declare function resolveMethod(index: MethodIndex, name: Path | string): BoundMethod<AnyRemoteHandler> | null;
|
|
27
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/dispatch/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC,CAAA;AAKpE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,gBAAgB,CAAC,EAAE,GAAG,WAAW,CAmBtF;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,GAAG,MAAM,GAClB,WAAW,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAEtC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method resolution — the index the dispatcher queries on every call.
|
|
3
|
+
*
|
|
4
|
+
* Owns both the index's construction and its lookup contract:
|
|
5
|
+
* - `buildMethodIndex` is called once at server startup.
|
|
6
|
+
* - `resolveMethod` is called once per inbound call.
|
|
7
|
+
*
|
|
8
|
+
* Each method is indexed under its `BoundMethod.ref`
|
|
9
|
+
* (`namespace.Owner.method.name`) and under a short alias `Owner.name`.
|
|
10
|
+
* The short alias is only registered when it is unambiguous — two methods
|
|
11
|
+
* whose owners live in different namespaces (e.g. class vs interface) and
|
|
12
|
+
* share the same local name would collide, and we refuse to register the
|
|
13
|
+
* ambiguous key rather than silently overwriting.
|
|
14
|
+
*
|
|
15
|
+
* Inbound names may arrive as `Path`, full `ref`, short alias, a tree path
|
|
16
|
+
* `/<domain>/<namespace.Owner>/<method>`, or the typed colon-form MethodPath
|
|
17
|
+
* `/:<domain>:<namespace.Owner>:<method>` (what the kernel forwards when a
|
|
18
|
+
* caller addresses the method in `:`-delimited form). All shapes normalize to
|
|
19
|
+
* the same lookup key.
|
|
20
|
+
*/
|
|
21
|
+
const NAMESPACE_PREFIXES = ['class.', 'interface.'];
|
|
22
|
+
const METHOD_INFIX = 'method';
|
|
23
|
+
export function buildMethodIndex(methods) {
|
|
24
|
+
const index = new Map();
|
|
25
|
+
const shortFormAmbiguous = new Set();
|
|
26
|
+
for (const m of methods) {
|
|
27
|
+
index.set(m.ref, m);
|
|
28
|
+
const shortForm = `${m.owner}.${m.method}`;
|
|
29
|
+
if (shortFormAmbiguous.has(shortForm))
|
|
30
|
+
continue;
|
|
31
|
+
const existing = index.get(shortForm);
|
|
32
|
+
if (existing && existing !== m) {
|
|
33
|
+
index.delete(shortForm);
|
|
34
|
+
shortFormAmbiguous.add(shortForm);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
index.set(shortForm, m);
|
|
38
|
+
}
|
|
39
|
+
return index;
|
|
40
|
+
}
|
|
41
|
+
export function resolveMethod(index, name) {
|
|
42
|
+
return index.get(normalizeMethod(name)) ?? null;
|
|
43
|
+
}
|
|
44
|
+
function normalizeMethod(name) {
|
|
45
|
+
const raw = typeof name === 'string' ? name : name.raw;
|
|
46
|
+
if (!raw.startsWith('/'))
|
|
47
|
+
return raw;
|
|
48
|
+
// Typed colon-form MethodPath (`/:<domain>:<owner>:<method>`) vs. tree
|
|
49
|
+
// slash-form (`/<domain>/<owner>/<method>`). The owner segment carries its own
|
|
50
|
+
// `.` (e.g. `interface.NoteOps`), so the path separator is unambiguous.
|
|
51
|
+
const separator = raw.startsWith('/:') ? ':' : '/';
|
|
52
|
+
const segments = raw
|
|
53
|
+
.replace(/^\/+/, '')
|
|
54
|
+
.split(separator)
|
|
55
|
+
.filter((s) => s.length > 0);
|
|
56
|
+
if (segments.length < 3)
|
|
57
|
+
return raw;
|
|
58
|
+
const owner = segments[segments.length - 2];
|
|
59
|
+
const method = segments[segments.length - 1];
|
|
60
|
+
if (NAMESPACE_PREFIXES.some((p) => owner.startsWith(p))) {
|
|
61
|
+
return `${owner}.${METHOD_INFIX}.${method}`;
|
|
62
|
+
}
|
|
63
|
+
return `${owner}.${method}`;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/dispatch/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AASH,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,YAAY,CAAU,CAAA;AAC5D,MAAM,YAAY,GAAG,QAAQ,CAAA;AAE7B,MAAM,UAA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,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;IAClD,MAAM,QAAQ,GAAG,GAAG;SACjB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;SACnB,KAAK,CAAC,SAAS,CAAC;SAChB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAC9B,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IACnC,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAE,CAAA;IAC5C,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAE,CAAA;IAC7C,IAAI,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,OAAO,GAAG,KAAK,IAAI,YAAY,IAAI,MAAM,EAAE,CAAA;IAC7C,CAAC;IACD,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self resolution — pipeline step 3.
|
|
3
|
+
*
|
|
4
|
+
* `_self` is a path reference to the node the non-static method runs on.
|
|
5
|
+
* Currently a thin parse: the caller's string becomes a `Path`, and handlers
|
|
6
|
+
* build recursive paths as `${self.path}::method` (the `Path`'s `toString`
|
|
7
|
+
* yields its raw form, so template literals work unchanged).
|
|
8
|
+
*
|
|
9
|
+
* `resolveSelf` receives the bare self target (`@<id>` or a tree path) — the
|
|
10
|
+
* method ref travels in a separate dispatch channel, so `::method` never
|
|
11
|
+
* reaches here. For the `@<id>` form the parsed `Path` is an `IdPath` which
|
|
12
|
+
* already carries the node id; surfacing it on `SelfResult.id` saves every
|
|
13
|
+
* worker handler from either parsing `self.path.raw` by hand or doing a
|
|
14
|
+
* `Node::get` round-trip just to recover the id of the node it's already
|
|
15
|
+
* operating on.
|
|
16
|
+
*
|
|
17
|
+
* Kept as a distinct step so a future implementation can do a real
|
|
18
|
+
* resolution here (e.g. hydrate a node/accessor) without touching callers.
|
|
19
|
+
*/
|
|
20
|
+
import { Path, type NodeId } from '@astrale-os/kernel-core';
|
|
21
|
+
export type SelfResult = {
|
|
22
|
+
path: Path;
|
|
23
|
+
/** Set when `path` is an `IdPath` (i.e. `@<id>::method` calls). */
|
|
24
|
+
id?: NodeId;
|
|
25
|
+
};
|
|
26
|
+
export declare function resolveSelf(ref: string): SelfResult;
|
|
27
|
+
//# sourceMappingURL=self.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self.d.ts","sourceRoot":"","sources":["../../src/dispatch/self.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAU,IAAI,EAAE,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEnE,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,IAAI,CAAA;IACV,mEAAmE;IACnE,EAAE,CAAC,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAGnD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self resolution — pipeline step 3.
|
|
3
|
+
*
|
|
4
|
+
* `_self` is a path reference to the node the non-static method runs on.
|
|
5
|
+
* Currently a thin parse: the caller's string becomes a `Path`, and handlers
|
|
6
|
+
* build recursive paths as `${self.path}::method` (the `Path`'s `toString`
|
|
7
|
+
* yields its raw form, so template literals work unchanged).
|
|
8
|
+
*
|
|
9
|
+
* `resolveSelf` receives the bare self target (`@<id>` or a tree path) — the
|
|
10
|
+
* method ref travels in a separate dispatch channel, so `::method` never
|
|
11
|
+
* reaches here. For the `@<id>` form the parsed `Path` is an `IdPath` which
|
|
12
|
+
* already carries the node id; surfacing it on `SelfResult.id` saves every
|
|
13
|
+
* worker handler from either parsing `self.path.raw` by hand or doing a
|
|
14
|
+
* `Node::get` round-trip just to recover the id of the node it's already
|
|
15
|
+
* operating on.
|
|
16
|
+
*
|
|
17
|
+
* Kept as a distinct step so a future implementation can do a real
|
|
18
|
+
* resolution here (e.g. hydrate a node/accessor) without touching callers.
|
|
19
|
+
*/
|
|
20
|
+
import { IdPath, Path } from '@astrale-os/kernel-core';
|
|
21
|
+
export function resolveSelf(ref) {
|
|
22
|
+
const path = Path.parse(ref);
|
|
23
|
+
return path instanceof IdPath ? { path, id: path.id } : { path };
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=self.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self.js","sourceRoot":"","sources":["../../src/dispatch/self.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAe,MAAM,yBAAyB,CAAA;AAQnE,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC5B,OAAO,IAAI,YAAY,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAA;AAClE,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Param / result validation helpers — Zod `safeParse` wrappers returning a
|
|
3
|
+
* tagged result. Callers convert a `false` outcome into a typed error:
|
|
4
|
+
* `SdkValidationError` (input, → 422) or `SdkResultValidationError`
|
|
5
|
+
* (output, → 500).
|
|
6
|
+
*/
|
|
7
|
+
import type { z } from 'zod';
|
|
8
|
+
export type ValidationResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
data: Record<string, unknown>;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
issues: unknown[];
|
|
14
|
+
};
|
|
15
|
+
export declare function validateParams(inputSchema: z.ZodType, params: unknown): ValidationResult;
|
|
16
|
+
/**
|
|
17
|
+
* Result of validating a handler's output against its `outputSchema`. Unlike
|
|
18
|
+
* params, an output may be any shape (object, primitive, array), so `data` is
|
|
19
|
+
* `unknown` rather than `Record<string, unknown>`.
|
|
20
|
+
*/
|
|
21
|
+
export type ResultValidationResult = {
|
|
22
|
+
ok: true;
|
|
23
|
+
data: unknown;
|
|
24
|
+
} | {
|
|
25
|
+
ok: false;
|
|
26
|
+
issues: unknown[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Validate a handler's return value against its `outputSchema`. Mirrors the
|
|
30
|
+
* kernel's `validateOutput` (`runtime/.../validation/output.ts`) so deployed
|
|
31
|
+
* domains enforce the same output contract as in-process methods. Returns the
|
|
32
|
+
* parsed `data` (applies Zod `default`/`transform`/coercions) on success.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateResult(outputSchema: z.ZodType, result: unknown): ResultValidationResult;
|
|
35
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/dispatch/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAC3C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAA;AAEpC,wBAAgB,cAAc,CAAC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAMxF;AAED;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAA;AAEnG;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,sBAAsB,CAM/F"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Param / result validation helpers — Zod `safeParse` wrappers returning a
|
|
3
|
+
* tagged result. Callers convert a `false` outcome into a typed error:
|
|
4
|
+
* `SdkValidationError` (input, → 422) or `SdkResultValidationError`
|
|
5
|
+
* (output, → 500).
|
|
6
|
+
*/
|
|
7
|
+
export function validateParams(inputSchema, params) {
|
|
8
|
+
const result = inputSchema.safeParse(params);
|
|
9
|
+
if (result.success) {
|
|
10
|
+
return { ok: true, data: result.data };
|
|
11
|
+
}
|
|
12
|
+
return { ok: false, issues: result.error.issues };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validate a handler's return value against its `outputSchema`. Mirrors the
|
|
16
|
+
* kernel's `validateOutput` (`runtime/.../validation/output.ts`) so deployed
|
|
17
|
+
* domains enforce the same output contract as in-process methods. Returns the
|
|
18
|
+
* parsed `data` (applies Zod `default`/`transform`/coercions) on success.
|
|
19
|
+
*/
|
|
20
|
+
export function validateResult(outputSchema, result) {
|
|
21
|
+
const parsed = outputSchema.safeParse(result);
|
|
22
|
+
if (parsed.success) {
|
|
23
|
+
return { ok: true, data: parsed.data };
|
|
24
|
+
}
|
|
25
|
+
return { ok: false, issues: parsed.error.issues };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/dispatch/validate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,MAAM,UAAU,cAAc,CAAC,WAAsB,EAAE,MAAe;IACpE,MAAM,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAC5C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAA+B,EAAE,CAAA;IACnE,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;AACnD,CAAC;AASD;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,YAAuB,EAAE,MAAe;IACrE,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAC7C,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAA;IACxC,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-side spec builder: CompiledDomain → serialize → Graph.
|
|
3
|
+
*
|
|
4
|
+
* Serializes BoundMethod[] into FunctionSchema[], generates entries for
|
|
5
|
+
* inherited methods not covered by the domain's handlers, then delegates
|
|
6
|
+
* to serialize() for graph blueprint generation.
|
|
7
|
+
*
|
|
8
|
+
* Domain-side Methods are remote-bound: dispatch routes through
|
|
9
|
+
* `binding.remoteUrl` and never reaches the kernel sandbox. We therefore
|
|
10
|
+
* do NOT stamp `code` on emitted FunctionSchema entries — there is no
|
|
11
|
+
* sandbox-eval'able body. Only the kernel domain (compiled in-process)
|
|
12
|
+
* carries `code` strings.
|
|
13
|
+
*
|
|
14
|
+
* The emitted graph is absolute — the Tree produced by `serialize()` is
|
|
15
|
+
* already mounted at `/<origin>`, so `tree.toGraph()` lifts every internal
|
|
16
|
+
* relative path into its host-graph absolute form. Wire serialization is the
|
|
17
|
+
* caller's responsibility (`graph.toWire()`).
|
|
18
|
+
*/
|
|
19
|
+
import type { WireGraph } from '@astrale-os/kernel-core';
|
|
20
|
+
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
21
|
+
import type { RemoteDomain } from './define';
|
|
22
|
+
/**
|
|
23
|
+
* Build the install-ready wire graph for a domain served at `url`: materialize
|
|
24
|
+
* the domain at its real serving URL (so every binding carries the live URL —
|
|
25
|
+
* the define-time compile carries none), serialize, and emit the wire form.
|
|
26
|
+
* This is the graph the kernel installs and re-hashes to verify. There is no
|
|
27
|
+
* url-less variant: an install graph without bindings is uninstallable (the
|
|
28
|
+
* kernel install guard rejects it).
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildInstallGraph<S extends Schema>(domain: RemoteDomain<S>, url: string): WireGraph;
|
|
31
|
+
/**
|
|
32
|
+
* Content hash of the install graph. Delegates the canonical hash to kernel-core's
|
|
33
|
+
* `hashInstallGraph` — the same algorithm the kernel re-runs on install to verify
|
|
34
|
+
* the received graph against the signed hash.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildInstallGraphHash<S extends Schema>(domain: RemoteDomain<S>, url: string): Promise<string>;
|
|
37
|
+
//# sourceMappingURL=build-spec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-spec.d.ts","sourceRoot":"","sources":["../../src/domain/build-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAE/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAKpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAK5C;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,GAAG,EAAE,MAAM,GACV,SAAS,CAGX;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,MAAM,EACpD,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,EACvB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAEjB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-side spec builder: CompiledDomain → serialize → Graph.
|
|
3
|
+
*
|
|
4
|
+
* Serializes BoundMethod[] into FunctionSchema[], generates entries for
|
|
5
|
+
* inherited methods not covered by the domain's handlers, then delegates
|
|
6
|
+
* to serialize() for graph blueprint generation.
|
|
7
|
+
*
|
|
8
|
+
* Domain-side Methods are remote-bound: dispatch routes through
|
|
9
|
+
* `binding.remoteUrl` and never reaches the kernel sandbox. We therefore
|
|
10
|
+
* do NOT stamp `code` on emitted FunctionSchema entries — there is no
|
|
11
|
+
* sandbox-eval'able body. Only the kernel domain (compiled in-process)
|
|
12
|
+
* carries `code` strings.
|
|
13
|
+
*
|
|
14
|
+
* The emitted graph is absolute — the Tree produced by `serialize()` is
|
|
15
|
+
* already mounted at `/<origin>`, so `tree.toGraph()` lifts every internal
|
|
16
|
+
* relative path into its host-graph absolute form. Wire serialization is the
|
|
17
|
+
* caller's responsibility (`graph.toWire()`).
|
|
18
|
+
*/
|
|
19
|
+
import { hashInstallGraph, serialize, zodToJsonSchema } from '@astrale-os/kernel-core/domain';
|
|
20
|
+
import { extractBinding } from './contract';
|
|
21
|
+
import { materializeRemoteDomain } from './define';
|
|
22
|
+
/**
|
|
23
|
+
* Build the install-ready wire graph for a domain served at `url`: materialize
|
|
24
|
+
* the domain at its real serving URL (so every binding carries the live URL —
|
|
25
|
+
* the define-time compile carries none), serialize, and emit the wire form.
|
|
26
|
+
* This is the graph the kernel installs and re-hashes to verify. There is no
|
|
27
|
+
* url-less variant: an install graph without bindings is uninstallable (the
|
|
28
|
+
* kernel install guard rejects it).
|
|
29
|
+
*/
|
|
30
|
+
export function buildInstallGraph(domain, url) {
|
|
31
|
+
const { compiled } = materializeRemoteDomain(domain, url);
|
|
32
|
+
return buildSpecInternal(compiled, domain.methods, url).toWire();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Content hash of the install graph. Delegates the canonical hash to kernel-core's
|
|
36
|
+
* `hashInstallGraph` — the same algorithm the kernel re-runs on install to verify
|
|
37
|
+
* the received graph against the signed hash.
|
|
38
|
+
*/
|
|
39
|
+
export function buildInstallGraphHash(domain, url) {
|
|
40
|
+
return hashInstallGraph(buildInstallGraph(domain, url));
|
|
41
|
+
}
|
|
42
|
+
// ── Internal ────────────────────────────────────────────────
|
|
43
|
+
function buildSpecInternal(compiled, methods, url) {
|
|
44
|
+
const serialized = serializeMethodsWithStubs(compiled, methods, url);
|
|
45
|
+
const tree = serialize(compiled, serialized);
|
|
46
|
+
// Views / RemoteFunctions are auto-materialized into the Core BEFORE
|
|
47
|
+
// `compileDomain` runs (see `extend-core.ts`). By the time we reach
|
|
48
|
+
// `serialize` here the Tree already contains their nodes/edges.
|
|
49
|
+
return tree.toGraph();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Serialize BoundMethod[] and generate stubs for methods in compiled.$.methods
|
|
53
|
+
* that have no corresponding BoundMethod (inherited-sealed, inherited-default).
|
|
54
|
+
*
|
|
55
|
+
* Every Method's binding defaults its `remoteUrl` to the serving URL: domain
|
|
56
|
+
* methods are remote-bound — the kernel dispatches them by redirecting to the
|
|
57
|
+
* worker — so a method node without a remote binding is uninstallable (the
|
|
58
|
+
* kernel install guard rejects it). An explicit per-method `remoteUrl` wins.
|
|
59
|
+
*/
|
|
60
|
+
function serializeMethodsWithStubs(compiled, methods, url) {
|
|
61
|
+
const bound = new Set(methods.map((m) => m.ref));
|
|
62
|
+
const result = methods.map((m) => serializeFromBoundMethod(m, url));
|
|
63
|
+
// Generate entries for unbound methods (replaces fillMissingCallables).
|
|
64
|
+
// No `code` is stamped — domain-side Methods are binding-only. The `ref` MUST
|
|
65
|
+
// be the QUALIFIED `ResolvedMethod.ref` (`<ns>.<Type>.method.<m>`) — the exact
|
|
66
|
+
// form `serialize`'s method-node lookup uses; re-deriving a bare `Type.method`
|
|
67
|
+
// is the F11 bug (interface methods then never resolve → MISSING_HANDLER).
|
|
68
|
+
for (const classMethods of Object.values(compiled.$.methods)) {
|
|
69
|
+
for (const rm of Object.values(classMethods)) {
|
|
70
|
+
const ref = rm.ref;
|
|
71
|
+
if (bound.has(ref))
|
|
72
|
+
continue;
|
|
73
|
+
result.push({
|
|
74
|
+
ref,
|
|
75
|
+
inputSchema: { type: 'object' },
|
|
76
|
+
outputSchema: {},
|
|
77
|
+
output: 'value',
|
|
78
|
+
binding: { remoteUrl: url },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
function serializeFromBoundMethod(method, url) {
|
|
85
|
+
const binding = extractBinding(method.handler);
|
|
86
|
+
return {
|
|
87
|
+
ref: method.ref,
|
|
88
|
+
inputSchema: zodToJsonSchema(method.inputSchema),
|
|
89
|
+
outputSchema: zodToJsonSchema(method.outputSchema),
|
|
90
|
+
isStatic: method.isStatic || undefined,
|
|
91
|
+
output: method.output,
|
|
92
|
+
binding: binding?.remoteUrl ? binding : { ...binding, remoteUrl: url },
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=build-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-spec.js","sourceRoot":"","sources":["../../src/domain/build-spec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gCAAgC,C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
|
+
* `ref` plus optional `binding` — because the SDK's SdkDispatcher
|
|
6
|
+
* handles dispatch via KernelAPI.call, not via runtime contract hooks.
|
|
7
|
+
*/
|
|
8
|
+
import type { AuthPolicy, FunctionBinding, MountableContract, RouteBinding } from '@astrale-os/kernel-api/routed';
|
|
9
|
+
import type { BoundMethod } from '@astrale-os/kernel-core/domain';
|
|
10
|
+
import type { AnyRemoteHandler } from '../method/single';
|
|
11
|
+
export declare function toSdkContract(method: BoundMethod<AnyRemoteHandler>): MountableContract;
|
|
12
|
+
export declare function extractBinding(handler: {
|
|
13
|
+
route?: RouteBinding;
|
|
14
|
+
remoteUrl?: string;
|
|
15
|
+
auth?: AuthPolicy;
|
|
16
|
+
}): FunctionBinding | undefined;
|
|
17
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/domain/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,YAAY,EACb,MAAM,+BAA+B,CAAA;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAA;AAEjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,iBAAiB,CAQtF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE;IACtC,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,GAAG,eAAe,GAAG,SAAS,CAQ9B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BoundMethod → MountableContract translator.
|
|
3
|
+
*
|
|
4
|
+
* The narrow view carries only what the server's mount planner reads —
|
|
5
|
+
* `ref` plus optional `binding` — because the SDK's SdkDispatcher
|
|
6
|
+
* handles dispatch via KernelAPI.call, not via runtime contract hooks.
|
|
7
|
+
*/
|
|
8
|
+
export function toSdkContract(method) {
|
|
9
|
+
const handler = method.handler;
|
|
10
|
+
const binding = extractBinding(handler);
|
|
11
|
+
return binding === undefined ? { ref: method.ref } : { ref: method.ref, binding };
|
|
12
|
+
}
|
|
13
|
+
export function extractBinding(handler) {
|
|
14
|
+
const { route, remoteUrl, auth } = handler;
|
|
15
|
+
if (route === undefined && remoteUrl === undefined && auth === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const binding = {};
|
|
18
|
+
if (remoteUrl !== undefined)
|
|
19
|
+
binding.remoteUrl = remoteUrl;
|
|
20
|
+
if (route !== undefined)
|
|
21
|
+
binding.route = route;
|
|
22
|
+
if (auth !== undefined)
|
|
23
|
+
binding.auth = auth;
|
|
24
|
+
return binding;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=contract.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/domain/contract.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,MAAM,UAAU,aAAa,CAAC,MAAqC;IACjE,MAAM,OAAO,GAAG,MAAM,CAAC,OAItB,CAAA;IACD,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,CAAA;AACnF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAI9B;IACC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,OAAO,CAAA;IAC1C,IAAI,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC1F,MAAM,OAAO,GAAoB,EAAE,CAAA;IACnC,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,CAAC,SAAS,GAAG,SAAS,CAAA;IAC1D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAA;IAC9C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAA;IAC3C,OAAO,OAAO,CAAA;AAChB,CAAC"}
|