@pactor-app/runtime 1.18.1 → 1.21.0
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/index.cjs +36 -1
- package/dist/index.js +36 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -82,7 +82,14 @@ function createFetchHttpAdapter() {
|
|
|
82
82
|
headers["content-type"] ?? (headers["content-type"] = "application/json");
|
|
83
83
|
body = JSON.stringify(config.body);
|
|
84
84
|
}
|
|
85
|
-
const response = await fetch(url, {
|
|
85
|
+
const response = await fetch(url, {
|
|
86
|
+
method,
|
|
87
|
+
headers,
|
|
88
|
+
body,
|
|
89
|
+
// 跨源 cookie 会话(服务端开通 CORS + Allow-Credentials 时生效;
|
|
90
|
+
// 同源行为不变)
|
|
91
|
+
credentials: "include"
|
|
92
|
+
});
|
|
86
93
|
if (!response.ok) {
|
|
87
94
|
throw new Error(
|
|
88
95
|
`[@pactor-app/runtime] http request failed: ${response.status} ${response.statusText} (${config.url})`
|
|
@@ -604,6 +611,34 @@ function registerBuiltinActions(registry) {
|
|
|
604
611
|
};
|
|
605
612
|
}
|
|
606
613
|
});
|
|
614
|
+
register("service.call", async (action, ctx) => {
|
|
615
|
+
const name = action.params?.["service"];
|
|
616
|
+
if (typeof name !== "string" || name === "") {
|
|
617
|
+
return {
|
|
618
|
+
ok: false,
|
|
619
|
+
error: new Error("[@pactor-app/runtime] service.call \u7F3A\u5C11 params.service")
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
const handler = ctx.context.services.get(name);
|
|
623
|
+
if (!handler) {
|
|
624
|
+
return {
|
|
625
|
+
ok: false,
|
|
626
|
+
error: new Error(`[@pactor-app/runtime] service \u672A\u6CE8\u518C: ${name}`)
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
try {
|
|
630
|
+
const callParams = action.params?.["params"];
|
|
631
|
+
const data = await handler(
|
|
632
|
+
isRecord(callParams) ? callParams : {}
|
|
633
|
+
);
|
|
634
|
+
return { ok: true, data };
|
|
635
|
+
} catch (cause) {
|
|
636
|
+
return {
|
|
637
|
+
ok: false,
|
|
638
|
+
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
});
|
|
607
642
|
register("sequence", async (action, ctx) => {
|
|
608
643
|
for (const child of asActions(action.params?.["actions"])) {
|
|
609
644
|
const result = await ctx.execute(child);
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,14 @@ function createFetchHttpAdapter() {
|
|
|
34
34
|
headers["content-type"] ?? (headers["content-type"] = "application/json");
|
|
35
35
|
body = JSON.stringify(config.body);
|
|
36
36
|
}
|
|
37
|
-
const response = await fetch(url, {
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
body,
|
|
41
|
+
// 跨源 cookie 会话(服务端开通 CORS + Allow-Credentials 时生效;
|
|
42
|
+
// 同源行为不变)
|
|
43
|
+
credentials: "include"
|
|
44
|
+
});
|
|
38
45
|
if (!response.ok) {
|
|
39
46
|
throw new Error(
|
|
40
47
|
`[@pactor-app/runtime] http request failed: ${response.status} ${response.statusText} (${config.url})`
|
|
@@ -559,6 +566,34 @@ function registerBuiltinActions(registry) {
|
|
|
559
566
|
};
|
|
560
567
|
}
|
|
561
568
|
});
|
|
569
|
+
register("service.call", async (action, ctx) => {
|
|
570
|
+
const name = action.params?.["service"];
|
|
571
|
+
if (typeof name !== "string" || name === "") {
|
|
572
|
+
return {
|
|
573
|
+
ok: false,
|
|
574
|
+
error: new Error("[@pactor-app/runtime] service.call \u7F3A\u5C11 params.service")
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const handler = ctx.context.services.get(name);
|
|
578
|
+
if (!handler) {
|
|
579
|
+
return {
|
|
580
|
+
ok: false,
|
|
581
|
+
error: new Error(`[@pactor-app/runtime] service \u672A\u6CE8\u518C: ${name}`)
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
const callParams = action.params?.["params"];
|
|
586
|
+
const data = await handler(
|
|
587
|
+
isRecord(callParams) ? callParams : {}
|
|
588
|
+
);
|
|
589
|
+
return { ok: true, data };
|
|
590
|
+
} catch (cause) {
|
|
591
|
+
return {
|
|
592
|
+
ok: false,
|
|
593
|
+
error: cause instanceof Error ? cause : new Error(String(cause))
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
});
|
|
562
597
|
register("sequence", async (action, ctx) => {
|
|
563
598
|
for (const child of asActions(action.params?.["actions"])) {
|
|
564
599
|
const result = await ctx.execute(child);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pactor-app/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"description": "Pactor runtime: RuntimeContext, StateStore, DataSource runtime, action engine, React renderer and page runtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pactor",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@pactor-app/core": "1.
|
|
49
|
-
"@pactor-app/expression": "1.
|
|
50
|
-
"@pactor-app/schema": "1.
|
|
48
|
+
"@pactor-app/core": "1.21.0",
|
|
49
|
+
"@pactor-app/expression": "1.21.0",
|
|
50
|
+
"@pactor-app/schema": "1.21.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=18"
|