@opensaas/stack-core 0.44.0-alpha.6 → 0.44.0-alpha.7
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/CHANGELOG.md +655 -0
- package/dist/.build-hash +1 -1
- package/dist/access/actor.d.ts +56 -0
- package/dist/access/actor.d.ts.map +1 -0
- package/dist/access/actor.js +66 -0
- package/dist/access/actor.js.map +1 -0
- package/dist/access/decide-advertisement.d.ts +55 -0
- package/dist/access/decide-advertisement.d.ts.map +1 -0
- package/dist/access/decide-advertisement.js +125 -0
- package/dist/access/decide-advertisement.js.map +1 -0
- package/dist/access/declared-dependencies.d.ts +4 -89
- package/dist/access/declared-dependencies.d.ts.map +1 -1
- package/dist/access/declared-dependencies.js +14 -84
- package/dist/access/declared-dependencies.js.map +1 -1
- package/dist/access/depth-limits.d.ts +2 -0
- package/dist/access/depth-limits.d.ts.map +1 -1
- package/dist/access/depth-limits.js +2 -0
- package/dist/access/depth-limits.js.map +1 -1
- package/dist/access/engine.d.ts +1 -24
- package/dist/access/engine.d.ts.map +1 -1
- package/dist/access/engine.js +0 -35
- package/dist/access/engine.js.map +1 -1
- package/dist/access/field-access.d.ts +21 -19
- package/dist/access/field-access.d.ts.map +1 -1
- package/dist/access/field-access.js +100 -122
- package/dist/access/field-access.js.map +1 -1
- package/dist/access/index.d.ts +3 -6
- package/dist/access/index.d.ts.map +1 -1
- package/dist/access/index.js +3 -6
- package/dist/access/index.js.map +1 -1
- package/dist/access/rule-item.d.ts +7 -7
- package/dist/access/rule-item.d.ts.map +1 -1
- package/dist/access/rule-item.js +38 -38
- package/dist/access/rule-item.js.map +1 -1
- package/dist/access/session-vocabulary.d.ts +124 -0
- package/dist/access/session-vocabulary.d.ts.map +1 -0
- package/dist/access/session-vocabulary.js +366 -0
- package/dist/access/session-vocabulary.js.map +1 -0
- package/dist/access/transaction-registry.d.ts +6 -0
- package/dist/access/transaction-registry.d.ts.map +1 -1
- package/dist/access/transaction-registry.js +19 -2
- package/dist/access/transaction-registry.js.map +1 -1
- package/dist/access/types.d.ts +55 -6
- package/dist/access/types.d.ts.map +1 -1
- package/dist/access/vocabulary-filter-specs.d.ts +17 -0
- package/dist/access/vocabulary-filter-specs.d.ts.map +1 -0
- package/dist/access/vocabulary-filter-specs.js +27 -0
- package/dist/access/vocabulary-filter-specs.js.map +1 -0
- package/dist/client-safe.d.ts +8 -0
- package/dist/client-safe.d.ts.map +1 -0
- package/dist/client-safe.js +8 -0
- package/dist/client-safe.js.map +1 -0
- package/dist/config/field-kind.d.ts +7 -21
- package/dist/config/field-kind.d.ts.map +1 -1
- package/dist/config/field-kind.js +8 -5
- package/dist/config/field-kind.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +3 -2
- package/dist/config/index.js.map +1 -1
- package/dist/config/mcp-default-tools.d.ts +3 -0
- package/dist/config/mcp-default-tools.d.ts.map +1 -0
- package/dist/config/mcp-default-tools.js +14 -0
- package/dist/config/mcp-default-tools.js.map +1 -0
- package/dist/config/mcp-tool-names.d.ts +2 -0
- package/dist/config/mcp-tool-names.d.ts.map +1 -1
- package/dist/config/mcp-tool-names.js +17 -5
- package/dist/config/mcp-tool-names.js.map +1 -1
- package/dist/config/nav-count.d.ts +8 -16
- package/dist/config/nav-count.d.ts.map +1 -1
- package/dist/config/nav-count.js +20 -32
- package/dist/config/nav-count.js.map +1 -1
- package/dist/config/plugin-engine.d.ts.map +1 -1
- package/dist/config/plugin-engine.js +6 -0
- package/dist/config/plugin-engine.js.map +1 -1
- package/dist/config/types.d.ts +141 -28
- package/dist/config/types.d.ts.map +1 -1
- package/dist/context/engine-context.d.ts +2 -0
- package/dist/context/engine-context.d.ts.map +1 -1
- package/dist/context/engine-context.js +8 -0
- package/dist/context/engine-context.js.map +1 -1
- package/dist/context/hook-pipeline.d.ts +2 -1
- package/dist/context/hook-pipeline.d.ts.map +1 -1
- package/dist/context/hook-pipeline.js +4 -2
- package/dist/context/hook-pipeline.js.map +1 -1
- package/dist/context/index.d.ts +5 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +156 -84
- package/dist/context/index.js.map +1 -1
- package/dist/context/junction.d.ts +28 -21
- package/dist/context/junction.d.ts.map +1 -1
- package/dist/context/junction.js +74 -69
- package/dist/context/junction.js.map +1 -1
- package/dist/context/plugin-field-write.d.ts.map +1 -1
- package/dist/context/plugin-field-write.js +19 -25
- package/dist/context/plugin-field-write.js.map +1 -1
- package/dist/context/process-lifetime.d.ts +8 -0
- package/dist/context/process-lifetime.d.ts.map +1 -0
- package/dist/context/process-lifetime.js +14 -0
- package/dist/context/process-lifetime.js.map +1 -0
- package/dist/context/relationship-input.d.ts +2 -15
- package/dist/context/relationship-input.d.ts.map +1 -1
- package/dist/context/relationship-input.js +44 -85
- package/dist/context/relationship-input.js.map +1 -1
- package/dist/context/transaction-boundary.d.ts +3 -2
- package/dist/context/transaction-boundary.d.ts.map +1 -1
- package/dist/context/transaction-boundary.js +17 -2
- package/dist/context/transaction-boundary.js.map +1 -1
- package/dist/context/write-pipeline.d.ts +5 -19
- package/dist/context/write-pipeline.d.ts.map +1 -1
- package/dist/context/write-pipeline.js +40 -98
- package/dist/context/write-pipeline.js.map +1 -1
- package/dist/context/write-target.d.ts +52 -0
- package/dist/context/write-target.d.ts.map +1 -0
- package/dist/context/write-target.js +118 -0
- package/dist/context/write-target.js.map +1 -0
- package/dist/contract/dependencies.d.ts +24 -10
- package/dist/contract/dependencies.d.ts.map +1 -1
- package/dist/contract/dependencies.js +120 -80
- package/dist/contract/dependencies.js.map +1 -1
- package/dist/contract/derive.d.ts +6 -11
- package/dist/contract/derive.d.ts.map +1 -1
- package/dist/contract/derive.js +256 -211
- package/dist/contract/derive.js.map +1 -1
- package/dist/contract/id-boundary.js +1 -1
- package/dist/contract/id-boundary.js.map +1 -1
- package/dist/contract/strategy.d.ts +13 -0
- package/dist/contract/strategy.d.ts.map +1 -0
- package/dist/contract/strategy.js +38 -0
- package/dist/contract/strategy.js.map +1 -0
- package/dist/db/client-alias.d.ts +12 -0
- package/dist/db/client-alias.d.ts.map +1 -0
- package/dist/db/client-alias.js +8 -0
- package/dist/db/client-alias.js.map +1 -0
- package/dist/extend.d.ts +1 -1
- package/dist/extend.d.ts.map +1 -1
- package/dist/extend.js.map +1 -1
- package/dist/fields/index.d.ts +0 -3
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +25 -10
- package/dist/fields/index.js.map +1 -1
- package/dist/filter/collect.d.ts +28 -39
- package/dist/filter/collect.d.ts.map +1 -1
- package/dist/filter/collect.js +46 -68
- package/dist/filter/collect.js.map +1 -1
- package/dist/filter/index.d.ts +1 -1
- package/dist/filter/index.d.ts.map +1 -1
- package/dist/filter/index.js +1 -1
- package/dist/filter/index.js.map +1 -1
- package/dist/filter/map.d.ts +4 -0
- package/dist/filter/map.d.ts.map +1 -1
- package/dist/filter/map.js +36 -3
- package/dist/filter/map.js.map +1 -1
- package/dist/hooks/index.d.ts +4 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +34 -5
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.d.ts +8 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -5
- package/dist/internal.js.map +1 -1
- package/dist/mcp/advertise.d.ts +5 -13
- package/dist/mcp/advertise.d.ts.map +1 -1
- package/dist/mcp/advertise.js +7 -22
- package/dist/mcp/advertise.js.map +1 -1
- package/dist/mcp/arguments.d.ts.map +1 -1
- package/dist/mcp/arguments.js +8 -11
- package/dist/mcp/arguments.js.map +1 -1
- package/dist/mcp/field-schema.d.ts +4 -15
- package/dist/mcp/field-schema.d.ts.map +1 -1
- package/dist/mcp/field-schema.js +41 -71
- package/dist/mcp/field-schema.js.map +1 -1
- package/dist/mcp/handler.d.ts +111 -18
- package/dist/mcp/handler.d.ts.map +1 -1
- package/dist/mcp/handler.js +168 -73
- package/dist/mcp/handler.js.map +1 -1
- package/dist/mcp/index.d.ts +2 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/procedure-tools.d.ts +63 -0
- package/dist/mcp/procedure-tools.d.ts.map +1 -0
- package/dist/mcp/procedure-tools.js +139 -0
- package/dist/mcp/procedure-tools.js.map +1 -0
- package/dist/mcp/projection.d.ts.map +1 -1
- package/dist/mcp/projection.js +28 -36
- package/dist/mcp/projection.js.map +1 -1
- package/dist/mcp/reachability.d.ts +5 -1
- package/dist/mcp/reachability.d.ts.map +1 -1
- package/dist/mcp/reachability.js +24 -5
- package/dist/mcp/reachability.js.map +1 -1
- package/dist/mcp/relation-member.d.ts +15 -0
- package/dist/mcp/relation-member.d.ts.map +1 -0
- package/dist/mcp/relation-member.js +50 -0
- package/dist/mcp/relation-member.js.map +1 -0
- package/dist/mcp/types.d.ts +12 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.d.ts.map +1 -1
- package/dist/mcp/where-id-boundary.js +12 -24
- package/dist/mcp/where-id-boundary.js.map +1 -1
- package/dist/mcp/where-reachability.d.ts +2 -0
- package/dist/mcp/where-reachability.d.ts.map +1 -1
- package/dist/mcp/where-reachability.js +39 -23
- package/dist/mcp/where-reachability.js.map +1 -1
- package/dist/members/claims.d.ts +71 -0
- package/dist/members/claims.d.ts.map +1 -0
- package/dist/members/claims.js +199 -0
- package/dist/members/claims.js.map +1 -0
- package/dist/members/list-members.d.ts +87 -0
- package/dist/members/list-members.d.ts.map +1 -0
- package/dist/members/list-members.js +250 -0
- package/dist/members/list-members.js.map +1 -0
- package/dist/procedures/client.d.ts +163 -0
- package/dist/procedures/client.d.ts.map +1 -0
- package/dist/procedures/client.js +152 -0
- package/dist/procedures/client.js.map +1 -0
- package/dist/procedures/codes.d.ts +23 -0
- package/dist/procedures/codes.d.ts.map +1 -0
- package/dist/procedures/codes.js +46 -0
- package/dist/procedures/codes.js.map +1 -0
- package/dist/procedures/context-face.d.ts +4 -0
- package/dist/procedures/context-face.d.ts.map +1 -0
- package/dist/procedures/context-face.js +31 -0
- package/dist/procedures/context-face.js.map +1 -0
- package/dist/procedures/failures.d.ts +31 -0
- package/dist/procedures/failures.d.ts.map +1 -0
- package/dist/procedures/failures.js +51 -0
- package/dist/procedures/failures.js.map +1 -0
- package/dist/procedures/http.d.ts +114 -0
- package/dist/procedures/http.d.ts.map +1 -0
- package/dist/procedures/http.js +224 -0
- package/dist/procedures/http.js.map +1 -0
- package/dist/procedures/index.d.ts +7 -0
- package/dist/procedures/index.d.ts.map +1 -0
- package/dist/procedures/index.js +11 -0
- package/dist/procedures/index.js.map +1 -0
- package/dist/procedures/procedure.d.ts +204 -0
- package/dist/procedures/procedure.d.ts.map +1 -0
- package/dist/procedures/procedure.js +123 -0
- package/dist/procedures/procedure.js.map +1 -0
- package/dist/procedures/result.d.ts +42 -0
- package/dist/procedures/result.d.ts.map +1 -0
- package/dist/procedures/result.js +51 -0
- package/dist/procedures/result.js.map +1 -0
- package/dist/procedures/run.d.ts +36 -0
- package/dist/procedures/run.d.ts.map +1 -0
- package/dist/procedures/run.js +76 -0
- package/dist/procedures/run.js.map +1 -0
- package/dist/procedures/server.d.ts +131 -0
- package/dist/procedures/server.d.ts.map +1 -0
- package/dist/procedures/server.js +115 -0
- package/dist/procedures/server.js.map +1 -0
- package/dist/procedures/validate.d.ts +60 -0
- package/dist/procedures/validate.d.ts.map +1 -0
- package/dist/procedures/validate.js +254 -0
- package/dist/procedures/validate.js.map +1 -0
- package/dist/procedures/web-session.d.ts +12 -0
- package/dist/procedures/web-session.d.ts.map +1 -0
- package/dist/procedures/web-session.js +35 -0
- package/dist/procedures/web-session.js.map +1 -0
- package/dist/query/relationship-options.d.ts +2 -0
- package/dist/query/relationship-options.d.ts.map +1 -1
- package/dist/query/relationship-options.js +3 -2
- package/dist/query/relationship-options.js.map +1 -1
- package/dist/secured/binding.d.ts +84 -0
- package/dist/secured/binding.d.ts.map +1 -0
- package/dist/secured/binding.js +52 -0
- package/dist/secured/binding.js.map +1 -0
- package/dist/secured/declared-branch.d.ts +11 -0
- package/dist/secured/declared-branch.d.ts.map +1 -0
- package/dist/secured/declared-branch.js +17 -0
- package/dist/secured/declared-branch.js.map +1 -0
- package/dist/secured/field-visibility.d.ts +56 -0
- package/dist/secured/field-visibility.d.ts.map +1 -0
- package/dist/secured/field-visibility.js +624 -0
- package/dist/secured/field-visibility.js.map +1 -0
- package/dist/secured/include.d.ts +68 -41
- package/dist/secured/include.d.ts.map +1 -1
- package/dist/secured/include.js +217 -115
- package/dist/secured/include.js.map +1 -1
- package/dist/secured/lower.d.ts.map +1 -1
- package/dist/secured/lower.js +1 -3
- package/dist/secured/lower.js.map +1 -1
- package/dist/secured/read.d.ts +11 -108
- package/dist/secured/read.d.ts.map +1 -1
- package/dist/secured/read.js +46 -633
- package/dist/secured/read.js.map +1 -1
- package/dist/secured/select.d.ts +0 -24
- package/dist/secured/select.d.ts.map +1 -1
- package/dist/secured/select.js +60 -153
- package/dist/secured/select.js.map +1 -1
- package/dist/secured/vocabulary.d.ts +13 -1
- package/dist/secured/vocabulary.d.ts.map +1 -1
- package/dist/secured/vocabulary.js +173 -83
- package/dist/secured/vocabulary.js.map +1 -1
- package/dist/testing/untyped-rule.d.ts +8 -0
- package/dist/testing/untyped-rule.d.ts.map +1 -0
- package/dist/testing/untyped-rule.js +4 -0
- package/dist/testing/untyped-rule.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rows.d.ts +18 -1
- package/dist/types/rows.d.ts.map +1 -1
- package/dist/validation/config-refusal.d.ts +3 -1
- package/dist/validation/config-refusal.d.ts.map +1 -1
- package/dist/validation/database-config.d.ts +1 -0
- package/dist/validation/database-config.d.ts.map +1 -1
- package/dist/validation/database-config.js +1 -1
- package/dist/validation/database-config.js.map +1 -1
- package/dist/validation/default-value.d.ts.map +1 -1
- package/dist/validation/default-value.js +3 -8
- package/dist/validation/default-value.js.map +1 -1
- package/dist/validation/extension-packs.d.ts.map +1 -1
- package/dist/validation/extension-packs.js +1 -0
- package/dist/validation/extension-packs.js.map +1 -1
- package/dist/validation/field-config.d.ts +3 -2
- package/dist/validation/field-config.d.ts.map +1 -1
- package/dist/validation/field-config.js +3 -1
- package/dist/validation/field-config.js.map +1 -1
- package/dist/validation/field-names.d.ts +2 -1
- package/dist/validation/field-names.d.ts.map +1 -1
- package/dist/validation/field-names.js +76 -63
- package/dist/validation/field-names.js.map +1 -1
- package/dist/validation/identifier-names.d.ts +1 -0
- package/dist/validation/identifier-names.d.ts.map +1 -1
- package/dist/validation/identifier-names.js +17 -9
- package/dist/validation/identifier-names.js.map +1 -1
- package/dist/validation/needs-closure.d.ts +30 -14
- package/dist/validation/needs-closure.d.ts.map +1 -1
- package/dist/validation/needs-closure.js +184 -31
- package/dist/validation/needs-closure.js.map +1 -1
- package/dist/validation/schema.d.ts +1 -0
- package/dist/validation/schema.d.ts.map +1 -1
- package/dist/validation/schema.js +4 -2
- package/dist/validation/schema.js.map +1 -1
- package/package.json +20 -4
- package/dist/access/field-visibility.d.ts +0 -11
- package/dist/access/field-visibility.d.ts.map +0 -1
- package/dist/access/field-visibility.js +0 -366
- package/dist/access/field-visibility.js.map +0 -1
- package/dist/access/query-validation.d.ts +0 -30
- package/dist/access/query-validation.d.ts.map +0 -1
- package/dist/access/query-validation.js +0 -49
- package/dist/access/query-validation.js.map +0 -1
- package/dist/access/system-fields.d.ts +0 -2
- package/dist/access/system-fields.d.ts.map +0 -1
- package/dist/access/system-fields.js +0 -7
- package/dist/access/system-fields.js.map +0 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { OpenSaasConfig } from '../config/types.js';
|
|
2
|
+
import type { ProcedureArgsFor, ProcedureCodeOf, ProcedureDataOf, ProcedureNameOf } from './client.js';
|
|
3
|
+
import type { SessionOf } from './http.js';
|
|
4
|
+
import type { Procedure, ProcedureHostContext, ProcedureRegistry } from './procedure.js';
|
|
5
|
+
import { type ProcedureResult } from './result.js';
|
|
6
|
+
import { type UnexpectedErrorReporter } from './run.js';
|
|
7
|
+
/** The application context the procedures of `TRegistry` are typed to. */
|
|
8
|
+
export type RegistryContextOf<TRegistry> = TRegistry[keyof TRegistry] extends Procedure<infer C extends ProcedureHostContext, infer _TIn, infer _TOut, infer _TCode> ? C : never;
|
|
9
|
+
/** Options for {@link createServerCaller}. */
|
|
10
|
+
export interface ServerCallerOptions<TRegistry extends ProcedureRegistry<ProcedureHostContext>> {
|
|
11
|
+
/** The application's procedure registry. Only procedures exposing `'web'` are callable. */
|
|
12
|
+
procedures: TRegistry;
|
|
13
|
+
/**
|
|
14
|
+
* The resolved config, checked against the registry as `createProcedureHandler`
|
|
15
|
+
* checks it. Pass `await config` from `.opensaas/context.ts`. A framework's
|
|
16
|
+
* control flow is recognised by the built-in check and by the
|
|
17
|
+
* `isFrameworkControlFlow` of the config the context carries; this config's
|
|
18
|
+
* is the fallback, and the only one consulted for a throw from `getSession`,
|
|
19
|
+
* which happens before there is a context.
|
|
20
|
+
*/
|
|
21
|
+
config?: OpenSaasConfig;
|
|
22
|
+
/** The generated `getContext`: called with the resolved session, or with nothing when anonymous. */
|
|
23
|
+
getContext: (session?: SessionOf<RegistryContextOf<TRegistry>>) => Promise<RegistryContextOf<TRegistry>>;
|
|
24
|
+
/**
|
|
25
|
+
* Resolve the current request's session from the server, as from the
|
|
26
|
+
* request's cookies, and never from anything a caller passes. Called once
|
|
27
|
+
* per call and once per `context()`, and never cached, so two requests
|
|
28
|
+
* never share a session; wrapping it in React's `cache()` to share one
|
|
29
|
+
* lookup across a render is safe, since that cache is per request.
|
|
30
|
+
* Resolving `null` or `undefined` means anonymous.
|
|
31
|
+
*
|
|
32
|
+
* The caller sets `session.actor` to a human actor carrying the session's
|
|
33
|
+
* own `userId`, exactly as `createProcedureHandler` does: `userId` must be
|
|
34
|
+
* an own data property, not a getter, holding a non-empty string or a finite number.
|
|
35
|
+
*
|
|
36
|
+
* **The caller performs no cookie or `Origin` check.** Whatever this
|
|
37
|
+
* resolves is acted on as the signed-in person. In a Next.js server action
|
|
38
|
+
* the cross-site protection is Next's own server-action `Origin` check, and
|
|
39
|
+
* only there; widening `serverActions.allowedOrigins` widens this caller's
|
|
40
|
+
* exposure too. A route handler that calls `call` for a mutation must not
|
|
41
|
+
* answer `GET` and must check the request's origin itself, or serve the
|
|
42
|
+
* procedure through `createProcedureHandler` instead. Outside a request (a
|
|
43
|
+
* job, a script) there is no person to act for: this must resolve `null`,
|
|
44
|
+
* because any session it resolves there still gets
|
|
45
|
+
* `{ kind: 'human', userId, via: 'web' }`.
|
|
46
|
+
*/
|
|
47
|
+
getSession: () => Promise<SessionOf<RegistryContextOf<TRegistry>> | null | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Told of every failure the operator should see, with the procedure's name,
|
|
50
|
+
* as `createProcedureHandler`'s option of the same name is. Default
|
|
51
|
+
* `console.error`.
|
|
52
|
+
*/
|
|
53
|
+
onUnexpectedError?: UnexpectedErrorReporter;
|
|
54
|
+
}
|
|
55
|
+
/** The in-process caller {@link createServerCaller} returns. */
|
|
56
|
+
export interface ServerCaller<TRegistry extends ProcedureRegistry<ProcedureHostContext>> {
|
|
57
|
+
/**
|
|
58
|
+
* Call a procedure exposed to `'web'` by name, as the session `getSession`
|
|
59
|
+
* resolves for the current request. Never throws for an outcome of the
|
|
60
|
+
* pipeline: it resolves to `{ success: true, data }` or
|
|
61
|
+
* `{ success: false, error: { code, message, fieldErrors? } }`. A
|
|
62
|
+
* framework's control flow (`redirect()`, `notFound()`) thrown from the
|
|
63
|
+
* session resolver, the access rule or `run` is rethrown, so the framework
|
|
64
|
+
* acts on it; a transaction it leaves is rolled back first.
|
|
65
|
+
*
|
|
66
|
+
* The name's type is every key of the registry and does not reflect
|
|
67
|
+
* exposure: a procedure exposed only to `'mcp'` type-checks here, and at
|
|
68
|
+
* runtime answers `INTERNAL`, reported, as an unknown name does.
|
|
69
|
+
*/
|
|
70
|
+
call: <TName extends ProcedureNameOf<TRegistry>>(name: TName, ...args: ProcedureArgsFor<TRegistry, TName>) => Promise<ProcedureResult<ProcedureDataOf<TRegistry[TName]>, ProcedureCodeOf<TRegistry[TName]>>>;
|
|
71
|
+
/**
|
|
72
|
+
* The context for the current request's session, for a server component's
|
|
73
|
+
* reads through `context.db`. The session carries the same human actor a
|
|
74
|
+
* call does. Rejects with what resolving the session threw, a
|
|
75
|
+
* `ProcedureHostError` for a session with no usable `userId`, or the
|
|
76
|
+
* `InvalidSessionError` `getContext` throws.
|
|
77
|
+
*/
|
|
78
|
+
context: () => Promise<RegistryContextOf<TRegistry>>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The in-process host for server code running inside a request: a Next.js
|
|
82
|
+
* server action, and a server component through `context`. `call` runs a procedure through the same
|
|
83
|
+
* pipeline as `createProcedureHandler`, with the same exposure, access rule,
|
|
84
|
+
* input and output parsing, declared failures, result and redaction, and
|
|
85
|
+
* `context` gives a server component the context for the same session.
|
|
86
|
+
*
|
|
87
|
+
* Neither takes a session. Each resolves it with `getSession` on every call,
|
|
88
|
+
* and the session carries a human actor the caller sets itself. A procedure
|
|
89
|
+
* not exposed to `'web'` answers exactly as an unknown name does: `INTERNAL`,
|
|
90
|
+
* reported to `onUnexpectedError`. Unlike the HTTP host, a framework's control
|
|
91
|
+
* flow propagates, so a procedure may `redirect()`; over HTTP it is `INTERNAL`.
|
|
92
|
+
*
|
|
93
|
+
* **It performs no cookie or `Origin` check of its own.** A server action is
|
|
94
|
+
* protected by Next's server-action `Origin` check and nothing else, and
|
|
95
|
+
* widening `serverActions.allowedOrigins` widens this caller too. A route
|
|
96
|
+
* handler calling `call` for a mutation must answer only non-`GET` methods
|
|
97
|
+
* and check the origin itself, or serve the procedure through
|
|
98
|
+
* `createProcedureHandler`. A job or script outside a request must have
|
|
99
|
+
* `getSession` resolve `null`: any session it resolves there is acted on as
|
|
100
|
+
* a human on the web.
|
|
101
|
+
*
|
|
102
|
+
* Keep the module that creates the caller the one place that imports the
|
|
103
|
+
* generated `getContext`, and export `call` and `context` from it.
|
|
104
|
+
*
|
|
105
|
+
* @typeParam TRegistry - the registry's own type. Declare the registry with
|
|
106
|
+
* `satisfies ProcedureRegistry<Context>` rather than annotating it, so each
|
|
107
|
+
* name keeps its own procedure type.
|
|
108
|
+
*
|
|
109
|
+
* @throws {ProcedureHostError} for a registry a host refuses. See {@link assertProcedureRegistry}.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // lib/server.ts
|
|
114
|
+
* import { createServerCaller } from '@opensaas/stack-core/procedures'
|
|
115
|
+
* import { config, getContext } from '@/.opensaas/context'
|
|
116
|
+
* import { procedures } from '@/lib/procedures'
|
|
117
|
+
* import { getSession } from '@/lib/auth'
|
|
118
|
+
*
|
|
119
|
+
* const server = createServerCaller({
|
|
120
|
+
* procedures,
|
|
121
|
+
* config: await config,
|
|
122
|
+
* getContext,
|
|
123
|
+
* getSession,
|
|
124
|
+
* })
|
|
125
|
+
*
|
|
126
|
+
* export const callProcedure = server.call
|
|
127
|
+
* export const getServerContext = server.context
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export declare function createServerCaller<TRegistry extends ProcedureRegistry<ProcedureHostContext>>(options: ServerCallerOptions<TRegistry>): ServerCaller<TRegistry>;
|
|
131
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/procedures/server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAExD,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAA;A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,EACX,GAAG,IAAI,EAAE,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,KACxC,OAAO,CACV,eAAe,CAAC,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CACtF,CAAA;IACD;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAA;CACrD;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,SAAS,iBAAiB,CAAC,oBAAoB,CAAC,EAC1F,OAAO,EAAE,mBAAmB,CAAC,SAAS,CAAC,GACtC,YAAY,CAAC,SAAS,CAAC,CAwEzB"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { controlFlowPredicateOf, rethrowControlFlow } from '../access/decide-advertisement.js';
|
|
2
|
+
import { engineFaceOf } from '../context/engine-context.js';
|
|
3
|
+
import { failure, isReservedFailureCode } from './result.js';
|
|
4
|
+
import { guardReporter, runProcedure } from './run.js';
|
|
5
|
+
import { assertProcedureRegistry, ProcedureHostError } from './validate.js';
|
|
6
|
+
import { webProcedureOf, webSessionOf } from './web-session.js';
|
|
7
|
+
function defaultUnexpectedError(error, procedureName) {
|
|
8
|
+
console.error(`Procedure "${procedureName}" failed:`, error);
|
|
9
|
+
}
|
|
10
|
+
function isOutcomeOf(procedure, result) {
|
|
11
|
+
if (result.success)
|
|
12
|
+
return true;
|
|
13
|
+
const { code } = result.error;
|
|
14
|
+
return isReservedFailureCode(code) || Object.hasOwn(procedure.failures, code);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The in-process host for server code running inside a request: a Next.js
|
|
18
|
+
* server action, and a server component through `context`. `call` runs a procedure through the same
|
|
19
|
+
* pipeline as `createProcedureHandler`, with the same exposure, access rule,
|
|
20
|
+
* input and output parsing, declared failures, result and redaction, and
|
|
21
|
+
* `context` gives a server component the context for the same session.
|
|
22
|
+
*
|
|
23
|
+
* Neither takes a session. Each resolves it with `getSession` on every call,
|
|
24
|
+
* and the session carries a human actor the caller sets itself. A procedure
|
|
25
|
+
* not exposed to `'web'` answers exactly as an unknown name does: `INTERNAL`,
|
|
26
|
+
* reported to `onUnexpectedError`. Unlike the HTTP host, a framework's control
|
|
27
|
+
* flow propagates, so a procedure may `redirect()`; over HTTP it is `INTERNAL`.
|
|
28
|
+
*
|
|
29
|
+
* **It performs no cookie or `Origin` check of its own.** A server action is
|
|
30
|
+
* protected by Next's server-action `Origin` check and nothing else, and
|
|
31
|
+
* widening `serverActions.allowedOrigins` widens this caller too. A route
|
|
32
|
+
* handler calling `call` for a mutation must answer only non-`GET` methods
|
|
33
|
+
* and check the origin itself, or serve the procedure through
|
|
34
|
+
* `createProcedureHandler`. A job or script outside a request must have
|
|
35
|
+
* `getSession` resolve `null`: any session it resolves there is acted on as
|
|
36
|
+
* a human on the web.
|
|
37
|
+
*
|
|
38
|
+
* Keep the module that creates the caller the one place that imports the
|
|
39
|
+
* generated `getContext`, and export `call` and `context` from it.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam TRegistry - the registry's own type. Declare the registry with
|
|
42
|
+
* `satisfies ProcedureRegistry<Context>` rather than annotating it, so each
|
|
43
|
+
* name keeps its own procedure type.
|
|
44
|
+
*
|
|
45
|
+
* @throws {ProcedureHostError} for a registry a host refuses. See {@link assertProcedureRegistry}.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* // lib/server.ts
|
|
50
|
+
* import { createServerCaller } from '@opensaas/stack-core/procedures'
|
|
51
|
+
* import { config, getContext } from '@/.opensaas/context'
|
|
52
|
+
* import { procedures } from '@/lib/procedures'
|
|
53
|
+
* import { getSession } from '@/lib/auth'
|
|
54
|
+
*
|
|
55
|
+
* const server = createServerCaller({
|
|
56
|
+
* procedures,
|
|
57
|
+
* config: await config,
|
|
58
|
+
* getContext,
|
|
59
|
+
* getSession,
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* export const callProcedure = server.call
|
|
63
|
+
* export const getServerContext = server.context
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function createServerCaller(options) {
|
|
67
|
+
const { procedures, getContext, getSession } = options;
|
|
68
|
+
const onUnexpectedError = guardReporter(options.onUnexpectedError ?? defaultUnexpectedError);
|
|
69
|
+
const isFrameworkControlFlow = options.config?.isFrameworkControlFlow;
|
|
70
|
+
assertProcedureRegistry(procedures, { config: options.config });
|
|
71
|
+
const contextFor = (session) => session === null ? getContext() : getContext(session);
|
|
72
|
+
const context = async () => contextFor(webSessionOf(await getSession()));
|
|
73
|
+
async function invoke(name, input) {
|
|
74
|
+
const procedure = webProcedureOf(procedures, name);
|
|
75
|
+
if (procedure === undefined) {
|
|
76
|
+
onUnexpectedError(new ProcedureHostError(`No procedure named "${name}" is exposed to 'web'.`), name);
|
|
77
|
+
return failure('INTERNAL');
|
|
78
|
+
}
|
|
79
|
+
let session;
|
|
80
|
+
try {
|
|
81
|
+
session = webSessionOf(await getSession());
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
rethrowControlFlow(error, isFrameworkControlFlow);
|
|
85
|
+
onUnexpectedError(error, name);
|
|
86
|
+
return failure('INTERNAL');
|
|
87
|
+
}
|
|
88
|
+
let resolved;
|
|
89
|
+
const result = await runProcedure({
|
|
90
|
+
name,
|
|
91
|
+
procedure,
|
|
92
|
+
context: async () => {
|
|
93
|
+
resolved = await contextFor(session);
|
|
94
|
+
return resolved;
|
|
95
|
+
},
|
|
96
|
+
readInput: () => ({ ok: true, value: input }),
|
|
97
|
+
onUnexpectedError,
|
|
98
|
+
propagate: (error) => {
|
|
99
|
+
const engine = resolved === undefined ? undefined : engineFaceOf(resolved);
|
|
100
|
+
rethrowControlFlow(error, engine === undefined
|
|
101
|
+
? isFrameworkControlFlow
|
|
102
|
+
: controlFlowPredicateOf(engine, options.config));
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
if (isOutcomeOf(procedure, result))
|
|
106
|
+
return result;
|
|
107
|
+
onUnexpectedError(new ProcedureHostError(`Procedure "${name}" failed with a code it does not declare.`), name);
|
|
108
|
+
return failure('INTERNAL');
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
call: (name, ...args) => invoke(name, args[0]),
|
|
112
|
+
context,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/procedures/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAE9F,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAS3D,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAwB,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAA;AACpF,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AA6F/D,SAAS,sBAAsB,CAAC,KAAc,EAAE,aAAqB;IACnE,OAAO,CAAC,KAAK,CAAC,cAAc,aAAa,WAAW,EAAE,KAAK,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,WAAW,CAClB,SAA0C,EAC1C,MAAwC;IAExC,IAAI,MAAM,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,CAAA;IAC7B,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AA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
|
|
3
|
+
/** Thrown when a host is created over options or a registry it cannot serve. */
|
|
4
|
+
export declare class ProcedureHostError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Which of a procedure's two schemas a refusal is about. */
|
|
8
|
+
export type ProcedureSchemaSide = 'input' | 'output';
|
|
9
|
+
/** The schemas a host checks. Every procedure the builder defines carries them. */
|
|
10
|
+
export interface ProcedureSchemas {
|
|
11
|
+
readonly input: z.ZodType;
|
|
12
|
+
readonly output: z.ZodType;
|
|
13
|
+
}
|
|
14
|
+
/** What {@link assertProcedureRegistry} checks a registry against. */
|
|
15
|
+
export interface ProcedureRegistryChecks {
|
|
16
|
+
/**
|
|
17
|
+
* The resolved config. With it, a procedure named like one of its list
|
|
18
|
+
* custom tools or plugin-registered MCP tools is refused. Without it only
|
|
19
|
+
* the reserved generated-tool pattern is checked.
|
|
20
|
+
*/
|
|
21
|
+
config?: OpenSaasConfig;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Refuses a procedure whose schemas cannot be carried on the wire: `input`
|
|
25
|
+
* must convert to JSON Schema on its input side and `output` on its output
|
|
26
|
+
* side, which rules out dates, bigints and output transforms, and neither may
|
|
27
|
+
* hold `z.file()` or one of the open-ended shapes Zod provides, at any depth:
|
|
28
|
+
* `z.any()`, `z.unknown()`, `z.json()`, a loose object, a `z.looseRecord` or a
|
|
29
|
+
* `z.record` of `any`/`unknown`. An output object with a `.catchall()` is
|
|
30
|
+
* refused too, because it returns keys the schema does not declare.
|
|
31
|
+
*
|
|
32
|
+
* A hand-written schema that accepts as much as those do, such as a recursive
|
|
33
|
+
* union of every JSON type under another shape, is not recognised.
|
|
34
|
+
*
|
|
35
|
+
* Every host calls this when it is created.
|
|
36
|
+
*
|
|
37
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
38
|
+
*/
|
|
39
|
+
export declare function assertProcedureSchemas(name: string, procedure: ProcedureSchemas): void;
|
|
40
|
+
/**
|
|
41
|
+
* Refuses a procedure name that collides in the namespace procedures share
|
|
42
|
+
* with MCP tools. A name matching the reserved `list_<list>_<operation>`
|
|
43
|
+
* pattern is refused whether or not that generated tool is enabled, or its
|
|
44
|
+
* list exists. With a `config`, a name a list custom tool or a
|
|
45
|
+
* plugin-registered tool already carries is refused as well.
|
|
46
|
+
*
|
|
47
|
+
* @throws {ProcedureHostError} naming the procedure, what it clashes with and the fix.
|
|
48
|
+
*/
|
|
49
|
+
export declare function assertProcedureNamesAvailable(names: Iterable<string>, config?: OpenSaasConfig): void;
|
|
50
|
+
/**
|
|
51
|
+
* Everything a host checks about a registry when it is created: each name is
|
|
52
|
+
* well formed, each entry was defined by the generated `procedure` builder,
|
|
53
|
+
* each procedure's schemas can be carried on the wire
|
|
54
|
+
* ({@link assertProcedureSchemas}) and no name collides with an MCP tool
|
|
55
|
+
* ({@link assertProcedureNamesAvailable}).
|
|
56
|
+
*
|
|
57
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertProcedureRegistry(procedures: Readonly<Record<string, ProcedureSchemas>>, checks?: ProcedureRegistryChecks): void;
|
|
60
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/procedures/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAKxD,gFAAgF;AAChF,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,6DAA6D;AAC7D,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEpD,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAA;CAC3B;AAED,sEAAsE;AACtE,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;CACxB;AA4MD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,GAAG,IAAI,CAGtF;AAQD;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EACvB,MAAM,CAAC,EAAE,cAAc,GACtB,IAAI,CAmBN;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC,EACtD,MAAM,GAAE,uBAA4B,GACnC,IAAI,CAuBN"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
import { findMcpToolOwner, isReservedMcpToolName } from '../config/mcp-tool-names.js';
|
|
3
|
+
import { PROCEDURE_NAME_PATTERN } from './codes.js';
|
|
4
|
+
import { isProcedure } from './procedure.js';
|
|
5
|
+
import { isReservedFailureCode } from './result.js';
|
|
6
|
+
/** Thrown when a host is created over options or a registry it cannot serve. */
|
|
7
|
+
export class ProcedureHostError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'ProcedureHostError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const COMBINATORS = new Set(['anyOf', 'oneOf', 'allOf']);
|
|
14
|
+
function describePath(side, path) {
|
|
15
|
+
let described = side;
|
|
16
|
+
for (let index = 0; index < path.length; index++) {
|
|
17
|
+
const segment = path[index];
|
|
18
|
+
if (segment === 'properties') {
|
|
19
|
+
described += `.${String(path[++index])}`;
|
|
20
|
+
}
|
|
21
|
+
else if (segment === 'prefixItems') {
|
|
22
|
+
described += `[${String(path[++index])}]`;
|
|
23
|
+
}
|
|
24
|
+
else if (segment === 'items') {
|
|
25
|
+
described += '[]';
|
|
26
|
+
}
|
|
27
|
+
else if (segment === 'additionalProperties') {
|
|
28
|
+
described += '[key]';
|
|
29
|
+
}
|
|
30
|
+
else if (typeof segment === 'string' && COMBINATORS.has(segment)) {
|
|
31
|
+
index++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return described;
|
|
35
|
+
}
|
|
36
|
+
function isOpenEnded(schema) {
|
|
37
|
+
const { type } = schema._zod.def;
|
|
38
|
+
return type === 'any' || type === 'unknown';
|
|
39
|
+
}
|
|
40
|
+
const JSON_VALUE_OPTIONS = 'array,boolean,null,number,record,string';
|
|
41
|
+
function isJsonValue(schema) {
|
|
42
|
+
if (!(schema instanceof z.core.$ZodLazy))
|
|
43
|
+
return false;
|
|
44
|
+
const union = schema._zod.innerType;
|
|
45
|
+
if (!(union instanceof z.core.$ZodUnion))
|
|
46
|
+
return false;
|
|
47
|
+
const { options } = union._zod.def;
|
|
48
|
+
const kinds = options.map((option) => option._zod.def.type).sort();
|
|
49
|
+
return (kinds.join(',') === JSON_VALUE_OPTIONS &&
|
|
50
|
+
options.every((option) => {
|
|
51
|
+
if (option instanceof z.core.$ZodArray)
|
|
52
|
+
return option._zod.def.element === schema;
|
|
53
|
+
if (option instanceof z.core.$ZodRecord)
|
|
54
|
+
return option._zod.def.valueType === schema;
|
|
55
|
+
return true;
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
function openEndedFinding(schema, side, path) {
|
|
59
|
+
const { def } = schema._zod;
|
|
60
|
+
if (def.type === 'any' || def.type === 'unknown') {
|
|
61
|
+
return {
|
|
62
|
+
path,
|
|
63
|
+
problem: `is \`z.${def.type}()\`, which accepts any value`,
|
|
64
|
+
fix: 'Declare the shape it carries, for example `z.string()` or `z.object({ … })`.',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (isJsonValue(schema)) {
|
|
68
|
+
return {
|
|
69
|
+
path,
|
|
70
|
+
problem: 'is `z.json()` or its equivalent, which accepts any JSON value',
|
|
71
|
+
fix: 'Declare the shape it carries, for example `z.string()` or `z.object({ … })`.',
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (def.type === 'file') {
|
|
75
|
+
return {
|
|
76
|
+
path,
|
|
77
|
+
problem: 'is `z.file()`, which a JSON body cannot carry',
|
|
78
|
+
fix: 'Carry the bytes as a base64 string with `z.base64()`, or upload the file to storage and pass its reference.',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (def.type === 'object' && def.catchall !== undefined) {
|
|
82
|
+
if (isOpenEnded(def.catchall)) {
|
|
83
|
+
return {
|
|
84
|
+
path,
|
|
85
|
+
problem: 'is a loose object (`z.looseObject` or `.passthrough()`), which lets undeclared keys through',
|
|
86
|
+
fix: 'Use `z.object({ … })`, which removes undeclared keys, or `z.strictObject({ … })`, which refuses them.',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (side === 'output' && def.catchall._zod.def.type !== 'never') {
|
|
90
|
+
return {
|
|
91
|
+
path,
|
|
92
|
+
problem: 'has a `.catchall()`, which returns keys the schema does not declare',
|
|
93
|
+
fix: 'Use `z.object({ … })` or `z.strictObject({ … })`, or a `z.record` with a declared value type when the value is a map.',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (def.type === 'record' && def.mode === 'loose') {
|
|
98
|
+
return {
|
|
99
|
+
path,
|
|
100
|
+
problem: 'is a `z.looseRecord`, which lets keys its key schema does not match through with any value',
|
|
101
|
+
fix: 'Use `z.record`, which refuses a key its key schema does not match.',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (def.type === 'record' && isOpenEnded(def.valueType)) {
|
|
105
|
+
return {
|
|
106
|
+
path,
|
|
107
|
+
problem: 'is a `z.record` of values of any type',
|
|
108
|
+
fix: 'Declare the value type, for example `z.record(z.string(), z.string())`.',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const NO_VALUE_FIX = 'For a procedure that takes no input use `z.object({}).optional()`; for one that returns nothing use `z.null()` and return `null`.';
|
|
114
|
+
const UNREPRESENTABLE_FIXES = {
|
|
115
|
+
date: 'Use `z.iso.datetime()` and carry the date as an ISO string.',
|
|
116
|
+
bigint: 'Use `z.string()` and carry the value as a decimal string, or `z.int()` when it fits.',
|
|
117
|
+
transform: 'Move the transform into `run` and declare the shape `run` returns; an input schema may still transform.',
|
|
118
|
+
undefined: NO_VALUE_FIX,
|
|
119
|
+
void: NO_VALUE_FIX,
|
|
120
|
+
map: 'Use `z.record` with a declared value type.',
|
|
121
|
+
set: 'Use `z.array`.',
|
|
122
|
+
symbol: 'Use `z.string()`.',
|
|
123
|
+
nan: 'Use `z.number()`.',
|
|
124
|
+
custom: 'Use a built-in Zod type that describes the value.',
|
|
125
|
+
function: 'Use a built-in Zod type that describes the value.',
|
|
126
|
+
};
|
|
127
|
+
const GENERIC_FIX = 'Use a schema whose values JSON can carry.';
|
|
128
|
+
const LITERAL_UNDEFINED_FIX = 'Use `z.null()` for an empty value, or make the key optional with `.optional()`.';
|
|
129
|
+
function unrepresentableFix(schema) {
|
|
130
|
+
const { def } = schema._zod;
|
|
131
|
+
if (def.type !== 'literal')
|
|
132
|
+
return UNREPRESENTABLE_FIXES[def.type] ?? GENERIC_FIX;
|
|
133
|
+
const first = def.values.find((value) => value === undefined || typeof value === 'bigint');
|
|
134
|
+
return typeof first === 'bigint'
|
|
135
|
+
? (UNREPRESENTABLE_FIXES.bigint ?? GENERIC_FIX)
|
|
136
|
+
: LITERAL_UNDEFINED_FIX;
|
|
137
|
+
}
|
|
138
|
+
function byPath(left, right) {
|
|
139
|
+
return left.path.join('/').localeCompare(right.path.join('/'));
|
|
140
|
+
}
|
|
141
|
+
function isCatchallOf(candidate, parent) {
|
|
142
|
+
return (candidate.length === parent.length + 1 &&
|
|
143
|
+
candidate[parent.length] === 'additionalProperties' &&
|
|
144
|
+
parent.every((segment, index) => candidate[index] === segment));
|
|
145
|
+
}
|
|
146
|
+
function assertSchemaSide(name, side, schema) {
|
|
147
|
+
const findings = [];
|
|
148
|
+
const unrepresentable = [];
|
|
149
|
+
try {
|
|
150
|
+
z.toJSONSchema(schema, {
|
|
151
|
+
io: side,
|
|
152
|
+
unrepresentable: ({ zodSchema, path, message }) => {
|
|
153
|
+
unrepresentable.push({ path, schema: zodSchema, message });
|
|
154
|
+
return 'throw';
|
|
155
|
+
},
|
|
156
|
+
override: ({ zodSchema, path }) => {
|
|
157
|
+
const finding = openEndedFinding(zodSchema, side, path);
|
|
158
|
+
if (finding !== undefined)
|
|
159
|
+
findings.push(finding);
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const located = unrepresentable[0];
|
|
165
|
+
if (located === undefined) {
|
|
166
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
167
|
+
throw new ProcedureHostError(`Procedure "${name}": the ${side} schema cannot be converted to JSON Schema, and Zod does not say which part of it is at fault (${reason}). Change the schema until \`z.toJSONSchema(schema, { io: '${side}' })\` succeeds.`);
|
|
168
|
+
}
|
|
169
|
+
throw new ProcedureHostError(`Procedure "${name}": \`${describePath(side, located.path)}\` cannot be converted to JSON Schema on its ${side} side (${located.message}). ${unrepresentableFix(located.schema)}`);
|
|
170
|
+
}
|
|
171
|
+
const reported = findings
|
|
172
|
+
.filter((finding) => !findings.some((parent) => isCatchallOf(finding.path, parent.path)))
|
|
173
|
+
.sort(byPath)[0];
|
|
174
|
+
if (reported !== undefined) {
|
|
175
|
+
throw new ProcedureHostError(`Procedure "${name}": \`${describePath(side, reported.path)}\` ${reported.problem}. ${reported.fix}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Refuses a procedure whose schemas cannot be carried on the wire: `input`
|
|
180
|
+
* must convert to JSON Schema on its input side and `output` on its output
|
|
181
|
+
* side, which rules out dates, bigints and output transforms, and neither may
|
|
182
|
+
* hold `z.file()` or one of the open-ended shapes Zod provides, at any depth:
|
|
183
|
+
* `z.any()`, `z.unknown()`, `z.json()`, a loose object, a `z.looseRecord` or a
|
|
184
|
+
* `z.record` of `any`/`unknown`. An output object with a `.catchall()` is
|
|
185
|
+
* refused too, because it returns keys the schema does not declare.
|
|
186
|
+
*
|
|
187
|
+
* A hand-written schema that accepts as much as those do, such as a recursive
|
|
188
|
+
* union of every JSON type under another shape, is not recognised.
|
|
189
|
+
*
|
|
190
|
+
* Every host calls this when it is created.
|
|
191
|
+
*
|
|
192
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
193
|
+
*/
|
|
194
|
+
export function assertProcedureSchemas(name, procedure) {
|
|
195
|
+
assertSchemaSide(name, 'input', procedure.input);
|
|
196
|
+
assertSchemaSide(name, 'output', procedure.output);
|
|
197
|
+
}
|
|
198
|
+
function isResolvedConfig(config) {
|
|
199
|
+
if (typeof config !== 'object' || config === null)
|
|
200
|
+
return false;
|
|
201
|
+
const lists = Reflect.get(config, 'lists');
|
|
202
|
+
return typeof lists === 'object' && lists !== null;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Refuses a procedure name that collides in the namespace procedures share
|
|
206
|
+
* with MCP tools. A name matching the reserved `list_<list>_<operation>`
|
|
207
|
+
* pattern is refused whether or not that generated tool is enabled, or its
|
|
208
|
+
* list exists. With a `config`, a name a list custom tool or a
|
|
209
|
+
* plugin-registered tool already carries is refused as well.
|
|
210
|
+
*
|
|
211
|
+
* @throws {ProcedureHostError} naming the procedure, what it clashes with and the fix.
|
|
212
|
+
*/
|
|
213
|
+
export function assertProcedureNamesAvailable(names, config) {
|
|
214
|
+
if (config !== undefined && !isResolvedConfig(config)) {
|
|
215
|
+
throw new ProcedureHostError('The `config` a procedure host is given is not a resolved config. A config with plugins is a promise; pass the resolved one, `config: await config`.');
|
|
216
|
+
}
|
|
217
|
+
for (const name of names) {
|
|
218
|
+
if (isReservedMcpToolName(name)) {
|
|
219
|
+
throw new ProcedureHostError(`Procedure "${name}": the name matches the reserved list_<list>_<operation> pattern of generated MCP tools. Rename the procedure, for example to a verb phrase such as "publishPost".`);
|
|
220
|
+
}
|
|
221
|
+
const owner = config === undefined ? undefined : findMcpToolOwner(config, name);
|
|
222
|
+
if (owner !== undefined) {
|
|
223
|
+
throw new ProcedureHostError(`Procedure "${name}": the name is already taken by ${owner}. Procedures and MCP tools share one namespace; rename the procedure or that tool.`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Everything a host checks about a registry when it is created: each name is
|
|
229
|
+
* well formed, each entry was defined by the generated `procedure` builder,
|
|
230
|
+
* each procedure's schemas can be carried on the wire
|
|
231
|
+
* ({@link assertProcedureSchemas}) and no name collides with an MCP tool
|
|
232
|
+
* ({@link assertProcedureNamesAvailable}).
|
|
233
|
+
*
|
|
234
|
+
* @throws {ProcedureHostError} naming the procedure, the offending part and the fix.
|
|
235
|
+
*/
|
|
236
|
+
export function assertProcedureRegistry(procedures, checks = {}) {
|
|
237
|
+
const names = Object.keys(procedures);
|
|
238
|
+
for (const name of names) {
|
|
239
|
+
if (!PROCEDURE_NAME_PATTERN.test(name)) {
|
|
240
|
+
throw new ProcedureHostError(`Procedure name "${name}" must start with a letter and contain only letters, digits, "_" and "-" (at most 64 characters). Rename the registry key.`);
|
|
241
|
+
}
|
|
242
|
+
const entry = procedures[name];
|
|
243
|
+
if (!isProcedure(entry)) {
|
|
244
|
+
throw new ProcedureHostError(`Registry entry "${name}" is not a procedure. Define it with the generated \`procedure\` builder.`);
|
|
245
|
+
}
|
|
246
|
+
const reserved = Object.keys(entry.failures).find(isReservedFailureCode);
|
|
247
|
+
if (reserved !== undefined) {
|
|
248
|
+
throw new ProcedureHostError(`Procedure "${name}" declares the failure code "${reserved}", which is reserved. Declare a code of its own.`);
|
|
249
|
+
}
|
|
250
|
+
assertProcedureSchemas(name, entry);
|
|
251
|
+
}
|
|
252
|
+
assertProcedureNamesAvailable(names, checks.config);
|
|
253
|
+
}
|
|
254
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/procedures/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD,gFAAgF;AAChF,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,CAAC;CACF;AA6BD,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;AAE7E,SAAS,YAAY,CAAC,IAAyB,EAAE,IAAgB;IAC/D,IAAI,SAAS,GAAW,IAAI,CAAA;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QAC3B,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;YAC7B,SAAS,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAA;QAC1C,CAAC;aAAM,IAAI,OAAO,KAAK,aAAa,EAAE,CAAC;YACrC,SAAS,IAAI,IAAI,M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,EAAE,IAAI,CAAC,CAAA;QAC/E,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,kBAAkB,CAC1B,cAAc,IAAI,mCAAmC,KAAK,oFAAoF,CAC/I,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CACrC,UAAsD,EACtD,MAAM,GAA4B,EAAE;IAEpC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACrC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,kBAAkB,CAC1B,mBAAmB,IAAI,4HAA4H,CACpJ,CAAA;QACH,CAAC;QACD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;QAC9B,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,kBAAkB,CAC1B,mBAAmB,IAAI,2EAA2E,CACnG,CAAA;QACH,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;QACxE,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,IAAI,kBAAkB,CAC1B,cAAc,IAAI,gCAAgC,QAAQ,kDAAkD,CAC7G,CAAA;QACH,CAAC;QACD,sBAAsB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IACrC,CAAC;IACD,6BAA6B,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;AACrD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Procedure, type ProcedureHostContext, type ProcedureRegistry } from './procedure.js';
|
|
2
|
+
/** The procedure registered under `name` as an own property and exposed to `'web'`, if any. */
|
|
3
|
+
export declare function webProcedureOf<C extends ProcedureHostContext>(procedures: ProcedureRegistry<C>, name: string): Procedure<C> | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* The session a web host hands on for what the application's `getSession`
|
|
6
|
+
* resolved: `null` when there is none, otherwise a copy carrying a human actor
|
|
7
|
+
* built from the session's own `userId`. See ADR-0086.
|
|
8
|
+
*
|
|
9
|
+
* @throws {ProcedureHostError} when the resolved value is not an object, or has no usable `userId`.
|
|
10
|
+
*/
|
|
11
|
+
export declare function webSessionOf<S extends object>(resolved: S | null | undefined): S | null;
|
|
12
|
+
//# sourceMappingURL=web-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-session.d.ts","sourceRoot":"","sources":["../../src/procedures/web-session.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,gBAAgB,CAAA;AAGvB,+FAA+F;AAC/F,wBAAgB,cAAc,CAAC,CAAC,SAAS,oBAAoB,EAC3D,UAAU,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAChC,IAAI,EAAE,MAAM,GACX,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAK1B;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAiBvF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { humanActor, isActorUserId, sessionWithActor } from '../access/actor.js';
|
|
2
|
+
import { isProcedure, } from './procedure.js';
|
|
3
|
+
import { ProcedureHostError } from './validate.js';
|
|
4
|
+
/** The procedure registered under `name` as an own property and exposed to `'web'`, if any. */
|
|
5
|
+
export function webProcedureOf(procedures, name) {
|
|
6
|
+
if (!Object.hasOwn(procedures, name))
|
|
7
|
+
return undefined;
|
|
8
|
+
const found = procedures[name];
|
|
9
|
+
if (!isProcedure(found) || !found.expose.includes('web'))
|
|
10
|
+
return undefined;
|
|
11
|
+
return found;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The session a web host hands on for what the application's `getSession`
|
|
15
|
+
* resolved: `null` when there is none, otherwise a copy carrying a human actor
|
|
16
|
+
* built from the session's own `userId`. See ADR-0086.
|
|
17
|
+
*
|
|
18
|
+
* @throws {ProcedureHostError} when the resolved value is not an object, or has no usable `userId`.
|
|
19
|
+
*/
|
|
20
|
+
export function webSessionOf(resolved) {
|
|
21
|
+
if (resolved === null || resolved === undefined)
|
|
22
|
+
return null;
|
|
23
|
+
if (typeof resolved !== 'object') {
|
|
24
|
+
throw new ProcedureHostError(`getSession resolved a ${typeof resolved}; it must resolve a session object, null or undefined.`);
|
|
25
|
+
}
|
|
26
|
+
const held = Object.getOwnPropertyDescriptor(resolved, 'userId');
|
|
27
|
+
const userId = held !== undefined && 'value' in held ? held.value : undefined;
|
|
28
|
+
if (!isActorUserId(userId)) {
|
|
29
|
+
throw new ProcedureHostError('getSession resolved a signed-in session with no usable `userId`, so the host cannot say who is acting. ' +
|
|
30
|
+
'`userId` must be an own data property of the session, not a getter, holding a non-empty string or a finite number. ' +
|
|
31
|
+
"With @opensaas/stack-auth, include it in `authPlugin({ sessionFields })`, for example `sessionFields: ['userId', 'email']`.");
|
|
32
|
+
}
|
|
33
|
+
return sessionWithActor(resolved, humanActor(userId));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=web-session.js.map
|