@pylonsync/functions 0.3.362 → 0.3.363

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/types.d.ts CHANGED
@@ -449,6 +449,13 @@ export interface QueryCtx<R extends AuthRequirement = "optional"> {
449
449
  auth: AuthInfo<R>;
450
450
  /** Environment variables / secrets. */
451
451
  env: Record<string, string>;
452
+ /**
453
+ * Create a typed error. Unlike the mutation version there's no
454
+ * transaction to roll back — this exists so a query can answer with a
455
+ * code the caller can branch on (`AUCTION_NOT_FOUND`) instead of a bare
456
+ * `throw new Error(...)`, which reaches the client as `UNKNOWN`.
457
+ */
458
+ error(code: string, message: string): Error;
452
459
  /** Assert org membership (optionally a role) — see {@link RequireMember}. */
453
460
  requireMember: RequireMember;
454
461
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.3.362",
3
+ "version": "0.3.363",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/runtime.ts CHANGED
@@ -920,6 +920,13 @@ async function handleCall(msg: CallMessage): Promise<void> {
920
920
  db: reader,
921
921
  auth,
922
922
  env,
923
+ // No transaction to roll back here — this is purely so a query
924
+ // can fail with a code the caller can branch on.
925
+ error(code, message) {
926
+ const err = new Error(message);
927
+ (err as any).code = code;
928
+ return err;
929
+ },
923
930
  requireMember: makeRequireMember(auth.userId, (entity, filter) =>
924
931
  reader.query(entity, { ...filter, $limit: 1 }),
925
932
  ),
package/src/types.ts CHANGED
@@ -542,6 +542,13 @@ export interface QueryCtx<R extends AuthRequirement = "optional"> {
542
542
  auth: AuthInfo<R>;
543
543
  /** Environment variables / secrets. */
544
544
  env: Record<string, string>;
545
+ /**
546
+ * Create a typed error. Unlike the mutation version there's no
547
+ * transaction to roll back — this exists so a query can answer with a
548
+ * code the caller can branch on (`AUCTION_NOT_FOUND`) instead of a bare
549
+ * `throw new Error(...)`, which reaches the client as `UNKNOWN`.
550
+ */
551
+ error(code: string, message: string): Error;
545
552
  /** Assert org membership (optionally a role) — see {@link RequireMember}. */
546
553
  requireMember: RequireMember;
547
554
  }