@lunora/runtime 1.0.0-alpha.4 → 1.0.0-alpha.40
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/LICENSE.md +6 -0
- package/README.md +17 -0
- package/dist/index.d.mts +3393 -1170
- package/dist/index.d.ts +3393 -1170
- package/dist/index.mjs +1 -14
- package/dist/packem_shared/DEFAULT_LOG_COLUMNS-B0imn1l0.mjs +1 -0
- package/dist/packem_shared/DEFAULT_REGISTRY_CACHE_TTL_MS-CsNnfJzB.mjs +1 -0
- package/dist/packem_shared/HEALTH_PATH-BEE0A_lZ.mjs +1 -0
- package/dist/packem_shared/LOG_ARCHIVE_NOT_CONFIGURED-CDpi4yFD.mjs +1 -0
- package/dist/packem_shared/LOG_ARCHIVE_PATH-DGsEec3K.mjs +1 -0
- package/dist/packem_shared/LunoraError-ByasbDmd.mjs +1 -0
- package/dist/packem_shared/NOOP_EXECUTION_CONTEXT-YmXqH-jH.mjs +1 -0
- package/dist/packem_shared/analyticsEngineSink-CUWYuLHs.mjs +1 -0
- package/dist/packem_shared/applyJurisdiction-uRQLx282.mjs +1 -0
- package/dist/packem_shared/argsFromQuery-0KrWTkNx.mjs +1 -0
- package/dist/packem_shared/composeIdentityResolvers-DwE0Jbww.mjs +1 -0
- package/dist/packem_shared/composeWorker-IO6LYYK2.mjs +6 -0
- package/dist/packem_shared/createCrossShardRelationCapabilities-CMWiFA5s.mjs +1 -0
- package/dist/packem_shared/createKvCursorStore-C24tEuYk.mjs +3 -0
- package/dist/packem_shared/createQueryCoordinator-DqrEvhPD.mjs +1 -0
- package/dist/packem_shared/createShardClient-62qcYKGl.mjs +1 -0
- package/dist/packem_shared/decorateResponse-DBIWsRSZ.mjs +1 -0
- package/dist/packem_shared/emitLogEvent-BcdChmSV.mjs +1 -0
- package/dist/packem_shared/memoizeIdentity-CZGtDc4H.mjs +1 -0
- package/dist/packem_shared/method-guard-BbuR0VfS.mjs +1 -0
- package/dist/packem_shared/observability-DYnm-d4g.mjs +1 -0
- package/dist/packem_shared/otlp-resource-B-ByO9qo.mjs +1 -0
- package/dist/packem_shared/pipeline-log-reader-DU_CCGDA.mjs +1 -0
- package/dist/packem_shared/toAirbyteMessages-DBTuFjb5.mjs +1 -0
- package/package.json +6 -2
- package/dist/packem_shared/DEFAULT_REGISTRY_CACHE_TTL_MS-ocax8v0n.mjs +0 -78
- package/dist/packem_shared/LunoraError-CL0aOtpo.mjs +0 -46
- package/dist/packem_shared/analyticsEngineSink-DqEvrQs0.mjs +0 -141
- package/dist/packem_shared/applyJurisdiction-BkZtTkct.mjs +0 -20
- package/dist/packem_shared/composeWorker-Dxt4Mo0R.mjs +0 -2506
- package/dist/packem_shared/createCrossShardRelationCapabilities-C0KOf7er.mjs +0 -61
- package/dist/packem_shared/createQueryCoordinator-Cbds9cUI.mjs +0 -838
- package/dist/packem_shared/decorateResponse-DbISh_Wi.mjs +0 -233
- package/dist/packem_shared/emitLogEvent-pEdtqAK8.mjs +0 -20
- package/dist/packem_shared/toAirbyteMessages-DrHdplb4.mjs +0 -39
|
@@ -1,46 +0,0 @@
|
|
|
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 };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
const shouldSkip = (event, onlyErrors) => onlyErrors === true && event.ok;
|
|
2
|
-
const mergeHeaders = (defaults, overrides) => {
|
|
3
|
-
if (!overrides) {
|
|
4
|
-
return { ...defaults };
|
|
5
|
-
}
|
|
6
|
-
const merged = {};
|
|
7
|
-
const seen = /* @__PURE__ */ new Map();
|
|
8
|
-
for (const [name, value] of Object.entries(defaults)) {
|
|
9
|
-
const lower = name.toLowerCase();
|
|
10
|
-
seen.set(lower, name);
|
|
11
|
-
merged[name] = value;
|
|
12
|
-
}
|
|
13
|
-
for (const [name, value] of Object.entries(overrides)) {
|
|
14
|
-
const lower = name.toLowerCase();
|
|
15
|
-
const existing = seen.get(lower);
|
|
16
|
-
if (existing === void 0) {
|
|
17
|
-
seen.set(lower, name);
|
|
18
|
-
merged[name] = value;
|
|
19
|
-
} else {
|
|
20
|
-
merged[existing] = value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return merged;
|
|
24
|
-
};
|
|
25
|
-
const consoleSink = (options = {}) => {
|
|
26
|
-
const { onlyErrors } = options;
|
|
27
|
-
return {
|
|
28
|
-
onLog: (event) => {
|
|
29
|
-
if (event.level === "error") {
|
|
30
|
-
console.error("[lunora:log]", event.functionPath, event.message);
|
|
31
|
-
} else {
|
|
32
|
-
console.log("[lunora:log]", event.functionPath, event.message);
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
onRpc: (event) => {
|
|
36
|
-
if (shouldSkip(event, onlyErrors)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (event.ok) {
|
|
40
|
-
console.log("[lunora:rpc]", event);
|
|
41
|
-
} else {
|
|
42
|
-
console.error("[lunora:rpc]", event);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const webhookSink = (options) => {
|
|
48
|
-
const { headers, onlyErrors, transform, url } = options;
|
|
49
|
-
const mergedHeaders = mergeHeaders({ "content-type": "application/json" }, headers);
|
|
50
|
-
return {
|
|
51
|
-
onRpc: (event, context) => {
|
|
52
|
-
if (shouldSkip(event, onlyErrors)) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
let payload = event;
|
|
57
|
-
if (transform) {
|
|
58
|
-
try {
|
|
59
|
-
payload = transform(event);
|
|
60
|
-
} catch {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (payload === null || payload === void 0) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
const sent = fetch(url, {
|
|
68
|
-
body: JSON.stringify(payload),
|
|
69
|
-
headers: mergedHeaders,
|
|
70
|
-
method: "POST"
|
|
71
|
-
}).catch(() => {
|
|
72
|
-
});
|
|
73
|
-
if (context?.waitUntil) {
|
|
74
|
-
context.waitUntil(sent);
|
|
75
|
-
}
|
|
76
|
-
} catch {
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
const sentrySink = (options) => {
|
|
82
|
-
const { capture } = options;
|
|
83
|
-
const onlyErrors = options.onlyErrors ?? true;
|
|
84
|
-
return {
|
|
85
|
-
onRpc: (event) => {
|
|
86
|
-
if (shouldSkip(event, onlyErrors)) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
capture(event);
|
|
91
|
-
} catch {
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
const analyticsEngineSink = (options) => {
|
|
97
|
-
const { dataset, onlyErrors } = options;
|
|
98
|
-
return {
|
|
99
|
-
onRpc: (event) => {
|
|
100
|
-
if (shouldSkip(event, onlyErrors)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
try {
|
|
104
|
-
dataset.writeDataPoint({
|
|
105
|
-
blobs: [event.functionPath, event.ok ? "ok" : "error", event.shardKey ?? "", event.error?.code ?? "", event.fanOut?.table ?? ""],
|
|
106
|
-
doubles: [event.durationMs, event.ok ? 0 : 1, event.fanOut?.shards ?? 0, event.fanOut?.failed ?? 0],
|
|
107
|
-
indexes: [event.functionPath]
|
|
108
|
-
});
|
|
109
|
-
} catch {
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
const combineSinks = (...sinks) => {
|
|
115
|
-
return {
|
|
116
|
-
onLog: (event, context) => {
|
|
117
|
-
for (const sink of sinks) {
|
|
118
|
-
if (!sink.onLog) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
sink.onLog(event, context);
|
|
123
|
-
} catch {
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
onRpc: (event, context) => {
|
|
128
|
-
for (const sink of sinks) {
|
|
129
|
-
if (!sink.onRpc) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
sink.onRpc(event, context);
|
|
134
|
-
} catch {
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
export { analyticsEngineSink, combineSinks, consoleSink, sentrySink, webhookSink };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const applyJurisdiction = (namespace, jurisdiction) => {
|
|
2
|
-
if (jurisdiction === void 0) {
|
|
3
|
-
return namespace;
|
|
4
|
-
}
|
|
5
|
-
if (typeof namespace.jurisdiction !== "function") {
|
|
6
|
-
throw new TypeError(
|
|
7
|
-
`@lunora/runtime: Durable Object namespace does not support jurisdiction("${jurisdiction}") — update @cloudflare/workers-types or remove the jurisdiction option`
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
return namespace.jurisdiction(jurisdiction);
|
|
11
|
-
};
|
|
12
|
-
const resolveShard = (namespace, shardKey) => {
|
|
13
|
-
if (typeof namespace.getByName === "function") {
|
|
14
|
-
return namespace.getByName(shardKey);
|
|
15
|
-
}
|
|
16
|
-
const id = namespace.idFromName(shardKey);
|
|
17
|
-
return namespace.get(id);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export { applyJurisdiction, resolveShard };
|