@lunora/runtime 0.0.0 → 1.0.0-alpha.1

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/dist/index.mjs ADDED
@@ -0,0 +1,14 @@
1
+ export { toAirbyteMessages, toFivetranResponse } from './packem_shared/toAirbyteMessages-DrHdplb4.mjs';
2
+ export { composeWorker, createWorker, defineRpcEnvelope, withFrameworkWorker } from './packem_shared/composeWorker-BYHiNH_V.mjs';
3
+ export { createCrossShardRelationCapabilities } from './packem_shared/createCrossShardRelationCapabilities-C0KOf7er.mjs';
4
+ export { DEFAULT_REGISTRY_CACHE_TTL_MS, SHARD_REGISTRY_DO_NAME, createDynamicShardRegistry } from './packem_shared/createDynamicShardRegistry-BpCwo_mo.mjs';
5
+ export { LunoraError, toErrorResponse } from './packem_shared/LunoraError-CL0aOtpo.mjs';
6
+ export { emitLogEvent, emitRpcEvent } from './packem_shared/emitRpcEvent-pEdtqAK8.mjs';
7
+ export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink } from './packem_shared/consoleSink-DqEvrQs0.mjs';
8
+ export { createQueryCoordinator, createStaticShardRegistry, mergeStrategyForAggregate } from './packem_shared/createQueryCoordinator-DbxC7iUz.mjs';
9
+ export { resolveShard } from './packem_shared/resolveShard-DDkzWtrU.mjs';
10
+ export { decorateResponse, enforceOrigin, handleCorsPreflight, resolveSecurity } from './packem_shared/decorateResponse-DbISh_Wi.mjs';
11
+
12
+ const VERSION = "0.0.0";
13
+
14
+ export { VERSION };
@@ -0,0 +1,46 @@
1
+ class LunoraError extends Error {
2
+ code;
3
+ status;
4
+ constructor(message, options) {
5
+ super(message, { cause: options?.cause });
6
+ this.name = "LunoraError";
7
+ this.code = options?.code ?? "INTERNAL";
8
+ this.status = options?.status ?? 500;
9
+ }
10
+ toResponse() {
11
+ const body = { error: { code: this.code, message: this.message } };
12
+ return Response.json(body, {
13
+ headers: { "content-type": "application/json" },
14
+ status: this.status
15
+ });
16
+ }
17
+ }
18
+ const hasErrorShape = (error, name) => {
19
+ if (!error || typeof error !== "object") {
20
+ return false;
21
+ }
22
+ const candidate = error;
23
+ return candidate.name === name && typeof candidate.code === "string" && typeof candidate.status === "number" && typeof candidate.message === "string";
24
+ };
25
+ const isStructuralConflictError = (error) => hasErrorShape(error, "ConflictError");
26
+ const isStructuralLunoraError = (error) => hasErrorShape(error, "LunoraError");
27
+ const toErrorResponse = (error) => {
28
+ if (error instanceof LunoraError) {
29
+ return error.toResponse();
30
+ }
31
+ if (isStructuralLunoraError(error) || isStructuralConflictError(error)) {
32
+ const body2 = { error: { code: error.code, message: error.message } };
33
+ return Response.json(body2, {
34
+ headers: { "content-type": "application/json" },
35
+ status: error.status
36
+ });
37
+ }
38
+ console.error("[lunora] unhandled error:", error);
39
+ const body = { error: { code: "INTERNAL", message: "Internal error" } };
40
+ return Response.json(body, {
41
+ headers: { "content-type": "application/json" },
42
+ status: 500
43
+ });
44
+ };
45
+
46
+ export { LunoraError, isStructuralConflictError, isStructuralLunoraError, toErrorResponse };