@codex-data/sdk 2.4.12 → 2.5.2
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 +27 -0
- package/dist/edge.d.ts +1 -1
- package/dist/edge.js +2 -1
- package/dist/edge.mjs +23 -10
- package/dist/sdk/Query.d.ts +2 -1
- package/dist/sdk/Query.js +1 -0
- package/dist/sdk/Query.mjs +2 -1
- package/dist/sdk/edge.d.ts +9 -4
- package/dist/sdk/edge.js +21 -9
- package/dist/sdk/edge.mjs +20 -9
- package/dist/sdk/edgeSubscription.d.ts +3 -2
- package/dist/sdk/edgeSubscription.js +8 -4
- package/dist/sdk/edgeSubscription.mjs +7 -4
- package/dist/sdk/generated/gql.d.ts +7 -2
- package/dist/sdk/generated/gql.js +2 -1
- package/dist/sdk/generated/gql.mjs +2 -1
- package/dist/sdk/generated/graphql.d.ts +103 -18
- package/dist/sdk/generated/graphql.js +4 -3
- package/dist/sdk/generated/graphql.mjs +2 -1
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.js +18 -11
- package/dist/sdk/index.mjs +18 -11
- package/package.json +1 -1
- package/schema.graphql +5719 -5671
package/dist/sdk/index.d.ts
CHANGED
package/dist/sdk/index.js
CHANGED
|
@@ -35,6 +35,7 @@ class Codex {
|
|
|
35
35
|
var _a, _b;
|
|
36
36
|
this.apiKey = apiKey;
|
|
37
37
|
this.apiConfig = apiConfig;
|
|
38
|
+
this.edgeWsClients = new Map();
|
|
38
39
|
this.disposed = false;
|
|
39
40
|
const config = this.parseConfig((_a = this.apiConfig) !== null && _a !== void 0 ? _a : {});
|
|
40
41
|
this.queries = new Query_1.Query(this);
|
|
@@ -86,9 +87,9 @@ class Codex {
|
|
|
86
87
|
updateConfig(incomingConfig) {
|
|
87
88
|
var _a, _b, _c;
|
|
88
89
|
// If we have an existing websocket connection, dispose of it.
|
|
89
|
-
if (this.wsClient || this.
|
|
90
|
+
if (this.wsClient || this.edgeWsClients.size)
|
|
90
91
|
void this.dispose();
|
|
91
|
-
this.
|
|
92
|
+
this.edgeWsClients.clear();
|
|
92
93
|
this.disposed = false;
|
|
93
94
|
this.apiConfig = Object.assign(Object.assign({}, this.apiConfig), incomingConfig);
|
|
94
95
|
// Merge the incoming config with the existing config.
|
|
@@ -114,9 +115,12 @@ class Codex {
|
|
|
114
115
|
*/
|
|
115
116
|
dispose() {
|
|
116
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
-
var _a
|
|
118
|
+
var _a;
|
|
118
119
|
this.disposed = true;
|
|
119
|
-
yield Promise.all([
|
|
120
|
+
yield Promise.all([
|
|
121
|
+
(_a = this.wsClient) === null || _a === void 0 ? void 0 : _a.dispose(),
|
|
122
|
+
...Array.from(this.edgeWsClients.values(), (edge) => edge.dispose()),
|
|
123
|
+
]);
|
|
120
124
|
});
|
|
121
125
|
}
|
|
122
126
|
/**
|
|
@@ -163,7 +167,7 @@ class Codex {
|
|
|
163
167
|
* @returns A cleanup function to unsubscribe from the subscription.
|
|
164
168
|
*/
|
|
165
169
|
subscribe(doc, args, sink, options) {
|
|
166
|
-
var _a;
|
|
170
|
+
var _a, _b;
|
|
167
171
|
if (!this.wsClient) {
|
|
168
172
|
throw new Error("Websocket is not enabled in the config");
|
|
169
173
|
}
|
|
@@ -173,15 +177,18 @@ class Codex {
|
|
|
173
177
|
if (!(options === null || options === void 0 ? void 0 : options.useEdge))
|
|
174
178
|
return this.wsClient.subscribe(payload, sink);
|
|
175
179
|
// Validate before creating the edge transport or starting an operation.
|
|
176
|
-
const snapshot = (0, edge_1.prepareEdgeSubscription)(payload);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
const { payload: snapshot, networkId } = (0, edge_1.prepareEdgeSubscription)(payload);
|
|
181
|
+
const config = this.parseConfig((_a = this.apiConfig) !== null && _a !== void 0 ? _a : {});
|
|
182
|
+
const url = (_b = config.apiEdgeUrl) !== null && _b !== void 0 ? _b : (0, edge_1.edgeUrlForNetwork)(networkId);
|
|
183
|
+
let edge = this.edgeWsClients.get(url);
|
|
184
|
+
if (!edge) {
|
|
185
|
+
edge = (0, edge_1.createEdgeClient)(Object.assign(Object.assign({}, this.websocketOptions(config)), { url }));
|
|
186
|
+
edge.on("error", (error) => {
|
|
181
187
|
console.error("Websocket error: ", error);
|
|
182
188
|
});
|
|
189
|
+
this.edgeWsClients.set(url, edge);
|
|
183
190
|
}
|
|
184
|
-
return
|
|
191
|
+
return edge.subscribe(snapshot, sink);
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
exports.Codex = Codex;
|
package/dist/sdk/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLClient } from "graphql-request";
|
|
2
2
|
import { createClient, } from "graphql-ws";
|
|
3
3
|
import WebSocket from "isomorphic-ws";
|
|
4
|
-
import { createEdgeClient, prepareEdgeSubscription, } from "./edge";
|
|
4
|
+
import { createEdgeClient, edgeUrlForNetwork, prepareEdgeSubscription, } from "./edge";
|
|
5
5
|
import { invariant } from "./invariant";
|
|
6
6
|
import { Mutation } from "./Mutation";
|
|
7
7
|
import { Query } from "./Query";
|
|
@@ -19,6 +19,7 @@ export class Codex {
|
|
|
19
19
|
constructor(apiKey, apiConfig) {
|
|
20
20
|
this.apiKey = apiKey;
|
|
21
21
|
this.apiConfig = apiConfig;
|
|
22
|
+
this.edgeWsClients = new Map();
|
|
22
23
|
this.disposed = false;
|
|
23
24
|
const config = this.parseConfig(this.apiConfig ?? {});
|
|
24
25
|
this.queries = new Query(this);
|
|
@@ -77,9 +78,9 @@ export class Codex {
|
|
|
77
78
|
*/
|
|
78
79
|
updateConfig(incomingConfig) {
|
|
79
80
|
// If we have an existing websocket connection, dispose of it.
|
|
80
|
-
if (this.wsClient || this.
|
|
81
|
+
if (this.wsClient || this.edgeWsClients.size)
|
|
81
82
|
void this.dispose();
|
|
82
|
-
this.
|
|
83
|
+
this.edgeWsClients.clear();
|
|
83
84
|
this.disposed = false;
|
|
84
85
|
this.apiConfig = { ...this.apiConfig, ...incomingConfig };
|
|
85
86
|
// Merge the incoming config with the existing config.
|
|
@@ -105,7 +106,10 @@ export class Codex {
|
|
|
105
106
|
*/
|
|
106
107
|
async dispose() {
|
|
107
108
|
this.disposed = true;
|
|
108
|
-
await Promise.all([
|
|
109
|
+
await Promise.all([
|
|
110
|
+
this.wsClient?.dispose(),
|
|
111
|
+
...Array.from(this.edgeWsClients.values(), (edge) => edge.dispose()),
|
|
112
|
+
]);
|
|
109
113
|
}
|
|
110
114
|
/**
|
|
111
115
|
* This is the preferred way to execute queries.
|
|
@@ -154,17 +158,20 @@ export class Codex {
|
|
|
154
158
|
if (!options?.useEdge)
|
|
155
159
|
return this.wsClient.subscribe(payload, sink);
|
|
156
160
|
// Validate before creating the edge transport or starting an operation.
|
|
157
|
-
const snapshot = prepareEdgeSubscription(payload);
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
const { payload: snapshot, networkId } = prepareEdgeSubscription(payload);
|
|
162
|
+
const config = this.parseConfig(this.apiConfig ?? {});
|
|
163
|
+
const url = config.apiEdgeUrl ?? edgeUrlForNetwork(networkId);
|
|
164
|
+
let edge = this.edgeWsClients.get(url);
|
|
165
|
+
if (!edge) {
|
|
166
|
+
edge = createEdgeClient({
|
|
161
167
|
...this.websocketOptions(config),
|
|
162
|
-
url
|
|
168
|
+
url,
|
|
163
169
|
});
|
|
164
|
-
|
|
170
|
+
edge.on("error", (error) => {
|
|
165
171
|
console.error("Websocket error: ", error);
|
|
166
172
|
});
|
|
173
|
+
this.edgeWsClients.set(url, edge);
|
|
167
174
|
}
|
|
168
|
-
return
|
|
175
|
+
return edge.subscribe(snapshot, sink);
|
|
169
176
|
}
|
|
170
177
|
}
|