@ocap/gql 1.30.24 → 1.30.25
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/README.md +15 -0
- package/esm/http.d.mts +66 -0
- package/esm/http.mjs +635 -0
- package/esm/index.d.mts +8 -37
- package/esm/index.mjs +7 -429
- package/esm/ws.d.mts +3 -1
- package/esm/ws.mjs +2 -2
- package/lib/http.cjs +642 -0
- package/lib/http.d.cts +66 -0
- package/lib/index.cjs +11 -434
- package/lib/index.d.cts +8 -37
- package/lib/ws.cjs +2 -2
- package/lib/ws.d.cts +4 -2
- package/package.json +8 -3
package/lib/index.cjs
CHANGED
|
@@ -1,445 +1,22 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_http = require('./http.cjs');
|
|
2
3
|
const require_ws = require('./ws.cjs');
|
|
3
4
|
let node_http = require("node:http");
|
|
4
|
-
let _ocap_schema = require("@ocap/schema");
|
|
5
|
-
_ocap_schema = require_rolldown_runtime.__toESM(_ocap_schema);
|
|
6
|
-
let graphql = require("graphql");
|
|
7
|
-
let lodash_get = require("lodash/get");
|
|
8
|
-
lodash_get = require_rolldown_runtime.__toESM(lodash_get);
|
|
9
5
|
|
|
10
6
|
//#region src/index.ts
|
|
11
|
-
const
|
|
12
|
-
const result = await callback();
|
|
13
|
-
const resultsMap = {};
|
|
14
|
-
if (Array.isArray(keys)) keys.forEach((key) => {
|
|
15
|
-
resultsMap[key] = result[key];
|
|
16
|
-
});
|
|
17
|
-
else resultsMap[keys] = result;
|
|
18
|
-
return {
|
|
19
|
-
code: "OK",
|
|
20
|
-
page: result ? result.paging || {} : null,
|
|
21
|
-
...resultsMap
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
const formatContext = (ctx = {}) => {
|
|
25
|
-
return {
|
|
26
|
-
featureSwitch: {},
|
|
27
|
-
gasStakeHeaders: {
|
|
28
|
-
token: (0, lodash_get.default)(ctx, "headers[x-gas-payer-sig]", ""),
|
|
29
|
-
pk: (0, lodash_get.default)(ctx, "headers[x-gas-payer-pk]", "")
|
|
30
|
-
},
|
|
31
|
-
request: {
|
|
32
|
-
userAgent: (0, lodash_get.default)(ctx, "headers.user-agent"),
|
|
33
|
-
ip: (0, lodash_get.default)(ctx, "headers.x-real-ip") || ctx.ip || ctx._remoteAddress || ctx.connection?.remoteAddress || "-",
|
|
34
|
-
id: (0, lodash_get.default)(ctx, "headers[x-request-id]") || (0, lodash_get.default)(ctx, "headers[X-Request-ID]") || "-"
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
const resolvers = [
|
|
39
|
-
{
|
|
40
|
-
fn: "sendTx",
|
|
41
|
-
dataKey: "hash"
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
fn: "subscribe",
|
|
45
|
-
dataKey: "value"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
fn: "unsubscribe",
|
|
49
|
-
dataKey: "result"
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
fn: "getAccountState",
|
|
53
|
-
dataKey: "state"
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
fn: "getAssetState",
|
|
57
|
-
dataKey: "state"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
fn: "getFactoryState",
|
|
61
|
-
dataKey: "state"
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
fn: "getDelegateState",
|
|
65
|
-
dataKey: "state"
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
fn: "getTokenState",
|
|
69
|
-
dataKey: "state"
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
fn: "getForgeState",
|
|
73
|
-
dataKey: "state"
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
fn: "getStakeState",
|
|
77
|
-
dataKey: "state"
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
fn: "getEvidenceState",
|
|
81
|
-
dataKey: "state"
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
fn: "getRollupState",
|
|
85
|
-
dataKey: "state"
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
fn: "getRollupBlock",
|
|
89
|
-
dataKey: "block"
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
fn: "getTokenFactoryState",
|
|
93
|
-
dataKey: "state"
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
fn: "getAccountTokens",
|
|
97
|
-
dataKey: "tokens"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
fn: "getBlock",
|
|
101
|
-
dataKey: "block"
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
fn: "getBlocks",
|
|
105
|
-
dataKey: "blocks"
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
fn: "getChainInfo",
|
|
109
|
-
dataKey: "info"
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
fn: "getConfig",
|
|
113
|
-
dataKey: "config"
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
fn: "getForgeStats",
|
|
117
|
-
dataKey: "forgeStats"
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
fn: "getNetInfo",
|
|
121
|
-
dataKey: "netInfo"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
fn: "getNodeInfo",
|
|
125
|
-
dataKey: "info"
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
fn: "getTx",
|
|
129
|
-
dataKey: "info"
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
fn: "getUnconfirmedTxs",
|
|
133
|
-
dataKey: "unconfirmedTxs"
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
fn: "getValidatorsInfo",
|
|
137
|
-
dataKey: "validatorsInfo"
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
fn: "getTokenDistribution",
|
|
141
|
-
dataKey: "data"
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
fn: "listTransactions",
|
|
145
|
-
dataKey: ["transactions"]
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
fn: "listAssets",
|
|
149
|
-
dataKey: ["assets", "account"]
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
fn: "listAssetTransactions",
|
|
153
|
-
dataKey: ["transactions"]
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
fn: "listFactories",
|
|
157
|
-
dataKey: ["factories"]
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
fn: "listTokens",
|
|
161
|
-
dataKey: ["tokens"]
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
fn: "listTokenFactories",
|
|
165
|
-
dataKey: ["tokenFactories"]
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
fn: "listTopAccounts",
|
|
169
|
-
dataKey: ["accounts"]
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
fn: "listBlocks",
|
|
173
|
-
dataKey: ["blocks"]
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
fn: "listStakes",
|
|
177
|
-
dataKey: ["stakes"]
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
fn: "listRollups",
|
|
181
|
-
dataKey: ["rollups"]
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
fn: "listRollupBlocks",
|
|
185
|
-
dataKey: ["blocks"]
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
fn: "listRollupValidators",
|
|
189
|
-
dataKey: ["validators"]
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
fn: "listDelegations",
|
|
193
|
-
dataKey: ["delegations"]
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
fn: "listTokenFlows",
|
|
197
|
-
dataKey: "data"
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
fn: "verifyAccountRisk",
|
|
201
|
-
dataKey: "data"
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
fn: "search",
|
|
205
|
-
dataKey: ["results"]
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
fn: "estimateGas",
|
|
209
|
-
dataKey: ["estimate"]
|
|
210
|
-
}
|
|
211
|
-
];
|
|
212
|
-
const createResolvers = (resolver) => resolvers.reduce((acc, { fn, dataKey }) => {
|
|
213
|
-
acc[fn] = (args, ctx) => wrapResolver(fn, dataKey, () => {
|
|
214
|
-
const method = resolver[fn];
|
|
215
|
-
if (typeof method === "function") return method.call(resolver, args, formatContext(ctx));
|
|
216
|
-
return null;
|
|
217
|
-
});
|
|
218
|
-
return acc;
|
|
219
|
-
}, {});
|
|
220
|
-
const defaultErrorHandler = (err) => {
|
|
221
|
-
if (process.env.NODE_ENV !== "test") console.error("GraphQLError", err.originalError || err);
|
|
222
|
-
};
|
|
223
|
-
const MAX_BATCH_SIZE = 40;
|
|
224
|
-
const BODY_SIZE_LIMIT = 100 * 1024;
|
|
225
|
-
/**
|
|
226
|
-
* Read the raw request body as a utf-8 string, enforcing the size limit.
|
|
227
|
-
* Mirrors express-graphql's parseBody behavior for the subset of content
|
|
228
|
-
* types we support (JSON and application/graphql).
|
|
229
|
-
*/
|
|
230
|
-
async function readRawBody(req, limit) {
|
|
231
|
-
return new Promise((resolve, reject) => {
|
|
232
|
-
const chunks = [];
|
|
233
|
-
let size = 0;
|
|
234
|
-
req.on("data", (chunk) => {
|
|
235
|
-
size += chunk.length;
|
|
236
|
-
if (size > limit) {
|
|
237
|
-
const err = /* @__PURE__ */ new Error(`Request body too large (limit ${limit} bytes).`);
|
|
238
|
-
err.status = 413;
|
|
239
|
-
reject(err);
|
|
240
|
-
req.destroy();
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
chunks.push(chunk);
|
|
244
|
-
});
|
|
245
|
-
req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
246
|
-
req.on("error", reject);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Extract GraphQL params from the request. URL query string takes precedence
|
|
251
|
-
* over the body so that callers can override fields via `?query=...` on a
|
|
252
|
-
* POST. Supports four body modes (matches upstream express-graphql):
|
|
253
|
-
* 1. Already parsed by upstream middleware (req.body is an object)
|
|
254
|
-
* 2. Content-Type: application/json — JSON.parse the raw body
|
|
255
|
-
* 3. Content-Type: application/graphql — raw body IS the query
|
|
256
|
-
* 4. Content-Type: application/x-www-form-urlencoded — parse as query string
|
|
257
|
-
*/
|
|
258
|
-
async function parseGraphQLParams(req) {
|
|
259
|
-
const urlData = new URLSearchParams((req.url || "").split("?")[1] || "");
|
|
260
|
-
let query = urlData.get("query");
|
|
261
|
-
let variablesRaw = urlData.get("variables");
|
|
262
|
-
let operationName = urlData.get("operationName");
|
|
263
|
-
const raw = urlData.get("raw") != null;
|
|
264
|
-
if (req.method === "POST") {
|
|
265
|
-
const contentType = String(req.headers["content-type"] || "").split(";")[0].trim().toLowerCase();
|
|
266
|
-
const preparsed = req.body;
|
|
267
|
-
let bodyData = {};
|
|
268
|
-
if (preparsed != null && typeof preparsed === "object" && !Buffer.isBuffer(preparsed)) bodyData = preparsed;
|
|
269
|
-
else if (typeof preparsed === "string" && contentType === "application/graphql") bodyData = { query: preparsed };
|
|
270
|
-
else if (preparsed == null && contentType) {
|
|
271
|
-
const rawBody = await readRawBody(req, BODY_SIZE_LIMIT);
|
|
272
|
-
if (contentType === "application/graphql") bodyData = { query: rawBody };
|
|
273
|
-
else if (contentType === "application/json") try {
|
|
274
|
-
bodyData = JSON.parse(rawBody);
|
|
275
|
-
} catch {
|
|
276
|
-
const err = /* @__PURE__ */ new Error("POST body sent invalid JSON.");
|
|
277
|
-
err.status = 400;
|
|
278
|
-
throw err;
|
|
279
|
-
}
|
|
280
|
-
else if (contentType === "application/x-www-form-urlencoded") {
|
|
281
|
-
const form = new URLSearchParams(rawBody);
|
|
282
|
-
const parsed = {};
|
|
283
|
-
for (const [k, v] of form) parsed[k] = v;
|
|
284
|
-
bodyData = parsed;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (query == null && typeof bodyData.query === "string") query = bodyData.query;
|
|
288
|
-
if (variablesRaw == null && bodyData.variables != null) variablesRaw = bodyData.variables;
|
|
289
|
-
if (operationName == null && typeof bodyData.operationName === "string") operationName = bodyData.operationName;
|
|
290
|
-
}
|
|
291
|
-
let variables = null;
|
|
292
|
-
if (typeof variablesRaw === "string") try {
|
|
293
|
-
variables = JSON.parse(variablesRaw);
|
|
294
|
-
} catch {
|
|
295
|
-
const err = /* @__PURE__ */ new Error("Variables are invalid JSON.");
|
|
296
|
-
err.status = 400;
|
|
297
|
-
throw err;
|
|
298
|
-
}
|
|
299
|
-
else if (variablesRaw && typeof variablesRaw === "object") variables = variablesRaw;
|
|
300
|
-
return {
|
|
301
|
-
query,
|
|
302
|
-
variables,
|
|
303
|
-
operationName,
|
|
304
|
-
raw
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Minimal GraphiQL HTML served on GET + Accept: text/html when graphiql=true.
|
|
309
|
-
* Loads GraphiQL 3.x from unpkg; consumers who need offline GraphiQL should
|
|
310
|
-
* configure their own static route.
|
|
311
|
-
*/
|
|
312
|
-
const GRAPHIQL_HTML = `<!doctype html>
|
|
313
|
-
<html lang="en">
|
|
314
|
-
<head>
|
|
315
|
-
<meta charset="utf-8" />
|
|
316
|
-
<title>GraphiQL</title>
|
|
317
|
-
<link href="https://unpkg.com/graphiql@3/graphiql.min.css" rel="stylesheet" />
|
|
318
|
-
</head>
|
|
319
|
-
<body style="margin:0;height:100vh">
|
|
320
|
-
<div id="graphiql" style="height:100%">Loading...</div>
|
|
321
|
-
<script src="https://unpkg.com/react@18/umd/react.production.min.js" crossorigin><\/script>
|
|
322
|
-
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js" crossorigin><\/script>
|
|
323
|
-
<script src="https://unpkg.com/graphiql@3/graphiql.min.js" crossorigin><\/script>
|
|
324
|
-
<script>
|
|
325
|
-
const fetcher = GraphiQL.createFetcher({ url: window.location.pathname });
|
|
326
|
-
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
|
|
327
|
-
root.render(React.createElement(GraphiQL, { fetcher }));
|
|
328
|
-
<\/script>
|
|
329
|
-
</body>
|
|
330
|
-
</html>`;
|
|
331
|
-
function shouldShowGraphiQL(req, params, graphiqlEnabled) {
|
|
332
|
-
if (!graphiqlEnabled || params.raw) return false;
|
|
333
|
-
if (req.method !== "GET") return false;
|
|
334
|
-
return String(req.headers.accept || "").includes("text/html");
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Count the top-level field selections across all operation definitions
|
|
338
|
-
* in the document. Matches the behavior of the previous express-graphql
|
|
339
|
-
* customValidateFn exactly.
|
|
340
|
-
*/
|
|
341
|
-
function countTopLevelSelections(documentAST) {
|
|
342
|
-
return documentAST.definitions.flatMap((def) => (0, lodash_get.default)(def, "selectionSet.selections") || []).map((sel) => (0, lodash_get.default)(sel, "name.value")).filter((name) => typeof name === "string").length;
|
|
343
|
-
}
|
|
344
|
-
const createHttpHandler = ({ resolver = {}, onError = defaultErrorHandler, graphiql = true }) => {
|
|
345
|
-
const schema = (0, graphql.buildSchema)(_ocap_schema.default);
|
|
346
|
-
const rootValue = createResolvers(resolver);
|
|
347
|
-
const formatGraphQLError = (err) => {
|
|
348
|
-
onError(err);
|
|
349
|
-
const isProd = process.env.NODE_ENV === "production";
|
|
350
|
-
return {
|
|
351
|
-
code: (0, lodash_get.default)(err, "originalError.code", "INTERNAL"),
|
|
352
|
-
message: err.message,
|
|
353
|
-
locations: err.locations || [],
|
|
354
|
-
stack: isProd ? [] : (0, lodash_get.default)(err, "originalError.stack", "").split("\n"),
|
|
355
|
-
path: err.path
|
|
356
|
-
};
|
|
357
|
-
};
|
|
358
|
-
const formatAnyError = (input) => {
|
|
359
|
-
const message = typeof input === "string" ? input : input.message;
|
|
360
|
-
return formatGraphQLError(new graphql.GraphQLError(message, { originalError: typeof input === "string" ? new Error(message) : input }));
|
|
361
|
-
};
|
|
362
|
-
const sendJSON = (res, status, body) => {
|
|
363
|
-
res.statusCode = status;
|
|
364
|
-
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
365
|
-
res.end(JSON.stringify(body));
|
|
366
|
-
};
|
|
367
|
-
const sendHTML = (res, html) => {
|
|
368
|
-
res.statusCode = 200;
|
|
369
|
-
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
370
|
-
res.end(html);
|
|
371
|
-
};
|
|
372
|
-
return async (req, res) => {
|
|
373
|
-
if (req.method !== "GET" && req.method !== "POST") {
|
|
374
|
-
res.setHeader("Allow", "GET, POST");
|
|
375
|
-
sendJSON(res, 405, { errors: [formatAnyError("GraphQL only supports GET and POST requests.")] });
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
let params;
|
|
379
|
-
try {
|
|
380
|
-
params = await parseGraphQLParams(req);
|
|
381
|
-
} catch (err) {
|
|
382
|
-
sendJSON(res, err.status ?? 500, { errors: [formatAnyError(err)] });
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
const showGraphiQL = shouldShowGraphiQL(req, params, graphiql);
|
|
386
|
-
if (params.query == null) {
|
|
387
|
-
if (showGraphiQL) {
|
|
388
|
-
sendHTML(res, GRAPHIQL_HTML);
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
sendJSON(res, 400, { errors: [formatAnyError("Must provide query string.")] });
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
let documentAST;
|
|
395
|
-
try {
|
|
396
|
-
documentAST = (0, graphql.parse)(params.query);
|
|
397
|
-
} catch (syntaxError) {
|
|
398
|
-
sendJSON(res, 400, { errors: [formatGraphQLError(syntaxError)] });
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
try {
|
|
402
|
-
if (countTopLevelSelections(documentAST) > MAX_BATCH_SIZE) throw new Error(`Batch query size exceeded allowed maximum batch size of ${MAX_BATCH_SIZE}`);
|
|
403
|
-
} catch (batchError) {
|
|
404
|
-
sendJSON(res, 500, { errors: [formatAnyError(batchError)] });
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
if (req.method === "GET") {
|
|
408
|
-
const operationAST = (0, graphql.getOperationAST)(documentAST, params.operationName || void 0);
|
|
409
|
-
if (operationAST && operationAST.operation !== "query") {
|
|
410
|
-
res.setHeader("Allow", "POST");
|
|
411
|
-
sendJSON(res, 405, { errors: [formatAnyError(`Can only perform a ${operationAST.operation} operation from a POST request.`)] });
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
let result;
|
|
416
|
-
try {
|
|
417
|
-
result = await (0, graphql.execute)({
|
|
418
|
-
schema,
|
|
419
|
-
document: documentAST,
|
|
420
|
-
rootValue,
|
|
421
|
-
contextValue: req,
|
|
422
|
-
variableValues: params.variables,
|
|
423
|
-
operationName: params.operationName
|
|
424
|
-
});
|
|
425
|
-
} catch (contextError) {
|
|
426
|
-
sendJSON(res, 400, { errors: [formatAnyError(contextError)] });
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
const formattedResult = { data: result.data };
|
|
430
|
-
if (result.errors && result.errors.length > 0) formattedResult.errors = result.errors.map(formatGraphQLError);
|
|
431
|
-
sendJSON(res, result.data == null ? 500 : 200, formattedResult);
|
|
432
|
-
};
|
|
433
|
-
};
|
|
434
|
-
const createSocketHandler = ({ app, indexdb }) => {
|
|
7
|
+
const createSocketHandler = ({ app, indexdb, wsOptions }) => {
|
|
435
8
|
const httpServer = (0, node_http.createServer)(app);
|
|
436
|
-
require_ws.default({
|
|
9
|
+
require_ws.default({
|
|
10
|
+
indexdb,
|
|
11
|
+
wsOptions
|
|
12
|
+
}).attach(httpServer);
|
|
437
13
|
return httpServer;
|
|
438
14
|
};
|
|
439
15
|
|
|
440
16
|
//#endregion
|
|
441
|
-
exports.
|
|
442
|
-
exports.
|
|
17
|
+
exports.createFetchHandler = require_http.createFetchHandler;
|
|
18
|
+
exports.createHttpHandler = require_http.createHttpHandler;
|
|
19
|
+
exports.createResolvers = require_http.createResolvers;
|
|
443
20
|
exports.createSocketHandler = createSocketHandler;
|
|
444
|
-
exports.formatContext = formatContext;
|
|
445
|
-
exports.wrapResolver = wrapResolver;
|
|
21
|
+
exports.formatContext = require_http.formatContext;
|
|
22
|
+
exports.wrapResolver = require_http.wrapResolver;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,41 +1,10 @@
|
|
|
1
|
+
import { GqlRequestLike, GqlResponseLike, HttpHandlerOptions, Resolver, createFetchHandler, createHttpHandler, createResolvers, formatContext, wrapResolver } from "./http.cjs";
|
|
2
|
+
import { TIndexedAccountState, TIndexedAssetState, TIndexedDelegationState, TIndexedFactoryState, TIndexedRollupBlock, TIndexedRollupState, TIndexedStakeState, TIndexedTokenState, TIndexedTransaction } from "@ocap/types";
|
|
3
|
+
import { Express } from "express";
|
|
1
4
|
import { Server } from "node:http";
|
|
2
|
-
import { IResolver, IResolverContext, TIndexedAccountState, TIndexedAssetState, TIndexedDelegationState, TIndexedFactoryState, TIndexedRollupBlock, TIndexedRollupState, TIndexedStakeState, TIndexedTokenState, TIndexedTransaction, TPageInfo } from "@ocap/types";
|
|
3
|
-
import { Express, RequestHandler } from "express";
|
|
4
|
-
import { GraphQLError } from "graphql";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
|
-
|
|
8
|
-
paging?: TPageInfo;
|
|
9
|
-
[key: string]: any;
|
|
10
|
-
}
|
|
11
|
-
interface WrapResolverResult {
|
|
12
|
-
code: string;
|
|
13
|
-
page: TPageInfo | Record<string, never> | null;
|
|
14
|
-
[key: string]: any;
|
|
15
|
-
}
|
|
16
|
-
declare const wrapResolver: (_name: string, keys: string | string[], callback: () => Promise<ResolverResult | null> | ResolverResult | null | string) => Promise<WrapResolverResult>;
|
|
17
|
-
interface RequestContext {
|
|
18
|
-
headers?: Record<string, string>;
|
|
19
|
-
ip?: string;
|
|
20
|
-
_remoteAddress?: string;
|
|
21
|
-
connection?: {
|
|
22
|
-
remoteAddress?: string;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
declare const formatContext: (ctx?: RequestContext) => IResolverContext;
|
|
26
|
-
type Resolver = IResolver;
|
|
27
|
-
type ResolverFn = (args: unknown, ctx: unknown) => Promise<WrapResolverResult>;
|
|
28
|
-
declare const createResolvers: (resolver: Resolver) => Record<string, ResolverFn>;
|
|
29
|
-
interface HttpHandlerOptions {
|
|
30
|
-
resolver?: IResolver;
|
|
31
|
-
onError?: (err: GraphQLError) => void;
|
|
32
|
-
graphiql?: boolean;
|
|
33
|
-
}
|
|
34
|
-
declare const createHttpHandler: ({
|
|
35
|
-
resolver,
|
|
36
|
-
onError,
|
|
37
|
-
graphiql
|
|
38
|
-
}: HttpHandlerOptions) => RequestHandler;
|
|
7
|
+
|
|
39
8
|
/**
|
|
40
9
|
* IndexDB table with event subscription for WebSocket broadcasts
|
|
41
10
|
* Generic type T represents the indexed state type for the table
|
|
@@ -62,10 +31,12 @@ interface Indexdb {
|
|
|
62
31
|
interface SocketHandlerOptions {
|
|
63
32
|
app: Express;
|
|
64
33
|
indexdb: Indexdb;
|
|
34
|
+
wsOptions?: Record<string, unknown>;
|
|
65
35
|
}
|
|
66
36
|
declare const createSocketHandler: ({
|
|
67
37
|
app,
|
|
68
|
-
indexdb
|
|
38
|
+
indexdb,
|
|
39
|
+
wsOptions
|
|
69
40
|
}: SocketHandlerOptions) => Server;
|
|
70
41
|
//#endregion
|
|
71
|
-
export {
|
|
42
|
+
export { GqlRequestLike, GqlResponseLike, HttpHandlerOptions, Resolver, createFetchHandler, createHttpHandler, createResolvers, createSocketHandler, formatContext, wrapResolver };
|
package/lib/ws.cjs
CHANGED
|
@@ -3,8 +3,8 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
|
3
3
|
let _arcblock_ws = require("@arcblock/ws");
|
|
4
4
|
|
|
5
5
|
//#region src/ws.ts
|
|
6
|
-
function createWebsocketServer({ indexdb }) {
|
|
7
|
-
const wsServer = new _arcblock_ws.WsServer(
|
|
6
|
+
function createWebsocketServer({ indexdb, wsOptions = {} }) {
|
|
7
|
+
const wsServer = new _arcblock_ws.WsServer(wsOptions);
|
|
8
8
|
const mutableTables = [
|
|
9
9
|
"account",
|
|
10
10
|
"asset",
|
package/lib/ws.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Server } from "node:http";
|
|
2
1
|
import { TIndexedAccountState, TIndexedAssetState, TIndexedDelegationState, TIndexedFactoryState, TIndexedRollupBlock, TIndexedRollupState, TIndexedStakeState, TIndexedTokenState, TIndexedTransaction } from "@ocap/types";
|
|
2
|
+
import { Server } from "node:http";
|
|
3
3
|
|
|
4
4
|
//#region src/ws.d.ts
|
|
5
5
|
|
|
@@ -29,9 +29,11 @@ interface WsServerInstance {
|
|
|
29
29
|
attach: (server: Server) => void;
|
|
30
30
|
}
|
|
31
31
|
declare function createWebsocketServer({
|
|
32
|
-
indexdb
|
|
32
|
+
indexdb,
|
|
33
|
+
wsOptions
|
|
33
34
|
}: {
|
|
34
35
|
indexdb: Indexdb;
|
|
36
|
+
wsOptions?: Record<string, unknown>;
|
|
35
37
|
}): WsServerInstance;
|
|
36
38
|
//#endregion
|
|
37
39
|
export { createWebsocketServer as default };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.30.
|
|
6
|
+
"version": "1.30.25",
|
|
7
7
|
"description": "Resolver middleware for ocap adapters",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
"import": "./esm/index.mjs",
|
|
16
16
|
"default": "./lib/index.cjs"
|
|
17
17
|
},
|
|
18
|
+
"./http": {
|
|
19
|
+
"types": "./esm/http.d.mts",
|
|
20
|
+
"import": "./esm/http.mjs",
|
|
21
|
+
"default": "./lib/http.cjs"
|
|
22
|
+
},
|
|
18
23
|
"./lib/*.js": {
|
|
19
24
|
"types": "./esm/*.d.mts",
|
|
20
25
|
"import": "./esm/*.mjs",
|
|
@@ -46,8 +51,8 @@
|
|
|
46
51
|
],
|
|
47
52
|
"license": "MIT",
|
|
48
53
|
"dependencies": {
|
|
49
|
-
"@arcblock/ws": "1.30.
|
|
50
|
-
"@ocap/schema": "1.30.
|
|
54
|
+
"@arcblock/ws": "1.30.25",
|
|
55
|
+
"@ocap/schema": "1.30.25",
|
|
51
56
|
"graphql": "^16.13.2",
|
|
52
57
|
"lodash": "^4.17.23"
|
|
53
58
|
},
|