k99 0.6.0-alpha.7 → 0.6.0-alpha.9
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/browser.cjs +1 -1
- package/browser.d.ts +1 -1
- package/browser.js +1 -1
- package/browser.min.js +1 -1
- package/browser.min.mjs +1 -1
- package/browser.mjs +1 -1
- package/cli/index.cjs +2 -2
- package/cli/{index.d.ts → index.d.cts} +7 -35
- package/cli.cjs +1 -1
- package/index.cjs +211 -52
- package/index.d.ts +24 -15
- package/index.js +211 -52
- package/index.min.js +2 -2
- package/index.min.mjs +2 -2
- package/index.mjs +211 -52
- package/node/index.cjs +8 -3
- package/node/{index.d.ts → index.d.cts} +84 -83
- package/package.json +6 -3
- package/services.cjs +1 -1
- package/services.d.ts +1 -1
- package/services.js +1 -1
- package/services.min.js +1 -1
- package/services.min.mjs +1 -1
- package/services.mjs +1 -1
- package/starter.cjs +1 -1
package/browser.cjs
CHANGED
package/browser.d.ts
CHANGED
package/browser.js
CHANGED
package/browser.min.js
CHANGED
package/browser.min.mjs
CHANGED
package/browser.mjs
CHANGED
package/cli/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* k99 v0.6.0-alpha.
|
|
2
|
+
* k99 v0.6.0-alpha.9
|
|
3
3
|
* (c) 2019-2023 猛火Fierflame
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -106,7 +106,7 @@ async function exec({
|
|
|
106
106
|
cfg.dependencies = {};
|
|
107
107
|
}
|
|
108
108
|
if (!cfg.dependencies.k99) {
|
|
109
|
-
cfg.dependencies.k99 = '^0.6.0-alpha.
|
|
109
|
+
cfg.dependencies.k99 = '^0.6.0-alpha.9';
|
|
110
110
|
}
|
|
111
111
|
await fsPromise__namespace.writeFile('package.json', JSON.stringify(cfg, null, 2));
|
|
112
112
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* k99 v0.6.0-alpha.
|
|
2
|
+
* k99 v0.6.0-alpha.9
|
|
3
3
|
* (c) 2019-2023 猛火Fierflame
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -10,11 +10,7 @@ declare const name$3 = "socket";
|
|
|
10
10
|
declare const explain$5 = "\u76D1\u542C\u7684\u672C\u5730\u5957\u63A5\u5B57";
|
|
11
11
|
|
|
12
12
|
declare namespace listen {
|
|
13
|
-
export {
|
|
14
|
-
explain$5 as explain,
|
|
15
|
-
name$3 as name,
|
|
16
|
-
value$3 as value,
|
|
17
|
-
};
|
|
13
|
+
export { explain$5 as explain, name$3 as name, value$3 as value };
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
declare function value$2(...opts: string[]): string;
|
|
@@ -22,11 +18,7 @@ declare const name$2 = "path";
|
|
|
22
18
|
declare const explain$4 = "\u73AF\u5883\u8DEF\u5F84";
|
|
23
19
|
|
|
24
20
|
declare namespace path {
|
|
25
|
-
export {
|
|
26
|
-
explain$4 as explain,
|
|
27
|
-
name$2 as name,
|
|
28
|
-
value$2 as value,
|
|
29
|
-
};
|
|
21
|
+
export { explain$4 as explain, name$2 as name, value$2 as value };
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
declare function value$1(...opts: string[]): number | undefined;
|
|
@@ -34,11 +26,7 @@ declare const name$1 = "port";
|
|
|
34
26
|
declare const explain$3 = "\u76D1\u542C\u7684\u7F51\u7EDC\u7AEF\u53E3\u53F7";
|
|
35
27
|
|
|
36
28
|
declare namespace port {
|
|
37
|
-
export {
|
|
38
|
-
explain$3 as explain,
|
|
39
|
-
name$1 as name,
|
|
40
|
-
value$1 as value,
|
|
41
|
-
};
|
|
29
|
+
export { explain$3 as explain, name$1 as name, value$1 as value };
|
|
42
30
|
}
|
|
43
31
|
|
|
44
32
|
declare function value(...opts: string[]): string;
|
|
@@ -48,11 +36,7 @@ declare const explain$2 = "\u7ED1\u5B9A\u7684 IP";
|
|
|
48
36
|
declare const bind_name: typeof name;
|
|
49
37
|
declare const bind_value: typeof value;
|
|
50
38
|
declare namespace bind {
|
|
51
|
-
export {
|
|
52
|
-
explain$2 as explain,
|
|
53
|
-
bind_name as name,
|
|
54
|
-
bind_value as value,
|
|
55
|
-
};
|
|
39
|
+
export { explain$2 as explain, bind_name as name, bind_value as value };
|
|
56
40
|
}
|
|
57
41
|
|
|
58
42
|
type List = keyof typeof opt;
|
|
@@ -71,13 +55,7 @@ declare const explain$1 = "\u542F\u52A8\u670D\u52A1\u5668";
|
|
|
71
55
|
declare function help$1(...argv: string[]): Promise<void>;
|
|
72
56
|
|
|
73
57
|
declare namespace start {
|
|
74
|
-
export {
|
|
75
|
-
argv$1 as argv,
|
|
76
|
-
exec$1 as exec,
|
|
77
|
-
explain$1 as explain,
|
|
78
|
-
help$1 as help,
|
|
79
|
-
opts$1 as opts,
|
|
80
|
-
};
|
|
58
|
+
export { argv$1 as argv, exec$1 as exec, explain$1 as explain, help$1 as help, opts$1 as opts };
|
|
81
59
|
}
|
|
82
60
|
|
|
83
61
|
declare function exec({ path }: opt, ...args: string[]): Promise<void>;
|
|
@@ -92,13 +70,7 @@ declare const init_explain: typeof explain;
|
|
|
92
70
|
declare const init_help: typeof help;
|
|
93
71
|
declare const init_opts: typeof opts;
|
|
94
72
|
declare namespace init {
|
|
95
|
-
export {
|
|
96
|
-
init_argv as argv,
|
|
97
|
-
init_exec as exec,
|
|
98
|
-
init_explain as explain,
|
|
99
|
-
init_help as help,
|
|
100
|
-
init_opts as opts,
|
|
101
|
-
};
|
|
73
|
+
export { init_argv as argv, init_exec as exec, init_explain as explain, init_help as help, init_opts as opts };
|
|
102
74
|
}
|
|
103
75
|
|
|
104
76
|
declare const _default: {
|
package/cli.cjs
CHANGED
package/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* k99 v0.6.0-alpha.
|
|
2
|
+
* k99 v0.6.0-alpha.9
|
|
3
3
|
* (c) 2019-2023 猛火Fierflame
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -373,6 +373,7 @@ function createWrite() {
|
|
|
373
373
|
abortReject = reject;
|
|
374
374
|
}
|
|
375
375
|
});
|
|
376
|
+
abortedPromise.then(null, () => {});
|
|
376
377
|
function abort(e) {
|
|
377
378
|
if (abortException) {
|
|
378
379
|
return false;
|
|
@@ -889,67 +890,70 @@ function signal2promise(signal) {
|
|
|
889
890
|
});
|
|
890
891
|
});
|
|
891
892
|
}
|
|
892
|
-
function main(req, getHandler, environment, parent) {
|
|
893
|
+
function main(req, getHandler, environment, runner, parent) {
|
|
893
894
|
const aborted = signal2promise(req.signal);
|
|
894
895
|
const {
|
|
895
896
|
context,
|
|
896
897
|
setParams,
|
|
897
898
|
destroy,
|
|
898
899
|
sendHeaders
|
|
899
|
-
} = createContext(req, opt => main(createRequest(opt), getHandler, environment, context), environment, parent);
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
const [writable, readable, abortResponse] = createWrite();
|
|
906
|
-
aborted.catch(e => abortResponse(e));
|
|
907
|
-
function send() {
|
|
908
|
-
if (!sendHeaders()) {
|
|
909
|
-
return;
|
|
900
|
+
} = createContext(req, opt => main(createRequest(opt), getHandler, environment, runner, context), environment, parent);
|
|
901
|
+
function run() {
|
|
902
|
+
return Promise.race([aborted, Promise.resolve().then(() => getHandler(context, setParams))]).then(handler => new Promise(resolve => {
|
|
903
|
+
if (!handler) {
|
|
904
|
+
destroy();
|
|
905
|
+
return resolve(null);
|
|
910
906
|
}
|
|
911
|
-
const
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
907
|
+
const [writable, readable, abortResponse] = createWrite();
|
|
908
|
+
aborted.catch(e => abortResponse(e));
|
|
909
|
+
function send() {
|
|
910
|
+
if (!sendHeaders()) {
|
|
911
|
+
return;
|
|
912
|
+
}
|
|
913
|
+
const {
|
|
914
|
+
status
|
|
915
|
+
} = context;
|
|
916
|
+
resolve({
|
|
917
|
+
...readable,
|
|
918
|
+
get status() {
|
|
919
|
+
return status;
|
|
920
|
+
},
|
|
921
|
+
get finished() {
|
|
922
|
+
return writable.ended;
|
|
923
|
+
},
|
|
924
|
+
headers: Object.freeze(context.getHeaders()),
|
|
925
|
+
[Symbol.asyncIterator]() {
|
|
926
|
+
return readable;
|
|
927
|
+
}
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
const contextS = {
|
|
919
931
|
get finished() {
|
|
920
932
|
return writable.ended;
|
|
921
933
|
},
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
return
|
|
934
|
+
write(chunk) {
|
|
935
|
+
send();
|
|
936
|
+
return writable.write(chunk);
|
|
925
937
|
}
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
get finished() {
|
|
930
|
-
return writable.ended;
|
|
931
|
-
},
|
|
932
|
-
write(chunk) {
|
|
938
|
+
};
|
|
939
|
+
const actionContext = Object.create(context, Object.getOwnPropertyDescriptors(contextS));
|
|
940
|
+
Promise.race([aborted, runHandle(actionContext, handler)]).then(() => {
|
|
933
941
|
send();
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
send();
|
|
945
|
-
abortResponse(e);
|
|
942
|
+
destroy();
|
|
943
|
+
writable.end();
|
|
944
|
+
}, e => {
|
|
945
|
+
context.status = 500;
|
|
946
|
+
send();
|
|
947
|
+
abortResponse(e);
|
|
948
|
+
destroy(e || true);
|
|
949
|
+
writable.end();
|
|
950
|
+
});
|
|
951
|
+
}), e => {
|
|
946
952
|
destroy(e || true);
|
|
947
|
-
|
|
953
|
+
return Promise.reject(e);
|
|
948
954
|
});
|
|
949
|
-
}
|
|
950
|
-
|
|
951
|
-
return Promise.reject(e);
|
|
952
|
-
});
|
|
955
|
+
}
|
|
956
|
+
return runner ? runner(context, run) : run();
|
|
953
957
|
}
|
|
954
958
|
|
|
955
959
|
async function defaultRead$2() {
|
|
@@ -1138,12 +1142,12 @@ function createEnvironment(options) {
|
|
|
1138
1142
|
|
|
1139
1143
|
function run(req, getHandler, options) {
|
|
1140
1144
|
const environment = createEnvironment(options);
|
|
1141
|
-
return main(req, getHandler, environment);
|
|
1145
|
+
return main(req, getHandler, environment, options?.runner);
|
|
1142
1146
|
}
|
|
1143
1147
|
|
|
1144
1148
|
function make(getHandler, options) {
|
|
1145
1149
|
const environment = createEnvironment(options);
|
|
1146
|
-
return r => main(r, getHandler, environment);
|
|
1150
|
+
return r => main(r, getHandler, environment, options?.runner);
|
|
1147
1151
|
}
|
|
1148
1152
|
|
|
1149
1153
|
async function runHandles(context, handlers) {
|
|
@@ -1531,6 +1535,28 @@ class ApiRouter extends Router {
|
|
|
1531
1535
|
* @param router 要注册的子路由
|
|
1532
1536
|
*/
|
|
1533
1537
|
|
|
1538
|
+
/**
|
|
1539
|
+
* 添加子路由
|
|
1540
|
+
* @param path 要注册的路径
|
|
1541
|
+
* @param router 要注册的子路由
|
|
1542
|
+
*/
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* 添加子路由
|
|
1546
|
+
* @param path 要注册的路径
|
|
1547
|
+
*/
|
|
1548
|
+
|
|
1549
|
+
/**
|
|
1550
|
+
* 添加子路由
|
|
1551
|
+
* @param find 要注册的子路由的 Finder
|
|
1552
|
+
*/
|
|
1553
|
+
|
|
1554
|
+
/**
|
|
1555
|
+
* 添加子路由
|
|
1556
|
+
* @param path 要注册的路径
|
|
1557
|
+
* @param find 要注册的子路由的 Finder
|
|
1558
|
+
*/
|
|
1559
|
+
|
|
1534
1560
|
route(...p) {
|
|
1535
1561
|
const [a] = p;
|
|
1536
1562
|
if (a && typeof a === 'object' && !(a instanceof Router)) {
|
|
@@ -1571,6 +1597,19 @@ class ApiRouter extends Router {
|
|
|
1571
1597
|
* @param handler 要注册的处理函数
|
|
1572
1598
|
*/
|
|
1573
1599
|
|
|
1600
|
+
/**
|
|
1601
|
+
* 注册处理函数
|
|
1602
|
+
* @param method 要注册的方法
|
|
1603
|
+
* @param path 要注册的路径
|
|
1604
|
+
* @param handler 要注册的处理函数
|
|
1605
|
+
*/
|
|
1606
|
+
|
|
1607
|
+
/**
|
|
1608
|
+
* 注册处理函数
|
|
1609
|
+
* @param method 要注册的方法
|
|
1610
|
+
* @param path 要注册的路径
|
|
1611
|
+
*/
|
|
1612
|
+
|
|
1574
1613
|
verb(methods, path, handler) {
|
|
1575
1614
|
const allMethods = getMethods(methods);
|
|
1576
1615
|
if (!allMethods.length) {
|
|
@@ -1583,6 +1622,22 @@ class ApiRouter extends Router {
|
|
|
1583
1622
|
* @param handler 要注册的处理函数
|
|
1584
1623
|
*/
|
|
1585
1624
|
|
|
1625
|
+
/**
|
|
1626
|
+
* 注册处理函数
|
|
1627
|
+
* @param path 要注册的路径
|
|
1628
|
+
* @param handler 要注册的处理函数
|
|
1629
|
+
*/
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* 注册 HTTP GET/POST/PUT/DELETE 处理函数
|
|
1633
|
+
* @param path 要注册的路径
|
|
1634
|
+
*/
|
|
1635
|
+
|
|
1636
|
+
/**
|
|
1637
|
+
* 注册 HTTP GET/POST/PUT/DELETE 处理函数
|
|
1638
|
+
* @param path 要注册的路径
|
|
1639
|
+
*/
|
|
1640
|
+
|
|
1586
1641
|
match(...p) {
|
|
1587
1642
|
return verb(this.#routes, ['GET', 'POST', 'PUT', 'DELETE'], p);
|
|
1588
1643
|
}
|
|
@@ -1591,6 +1646,22 @@ class ApiRouter extends Router {
|
|
|
1591
1646
|
* @param handler 要注册的处理函数
|
|
1592
1647
|
*/
|
|
1593
1648
|
|
|
1649
|
+
/**
|
|
1650
|
+
* 注册 HTTP GET 处理函数
|
|
1651
|
+
* @param path 要注册的路径
|
|
1652
|
+
* @param handler 要注册的处理函数
|
|
1653
|
+
*/
|
|
1654
|
+
|
|
1655
|
+
/**
|
|
1656
|
+
* 注册 HTTP GET 处理函数
|
|
1657
|
+
* @param path 要注册的路径
|
|
1658
|
+
*/
|
|
1659
|
+
|
|
1660
|
+
/**
|
|
1661
|
+
* 注册 HTTP GET 处理函数
|
|
1662
|
+
* @param path 要注册的路径
|
|
1663
|
+
*/
|
|
1664
|
+
|
|
1594
1665
|
get(...p) {
|
|
1595
1666
|
return verb(this.#routes, ['GET'], p);
|
|
1596
1667
|
}
|
|
@@ -1599,6 +1670,22 @@ class ApiRouter extends Router {
|
|
|
1599
1670
|
* @param handler 要注册的处理函数
|
|
1600
1671
|
*/
|
|
1601
1672
|
|
|
1673
|
+
/**
|
|
1674
|
+
* 注册 HTTP POST 处理函数
|
|
1675
|
+
* @param path 要注册的路径
|
|
1676
|
+
* @param handler 要注册的处理函数
|
|
1677
|
+
*/
|
|
1678
|
+
|
|
1679
|
+
/**
|
|
1680
|
+
* 注册 HTTP POST 处理函数
|
|
1681
|
+
* @param path 要注册的路径
|
|
1682
|
+
*/
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
* 注册 HTTP POST 处理函数
|
|
1686
|
+
* @param path 要注册的路径
|
|
1687
|
+
*/
|
|
1688
|
+
|
|
1602
1689
|
post(...p) {
|
|
1603
1690
|
return verb(this.#routes, ['POST'], p);
|
|
1604
1691
|
}
|
|
@@ -1607,6 +1694,22 @@ class ApiRouter extends Router {
|
|
|
1607
1694
|
* @param handler 要注册的处理函数
|
|
1608
1695
|
*/
|
|
1609
1696
|
|
|
1697
|
+
/**
|
|
1698
|
+
* 注册 HTTP PUT 处理函数
|
|
1699
|
+
* @param path 要注册的路径
|
|
1700
|
+
* @param handler 要注册的处理函数
|
|
1701
|
+
*/
|
|
1702
|
+
|
|
1703
|
+
/**
|
|
1704
|
+
* 注册 HTTP PUT 处理函数
|
|
1705
|
+
* @param path 要注册的路径
|
|
1706
|
+
*/
|
|
1707
|
+
|
|
1708
|
+
/**
|
|
1709
|
+
* 注册 HTTP PUT 处理函数
|
|
1710
|
+
* @param path 要注册的路径
|
|
1711
|
+
*/
|
|
1712
|
+
|
|
1610
1713
|
put(...p) {
|
|
1611
1714
|
return verb(this.#routes, ['PUT'], p);
|
|
1612
1715
|
}
|
|
@@ -1615,6 +1718,22 @@ class ApiRouter extends Router {
|
|
|
1615
1718
|
* @param handler 要注册的处理函数
|
|
1616
1719
|
*/
|
|
1617
1720
|
|
|
1721
|
+
/**
|
|
1722
|
+
* 注册 HTTP DELETE 处理函数
|
|
1723
|
+
* @param path 要注册的路径
|
|
1724
|
+
* @param handler 要注册的处理函数
|
|
1725
|
+
*/
|
|
1726
|
+
|
|
1727
|
+
/**
|
|
1728
|
+
* 注册 HTTP DELETE 处理函数
|
|
1729
|
+
* @param path 要注册的路径
|
|
1730
|
+
*/
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
* 注册 HTTP DELETE 处理函数
|
|
1734
|
+
* @param path 要注册的路径
|
|
1735
|
+
*/
|
|
1736
|
+
|
|
1618
1737
|
delete(...p) {
|
|
1619
1738
|
return verb(this.#routes, ['DELETE'], p);
|
|
1620
1739
|
}
|
|
@@ -1623,6 +1742,22 @@ class ApiRouter extends Router {
|
|
|
1623
1742
|
* @param handler 要注册的处理函数
|
|
1624
1743
|
*/
|
|
1625
1744
|
|
|
1745
|
+
/**
|
|
1746
|
+
* 注册 HTTP HEAD 处理函数
|
|
1747
|
+
* @param path 要注册的路径
|
|
1748
|
+
* @param handler 要注册的处理函数
|
|
1749
|
+
*/
|
|
1750
|
+
|
|
1751
|
+
/**
|
|
1752
|
+
* 注册 HTTP HEAD 处理函数
|
|
1753
|
+
* @param path 要注册的路径
|
|
1754
|
+
*/
|
|
1755
|
+
|
|
1756
|
+
/**
|
|
1757
|
+
* 注册 HTTP HEAD 处理函数
|
|
1758
|
+
* @param path 要注册的路径
|
|
1759
|
+
*/
|
|
1760
|
+
|
|
1626
1761
|
head(...p) {
|
|
1627
1762
|
return verb(this.#routes, ['HEAD'], p);
|
|
1628
1763
|
}
|
|
@@ -1631,6 +1766,22 @@ class ApiRouter extends Router {
|
|
|
1631
1766
|
* @param handler 要注册的处理函数
|
|
1632
1767
|
*/
|
|
1633
1768
|
|
|
1769
|
+
/**
|
|
1770
|
+
* 注册 HTTP OPTIONS 处理函数
|
|
1771
|
+
* @param path 要注册的路径
|
|
1772
|
+
* @param handler 要注册的处理函数
|
|
1773
|
+
*/
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* 注册 HTTP OPTIONS 处理函数
|
|
1777
|
+
* @param path 要注册的路径
|
|
1778
|
+
*/
|
|
1779
|
+
|
|
1780
|
+
/**
|
|
1781
|
+
* 注册 HTTP OPTIONS 处理函数
|
|
1782
|
+
* @param path 要注册的路径
|
|
1783
|
+
*/
|
|
1784
|
+
|
|
1634
1785
|
options(...p) {
|
|
1635
1786
|
return verb(this.#routes, ['OPTIONS'], p);
|
|
1636
1787
|
}
|
|
@@ -1645,7 +1796,8 @@ class Plugin {
|
|
|
1645
1796
|
router,
|
|
1646
1797
|
setting,
|
|
1647
1798
|
asset,
|
|
1648
|
-
log
|
|
1799
|
+
log,
|
|
1800
|
+
runner
|
|
1649
1801
|
} = {}) {
|
|
1650
1802
|
const routers = [];
|
|
1651
1803
|
for (const plugin of Object.values(plugins)) {
|
|
@@ -1657,7 +1809,8 @@ class Plugin {
|
|
|
1657
1809
|
return make(Router.make(routers), {
|
|
1658
1810
|
setting,
|
|
1659
1811
|
asset: Plugin.bindAsset(asset, plugins),
|
|
1660
|
-
log
|
|
1812
|
+
log,
|
|
1813
|
+
runner
|
|
1661
1814
|
});
|
|
1662
1815
|
}
|
|
1663
1816
|
static bindAsset(api, plugins, pluginPath = 'plugins') {
|
|
@@ -1700,6 +1853,12 @@ class Plugin {
|
|
|
1700
1853
|
|
|
1701
1854
|
/** 包名 */
|
|
1702
1855
|
|
|
1856
|
+
/** 版本 */
|
|
1857
|
+
|
|
1858
|
+
/** 作者 */
|
|
1859
|
+
|
|
1860
|
+
/** 开源协议 */
|
|
1861
|
+
|
|
1703
1862
|
constructor(name, /** 版本 */
|
|
1704
1863
|
version, {
|
|
1705
1864
|
author,
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* k99 v0.6.0-alpha.
|
|
2
|
+
* k99 v0.6.0-alpha.9
|
|
3
3
|
* (c) 2019-2023 猛火Fierflame
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -216,6 +216,8 @@ declare namespace Service {
|
|
|
216
216
|
readonly rootOnly?: boolean;
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
|
+
type StoreService<T> = Service<T | undefined, T, [s?: T]>;
|
|
220
|
+
type StateService<T> = Service<T, T, []>;
|
|
219
221
|
interface Context {
|
|
220
222
|
readonly environment?: Environment;
|
|
221
223
|
/** 当前的路由 */
|
|
@@ -338,6 +340,10 @@ interface Handler {
|
|
|
338
340
|
plugin?: string;
|
|
339
341
|
}
|
|
340
342
|
|
|
343
|
+
interface Runner {
|
|
344
|
+
(context: Context, run: () => Promise<K99Response | null>): Promise<K99Response | null>;
|
|
345
|
+
}
|
|
346
|
+
|
|
341
347
|
interface Guard {
|
|
342
348
|
(ctx: Context): PromiseLike<boolean | Handler | void> | boolean | Handler | void;
|
|
343
349
|
}
|
|
@@ -347,7 +353,7 @@ type FindItem = [
|
|
|
347
353
|
string[]
|
|
348
354
|
];
|
|
349
355
|
interface Finder {
|
|
350
|
-
(method: Method, path: string[]): AsyncIterable<FindItem> | Iterable<FindItem>;
|
|
356
|
+
(this: Router, method: Method, path: string[]): AsyncIterable<FindItem> | Iterable<FindItem>;
|
|
351
357
|
}
|
|
352
358
|
declare abstract class Router {
|
|
353
359
|
disabled: boolean;
|
|
@@ -364,14 +370,14 @@ declare namespace Router {
|
|
|
364
370
|
}
|
|
365
371
|
}
|
|
366
372
|
|
|
367
|
-
interface Match {
|
|
368
|
-
(paths: string[]): [Record<string, string | string[]>, string[]] | undefined;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
373
|
interface Binder {
|
|
372
374
|
(handler: Handler): () => void;
|
|
373
375
|
}
|
|
374
376
|
|
|
377
|
+
interface Match {
|
|
378
|
+
(paths: string[]): [Record<string, string | string[]>, string[]] | undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
375
381
|
interface Route {
|
|
376
382
|
/** 路径匹配 */
|
|
377
383
|
match?: Match;
|
|
@@ -603,18 +609,20 @@ declare class ApiRouter extends Router {
|
|
|
603
609
|
options(...path: Parameters<typeof String.raw>): Binder;
|
|
604
610
|
}
|
|
605
611
|
|
|
606
|
-
declare function main(req: K99Request, getHandler: (ctx: Context, setParams: (v: any) => void) => PromiseLike<Handler | null> | Handler | null, environment?: Environment, parent?: Context): Promise<K99Response | null>;
|
|
612
|
+
declare function main(req: K99Request, getHandler: (ctx: Context, setParams: (v: any) => void) => PromiseLike<Handler | null> | Handler | null, environment?: Environment, runner?: Runner, parent?: Context): Promise<K99Response | null>;
|
|
607
613
|
|
|
608
614
|
declare function run(req: K99Request, getHandler: (ctx: Context, setParams: (v: any) => void) => Promise<Handler | null> | Handler | null, options?: {
|
|
609
615
|
setting?: Setting.Api;
|
|
610
616
|
asset?: Asset.Api;
|
|
611
617
|
log?: Log.Api;
|
|
618
|
+
runner?: Runner;
|
|
612
619
|
}): Promise<K99Response | null>;
|
|
613
620
|
|
|
614
621
|
declare function make(getHandler: (ctx: Context, setParams: (v: any) => void) => Promise<Handler | null> | Handler | null, options?: {
|
|
615
622
|
setting?: Setting.Api;
|
|
616
623
|
asset?: Asset.Api;
|
|
617
624
|
log?: Log.Api;
|
|
625
|
+
runner?: Runner;
|
|
618
626
|
}): (r: K99Request) => Promise<K99Response | null>;
|
|
619
627
|
|
|
620
628
|
declare function merge(...handlers: (Handler | Handler[])[]): Handler;
|
|
@@ -622,20 +630,21 @@ declare function merge(...handlers: (Handler | Handler[])[]): Handler;
|
|
|
622
630
|
declare function service<T, D, P extends any[]>(exec: (ctx: ServiceContext<D, false>, ...p: P) => T, destroy?: ((ctx: ServiceContext<D, true>) => PromiseLike<void> | void) | null, options?: Service.Options): Service<T, D, P>;
|
|
623
631
|
declare function service<T, D, P extends any[]>(exec: (ctx: ServiceContext<D, false>, ...p: P) => T, options?: Service.Options): Service<T, D, P>;
|
|
624
632
|
|
|
625
|
-
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, options?: Service.Options):
|
|
626
|
-
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, options?: Service.Options):
|
|
627
|
-
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, exec?: ((state: T, ctx: ServiceContext<T, false>) => any) | null, options?: Service.Options):
|
|
633
|
+
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, options?: Service.Options): StateService<T>;
|
|
634
|
+
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, options?: Service.Options): StateService<T>;
|
|
635
|
+
declare function stateService<T>(init: (ctx: ServiceContext<void, false>) => T, destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, exec?: ((state: T, ctx: ServiceContext<T, false>) => any) | null, options?: Service.Options): StateService<T>;
|
|
628
636
|
|
|
629
|
-
declare function storeService<T>(options?: Service.Options):
|
|
630
|
-
declare function storeService<T>(destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, options?: Service.Options):
|
|
631
|
-
declare function storeService<T>(destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, exec?: ((state: T | undefined, ctx: ServiceContext<T, false>) => any) | null, options?: Service.Options):
|
|
637
|
+
declare function storeService<T>(options?: Service.Options): StoreService<T>;
|
|
638
|
+
declare function storeService<T>(destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, options?: Service.Options): StoreService<T>;
|
|
639
|
+
declare function storeService<T>(destroy?: ((state: T | undefined, ctx: ServiceContext<T, true>) => PromiseLike<void> | void) | null, exec?: ((state: T | undefined, ctx: ServiceContext<T, false>) => any) | null, options?: Service.Options): StoreService<T>;
|
|
632
640
|
|
|
633
641
|
declare abstract class Plugin<T extends Router = Router> {
|
|
634
|
-
static make(plugins: Record<string, Plugin>, { router, setting, asset, log }?: {
|
|
642
|
+
static make(plugins: Record<string, Plugin>, { router, setting, asset, log, runner }?: {
|
|
635
643
|
router?: Router;
|
|
636
644
|
asset?: Asset.Api;
|
|
637
645
|
setting?: Setting.Api;
|
|
638
646
|
log?: Log.Api;
|
|
647
|
+
runner?: Runner;
|
|
639
648
|
}): (r: K99Request) => Promise<K99Response | null>;
|
|
640
649
|
static bindAsset(api: Asset.Api, plugins?: Record<string, Plugin>, pluginPath?: string): Asset.Api;
|
|
641
650
|
static bindAsset(api?: Asset.Api, plugins?: Record<string, Plugin>, pluginPath?: string): Asset.Api | undefined;
|
|
@@ -673,4 +682,4 @@ declare function createEnvironment(options?: {
|
|
|
673
682
|
error?: (e: unknown) => void;
|
|
674
683
|
}): Environment;
|
|
675
684
|
|
|
676
|
-
export { ActionContext, ApiRouter, Asset, Binder, Context, CookieClearOption, CookieOption, CookieOptionInfo, Encoding, Environment, FindItem, Finder, Guard, Handler, HexEncoding, K99Headers, K99Request, K99Response, Log, Match, Method, Plugin, Route, RouteBinder, Router, RouterRoute, Service, ServiceContext, Setting, WriteType, createEnvironment, main, make, merge, run, service, stateService, storeService };
|
|
685
|
+
export { type ActionContext, ApiRouter, Asset, type Binder, type Context, type CookieClearOption, type CookieOption, type CookieOptionInfo, type Encoding, type Environment, type FindItem, type Finder, type Guard, type Handler, type HexEncoding, type K99Headers, K99Request, type K99Response, Log, type Match, type Method, Plugin, type Route, type RouteBinder, Router, type RouterRoute, type Runner, Service, type ServiceContext, Setting, type WriteType, createEnvironment, main, make, merge, run, service, stateService, storeService };
|