@atomservice/functions-sdk 0.1.6 → 0.1.8
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 +21 -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,13 @@ 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
|
+
console.log(" ")
|
|
122
|
+
}
|
|
123
|
+
|
|
117
124
|
return Bun.serve({
|
|
118
125
|
port: options.port,
|
|
119
126
|
async fetch(request) {
|
|
@@ -124,7 +131,7 @@ export function serve(
|
|
|
124
131
|
return Response.json({ ok: true, functions })
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
if (request.method === "POST" && url.pathname.startsWith(INVOKE_PATH_PREFIX)) {
|
|
134
|
+
if ((request.method === "GET" || request.method === "POST") && url.pathname.startsWith(INVOKE_PATH_PREFIX)) {
|
|
128
135
|
const name = url.pathname.slice(INVOKE_PATH_PREFIX.length)
|
|
129
136
|
const def = registry[name]
|
|
130
137
|
if (!def) {
|
|
@@ -148,16 +155,23 @@ export function serve(
|
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
const id = requestId(request)
|
|
151
|
-
const
|
|
158
|
+
const queryParams: Record<string, unknown> = {}
|
|
159
|
+
url.searchParams.forEach((v, k) => {
|
|
160
|
+
queryParams[k] = v
|
|
161
|
+
})
|
|
162
|
+
const bodyParams = await readBody(request)
|
|
163
|
+
const event = typeof bodyParams === "object" && bodyParams !== null
|
|
164
|
+
? { ...queryParams, ...(bodyParams as Record<string, unknown>) }
|
|
165
|
+
: queryParams
|
|
152
166
|
const deps = { executor: router.pick(def), name, requestId: id, defaultTimeout: options.defaultTimeout }
|
|
153
167
|
|
|
154
168
|
if (isStreamKind(def)) {
|
|
155
|
-
const response = invokeStream(def,
|
|
169
|
+
const response = invokeStream(def, event, deps)
|
|
156
170
|
response.headers.set(REQUEST_ID_HEADER, id)
|
|
157
171
|
return response
|
|
158
172
|
}
|
|
159
173
|
|
|
160
|
-
const { status, envelope } = await invokeOneShot(def,
|
|
174
|
+
const { status, envelope } = await invokeOneShot(def, event, deps)
|
|
161
175
|
return Response.json(envelope, { status, headers: { [REQUEST_ID_HEADER]: id } })
|
|
162
176
|
}
|
|
163
177
|
|