@lvce-editor/search-process 8.1.0 → 9.0.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 (2) hide show
  1. package/dist/index.js +118 -118
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -8,59 +8,6 @@ import { Writable } from 'node:stream';
8
8
  import { pipeline } from 'node:stream/promises';
9
9
  import { Buffer as Buffer$1 } from 'node:buffer';
10
10
 
11
- class AssertionError extends Error {
12
- constructor(message) {
13
- super(message);
14
- this.name = 'AssertionError';
15
- }
16
- }
17
- const getType = value => {
18
- switch (typeof value) {
19
- case 'number':
20
- return 'number';
21
- case 'function':
22
- return 'function';
23
- case 'string':
24
- return 'string';
25
- case 'object':
26
- if (value === null) {
27
- return 'null';
28
- }
29
- if (Array.isArray(value)) {
30
- return 'array';
31
- }
32
- return 'object';
33
- case 'boolean':
34
- return 'boolean';
35
- default:
36
- return 'unknown';
37
- }
38
- };
39
- const object = value => {
40
- const type = getType(value);
41
- if (type !== 'object') {
42
- throw new AssertionError('expected value to be of type object');
43
- }
44
- };
45
- const number = value => {
46
- const type = getType(value);
47
- if (type !== 'number') {
48
- throw new AssertionError('expected value to be of type number');
49
- }
50
- };
51
- const array = value => {
52
- const type = getType(value);
53
- if (type !== 'array') {
54
- throw new AssertionError('expected value to be of type array');
55
- }
56
- };
57
- const string = value => {
58
- const type = getType(value);
59
- if (type !== 'string') {
60
- throw new AssertionError('expected value to be of type string');
61
- }
62
- };
63
-
64
11
  const normalizeLine = line => {
65
12
  if (line.startsWith('Error: ')) {
66
13
  return line.slice('Error: '.length);
@@ -117,6 +64,59 @@ class VError extends Error {
117
64
  }
118
65
  }
119
66
 
67
+ class AssertionError extends Error {
68
+ constructor(message) {
69
+ super(message);
70
+ this.name = 'AssertionError';
71
+ }
72
+ }
73
+ const getType = value => {
74
+ switch (typeof value) {
75
+ case 'number':
76
+ return 'number';
77
+ case 'function':
78
+ return 'function';
79
+ case 'string':
80
+ return 'string';
81
+ case 'object':
82
+ if (value === null) {
83
+ return 'null';
84
+ }
85
+ if (Array.isArray(value)) {
86
+ return 'array';
87
+ }
88
+ return 'object';
89
+ case 'boolean':
90
+ return 'boolean';
91
+ default:
92
+ return 'unknown';
93
+ }
94
+ };
95
+ const object = value => {
96
+ const type = getType(value);
97
+ if (type !== 'object') {
98
+ throw new AssertionError('expected value to be of type object');
99
+ }
100
+ };
101
+ const number = value => {
102
+ const type = getType(value);
103
+ if (type !== 'number') {
104
+ throw new AssertionError('expected value to be of type number');
105
+ }
106
+ };
107
+ const array = value => {
108
+ const type = getType(value);
109
+ if (type !== 'array') {
110
+ throw new AssertionError('expected value to be of type array');
111
+ }
112
+ };
113
+ const string = value => {
114
+ const type = getType(value);
115
+ if (type !== 'string') {
116
+ throw new AssertionError('expected value to be of type string');
117
+ }
118
+ };
119
+
120
120
  const isMessagePort = value => {
121
121
  return value && value instanceof MessagePort;
122
122
  };
@@ -1156,7 +1156,7 @@ const handleIpc = ipc => {
1156
1156
  ipc.on('message', handleMessage);
1157
1157
  }
1158
1158
  };
1159
- const listen$2 = async (module, options) => {
1159
+ const listen$1 = async (module, options) => {
1160
1160
  const rawIpc = await module.listen(options);
1161
1161
  if (module.signal) {
1162
1162
  module.signal(rawIpc);
@@ -1164,43 +1164,47 @@ const listen$2 = async (module, options) => {
1164
1164
  const ipc = module.wrap(rawIpc);
1165
1165
  return ipc;
1166
1166
  };
1167
- const create$c = async ({
1167
+ const create$e = async ({
1168
1168
  commandMap,
1169
- messagePort
1169
+ messagePort,
1170
+ requiresSocket
1170
1171
  }) => {
1171
1172
  // TODO create a commandMap per rpc instance
1172
1173
  register(commandMap);
1173
- const ipc = await listen$2(IpcChildWithElectronMessagePort$1, {
1174
+ const ipc = await listen$1(IpcChildWithElectronMessagePort$1, {
1174
1175
  messagePort
1175
1176
  });
1177
+ if (requiresSocket) {
1178
+ ipc.requiresSocket = requiresSocket;
1179
+ }
1176
1180
  handleIpc(ipc);
1177
1181
  const rpc = createRpc(ipc);
1178
1182
  return rpc;
1179
1183
  };
1180
1184
  const ElectronMessagePortRpcClient = {
1181
1185
  __proto__: null,
1182
- create: create$c
1186
+ create: create$e
1183
1187
  };
1184
- const create$b = async ({
1188
+ const create$d = async ({
1185
1189
  commandMap
1186
1190
  }) => {
1187
1191
  // TODO create a commandMap per rpc instance
1188
1192
  register(commandMap);
1189
- const ipc = await listen$2(IpcChildWithElectronUtilityProcess$1);
1193
+ const ipc = await listen$1(IpcChildWithElectronUtilityProcess$1);
1190
1194
  handleIpc(ipc);
1191
1195
  const rpc = createRpc(ipc);
1192
1196
  return rpc;
1193
1197
  };
1194
1198
  const ElectronUtilityProcessRpcClient = {
1195
1199
  __proto__: null,
1196
- create: create$b
1200
+ create: create$d
1197
1201
  };
1198
1202
  const create$7 = async ({
1199
1203
  commandMap
1200
1204
  }) => {
1201
1205
  // TODO create a commandMap per rpc instance
1202
1206
  register(commandMap);
1203
- const ipc = await listen$2(IpcChildWithNodeForkedProcess$1);
1207
+ const ipc = await listen$1(IpcChildWithNodeForkedProcess$1);
1204
1208
  handleIpc(ipc);
1205
1209
  const rpc = createRpc(ipc);
1206
1210
  return rpc;
@@ -1212,14 +1216,18 @@ const NodeForkedProcessRpcClient = {
1212
1216
  const create$5 = async ({
1213
1217
  commandMap,
1214
1218
  request,
1215
- handle
1219
+ handle,
1220
+ requiresSocket
1216
1221
  }) => {
1217
1222
  // TODO create a commandMap per rpc instance
1218
1223
  register(commandMap);
1219
- const ipc = await listen$2(IpcChildWithWebSocket, {
1224
+ const ipc = await listen$1(IpcChildWithWebSocket, {
1220
1225
  request,
1221
1226
  handle
1222
1227
  });
1228
+ if (requiresSocket) {
1229
+ ipc.requiresSocket = requiresSocket;
1230
+ }
1223
1231
  handleIpc(ipc);
1224
1232
  const rpc = createRpc(ipc);
1225
1233
  return rpc;
@@ -1233,7 +1241,7 @@ const create$4 = async ({
1233
1241
  }) => {
1234
1242
  // TODO create a commandMap per rpc instance
1235
1243
  register(commandMap);
1236
- const ipc = await listen$2(IpcChildWithNodeWorker$1);
1244
+ const ipc = await listen$1(IpcChildWithNodeWorker$1);
1237
1245
  handleIpc(ipc);
1238
1246
  const rpc = createRpc(ipc);
1239
1247
  return rpc;
@@ -1243,54 +1251,10 @@ const NodeWorkerRpcClient = {
1243
1251
  create: create$4
1244
1252
  };
1245
1253
 
1246
- const NodeWorker = 1;
1247
- const NodeForkedProcess = 2;
1248
- const ElectronUtilityProcess = 3;
1249
- const ElectronMessagePort = 4;
1250
- const WebSocket = 6;
1251
- const Auto = argv => {
1252
- if (argv.includes('--ipc-type=node-worker')) {
1253
- return NodeWorker;
1254
- }
1255
- if (argv.includes('--ipc-type=node-forked-process')) {
1256
- return NodeForkedProcess;
1257
- }
1258
- if (argv.includes('--ipc-type=electron-utility-process')) {
1259
- return ElectronUtilityProcess;
1260
- }
1261
- throw new Error(`[search-process] unknown ipc type`);
1262
- };
1263
-
1264
- const getModule = method => {
1265
- switch (method) {
1266
- case NodeForkedProcess:
1267
- return NodeForkedProcessRpcClient.create;
1268
- case NodeWorker:
1269
- return NodeWorkerRpcClient.create;
1270
- case ElectronUtilityProcess:
1271
- return ElectronUtilityProcessRpcClient.create;
1272
- case ElectronMessagePort:
1273
- return ElectronMessagePortRpcClient.create;
1274
- case WebSocket:
1275
- return NodeWebSocketRpcClient.create;
1276
- default:
1277
- throw new Error('unexpected ipc type');
1278
- }
1279
- };
1280
-
1281
- const listen$1 = async ({
1282
- method,
1283
- ...params
1284
- }) => {
1285
- const create = getModule(method);
1286
- const rpc = await create(params);
1287
- return rpc;
1288
- };
1289
-
1290
- const handleElectronMessagePort = async (messagePort, ...params) => {
1254
+ const handleElectronMessagePort = async messagePort => {
1291
1255
  object(messagePort);
1292
- await listen$1({
1293
- method: ElectronMessagePort,
1256
+ await ElectronMessagePortRpcClient.create({
1257
+ commandMap: {},
1294
1258
  messagePort
1295
1259
  });
1296
1260
  };
@@ -1298,10 +1262,10 @@ const handleElectronMessagePort = async (messagePort, ...params) => {
1298
1262
  const handleWebSocket = async (handle, request) => {
1299
1263
  object(handle);
1300
1264
  object(request);
1301
- await listen$1({
1302
- method: WebSocket,
1303
- request,
1304
- handle
1265
+ await NodeWebSocketRpcClient.create({
1266
+ commandMap: {},
1267
+ handle,
1268
+ request
1305
1269
  });
1306
1270
  };
1307
1271
 
@@ -1693,9 +1657,45 @@ const commandMap = {
1693
1657
  'TextSearch.search': search
1694
1658
  };
1695
1659
 
1660
+ const NodeWorker = 1;
1661
+ const NodeForkedProcess = 2;
1662
+ const ElectronUtilityProcess = 3;
1663
+ const ElectronMessagePort = 4;
1664
+ const WebSocket = 6;
1665
+ const Auto = argv => {
1666
+ if (argv.includes('--ipc-type=node-worker')) {
1667
+ return NodeWorker;
1668
+ }
1669
+ if (argv.includes('--ipc-type=node-forked-process')) {
1670
+ return NodeForkedProcess;
1671
+ }
1672
+ if (argv.includes('--ipc-type=electron-utility-process')) {
1673
+ return ElectronUtilityProcess;
1674
+ }
1675
+ throw new Error(`[search-process] unknown ipc type`);
1676
+ };
1677
+
1678
+ const getModule = method => {
1679
+ switch (method) {
1680
+ case NodeForkedProcess:
1681
+ return NodeForkedProcessRpcClient.create;
1682
+ case NodeWorker:
1683
+ return NodeWorkerRpcClient.create;
1684
+ case ElectronUtilityProcess:
1685
+ return ElectronUtilityProcessRpcClient.create;
1686
+ case ElectronMessagePort:
1687
+ return ElectronMessagePortRpcClient.create;
1688
+ case WebSocket:
1689
+ return NodeWebSocketRpcClient.create;
1690
+ default:
1691
+ throw new Error('unexpected ipc type');
1692
+ }
1693
+ };
1694
+
1696
1695
  const listen = async argv => {
1697
- await listen$1({
1698
- method: Auto(argv),
1696
+ const method = Auto(argv);
1697
+ const create = getModule(method);
1698
+ await create({
1699
1699
  commandMap: commandMap
1700
1700
  });
1701
1701
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/search-process",
3
- "version": "8.1.0",
3
+ "version": "9.0.0",
4
4
  "description": "Search Process",
5
5
  "keywords": [
6
6
  "Lvce Editor",
@@ -18,7 +18,7 @@
18
18
  "search-process": "bin/searchProcess.js"
19
19
  },
20
20
  "dependencies": {
21
- "execa": "^9.5.2",
21
+ "execa": "^9.5.3",
22
22
  "ws": "^8.18.2"
23
23
  },
24
24
  "optionalDependencies": {