@pylonsync/functions 0.3.22 → 0.3.24
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/runtime.ts +26 -1
- package/src/types.ts +4 -0
package/package.json
CHANGED
package/src/runtime.ts
CHANGED
|
@@ -77,6 +77,23 @@ function fenceStdout(): void {
|
|
|
77
77
|
const line = args
|
|
78
78
|
.map((a) => {
|
|
79
79
|
if (typeof a === "string") return a;
|
|
80
|
+
// Error: JSON.stringify yields `{}` because message/stack are
|
|
81
|
+
// non-enumerable. That made `console.error("x:", err)` log as `x: {}`,
|
|
82
|
+
// hiding the real failure from operators. Unwrap by hand.
|
|
83
|
+
if (a instanceof Error) {
|
|
84
|
+
const parts = [a.stack || `${a.name}: ${a.message}`];
|
|
85
|
+
const code = (a as { code?: unknown }).code;
|
|
86
|
+
if (code !== undefined) parts.push(`code=${String(code)}`);
|
|
87
|
+
const cause = (a as { cause?: unknown }).cause;
|
|
88
|
+
if (cause !== undefined) {
|
|
89
|
+
try {
|
|
90
|
+
parts.push(`cause=${cause instanceof Error ? cause.stack || cause.message : JSON.stringify(cause)}`);
|
|
91
|
+
} catch {
|
|
92
|
+
parts.push(`cause=${String(cause)}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return parts.join(" ");
|
|
96
|
+
}
|
|
80
97
|
try {
|
|
81
98
|
return JSON.stringify(a);
|
|
82
99
|
} catch {
|
|
@@ -543,10 +560,17 @@ async function handleCall(msg: CallMessage): Promise<void> {
|
|
|
543
560
|
null,
|
|
544
561
|
};
|
|
545
562
|
|
|
563
|
+
// Env is read-only config — safe to expose on every ctx variant. Without
|
|
564
|
+
// this, queries/mutations that need a config flag have to be declared as
|
|
565
|
+
// actions just to reach `process.env`, which is a footgun: the failure
|
|
566
|
+
// mode is `ctx.env.X` throwing "cannot read properties of undefined" at
|
|
567
|
+
// runtime, with no compile-time hint.
|
|
568
|
+
const env = process.env as Record<string, string>;
|
|
569
|
+
|
|
546
570
|
let ctx: QueryCtx | MutationCtx | ActionCtx;
|
|
547
571
|
switch (def.type) {
|
|
548
572
|
case "query":
|
|
549
|
-
ctx = { db: buildDbReader(msg.call_id), auth };
|
|
573
|
+
ctx = { db: buildDbReader(msg.call_id), auth, env };
|
|
550
574
|
break;
|
|
551
575
|
case "mutation":
|
|
552
576
|
ctx = {
|
|
@@ -554,6 +578,7 @@ async function handleCall(msg: CallMessage): Promise<void> {
|
|
|
554
578
|
auth,
|
|
555
579
|
stream,
|
|
556
580
|
scheduler,
|
|
581
|
+
env,
|
|
557
582
|
error(code, message) {
|
|
558
583
|
const err = new Error(message);
|
|
559
584
|
(err as any).code = code;
|
package/src/types.ts
CHANGED
|
@@ -179,6 +179,8 @@ export interface Scheduler {
|
|
|
179
179
|
export interface QueryCtx {
|
|
180
180
|
db: DbReader;
|
|
181
181
|
auth: AuthInfo;
|
|
182
|
+
/** Environment variables / secrets. */
|
|
183
|
+
env: Record<string, string>;
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** Context for mutation handlers (read + write, transactional). */
|
|
@@ -187,6 +189,8 @@ export interface MutationCtx {
|
|
|
187
189
|
auth: AuthInfo;
|
|
188
190
|
stream: Stream;
|
|
189
191
|
scheduler: Scheduler;
|
|
192
|
+
/** Environment variables / secrets. */
|
|
193
|
+
env: Record<string, string>;
|
|
190
194
|
/** Create a typed error that triggers rollback. */
|
|
191
195
|
error(code: string, message: string): Error;
|
|
192
196
|
}
|