@codex-data/sdk 2.3.43 → 2.4.1
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/edge.d.ts +2 -0
- package/dist/edge.js +8 -0
- package/dist/edge.mjs +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/sdk/Mutation.d.ts +2 -1
- package/dist/sdk/Mutation.js +1 -0
- package/dist/sdk/Mutation.mjs +2 -1
- package/dist/sdk/Query.d.ts +4 -2
- package/dist/sdk/Query.js +3 -1
- package/dist/sdk/Query.mjs +4 -2
- package/dist/sdk/Subscribe.d.ts +32 -30
- package/dist/sdk/Subscribe.js +74 -69
- package/dist/sdk/Subscribe.mjs +74 -69
- package/dist/sdk/edge.d.ts +24 -0
- package/dist/sdk/edge.js +111 -0
- package/dist/sdk/edge.mjs +95 -0
- package/dist/sdk/edgeSubscription.d.ts +3 -0
- package/dist/sdk/edgeSubscription.js +76 -0
- package/dist/sdk/edgeSubscription.mjs +72 -0
- package/dist/sdk/generated/gql.d.ts +86 -66
- package/dist/sdk/generated/gql.js +37 -33
- package/dist/sdk/generated/gql.mjs +37 -33
- package/dist/sdk/generated/graphql.d.ts +5391 -61
- package/dist/sdk/generated/graphql.js +261 -40
- package/dist/sdk/generated/graphql.mjs +256 -35
- package/dist/sdk/index.d.ts +6 -1
- package/dist/sdk/index.js +36 -18
- package/dist/sdk/index.mjs +40 -20
- package/package.json +39 -24
- package/schema.graphql +2539 -1575
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Client, type ClientOptions, createClient, type Event, type EventListener, type ExecutionResult, type Sink, type SubscribePayload } from "graphql-ws";
|
|
2
|
+
export { createClient };
|
|
3
|
+
export declare const DEFAULT_EDGE_URL = "wss://fra.edge.codex.io/graphql";
|
|
4
|
+
export interface SubscriptionOptions {
|
|
5
|
+
/** Experimental: use edge for supported Solana streams whose commitments include Processed. */
|
|
6
|
+
useEdge?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ClientWithEdge extends Client {
|
|
9
|
+
/** Observe both transports, or select one with useEdge. */
|
|
10
|
+
on<E extends Event>(event: E, listener: EventListener<E>, options?: SubscriptionOptions): () => void;
|
|
11
|
+
subscribe<Data = Record<string, unknown>, Extensions = unknown>(payload: SubscribePayload, sink: Sink<ExecutionResult<Data, Extensions>>, options?: SubscriptionOptions): () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface EdgeClientOptions extends Omit<ClientOptions, "url"> {
|
|
14
|
+
/** Defaults to the regional edge endpoint. */
|
|
15
|
+
url?: ClientOptions["url"];
|
|
16
|
+
}
|
|
17
|
+
/** Create a transport that connects only to edge. */
|
|
18
|
+
export declare function createEdgeClient(options: EdgeClientOptions): Client;
|
|
19
|
+
/** Snapshot and validate the arguments that will actually be sent to edge. */
|
|
20
|
+
export declare function prepareEdgeSubscription(payload: SubscribePayload, replacer?: ClientOptions["jsonMessageReplacer"]): SubscribePayload;
|
|
21
|
+
/** Add per-subscription edge routing to an existing GraphQL client. */
|
|
22
|
+
export declare function withEdge(main: Client, options: ClientOptions & {
|
|
23
|
+
edgeUrl?: string;
|
|
24
|
+
}): ClientWithEdge;
|
package/dist/sdk/edge.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.DEFAULT_EDGE_URL = exports.createClient = void 0;
|
|
24
|
+
exports.createEdgeClient = createEdgeClient;
|
|
25
|
+
exports.prepareEdgeSubscription = prepareEdgeSubscription;
|
|
26
|
+
exports.withEdge = withEdge;
|
|
27
|
+
const graphql_ws_1 = require("graphql-ws");
|
|
28
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return graphql_ws_1.createClient; } });
|
|
29
|
+
const edgeSubscription_1 = require("./edgeSubscription");
|
|
30
|
+
exports.DEFAULT_EDGE_URL = "wss://fra.edge.codex.io/graphql";
|
|
31
|
+
/** Create a transport that connects only to edge. */
|
|
32
|
+
function createEdgeClient(options) {
|
|
33
|
+
var _a;
|
|
34
|
+
return (0, graphql_ws_1.createClient)(Object.assign(Object.assign({}, options), { url: (_a = options.url) !== null && _a !== void 0 ? _a : exports.DEFAULT_EDGE_URL }));
|
|
35
|
+
}
|
|
36
|
+
/** Snapshot and validate the arguments that will actually be sent to edge. */
|
|
37
|
+
function prepareEdgeSubscription(payload, replacer) {
|
|
38
|
+
const snapshot = JSON.parse(JSON.stringify(payload, replacer));
|
|
39
|
+
(0, edgeSubscription_1.assertEdgeSubscription)(snapshot);
|
|
40
|
+
return snapshot;
|
|
41
|
+
}
|
|
42
|
+
/** Add per-subscription edge routing to an existing GraphQL client. */
|
|
43
|
+
function withEdge(main, options) {
|
|
44
|
+
const { edgeUrl = exports.DEFAULT_EDGE_URL } = options, wsOptions = __rest(options, ["edgeUrl"]);
|
|
45
|
+
const mainHandlers = new Set();
|
|
46
|
+
const edgeHandlers = new Set(wsOptions.on ? [wsOptions.on] : []);
|
|
47
|
+
const handlersFor = (useEdge) => {
|
|
48
|
+
const handlers = () => Array.from(useEdge ? edgeHandlers : mainHandlers);
|
|
49
|
+
// Install before createClient so even non-lazy connection events are observed.
|
|
50
|
+
return {
|
|
51
|
+
connecting: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.connecting) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
52
|
+
opened: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.opened) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
53
|
+
connected: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.connected) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
54
|
+
ping: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.ping) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
55
|
+
pong: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.pong) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
56
|
+
message: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.message) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
57
|
+
closed: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.closed) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
58
|
+
error: (...args) => handlers().forEach((on) => { var _a; return (_a = on === null || on === void 0 ? void 0 : on.error) === null || _a === void 0 ? void 0 : _a.call(on, ...args); }),
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const mainEvents = handlersFor(false);
|
|
62
|
+
main.on("connecting", mainEvents.connecting);
|
|
63
|
+
main.on("opened", mainEvents.opened);
|
|
64
|
+
main.on("connected", mainEvents.connected);
|
|
65
|
+
main.on("ping", mainEvents.ping);
|
|
66
|
+
main.on("pong", mainEvents.pong);
|
|
67
|
+
main.on("message", mainEvents.message);
|
|
68
|
+
main.on("closed", mainEvents.closed);
|
|
69
|
+
main.on("error", mainEvents.error);
|
|
70
|
+
let edge;
|
|
71
|
+
let disposed = false;
|
|
72
|
+
return Object.assign(Object.assign({}, main), { on: (event, listener, subscriptionOptions = {}) => {
|
|
73
|
+
const handlers = { [event]: listener };
|
|
74
|
+
if (subscriptionOptions.useEdge !== true)
|
|
75
|
+
mainHandlers.add(handlers);
|
|
76
|
+
if (subscriptionOptions.useEdge !== false)
|
|
77
|
+
edgeHandlers.add(handlers);
|
|
78
|
+
return () => {
|
|
79
|
+
mainHandlers.delete(handlers);
|
|
80
|
+
edgeHandlers.delete(handlers);
|
|
81
|
+
};
|
|
82
|
+
}, subscribe: (payload, sink, subscriptionOptions = {}) => {
|
|
83
|
+
if (disposed)
|
|
84
|
+
throw new Error("Edge client has been disposed");
|
|
85
|
+
if (!subscriptionOptions.useEdge)
|
|
86
|
+
return main.subscribe(payload, sink);
|
|
87
|
+
// Reject before creating an edge client or opening any upstream operation.
|
|
88
|
+
const snapshot = prepareEdgeSubscription(payload, wsOptions.jsonMessageReplacer);
|
|
89
|
+
if (!edge) {
|
|
90
|
+
// Edge payloads are serialized once, before validation. Preserve custom
|
|
91
|
+
// serialization for handshakes without transforming subscriptions again.
|
|
92
|
+
let subscriptionMessage = false;
|
|
93
|
+
edge = createEdgeClient(Object.assign(Object.assign({}, wsOptions), { url: edgeUrl, on: handlersFor(true), jsonMessageReplacer: function (key, value) {
|
|
94
|
+
if (key === "")
|
|
95
|
+
subscriptionMessage = (value === null || value === void 0 ? void 0 : value.type) === "subscribe";
|
|
96
|
+
return subscriptionMessage
|
|
97
|
+
? value
|
|
98
|
+
: wsOptions.jsonMessageReplacer
|
|
99
|
+
? wsOptions.jsonMessageReplacer.call(this, key, value)
|
|
100
|
+
: value;
|
|
101
|
+
} }));
|
|
102
|
+
}
|
|
103
|
+
return edge.subscribe(snapshot, sink);
|
|
104
|
+
}, terminate: () => {
|
|
105
|
+
main.terminate();
|
|
106
|
+
edge === null || edge === void 0 ? void 0 : edge.terminate();
|
|
107
|
+
}, dispose: () => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
disposed = true;
|
|
109
|
+
yield Promise.all([main.dispose(), edge === null || edge === void 0 ? void 0 : edge.dispose()]);
|
|
110
|
+
}) });
|
|
111
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createClient, } from "graphql-ws";
|
|
2
|
+
import { assertEdgeSubscription } from "./edgeSubscription";
|
|
3
|
+
export { createClient };
|
|
4
|
+
export const DEFAULT_EDGE_URL = "wss://fra.edge.codex.io/graphql";
|
|
5
|
+
/** Create a transport that connects only to edge. */
|
|
6
|
+
export function createEdgeClient(options) {
|
|
7
|
+
return createClient({ ...options, url: options.url ?? DEFAULT_EDGE_URL });
|
|
8
|
+
}
|
|
9
|
+
/** Snapshot and validate the arguments that will actually be sent to edge. */
|
|
10
|
+
export function prepareEdgeSubscription(payload, replacer) {
|
|
11
|
+
const snapshot = JSON.parse(JSON.stringify(payload, replacer));
|
|
12
|
+
assertEdgeSubscription(snapshot);
|
|
13
|
+
return snapshot;
|
|
14
|
+
}
|
|
15
|
+
/** Add per-subscription edge routing to an existing GraphQL client. */
|
|
16
|
+
export function withEdge(main, options) {
|
|
17
|
+
const { edgeUrl = DEFAULT_EDGE_URL, ...wsOptions } = options;
|
|
18
|
+
const mainHandlers = new Set();
|
|
19
|
+
const edgeHandlers = new Set(wsOptions.on ? [wsOptions.on] : []);
|
|
20
|
+
const handlersFor = (useEdge) => {
|
|
21
|
+
const handlers = () => Array.from(useEdge ? edgeHandlers : mainHandlers);
|
|
22
|
+
// Install before createClient so even non-lazy connection events are observed.
|
|
23
|
+
return {
|
|
24
|
+
connecting: (...args) => handlers().forEach((on) => on?.connecting?.(...args)),
|
|
25
|
+
opened: (...args) => handlers().forEach((on) => on?.opened?.(...args)),
|
|
26
|
+
connected: (...args) => handlers().forEach((on) => on?.connected?.(...args)),
|
|
27
|
+
ping: (...args) => handlers().forEach((on) => on?.ping?.(...args)),
|
|
28
|
+
pong: (...args) => handlers().forEach((on) => on?.pong?.(...args)),
|
|
29
|
+
message: (...args) => handlers().forEach((on) => on?.message?.(...args)),
|
|
30
|
+
closed: (...args) => handlers().forEach((on) => on?.closed?.(...args)),
|
|
31
|
+
error: (...args) => handlers().forEach((on) => on?.error?.(...args)),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const mainEvents = handlersFor(false);
|
|
35
|
+
main.on("connecting", mainEvents.connecting);
|
|
36
|
+
main.on("opened", mainEvents.opened);
|
|
37
|
+
main.on("connected", mainEvents.connected);
|
|
38
|
+
main.on("ping", mainEvents.ping);
|
|
39
|
+
main.on("pong", mainEvents.pong);
|
|
40
|
+
main.on("message", mainEvents.message);
|
|
41
|
+
main.on("closed", mainEvents.closed);
|
|
42
|
+
main.on("error", mainEvents.error);
|
|
43
|
+
let edge;
|
|
44
|
+
let disposed = false;
|
|
45
|
+
return {
|
|
46
|
+
...main,
|
|
47
|
+
on: (event, listener, subscriptionOptions = {}) => {
|
|
48
|
+
const handlers = { [event]: listener };
|
|
49
|
+
if (subscriptionOptions.useEdge !== true)
|
|
50
|
+
mainHandlers.add(handlers);
|
|
51
|
+
if (subscriptionOptions.useEdge !== false)
|
|
52
|
+
edgeHandlers.add(handlers);
|
|
53
|
+
return () => {
|
|
54
|
+
mainHandlers.delete(handlers);
|
|
55
|
+
edgeHandlers.delete(handlers);
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
subscribe: (payload, sink, subscriptionOptions = {}) => {
|
|
59
|
+
if (disposed)
|
|
60
|
+
throw new Error("Edge client has been disposed");
|
|
61
|
+
if (!subscriptionOptions.useEdge)
|
|
62
|
+
return main.subscribe(payload, sink);
|
|
63
|
+
// Reject before creating an edge client or opening any upstream operation.
|
|
64
|
+
const snapshot = prepareEdgeSubscription(payload, wsOptions.jsonMessageReplacer);
|
|
65
|
+
if (!edge) {
|
|
66
|
+
// Edge payloads are serialized once, before validation. Preserve custom
|
|
67
|
+
// serialization for handshakes without transforming subscriptions again.
|
|
68
|
+
let subscriptionMessage = false;
|
|
69
|
+
edge = createEdgeClient({
|
|
70
|
+
...wsOptions,
|
|
71
|
+
url: edgeUrl,
|
|
72
|
+
on: handlersFor(true),
|
|
73
|
+
jsonMessageReplacer: function (key, value) {
|
|
74
|
+
if (key === "")
|
|
75
|
+
subscriptionMessage = value?.type === "subscribe";
|
|
76
|
+
return subscriptionMessage
|
|
77
|
+
? value
|
|
78
|
+
: wsOptions.jsonMessageReplacer
|
|
79
|
+
? wsOptions.jsonMessageReplacer.call(this, key, value)
|
|
80
|
+
: value;
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return edge.subscribe(snapshot, sink);
|
|
85
|
+
},
|
|
86
|
+
terminate: () => {
|
|
87
|
+
main.terminate();
|
|
88
|
+
edge?.terminate();
|
|
89
|
+
},
|
|
90
|
+
dispose: async () => {
|
|
91
|
+
disposed = true;
|
|
92
|
+
await Promise.all([main.dispose(), edge?.dispose()]);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertEdgeSubscription = assertEdgeSubscription;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const SOLANA_NETWORK_ID = 1399811149;
|
|
6
|
+
const SUPPORTED_OPERATIONS = new Set([
|
|
7
|
+
"onEventsCreated",
|
|
8
|
+
"onTokenEventsCreated",
|
|
9
|
+
"onBarsUpdated",
|
|
10
|
+
"onTokenBarsUpdated",
|
|
11
|
+
]);
|
|
12
|
+
/** Validate the actual GraphQL arguments, including literals and variable defaults. */
|
|
13
|
+
function assertEdgeSubscription(payload) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
function fail() {
|
|
16
|
+
throw new Error("useEdge requires a supported Solana subscription with commitmentLevel including Processed");
|
|
17
|
+
}
|
|
18
|
+
const document = (0, graphql_1.parse)(payload.query);
|
|
19
|
+
const operation = (0, graphql_1.getOperationAST)(document, payload.operationName);
|
|
20
|
+
if (!operation || operation.operation !== "subscription")
|
|
21
|
+
fail();
|
|
22
|
+
// Edge executes a single root field; root fragments and conditional roots
|
|
23
|
+
// are not supported by its current customer transport.
|
|
24
|
+
const selections = operation.selectionSet.selections;
|
|
25
|
+
if (selections.length !== 1)
|
|
26
|
+
fail();
|
|
27
|
+
const field = selections[0];
|
|
28
|
+
if (field.kind !== graphql_1.Kind.FIELD || !SUPPORTED_OPERATIONS.has(field.name.value))
|
|
29
|
+
fail();
|
|
30
|
+
if ((_a = field.directives) === null || _a === void 0 ? void 0 : _a.length)
|
|
31
|
+
fail();
|
|
32
|
+
const variables = Object.assign({}, payload.variables);
|
|
33
|
+
for (const definition of (_b = operation.variableDefinitions) !== null && _b !== void 0 ? _b : []) {
|
|
34
|
+
const name = definition.variable.name.value;
|
|
35
|
+
if (variables[name] === undefined &&
|
|
36
|
+
definition.defaultValue !== undefined) {
|
|
37
|
+
variables[name] = (0, graphql_1.valueFromASTUntyped)(definition.defaultValue);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const args = Object.fromEntries(((_c = field.arguments) !== null && _c !== void 0 ? _c : []).map((argument) => [
|
|
41
|
+
argument.name.value,
|
|
42
|
+
(0, graphql_1.valueFromASTUntyped)(argument.value, variables),
|
|
43
|
+
]));
|
|
44
|
+
const levels = Array.isArray(args.commitmentLevel)
|
|
45
|
+
? args.commitmentLevel
|
|
46
|
+
: [args.commitmentLevel];
|
|
47
|
+
if (!levels.includes("Processed") ||
|
|
48
|
+
[...levels].some((level) => level !== "Processed" &&
|
|
49
|
+
level !== "Confirmed" &&
|
|
50
|
+
level !== "Preprocessed"))
|
|
51
|
+
fail();
|
|
52
|
+
const networks = [];
|
|
53
|
+
const collect = (value) => {
|
|
54
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
55
|
+
return;
|
|
56
|
+
for (const [name, item] of Object.entries(value)) {
|
|
57
|
+
if (name === "networkId" && item != null)
|
|
58
|
+
networks.push(item);
|
|
59
|
+
if (["id", "pairId", "tokenId"].includes(name) && item != null) {
|
|
60
|
+
if (typeof item !== "string" || !/^[^:]+:\d+$/.test(item))
|
|
61
|
+
fail();
|
|
62
|
+
networks.push(Number(item.slice(item.lastIndexOf(":") + 1)));
|
|
63
|
+
}
|
|
64
|
+
if (name === "input")
|
|
65
|
+
collect(item);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
collect(args);
|
|
69
|
+
if (!networks.length ||
|
|
70
|
+
networks.some((network) => network !== SOLANA_NETWORK_ID))
|
|
71
|
+
fail();
|
|
72
|
+
// Without an explicit quote, edge proxies this request back to Oregon.
|
|
73
|
+
if (field.name.value === "onBarsUpdated" && args.quoteToken == null) {
|
|
74
|
+
throw new Error("useEdge onBarsUpdated requires an explicit quoteToken");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getOperationAST, Kind, parse, valueFromASTUntyped } from "graphql";
|
|
2
|
+
const SOLANA_NETWORK_ID = 1399811149;
|
|
3
|
+
const SUPPORTED_OPERATIONS = new Set([
|
|
4
|
+
"onEventsCreated",
|
|
5
|
+
"onTokenEventsCreated",
|
|
6
|
+
"onBarsUpdated",
|
|
7
|
+
"onTokenBarsUpdated",
|
|
8
|
+
]);
|
|
9
|
+
/** Validate the actual GraphQL arguments, including literals and variable defaults. */
|
|
10
|
+
export function assertEdgeSubscription(payload) {
|
|
11
|
+
function fail() {
|
|
12
|
+
throw new Error("useEdge requires a supported Solana subscription with commitmentLevel including Processed");
|
|
13
|
+
}
|
|
14
|
+
const document = parse(payload.query);
|
|
15
|
+
const operation = getOperationAST(document, payload.operationName);
|
|
16
|
+
if (!operation || operation.operation !== "subscription")
|
|
17
|
+
fail();
|
|
18
|
+
// Edge executes a single root field; root fragments and conditional roots
|
|
19
|
+
// are not supported by its current customer transport.
|
|
20
|
+
const selections = operation.selectionSet.selections;
|
|
21
|
+
if (selections.length !== 1)
|
|
22
|
+
fail();
|
|
23
|
+
const field = selections[0];
|
|
24
|
+
if (field.kind !== Kind.FIELD || !SUPPORTED_OPERATIONS.has(field.name.value))
|
|
25
|
+
fail();
|
|
26
|
+
if (field.directives?.length)
|
|
27
|
+
fail();
|
|
28
|
+
const variables = { ...payload.variables };
|
|
29
|
+
for (const definition of operation.variableDefinitions ?? []) {
|
|
30
|
+
const name = definition.variable.name.value;
|
|
31
|
+
if (variables[name] === undefined &&
|
|
32
|
+
definition.defaultValue !== undefined) {
|
|
33
|
+
variables[name] = valueFromASTUntyped(definition.defaultValue);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const args = Object.fromEntries((field.arguments ?? []).map((argument) => [
|
|
37
|
+
argument.name.value,
|
|
38
|
+
valueFromASTUntyped(argument.value, variables),
|
|
39
|
+
]));
|
|
40
|
+
const levels = Array.isArray(args.commitmentLevel)
|
|
41
|
+
? args.commitmentLevel
|
|
42
|
+
: [args.commitmentLevel];
|
|
43
|
+
if (!levels.includes("Processed") ||
|
|
44
|
+
[...levels].some((level) => level !== "Processed" &&
|
|
45
|
+
level !== "Confirmed" &&
|
|
46
|
+
level !== "Preprocessed"))
|
|
47
|
+
fail();
|
|
48
|
+
const networks = [];
|
|
49
|
+
const collect = (value) => {
|
|
50
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
51
|
+
return;
|
|
52
|
+
for (const [name, item] of Object.entries(value)) {
|
|
53
|
+
if (name === "networkId" && item != null)
|
|
54
|
+
networks.push(item);
|
|
55
|
+
if (["id", "pairId", "tokenId"].includes(name) && item != null) {
|
|
56
|
+
if (typeof item !== "string" || !/^[^:]+:\d+$/.test(item))
|
|
57
|
+
fail();
|
|
58
|
+
networks.push(Number(item.slice(item.lastIndexOf(":") + 1)));
|
|
59
|
+
}
|
|
60
|
+
if (name === "input")
|
|
61
|
+
collect(item);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
collect(args);
|
|
65
|
+
if (!networks.length ||
|
|
66
|
+
networks.some((network) => network !== SOLANA_NETWORK_ID))
|
|
67
|
+
fail();
|
|
68
|
+
// Without an explicit quote, edge proxies this request back to Oregon.
|
|
69
|
+
if (field.name.value === "onBarsUpdated" && args.quoteToken == null) {
|
|
70
|
+
throw new Error("useEdge onBarsUpdated requires an explicit quoteToken");
|
|
71
|
+
}
|
|
72
|
+
}
|