@codex-data/sdk 0.5.7
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 +104 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/graphql.d.ts +7438 -0
- package/dist/resources/graphql.d.ts.map +1 -0
- package/dist/resources/graphql.js +1314 -0
- package/dist/resources/graphql.js.map +1 -0
- package/dist/resources/graphql.schema.json +50830 -0
- package/dist/resources/graphql.ts +7976 -0
- package/dist/resources/schema.graphql +10393 -0
- package/dist/sdk/Mutation.d.ts +14 -0
- package/dist/sdk/Mutation.d.ts.map +1 -0
- package/dist/sdk/Mutation.js +22 -0
- package/dist/sdk/Mutation.js.map +1 -0
- package/dist/sdk/Query.d.ts +22 -0
- package/dist/sdk/Query.d.ts.map +1 -0
- package/dist/sdk/Query.js +35 -0
- package/dist/sdk/Query.js.map +1 -0
- package/dist/sdk/Query.test.d.ts +2 -0
- package/dist/sdk/Query.test.d.ts.map +1 -0
- package/dist/sdk/Query.test.js +50 -0
- package/dist/sdk/Query.test.js.map +1 -0
- package/dist/sdk/Subscribe.d.ts +17 -0
- package/dist/sdk/Subscribe.d.ts.map +1 -0
- package/dist/sdk/Subscribe.js +28 -0
- package/dist/sdk/Subscribe.js.map +1 -0
- package/dist/sdk/generated/fragment-masking.d.ts +16 -0
- package/dist/sdk/generated/fragment-masking.d.ts.map +1 -0
- package/dist/sdk/generated/fragment-masking.js +23 -0
- package/dist/sdk/generated/fragment-masking.js.map +1 -0
- package/dist/sdk/generated/gql.d.ts +243 -0
- package/dist/sdk/generated/gql.d.ts.map +1 -0
- package/dist/sdk/generated/gql.js +70 -0
- package/dist/sdk/generated/gql.js.map +1 -0
- package/dist/sdk/generated/graphql.d.ts +11765 -0
- package/dist/sdk/generated/graphql.d.ts.map +1 -0
- package/dist/sdk/generated/graphql.js +1338 -0
- package/dist/sdk/generated/graphql.js.map +1 -0
- package/dist/sdk/generated/index.d.ts +3 -0
- package/dist/sdk/generated/index.d.ts.map +1 -0
- package/dist/sdk/generated/index.js +19 -0
- package/dist/sdk/generated/index.js.map +1 -0
- package/dist/sdk/index.d.ts +23 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +76 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/index.test.d.ts +2 -0
- package/dist/sdk/index.test.d.ts.map +1 -0
- package/dist/sdk/index.test.js +78 -0
- package/dist/sdk/index.test.js.map +1 -0
- package/dist/sdk/invariant.d.ts +2 -0
- package/dist/sdk/invariant.d.ts.map +1 -0
- package/dist/sdk/invariant.js +31 -0
- package/dist/sdk/invariant.js.map +1 -0
- package/package.json +60 -0
- package/src/index.ts +2 -0
- package/src/resources/.keep +0 -0
- package/src/resources/graphql.schema.json +50830 -0
- package/src/resources/graphql.ts +7976 -0
- package/src/resources/schema.graphql +10393 -0
- package/src/sdk/Mutation.ts +15 -0
- package/src/sdk/Query.test.ts +40 -0
- package/src/sdk/Query.ts +65 -0
- package/src/sdk/Subscribe.ts +61 -0
- package/src/sdk/generated/fragment-masking.ts +66 -0
- package/src/sdk/generated/gql.ts +157 -0
- package/src/sdk/generated/graphql.ts +8215 -0
- package/src/sdk/generated/index.ts +2 -0
- package/src/sdk/graphql/CreateWebhooks.graphql +1145 -0
- package/src/sdk/graphql/DeleteWebhooks.graphql +5 -0
- package/src/sdk/graphql/FilterExchanges.graphql +23 -0
- package/src/sdk/graphql/FilterPairs.graphql +124 -0
- package/src/sdk/graphql/FilterTokens.graphql +129 -0
- package/src/sdk/graphql/GetBars.graphql +32 -0
- package/src/sdk/graphql/GetDetailedPairStats.graphql +941 -0
- package/src/sdk/graphql/GetNetworkStatus.graphql +7 -0
- package/src/sdk/graphql/GetNetworks.graphql +6 -0
- package/src/sdk/graphql/GetPairEvents.graphql +28 -0
- package/src/sdk/graphql/GetPrice.graphql +9 -0
- package/src/sdk/graphql/GetSparklines.graphql +10 -0
- package/src/sdk/graphql/GetSymbol.graphql +11 -0
- package/src/sdk/graphql/GetTokens.graphql +14 -0
- package/src/sdk/graphql/GetWebhooks.graphql +168 -0
- package/src/sdk/graphql/ListPairsForToken.graphql +105 -0
- package/src/sdk/graphql/ListTopTokens.graphql +48 -0
- package/src/sdk/graphql/OnBarsUpdated.graphql +183 -0
- package/src/sdk/graphql/OnDetailedStatsUpdated.graphql +324 -0
- package/src/sdk/graphql/OnEventsCreated.graphql +62 -0
- package/src/sdk/graphql/OnNftAssetsCreated.graphql +29 -0
- package/src/sdk/graphql/OnNftEventsCreated.graphql +83 -0
- package/src/sdk/graphql/OnPairMetadataUpdated.graphql +55 -0
- package/src/sdk/graphql/OnPriceUpdated.graphql +9 -0
- package/src/sdk/index.test.ts +78 -0
- package/src/sdk/index.ts +100 -0
- package/src/sdk/invariant.ts +34 -0
package/src/sdk/index.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
2
|
+
import { GraphQLClient, Variables } from "graphql-request";
|
|
3
|
+
import { VariablesAndRequestHeadersArgs } from "graphql-request/build/esm/types";
|
|
4
|
+
import {
|
|
5
|
+
Client as GraphQLWsClient,
|
|
6
|
+
createClient,
|
|
7
|
+
ExecutionResult,
|
|
8
|
+
Sink,
|
|
9
|
+
} from "graphql-ws";
|
|
10
|
+
import WebSocket from "isomorphic-ws";
|
|
11
|
+
|
|
12
|
+
import { invariant } from "./invariant";
|
|
13
|
+
import { Mutation } from "./Mutation";
|
|
14
|
+
import { Query } from "./Query";
|
|
15
|
+
import { Subscribe } from "./Subscribe";
|
|
16
|
+
|
|
17
|
+
export type CleanupFunction = () => void;
|
|
18
|
+
|
|
19
|
+
export class Codex {
|
|
20
|
+
private client: GraphQLClient;
|
|
21
|
+
private wsClient: GraphQLWsClient;
|
|
22
|
+
public queries: Query;
|
|
23
|
+
public mutations: Mutation;
|
|
24
|
+
public subscriptions: Subscribe;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
private apiKey: string,
|
|
28
|
+
private apiUrl: string = `https://graph.codex.io/graphql`,
|
|
29
|
+
private apiRealtimeUrl: string = `wss://graph.codex.io/graphql`,
|
|
30
|
+
) {
|
|
31
|
+
invariant(this.apiKey, "apiKey must be defined");
|
|
32
|
+
this.queries = new Query(this);
|
|
33
|
+
this.mutations = new Mutation(this);
|
|
34
|
+
this.subscriptions = new Subscribe(this);
|
|
35
|
+
this.client = new GraphQLClient(this.apiUrl, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: new Headers({
|
|
38
|
+
"Content-Type": "application/json",
|
|
39
|
+
Authorization: this.apiKey,
|
|
40
|
+
"X-Apollo-Operation-Name": "query",
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
this.wsClient = createClient({
|
|
44
|
+
webSocketImpl: WebSocket,
|
|
45
|
+
url: this.apiRealtimeUrl,
|
|
46
|
+
connectionParams: {
|
|
47
|
+
Authorization: this.apiKey,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async query<TResults, TVars extends Variables>(
|
|
53
|
+
doc: TypedDocumentNode<TResults, TVars>,
|
|
54
|
+
args: TVars = {} as TVars,
|
|
55
|
+
) {
|
|
56
|
+
const res = await this.client.request<typeof doc, TVars>(
|
|
57
|
+
doc,
|
|
58
|
+
...([args] as unknown as VariablesAndRequestHeadersArgs<TVars>),
|
|
59
|
+
);
|
|
60
|
+
return res as TResults;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public async mutation<TResults, TVars extends Variables>(
|
|
64
|
+
doc: TypedDocumentNode<TResults, TVars>,
|
|
65
|
+
args: TVars = {} as TVars,
|
|
66
|
+
) {
|
|
67
|
+
const res = await this.client.request<typeof doc, TVars>(
|
|
68
|
+
doc,
|
|
69
|
+
...([args] as unknown as VariablesAndRequestHeadersArgs<TVars>),
|
|
70
|
+
);
|
|
71
|
+
return res as TResults;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Very simple network based fetch implementation, no compilation required
|
|
75
|
+
public async send<TResults, V extends Variables = Variables>(
|
|
76
|
+
gqlString: string,
|
|
77
|
+
args: V = {} as V,
|
|
78
|
+
) {
|
|
79
|
+
const res = await this.client.request<TResults>(gqlString, args);
|
|
80
|
+
return res;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public subscribe<
|
|
84
|
+
TResults,
|
|
85
|
+
TVars extends Record<string, unknown> = Record<string, never>,
|
|
86
|
+
>(
|
|
87
|
+
doc: string,
|
|
88
|
+
args: TVars,
|
|
89
|
+
sink: Sink<ExecutionResult<TResults>>,
|
|
90
|
+
): CleanupFunction {
|
|
91
|
+
const cleanup = this.wsClient.subscribe<TResults>(
|
|
92
|
+
{
|
|
93
|
+
query: doc,
|
|
94
|
+
variables: args,
|
|
95
|
+
},
|
|
96
|
+
sink,
|
|
97
|
+
);
|
|
98
|
+
return cleanup;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const isProduction: boolean = process.env.NODE_ENV === "production";
|
|
2
|
+
const prefix = "Invariant failed";
|
|
3
|
+
|
|
4
|
+
// Throw an error if the condition fails
|
|
5
|
+
// Strip out error messages for production
|
|
6
|
+
// > Not providing an inline default argument for message as the result is smaller
|
|
7
|
+
export function invariant(
|
|
8
|
+
condition: unknown,
|
|
9
|
+
// Can provide a string, or a function that returns a string for cases where
|
|
10
|
+
// the message takes a fair amount of effort to compute
|
|
11
|
+
message?: string | (() => string),
|
|
12
|
+
): asserts condition {
|
|
13
|
+
if (condition) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
// Condition not passed
|
|
17
|
+
|
|
18
|
+
// In production we strip the message but still throw
|
|
19
|
+
if (isProduction) {
|
|
20
|
+
throw new Error(prefix);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// When not in production we allow the message to pass through
|
|
24
|
+
// *This block will be removed in production builds*
|
|
25
|
+
|
|
26
|
+
const provided: string | undefined =
|
|
27
|
+
typeof message === "function" ? message() : message;
|
|
28
|
+
|
|
29
|
+
// Options:
|
|
30
|
+
// 1. message provided: `${prefix}: ${provided}`
|
|
31
|
+
// 2. message not provided: prefix
|
|
32
|
+
const value: string = provided ? `${prefix}: ${provided}` : prefix;
|
|
33
|
+
throw new Error(value);
|
|
34
|
+
}
|