@pylonsync/functions 0.3.27 → 0.3.28

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
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/define.ts CHANGED
@@ -15,16 +15,32 @@ import type {
15
15
  interface QueryDef<TArgs, TReturn> {
16
16
  args?: Record<string, Validator>;
17
17
  handler: (ctx: QueryCtx, args: TArgs) => Promise<TReturn>;
18
+ /**
19
+ * When true, the function is callable only via `ctx.runQuery()`
20
+ * from another function — never via the public `/api/fn/<name>`
21
+ * HTTP endpoint. The router refuses external calls with
22
+ * `404 FN_NOT_FOUND` so probing can't even confirm the name exists.
23
+ *
24
+ * Use for queries that are meant as helpers for trusted action /
25
+ * mutation flows but would be unsafe if any caller could invoke
26
+ * them directly (e.g. they trust args without re-checking caller
27
+ * authority).
28
+ */
29
+ internal?: boolean;
18
30
  }
19
31
 
20
32
  interface MutationDef<TArgs, TReturn> {
21
33
  args?: Record<string, Validator>;
22
34
  handler: (ctx: MutationCtx, args: TArgs) => Promise<TReturn>;
35
+ /** See QueryDef.internal — applies the same way to mutations. */
36
+ internal?: boolean;
23
37
  }
24
38
 
25
39
  interface ActionDef<TArgs, TReturn> {
26
40
  args?: Record<string, Validator>;
27
41
  handler: (ctx: ActionCtx, args: TArgs) => Promise<TReturn>;
42
+ /** See QueryDef.internal — applies the same way to actions. */
43
+ internal?: boolean;
28
44
  }
29
45
 
30
46
  /**
@@ -49,7 +65,12 @@ interface ActionDef<TArgs, TReturn> {
49
65
  export function query<TArgs = Record<string, unknown>, TReturn = unknown>(
50
66
  def: QueryDef<TArgs, TReturn>
51
67
  ): FnDefinition<TArgs, TReturn> {
52
- return { type: "query", args: def.args, handler: def.handler };
68
+ return {
69
+ type: "query",
70
+ args: def.args,
71
+ handler: def.handler,
72
+ internal: def.internal,
73
+ };
53
74
  }
54
75
 
55
76
  /**
@@ -78,7 +99,12 @@ export function query<TArgs = Record<string, unknown>, TReturn = unknown>(
78
99
  export function mutation<TArgs = Record<string, unknown>, TReturn = unknown>(
79
100
  def: MutationDef<TArgs, TReturn>
80
101
  ): FnDefinition<TArgs, TReturn> {
81
- return { type: "mutation", args: def.args, handler: def.handler };
102
+ return {
103
+ type: "mutation",
104
+ args: def.args,
105
+ handler: def.handler,
106
+ internal: def.internal,
107
+ };
82
108
  }
83
109
 
84
110
  /**
@@ -105,5 +131,10 @@ export function mutation<TArgs = Record<string, unknown>, TReturn = unknown>(
105
131
  export function action<TArgs = Record<string, unknown>, TReturn = unknown>(
106
132
  def: ActionDef<TArgs, TReturn>
107
133
  ): FnDefinition<TArgs, TReturn> {
108
- return { type: "action", args: def.args, handler: def.handler };
134
+ return {
135
+ type: "action",
136
+ args: def.args,
137
+ handler: def.handler,
138
+ internal: def.internal,
139
+ };
109
140
  }
package/src/runtime.ts CHANGED
@@ -715,6 +715,11 @@ async function main() {
715
715
  name,
716
716
  fn_type: def.type,
717
717
  args_schema: def.args || null,
718
+ // Whether the function is callable only via runQuery/runMutation/
719
+ // runAction from another function. The Rust router refuses /api/fn
720
+ // requests for internal fns; the Bun runtime here doesn't gate
721
+ // (nested calls go through the same dispatcher).
722
+ internal: def.internal === true,
718
723
  }));
719
724
  send({ type: "ready", functions });
720
725
 
package/src/types.ts CHANGED
@@ -277,6 +277,14 @@ export interface FnDefinition<TArgs = unknown, TReturn = unknown> {
277
277
  type: FnType;
278
278
  args?: Record<string, Validator>;
279
279
  handler: (ctx: any, args: TArgs) => Promise<TReturn>;
280
+ /**
281
+ * When true, this function is reachable only via `ctx.runQuery()` /
282
+ * `ctx.runMutation()` / `ctx.runAction()` from another function —
283
+ * the public `/api/fn/<name>` endpoint refuses external calls.
284
+ * The router enforces this; the runtime treats internal == external
285
+ * for execution.
286
+ */
287
+ internal?: boolean;
280
288
  }
281
289
 
282
290
  // ---------------------------------------------------------------------------