@pylonsync/functions 0.22.33 → 0.22.35
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 +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/workflows.d.ts +11 -0
- package/package.json +4 -3
- package/src/index.ts +1 -1
- package/src/ssr-client-bundler.test.ts +11 -0
- package/src/ssr-client-bundler.ts +13 -1
- package/src/workflows.test.ts +39 -0
- package/src/workflows.ts +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Campbell Venture Studio, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
export { query, mutation, action } from "./define";
|
|
21
21
|
export { v } from "./validators";
|
|
22
|
-
export { workflow } from "./workflows";
|
|
22
|
+
export { isWorkflowSignal, workflow } from "./workflows";
|
|
23
23
|
export type { RawResponse, RawResponseInit } from "./response";
|
|
24
24
|
export { agent, isAgentDefinition, validatorToJsonSchema, validatorSchemaToJsonSchema, } from "./agent";
|
|
25
25
|
export type { AgentDefinition, AgentTool, AgentToolRun, AgentCallArgs, AgentResult, } from "./agent";
|
package/dist/workflows.d.ts
CHANGED
|
@@ -137,6 +137,17 @@ export declare function workflow<TInput = unknown>(name: string, fn: (wf: Workfl
|
|
|
137
137
|
}): WorkflowDefinition<TInput>;
|
|
138
138
|
/** Runtime shape check for a `workflows/` file's default export. */
|
|
139
139
|
export declare function isWorkflowDefinition(v: unknown): v is WorkflowDefinition;
|
|
140
|
+
/**
|
|
141
|
+
* Whether `err` is the engine pausing the workflow (a slice boundary or a
|
|
142
|
+
* wait), not a failure. A `try`/`catch` around steps in a workflow body must
|
|
143
|
+
* rethrow these untouched, or the workflow treats every pause as a crash:
|
|
144
|
+
*
|
|
145
|
+
* catch (err) {
|
|
146
|
+
* if (isWorkflowSignal(err)) throw err;
|
|
147
|
+
* // real failure handling
|
|
148
|
+
* }
|
|
149
|
+
*/
|
|
150
|
+
export declare function isWorkflowSignal(err: unknown): boolean;
|
|
140
151
|
/**
|
|
141
152
|
* Execute one slice of `def` for `request`, returning the engine verdict.
|
|
142
153
|
* Never throws for handler errors — a step failure becomes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pylonsync/functions",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.35",
|
|
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",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"src",
|
|
31
31
|
"dist",
|
|
32
32
|
"assets",
|
|
33
|
-
"README.md"
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
34
35
|
],
|
|
35
36
|
"scripts": {
|
|
36
37
|
"check": "tsc --noEmit",
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
"functions",
|
|
46
47
|
"database"
|
|
47
48
|
],
|
|
48
|
-
"license": "MIT
|
|
49
|
+
"license": "MIT",
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"satori": "^0.26.0",
|
|
51
52
|
"@resvg/resvg-wasm": "^2.6.2",
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
export { query, mutation, action } from "./define";
|
|
22
22
|
export { v } from "./validators";
|
|
23
|
-
export { workflow } from "./workflows";
|
|
23
|
+
export { isWorkflowSignal, workflow } from "./workflows";
|
|
24
24
|
export type { RawResponse, RawResponseInit } from "./response";
|
|
25
25
|
export {
|
|
26
26
|
agent,
|
|
@@ -804,3 +804,14 @@ describe("nearestBoundaryComponent across route groups", () => {
|
|
|
804
804
|
).toBe("app/(marketing)/not-found");
|
|
805
805
|
});
|
|
806
806
|
});
|
|
807
|
+
|
|
808
|
+
describe("client router popstate", () => {
|
|
809
|
+
test("a hash-only popstate does not re-render the route", () => {
|
|
810
|
+
// Clicking a same-page anchor fires popstate. Treating it as a navigation
|
|
811
|
+
// re-rendered the page and scrolled back to the top.
|
|
812
|
+
const src = fs.readFileSync(path.join(import.meta.dir, "ssr-client-bundler.ts"), "utf8");
|
|
813
|
+
const popstate = src.slice(src.indexOf('window.addEventListener("popstate"'));
|
|
814
|
+
expect(popstate).toContain("if (next === renderedPath) return;");
|
|
815
|
+
expect(src.match(/renderedPath = location\.pathname \+ location\.search;/g)?.length).toBeGreaterThanOrEqual(3);
|
|
816
|
+
});
|
|
817
|
+
});
|
|
@@ -830,6 +830,12 @@ function renderPendingPlaceholder(pathname, manifest, myEpoch) {
|
|
|
830
830
|
return true;
|
|
831
831
|
}
|
|
832
832
|
|
|
833
|
+
// The path and query the page last rendered. A popstate that keeps them and
|
|
834
|
+
// only changes the hash is a same-page jump (an anchor link, a back press
|
|
835
|
+
// between anchors), not a navigation: re-rendering for it would reset the
|
|
836
|
+
// scroll to the top.
|
|
837
|
+
let renderedPath = "";
|
|
838
|
+
|
|
833
839
|
async function navigate(href, opts) {
|
|
834
840
|
const push = !opts || opts.push !== false;
|
|
835
841
|
const url = new URL(href, location.href);
|
|
@@ -891,6 +897,7 @@ async function navigate(href, opts) {
|
|
|
891
897
|
history.pushState({ component: matched.component }, "", target);
|
|
892
898
|
}
|
|
893
899
|
window.dispatchEvent(new Event("pylon:navigation"));
|
|
900
|
+
renderedPath = location.pathname + location.search;
|
|
894
901
|
window.scrollTo(0, 0);
|
|
895
902
|
didOptimistic = true;
|
|
896
903
|
}
|
|
@@ -915,6 +922,7 @@ async function navigate(href, opts) {
|
|
|
915
922
|
loadManifest().then((manifest) => {
|
|
916
923
|
if (navState.settled || myEpoch !== navEpoch) return;
|
|
917
924
|
if (renderPendingPlaceholder(url.pathname, manifest, myEpoch)) {
|
|
925
|
+
renderedPath = location.pathname + location.search;
|
|
918
926
|
window.scrollTo(0, 0);
|
|
919
927
|
}
|
|
920
928
|
});
|
|
@@ -1013,6 +1021,7 @@ async function navigate(href, opts) {
|
|
|
1013
1021
|
// re-read location after a Link click or a router.push(). popstate already
|
|
1014
1022
|
// covers back/forward, but pushState/replaceState fire no event.
|
|
1015
1023
|
window.dispatchEvent(new Event("pylon:navigation"));
|
|
1024
|
+
renderedPath = location.pathname + location.search;
|
|
1016
1025
|
// After a successful nav, scroll to top (Next.js default).
|
|
1017
1026
|
window.scrollTo(0, 0);
|
|
1018
1027
|
}
|
|
@@ -1042,8 +1051,11 @@ function installNavHandlers() {
|
|
|
1042
1051
|
const seed = seeds ? seeds.get(link) : undefined;
|
|
1043
1052
|
navigate(href, seed != null ? { seed } : undefined);
|
|
1044
1053
|
});
|
|
1054
|
+
renderedPath = location.pathname + location.search;
|
|
1045
1055
|
window.addEventListener("popstate", () => {
|
|
1046
|
-
|
|
1056
|
+
const next = location.pathname + location.search;
|
|
1057
|
+
if (next === renderedPath) return;
|
|
1058
|
+
navigate(next, { push: false });
|
|
1047
1059
|
});
|
|
1048
1060
|
// Progressive-enhancement form submit (#276): intercept <form data-pylon-form>
|
|
1049
1061
|
// so the page doesn't full-reload. fetch the same route.ts endpoint, follow
|
package/src/workflows.test.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { describe, expect, test } from "bun:test";
|
|
|
15
15
|
import {
|
|
16
16
|
executeWorkflowSlice,
|
|
17
17
|
isWorkflowDefinition,
|
|
18
|
+
isWorkflowSignal,
|
|
18
19
|
workflow,
|
|
19
20
|
type WorkflowRunRequest,
|
|
20
21
|
type WorkflowStepResult,
|
|
@@ -264,3 +265,41 @@ describe("executeWorkflowSlice", () => {
|
|
|
264
265
|
expect(res).toEqual({ action: "complete", output: { echoed: 42 } });
|
|
265
266
|
});
|
|
266
267
|
});
|
|
268
|
+
|
|
269
|
+
describe("catching errors around steps", () => {
|
|
270
|
+
test("a pause is a workflow signal, not a failure, when the body catches it", async () => {
|
|
271
|
+
const failures: unknown[] = [];
|
|
272
|
+
const guarded = workflow("guarded", async (wf) => {
|
|
273
|
+
try {
|
|
274
|
+
await wf.step("one", () => 1);
|
|
275
|
+
await wf.step("two", () => 2);
|
|
276
|
+
return { ok: true };
|
|
277
|
+
} catch (err) {
|
|
278
|
+
if (isWorkflowSignal(err)) throw err;
|
|
279
|
+
failures.push(err);
|
|
280
|
+
throw err;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
// Slice 0 runs step one and pauses at step two's boundary.
|
|
284
|
+
const res = await executeWorkflowSlice(guarded, req(0, []), ctx);
|
|
285
|
+
expect(res).toMatchObject({ action: "step_complete", step_name: "one" });
|
|
286
|
+
expect(failures).toEqual([]);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test("without the check, the body sees the pause as an error (the bug the helper prevents)", async () => {
|
|
290
|
+
const seen: string[] = [];
|
|
291
|
+
const careless = workflow("careless", async (wf) => {
|
|
292
|
+
try {
|
|
293
|
+
await wf.step("one", () => 1);
|
|
294
|
+
await wf.step("two", () => 2);
|
|
295
|
+
} catch (err) {
|
|
296
|
+
seen.push((err as Error).message);
|
|
297
|
+
throw err;
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
await executeWorkflowSlice(careless, req(0, []), ctx);
|
|
301
|
+
expect(seen).toEqual(["slice boundary"]);
|
|
302
|
+
expect(isWorkflowSignal(new Error("slice boundary"))).toBe(false);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
package/src/workflows.ts
CHANGED
|
@@ -178,6 +178,20 @@ class SliceBoundary extends Error {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Whether `err` is the engine pausing the workflow (a slice boundary or a
|
|
183
|
+
* wait), not a failure. A `try`/`catch` around steps in a workflow body must
|
|
184
|
+
* rethrow these untouched, or the workflow treats every pause as a crash:
|
|
185
|
+
*
|
|
186
|
+
* catch (err) {
|
|
187
|
+
* if (isWorkflowSignal(err)) throw err;
|
|
188
|
+
* // real failure handling
|
|
189
|
+
* }
|
|
190
|
+
*/
|
|
191
|
+
export function isWorkflowSignal(err: unknown): boolean {
|
|
192
|
+
return err instanceof SliceBoundary || err instanceof WorkflowPaused;
|
|
193
|
+
}
|
|
194
|
+
|
|
181
195
|
/**
|
|
182
196
|
* Execute one slice of `def` for `request`, returning the engine verdict.
|
|
183
197
|
* Never throws for handler errors — a step failure becomes
|