@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.
Files changed (97) hide show
  1. package/README.md +104 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +32 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/resources/graphql.d.ts +7438 -0
  7. package/dist/resources/graphql.d.ts.map +1 -0
  8. package/dist/resources/graphql.js +1314 -0
  9. package/dist/resources/graphql.js.map +1 -0
  10. package/dist/resources/graphql.schema.json +50830 -0
  11. package/dist/resources/graphql.ts +7976 -0
  12. package/dist/resources/schema.graphql +10393 -0
  13. package/dist/sdk/Mutation.d.ts +14 -0
  14. package/dist/sdk/Mutation.d.ts.map +1 -0
  15. package/dist/sdk/Mutation.js +22 -0
  16. package/dist/sdk/Mutation.js.map +1 -0
  17. package/dist/sdk/Query.d.ts +22 -0
  18. package/dist/sdk/Query.d.ts.map +1 -0
  19. package/dist/sdk/Query.js +35 -0
  20. package/dist/sdk/Query.js.map +1 -0
  21. package/dist/sdk/Query.test.d.ts +2 -0
  22. package/dist/sdk/Query.test.d.ts.map +1 -0
  23. package/dist/sdk/Query.test.js +50 -0
  24. package/dist/sdk/Query.test.js.map +1 -0
  25. package/dist/sdk/Subscribe.d.ts +17 -0
  26. package/dist/sdk/Subscribe.d.ts.map +1 -0
  27. package/dist/sdk/Subscribe.js +28 -0
  28. package/dist/sdk/Subscribe.js.map +1 -0
  29. package/dist/sdk/generated/fragment-masking.d.ts +16 -0
  30. package/dist/sdk/generated/fragment-masking.d.ts.map +1 -0
  31. package/dist/sdk/generated/fragment-masking.js +23 -0
  32. package/dist/sdk/generated/fragment-masking.js.map +1 -0
  33. package/dist/sdk/generated/gql.d.ts +243 -0
  34. package/dist/sdk/generated/gql.d.ts.map +1 -0
  35. package/dist/sdk/generated/gql.js +70 -0
  36. package/dist/sdk/generated/gql.js.map +1 -0
  37. package/dist/sdk/generated/graphql.d.ts +11765 -0
  38. package/dist/sdk/generated/graphql.d.ts.map +1 -0
  39. package/dist/sdk/generated/graphql.js +1338 -0
  40. package/dist/sdk/generated/graphql.js.map +1 -0
  41. package/dist/sdk/generated/index.d.ts +3 -0
  42. package/dist/sdk/generated/index.d.ts.map +1 -0
  43. package/dist/sdk/generated/index.js +19 -0
  44. package/dist/sdk/generated/index.js.map +1 -0
  45. package/dist/sdk/index.d.ts +23 -0
  46. package/dist/sdk/index.d.ts.map +1 -0
  47. package/dist/sdk/index.js +76 -0
  48. package/dist/sdk/index.js.map +1 -0
  49. package/dist/sdk/index.test.d.ts +2 -0
  50. package/dist/sdk/index.test.d.ts.map +1 -0
  51. package/dist/sdk/index.test.js +78 -0
  52. package/dist/sdk/index.test.js.map +1 -0
  53. package/dist/sdk/invariant.d.ts +2 -0
  54. package/dist/sdk/invariant.d.ts.map +1 -0
  55. package/dist/sdk/invariant.js +31 -0
  56. package/dist/sdk/invariant.js.map +1 -0
  57. package/package.json +60 -0
  58. package/src/index.ts +2 -0
  59. package/src/resources/.keep +0 -0
  60. package/src/resources/graphql.schema.json +50830 -0
  61. package/src/resources/graphql.ts +7976 -0
  62. package/src/resources/schema.graphql +10393 -0
  63. package/src/sdk/Mutation.ts +15 -0
  64. package/src/sdk/Query.test.ts +40 -0
  65. package/src/sdk/Query.ts +65 -0
  66. package/src/sdk/Subscribe.ts +61 -0
  67. package/src/sdk/generated/fragment-masking.ts +66 -0
  68. package/src/sdk/generated/gql.ts +157 -0
  69. package/src/sdk/generated/graphql.ts +8215 -0
  70. package/src/sdk/generated/index.ts +2 -0
  71. package/src/sdk/graphql/CreateWebhooks.graphql +1145 -0
  72. package/src/sdk/graphql/DeleteWebhooks.graphql +5 -0
  73. package/src/sdk/graphql/FilterExchanges.graphql +23 -0
  74. package/src/sdk/graphql/FilterPairs.graphql +124 -0
  75. package/src/sdk/graphql/FilterTokens.graphql +129 -0
  76. package/src/sdk/graphql/GetBars.graphql +32 -0
  77. package/src/sdk/graphql/GetDetailedPairStats.graphql +941 -0
  78. package/src/sdk/graphql/GetNetworkStatus.graphql +7 -0
  79. package/src/sdk/graphql/GetNetworks.graphql +6 -0
  80. package/src/sdk/graphql/GetPairEvents.graphql +28 -0
  81. package/src/sdk/graphql/GetPrice.graphql +9 -0
  82. package/src/sdk/graphql/GetSparklines.graphql +10 -0
  83. package/src/sdk/graphql/GetSymbol.graphql +11 -0
  84. package/src/sdk/graphql/GetTokens.graphql +14 -0
  85. package/src/sdk/graphql/GetWebhooks.graphql +168 -0
  86. package/src/sdk/graphql/ListPairsForToken.graphql +105 -0
  87. package/src/sdk/graphql/ListTopTokens.graphql +48 -0
  88. package/src/sdk/graphql/OnBarsUpdated.graphql +183 -0
  89. package/src/sdk/graphql/OnDetailedStatsUpdated.graphql +324 -0
  90. package/src/sdk/graphql/OnEventsCreated.graphql +62 -0
  91. package/src/sdk/graphql/OnNftAssetsCreated.graphql +29 -0
  92. package/src/sdk/graphql/OnNftEventsCreated.graphql +83 -0
  93. package/src/sdk/graphql/OnPairMetadataUpdated.graphql +55 -0
  94. package/src/sdk/graphql/OnPriceUpdated.graphql +9 -0
  95. package/src/sdk/index.test.ts +78 -0
  96. package/src/sdk/index.ts +100 -0
  97. package/src/sdk/invariant.ts +34 -0
@@ -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
+ }