@lvce-editor/file-system-worker 1.3.0 → 1.5.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/fileSystemWorkerMain.js +79 -45
- package/package.json +1 -1
|
@@ -485,7 +485,7 @@ const waitForWebSocketToBeOpen = webSocket => {
|
|
|
485
485
|
error: Error$3
|
|
486
486
|
});
|
|
487
487
|
};
|
|
488
|
-
const create$
|
|
488
|
+
const create$7 = async ({
|
|
489
489
|
webSocket
|
|
490
490
|
}) => {
|
|
491
491
|
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
@@ -522,7 +522,7 @@ const wrap = webSocket => {
|
|
|
522
522
|
};
|
|
523
523
|
const IpcParentWithWebSocket$1 = {
|
|
524
524
|
__proto__: null,
|
|
525
|
-
create: create$
|
|
525
|
+
create: create$7,
|
|
526
526
|
wrap
|
|
527
527
|
};
|
|
528
528
|
|
|
@@ -535,7 +535,7 @@ const create$4$1 = (method, params) => {
|
|
|
535
535
|
};
|
|
536
536
|
};
|
|
537
537
|
const callbacks = Object.create(null);
|
|
538
|
-
const set$
|
|
538
|
+
const set$2 = (id, fn) => {
|
|
539
539
|
callbacks[id] = fn;
|
|
540
540
|
};
|
|
541
541
|
const get$1 = id => {
|
|
@@ -545,16 +545,16 @@ const remove$1 = id => {
|
|
|
545
545
|
delete callbacks[id];
|
|
546
546
|
};
|
|
547
547
|
let id = 0;
|
|
548
|
-
const create$3
|
|
548
|
+
const create$3 = () => {
|
|
549
549
|
return ++id;
|
|
550
550
|
};
|
|
551
551
|
const registerPromise = () => {
|
|
552
|
-
const id = create$3
|
|
552
|
+
const id = create$3();
|
|
553
553
|
const {
|
|
554
554
|
resolve,
|
|
555
555
|
promise
|
|
556
556
|
} = Promise.withResolvers();
|
|
557
|
-
set$
|
|
557
|
+
set$2(id, resolve);
|
|
558
558
|
return {
|
|
559
559
|
id,
|
|
560
560
|
promise
|
|
@@ -627,6 +627,16 @@ const constructError = (message, type, name) => {
|
|
|
627
627
|
}
|
|
628
628
|
return new ErrorConstructor(message);
|
|
629
629
|
};
|
|
630
|
+
const joinLines = lines => {
|
|
631
|
+
return lines.join(NewLine);
|
|
632
|
+
};
|
|
633
|
+
const splitLines = lines => {
|
|
634
|
+
return lines.split(NewLine);
|
|
635
|
+
};
|
|
636
|
+
const getCurrentStack = () => {
|
|
637
|
+
const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
|
|
638
|
+
return currentStack;
|
|
639
|
+
};
|
|
630
640
|
const getNewLineIndex = (string, startIndex = undefined) => {
|
|
631
641
|
return string.indexOf(NewLine, startIndex);
|
|
632
642
|
};
|
|
@@ -637,19 +647,16 @@ const getParentStack = error => {
|
|
|
637
647
|
}
|
|
638
648
|
return parentStack;
|
|
639
649
|
};
|
|
640
|
-
const joinLines = lines => {
|
|
641
|
-
return lines.join(NewLine);
|
|
642
|
-
};
|
|
643
650
|
const MethodNotFound = -32601;
|
|
644
651
|
const Custom = -32001;
|
|
645
|
-
const splitLines = lines => {
|
|
646
|
-
return lines.split(NewLine);
|
|
647
|
-
};
|
|
648
652
|
const restoreJsonRpcError = error => {
|
|
653
|
+
const currentStack = getCurrentStack();
|
|
649
654
|
if (error && error instanceof Error) {
|
|
655
|
+
if (typeof error.stack === 'string') {
|
|
656
|
+
error.stack = error.stack + NewLine + currentStack;
|
|
657
|
+
}
|
|
650
658
|
return error;
|
|
651
659
|
}
|
|
652
|
-
const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
|
|
653
660
|
if (error && error.code && error.code === MethodNotFound) {
|
|
654
661
|
const restoredError = new JsonRpcError(error.message);
|
|
655
662
|
const parentStack = getParentStack(error);
|
|
@@ -730,6 +737,17 @@ const getErrorType = prettyError => {
|
|
|
730
737
|
}
|
|
731
738
|
return undefined;
|
|
732
739
|
};
|
|
740
|
+
const isAlreadyStack = line => {
|
|
741
|
+
return line.trim().startsWith('at ');
|
|
742
|
+
};
|
|
743
|
+
const getStack = prettyError => {
|
|
744
|
+
const stackString = prettyError.stack || '';
|
|
745
|
+
const newLineIndex = stackString.indexOf('\n');
|
|
746
|
+
if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
|
|
747
|
+
return stackString.slice(newLineIndex + 1);
|
|
748
|
+
}
|
|
749
|
+
return stackString;
|
|
750
|
+
};
|
|
733
751
|
const getErrorProperty = (error, prettyError) => {
|
|
734
752
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
735
753
|
return {
|
|
@@ -742,7 +760,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
742
760
|
code: Custom,
|
|
743
761
|
message: prettyError.message,
|
|
744
762
|
data: {
|
|
745
|
-
stack: prettyError
|
|
763
|
+
stack: getStack(prettyError),
|
|
746
764
|
codeFrame: prettyError.codeFrame,
|
|
747
765
|
type: getErrorType(prettyError),
|
|
748
766
|
code: prettyError.code,
|
|
@@ -750,20 +768,20 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
750
768
|
}
|
|
751
769
|
};
|
|
752
770
|
};
|
|
753
|
-
const create$1$1 = (
|
|
771
|
+
const create$1$1 = (id, error) => {
|
|
754
772
|
return {
|
|
755
773
|
jsonrpc: Two,
|
|
756
|
-
id
|
|
774
|
+
id,
|
|
757
775
|
error
|
|
758
776
|
};
|
|
759
777
|
};
|
|
760
|
-
const getErrorResponse = (
|
|
778
|
+
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
761
779
|
const prettyError = preparePrettyError(error);
|
|
762
780
|
logError(error, prettyError);
|
|
763
781
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
764
|
-
return create$1$1(
|
|
782
|
+
return create$1$1(id, errorProperty);
|
|
765
783
|
};
|
|
766
|
-
const create$
|
|
784
|
+
const create$6 = (message, result) => {
|
|
767
785
|
return {
|
|
768
786
|
jsonrpc: Two,
|
|
769
787
|
id: message.id,
|
|
@@ -772,14 +790,29 @@ const create$5 = (message, result) => {
|
|
|
772
790
|
};
|
|
773
791
|
const getSuccessResponse = (message, result) => {
|
|
774
792
|
const resultProperty = result ?? null;
|
|
775
|
-
return create$
|
|
793
|
+
return create$6(message, resultProperty);
|
|
794
|
+
};
|
|
795
|
+
const getErrorResponseSimple = (id, error) => {
|
|
796
|
+
return {
|
|
797
|
+
jsonrpc: Two,
|
|
798
|
+
id,
|
|
799
|
+
error: {
|
|
800
|
+
code: Custom,
|
|
801
|
+
// @ts-ignore
|
|
802
|
+
message: error.message,
|
|
803
|
+
data: error
|
|
804
|
+
}
|
|
805
|
+
};
|
|
776
806
|
};
|
|
777
807
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
778
808
|
try {
|
|
779
809
|
const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
|
|
780
810
|
return getSuccessResponse(message, result);
|
|
781
811
|
} catch (error) {
|
|
782
|
-
|
|
812
|
+
if (ipc.canUseSimpleErrorResponse) {
|
|
813
|
+
return getErrorResponseSimple(message.id, error);
|
|
814
|
+
}
|
|
815
|
+
return getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
783
816
|
}
|
|
784
817
|
};
|
|
785
818
|
const defaultPreparePrettyError = error => {
|
|
@@ -834,7 +867,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
834
867
|
try {
|
|
835
868
|
ipc.send(response);
|
|
836
869
|
} catch (error) {
|
|
837
|
-
const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
|
|
870
|
+
const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
|
|
838
871
|
ipc.send(errorResponse);
|
|
839
872
|
}
|
|
840
873
|
return;
|
|
@@ -939,7 +972,7 @@ const listen$1 = async (module, options) => {
|
|
|
939
972
|
const ipc = module.wrap(rawIpc);
|
|
940
973
|
return ipc;
|
|
941
974
|
};
|
|
942
|
-
const create$
|
|
975
|
+
const create$5 = async ({
|
|
943
976
|
commandMap,
|
|
944
977
|
messagePort
|
|
945
978
|
}) => {
|
|
@@ -955,20 +988,20 @@ const create$3 = async ({
|
|
|
955
988
|
messagePort.start();
|
|
956
989
|
return rpc;
|
|
957
990
|
};
|
|
958
|
-
const create$
|
|
991
|
+
const create$4 = async ({
|
|
959
992
|
commandMap,
|
|
960
993
|
messagePort
|
|
961
994
|
}) => {
|
|
962
|
-
return create$
|
|
995
|
+
return create$5({
|
|
963
996
|
commandMap,
|
|
964
997
|
messagePort
|
|
965
998
|
});
|
|
966
999
|
};
|
|
967
1000
|
const PlainMessagePortRpcParent = {
|
|
968
1001
|
__proto__: null,
|
|
969
|
-
create: create$
|
|
1002
|
+
create: create$4
|
|
970
1003
|
};
|
|
971
|
-
const create$
|
|
1004
|
+
const create$2 = async ({
|
|
972
1005
|
commandMap,
|
|
973
1006
|
webSocket
|
|
974
1007
|
}) => {
|
|
@@ -984,9 +1017,9 @@ const create$1 = async ({
|
|
|
984
1017
|
};
|
|
985
1018
|
const WebSocketRpcParent = {
|
|
986
1019
|
__proto__: null,
|
|
987
|
-
create: create$
|
|
1020
|
+
create: create$2
|
|
988
1021
|
};
|
|
989
|
-
const create$
|
|
1022
|
+
const create$1 = async ({
|
|
990
1023
|
commandMap
|
|
991
1024
|
}) => {
|
|
992
1025
|
// TODO create a commandMap per rpc instance
|
|
@@ -998,11 +1031,11 @@ const create$4 = async ({
|
|
|
998
1031
|
};
|
|
999
1032
|
const WebWorkerRpcClient = {
|
|
1000
1033
|
__proto__: null,
|
|
1001
|
-
create: create$
|
|
1034
|
+
create: create$1
|
|
1002
1035
|
};
|
|
1003
1036
|
|
|
1004
1037
|
const rpcs = Object.create(null);
|
|
1005
|
-
const set$
|
|
1038
|
+
const set$g = (id, rpc) => {
|
|
1006
1039
|
rpcs[id] = rpc;
|
|
1007
1040
|
};
|
|
1008
1041
|
const get = id => {
|
|
@@ -1026,7 +1059,11 @@ const create = rpcId => {
|
|
|
1026
1059
|
return rpc.invokeAndTransfer(method, ...params);
|
|
1027
1060
|
},
|
|
1028
1061
|
set(rpc) {
|
|
1029
|
-
set$
|
|
1062
|
+
set$g(rpcId, rpc);
|
|
1063
|
+
},
|
|
1064
|
+
async dispose() {
|
|
1065
|
+
const rpc = get(rpcId);
|
|
1066
|
+
await rpc.dispose();
|
|
1030
1067
|
}
|
|
1031
1068
|
};
|
|
1032
1069
|
};
|
|
@@ -1037,23 +1074,20 @@ const RpcId = {
|
|
|
1037
1074
|
__proto__: null,
|
|
1038
1075
|
FileSystemWorker: FileSystemWorker$1};
|
|
1039
1076
|
const {
|
|
1040
|
-
|
|
1041
|
-
set: set$
|
|
1042
|
-
|
|
1043
|
-
const RendererWorker = {
|
|
1077
|
+
invoke: invoke$8,
|
|
1078
|
+
set: set$8} = create(FileSystemProcess$1);
|
|
1079
|
+
const FileSystemProcess = {
|
|
1044
1080
|
__proto__: null,
|
|
1045
|
-
|
|
1046
|
-
set: set$
|
|
1081
|
+
invoke: invoke$8,
|
|
1082
|
+
set: set$8
|
|
1047
1083
|
};
|
|
1048
1084
|
const {
|
|
1049
|
-
|
|
1050
|
-
set: set$
|
|
1051
|
-
|
|
1052
|
-
const FileSystemProcess = {
|
|
1085
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1086
|
+
set: set$3} = create(RendererWorker$1);
|
|
1087
|
+
const RendererWorker = {
|
|
1053
1088
|
__proto__: null,
|
|
1054
|
-
|
|
1055
|
-
set: set$
|
|
1056
|
-
};
|
|
1089
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1090
|
+
set: set$3};
|
|
1057
1091
|
|
|
1058
1092
|
const {
|
|
1059
1093
|
invoke,
|