@thestarweb/star-framework-web-runtime 0.0.0-stage → 1.1.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.
Files changed (93) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/dist/index.js +4 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/load-package.js +46 -0
  5. package/dist/load-package.js.map +1 -0
  6. package/dist/main.js +95 -0
  7. package/dist/main.js.map +1 -0
  8. package/dist/mime.js +6 -0
  9. package/dist/mime.js.map +1 -0
  10. package/dist/node.js +55 -0
  11. package/dist/node.js.map +1 -0
  12. package/dist/package-loader/base-package-loader.js +125 -0
  13. package/dist/package-loader/base-package-loader.js.map +1 -0
  14. package/dist/package-loader/default-loader/index.js +17 -0
  15. package/dist/package-loader/default-loader/index.js.map +1 -0
  16. package/dist/package-loader/index.js +14 -0
  17. package/dist/package-loader/index.js.map +1 -0
  18. package/dist/package-loader/worker-thread/index.js +82 -0
  19. package/dist/package-loader/worker-thread/index.js.map +1 -0
  20. package/dist/package-loader/worker-thread/main-thread-ctrl.js +101 -0
  21. package/dist/package-loader/worker-thread/main-thread-ctrl.js.map +1 -0
  22. package/dist/package-loader/worker-thread/types.js +14 -0
  23. package/dist/package-loader/worker-thread/types.js.map +1 -0
  24. package/dist/package-loader/worker-thread/worker.js +51 -0
  25. package/dist/package-loader/worker-thread/worker.js.map +1 -0
  26. package/dist/parse-instances-config.js +81 -0
  27. package/dist/parse-instances-config.js.map +1 -0
  28. package/dist/remote-call/const.js +21 -0
  29. package/dist/remote-call/const.js.map +1 -0
  30. package/dist/remote-call/remote-call-client.js +76 -0
  31. package/dist/remote-call/remote-call-client.js.map +1 -0
  32. package/dist/remote-call/utile/message-port-to-connection.js +147 -0
  33. package/dist/remote-call/utile/message-port-to-connection.js.map +1 -0
  34. package/dist/remote-call/utile/remote-message/build.js +30 -0
  35. package/dist/remote-call/utile/remote-message/build.js.map +1 -0
  36. package/dist/remote-call/utile/remote-message/json-handle.js +15 -0
  37. package/dist/remote-call/utile/remote-message/json-handle.js.map +1 -0
  38. package/dist/remote-call/utile/remote-message/message.js +45 -0
  39. package/dist/remote-call/utile/remote-message/message.js.map +1 -0
  40. package/dist/remote-call/utile/remote-message/reader.js +18 -0
  41. package/dist/remote-call/utile/remote-message/reader.js.map +1 -0
  42. package/dist/remote-call/utile/remote-message/uint8-array-handle.js +27 -0
  43. package/dist/remote-call/utile/remote-message/uint8-array-handle.js.map +1 -0
  44. package/dist/remote-call/utile/remote-message/uint8-handle.js +19 -0
  45. package/dist/remote-call/utile/remote-message/uint8-handle.js.map +1 -0
  46. package/dist/remote-call/utile/remote-message/value-handle.js +5 -0
  47. package/dist/remote-call/utile/remote-message/value-handle.js.map +1 -0
  48. package/dist/remote-call/utile/remote-message/var-char-handle.js +31 -0
  49. package/dist/remote-call/utile/remote-message/var-char-handle.js.map +1 -0
  50. package/dist/remote-call/utile/remote-message/var-uint-handle.js +36 -0
  51. package/dist/remote-call/utile/remote-message/var-uint-handle.js.map +1 -0
  52. package/dist/type.js +16 -0
  53. package/dist/type.js.map +1 -0
  54. package/dist/types/config.js +11 -0
  55. package/dist/types/config.js.map +1 -0
  56. package/dist/types/index.js +5 -0
  57. package/dist/types/index.js.map +1 -0
  58. package/dist/types/instance.js +7 -0
  59. package/dist/types/instance.js.map +1 -0
  60. package/dist/types/package-info.js +4 -0
  61. package/dist/types/package-info.js.map +1 -0
  62. package/dist/types/resolved.js +13 -0
  63. package/dist/types/resolved.js.map +1 -0
  64. package/package.json +35 -5
  65. package/src/index.ts +3 -0
  66. package/src/mime.ts +5 -0
  67. package/src/node.ts +49 -0
  68. package/src/package-loader/base-package-loader.ts +142 -0
  69. package/src/package-loader/default-loader/index.ts +15 -0
  70. package/src/package-loader/index.ts +23 -0
  71. package/src/package-loader/worker-thread/index.ts +81 -0
  72. package/src/package-loader/worker-thread/main-thread-ctrl.ts +99 -0
  73. package/src/package-loader/worker-thread/types.ts +15 -0
  74. package/src/package-loader/worker-thread/worker.ts +49 -0
  75. package/src/parse-instances-config.ts +84 -0
  76. package/src/remote-call/const.ts +17 -0
  77. package/src/remote-call/remote-call-client.ts +95 -0
  78. package/src/remote-call/utile/message-port-to-connection.ts +134 -0
  79. package/src/remote-call/utile/remote-message/build.ts +26 -0
  80. package/src/remote-call/utile/remote-message/json-handle.ts +14 -0
  81. package/src/remote-call/utile/remote-message/message.ts +57 -0
  82. package/src/remote-call/utile/remote-message/reader.ts +16 -0
  83. package/src/remote-call/utile/remote-message/uint8-array-handle.ts +23 -0
  84. package/src/remote-call/utile/remote-message/uint8-handle.ts +16 -0
  85. package/src/remote-call/utile/remote-message/value-handle.ts +10 -0
  86. package/src/remote-call/utile/remote-message/var-char-handle.ts +28 -0
  87. package/src/remote-call/utile/remote-message/var-uint-handle.ts +32 -0
  88. package/src/types/config.ts +13 -0
  89. package/src/types/index.ts +4 -0
  90. package/src/types/instance.ts +15 -0
  91. package/src/types/package-info.ts +14 -0
  92. package/src/types/resolved.ts +44 -0
  93. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/message.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;;+BACpB,mBAAmB;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,QAAQ,GAAG;IAChB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE;QACzB,EAAE,IAAI,EAAE,IAAa,EAAE,MAAM,EAAE,aAAa,EAAE;QAC9C,EAAE,IAAI,EAAE,MAAe,EAAE,MAAM,EAAE,aAAa,EAAE;QAChD,EAAE,IAAI,EAAE,YAAqB,EAAE,MAAM,EAAE,WAAW,EAAE;QACpD,EAAE,IAAI,EAAE,SAAkB,EAAE,MAAM,EAAE,aAAa,EAAE;QACnD,EAAE,IAAI,EAAE,MAAe,EAAE,MAAM,EAAE,aAAa,EAAE;QAChD,EAAE,IAAI,EAAE,QAAiB,EAAE,MAAM,EAAE,UAAU,EAAE;QAC/C,EAAE,IAAI,EAAE,SAAkB,EAAE,MAAM,EAAE,UAAU,EAAE;KAChD;IACD,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE;QAC5B,EAAE,IAAI,EAAE,MAAe,EAAE,MAAM,EAAE,aAAa,EAAE;QAChD,EAAE,IAAI,EAAE,QAAiB,EAAE,MAAM,EAAE,UAAU,EAAE;KAC/C;CAC2E,CAAC;;;AAY9E,MAAM,UAAU,aAAa,CAC5B,IAAO,EACP,CAAqB;IAErB,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC9B,OAAO,YAAY,CAClB,MAAM,CAAC,GAAG,cAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAU,wBAAC,CAC1D,CAAC;AACH,CAAC;;AAED,MAAM,UAAU,WAAW,CAC1B,IAAO,EACP,OAAmB;IAEnB,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,IAAI,GAAQ,EAAE,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,cAAC,CAAC,CAAC,EAAE,EAAE;QAC7B,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC,wBAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,18 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ export class Reader {
6
+ arr;
7
+ pos;
8
+ constructor(arr, pos = 0) {
9
+ this.arr = arr;
10
+ this.pos = pos;
11
+ }
12
+ static reader(arr, handle, pos = 0) {
13
+ const reader = new Reader(arr, pos);
14
+ return handle.map(__assignType(i => i.read(reader), ['i', '', 'P"2!"/"']));
15
+ }
16
+ static __type = ['arr', 'pos', 'constructor', 'handle', 'reader', 'Reader', 'PW2!:"2":"0#PW2!"2$"2""0%s5w&'];
17
+ }
18
+ //# sourceMappingURL=reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reader.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/reader.ts"],"names":[],"mappings":";;;;AAEA,MAAM,OAAO,MAAM;IAEV;IACA;IAFR,YACQ,GAAe,EACf,MAAM,CAAC;QADP,QAAG,GAAH,GAAG,CAAY;QACf,QAAG,GAAH,GAAG,CAAI;IACZ,CAAC;IACJ,MAAM,CAAC,MAAM,CACZ,GAAe,EACf,MAAS,EACT,GAAG,GAAG,CAAC;QAEL,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,EAAC,GAAG,CAAC,CAAC;QACrC,OAAO,MAAM,CAAC,GAAG,cAAC,CAAC,CAAA,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,wBAAC,CAAA;IACtC,CAAC"}
@@ -0,0 +1,27 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { VarUIntHandle } from "./var-uint-handle.js";
6
+ export const UInt8ArrayHandle = {
7
+ build(value) {
8
+ const lFlag = VarUIntHandle.build(value.length);
9
+ const length = lFlag.length + value.length;
10
+ return {
11
+ length,
12
+ fill: __assignType(function fill(builder) {
13
+ lFlag.fill(builder);
14
+ builder.buff.set(value, builder.offset);
15
+ builder.offset += value.length;
16
+ }, ['builder', 'fill', 'P"2!"/"']),
17
+ };
18
+ },
19
+ read: __assignType(function (reader) {
20
+ const length = VarUIntHandle.read(reader);
21
+ const end = reader.pos + length;
22
+ const res = reader.arr.subarray(reader.pos, end);
23
+ reader.pos = end;
24
+ return res;
25
+ }, ['reader', '', 'P"2!"/"']),
26
+ };
27
+ //# sourceMappingURL=uint8-array-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8-array-handle.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/uint8-array-handle.ts"],"names":[],"mappings":";;;;AACA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAA4B;IACxD,KAAK,CAAC,KAAK;QACV,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3C,OAAO;YACN,MAAM;YACN,IAAI,wBAAJ,IAAI,CAAC,OAAO;gBACX,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;gBACvC,OAAO,CAAC,MAAM,IAAE,KAAK,CAAC,MAAM,CAAC;YAC9B,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,eAAE,UAAU,MAAM;QACpB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC;QAChC,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;QAChD,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,OAAO,GAAG,CAAC;IACb,CAAC,4BAAA;CACD,CAAC"}
@@ -0,0 +1,19 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { Reader } from "./reader.js";
6
+ export const UInt8Handle = {
7
+ build(value) {
8
+ return {
9
+ length: 1,
10
+ fill: __assignType(function fill(builder) {
11
+ builder.buff[builder.offset++] = value;
12
+ }, ['builder', 'fill', 'P"2!"/"']),
13
+ };
14
+ },
15
+ read: __assignType(function read(reader) {
16
+ return reader.arr[reader.pos++];
17
+ }, [() => Reader, 'reader', 'read', 'PP7!2""/#']),
18
+ };
19
+ //# sourceMappingURL=uint8-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8-handle.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/uint8-handle.ts"],"names":[],"mappings":";;;;AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,MAAM,WAAW,GAAwB;IAC/C,KAAK,CAAC,KAAK;QACV,OAAO;YACN,MAAM,EAAE,CAAC;YACT,IAAI,wBAAJ,IAAI,CAAC,OAAO;gBACX,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;YACxC,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,wBAAJ,IAAI,CAAC,MAAc;QAClB,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IACjC,CAAC;CACD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Builder } from "./build.js";
2
+ import { Reader } from "./reader.js";
3
+ const __ΩValueHandle = ['T', 'value', 'length', () => Builder, 'builder', 'fill', 'build', () => Reader, 'reader', 'read', 'ValueHandle', 'b!PPe#!2"P\'4#9PP7$2%$1&M1\'PP7(2)e#!1*Mw+y'];
4
+ export { __ΩValueHandle as __ΩValueHandle };
5
+ //# sourceMappingURL=value-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value-handle.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/value-handle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,31 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ import { Buffer } from "node:buffer";
6
+ import { VarUIntHandle } from "./var-uint-handle.js";
7
+ const encoder = new TextEncoder();
8
+ const decoder = new TextDecoder();
9
+ export const VarCharHandle = {
10
+ build(value) {
11
+ let strLength = Buffer.byteLength(value, "utf-8");
12
+ const lFlag = VarUIntHandle.build(strLength);
13
+ const length = lFlag.length + strLength;
14
+ return {
15
+ length,
16
+ fill: __assignType(function fill(builder) {
17
+ lFlag.fill(builder);
18
+ builder.buff.write(value, builder.offset, strLength, "utf-8");
19
+ builder.offset += strLength;
20
+ }, ['builder', 'fill', 'P"2!"/"']),
21
+ };
22
+ },
23
+ read: __assignType(function (reader) {
24
+ const length = VarUIntHandle.read(reader);
25
+ const end = reader.pos + length;
26
+ const text = decoder.decode(reader.arr.subarray(reader.pos, end));
27
+ reader.pos = end;
28
+ return text;
29
+ }, ['reader', '', 'P"2!"/"']),
30
+ };
31
+ //# sourceMappingURL=var-char-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"var-char-handle.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/var-char-handle.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAwB;IACjD,KAAK,CAAC,KAAK;QACV,IAAI,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAClD,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC;QACxC,OAAO;YACN,MAAM;YACN,IAAI,wBAAJ,IAAI,CAAC,OAAO;gBACX,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACpB,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;gBAC9D,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC;YAC7B,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,eAAE,UAAU,MAAM;QACrB,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAClE,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;QACjB,OAAO,IAAI,CAAC;IACb,CAAC,4BAAA;CACD,CAAC"}
@@ -0,0 +1,36 @@
1
+ function __assignType(fn, args) {
2
+ fn.__type = args;
3
+ return fn;
4
+ }
5
+ const map = [0x80, 0x4000, 0x200000, 0x10000000, 0x800000000];
6
+ export const VarUIntHandle = {
7
+ build(value) {
8
+ let i = 0;
9
+ while (map[i] < value)
10
+ i++;
11
+ const length = i + 1;
12
+ return {
13
+ length,
14
+ fill: __assignType(function fill(builder) {
15
+ let v = value;
16
+ while (v > 0x7f) {
17
+ builder.write((v & 0x7f) | 0x80);
18
+ v >>= 7;
19
+ }
20
+ builder.write(v);
21
+ }, ['builder', 'fill', 'P"2!"/"']),
22
+ };
23
+ },
24
+ read: __assignType(function (reader) {
25
+ let value;
26
+ let res = 0;
27
+ let i = 0;
28
+ do {
29
+ value = reader.arr[reader.pos++];
30
+ res += (value & 0x7f) << i;
31
+ i += 7;
32
+ } while (value & 0x80);
33
+ return res;
34
+ }, ['reader', '', 'P"2!"/"']),
35
+ };
36
+ //# sourceMappingURL=var-uint-handle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"var-uint-handle.js","sourceRoot":"","sources":["../../../../src/remote-call/utile/remote-message/var-uint-handle.ts"],"names":[],"mappings":";;;;AAEA,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAwB;IACjD,KAAK,CAAC,KAAK;QACV,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK;YAAE,CAAC,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC;QACrB,OAAO;YACN,MAAM;YACN,IAAI,wBAAJ,IAAI,CAAC,OAAO;gBACX,IAAI,CAAC,GAAG,KAAK,CAAC;gBACd,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC;oBACjB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;oBACjC,CAAC,KAAK,CAAC,CAAC;gBACT,CAAC;gBACD,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;SACD,CAAC;IACH,CAAC;IACD,IAAI,eAAE,UAAU,MAAM;QACrB,IAAI,KAAa,CAAC;QAClB,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,GAAG,CAAC;YACH,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YACjC,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,CAAC,IAAI,CAAC,CAAC;QACR,CAAC,QAAQ,KAAK,GAAG,IAAI,EAAE;QACvB,OAAO,GAAG,CAAC;IACZ,CAAC,4BAAA;CACD,CAAC"}
package/dist/type.js ADDED
@@ -0,0 +1,16 @@
1
+ const __ΩServerRuntimeContext = ['root', 'static', 'indexHtml', 'ServerRuntimeContext', 'P&4!&4"&4#Mw$y'];
2
+ export { __ΩServerRuntimeContext as __ΩServerRuntimeContext };
3
+ const __ΩParsedPackage = [() => __ΩServerRuntimeContext, () => __ΩServerInstance, 'instances', 'ParsedPackage', 'Pn!n"4#Mw$y'];
4
+ export { __ΩParsedPackage as __ΩParsedPackage };
5
+ const __ΩServerInstanceConfig = [() => __ΩParsedPackage, 'package', 'url', '', 'prefix', 'if', 'important', 'ServerInstanceConfig', 'PP&n!J4"P&P!2#&/$J4%8P!2#)/$4&8\'4\'8Mw(y'];
6
+ export { __ΩServerInstanceConfig as __ΩServerInstanceConfig };
7
+ const __ΩServerConfig = [() => __ΩServerInstanceConfig, 'instances', 'port', 'ServerConfig', 'Pn!F4"\'4#Mw$y'];
8
+ export { __ΩServerConfig as __ΩServerConfig };
9
+ const __ΩRequestContext = ['prefix', 'RequestContext', 'P&4!8Mw"y'];
10
+ export { __ΩRequestContext as __ΩRequestContext };
11
+ const __ΩServerInstance = ['method', 'url', 'header', 'body', () => __ΩRequestContext, 'context', 'code', 'res', '', 'onRequest', 'ServerInstance', 'PP&2!P&!J2""2#!2$n%2&PP\'4\'"4#P!!,J4(M-J`/)4*Mw+y'];
12
+ export { __ΩServerInstance as __ΩServerInstance };
13
+ const __ΩPackageInfoV1 = ["1", 'sf-formate', 'name', 'version', 'buildAt', 'dir', 'main', 'server', 'browser', 'PackageInfoV1', 'P.!4"&4#&4$\'4%P&4&&4\'M4(P&4&M4)Mw*y'];
14
+ const __ΩPackageInfo = [() => __ΩPackageInfoV1, 'PackageInfo', 'n!w"y'];
15
+ export { __ΩPackageInfo as __ΩPackageInfo };
16
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ const __ΩParameters = ['T', 'args', '', 'Parameters', 'l>e"!R!RPde#!Ph"!@2""/#qk#\'QRb!Pde"!p)w$y'];
2
+ import { loadPackage } from "../package-loader/index.js";
3
+ /*@ts-ignore*/
4
+ import { __ΩResolvedServerInstance } from "./resolved.js";
5
+ const __ΩInlineServer = [() => __ΩResolvedServerInstance, 'InlineServer', 'n!w"y'];
6
+ export { __ΩInlineServer as __ΩInlineServer };
7
+ const __ΩServerInstanceConfig = [() => __ΩInlineServer, () => __ΩParameters, () => loadPackage, 0, 'ServerInstanceConfig', 'Pn!i#o"".$fJw%y'];
8
+ export { __ΩServerInstanceConfig as __ΩServerInstanceConfig };
9
+ const __ΩServerConfig = [() => __ΩServerInstanceConfig, 'instances', 'port', 'ServerConfig', 'Pn!F4"\'4#Mw$y'];
10
+ export { __ΩServerConfig as __ΩServerConfig };
11
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;;0CAClB,eAAe"}
@@ -0,0 +1,5 @@
1
+ export * from "./config.js";
2
+ export * from "./instance.js";
3
+ export * from "./package-info.js";
4
+ export * from "./resolved.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ /*@ts-ignore*/
2
+ import { __ΩRequestContext, __ΩResponseData, __ΩRequestProp } from "./resolved.js";
3
+ const __ΩServerInstanceOld = ['method', 'url', 'header', 'body', () => __ΩRequestContext, 'context', () => __ΩResponseData, '', 'onRequest', 'ServerInstanceOld', 'PP&2!P&!J2""2#!2$n%2&Pn\'-J`/(4)Mw*y'];
4
+ export { __ΩServerInstanceOld as __ΩServerInstanceOld };
5
+ const __ΩServerInstance = [() => __ΩRequestProp, 'requestProp', () => __ΩResponseData, '', 'onRequest', 'ServerInstance', 'PPn!2"n#`/$4%Mw&y'];
6
+ export { __ΩServerInstance as __ΩServerInstance };
7
+ //# sourceMappingURL=instance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance.js","sourceRoot":"","sources":["../../src/types/instance.ts"],"names":[],"mappings":";mEAC0D,eAAe"}
@@ -0,0 +1,4 @@
1
+ const __ΩPackageInfoV1 = ["1", 'sf-formate', 'name', 'version', 'buildAt', 'dir', 'main', 'server', 'browser', 'PackageInfoV1', 'P.!4"&4#&4$\'4%P&4&&4\'M4(P&4&M4)Mw*y'];
2
+ const __ΩPackageInfo = [() => __ΩPackageInfoV1, 'PackageInfo', 'n!w"y'];
3
+ export { __ΩPackageInfo as __ΩPackageInfo };
4
+ //# sourceMappingURL=package-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-info.js","sourceRoot":"","sources":["../../src/types/package-info.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ const __ΩServerRuntimeContext = ['root', 'static', 'indexHtml', () => __ΩRequestProp, 'prop', () => __ΩResponseData, '', 'innerCall', 'ServerRuntimeContext', 'P&4!&4"&4#Pn$2%n&`/\'4(Mw)y'];
2
+ export { __ΩServerRuntimeContext as __ΩServerRuntimeContext };
3
+ const __ΩRequestContext = ['prefix', 'RequestContext', 'P&4!8Mw"y'];
4
+ export { __ΩRequestContext as __ΩRequestContext };
5
+ const __ΩMethod = ["GET", "POST", "PUT", "DELETE", "WS", "OPTION", 'Method', 'P.!.".#.$.%.&Jw\'y'];
6
+ export { __ΩMethod as __ΩMethod };
7
+ const __ΩRequestProp = ['ip', 'port', () => __ΩMethod, 'method', 'url', 'header', 'body', () => __ΩRequestContext, 'context', 'signal', 'appName', 'RequestProp', 'P&4!\'4"n#4$!4%"4&!4\'n(4)!4*&4+8Mw,y'];
8
+ export { __ΩRequestProp as __ΩRequestProp };
9
+ const __ΩResponseData = ['code', 'header', 'data', 'ResponseData', 'P\'4!"4"P!,J4#Mw$y'];
10
+ export { __ΩResponseData as __ΩResponseData };
11
+ const __ΩResolvedServerInstance = ['host', 'prefix', 'ip', 'matchRequest', 'important', 'staticFilePath', 'name', () => __ΩRequestProp, 'prop', () => __ΩResponseData, '', 'onRequest', 'destroy', 'ResolvedServerInstance', 'PPA4!8A4"8A4#8M4$9\'4%89&4&89&4\'9Pn(2)n*`/+4,P$1-8Mw.y'];
12
+ export { __ΩResolvedServerInstance as __ΩResolvedServerInstance };
13
+ //# sourceMappingURL=resolved.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolved.js","sourceRoot":"","sources":["../../src/types/resolved.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
- "name": "@thestarweb/star-framework-web-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@thestarweb/star-framework-web-runtime",
3
+ "version": "1.1.0",
4
+ "description": "Star Framework Web App",
5
+ "main": "dist/index.js",
6
+ "types": "src/index.ts",
7
+ "type": "module",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "scripts": {
12
+ "build": "tspc -p tsconfig.build.json",
13
+ "dev": "tspc -p tsconfig.build.json --watch",
14
+ "test": "vitest"
15
+ },
16
+ "dependencies": {
17
+ "@deepkit/type": "^1.0.19",
18
+ "quico": "^0.8.0",
19
+ "tslib": "^2.8.1"
20
+ },
21
+ "devDependencies": {
22
+ "@deepkit/type-compiler": "^1.0.0",
23
+ "@types/node": "^26.0.1",
24
+ "ts-patch": "^4.0.1",
25
+ "typescript": "^6.0.3",
26
+ "vitest": "^4.1.9"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "src",
31
+ "CHANGELOG.md",
32
+ "README.md"
33
+ ],
34
+ "license": "ISC",
35
+ "gitHead": "73b2a3760846f5064748c7abf316813725dfa3e5"
36
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./types/index.js";
2
+ export * from "./node.js";
3
+ export {handleRef} from './parse-instances-config.js'
package/src/mime.ts ADDED
@@ -0,0 +1,5 @@
1
+ export const MIMEMap: Record<string, string> = {
2
+ js: "text/javascript",
3
+ mjs: "text/javascript",
4
+ css: "text/css",
5
+ };
package/src/node.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { createServer } from "http";
2
+ import { ServerConfig } from "./types/index.js";
3
+ import { Readable } from "stream";
4
+ import { parseInstancesConfig } from "./parse-instances-config.js";
5
+
6
+ export async function createHttpServer(config: ServerConfig) {
7
+ const server = createServer();
8
+ let handle = await parseInstancesConfig(config.instances);
9
+ server.on("request", async (req, res) => {
10
+ const controller = new AbortController();
11
+ const { signal } = controller;
12
+ res.on("close", () => {
13
+ controller.abort();
14
+ });
15
+ const url = new URL(
16
+ req.url || "/",
17
+ `http://${req.headers.host || "127.0.0.1"}/`,
18
+ );
19
+ const ret = await handle({
20
+ method: (req.method?.toUpperCase() as any) || "GET",
21
+ url,
22
+ header: req.headers,
23
+ body: Readable.toWeb(req) as any,
24
+ context: { prefix: "/" },
25
+ signal,
26
+ ip: req.socket.remoteAddress || "127.0.0.1",
27
+ port: req.socket.remotePort || 0,
28
+ });
29
+ if (signal.aborted) return;
30
+ if (ret.code) {
31
+ res.statusCode = ret.code;
32
+ }
33
+ Object.entries(ret.header).forEach(([key, data]) => {
34
+ res.setHeader(key, data as any);
35
+ });
36
+ if (ret.data) {
37
+ if (ret.data instanceof Readable) {
38
+ ret.data.pipe(res);
39
+ } else {
40
+ Readable.fromWeb(ret.data as any).pipe(res);
41
+ }
42
+ } else {
43
+ res.end();
44
+ }
45
+ });
46
+ server.listen(config.port);
47
+ console.log(`server start at: http://127.0.0.1:${config.port}`);
48
+ return {};
49
+ }
@@ -0,0 +1,142 @@
1
+ import { Readable } from "node:stream";
2
+ import {
3
+ PackageInfo,
4
+ RequestProp,
5
+ ResolvedServerInstance,
6
+ ResponseData,
7
+ ServerRuntimeContext,
8
+ } from "../types/index.js";
9
+ import { isAbsolute, join } from "node:path";
10
+ import { readFile } from "node:fs/promises";
11
+ import { reflectOrUndefined, typeOf, validate } from "@deepkit/type";
12
+ import { FSWatcher, watch } from "node:fs";
13
+ import { handleRef } from "../parse-instances-config.js";
14
+
15
+ export interface CommonPackageConfig {
16
+ package: string;
17
+ host?: string | RegExp | (string | RegExp)[];
18
+ prefix?: string | RegExp | (string | RegExp)[];
19
+ ip?: string | RegExp | (string | RegExp)[];
20
+ important?: number | undefined;
21
+ name?: string;
22
+ }
23
+
24
+ function strToReg(str: string, matchEnd: boolean) {
25
+ return new RegExp(
26
+ `^${str.replace(/([\.\[\]\(\)\^\$\+\*\{\}\|\\])/g, "\\$1")}${matchEnd ? "$" : ""}`,
27
+ );
28
+ }
29
+ function mergeToReg(
30
+ config: string | RegExp | (string | RegExp)[],
31
+ matchEnd = true,
32
+ ) {
33
+ if (Array.isArray(config)) {
34
+ return new RegExp(
35
+ config
36
+ .map(
37
+ (i) => `(${i instanceof RegExp ? i.source : strToReg(i, matchEnd)})`,
38
+ )
39
+ .join("|"),
40
+ );
41
+ }
42
+ if (config instanceof RegExp) return config;
43
+ return strToReg(config, matchEnd);
44
+ }
45
+
46
+ export abstract class BasePackageLoader implements ResolvedServerInstance {
47
+ private _running = true;
48
+ private _packagePath!: string;
49
+ private _packageInfo!: PackageInfo;
50
+ private _mainPath!: string;
51
+ public get name() {
52
+ return this._config.name || this._packageInfo.name;
53
+ }
54
+ get mainPath() {
55
+ return this._mainPath;
56
+ }
57
+ serverRuntimeContext!: ServerRuntimeContext;
58
+ staticFilePath?: string | undefined;
59
+ async loadPackageInfo() {
60
+ this._packagePath = isAbsolute(this._config.package)
61
+ ? this._config.package
62
+ : join(process.cwd(), this._config.package);
63
+ const info = JSON.parse(
64
+ await readFile(join(this._packagePath, "package-info.json"), "utf8"),
65
+ ) as PackageInfo;
66
+ if (!this._running) return;
67
+ const error = validate(info, typeOf<PackageInfo>());
68
+ if (error?.length) {
69
+ throw new Error(error.map((i) => i.message).join("、"));
70
+ }
71
+ this._packageInfo = info;
72
+ this._mainPath = join(this._packagePath, info.server.dir, info.server.main);
73
+ const browserDir = join(this._packagePath, info.browser.dir);
74
+ this.serverRuntimeContext = {
75
+ root: this._packagePath,
76
+ static: browserDir,
77
+ indexHtml: await readFile(join(browserDir, "index.html"), "utf-8"),
78
+ innerCall: this.innerCall,
79
+ };
80
+ if (!this._running) return;
81
+ this.staticFilePath = browserDir;
82
+ this.matchRequest.host = this.config.host
83
+ ? mergeToReg(this.config.host)
84
+ : undefined;
85
+ this.matchRequest.prefix = this.config.prefix
86
+ ? mergeToReg(this.config.prefix, false)
87
+ : undefined;
88
+ this.matchRequest.ip = this.config.ip
89
+ ? mergeToReg(this.config.ip)
90
+ : undefined;
91
+ }
92
+ get important() {
93
+ return this._config.important;
94
+ }
95
+ abstract load(isHoot: boolean): void | Promise<void>;
96
+ private watchHandle!: FSWatcher;
97
+ currentVersion = Date.now();
98
+ reloadTimeout?: NodeJS.Timeout;
99
+ lazyCheck() {
100
+ if (this.currentVersion + 5000 > Date.now()) {
101
+ if (!this.reloadTimeout) {
102
+ this.reloadTimeout = setTimeout(() => {
103
+ this.reloadTimeout = undefined;
104
+ this.lazyCheck();
105
+ }, 5200);
106
+ }
107
+ } else {
108
+ this.loadPackageInfo().then(() => {
109
+ if (this._running) {
110
+ this.load(true);
111
+ }
112
+ });
113
+ }
114
+ }
115
+ startLoading: Promise<void>;
116
+ public get config() {
117
+ return this._config;
118
+ }
119
+ innerCall:(prop: RequestProp)=>Promise<ResponseData>
120
+ constructor(protected _config: CommonPackageConfig) {
121
+ this.innerCall = handleRef.value;
122
+ this.startLoading = this.loadPackageInfo().then(() => {
123
+ if (!this._running) return;
124
+ this.watchHandle = watch(
125
+ this._packagePath,
126
+ { recursive: true },
127
+ (type, file) => {
128
+ if (file?.endsWith(".js")) {
129
+ this.currentVersion = Date.now();
130
+ this.lazyCheck();
131
+ }
132
+ },
133
+ );
134
+ return this.load(false);
135
+ });
136
+ }
137
+ matchRequest: ResolvedServerInstance["matchRequest"] = {};
138
+ destroy?(): void {
139
+ throw new Error("Method not implemented.");
140
+ }
141
+ abstract onRequest(prop: RequestProp): Promise<ResponseData>;
142
+ }
@@ -0,0 +1,15 @@
1
+ import { ServerInstance } from "../../types/instance.js";
2
+ import { RequestProp, ResponseData } from "../../types/resolved.js";
3
+ import { BasePackageLoader } from "../base-package-loader.js";
4
+
5
+ export class PackageDefaultLoader extends BasePackageLoader {
6
+ instance!: ServerInstance
7
+ async load(isHoot: boolean) {
8
+ const module = await import(this.mainPath);
9
+ this.instance = await module.default(this.serverRuntimeContext);
10
+ }
11
+ async onRequest(prop: RequestProp): Promise<ResponseData> {
12
+ return await this.instance.onRequest(prop)
13
+ }
14
+ //
15
+ }
@@ -0,0 +1,23 @@
1
+ import { PackageDefaultLoader } from "./default-loader/index.js";
2
+ import { PackageWorkerThreadLoader } from "./worker-thread/index.js";
3
+
4
+ const map = {
5
+ Default: PackageDefaultLoader,
6
+ WorkerThread: PackageWorkerThreadLoader,
7
+ };
8
+ export async function loadPackage<T extends keyof typeof map>(
9
+ config:
10
+ | ({
11
+ /**
12
+ * 指定应用加载方式
13
+ * - `Default` 默认标准加载方式,直接讲程序import到运行库中,简单高效,但是不支持热更新、崩溃重启,无隔离
14
+ * - `WorkerThread` 使用WorkerThreads加载,存在可控的性能损耗,但能支持热更新、独立环境变量等参数,同时支持多实例、示例崩溃自动重启等
15
+ */
16
+ loader: T;
17
+ } & ConstructorParameters<(typeof map)[T]>[0])
18
+ | ConstructorParameters<typeof PackageWorkerThreadLoader>[0],
19
+ ) {
20
+ const t = new (map as any)[(config as any).loader || "Default"](config);
21
+ await t.startLoading;
22
+ return t;
23
+ }
@@ -0,0 +1,81 @@
1
+ import { RequestProp } from "../../types/index.js";
2
+ import {
3
+ BasePackageLoader,
4
+ CommonPackageConfig,
5
+ } from "../base-package-loader.js";
6
+ import { WorkerMainThreadCtrl } from "./main-thread-ctrl.js";
7
+
8
+ export class PackageWorkerThreadLoader extends BasePackageLoader {
9
+ public get config() {
10
+ return this._config;
11
+ }
12
+ activeIns: WorkerMainThreadCtrl[] = [];
13
+ loadingIns: Set<WorkerMainThreadCtrl> = new Set();
14
+ get loading() {
15
+ if (this.loadingIns.size > 0) {
16
+ return Promise.all([...this.loadingIns].map((i) => i.loading));
17
+ }
18
+ }
19
+ onInsOnline(ins: WorkerMainThreadCtrl) {
20
+ this.activeIns = [...new Set(this.activeIns).add(ins)];
21
+ this.loadingIns.delete(ins);
22
+ if (
23
+ this.activeIns.length + this.loadingIns.size <
24
+ this._config.expectationCount!
25
+ ) {
26
+ this.load(true);
27
+ } else {
28
+ if (this.activeIns.length > this._config.expectationCount!) {
29
+ this.activeIns.shift()!.kill();
30
+ }
31
+ if (this.activeIns[0].version < this.currentVersion) {
32
+ // 更新下一个实例
33
+ this.load(true);
34
+ }
35
+ }
36
+ }
37
+ onInsError(ins: WorkerMainThreadCtrl) {
38
+ this.activeIns = this.activeIns.filter((i) => i !== ins);
39
+ this.loadingIns.add(ins);
40
+ }
41
+ async load(isReload: boolean) {
42
+ if (isReload) {
43
+ this.loadingIns.add(new WorkerMainThreadCtrl(this));
44
+ } else {
45
+ for (var i = 0; i < this._config.expectationCount!; i++) {
46
+ this.loadingIns.add(new WorkerMainThreadCtrl(this));
47
+ }
48
+ }
49
+ await this.loading;
50
+ }
51
+ async loadPackageInfo() {
52
+ await super.loadPackageInfo();
53
+ if (!this._config.expectationCount) {
54
+ this._config.expectationCount = 1;
55
+ }
56
+ }
57
+ constructor(
58
+ protected _config: CommonPackageConfig & {
59
+ expectationCount?: number;
60
+ env?: Record<string, string>;
61
+ cwd?: string;
62
+ arg?: string[];
63
+ },
64
+ ) {
65
+ super(_config);
66
+ }
67
+ async onRequest(prop: RequestProp) {
68
+ if (this.activeIns.length === 0) {
69
+ return { code: 500, header: {}, data: null };
70
+ }
71
+ // TODO 如果有多个存活实例,应该做负载均衡,同时可能需要考虑动态扩容
72
+ return this.activeIns[0].onRequest(prop);
73
+ }
74
+ kill() {
75
+ this._config.expectationCount = 0;
76
+ this.activeIns.forEach((i) => i.kill());
77
+ this.activeIns = [];
78
+ this.loadingIns.forEach((i) => i.kill());
79
+ this.loadingIns.clear();
80
+ }
81
+ }