@atomservice/functions-sdk 0.1.6 → 0.1.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/package.json +1 -1
- package/src/sdk.consts.ts +1 -1
- package/src/sdk.runtime.ts +20 -7
package/package.json
CHANGED
package/src/sdk.consts.ts
CHANGED
package/src/sdk.runtime.ts
CHANGED
|
@@ -54,7 +54,7 @@ interface ExecutorRouter {
|
|
|
54
54
|
dispose: () => Promise<void>
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function buildExecutorRouter(registry:
|
|
57
|
+
function buildExecutorRouter<T extends FunctionRegistry>(registry: T, options: ServeOptions): ExecutorRouter {
|
|
58
58
|
const inline = new InlineExecutor(registry, makeContextFactory(options))
|
|
59
59
|
const workerEnv: Record<string, string> = {
|
|
60
60
|
...(process.env as Record<string, string>),
|
|
@@ -90,8 +90,8 @@ function overloaded(options: ServeOptions): boolean {
|
|
|
90
90
|
return rssMb > options.memoryLimitMb * MEMORY_BACKPRESSURE_RATIO
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
export function serve(
|
|
94
|
-
registry:
|
|
93
|
+
export function serve<T extends FunctionRegistry>(
|
|
94
|
+
registry: T,
|
|
95
95
|
overrides?: Partial<ServeOptions>,
|
|
96
96
|
): Bun.Server<undefined> | undefined {
|
|
97
97
|
const options = resolveOptions(overrides)
|
|
@@ -114,6 +114,12 @@ export function serve(
|
|
|
114
114
|
})
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
const fnNames = Object.keys(registry)
|
|
118
|
+
console.log("\n%s", options.bundle)
|
|
119
|
+
for (const name of fnNames) {
|
|
120
|
+
console.log("- %s/%s", options.bundle, name)
|
|
121
|
+
}
|
|
122
|
+
|
|
117
123
|
return Bun.serve({
|
|
118
124
|
port: options.port,
|
|
119
125
|
async fetch(request) {
|
|
@@ -124,7 +130,7 @@ export function serve(
|
|
|
124
130
|
return Response.json({ ok: true, functions })
|
|
125
131
|
}
|
|
126
132
|
|
|
127
|
-
if (request.method === "POST" && url.pathname.startsWith(INVOKE_PATH_PREFIX)) {
|
|
133
|
+
if ((request.method === "GET" || request.method === "POST") && url.pathname.startsWith(INVOKE_PATH_PREFIX)) {
|
|
128
134
|
const name = url.pathname.slice(INVOKE_PATH_PREFIX.length)
|
|
129
135
|
const def = registry[name]
|
|
130
136
|
if (!def) {
|
|
@@ -148,16 +154,23 @@ export function serve(
|
|
|
148
154
|
}
|
|
149
155
|
|
|
150
156
|
const id = requestId(request)
|
|
151
|
-
const
|
|
157
|
+
const queryParams: Record<string, unknown> = {}
|
|
158
|
+
url.searchParams.forEach((v, k) => {
|
|
159
|
+
queryParams[k] = v
|
|
160
|
+
})
|
|
161
|
+
const bodyParams = await readBody(request)
|
|
162
|
+
const event = typeof bodyParams === "object" && bodyParams !== null
|
|
163
|
+
? { ...queryParams, ...(bodyParams as Record<string, unknown>) }
|
|
164
|
+
: queryParams
|
|
152
165
|
const deps = { executor: router.pick(def), name, requestId: id, defaultTimeout: options.defaultTimeout }
|
|
153
166
|
|
|
154
167
|
if (isStreamKind(def)) {
|
|
155
|
-
const response = invokeStream(def,
|
|
168
|
+
const response = invokeStream(def, event, deps)
|
|
156
169
|
response.headers.set(REQUEST_ID_HEADER, id)
|
|
157
170
|
return response
|
|
158
171
|
}
|
|
159
172
|
|
|
160
|
-
const { status, envelope } = await invokeOneShot(def,
|
|
173
|
+
const { status, envelope } = await invokeOneShot(def, event, deps)
|
|
161
174
|
return Response.json(envelope, { status, headers: { [REQUEST_ID_HEADER]: id } })
|
|
162
175
|
}
|
|
163
176
|
|