@astrale-os/sdk 0.1.10 → 0.3.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/LICENSE +202 -0
- package/dist/auth/check.d.ts +1 -2
- package/dist/auth/check.d.ts.map +1 -1
- package/dist/auth/check.js +2 -6
- package/dist/auth/check.js.map +1 -1
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/issuer-mint.d.ts +53 -0
- package/dist/auth/issuer-mint.d.ts.map +1 -0
- package/dist/auth/issuer-mint.js +35 -0
- package/dist/auth/issuer-mint.js.map +1 -0
- package/dist/auth/kernel-client.d.ts +8 -2
- package/dist/auth/kernel-client.d.ts.map +1 -1
- package/dist/auth/kernel-client.js +22 -46
- package/dist/auth/kernel-client.js.map +1 -1
- package/dist/cli/dotenv.d.ts +8 -0
- package/dist/cli/dotenv.d.ts.map +1 -1
- package/dist/cli/dotenv.js +18 -0
- package/dist/cli/dotenv.js.map +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/log.d.ts +11 -0
- package/dist/cli/log.d.ts.map +1 -0
- package/dist/cli/log.js +17 -0
- package/dist/cli/log.js.map +1 -0
- package/dist/cli/publish.d.ts +35 -0
- package/dist/cli/publish.d.ts.map +1 -0
- package/dist/cli/publish.js +271 -0
- package/dist/cli/publish.js.map +1 -0
- package/dist/cli/run.d.ts +17 -2
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +102 -111
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/spec.d.ts.map +1 -1
- package/dist/cli/spec.js +1 -0
- package/dist/cli/spec.js.map +1 -1
- package/dist/config/adapter.d.ts +12 -11
- package/dist/config/adapter.d.ts.map +1 -1
- package/dist/config/adapter.js.map +1 -1
- package/dist/config/define-domain.d.ts +88 -27
- package/dist/config/define-domain.d.ts.map +1 -1
- package/dist/config/define-domain.js +79 -33
- package/dist/config/define-domain.js.map +1 -1
- package/dist/config/deploy.d.ts +1 -1
- package/dist/config/deploy.js +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/define/remote-function.d.ts +32 -17
- package/dist/define/remote-function.d.ts.map +1 -1
- package/dist/define/remote-function.js +10 -9
- package/dist/define/remote-function.js.map +1 -1
- package/dist/define/view.d.ts +8 -6
- package/dist/define/view.d.ts.map +1 -1
- package/dist/define/view.js +8 -6
- package/dist/define/view.js.map +1 -1
- package/dist/deploy/check.d.ts +6 -6
- package/dist/deploy/check.d.ts.map +1 -1
- package/dist/deploy/check.js +1 -1
- package/dist/deploy/check.js.map +1 -1
- package/dist/deploy/index.d.ts +0 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/index.js +0 -1
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/meta.d.ts +11 -0
- package/dist/deploy/meta.d.ts.map +1 -1
- package/dist/deploy/meta.js +23 -0
- package/dist/deploy/meta.js.map +1 -1
- package/dist/dispatch/dispatcher.d.ts +17 -4
- package/dist/dispatch/dispatcher.d.ts.map +1 -1
- package/dist/dispatch/dispatcher.js +15 -3
- package/dist/dispatch/dispatcher.js.map +1 -1
- package/dist/dispatch/execute.d.ts +6 -2
- package/dist/dispatch/execute.d.ts.map +1 -1
- package/dist/dispatch/execute.js +1 -0
- package/dist/dispatch/execute.js.map +1 -1
- package/dist/dispatch/identity.d.ts +12 -10
- package/dist/dispatch/identity.d.ts.map +1 -1
- package/dist/dispatch/identity.js +10 -15
- package/dist/dispatch/identity.js.map +1 -1
- package/dist/dispatch/index.d.ts +1 -1
- package/dist/dispatch/index.d.ts.map +1 -1
- package/dist/dispatch/index.js +1 -1
- package/dist/dispatch/index.js.map +1 -1
- package/dist/dispatch/self.d.ts +25 -37
- package/dist/dispatch/self.d.ts.map +1 -1
- package/dist/dispatch/self.js +60 -30
- package/dist/dispatch/self.js.map +1 -1
- package/dist/domain/binding.d.ts +18 -0
- package/dist/domain/binding.d.ts.map +1 -0
- package/dist/domain/binding.js +29 -0
- package/dist/domain/binding.js.map +1 -0
- package/dist/domain/build-spec.d.ts.map +1 -1
- package/dist/domain/build-spec.js +22 -7
- package/dist/domain/build-spec.js.map +1 -1
- package/dist/domain/define.d.ts +28 -43
- package/dist/domain/define.d.ts.map +1 -1
- package/dist/domain/define.js +23 -60
- package/dist/domain/define.js.map +1 -1
- package/dist/domain/extend-functions.d.ts +48 -0
- package/dist/domain/extend-functions.d.ts.map +1 -0
- package/dist/domain/extend-functions.js +84 -0
- package/dist/domain/extend-functions.js.map +1 -0
- package/dist/domain/extend-views.d.ts +45 -0
- package/dist/domain/extend-views.d.ts.map +1 -0
- package/dist/domain/extend-views.js +116 -0
- package/dist/domain/extend-views.js.map +1 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -5
- package/dist/index.js.map +1 -1
- package/dist/method/class.d.ts +2 -2
- package/dist/method/class.d.ts.map +1 -1
- package/dist/method/class.js.map +1 -1
- package/dist/method/context.d.ts +18 -3
- package/dist/method/context.d.ts.map +1 -1
- package/dist/method/index.d.ts +2 -2
- package/dist/method/index.d.ts.map +1 -1
- package/dist/method/index.js.map +1 -1
- package/dist/method/single.d.ts +25 -38
- package/dist/method/single.d.ts.map +1 -1
- package/dist/method/single.js +1 -11
- package/dist/method/single.js.map +1 -1
- package/dist/server/auxiliary-routes.d.ts.map +1 -1
- package/dist/server/auxiliary-routes.js +14 -3
- package/dist/server/auxiliary-routes.js.map +1 -1
- package/dist/server/create.d.ts +2 -15
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +15 -51
- package/dist/server/create.js.map +1 -1
- package/dist/server/domain-entry.d.ts +10 -0
- package/dist/server/domain-entry.d.ts.map +1 -1
- package/dist/server/domain-entry.js +2 -0
- package/dist/server/domain-entry.js.map +1 -1
- package/dist/server/index.d.ts +0 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +0 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/worker-entry.d.ts +3 -3
- package/dist/server/worker-entry.js +3 -3
- package/package.json +10 -11
- package/src/auth/check.ts +2 -6
- package/src/auth/index.ts +3 -1
- package/src/auth/issuer-mint.ts +75 -0
- package/src/auth/kernel-client.ts +31 -63
- package/src/cli/dotenv.ts +20 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/log.ts +18 -0
- package/src/cli/publish.ts +341 -0
- package/src/cli/run.ts +109 -125
- package/src/cli/spec.ts +1 -0
- package/src/config/adapter.ts +9 -11
- package/src/config/define-domain.ts +184 -53
- package/src/config/deploy.ts +1 -1
- package/src/config/index.ts +1 -1
- package/src/define/remote-function.ts +56 -21
- package/src/define/view.ts +8 -6
- package/src/deploy/check.ts +7 -7
- package/src/deploy/index.ts +0 -1
- package/src/deploy/meta.ts +25 -0
- package/src/dispatch/dispatcher.ts +32 -9
- package/src/dispatch/execute.ts +7 -2
- package/src/dispatch/identity.ts +17 -22
- package/src/dispatch/index.ts +1 -1
- package/src/dispatch/self.ts +117 -41
- package/src/domain/binding.ts +37 -0
- package/src/domain/build-spec.ts +32 -7
- package/src/domain/define.ts +71 -78
- package/src/domain/extend-functions.ts +106 -0
- package/src/domain/extend-views.ts +151 -0
- package/src/index.ts +36 -7
- package/src/method/class.ts +11 -7
- package/src/method/context.ts +19 -3
- package/src/method/index.ts +8 -2
- package/src/method/single.ts +35 -42
- package/src/server/auxiliary-routes.ts +14 -3
- package/src/server/create.ts +15 -51
- package/src/server/domain-entry.ts +12 -0
- package/src/server/index.ts +0 -1
- package/src/server/worker-entry.ts +3 -3
- package/src/deploy/hash-spec.ts +0 -31
- package/src/domain/extend-core.ts +0 -301
- package/src/server/worker-meta.ts +0 -25
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `defineDomain` — the WORKER-SAFE definition of a domain: what the domain *is*
|
|
3
|
-
* (its `schema`, `methods`, `deps`, `views`, standalone `functions
|
|
4
|
-
*
|
|
3
|
+
* (its `schema`, `methods`, `deps`, `views`, standalone `functions`) plus its
|
|
4
|
+
* addressing identity (`origin`, `requires`, `postInstall`). It
|
|
5
5
|
* deliberately carries NO deployment adapter — the adapter (`cloudflare(...)`,
|
|
6
6
|
* `astrale(...)`) is node-only code (filesystem, wrangler) that must never enter
|
|
7
7
|
* the worker bundle. The author wires this in a `domain.ts` the generated worker
|
|
@@ -11,25 +11,69 @@
|
|
|
11
11
|
* The modules are wired EXPLICITLY here — imported and passed in — not
|
|
12
12
|
* discovered from magic folder names. A renamed or mistyped module is a compile
|
|
13
13
|
* error at this call site, never a silently-missing worker route. The adapter
|
|
14
|
-
* reads this one definition for
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* reads this one definition for domain-side codegen; frontend source folders
|
|
15
|
+
* live in adapter env config. `defineDomain` itself builds no server and boots
|
|
16
|
+
* no kernel — it validates and packages the declaration.
|
|
17
17
|
*/
|
|
18
18
|
import type { Schema } from '@astrale-os/kernel-dsl';
|
|
19
|
-
import type {
|
|
19
|
+
import type { AnyRemoteFunctionDef, ViewDef } from '../define';
|
|
20
20
|
import type { SchemaMethodsImpl } from '../method';
|
|
21
21
|
type AnyViewDef = ViewDef<any>;
|
|
22
|
-
type AnyFunctionDef =
|
|
22
|
+
type AnyFunctionDef = AnyRemoteFunctionDef;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* binding. Always written out explicitly (`client: { dir: 'client' }`) — there
|
|
28
|
-
* is no boolean shorthand, so the source folder is never implicit.
|
|
24
|
+
* Optional presentation metadata for the domain, served verbatim on the
|
|
25
|
+
* worker's `/meta` endpoint (see `../deploy/meta`) so a host UI can brand a
|
|
26
|
+
* freshly-installed domain. Both the block and every field are optional.
|
|
29
27
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export interface DomainManifest {
|
|
29
|
+
/** Domain logo — an inline SVG string or a `data:` URL (no extra validation). */
|
|
30
|
+
logo?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Slug of one of THIS domain's own views to open first — the domain's entry
|
|
33
|
+
* surface. This is the SERVED form: a plain slug, stamped verbatim onto
|
|
34
|
+
* `/meta`. Authors don't write the slug directly — they pass the view OBJECT
|
|
35
|
+
* to `defineDomain` (see {@link DomainManifestConfig.entrypoint}), which
|
|
36
|
+
* resolves it to this slug. Pinned at app install to the `View` node at
|
|
37
|
+
* `/<origin>/views/<slug>` via the app's `entrypoint` edge.
|
|
38
|
+
*/
|
|
39
|
+
entrypoint?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The ROLES this domain declares — named capability identities a workspace
|
|
42
|
+
* registers when an app for this domain is installed, then assigns to users
|
|
43
|
+
* (`default: true` roles are auto-assigned to the installing user). The
|
|
44
|
+
* domain itself grants each role its resource permissions (typically in its
|
|
45
|
+
* `postInstall`); declaring a role here only names it. Slugs are validated
|
|
46
|
+
* (lowercase slug charset, unique) at `defineDomain`.
|
|
47
|
+
*/
|
|
48
|
+
roles?: readonly DomainRoleDecl[];
|
|
49
|
+
}
|
|
50
|
+
/** One declared role of the domain (see {@link DomainManifest.roles}). */
|
|
51
|
+
export interface DomainRoleDecl {
|
|
52
|
+
/** Stable role slug, unique within the domain (e.g. `"editor"`). */
|
|
53
|
+
slug: string;
|
|
54
|
+
/** Display name; defaults to the slug. */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** What holding this role means — shown in permission UIs. */
|
|
57
|
+
description?: string;
|
|
58
|
+
/** Auto-assign this role to the user installing an app for this domain. */
|
|
59
|
+
default?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The author-facing manifest accepted by {@link defineDomain} — identical to the
|
|
63
|
+
* served {@link DomainManifest} except `entrypoint` is the view OBJECT (a value
|
|
64
|
+
* of the `views` map) rather than its slug. `defineDomain` resolves it to the
|
|
65
|
+
* slug by identity, so a renamed or dropped view is a compile error at the
|
|
66
|
+
* reference site, never a stale string (the same guarantee `postInstall` gives
|
|
67
|
+
* for functions).
|
|
68
|
+
*/
|
|
69
|
+
export interface DomainManifestConfig extends Omit<DomainManifest, 'entrypoint'> {
|
|
70
|
+
/**
|
|
71
|
+
* The view to open first — the domain's entry surface. Pass the view OBJECT
|
|
72
|
+
* from this domain's own `views` map (e.g. `entrypoint: views.welcome`).
|
|
73
|
+
* Resolved to its slug here and served as {@link DomainManifest.entrypoint}.
|
|
74
|
+
*/
|
|
75
|
+
entrypoint?: AnyViewDef;
|
|
76
|
+
}
|
|
33
77
|
export interface DefineDomainConfig<S extends Schema, TDeps, TEnv = unknown> {
|
|
34
78
|
/** The domain schema (from `schema/`). Its `.domain` seeds the default origin. */
|
|
35
79
|
schema: S;
|
|
@@ -65,11 +109,14 @@ export interface DefineDomainConfig<S extends Schema, TDeps, TEnv = unknown> {
|
|
|
65
109
|
*/
|
|
66
110
|
functions?: Record<string, AnyFunctionDef>;
|
|
67
111
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
112
|
+
* Optional presentation metadata stamped onto `/meta`. When `manifest.entrypoint`
|
|
113
|
+
* is set it MUST be a view from this domain's own `views` map — passed as the
|
|
114
|
+
* OBJECT (`entrypoint: views.welcome`), resolved to its slug here. A view that
|
|
115
|
+
* isn't in `views` is a compile error at the reference site, and the
|
|
116
|
+
* resolution throws loudly if it's somehow absent — so a typo can never dangle
|
|
117
|
+
* to a NOT_FOUND view path at install.
|
|
71
118
|
*/
|
|
72
|
-
|
|
119
|
+
manifest?: DomainManifestConfig;
|
|
73
120
|
/**
|
|
74
121
|
* The domain's **addressing name** (the graph slug it mounts under, e.g.
|
|
75
122
|
* `'crm.acme.dev'`). Defaults to `schema.domain`. Must be a name, never a
|
|
@@ -82,11 +129,25 @@ export interface DefineDomainConfig<S extends Schema, TDeps, TEnv = unknown> {
|
|
|
82
129
|
/** Cross-domain deps, by origin. Verified present on the instance at install. */
|
|
83
130
|
requires?: readonly string[];
|
|
84
131
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
132
|
+
* Where the Domain node physically lives in the graph TREE — an absolute tree
|
|
133
|
+
* path whose LAST segment is the origin (e.g. `'/domains/crm.acme.dev'`).
|
|
134
|
+
* Optional; defaults to `/domains/<origin>`. This moves ONLY the physical
|
|
135
|
+
* `has_parent` position: the domain's `installed_in` edge and EVERY typed
|
|
136
|
+
* address (`/:<origin>`, `/:<origin>:Class`, …) stay ROOT-mounted, so
|
|
137
|
+
* addressing is unchanged. A platform domain that must stay top-level sets its
|
|
138
|
+
* own origin path (e.g. `'/workspace.astrale.ai'`).
|
|
88
139
|
*/
|
|
89
|
-
|
|
140
|
+
path?: string;
|
|
141
|
+
/**
|
|
142
|
+
* The function the kernel runs once after install, as __SYSTEM__ — where the
|
|
143
|
+
* domain seeds itself / posts its own grants. Reference it from the `functions`
|
|
144
|
+
* map: `postInstall: functions.seed`. The SDK derives its path by identity, so a
|
|
145
|
+
* typo or a renamed key is a compile error here, never a stale string. It is
|
|
146
|
+
* always a standalone function (a domain bootstrap belongs to the domain, not to
|
|
147
|
+
* a class) under THIS domain — you never write the origin, and the kernel
|
|
148
|
+
* resolves it relative to wherever the domain is installed.
|
|
149
|
+
*/
|
|
150
|
+
postInstall?: AnyFunctionDef;
|
|
90
151
|
}
|
|
91
152
|
export interface DomainDefinition {
|
|
92
153
|
schema: Schema;
|
|
@@ -99,13 +160,13 @@ export interface DomainDefinition {
|
|
|
99
160
|
deps?: (env: any, url: string) => any;
|
|
100
161
|
views?: Record<string, ViewDef>;
|
|
101
162
|
functions?: Record<string, AnyFunctionDef>;
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
dir: string;
|
|
105
|
-
};
|
|
163
|
+
/** Presentation metadata for `/meta`, validated at definition time. */
|
|
164
|
+
manifest?: DomainManifest;
|
|
106
165
|
origin: string;
|
|
107
166
|
requires: readonly string[];
|
|
108
167
|
postInstall?: string;
|
|
168
|
+
/** Physical tree path for the Domain node; default `/domains/<origin>`. */
|
|
169
|
+
path?: string;
|
|
109
170
|
}
|
|
110
171
|
export declare function defineDomain<S extends Schema, TDeps, TEnv = unknown>(config: DefineDomainConfig<S, TDeps, TEnv>): DomainDefinition;
|
|
111
172
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-domain.d.ts","sourceRoot":"","sources":["../../src/config/define-domain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"define-domain.d.ts","sourceRoot":"","sources":["../../src/config/define-domain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAIpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAQlD,KAAK,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;AAI9B,KAAK,cAAc,GAAG,oBAAoB,CAAA;AAE1C;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAClC;AAED,0EAA0E;AAC1E,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAA;IACZ,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,8DA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GAAG,CAAA;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAC1C,uEAAuE;IACvE,QAAQ,CAAC,EAAE,cAAc,CAAA;IACzB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,2EAA2E;IAC3E,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,IAAI,GAAG,OAAO,EAClE,MAAM,EAAE,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GACzC,gBAAgB,CAmGlB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `defineDomain` — the WORKER-SAFE definition of a domain: what the domain *is*
|
|
3
|
-
* (its `schema`, `methods`, `deps`, `views`, standalone `functions
|
|
4
|
-
*
|
|
3
|
+
* (its `schema`, `methods`, `deps`, `views`, standalone `functions`) plus its
|
|
4
|
+
* addressing identity (`origin`, `requires`, `postInstall`). It
|
|
5
5
|
* deliberately carries NO deployment adapter — the adapter (`cloudflare(...)`,
|
|
6
6
|
* `astrale(...)`) is node-only code (filesystem, wrangler) that must never enter
|
|
7
7
|
* the worker bundle. The author wires this in a `domain.ts` the generated worker
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
* The modules are wired EXPLICITLY here — imported and passed in — not
|
|
12
12
|
* discovered from magic folder names. A renamed or mistyped module is a compile
|
|
13
13
|
* error at this call site, never a silently-missing worker route. The adapter
|
|
14
|
-
* reads this one definition for
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* reads this one definition for domain-side codegen; frontend source folders
|
|
15
|
+
* live in adapter env config. `defineDomain` itself builds no server and boots
|
|
16
|
+
* no kernel — it validates and packages the declaration.
|
|
17
17
|
*/
|
|
18
|
-
import { DomainOrigin
|
|
18
|
+
import { DomainOrigin } from '@astrale-os/kernel-core/domain';
|
|
19
19
|
export function defineDomain(config) {
|
|
20
20
|
const rawOrigin = config.origin ?? schemaDomain(config.schema);
|
|
21
21
|
if (!rawOrigin) {
|
|
@@ -46,50 +46,96 @@ export function defineDomain(config) {
|
|
|
46
46
|
}
|
|
47
47
|
catch {
|
|
48
48
|
throw new Error(`defineDomain: invalid \`requires\` entry "${dep}". Use the dependency's origin slug ` +
|
|
49
|
-
'(lowercase FQDN-like, e.g. "
|
|
49
|
+
'(lowercase FQDN-like, e.g. "example.astrale.ai"), not a URL.');
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
+
// `path`, when set, is the Domain's physical tree path. Validate the
|
|
53
|
+
// two invariants the serializer/kernel rely on, string-only (no AbsolutePath
|
|
54
|
+
// import — this module must stay worker-safe): it is absolute with at least one
|
|
55
|
+
// segment, and its LAST segment equals the origin (the kernel derives origin
|
|
56
|
+
// from the mount basename in a few places, e.g. has_parent slug + get-access-
|
|
57
|
+
// token origin recovery). Full structural parse happens at build time.
|
|
58
|
+
if (config.path !== undefined) {
|
|
59
|
+
const loc = config.path;
|
|
60
|
+
if (!loc.startsWith('/') || loc === '/') {
|
|
61
|
+
throw new Error(`defineDomain: \`path\` must be an absolute graph path with at least ` +
|
|
62
|
+
`one segment (e.g. "/domains/${origin}"), not "${loc}".`);
|
|
63
|
+
}
|
|
64
|
+
if (loc.split('/').pop() !== origin) {
|
|
65
|
+
throw new Error(`defineDomain: \`path\` last segment must equal the origin "${origin}" ` +
|
|
66
|
+
`(e.g. "/domains/${origin}" or "/${origin}"), got "${loc}".`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// A `manifest.entrypoint` view is resolved to its slug below (in the return),
|
|
70
|
+
// where a view absent from `views` throws — see `resolveManifest`.
|
|
71
|
+
// Declared roles must carry valid, unique slugs — a role slug becomes a graph
|
|
72
|
+
// path segment and an identity subject, so the kernel's reserved separators
|
|
73
|
+
// (`/`, `:`, `@`) can never appear in one. Fail at authoring time.
|
|
74
|
+
if (config.manifest?.roles !== undefined) {
|
|
75
|
+
const seen = new Set();
|
|
76
|
+
for (const role of config.manifest.roles) {
|
|
77
|
+
if (!/^[a-z0-9][a-z0-9_-]*$/.test(role.slug)) {
|
|
78
|
+
throw new Error(`defineDomain: invalid \`manifest.roles\` slug "${role.slug}". ` +
|
|
79
|
+
'Use a lowercase slug (letters, digits, "_", "-"), e.g. "editor".');
|
|
80
|
+
}
|
|
81
|
+
if (seen.has(role.slug)) {
|
|
82
|
+
throw new Error(`defineDomain: duplicate \`manifest.roles\` slug "${role.slug}".`);
|
|
83
|
+
}
|
|
84
|
+
seen.add(role.slug);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
52
87
|
return {
|
|
53
88
|
schema: config.schema,
|
|
54
89
|
methods: config.methods,
|
|
55
90
|
...(config.deps ? { deps: config.deps } : {}),
|
|
56
91
|
...(config.views ? { views: config.views } : {}),
|
|
57
92
|
...(config.functions ? { functions: config.functions } : {}),
|
|
58
|
-
...(config.
|
|
93
|
+
...(config.manifest ? { manifest: resolveManifest(config.manifest, config.views) } : {}),
|
|
59
94
|
origin,
|
|
60
95
|
requires,
|
|
61
|
-
...(config.
|
|
62
|
-
|
|
96
|
+
...(config.path ? { path: config.path } : {}),
|
|
97
|
+
...(config.postInstall !== undefined
|
|
98
|
+
? { postInstall: normalizePostInstall(config.postInstall, origin, config.functions) }
|
|
63
99
|
: {}),
|
|
64
100
|
};
|
|
65
101
|
}
|
|
66
102
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* as `` `/:${schema.domain}:…` `` where `schema.domain` keeps its source
|
|
73
|
-
* casing, but the kernel stores graph nodes (and runs its guard) under the
|
|
74
|
-
* lowercased origin — so the origin segment is re-stamped canonical. Rejects a
|
|
75
|
-
* tree path or one pointing at a different domain (the kernel calls the hook
|
|
76
|
-
* as __SYSTEM__ and refuses a foreign target).
|
|
103
|
+
* Lower the author-facing manifest (view OBJECT for `entrypoint`) to the served
|
|
104
|
+
* {@link DomainManifest} (slug for `entrypoint`). The entrypoint view is matched
|
|
105
|
+
* to its `views`-map key by IDENTITY — the same mechanism `normalizePostInstall`
|
|
106
|
+
* uses for functions — so a view absent from `views` (one from another domain,
|
|
107
|
+
* or dropped) throws here instead of dangling to a NOT_FOUND view path at install.
|
|
77
108
|
*/
|
|
78
|
-
function
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
109
|
+
function resolveManifest(manifest, views) {
|
|
110
|
+
const { entrypoint, ...rest } = manifest;
|
|
111
|
+
if (entrypoint === undefined)
|
|
112
|
+
return rest;
|
|
113
|
+
const slug = views ? Object.entries(views).find(([, def]) => def === entrypoint)?.[0] : undefined;
|
|
114
|
+
if (slug === undefined) {
|
|
115
|
+
const viewKeys = Object.keys(views ?? {});
|
|
116
|
+
throw new Error("defineDomain: `manifest.entrypoint` must be one of this domain's own views " +
|
|
117
|
+
'(pass the view object, e.g. `entrypoint: views.welcome`). ' +
|
|
118
|
+
`Available views: ${viewKeys.length > 0 ? viewKeys.map((k) => `"${k}"`).join(', ') : '(none)'}.`);
|
|
84
119
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
120
|
+
return { ...rest, entrypoint: slug };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Resolve a `postInstall` function reference to the colon-path the bundle carries.
|
|
124
|
+
* The slug is the `functions` map key the reference is registered under (found by
|
|
125
|
+
* identity), so a renamed key is a compile error at the reference site AND the
|
|
126
|
+
* derived path follows the rename. The origin is never the author's to supply
|
|
127
|
+
* (postInstall is always a standalone function of THIS domain) and the path is
|
|
128
|
+
* mount-agnostic — the kernel resolves it wherever the domain is installed.
|
|
129
|
+
*/
|
|
130
|
+
function normalizePostInstall(postInstall, origin, functions) {
|
|
131
|
+
const slug = functions
|
|
132
|
+
? Object.entries(functions).find(([, def]) => def === postInstall)?.[0]
|
|
133
|
+
: undefined;
|
|
134
|
+
if (slug === undefined) {
|
|
135
|
+
throw new Error("defineDomain: `postInstall` must reference a function from this domain's `functions` map " +
|
|
136
|
+
'(e.g. `postInstall: functions.seed`).');
|
|
88
137
|
}
|
|
89
|
-
|
|
90
|
-
return postInstall.startsWith('/:')
|
|
91
|
-
? `/:${origin}${postInstall.slice(2 + slug.length)}`
|
|
92
|
-
: `/${origin}${postInstall.slice(1 + slug.length)}`;
|
|
138
|
+
return `/:${origin}:function.${slug}`;
|
|
93
139
|
}
|
|
94
140
|
function schemaDomain(schema) {
|
|
95
141
|
const value = schema.domain;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"define-domain.js","sourceRoot":"","sources":["../../src/config/define-domain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"define-domain.js","sourceRoot":"","sources":["../../src/config/define-domain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAA;AA4K7D,MAAM,UAAU,YAAY,CAC1B,MAA0C;IAE1C,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC9D,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,2DAA2D,CAC9D,CAAA;IACH,CAAC;IACD,IAAI,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,KAAK,CACb,0FAA0F,SAAS,KAAK;YACtG,8DAA8D,CACjE,CAAA;IACH,CAAC;IACD,6EAA6E;IAC7E,8EAA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;IACH,CAAC;IACD,OAAO,EAAE,GAAG,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAA;AACtC,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,WAA2B,EAC3B,MAAc,EACd,SAAqD;IAErD,MAAM,IAAI,GAAG,SAAS;QACpB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,SAAS,CAAA;IACb,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,2FAA2F;YACzF,uCAAuC,CAC1C,CAAA;IACH,CAAC;IACD,OAAO,KAAK,MAAM,aAAa,IAAI,EAAE,CAAA;AACvC,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,MAAM,KAAK,GAAI,MAA0C,CAAC,MAAM,CAAA;IAChE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAC1E,CAAC"}
|
package/dist/config/deploy.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* is authored in `astrale.config.ts` — a Node-only module the CLI loads but the
|
|
10
10
|
* worker never imports — so the adapter stays out of the bundle.
|
|
11
11
|
*
|
|
12
|
-
* export const domain = defineDomain({ schema, methods, deps, views
|
|
12
|
+
* export const domain = defineDomain({ schema, methods, deps, views })
|
|
13
13
|
*
|
|
14
14
|
* import { domain } from './domain'
|
|
15
15
|
* export default deploy(domain, cloudflare({ dev, prod }))
|
package/dist/config/deploy.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* is authored in `astrale.config.ts` — a Node-only module the CLI loads but the
|
|
10
10
|
* worker never imports — so the adapter stays out of the bundle.
|
|
11
11
|
*
|
|
12
|
-
* export const domain = defineDomain({ schema, methods, deps, views
|
|
12
|
+
* export const domain = defineDomain({ schema, methods, deps, views })
|
|
13
13
|
*
|
|
14
14
|
* import { domain } from './domain'
|
|
15
15
|
* export default deploy(domain, cloudflare({ dev, prod }))
|
package/dist/config/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* declaration.
|
|
14
14
|
*/
|
|
15
15
|
export { defineDomain } from './define-domain';
|
|
16
|
-
export type {
|
|
16
|
+
export type { DefineDomainConfig, DomainDefinition, DomainManifest } from './define-domain';
|
|
17
17
|
export { deploy } from './deploy';
|
|
18
18
|
export type { DeployConfig } from './deploy';
|
|
19
19
|
export { defineAdapter } from './adapter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAE3F,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzC,YAAY,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,UAAU,EACV,QAAQ,EACR,WAAW,GACZ,MAAM,WAAW,CAAA"}
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authoring a standalone remote function — a callable not bound to a class.
|
|
3
3
|
* (The verb keeps the `defineRemoteFunction` name; the node it materializes is
|
|
4
|
-
* the canonical kernel `Function` class, the former
|
|
4
|
+
* the canonical kernel `Function` class, replacing the former remote-function wrapper.)
|
|
5
5
|
*
|
|
6
6
|
* Each entry in `defineRemoteDomain({ remoteFunctions: { ... } })` becomes:
|
|
7
|
-
* - a graph node at `/${origin}/
|
|
8
|
-
* as the kernel `Function` class
|
|
9
|
-
* `
|
|
7
|
+
* - a graph node at `/${origin}/functions/<slug>` — a first-class domain MEMBER,
|
|
8
|
+
* materialized as the kernel `Function` class and attached to the Domain via an
|
|
9
|
+
* `of_domain` edge (slug `function.<slug>`), so it is addressable by the
|
|
10
|
+
* semantic path `/:${origin}:function.<slug>` (the form a `postInstall` uses).
|
|
10
11
|
* - a Hono route on the worker at the path implied by `binding`
|
|
11
|
-
* (`/<functionsFolder>/<slug>` POST by default —
|
|
12
|
+
* (`/<functionsFolder>/<slug>` POST by default — the route URL is decoupled
|
|
13
|
+
* from the graph layout).
|
|
12
14
|
*
|
|
13
|
-
* The slug = the map key (single source of truth, no duplication).
|
|
14
|
-
*
|
|
15
|
-
* `
|
|
16
|
-
* `Function.ref` on the graph node and as the dispatch key.
|
|
15
|
+
* The slug = the map key (single source of truth, no duplication). The member
|
|
16
|
+
* ref (`function.<slug>`), the layout (`/<origin>/functions/<slug>`), and the
|
|
17
|
+
* `of_domain` edge slug are all DERIVED from it — there is nothing else to name.
|
|
17
18
|
*/
|
|
18
19
|
import type { AuthPolicy, FunctionBinding } from '@astrale-os/kernel-api/routed';
|
|
19
20
|
import type { FnMap } from '@astrale-os/kernel-client';
|
|
20
21
|
import type { BoundClientSessionView } from '@astrale-os/kernel-client/session';
|
|
21
22
|
import type { Context } from 'hono';
|
|
22
23
|
import type { z } from 'zod';
|
|
24
|
+
import type { DomainIssuer } from '../auth/issuer-mint';
|
|
23
25
|
import type { CallRemoteFn } from '../dispatch/call-remote';
|
|
24
26
|
import type { AuthForPolicy, KernelForAuth } from '../method/context';
|
|
25
27
|
export type RemoteFunctionContext<TParams, TDeps = unknown, TKernel = BoundClientSessionView<FnMap> | null, TAuth extends AuthPolicy = AuthPolicy> = {
|
|
@@ -38,12 +40,20 @@ export type RemoteFunctionContext<TParams, TDeps = unknown, TKernel = BoundClien
|
|
|
38
40
|
/**
|
|
39
41
|
* `BoundClientSessionView` to the parent kernel, bound to the composed
|
|
40
42
|
* credential `union(delegation, self)` — same shape as `RemoteContext.kernel`
|
|
41
|
-
* for `remoteMethod
|
|
43
|
+
* for `remoteMethod`, including the typed graph read/write sugar flattened onto
|
|
44
|
+
* it (`kernel.get` / `kernel.children` / `kernel.query`,
|
|
45
|
+
* `kernel.createNode` / `kernel.mutate(patch)`, …) over the `function.get` /
|
|
46
|
+
* `function.mutate` syscalls. Nullability follows {@link KernelForAuth} of the
|
|
42
47
|
* function's `auth`: non-null for the default `'required'`, `… | null` for
|
|
43
48
|
* `'optional'`, `null` for `'public'` (use {@link RemoteFunctionContext.selfKernel}
|
|
44
49
|
* there, after verifying the upstream).
|
|
45
50
|
*/
|
|
46
51
|
kernel: TKernel;
|
|
52
|
+
/**
|
|
53
|
+
* Mint seam for identities THIS DOMAIN issues — same contract as
|
|
54
|
+
* {@link RemoteContext.issuer}.
|
|
55
|
+
*/
|
|
56
|
+
issuer: DomainIssuer;
|
|
47
57
|
/**
|
|
48
58
|
* Call another worker's remote method, re-minting the credential for the
|
|
49
59
|
* target's audience. Same contract as {@link RemoteContext.callRemote}: throws
|
|
@@ -63,12 +73,6 @@ export type RemoteFunctionContext<TParams, TDeps = unknown, TKernel = BoundClien
|
|
|
63
73
|
selfKernel: (kernelUrl?: string) => Promise<BoundClientSessionView<FnMap>>;
|
|
64
74
|
};
|
|
65
75
|
export type RemoteFunctionDef<TParams = unknown, TResult = unknown, TDeps = unknown, TAuth extends AuthPolicy = 'required'> = {
|
|
66
|
-
/**
|
|
67
|
-
* Canonical callable identity. Auto-derived as `function.<slug>` (where
|
|
68
|
-
* `<slug>` is the map key) when omitted. Stored as `Function.ref` on the
|
|
69
|
-
* graph node and used by the kernel dispatcher to route the call.
|
|
70
|
-
*/
|
|
71
|
-
ref?: string;
|
|
72
76
|
/** Zod schema for the call's parameters. */
|
|
73
77
|
inputSchema: z.ZodType<TParams>;
|
|
74
78
|
/** Zod schema for the call's result. */
|
|
@@ -99,10 +103,21 @@ export type RemoteFunctionDef<TParams = unknown, TResult = unknown, TDeps = unkn
|
|
|
99
103
|
/** Optional human-readable description. */
|
|
100
104
|
description?: string;
|
|
101
105
|
};
|
|
102
|
-
export type AnyRemoteFunctionDef = RemoteFunctionDef<any, any, any, AuthPolicy
|
|
106
|
+
export type AnyRemoteFunctionDef = Omit<RemoteFunctionDef<any, any, any, AuthPolicy>, 'authorize' | 'execute'> & {
|
|
107
|
+
authorize?: (ctx: any) => void | Promise<void>;
|
|
108
|
+
execute: (ctx: any) => any;
|
|
109
|
+
};
|
|
110
|
+
type _AssertTrue<T extends true> = T;
|
|
111
|
+
type _FnFitsBag<D> = D extends AnyRemoteFunctionDef ? true : false;
|
|
112
|
+
export type _AuthPolicyBagGuards = [
|
|
113
|
+
_AssertTrue<_FnFitsBag<RemoteFunctionDef<unknown, unknown, unknown, 'public'>>>,
|
|
114
|
+
_AssertTrue<_FnFitsBag<RemoteFunctionDef<unknown, unknown, unknown, 'optional'>>>,
|
|
115
|
+
_AssertTrue<_FnFitsBag<RemoteFunctionDef<unknown, unknown, unknown, 'required'>>>
|
|
116
|
+
];
|
|
103
117
|
/**
|
|
104
118
|
* Identity helper for authoring a RemoteFunction. Returns its argument
|
|
105
119
|
* unchanged — `defineRemoteDomain` consumes the typed shape.
|
|
106
120
|
*/
|
|
107
121
|
export declare function defineRemoteFunction<TParams, TResult, TDeps = unknown, TAuth extends AuthPolicy = 'required'>(def: RemoteFunctionDef<TParams, TResult, TDeps, TAuth>): RemoteFunctionDef<TParams, TResult, TDeps, TAuth>;
|
|
122
|
+
export {};
|
|
108
123
|
//# sourceMappingURL=remote-function.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-function.d.ts","sourceRoot":"","sources":["../../src/define/remote-function.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-function.d.ts","sourceRoot":"","sources":["../../src/define/remote-function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAChF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAC3D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAErE,MAAM,MAAM,qBAAqB,CAC/B,OAAO,EACP,KAAK,GAAG,OAAO,EACf,OAAO,GAAG,sBAAsB,CAAC,KAAK,CAAC,GAAG,IAAI,EAC9C,KAAK,SAAS,UAAU,GAAG,UAAU,IACnC;IACF,4DAA4D;IAC5D,MAAM,EAAE,OAAO,CAAA;IACf,sEAAsE;IACtE,CAAC,EAAE,OAAO,CAAA;IACV;;;;OAIG;IACH,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,CAAA;IAC1B,6DAA6D;IAC7D,IAAI,EAAE,KAAK,CAAA;IACX;;;;;;;;;;OAUG;IACH,MAAM,EAAE,OAAO,CAAA;IACf;;;OAGG;IACH,MAAM,EAAE,YAAY,CAAA;IACpB;;;;;OAKG;IACH,UAAU,EAAE,YAAY,CAAA;IAC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AAE,GAAG,KAAK,GAAG,CAAA;CAC3B,CAAA;AAOD,KAAK,WAAW,CAAC,CAAC,SAAS,IAAI,IAAI,CAAC,CAAA;AACpC,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,oBAAoB,GAAG,IAAI,GAAG,KAAK,CAAA;AAKlE,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/E,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IACjF,WAAW,CAAC,UAAU,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;CAClF,CAAA;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EACP,OAAO,EACP,KAAK,GAAG,OAAO,EACf,KAAK,SAAS,UAAU,GAAG,UAAU,EAErC,GAAG,EAAE,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,GACrD,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAEnD"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Authoring a standalone remote function — a callable not bound to a class.
|
|
3
3
|
* (The verb keeps the `defineRemoteFunction` name; the node it materializes is
|
|
4
|
-
* the canonical kernel `Function` class, the former
|
|
4
|
+
* the canonical kernel `Function` class, replacing the former remote-function wrapper.)
|
|
5
5
|
*
|
|
6
6
|
* Each entry in `defineRemoteDomain({ remoteFunctions: { ... } })` becomes:
|
|
7
|
-
* - a graph node at `/${origin}/
|
|
8
|
-
* as the kernel `Function` class
|
|
9
|
-
* `
|
|
7
|
+
* - a graph node at `/${origin}/functions/<slug>` — a first-class domain MEMBER,
|
|
8
|
+
* materialized as the kernel `Function` class and attached to the Domain via an
|
|
9
|
+
* `of_domain` edge (slug `function.<slug>`), so it is addressable by the
|
|
10
|
+
* semantic path `/:${origin}:function.<slug>` (the form a `postInstall` uses).
|
|
10
11
|
* - a Hono route on the worker at the path implied by `binding`
|
|
11
|
-
* (`/<functionsFolder>/<slug>` POST by default —
|
|
12
|
+
* (`/<functionsFolder>/<slug>` POST by default — the route URL is decoupled
|
|
13
|
+
* from the graph layout).
|
|
12
14
|
*
|
|
13
|
-
* The slug = the map key (single source of truth, no duplication).
|
|
14
|
-
*
|
|
15
|
-
* `
|
|
16
|
-
* `Function.ref` on the graph node and as the dispatch key.
|
|
15
|
+
* The slug = the map key (single source of truth, no duplication). The member
|
|
16
|
+
* ref (`function.<slug>`), the layout (`/<origin>/functions/<slug>`), and the
|
|
17
|
+
* `of_domain` edge slug are all DERIVED from it — there is nothing else to name.
|
|
17
18
|
*/
|
|
18
19
|
/**
|
|
19
20
|
* Identity helper for authoring a RemoteFunction. Returns its argument
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote-function.js","sourceRoot":"","sources":["../../src/define/remote-function.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"remote-function.js","sourceRoot":"","sources":["../../src/define/remote-function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgJH;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAMlC,GAAsD;IAEtD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
package/dist/define/view.d.ts
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
* Authoring a `View` — iframe-mountable callable served by the domain worker.
|
|
3
3
|
*
|
|
4
4
|
* Each entry in `defineRemoteDomain({ views: { ... } })` becomes both:
|
|
5
|
-
* - a
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* - a first-class domain MEMBER: a `View` node at `/${origin}/views/<slug>`
|
|
6
|
+
* attached to the Domain via an `of_domain` edge (slug `view.<slug>`),
|
|
7
|
+
* addressable as `/:${origin}:view.<slug>`. `<slug>` is the map key, so it
|
|
8
|
+
* lives in exactly one place.
|
|
8
9
|
* - a Hono route on the worker at the path implied by `binding`
|
|
9
|
-
* (`/<viewsFolder>/<slug>` by default
|
|
10
|
+
* (`/<viewsFolder>/<slug>` by default).
|
|
10
11
|
*
|
|
11
|
-
* The
|
|
12
|
-
* lands in `Function.binding.remoteUrl` is
|
|
12
|
+
* The graph layout (`/<origin>/views/<slug>`) is a fixed kernel convention; the
|
|
13
|
+
* URL path that lands in `Function.binding.remoteUrl` is
|
|
14
|
+
* `${url}/<viewsFolder>/<slug>` — DECOUPLED from the graph layout.
|
|
13
15
|
*
|
|
14
16
|
* The author can override the URL via `binding` — host and/or path
|
|
15
17
|
* placeholders are supported (the kernel's `route` mechanism does the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/define/view.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/define/view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAChF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEtD,MAAM,MAAM,iBAAiB,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,SAAS,UAAU,GAAG,UAAU,IAAI;IACtF,+DAA+D;IAC/D,CAAC,EAAE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,KAAK,EAAE,KAAK,CAAC,CAEvB"}
|
package/dist/define/view.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
* Authoring a `View` — iframe-mountable callable served by the domain worker.
|
|
3
3
|
*
|
|
4
4
|
* Each entry in `defineRemoteDomain({ views: { ... } })` becomes both:
|
|
5
|
-
* - a
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* - a first-class domain MEMBER: a `View` node at `/${origin}/views/<slug>`
|
|
6
|
+
* attached to the Domain via an `of_domain` edge (slug `view.<slug>`),
|
|
7
|
+
* addressable as `/:${origin}:view.<slug>`. `<slug>` is the map key, so it
|
|
8
|
+
* lives in exactly one place.
|
|
8
9
|
* - a Hono route on the worker at the path implied by `binding`
|
|
9
|
-
* (`/<viewsFolder>/<slug>` by default
|
|
10
|
+
* (`/<viewsFolder>/<slug>` by default).
|
|
10
11
|
*
|
|
11
|
-
* The
|
|
12
|
-
* lands in `Function.binding.remoteUrl` is
|
|
12
|
+
* The graph layout (`/<origin>/views/<slug>`) is a fixed kernel convention; the
|
|
13
|
+
* URL path that lands in `Function.binding.remoteUrl` is
|
|
14
|
+
* `${url}/<viewsFolder>/<slug>` — DECOUPLED from the graph layout.
|
|
13
15
|
*
|
|
14
16
|
* The author can override the URL via `binding` — host and/or path
|
|
15
17
|
* placeholders are supported (the kernel's `route` mechanism does the
|
package/dist/define/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/define/view.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/define/view.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAsFH;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,GAA0B;IAE1B,OAAO,GAAG,CAAA;AACZ,CAAC"}
|