univo 0.4.2 → 0.4.4

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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.Ckj3I8tQ.mjs';
1
+ export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.Cwz0D-bk.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.7S1OTdpc.js';
1
+ export { A as Action, B as Block, E as Event, F as Filter, H as Head, e as Indexer, f as PrivateMetadata, P as PublicMetadata, g as Result, c as defineAction, a as defineEvent, d as defineIndexer } from './shared/univo.BL1Gu6sU.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/index.mjs CHANGED
@@ -1,11 +1,22 @@
1
1
  import { hexToNumber, numberToHex, hexToBytes, keccak256, toRlp, hexToBigInt, numberToBytes, isHex, concatBytes, concatHex, formatTransaction, serializeTransaction } from 'viem';
2
2
  import { local } from './transport.mjs';
3
- import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, i as isHexEqual, a as compress, b as iife, e as decoder } from './shared/univo.CUNaTwXY.mjs';
3
+ import { c as createLogger, r as retry, v as version, n as normalizeHex, d as decompress, b as isHexEqual, a as compress, i as iife, e as decoder } from './shared/univo.DAgQmcSe.mjs';
4
4
  import { AdapterError } from './metadata/adapters.mjs';
5
- import { c as createException, a as catchException } from './shared/univo.C0flyVee.mjs';
6
5
  import 'ws';
7
6
  import 'partysocket';
8
7
 
8
+ function createException(message) {
9
+ return `univo:${message}`;
10
+ }
11
+ function catchException(unknown, exception) {
12
+ if (unknown instanceof Error) {
13
+ if (unknown.message === exception) {
14
+ return true;
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+
9
20
  function matchFilter(block, filter) {
10
21
  if (hexToNumber(block.eth_chainId) !== filter.chain) {
11
22
  return false;
@@ -1073,30 +1084,37 @@ function defineIndexer(opts) {
1073
1084
  const IncompleteBlockError = createException("Received block with missing required property");
1074
1085
  const private_writeEvents = async (params) => {
1075
1086
  if (allEvents.length === 0) {
1076
- return { failures: [] };
1087
+ return { results: [] };
1077
1088
  }
1078
1089
  const relevantEvents = allEvents.filter((event) => params.events.includes(event.id));
1079
1090
  if (relevantEvents.length === 0) {
1080
- return { failures: [] };
1091
+ return { results: [] };
1081
1092
  }
1082
1093
  if (params.events.length === 0) {
1083
- return { failures: [] };
1094
+ return { results: [] };
1084
1095
  }
1085
- const failures = {};
1096
+ const results = {};
1086
1097
  let accessedUndefinedKey = false;
1087
1098
  const proxiedBlocks = getWriteEventsProxy(params.blocks, () => {
1088
1099
  accessedUndefinedKey = true;
1089
1100
  throw new Error(IncompleteBlockError);
1090
1101
  });
1091
- const promises = eventsGroupedByStorageMap.entries().map(async ([storage, grouped_events]) => {
1102
+ const promises = eventsGroupedByStorageMap.entries().map(async ([storage, groupedEvents]) => {
1103
+ const requestedEvents = groupedEvents.filter((event) => params.events.includes(event.id));
1092
1104
  const batch = [];
1093
- for (const event of grouped_events) {
1094
- if (!params.events.includes(event.id)) {
1095
- continue;
1096
- }
1105
+ for (const event of requestedEvents) {
1097
1106
  for (const block of proxiedBlocks) {
1098
1107
  try {
1099
1108
  if (!event.filters.some((filter) => matchFilter(block, filter))) {
1109
+ results[event.id + block.eth_getBlockByNumber.number] ??= {
1110
+ status: "ignored",
1111
+ event_id: event.id,
1112
+ chain: block.eth_chainId,
1113
+ hash: block.eth_getBlockByNumber.hash,
1114
+ number: block.eth_getBlockByNumber.number,
1115
+ parent_hash: block.eth_getBlockByNumber.parentHash,
1116
+ created_at: Date.now()
1117
+ };
1100
1118
  continue;
1101
1119
  }
1102
1120
  const events = event.handler(block);
@@ -1113,7 +1131,7 @@ function defineIndexer(opts) {
1113
1131
  log.error(error.message);
1114
1132
  }
1115
1133
  }
1116
- failures[event.id + block.eth_getBlockByNumber.number] ??= {
1134
+ results[event.id + block.eth_getBlockByNumber.number] ??= {
1117
1135
  status,
1118
1136
  event_id: event.id,
1119
1137
  chain: block.eth_chainId,
@@ -1125,47 +1143,51 @@ function defineIndexer(opts) {
1125
1143
  }
1126
1144
  }
1127
1145
  }
1128
- if (batch.length === 0) {
1129
- return;
1130
- }
1131
- const start = Date.now();
1132
- try {
1133
- await retry(() => storage.upsert(batch), 2);
1134
- if (accessedUndefinedKey) {
1135
- throw new Error(IncompleteBlockError);
1136
- }
1137
- } catch (error) {
1138
- const status = catchException(error, IncompleteBlockError) ? "incomplete_error" : "upsert_error";
1139
- if (status === "upsert_error") {
1140
- if (error instanceof Error) {
1141
- log.error(error.message);
1146
+ if (batch.length > 0) {
1147
+ try {
1148
+ await retry(() => storage.upsert(batch), 2);
1149
+ if (accessedUndefinedKey) {
1150
+ throw new Error(IncompleteBlockError);
1142
1151
  }
1143
- }
1144
- for (const event of relevantEvents) {
1145
- for (const block of proxiedBlocks) {
1146
- if (!event.filters.some((filter) => matchFilter(block, filter))) {
1147
- continue;
1152
+ } catch (error) {
1153
+ const status = catchException(error, IncompleteBlockError) ? "incomplete_error" : "upsert_error";
1154
+ if (status === "upsert_error") {
1155
+ if (error instanceof Error) {
1156
+ log.error(error.message);
1157
+ }
1158
+ }
1159
+ for (const event of requestedEvents) {
1160
+ for (const block of proxiedBlocks) {
1161
+ results[event.id + block.eth_getBlockByNumber.number] ??= {
1162
+ status,
1163
+ event_id: event.id,
1164
+ chain: block.eth_chainId,
1165
+ hash: block.eth_getBlockByNumber.hash,
1166
+ number: block.eth_getBlockByNumber.number,
1167
+ parent_hash: block.eth_getBlockByNumber.parentHash,
1168
+ created_at: Date.now()
1169
+ };
1148
1170
  }
1149
- failures[event.id + block.eth_getBlockByNumber.number] ??= {
1150
- status,
1151
- event_id: event.id,
1152
- chain: block.eth_chainId,
1153
- hash: block.eth_getBlockByNumber.hash,
1154
- number: block.eth_getBlockByNumber.number,
1155
- parent_hash: block.eth_getBlockByNumber.parentHash,
1156
- created_at: Date.now()
1157
- };
1158
1171
  }
1159
1172
  }
1160
1173
  }
1161
- const stop = Date.now() - start;
1162
- for (const event of relevantEvents) {
1163
- log.debug(`Recorded ${batch.length} ${event.id} in ${stop}ms`);
1174
+ for (const event of requestedEvents) {
1175
+ for (const block of proxiedBlocks) {
1176
+ results[event.id + block.eth_getBlockByNumber.number] ??= {
1177
+ status: "ok",
1178
+ event_id: event.id,
1179
+ chain: block.eth_chainId,
1180
+ hash: block.eth_getBlockByNumber.hash,
1181
+ number: block.eth_getBlockByNumber.number,
1182
+ parent_hash: block.eth_getBlockByNumber.parentHash,
1183
+ created_at: Date.now()
1184
+ };
1185
+ }
1164
1186
  }
1165
1187
  });
1166
1188
  await Promise.all(promises);
1167
- const failuresArray = Object.values(failures);
1168
- return { failures: failuresArray };
1189
+ const resultsArray = Object.values(results);
1190
+ return { results: resultsArray };
1169
1191
  };
1170
1192
  const private_writeEventsAndGetKeys = async (params) => {
1171
1193
  if (allEvents.length === 0) {
package/dist/proxy.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.Ckj3I8tQ.mjs';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.Cwz0D-bk.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/proxy.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as Transport, I as IndexerRpc } from './shared/univo.7S1OTdpc.js';
1
+ import { T as Transport, I as IndexerRpc } from './shared/univo.BL1Gu6sU.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/proxy.mjs CHANGED
@@ -1,12 +1,39 @@
1
- import { g as getException } from './shared/univo.C0flyVee.mjs';
2
- import { c as createLogger, d as decompress, e as decoder } from './shared/univo.CUNaTwXY.mjs';
1
+ import { c as createLogger } from './shared/univo.DAgQmcSe.mjs';
3
2
 
4
3
  function http(opts) {
5
4
  const log = createLogger({ quiet: opts.quiet, prefix: "[proxy]" });
6
5
  return async function proxy(req) {
7
- let body_buffer;
6
+ const authorization = req.headers.get("Authorization");
7
+ const compressed = req.headers.get("Content-Encoding") === "gzip";
8
+ const authenticated = authorization === `Bearer ${opts.signingKey}`;
9
+ if (compressed && (!authorization || !authenticated)) {
10
+ return Response.json(
11
+ { jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid bearer token" } },
12
+ //
13
+ { status: 400 }
14
+ );
15
+ }
16
+ let body_string = "";
8
17
  try {
9
- body_buffer = await req.arrayBuffer();
18
+ if (compressed) {
19
+ if (!req.body) {
20
+ throw new Error("Missing compressed request body");
21
+ }
22
+ const reader = req.body.pipeThrough(new DecompressionStream("gzip")).pipeThrough(new TextDecoderStream()).getReader();
23
+ try {
24
+ while (true) {
25
+ const { done, value } = await reader.read();
26
+ if (done) {
27
+ break;
28
+ }
29
+ body_string += value;
30
+ }
31
+ } finally {
32
+ reader.releaseLock();
33
+ }
34
+ } else {
35
+ body_string = await req.text();
36
+ }
10
37
  } catch {
11
38
  return Response.json(
12
39
  { jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid request body" } },
@@ -14,28 +41,6 @@ function http(opts) {
14
41
  { status: 400 }
15
42
  );
16
43
  }
17
- const authorization = req.headers.get("Authorization");
18
- const authenticated = authorization === `Bearer ${opts.signingKey}`;
19
- let body_string;
20
- if (req.headers.get("Content-Encoding") === "gzip") {
21
- if (!authorization) {
22
- return Response.json(
23
- { jsonrpc: "2.0", id: null, error: { code: 0, message: "No bearer token provided" } },
24
- //
25
- { status: 400 }
26
- );
27
- }
28
- if (!authenticated) {
29
- return Response.json(
30
- { jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid bearer token" } },
31
- //
32
- { status: 400 }
33
- );
34
- }
35
- body_string = await decompress(body_buffer);
36
- } else {
37
- body_string = decoder.decode(body_buffer);
38
- }
39
44
  let json;
40
45
  try {
41
46
  json = JSON.parse(body_string);
@@ -46,40 +51,21 @@ function http(opts) {
46
51
  { status: 400 }
47
52
  );
48
53
  }
49
- if (json.method.startsWith("private_")) {
50
- if (!authorization) {
51
- return Response.json(
52
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "No bearer token provided" } },
53
- //
54
- { status: 400 }
55
- );
56
- }
57
- if (authorization !== `Bearer ${opts.signingKey}`) {
58
- return Response.json(
59
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Invalid bearer token" } },
60
- //
61
- { status: 400 }
62
- );
63
- }
54
+ if (json.method.startsWith("private_") && (!authorization || !authenticated)) {
55
+ return Response.json(
56
+ { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Invalid bearer token" } },
57
+ //
58
+ { status: 400 }
59
+ );
64
60
  }
65
61
  try {
66
62
  const result = await opts.indexer.request({ method: json.method, params: json.params });
67
63
  return Response.json({ jsonrpc: "2.0", id: json.id, result });
68
64
  } catch (error) {
69
- const message = getException(error);
70
- if (message) {
71
- log.error(message);
72
- return Response.json(
73
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message } },
74
- //
75
- { status: 400 }
76
- );
77
- }
78
- if (error instanceof Error) {
79
- log.error(error.message);
80
- }
65
+ const message = error instanceof Error ? error.message : "Internal error";
66
+ log.error(message);
81
67
  return Response.json(
82
- { jsonrpc: "2.0", id: json.id, error: { code: 0, message: "Internal server error" } },
68
+ { jsonrpc: "2.0", id: json.id, error: { code: 0, message } },
83
69
  //
84
70
  { status: 500 }
85
71
  );
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.Ckj3I8tQ.mjs';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.Cwz0D-bk.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
@@ -1,4 +1,4 @@
1
- import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.7S1OTdpc.js';
1
+ import { T as Transport, R as Rpc, I as IndexerRpc } from './shared/univo.BL1Gu6sU.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
package/dist/realtime.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { hexToNumber } from 'viem';
2
- import { c as createLogger, b as iife, m as mutex, l as lifecycle, q as queue, r as retry, i as isHexEqual } from './shared/univo.CUNaTwXY.mjs';
2
+ import { c as createLogger, i as iife, m as mutex, l as lifecycle, q as queue, r as retry, b as isHexEqual } from './shared/univo.DAgQmcSe.mjs';
3
3
 
4
4
  function defineBlockchain(opts) {
5
5
  const log = createLogger({ quiet: opts.quiet });
@@ -182,6 +182,7 @@ function realtime(realtime2) {
182
182
  }
183
183
  }
184
184
  const mutex_finalize = mutex(finalize);
185
+ void mutex_finalize();
185
186
  let chainFinalizedHeight = hexToNumber(chainFinalizedBlock.number);
186
187
  async function poll() {
187
188
  try {
package/dist/rpc.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as IndexerRpc, R as Rpc } from './shared/univo.Ckj3I8tQ.mjs';
1
+ export { I as IndexerRpc, R as Rpc } from './shared/univo.Cwz0D-bk.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
package/dist/rpc.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { I as IndexerRpc, R as Rpc } from './shared/univo.7S1OTdpc.js';
1
+ export { I as IndexerRpc, R as Rpc } from './shared/univo.BL1Gu6sU.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
@@ -51,13 +51,13 @@ type IndexerRpc = {
51
51
  private_getMetadata: () => Promise<PrivateMetadata>;
52
52
  /**
53
53
  * Accepts a list of events and a batch of minified block data and writes to storage
54
- * @returns A list of failures that occured for each event and block pair
54
+ * @returns A list of results indicating the status of each processed block
55
55
  */
56
56
  private_writeEvents: (params: {
57
57
  events: string[];
58
58
  blocks: Block[];
59
59
  }) => Promise<{
60
- failures: Result[];
60
+ results: Result[];
61
61
  }>;
62
62
  /**
63
63
  * Accepts a block head and writes events to storage
@@ -51,13 +51,13 @@ type IndexerRpc = {
51
51
  private_getMetadata: () => Promise<PrivateMetadata>;
52
52
  /**
53
53
  * Accepts a list of events and a batch of minified block data and writes to storage
54
- * @returns A list of failures that occured for each event and block pair
54
+ * @returns A list of results indicating the status of each processed block
55
55
  */
56
56
  private_writeEvents: (params: {
57
57
  events: string[];
58
58
  blocks: Block[];
59
59
  }) => Promise<{
60
- failures: Result[];
60
+ results: Result[];
61
61
  }>;
62
62
  /**
63
63
  * Accepts a block head and writes events to storage
@@ -1,5 +1,5 @@
1
1
  const name = "univo";
2
- const version = "0.4.2";
2
+ const version = "0.4.4";
3
3
 
4
4
  function createLogger(opts) {
5
5
  const noop = (..._) => {
@@ -159,4 +159,4 @@ const normalizeHex = (hex, length) => {
159
159
  return `0x${hex.slice(2).toLowerCase().padStart(length, "0")}`;
160
160
  };
161
161
 
162
- export { compress as a, iife as b, createLogger as c, decompress as d, decoder as e, name as f, isHexEqual as i, lifecycle as l, mutex as m, normalizeHex as n, queue as q, retry as r, version as v };
162
+ export { compress as a, isHexEqual as b, createLogger as c, decompress as d, decoder as e, iife as i, lifecycle as l, mutex as m, normalizeHex as n, queue as q, retry as r, version as v };
@@ -1,4 +1,4 @@
1
- export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.Ckj3I8tQ.mjs';
1
+ export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.Cwz0D-bk.mjs';
2
2
  import 'viem';
3
3
  import './metadata.mjs';
4
4
  import './metadata/adapters.mjs';
@@ -1,4 +1,4 @@
1
- export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.7S1OTdpc.js';
1
+ export { T as Transport, b as browser, h as http, l as local, w as wss } from './shared/univo.BL1Gu6sU.js';
2
2
  import 'viem';
3
3
  import './metadata.js';
4
4
  import './metadata/adapters.js';
@@ -1,6 +1,6 @@
1
1
  import ws from 'ws';
2
2
  import { WebSocket } from 'partysocket';
3
- import { a as compress, c as createLogger, m as mutex } from './shared/univo.CUNaTwXY.mjs';
3
+ import { c as createLogger, m as mutex, a as compress } from './shared/univo.DAgQmcSe.mjs';
4
4
 
5
5
  const DEFAULT_TIMEOUT_MS = 60 * 1e3;
6
6
  function local(rpc) {
package/package.json CHANGED
@@ -2,13 +2,10 @@
2
2
  "name": "univo",
3
3
  "license": "MIT",
4
4
  "type": "module",
5
- "version": "0.4.2",
5
+ "version": "0.4.4",
6
6
  "sideEffects": false,
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
- "bin": {
10
- "univo": "dist/cli.mjs"
11
- },
12
9
  "exports": {
13
10
  ".": {
14
11
  "types": "./dist/index.d.ts",
@@ -60,15 +57,11 @@
60
57
  ],
61
58
  "scripts": {
62
59
  "test": "vitest",
63
- "build": "unbuild",
64
- "univo": "NODE_ENV=production LOG_LEVEL=DEBUG jiti ./src/cli"
60
+ "build": "unbuild"
65
61
  },
66
62
  "dependencies": {
67
63
  "aws4fetch": "1.0.20",
68
- "citty": "^0.1.6",
69
- "dotenv": "^17.2.2",
70
64
  "fast-xml-parser": "5.11.1",
71
- "open": "^10.2.0",
72
65
  "partysocket": "^1.1.3",
73
66
  "ws": "^8.18.1"
74
67
  },
@@ -77,7 +70,7 @@
77
70
  "@types/node": "^20.11.27",
78
71
  "@types/ws": "^8.18.1",
79
72
  "changelogen": "^0.6.1",
80
- "jiti": "^2.4.2",
73
+ "dotenv": "^17.2.2",
81
74
  "msw": "^2.10.2",
82
75
  "typescript": "^5.8.2",
83
76
  "unbuild": "^3.5.0",
package/dist/cli.d.mts DELETED
@@ -1 +0,0 @@
1
-
package/dist/cli.d.ts DELETED
@@ -1 +0,0 @@
1
-
package/dist/cli.mjs DELETED
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env node
2
- import ws from 'ws';
3
- import open from 'open';
4
- import { config } from 'dotenv';
5
- import { WebSocket } from 'partysocket';
6
- import { defineCommand, runMain } from 'citty';
7
- import { http } from './transport.mjs';
8
- import { c as createLogger, v as version, f as name } from './shared/univo.CUNaTwXY.mjs';
9
-
10
- const log = createLogger({ quiet: false });
11
- const dev = defineCommand({
12
- args: {
13
- url: {
14
- required: true,
15
- type: "positional",
16
- description: "Endpoint url like http://localhost:3000"
17
- }
18
- },
19
- async run(ctx) {
20
- try {
21
- if (!ctx.args.url.startsWith("http://")) {
22
- throw new Error("`url` must start with http://");
23
- }
24
- config({ quiet: true });
25
- const localSigningKey = process.env.UNIVO_SIGNING_KEY;
26
- if (localSigningKey === void 0) {
27
- throw new Error("Please provide a UNIVO_SIGNING_KEY environment variable");
28
- }
29
- const client = http(ctx.args.url, { signingKey: localSigningKey });
30
- await client.request({ method: "private_getMetadata", params: [] }).catch(() => {
31
- throw new Error(`Failed to connect to ${ctx.args.url}. Check that your server is running on the correct port.`);
32
- });
33
- const remoteSigningKey = crypto.randomUUID();
34
- const url = `https://tunnel-univo.app/v1/${crypto.randomUUID()}`;
35
- const endpoint = {
36
- url,
37
- signing_key: remoteSigningKey
38
- };
39
- const encoder = new TextEncoder();
40
- const data = encoder.encode(JSON.stringify(endpoint));
41
- const encoded = data.toBase64({ alphabet: "base64url", omitPadding: true });
42
- await open(`https://univo.app/dev/${encoded}`);
43
- const ws$1 = new WebSocket(url, [], { WebSocket: ws });
44
- ws$1.binaryType = "arraybuffer";
45
- ws$1.onerror = (event) => {
46
- log.error(event.message);
47
- };
48
- ws$1.onopen = () => {
49
- log.info(`Dev server started for ${ctx.args.url}`);
50
- };
51
- ws$1.onclose = () => {
52
- log.info(`Dev server closed for ${ctx.args.url}`);
53
- };
54
- ws$1.onmessage = async (event) => {
55
- try {
56
- const json = JSON.parse(event.data);
57
- log.debug(`Received request (${json.id}) for method '${json.method}'`);
58
- const result = await client.request({ method: json.method, params: json.params });
59
- ws$1.send(JSON.stringify({ jsonrpc: "2.0", id: json.id, result }));
60
- } catch {
61
- ws$1.send(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: 0, message: "Invalid request" } }));
62
- }
63
- };
64
- } catch (error) {
65
- if (error instanceof Error) {
66
- return log.error(error.message);
67
- }
68
- throw error;
69
- }
70
- }
71
- });
72
- const main = defineCommand({
73
- subCommands: { dev },
74
- meta: { name, version }
75
- });
76
- runMain(main).catch((error) => {
77
- if (error instanceof Error) log.error(error.message);
78
- process.exit(1);
79
- });
@@ -1,21 +0,0 @@
1
- function createException(message) {
2
- return `univo:${message}`;
3
- }
4
- function catchException(unknown, exception) {
5
- if (unknown instanceof Error) {
6
- if (unknown.message === exception) {
7
- return true;
8
- }
9
- }
10
- return false;
11
- }
12
- function getException(unknown) {
13
- if (unknown instanceof Error) {
14
- if (unknown.message.startsWith("univo")) {
15
- const [_, message] = unknown.message.split(":");
16
- if (message) return message;
17
- }
18
- }
19
- }
20
-
21
- export { catchException as a, createException as c, getException as g };