apps 0.0.1-beta.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.
Files changed (135) hide show
  1. package/README.md +191 -0
  2. package/check-publish.mjs +10 -0
  3. package/framework-reference.json +1 -0
  4. package/js/chunk-22WRQZT7.js +389 -0
  5. package/js/chunk-2OTCEKL2.js +29480 -0
  6. package/js/chunk-36DNRFZQ.js +34 -0
  7. package/js/chunk-3ANFZFCV.js +1799 -0
  8. package/js/chunk-7JXHF5IF.js +138 -0
  9. package/js/chunk-BCSNKUAC.js +0 -0
  10. package/js/chunk-BKVL7XAJ.js +47 -0
  11. package/js/chunk-BPEFS4YF.js +1323 -0
  12. package/js/chunk-C24KEZXR.js +59 -0
  13. package/js/chunk-D6BKYP2L.js +877 -0
  14. package/js/chunk-EP6AEUZO.js +19 -0
  15. package/js/chunk-HP7E42X6.js +1719 -0
  16. package/js/chunk-KWTCHVLT.js +284 -0
  17. package/js/chunk-LOKGDT6B.js +28 -0
  18. package/js/chunk-MLKGABMK.js +9 -0
  19. package/js/chunk-OWD2YICM.js +2486 -0
  20. package/js/chunk-Q2FD5IBM.js +899 -0
  21. package/js/chunk-R6JMJSVT.js +590 -0
  22. package/js/chunk-SBKHUC5L.js +56 -0
  23. package/js/chunk-VFUZI3NY.js +75 -0
  24. package/js/chunk-W7Q5EOTS.js +4375 -0
  25. package/js/chunk-WIDTG42X.js +171 -0
  26. package/js/chunk-X3YBZCJW.js +246 -0
  27. package/js/chunk-YDR4CPJA.js +2357 -0
  28. package/js/client.js +1023 -0
  29. package/js/contracts.js +163 -0
  30. package/js/effect.js +44 -0
  31. package/js/graphql.js +392 -0
  32. package/js/host.js +193 -0
  33. package/js/index.js +284 -0
  34. package/js/mcp/effect.js +23 -0
  35. package/js/mcp/stdio.js +123 -0
  36. package/js/mcp.js +37 -0
  37. package/js/openapi.js +246 -0
  38. package/js/operations/approval.js +9 -0
  39. package/js/react.js +37 -0
  40. package/js/storage/facet.js +546 -0
  41. package/js/ui/auth/contracts.js +19 -0
  42. package/js/ui/auth.js +28 -0
  43. package/js/ui/contracts.js +24 -0
  44. package/js/ui/serving.js +286 -0
  45. package/package.json +116 -0
  46. package/runtime.json +1 -0
  47. package/types/app-data/src/contracts/database.d.ts +193 -0
  48. package/types/app-data/src/implementation/cursor.d.ts +10 -0
  49. package/types/app-data/src/implementation/index-key.d.ts +7 -0
  50. package/types/app-data/src/implementation/promise.d.ts +68 -0
  51. package/types/app-data/src/implementation/range.d.ts +8 -0
  52. package/types/app-data/src/implementation/schema.d.ts +33 -0
  53. package/types/app-data/src/implementation/sqlite.d.ts +11 -0
  54. package/types/app-data/src/index.d.ts +4 -0
  55. package/types/apps/src/approval.d.ts +10 -0
  56. package/types/apps/src/client.d.ts +5 -0
  57. package/types/apps/src/contracts/app.d.ts +58 -0
  58. package/types/apps/src/contracts/approval.d.ts +14 -0
  59. package/types/apps/src/contracts/context.d.ts +25 -0
  60. package/types/apps/src/contracts/elicitation.d.ts +86 -0
  61. package/types/apps/src/contracts/graphql.d.ts +102 -0
  62. package/types/apps/src/contracts/host.d.ts +568 -0
  63. package/types/apps/src/contracts/http.d.ts +20 -0
  64. package/types/apps/src/contracts/live.d.ts +26 -0
  65. package/types/apps/src/contracts/mcp.d.ts +93 -0
  66. package/types/apps/src/contracts/openapi.d.ts +105 -0
  67. package/types/apps/src/contracts/operations.d.ts +30 -0
  68. package/types/apps/src/contracts/optimistic.d.ts +22 -0
  69. package/types/apps/src/contracts/provider.d.ts +96 -0
  70. package/types/apps/src/contracts/schedules.d.ts +51 -0
  71. package/types/apps/src/contracts/schema.d.ts +20 -0
  72. package/types/apps/src/contracts/storage.d.ts +68 -0
  73. package/types/apps/src/contracts/tools.d.ts +11 -0
  74. package/types/apps/src/contracts/ui-auth.d.ts +28 -0
  75. package/types/apps/src/contracts/ui.d.ts +90 -0
  76. package/types/apps/src/contracts/webhook-protocol.d.ts +102 -0
  77. package/types/apps/src/contracts/webhooks.d.ts +53 -0
  78. package/types/apps/src/contracts/workflows.d.ts +277 -0
  79. package/types/apps/src/effect.d.ts +10 -0
  80. package/types/apps/src/facet.d.ts +5 -0
  81. package/types/apps/src/graphql.d.ts +10 -0
  82. package/types/apps/src/host.d.ts +16 -0
  83. package/types/apps/src/implementation/account-operations.d.ts +32 -0
  84. package/types/apps/src/implementation/app.d.ts +40 -0
  85. package/types/apps/src/implementation/authoring.d.ts +12 -0
  86. package/types/apps/src/implementation/elicitation.d.ts +103 -0
  87. package/types/apps/src/implementation/graphql.d.ts +5 -0
  88. package/types/apps/src/implementation/host.d.ts +3 -0
  89. package/types/apps/src/implementation/http.d.ts +5 -0
  90. package/types/apps/src/implementation/live.d.ts +18 -0
  91. package/types/apps/src/implementation/mcp-call.d.ts +19 -0
  92. package/types/apps/src/implementation/mcp-client.d.ts +50 -0
  93. package/types/apps/src/implementation/mcp-stdio.d.ts +4 -0
  94. package/types/apps/src/implementation/mcp-tools.d.ts +6 -0
  95. package/types/apps/src/implementation/mcp.d.ts +4 -0
  96. package/types/apps/src/implementation/openapi-request.d.ts +11 -0
  97. package/types/apps/src/implementation/openapi.d.ts +5 -0
  98. package/types/apps/src/implementation/operations.d.ts +65 -0
  99. package/types/apps/src/implementation/optimistic.d.ts +30 -0
  100. package/types/apps/src/implementation/protocol-operations.d.ts +24 -0
  101. package/types/apps/src/implementation/provider.d.ts +16 -0
  102. package/types/apps/src/implementation/query-commit.d.ts +10 -0
  103. package/types/apps/src/implementation/schedules.d.ts +16 -0
  104. package/types/apps/src/implementation/schema.d.ts +93 -0
  105. package/types/apps/src/implementation/storage.d.ts +13 -0
  106. package/types/apps/src/implementation/ui-auth.d.ts +13 -0
  107. package/types/apps/src/implementation/ui-client.d.ts +16 -0
  108. package/types/apps/src/implementation/ui-errors.d.ts +2 -0
  109. package/types/apps/src/implementation/ui-serving.d.ts +16 -0
  110. package/types/apps/src/implementation/ui-watch.d.ts +2 -0
  111. package/types/apps/src/implementation/webhooks.d.ts +29 -0
  112. package/types/apps/src/implementation/workflow-context.d.ts +8 -0
  113. package/types/apps/src/implementation/workflow-rpc.d.ts +5 -0
  114. package/types/apps/src/implementation/workflows.d.ts +27 -0
  115. package/types/apps/src/index.d.ts +58 -0
  116. package/types/apps/src/mcp-stdio.d.ts +8 -0
  117. package/types/apps/src/mcp.d.ts +10 -0
  118. package/types/apps/src/openapi.d.ts +10 -0
  119. package/types/apps/src/react.d.ts +7 -0
  120. package/types/apps/src/ui-auth.d.ts +3 -0
  121. package/types/apps/src/ui-serving.d.ts +3 -0
  122. package/types/telemetry/src/browser-operations.d.ts +16 -0
  123. package/types/telemetry/src/browser-performance.d.ts +11 -0
  124. package/types/telemetry/src/browser-request-timing.d.ts +2 -0
  125. package/types/telemetry/src/browser.d.ts +27 -0
  126. package/types/telemetry/src/config.d.ts +83 -0
  127. package/types/telemetry/src/context.d.ts +14 -0
  128. package/types/telemetry/src/index.d.ts +9 -0
  129. package/types/telemetry/src/layer.d.ts +7 -0
  130. package/types/telemetry/src/measurements.d.ts +8 -0
  131. package/types/telemetry/src/pending-span.d.ts +7 -0
  132. package/types/telemetry/src/relay.d.ts +28 -0
  133. package/types/telemetry/src/span-attributes.d.ts +29 -0
  134. package/types/telemetry/src/trace-context.d.ts +20 -0
  135. package/types/telemetry/src/transport.d.ts +6 -0
@@ -0,0 +1,171 @@
1
+ import {
2
+ adaptMcpTools,
3
+ mcpClient,
4
+ mcpJsonSchemaValidator
5
+ } from "./chunk-KWTCHVLT.js";
6
+ import {
7
+ McpError,
8
+ McpToolsOptions,
9
+ defaultMcpClientLimits
10
+ } from "./chunk-22WRQZT7.js";
11
+ import {
12
+ captureTelemetry
13
+ } from "./chunk-OWD2YICM.js";
14
+ import {
15
+ FetchHttpClient_exports
16
+ } from "./chunk-VFUZI3NY.js";
17
+ import {
18
+ HttpClientRequest_exports,
19
+ HttpClient_exports
20
+ } from "./chunk-W7Q5EOTS.js";
21
+ import {
22
+ Effect_exports,
23
+ Redacted_exports,
24
+ Schema_exports,
25
+ Stream_exports
26
+ } from "./chunk-2OTCEKL2.js";
27
+
28
+ // src/implementation/mcp.ts
29
+ import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
30
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
31
+ import { ErrorCode, McpError as ProtocolError } from "@modelcontextprotocol/sdk/types.js";
32
+ import { SSEClientTransport, SseError } from "@modelcontextprotocol/sdk/client/sse.js";
33
+ import {
34
+ StreamableHTTPClientTransport,
35
+ StreamableHTTPError
36
+ } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
37
+ var failure = (phase, error) => {
38
+ const status = error instanceof UnauthorizedError ? 401 : error instanceof StreamableHTTPError || error instanceof SseError ? error.code : void 0;
39
+ return new McpError({
40
+ phase,
41
+ reason: error instanceof ProtocolError && error.code === ErrorCode.RequestTimeout ? "timeout" : status === 401 || status === 403 ? "unauthorized" : "request",
42
+ ...status === void 0 ? {} : { status }
43
+ });
44
+ };
45
+ var transportFetch = (connection, telemetry) => (url, init) => Effect_exports.runPromiseWith(telemetry.context)(
46
+ Effect_exports.gen(function* () {
47
+ const target = yield* Effect_exports.try({
48
+ try: () => new URL(url),
49
+ catch: () => failure("transport", void 0)
50
+ });
51
+ if (target.origin !== connection.url.origin || target.username || target.password)
52
+ return yield* failure("transport", void 0);
53
+ const headers = new Headers(Redacted_exports.value(connection.headers));
54
+ new Headers(init?.headers).forEach((value, name) => headers.set(name, value));
55
+ const request = yield* Effect_exports.try({
56
+ try: () => HttpClientRequest_exports.fromWeb(new Request(target, { ...init, headers })),
57
+ catch: () => failure("transport", void 0)
58
+ });
59
+ const client = yield* HttpClient_exports.HttpClient;
60
+ const response = yield* client.execute(request);
61
+ return new Response(
62
+ [204, 205, 304].includes(response.status) ? null : Stream_exports.toReadableStream(response.stream),
63
+ {
64
+ status: response.status,
65
+ headers: response.headers
66
+ }
67
+ );
68
+ }).pipe(
69
+ Effect_exports.provide(FetchHttpClient_exports.layer),
70
+ Effect_exports.provideService(FetchHttpClient_exports.RequestInit, { redirect: "manual" }),
71
+ Effect_exports.provideService(
72
+ FetchHttpClient_exports.Fetch,
73
+ (url2, options) => globalThis.fetch(url2, {
74
+ ...options,
75
+ signal: AbortSignal.any([
76
+ ...options?.signal ? [options.signal] : [],
77
+ ...init?.signal ? [init.signal] : []
78
+ ])
79
+ })
80
+ ),
81
+ Effect_exports.mapError(() => failure("transport", void 0))
82
+ ),
83
+ init?.signal ? { signal: init.signal } : {}
84
+ );
85
+ function withClient(connection, mode, use) {
86
+ const attempt = (kind) => Effect_exports.scoped(
87
+ Effect_exports.gen(function* () {
88
+ const telemetry = yield* captureTelemetry;
89
+ const { client, transport } = yield* Effect_exports.acquireRelease(
90
+ Effect_exports.sync(() => {
91
+ const fetch = transportFetch(connection, telemetry);
92
+ return {
93
+ client: new Client(
94
+ { name: "executor-apps", version: "0.1.0" },
95
+ {
96
+ jsonSchemaValidator: mcpJsonSchemaValidator,
97
+ capabilities: mode === "call" ? { elicitation: { form: {} } } : {}
98
+ }
99
+ ),
100
+ transport: kind === "http" ? new StreamableHTTPClientTransport(connection.url, {
101
+ fetch,
102
+ reconnectionOptions: {
103
+ maxRetries: 0,
104
+ initialReconnectionDelay: 1e3,
105
+ maxReconnectionDelay: 1e3,
106
+ reconnectionDelayGrowFactor: 1
107
+ }
108
+ }) : new SSEClientTransport(connection.url, { fetch })
109
+ };
110
+ }),
111
+ ({ client: client2, transport: transport2 }) => Effect_exports.gen(function* () {
112
+ if (transport2 instanceof StreamableHTTPClientTransport && transport2.sessionId !== void 0) {
113
+ yield* Effect_exports.tryPromise(() => transport2.terminateSession()).pipe(
114
+ Effect_exports.timeout(defaultMcpClientLimits.cleanupTimeoutMs),
115
+ Effect_exports.ignore
116
+ );
117
+ }
118
+ yield* Effect_exports.tryPromise(() => client2.close()).pipe(
119
+ Effect_exports.timeout(defaultMcpClientLimits.cleanupTimeoutMs),
120
+ Effect_exports.ignore
121
+ );
122
+ }).pipe(Effect_exports.withSpan("provider.mcp.close"))
123
+ );
124
+ const wire = transport;
125
+ yield* Effect_exports.tryPromise({
126
+ try: (signal) => client.connect(wire, { signal, timeout: connection.timeoutMs }),
127
+ catch: (error) => failure("connect", error)
128
+ }).pipe(Effect_exports.timeout(connection.timeoutMs), Effect_exports.withSpan("provider.mcp.connect"));
129
+ return yield* use(client);
130
+ })
131
+ ).pipe(
132
+ Effect_exports.withSpan("provider.mcp.session", {
133
+ attributes: {
134
+ "mcp.transport": kind,
135
+ "mcp.operation": mode,
136
+ "server.address": connection.url.hostname
137
+ }
138
+ })
139
+ );
140
+ return attempt("http").pipe(
141
+ // Fallback is only for negotiation. Tool calls are never automatically replayed.
142
+ Effect_exports.catch(
143
+ (error) => Schema_exports.is(McpError)(error) && error.phase === "connect" && (error.status === 404 || error.status === 405) ? attempt("sse") : Effect_exports.fail(error)
144
+ ),
145
+ (operation) => mode === "discover" ? operation.pipe(Effect_exports.timeout(connection.timeoutMs)) : operation,
146
+ Effect_exports.catchTag(
147
+ "TimeoutError",
148
+ () => Effect_exports.fail(new McpError({ phase: "transport", reason: "timeout" }))
149
+ )
150
+ );
151
+ }
152
+ var mcpToolsEffect = (input) => Effect_exports.gen(function* () {
153
+ const options = yield* Schema_exports.decodeUnknownEffect(McpToolsOptions)(input).pipe(
154
+ Effect_exports.mapError(() => new McpError({ phase: "connect", reason: "invalid_input" }))
155
+ );
156
+ const url = new URL(options.url);
157
+ if (url.username || url.password || url.hash)
158
+ return yield* new McpError({ phase: "connect", reason: "invalid_input" });
159
+ const connection = {
160
+ url,
161
+ headers: Redacted_exports.make({ ...options.headers }),
162
+ timeoutMs: options.timeoutMs ?? defaultMcpClientLimits.timeoutMs
163
+ };
164
+ return yield* adaptMcpTools(
165
+ mcpClient((mode, use) => withClient(connection, mode, use), connection.timeoutMs, failure)
166
+ );
167
+ });
168
+
169
+ export {
170
+ mcpToolsEffect
171
+ };
@@ -0,0 +1,246 @@
1
+ import {
2
+ parseDatabaseSchema,
3
+ promiseTable
4
+ } from "./chunk-R6JMJSVT.js";
5
+ import {
6
+ nativeOperation
7
+ } from "./chunk-C24KEZXR.js";
8
+ import {
9
+ ScheduleTiming
10
+ } from "./chunk-HP7E42X6.js";
11
+ import {
12
+ decoderOf,
13
+ isSchema,
14
+ storageFieldOf
15
+ } from "./chunk-BPEFS4YF.js";
16
+ import {
17
+ AppStorageUnavailable
18
+ } from "./chunk-EP6AEUZO.js";
19
+ import {
20
+ JsonValue
21
+ } from "./chunk-36DNRFZQ.js";
22
+ import {
23
+ Effect_exports,
24
+ Schema_exports
25
+ } from "./chunk-2OTCEKL2.js";
26
+
27
+ // src/implementation/authoring.ts
28
+ var NativeCallback = /* @__PURE__ */ Symbol("apps.NativeCallback");
29
+ var fromPromise = (callback) => (...args) => {
30
+ if (NativeCallback in callback) {
31
+ const native = callback[NativeCallback];
32
+ return native(...args);
33
+ }
34
+ return Effect_exports.tryPromise({ try: () => callback(...args), catch: (error) => error });
35
+ };
36
+ var toPromise = (operation, signal) => {
37
+ const native = (...args) => Effect_exports.suspend(() => {
38
+ if (signal === void 0) return operation(...args);
39
+ if (signal.aborted) return Effect_exports.interrupt;
40
+ const cancelled = Effect_exports.callback((resume) => {
41
+ if (signal.aborted) {
42
+ resume(Effect_exports.interrupt);
43
+ return;
44
+ }
45
+ const abort = () => resume(Effect_exports.interrupt);
46
+ signal.addEventListener("abort", abort, { once: true });
47
+ return Effect_exports.sync(() => signal.removeEventListener("abort", abort));
48
+ });
49
+ return Effect_exports.raceFirst(
50
+ cancelled,
51
+ Effect_exports.suspend(() => operation(...args))
52
+ );
53
+ });
54
+ return Object.assign((...args) => Effect_exports.runPromise(native(...args)), {
55
+ [NativeCallback]: native
56
+ });
57
+ };
58
+
59
+ // src/implementation/workflows.ts
60
+ var NativeWorkflow = /* @__PURE__ */ Symbol("apps.Workflow");
61
+ var workflow = (options, run) => ({
62
+ [NativeWorkflow]: {
63
+ input: decoderOf(options.input),
64
+ ...options.output === void 0 ? {} : { output: decoderOf(options.output) },
65
+ ...options.description === void 0 ? {} : { description: options.description },
66
+ run: (context, input) => Effect_exports.tryPromise({
67
+ // SAFETY: defineApp checks required context; the host supplies the pinned run's capabilities.
68
+ try: () => run(context, input),
69
+ catch: (error) => error
70
+ })
71
+ }
72
+ });
73
+ var nativeWorkflow = (value) => {
74
+ if (typeof value !== "object" || value === null || !(NativeWorkflow in value)) return void 0;
75
+ return value[NativeWorkflow];
76
+ };
77
+
78
+ // src/implementation/app.ts
79
+ var InternalApp = /* @__PURE__ */ Symbol("apps.App");
80
+ var isApp = (value) => typeof value === "object" && value !== null && InternalApp in value;
81
+ var toEffectApp = (app) => app[InternalApp];
82
+ function adaptDefinition(definition) {
83
+ if ("tools" in definition) throw new Error("Use queries and mutations instead of tools");
84
+ const webhooks = definition.webhooks === void 0 ? {} : {
85
+ webhooks: Object.fromEntries(
86
+ Object.entries(definition.webhooks).map(([name, webhook]) => [
87
+ name,
88
+ {
89
+ ...webhook,
90
+ ...webhook.register === void 0 ? {} : { register: fromPromise(webhook.register) },
91
+ handle: fromPromise(webhook.handle),
92
+ ...webhook.unregister === void 0 ? {} : { unregister: fromPromise(webhook.unregister) },
93
+ ..."config" in webhook && isSchema(webhook.config) ? { config: decoderOf(webhook.config) } : {},
94
+ ..."state" in webhook && isSchema(webhook.state) ? { state: decoderOf(webhook.state) } : {}
95
+ }
96
+ ])
97
+ )
98
+ };
99
+ const operations = (kind, catalog) => Object.fromEntries(
100
+ Object.entries(catalog).map(([name, value]) => {
101
+ const operation = nativeOperation(value);
102
+ if (operation === void 0 || operation.kind !== kind)
103
+ throw new Error("Invalid app data operation");
104
+ return [name, operation];
105
+ })
106
+ );
107
+ const workflows = definition.workflows === void 0 ? {} : {
108
+ workflows: Object.fromEntries(
109
+ Object.entries(definition.workflows).map(([name, value]) => {
110
+ const declared = nativeWorkflow(value);
111
+ if (declared === void 0) throw new Error("Invalid workflow declaration");
112
+ return [name, declared];
113
+ })
114
+ )
115
+ };
116
+ const data = {
117
+ ...definition.queries === void 0 ? {} : { queries: operations("query", definition.queries) },
118
+ ...definition.mutations === void 0 ? {} : { mutations: operations("mutation", definition.mutations) }
119
+ };
120
+ const schedules = definition.schedules === void 0 ? {} : {
121
+ schedules: Object.fromEntries(
122
+ Object.entries(definition.schedules).map(([name, schedule]) => {
123
+ const matches = Object.entries(definition.mutations ?? {}).filter(
124
+ ([, operation]) => operation === schedule.operation
125
+ );
126
+ const match = matches[0];
127
+ if (match === void 0 || matches.length !== 1)
128
+ throw new Error("A schedule must reference exactly one named mutation in this app");
129
+ return [
130
+ name,
131
+ {
132
+ timing: Schema_exports.decodeUnknownSync(ScheduleTiming)(schedule.timing),
133
+ input: Schema_exports.decodeUnknownSync(JsonValue)(schedule.input),
134
+ tool: `mutations.${match[0]}`
135
+ }
136
+ ];
137
+ })
138
+ )
139
+ };
140
+ return {
141
+ ...definition,
142
+ ...webhooks,
143
+ ...workflows,
144
+ ...data,
145
+ ...schedules
146
+ };
147
+ }
148
+ var defineApp = (requirements, definition) => {
149
+ const evaluate = typeof definition === "function" ? definition : async () => definition;
150
+ const factory = fromPromise(evaluate);
151
+ const native = {
152
+ accounts: requirements.accounts,
153
+ ...requirements.database === void 0 ? {} : { database: requirements.database },
154
+ evaluate: (context) => factory(context).pipe(Effect_exports.map((value) => adaptDefinition(value)))
155
+ };
156
+ return {
157
+ [InternalApp]: native,
158
+ accounts: native.accounts,
159
+ evaluate: (context) => Effect_exports.runPromise(factory(context))
160
+ };
161
+ };
162
+
163
+ // src/implementation/storage.ts
164
+ var table = (fields) => tableWithIndexes(fields, []);
165
+ var tableWithIndexes = (fields, indexes) => ({
166
+ fields,
167
+ indexes,
168
+ index: (name, fieldsInIndex) => tableWithIndexes(fields, [...indexes, { name, fields: fieldsInIndex }])
169
+ });
170
+ var serialize = (tables) => {
171
+ const definitions = Object.fromEntries(
172
+ Object.entries(tables).map(([name, table2]) => [
173
+ name,
174
+ {
175
+ fields: Object.fromEntries(
176
+ Object.entries(table2.fields).map(([fieldName, schema]) => {
177
+ const field = storageFieldOf(schema);
178
+ if (field === void 0) throw new Error("Database columns must use a scalar schema");
179
+ return [fieldName, field];
180
+ })
181
+ ),
182
+ indexes: table2.indexes
183
+ }
184
+ ])
185
+ );
186
+ return Effect_exports.runSync(parseDatabaseSchema(definitions));
187
+ };
188
+ var authorDatabase = (tables, session, signal, writable) => {
189
+ return Object.fromEntries(
190
+ Object.entries(tables).map(([name, table2]) => {
191
+ const api = promiseTable(session, name, signal);
192
+ const parseFields = (input, partial) => {
193
+ const values = Schema_exports.decodeUnknownSync(
194
+ Schema_exports.Record(Schema_exports.String, Schema_exports.Unknown)
195
+ )(input);
196
+ const fields = {};
197
+ for (const [key, value] of Object.entries(values)) {
198
+ if (value === void 0) continue;
199
+ const field = Object.hasOwn(table2.fields, key) ? table2.fields[key] : void 0;
200
+ if (field === void 0) throw new Error("Unknown database column");
201
+ const definition = storageFieldOf(field);
202
+ fields[key] = value === null && definition?.optional ? null : field.parse(value);
203
+ }
204
+ if (!partial) {
205
+ for (const [key, field] of Object.entries(table2.fields))
206
+ if (!Object.hasOwn(fields, key)) {
207
+ const value = field.parse(void 0);
208
+ if (value !== void 0) fields[key] = value;
209
+ }
210
+ }
211
+ return fields;
212
+ };
213
+ const read = { get: api.get, withIndex: api.withIndex };
214
+ return [
215
+ name,
216
+ writable ? {
217
+ ...read,
218
+ insert: (value) => api.insert(parseFields(value, false)),
219
+ update: (id, value) => api.update(id, parseFields(value, true)),
220
+ delete: api.delete
221
+ } : read
222
+ ];
223
+ })
224
+ );
225
+ };
226
+ var defineDatabase = (tables) => ({
227
+ schema: serialize(tables),
228
+ tables
229
+ });
230
+ var unavailableStorage = {
231
+ read: () => Effect_exports.fail(new AppStorageUnavailable()),
232
+ mutate: () => Effect_exports.fail(new AppStorageUnavailable())
233
+ };
234
+
235
+ export {
236
+ fromPromise,
237
+ toPromise,
238
+ workflow,
239
+ isApp,
240
+ toEffectApp,
241
+ defineApp,
242
+ table,
243
+ authorDatabase,
244
+ defineDatabase,
245
+ unavailableStorage
246
+ };