apps 0.0.1-beta.4 → 0.0.1-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -44
- package/framework-reference.json +1 -1
- package/js/{chunk-QKHR7BMF.js → chunk-3MMG2H6M.js} +89 -53
- package/js/{chunk-EQB7JMAL.js → chunk-6XGB4BAL.js} +146 -31
- package/js/chunk-ADD6H64X.js +729 -0
- package/js/{chunk-6VRYO2BG.js → chunk-AHGGO2VY.js} +837 -254
- package/js/{chunk-FDNTX5QJ.js → chunk-CQD3WSYH.js} +2 -2
- package/js/{chunk-EVJUVWN2.js → chunk-DKUEYTYD.js} +463 -218
- package/js/chunk-EM4UL26F.js +118 -0
- package/js/{chunk-2VPJHFOU.js → chunk-FXWRE655.js} +128 -24
- package/js/{chunk-5MQZEB6Y.js → chunk-JI3EP2GL.js} +40 -12
- package/js/chunk-JJSLEJ6T.js +156 -0
- package/js/chunk-KAQD3DTI.js +16 -0
- package/js/chunk-KIM5HXNK.js +49 -0
- package/js/chunk-MJZYV7IO.js +255 -0
- package/js/{chunk-FW5HBOIK.js → chunk-MXDKXAY4.js} +19117 -18309
- package/js/{chunk-T2LAZCAD.js → chunk-NKWWPJYX.js} +3 -3
- package/js/chunk-OD3KFKZD.js +1617 -0
- package/js/{chunk-3M2MEDNL.js → chunk-OTCLXFLL.js} +1337 -188
- package/js/chunk-P7MGDPFD.js +240 -0
- package/js/{chunk-ZCAMUXSG.js → chunk-PNVCCB4L.js} +432 -79
- package/js/{chunk-D47C7KG5.js → chunk-RIXVGVA6.js} +2 -2
- package/js/{chunk-NQ3OMCA5.js → chunk-TT6OU4UG.js} +2 -2
- package/js/{chunk-YEJOQEII.js → chunk-UOZMSUJ2.js} +61 -9
- package/js/chunk-UTJIGUSS.js +42 -0
- package/js/{chunk-G7ZIRKMK.js → chunk-VIU2XXA7.js} +228 -264
- package/js/{chunk-HDJH3RPR.js → chunk-VJQXXOQ3.js} +4 -4
- package/js/{chunk-WFSQXYUT.js → chunk-WPBR4AWB.js} +523 -63
- package/js/{chunk-SATWJKN6.js → chunk-YQ35E7KS.js} +2 -2
- package/js/chunk-ZUKBIHMK.js +92 -0
- package/js/client.js +122 -88
- package/js/contracts.js +116 -25
- package/js/effect.js +19 -20
- package/js/{es-APDZKREY.js → es-DIULA3ZF.js} +62 -1659
- package/js/graphql.js +57 -55
- package/js/host.js +19 -20
- package/js/index.js +245 -212
- package/js/mcp/effect.js +23 -22
- package/js/mcp/stdio.js +34 -30
- package/js/mcp.js +104 -68
- package/js/openapi.js +4087 -1503
- package/js/react.js +2 -3
- package/js/skills/effect.js +6 -3
- package/js/skills.js +147 -65
- package/js/storage/facet.js +1 -540
- package/js/ui/auth/contracts.js +2 -2
- package/js/ui/auth.js +5 -5
- package/js/ui/contracts.js +5 -4
- package/js/ui/serving.js +8517 -214
- package/package.json +2 -3
- package/runtime.json +1 -1
- package/types/app-data/src/contracts/database.d.ts +33 -6
- package/types/apps/src/contracts/api-response-error.d.ts +4 -0
- package/types/apps/src/contracts/app.d.ts +7 -8
- package/types/apps/src/contracts/cache.d.ts +14 -0
- package/types/apps/src/contracts/context.d.ts +12 -11
- package/types/apps/src/contracts/elicitation.d.ts +6 -6
- package/types/apps/src/contracts/failure.d.ts +54 -0
- package/types/apps/src/contracts/graphql.d.ts +2 -1
- package/types/apps/src/contracts/host.d.ts +44 -17
- package/types/apps/src/contracts/live.d.ts +2 -0
- package/types/apps/src/contracts/mcp.d.ts +96 -10
- package/types/apps/src/contracts/network.d.ts +84 -0
- package/types/apps/src/contracts/openapi-compile.d.ts +32 -3
- package/types/apps/src/contracts/openapi.d.ts +45 -9
- package/types/apps/src/contracts/operations.d.ts +8 -9
- package/types/apps/src/contracts/protocol-version.d.ts +2 -2
- package/types/apps/src/contracts/protocols/1.d.ts +263 -74
- package/types/apps/src/contracts/protocols/10.d.ts +1450 -0
- package/types/apps/src/contracts/protocols/2.d.ts +66 -24
- package/types/apps/src/contracts/protocols/3.d.ts +715 -0
- package/types/apps/src/contracts/protocols/4.d.ts +1297 -0
- package/types/apps/src/contracts/protocols/5.d.ts +1174 -0
- package/types/apps/src/contracts/protocols/6.d.ts +1620 -0
- package/types/apps/src/contracts/protocols/7.d.ts +1784 -0
- package/types/apps/src/contracts/protocols/8.d.ts +1130 -0
- package/types/apps/src/contracts/protocols/9.d.ts +1106 -0
- package/types/apps/src/contracts/protocols/oauth.d.ts +89 -0
- package/types/apps/src/contracts/provider-error.d.ts +9 -0
- package/types/apps/src/contracts/provider.d.ts +115 -10
- package/types/apps/src/contracts/router.d.ts +59 -0
- package/types/apps/src/contracts/skills.d.ts +39 -9
- package/types/apps/src/contracts/sql.d.ts +58 -0
- package/types/apps/src/contracts/ui.d.ts +19 -1
- package/types/apps/src/contracts/workflows.d.ts +40 -3
- package/types/apps/src/facet.d.ts +4 -5
- package/types/apps/src/graphql.d.ts +1 -3
- package/types/apps/src/implementation/account-router.d.ts +12 -0
- package/types/apps/src/implementation/app.d.ts +5 -4
- package/types/apps/src/implementation/browser-scripts.gen.d.ts +6 -0
- package/types/apps/src/implementation/catalog-cache.d.ts +32 -5
- package/types/apps/src/implementation/elicitation.d.ts +12 -12
- package/types/apps/src/implementation/failure-detail.d.ts +47 -0
- package/types/apps/src/implementation/graphql-catalog.d.ts +4 -7
- package/types/apps/src/implementation/graphql.d.ts +4 -3
- package/types/apps/src/implementation/input-problems.d.ts +6 -2
- package/types/apps/src/implementation/live.d.ts +2 -2
- package/types/apps/src/implementation/mcp-call.d.ts +6 -5
- package/types/apps/src/implementation/mcp-catalog.d.ts +7 -8
- package/types/apps/src/implementation/mcp-client.d.ts +49 -25
- package/types/apps/src/implementation/mcp-stdio.d.ts +1 -1
- package/types/apps/src/implementation/mcp-tools.d.ts +2 -1
- package/types/apps/src/implementation/mcp.d.ts +52 -25
- package/types/apps/src/implementation/network.d.ts +16 -0
- package/types/apps/src/implementation/openapi-compile.d.ts +27 -6
- package/types/apps/src/implementation/openapi-document.d.ts +46 -19
- package/types/apps/src/implementation/openapi-names.d.ts +9 -4
- package/types/apps/src/implementation/openapi-request.d.ts +10 -2
- package/types/apps/src/implementation/openapi-source.d.ts +8 -6
- package/types/apps/src/implementation/openapi-upgrade.d.ts +4 -0
- package/types/apps/src/implementation/operations.d.ts +36 -3
- package/types/apps/src/implementation/optimistic.d.ts +1 -1
- package/types/apps/src/implementation/protocol-operations.d.ts +6 -4
- package/types/apps/src/implementation/provider-error.d.ts +28 -1
- package/types/apps/src/implementation/provider.d.ts +19 -5
- package/types/apps/src/implementation/query-commit.d.ts +1 -1
- package/types/apps/src/implementation/router-catalog.d.ts +223 -0
- package/types/apps/src/implementation/router.d.ts +68 -0
- package/types/apps/src/implementation/runtime-yield.d.ts +7 -0
- package/types/apps/src/implementation/schema.d.ts +95 -11
- package/types/apps/src/implementation/skills.d.ts +18 -24
- package/types/apps/src/implementation/sql.d.ts +66 -0
- package/types/apps/src/implementation/ui-account-notice.d.ts +9 -0
- package/types/apps/src/implementation/ui-auth.d.ts +1 -1
- package/types/apps/src/implementation/ui-client.d.ts +2 -2
- package/types/apps/src/implementation/ui-document.d.ts +5 -0
- package/types/apps/src/implementation/ui-errors.d.ts +1 -1
- package/types/apps/src/implementation/ui-serving.d.ts +11 -5
- package/types/apps/src/implementation/ui-watch.d.ts +1 -1
- package/types/apps/src/implementation/upstream-error.d.ts +7 -0
- package/types/apps/src/implementation/webhooks.d.ts +1 -1
- package/types/apps/src/implementation/workflow-context.d.ts +11 -3
- package/types/apps/src/index.d.ts +30 -13
- package/types/apps/src/mcp-stdio.d.ts +2 -5
- package/types/apps/src/mcp.d.ts +25 -5
- package/types/apps/src/openapi.d.ts +6 -6
- package/types/apps/src/react.d.ts +1 -1
- package/types/apps/src/skills.d.ts +10 -8
- package/types/telemetry/src/app-records.d.ts +42 -0
- package/types/telemetry/src/browser-operations.d.ts +6 -3
- package/types/telemetry/src/browser.d.ts +2 -2
- package/types/telemetry/src/config.d.ts +2 -2
- package/types/telemetry/src/layer.d.ts +2 -2
- package/types/telemetry/src/recorded-failure.d.ts +20 -0
- package/types/telemetry/src/relay.d.ts +2 -2
- package/types/telemetry/src/transport.d.ts +8 -1
- package/types/utils/src/api-error.d.ts +53 -0
- package/types/utils/src/recorded-message.d.ts +15 -0
- package/js/chunk-BMOIAIVR.js +0 -138
- package/js/chunk-DHUDODG5.js +0 -213
- package/js/chunk-FZJOYIZO.js +0 -19
- package/js/chunk-LGIYBDWA.js +0 -85
- package/js/chunk-M6ZRRIBI.js +0 -877
- package/js/chunk-PLCMJREA.js +0 -590
- package/js/chunk-PYUYJRSK.js +0 -93
- package/js/chunk-SWPD52J7.js +0 -35
- package/js/chunk-W7D7WVSY.js +0 -18
- package/js/chunk-Z5NMEGJN.js +0 -29
- package/js/chunk-ZJWDMTE3.js +0 -63
- package/types/app-data/src/implementation/cursor.d.ts +0 -10
- package/types/app-data/src/implementation/index-key.d.ts +0 -7
- package/types/app-data/src/implementation/promise.d.ts +0 -68
- package/types/app-data/src/implementation/range.d.ts +0 -8
- package/types/app-data/src/implementation/schema.d.ts +0 -33
- package/types/app-data/src/implementation/sqlite.d.ts +0 -11
- package/types/app-data/src/index.d.ts +0 -4
- package/types/apps/src/contracts/dynamic-tools.d.ts +0 -13
- package/types/apps/src/contracts/storage.d.ts +0 -68
- package/types/apps/src/implementation/account-operations.d.ts +0 -151
- package/types/apps/src/implementation/dynamic-tools.d.ts +0 -8
- package/types/apps/src/implementation/storage.d.ts +0 -13
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FetchOptionUnsupported,
|
|
3
|
+
NetworkRefusedHeader,
|
|
4
|
+
RestrictedFetchOption,
|
|
5
|
+
networkRefusalHeader,
|
|
6
|
+
networkRefusalStatus,
|
|
7
|
+
supportedFetchOptions
|
|
8
|
+
} from "./chunk-P7MGDPFD.js";
|
|
9
|
+
import {
|
|
10
|
+
invocationFetch
|
|
11
|
+
} from "./chunk-PNVCCB4L.js";
|
|
12
|
+
import {
|
|
13
|
+
Effect_exports,
|
|
14
|
+
Schema_exports
|
|
15
|
+
} from "./chunk-MXDKXAY4.js";
|
|
16
|
+
|
|
17
|
+
// src/implementation/network.ts
|
|
18
|
+
var refusalHeader = (status, header) => status === networkRefusalStatus && header !== null && header !== void 0 ? header : void 0;
|
|
19
|
+
var failOnNetworkRefusal = (response) => {
|
|
20
|
+
const header = refusalHeader(response.status, response.headers[networkRefusalHeader]);
|
|
21
|
+
return header === void 0 ? Effect_exports.void : Schema_exports.decodeUnknownEffect(NetworkRefusedHeader)(header).pipe(
|
|
22
|
+
Effect_exports.orDie,
|
|
23
|
+
Effect_exports.flatMap(Effect_exports.fail)
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
var unsupportedOption = (init) => {
|
|
27
|
+
for (const option of RestrictedFetchOption.literals) {
|
|
28
|
+
const value = init?.[option];
|
|
29
|
+
const supported = supportedFetchOptions[option];
|
|
30
|
+
if (value !== void 0 && !supported.includes(value))
|
|
31
|
+
return new FetchOptionUnsupported({ option, value: String(value), supported });
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
};
|
|
35
|
+
var appFetch = (fetch) => async (input, init) => {
|
|
36
|
+
const unsupported = unsupportedOption(init);
|
|
37
|
+
if (unsupported !== void 0) throw unsupported;
|
|
38
|
+
const response = await fetch(input, init);
|
|
39
|
+
const header = refusalHeader(response.status, response.headers.get(networkRefusalHeader));
|
|
40
|
+
if (header === void 0) return response;
|
|
41
|
+
await response.body?.cancel();
|
|
42
|
+
throw Schema_exports.decodeUnknownSync(NetworkRefusedHeader)(header);
|
|
43
|
+
};
|
|
44
|
+
var appInvocationFetch = (signal) => invocationFetch(signal).pipe(Effect_exports.map(appFetch));
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
failOnNetworkRefusal,
|
|
48
|
+
appInvocationFetch
|
|
49
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HostedTool,
|
|
3
|
+
RouterKey,
|
|
4
|
+
RouterMeta,
|
|
5
|
+
reservedRouterKeys
|
|
6
|
+
} from "./chunk-OTCLXFLL.js";
|
|
7
|
+
import {
|
|
8
|
+
decoderOf,
|
|
9
|
+
schemaArgument
|
|
10
|
+
} from "./chunk-WPBR4AWB.js";
|
|
11
|
+
import {
|
|
12
|
+
Effect_exports,
|
|
13
|
+
Schema_exports
|
|
14
|
+
} from "./chunk-MXDKXAY4.js";
|
|
15
|
+
|
|
16
|
+
// src/implementation/authoring.ts
|
|
17
|
+
var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
|
|
18
|
+
var fromPromise = (callback) => (...args) => {
|
|
19
|
+
if (NativeCallback in callback) {
|
|
20
|
+
const native = callback[NativeCallback];
|
|
21
|
+
return native(...args);
|
|
22
|
+
}
|
|
23
|
+
return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error });
|
|
24
|
+
};
|
|
25
|
+
var toPromise = (operation, signal) => {
|
|
26
|
+
const native = (...args) => Effect_exports.suspend(() => {
|
|
27
|
+
if (signal === void 0) return operation(...args);
|
|
28
|
+
if (signal.aborted) return Effect_exports.interrupt;
|
|
29
|
+
const cancelled = Effect_exports.callback((resume) => {
|
|
30
|
+
if (signal.aborted) {
|
|
31
|
+
resume(Effect_exports.interrupt);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const abort = () => resume(Effect_exports.interrupt);
|
|
35
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
36
|
+
return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
|
|
37
|
+
});
|
|
38
|
+
return Effect_exports.raceFirst(
|
|
39
|
+
cancelled,
|
|
40
|
+
Effect_exports.suspend(() => operation(...args))
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
return Object.assign((...args) => Effect_exports.runPromise(native(...args)), {
|
|
44
|
+
[NativeCallback]: native
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/implementation/operations.ts
|
|
49
|
+
var NativeOperation = /* @__PURE__ */ Symbol("apps.Operation");
|
|
50
|
+
var NativeRouterKey = /* @__PURE__ */ Symbol("apps.Router");
|
|
51
|
+
var operationDeclaration = (operation) => ({
|
|
52
|
+
kind: operation.kind,
|
|
53
|
+
[NativeOperation]: operation
|
|
54
|
+
});
|
|
55
|
+
var nativeOperation = (value) => {
|
|
56
|
+
if (typeof value !== "object" || value === null || !(NativeOperation in value)) return void 0;
|
|
57
|
+
return value[NativeOperation];
|
|
58
|
+
};
|
|
59
|
+
var operationOptions = (options) => {
|
|
60
|
+
const approval = options.approval;
|
|
61
|
+
return {
|
|
62
|
+
...options.description === void 0 ? {} : { description: options.description },
|
|
63
|
+
...options.title === void 0 ? {} : { title: options.title },
|
|
64
|
+
...options.annotations === void 0 ? {} : { annotations: options.annotations },
|
|
65
|
+
...options._meta === void 0 ? {} : { _meta: options._meta },
|
|
66
|
+
input: decoderOf(options.input),
|
|
67
|
+
...approval === void 0 ? {} : {
|
|
68
|
+
approval: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
var approvedOperation = (operation, approval) => {
|
|
73
|
+
const copy = Object.defineProperties({}, Object.getOwnPropertyDescriptors(operation));
|
|
74
|
+
return Object.defineProperty(copy, "approval", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
value: (context) => Effect_exports.tryPromise({ try: async () => approval(context), catch: (error) => error })
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
var withApproval = (operation, approval) => ({
|
|
80
|
+
...operation,
|
|
81
|
+
[NativeOperation]: approvedOperation(operation[NativeOperation], approval)
|
|
82
|
+
});
|
|
83
|
+
var toolAnnotations = (operation) => nativeOperation(operation)?.annotations;
|
|
84
|
+
var make = (kind, options, run) => operationDeclaration({
|
|
85
|
+
...operationOptions({ ...options, input: schemaArgument(options.input, `The ${kind} input`) }),
|
|
86
|
+
kind,
|
|
87
|
+
// The host always validates JSON serialization, even without a stronger output declaration.
|
|
88
|
+
...options.output === void 0 ? {} : { output: decoderOf(schemaArgument(options.output, `The ${kind} output`)) },
|
|
89
|
+
run: (context, input) => Effect_exports.tryPromise({
|
|
90
|
+
// SAFETY: defineApp checks the handler context against its requirements.
|
|
91
|
+
// The host validates account bindings and creates the matching storage facade.
|
|
92
|
+
try: () => run(context, input),
|
|
93
|
+
catch: (error) => error
|
|
94
|
+
})
|
|
95
|
+
});
|
|
96
|
+
var query = (options, run) => make("query", options, run);
|
|
97
|
+
var mutation = (options, run) => make("mutation", options, run);
|
|
98
|
+
|
|
99
|
+
// src/implementation/router.ts
|
|
100
|
+
var routerDeclaration = (node) => ({
|
|
101
|
+
[NativeRouterKey]: node
|
|
102
|
+
});
|
|
103
|
+
var nativeRouter = (value) => {
|
|
104
|
+
if (typeof value !== "object" || value === null || !(NativeRouterKey in value)) return void 0;
|
|
105
|
+
return value[NativeRouterKey];
|
|
106
|
+
};
|
|
107
|
+
var nativeNode = (value) => nativeOperation(value) ?? nativeRouter(value);
|
|
108
|
+
var metaOf = (options) => {
|
|
109
|
+
if (options === void 0) return void 0;
|
|
110
|
+
const defined = Object.fromEntries(
|
|
111
|
+
Object.entries(options).filter(([, value]) => value !== void 0)
|
|
112
|
+
);
|
|
113
|
+
return Object.keys(defined).length === 0 ? void 0 : Schema_exports.decodeUnknownSync(RouterMeta)(defined);
|
|
114
|
+
};
|
|
115
|
+
var mergeMeta = (base, override) => base === void 0 ? override : override === void 0 ? base : { ...base, ...override };
|
|
116
|
+
function router(children, options) {
|
|
117
|
+
const meta = metaOf(options);
|
|
118
|
+
const existing = nativeRouter(children);
|
|
119
|
+
if (existing !== void 0)
|
|
120
|
+
return routerDeclaration(
|
|
121
|
+
existing.kind === "router" ? { ...existing, ...withMeta(mergeMeta(existing.meta, meta)) } : { ...existing, ...withOverrides(mergeMeta(existing.overrides, meta)) }
|
|
122
|
+
);
|
|
123
|
+
const nodes = {};
|
|
124
|
+
for (const [key, value] of Object.entries(children)) {
|
|
125
|
+
if (reservedRouterKeys.has(key)) throw new Error(`Router key "${key}" is reserved`);
|
|
126
|
+
if (!Schema_exports.is(RouterKey)(key))
|
|
127
|
+
throw new Error(`Router key "${key}" must start with a letter or _ and contain no dots`);
|
|
128
|
+
const node = nativeNode(value);
|
|
129
|
+
if (node === void 0)
|
|
130
|
+
throw new Error(`Router key "${key}" must be a query, mutation or router`);
|
|
131
|
+
nodes[key] = node;
|
|
132
|
+
}
|
|
133
|
+
return routerDeclaration({ kind: "router", ...withMeta(meta), children: nodes });
|
|
134
|
+
}
|
|
135
|
+
var withMeta = (meta) => meta === void 0 ? {} : { meta };
|
|
136
|
+
var withOverrides = (overrides) => overrides === void 0 ? {} : { overrides };
|
|
137
|
+
var dynamicRouter = (source) => {
|
|
138
|
+
const meta = source.meta;
|
|
139
|
+
return routerDeclaration({
|
|
140
|
+
kind: "dynamic",
|
|
141
|
+
...meta === void 0 ? {} : {
|
|
142
|
+
meta: () => fromPromise(async () => meta())().pipe(
|
|
143
|
+
Effect_exports.flatMap((options) => Schema_exports.decodeUnknownEffect(RouterMeta)(options))
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
list: () => fromPromise(async () => source.list())().pipe(
|
|
147
|
+
Effect_exports.flatMap(Schema_exports.decodeUnknownEffect(Schema_exports.Array(HostedTool)))
|
|
148
|
+
),
|
|
149
|
+
resolve: (name) => fromPromise(async () => source.resolve(name))().pipe(
|
|
150
|
+
Effect_exports.map((value) => {
|
|
151
|
+
if (value === void 0) return void 0;
|
|
152
|
+
const operation = nativeOperation(value);
|
|
153
|
+
if (operation === void 0) throw new Error("Expected an operation declaration");
|
|
154
|
+
return operation;
|
|
155
|
+
})
|
|
156
|
+
)
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
var joinPath = (path, name) => path === "" ? name : `${path}.${name}`;
|
|
160
|
+
var locate = (root, name) => {
|
|
161
|
+
if (root?.kind === "dynamic") return { kind: "dynamic", source: root, router: "", name };
|
|
162
|
+
let current = root;
|
|
163
|
+
let path = "";
|
|
164
|
+
let rest = name;
|
|
165
|
+
while (current !== void 0) {
|
|
166
|
+
const dot = rest.indexOf(".");
|
|
167
|
+
const key = dot < 0 ? rest : rest.slice(0, dot);
|
|
168
|
+
const child = Object.hasOwn(current.children, key) ? current.children[key] : void 0;
|
|
169
|
+
if (child === void 0) return void 0;
|
|
170
|
+
const remaining = dot < 0 ? void 0 : rest.slice(dot + 1);
|
|
171
|
+
switch (child.kind) {
|
|
172
|
+
case "query":
|
|
173
|
+
case "mutation":
|
|
174
|
+
return remaining === void 0 ? { kind: "operation", operation: child, router: path } : void 0;
|
|
175
|
+
case "dynamic":
|
|
176
|
+
return remaining === void 0 || remaining === "" ? void 0 : { kind: "dynamic", source: child, router: joinPath(path, key), name: remaining };
|
|
177
|
+
case "router":
|
|
178
|
+
if (remaining === void 0) return void 0;
|
|
179
|
+
current = child;
|
|
180
|
+
path = joinPath(path, key);
|
|
181
|
+
rest = remaining;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return void 0;
|
|
185
|
+
};
|
|
186
|
+
var declaredOperations = (root, path = "") => Object.entries(root?.children ?? {}).flatMap(([key, child]) => {
|
|
187
|
+
const name = joinPath(path, key);
|
|
188
|
+
switch (child.kind) {
|
|
189
|
+
case "query":
|
|
190
|
+
case "mutation":
|
|
191
|
+
return [{ name, router: path, operation: child }];
|
|
192
|
+
case "router":
|
|
193
|
+
return declaredOperations(child, name);
|
|
194
|
+
case "dynamic":
|
|
195
|
+
return [];
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
var withApprovals = (source, policy) => {
|
|
199
|
+
const native = nativeRouter(source);
|
|
200
|
+
if (native === void 0) throw new Error("withApprovals expects a router");
|
|
201
|
+
const operation = (node, name) => {
|
|
202
|
+
const approval = policy(operationDeclaration(node), name);
|
|
203
|
+
return approval === void 0 ? node : approvedOperation(node, approval);
|
|
204
|
+
};
|
|
205
|
+
const child = (node, name) => {
|
|
206
|
+
switch (node.kind) {
|
|
207
|
+
case "query":
|
|
208
|
+
case "mutation":
|
|
209
|
+
return operation(node, name);
|
|
210
|
+
case "router":
|
|
211
|
+
case "dynamic":
|
|
212
|
+
return walk(node, name);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
const walk = (node, path) => node.kind === "dynamic" ? {
|
|
216
|
+
...node,
|
|
217
|
+
resolve: (name) => node.resolve(name).pipe(
|
|
218
|
+
Effect_exports.flatMap(
|
|
219
|
+
(resolved) => resolved === void 0 ? Effect_exports.succeed(void 0) : Effect_exports.try({
|
|
220
|
+
try: () => operation(resolved, joinPath(path, name)),
|
|
221
|
+
catch: (error) => error
|
|
222
|
+
})
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
} : {
|
|
226
|
+
...node,
|
|
227
|
+
children: Object.fromEntries(
|
|
228
|
+
Object.entries(node.children).map(([key, value]) => [
|
|
229
|
+
key,
|
|
230
|
+
child(value, joinPath(path, key))
|
|
231
|
+
])
|
|
232
|
+
)
|
|
233
|
+
};
|
|
234
|
+
return routerDeclaration(walk(native, ""));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
fromPromise,
|
|
239
|
+
toPromise,
|
|
240
|
+
operationDeclaration,
|
|
241
|
+
nativeOperation,
|
|
242
|
+
withApproval,
|
|
243
|
+
toolAnnotations,
|
|
244
|
+
query,
|
|
245
|
+
mutation,
|
|
246
|
+
routerDeclaration,
|
|
247
|
+
nativeRouter,
|
|
248
|
+
mergeMeta,
|
|
249
|
+
router,
|
|
250
|
+
dynamicRouter,
|
|
251
|
+
joinPath,
|
|
252
|
+
locate,
|
|
253
|
+
declaredOperations,
|
|
254
|
+
withApprovals
|
|
255
|
+
};
|