@xyo-network/api-graphql-plugin 2.78.3
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/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/browser/Plugin.d.cts +59 -0
- package/dist/browser/Plugin.d.cts.map +1 -0
- package/dist/browser/Plugin.d.mts +59 -0
- package/dist/browser/Plugin.d.mts.map +1 -0
- package/dist/browser/Plugin.d.ts +59 -0
- package/dist/browser/Plugin.d.ts.map +1 -0
- package/dist/browser/Witness.d.cts +52 -0
- package/dist/browser/Witness.d.cts.map +1 -0
- package/dist/browser/Witness.d.mts +52 -0
- package/dist/browser/Witness.d.mts.map +1 -0
- package/dist/browser/Witness.d.ts +52 -0
- package/dist/browser/Witness.d.ts.map +1 -0
- package/dist/browser/index.cjs +90 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +5 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.d.mts +5 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +67 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/node/Plugin.d.cts +59 -0
- package/dist/node/Plugin.d.cts.map +1 -0
- package/dist/node/Plugin.d.mts +59 -0
- package/dist/node/Plugin.d.mts.map +1 -0
- package/dist/node/Plugin.d.ts +59 -0
- package/dist/node/Plugin.d.ts.map +1 -0
- package/dist/node/Witness.d.cts +52 -0
- package/dist/node/Witness.d.cts.map +1 -0
- package/dist/node/Witness.d.mts +52 -0
- package/dist/node/Witness.d.mts.map +1 -0
- package/dist/node/Witness.d.ts +52 -0
- package/dist/node/Witness.d.ts.map +1 -0
- package/dist/node/index.d.cts +5 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +5 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +99 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/index.mjs +67 -0
- package/dist/node/index.mjs.map +1 -0
- package/package.json +73 -0
- package/src/Plugin.ts +14 -0
- package/src/Witness.ts +99 -0
- package/src/index.ts +8 -0
- package/typedoc.json +5 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// src/Plugin.ts
|
|
2
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
3
|
+
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
4
|
+
|
|
5
|
+
// src/Witness.ts
|
|
6
|
+
import { assertEx } from "@xylabs/assert";
|
|
7
|
+
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
8
|
+
import { AxiosJson } from "@xyo-network/axios";
|
|
9
|
+
import { isPayloadOfSchemaType } from "@xyo-network/payload-model";
|
|
10
|
+
var ApiGraphqlWitnessConfigSchema = "network.xyo.api.witness.config";
|
|
11
|
+
var GraphqlQuerySchema = "network.xyo.graphql.query";
|
|
12
|
+
var GraphqlResultSchema = "network.xyo.graphql.result";
|
|
13
|
+
var isGraphqlQuery = isPayloadOfSchemaType(GraphqlQuerySchema);
|
|
14
|
+
var ApiGraphqlWitness = class extends AbstractWitness {
|
|
15
|
+
static configSchemas = [ApiGraphqlWitnessConfigSchema];
|
|
16
|
+
get endpoint() {
|
|
17
|
+
return assertEx(this.config.endpoint ?? this.params.endpoint, "No endpoint specified");
|
|
18
|
+
}
|
|
19
|
+
get headers() {
|
|
20
|
+
return this.params.headers;
|
|
21
|
+
}
|
|
22
|
+
get timeout() {
|
|
23
|
+
return this.config.timeout;
|
|
24
|
+
}
|
|
25
|
+
async observeHandler(payloads) {
|
|
26
|
+
await this.started("throw");
|
|
27
|
+
const queries = (payloads == null ? void 0 : payloads.filter(isGraphqlQuery)) ?? [];
|
|
28
|
+
const axios = new AxiosJson({ headers: this.headers, timeout: this.timeout });
|
|
29
|
+
const observations = await Promise.all(
|
|
30
|
+
queries.map(async ({ query, variables }) => {
|
|
31
|
+
const httpResult = await axios.post(this.endpoint, { query, variables });
|
|
32
|
+
const result = {
|
|
33
|
+
http: {
|
|
34
|
+
status: httpResult.status
|
|
35
|
+
},
|
|
36
|
+
result: httpResult.data,
|
|
37
|
+
schema: GraphqlResultSchema
|
|
38
|
+
};
|
|
39
|
+
return result;
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
return observations.flat();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/Plugin.ts
|
|
47
|
+
var ApiGraphqlWitnessPlugin = () => createPayloadSetWitnessPlugin(
|
|
48
|
+
{ required: { [GraphqlQuerySchema]: 1 }, schema: PayloadSetSchema },
|
|
49
|
+
{
|
|
50
|
+
witness: async (params) => {
|
|
51
|
+
return await ApiGraphqlWitness.create(params);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// src/index.ts
|
|
57
|
+
var src_default = ApiGraphqlWitnessPlugin;
|
|
58
|
+
export {
|
|
59
|
+
ApiGraphqlWitness,
|
|
60
|
+
ApiGraphqlWitnessConfigSchema,
|
|
61
|
+
ApiGraphqlWitnessPlugin,
|
|
62
|
+
GraphqlQuerySchema,
|
|
63
|
+
GraphqlResultSchema,
|
|
64
|
+
src_default as default,
|
|
65
|
+
isGraphqlQuery
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Plugin.ts","../../src/Witness.ts","../../src/index.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { ApiGraphqlWitness, GraphqlQuerySchema } from './Witness'\n\nexport const ApiGraphqlWitnessPlugin = () =>\n createPayloadSetWitnessPlugin<ApiGraphqlWitness>(\n { required: { [GraphqlQuerySchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n return await ApiGraphqlWitness.create(params)\n },\n },\n )\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport { AxiosJson } from '@xyo-network/axios'\nimport { NftCollectionWitnessConfigSchema } from '@xyo-network/crypto-nft-collection-payload-plugin'\nimport { AnyConfigSchema } from '@xyo-network/module-model'\nimport { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'\nimport { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport type { ExecutionResult } from 'graphql'\n\nexport const ApiGraphqlWitnessConfigSchema = 'network.xyo.api.witness.config'\nexport type ApiGraphqlWitnessConfigSchema = typeof ApiGraphqlWitnessConfigSchema\n\nexport type ApiGraphqlWitnessConfig = WitnessConfig<{\n endpoint?: string\n schema: ApiGraphqlWitnessConfigSchema\n timeout?: number\n}>\n\nexport type HttpHeaderValue = string | string[] | number | boolean | null\n\nexport interface HttpHeaders {\n [key: string]: HttpHeaderValue\n}\n\nexport type ApiGraphqlWitnessParams = WitnessParams<\n AnyConfigSchema<ApiGraphqlWitnessConfig>,\n {\n endpoint?: string\n headers?: HttpHeaders\n }\n>\n\nexport const GraphqlQuerySchema = 'network.xyo.graphql.query'\nexport type GraphqlQuerySchema = typeof GraphqlQuerySchema\n\nexport type GraphqlQuery = Payload<\n {\n query: string\n variables: Record<string, unknown>\n },\n GraphqlQuerySchema\n>\n\nexport const GraphqlResultSchema = 'network.xyo.graphql.result'\nexport type GraphqlResultSchema = typeof GraphqlResultSchema\n\nexport type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Payload<\n {\n http?: {\n code?: string\n ipAddress?: string\n status?: number\n }\n result?: ExecutionResult<TData, TExtensions>\n },\n GraphqlResultSchema\n>\n\nexport const isGraphqlQuery = isPayloadOfSchemaType<GraphqlQuery>(GraphqlQuerySchema)\n\nexport class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<\n TParams,\n GraphqlQuery,\n GraphqlResult\n> {\n static override configSchemas = [ApiGraphqlWitnessConfigSchema]\n\n get endpoint() {\n return assertEx(this.config.endpoint ?? this.params.endpoint, 'No endpoint specified')\n }\n\n get headers() {\n return this.params.headers\n }\n\n get timeout() {\n return this.config.timeout\n }\n\n protected override async observeHandler(payloads?: GraphqlQuery[]): Promise<GraphqlResult[]> {\n await this.started('throw')\n const queries = payloads?.filter(isGraphqlQuery) ?? []\n const axios = new AxiosJson({ headers: this.headers, timeout: this.timeout })\n const observations = await Promise.all(\n queries.map(async ({ query, variables }) => {\n const httpResult = await axios.post(this.endpoint, { query, variables })\n const result: GraphqlResult = {\n http: {\n status: httpResult.status,\n },\n result: httpResult.data,\n schema: GraphqlResultSchema,\n }\n return result\n }),\n )\n return observations.flat()\n }\n}\n","import { ApiGraphqlWitnessPlugin } from './Plugin'\n\nexport * from './Witness'\n\nexport { ApiGraphqlWitnessPlugin }\n\n// eslint-disable-next-line import/no-default-export\nexport default ApiGraphqlWitnessPlugin\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACD9C,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAG1B,SAAS,6BAAsC;AAIxC,IAAM,gCAAgC;AAuBtC,IAAM,qBAAqB;AAW3B,IAAM,sBAAsB;AAe5B,IAAM,iBAAiB,sBAAoC,kBAAkB;AAE7E,IAAM,oBAAN,cAAmG,gBAIxG;AAAA,EACA,OAAgB,gBAAgB,CAAC,6BAA6B;AAAA,EAE9D,IAAI,WAAW;AACb,WAAO,SAAS,KAAK,OAAO,YAAY,KAAK,OAAO,UAAU,uBAAuB;AAAA,EACvF;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,UAAU;AACZ,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,MAAyB,eAAe,UAAqD;AAC3F,UAAM,KAAK,QAAQ,OAAO;AAC1B,UAAM,WAAU,qCAAU,OAAO,oBAAmB,CAAC;AACrD,UAAM,QAAQ,IAAI,UAAU,EAAE,SAAS,KAAK,SAAS,SAAS,KAAK,QAAQ,CAAC;AAC5E,UAAM,eAAe,MAAM,QAAQ;AAAA,MACjC,QAAQ,IAAI,OAAO,EAAE,OAAO,UAAU,MAAM;AAC1C,cAAM,aAAa,MAAM,MAAM,KAAK,KAAK,UAAU,EAAE,OAAO,UAAU,CAAC;AACvE,cAAM,SAAwB;AAAA,UAC5B,MAAM;AAAA,YACJ,QAAQ,WAAW;AAAA,UACrB;AAAA,UACA,QAAQ,WAAW;AAAA,UACnB,QAAQ;AAAA,QACV;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AACA,WAAO,aAAa,KAAK;AAAA,EAC3B;AACF;;;AD7FO,IAAM,0BAA0B,MACrC;AAAA,EACE,EAAE,UAAU,EAAE,CAAC,kBAAkB,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EAClE;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,aAAO,MAAM,kBAAkB,OAAO,MAAM;AAAA,IAC9C;AAAA,EACF;AACF;;;AENF,IAAO,cAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/api-graphql-plugin",
|
|
3
|
+
"author": {
|
|
4
|
+
"email": "support@xyo.network",
|
|
5
|
+
"name": "XYO Development Team",
|
|
6
|
+
"url": "https://xyo.network"
|
|
7
|
+
},
|
|
8
|
+
"bugs": {
|
|
9
|
+
"email": "support@xyo.network",
|
|
10
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js/issues"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@xylabs/assert": "^2.13.3",
|
|
14
|
+
"@xyo-network/abstract-witness": "~2.78.3",
|
|
15
|
+
"@xyo-network/axios": "~2.78.3",
|
|
16
|
+
"@xyo-network/crypto-nft-collection-payload-plugin": "~2.78.3",
|
|
17
|
+
"@xyo-network/module-model": "~2.78.3",
|
|
18
|
+
"@xyo-network/payload-model": "~2.78.3",
|
|
19
|
+
"@xyo-network/payloadset-plugin": "~2.78.3",
|
|
20
|
+
"@xyo-network/witness-model": "~2.78.3"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@xylabs/jest-helpers": "^2.13.3",
|
|
24
|
+
"@xylabs/ts-scripts-yarn3": "^3.1.13",
|
|
25
|
+
"@xylabs/tsconfig": "^3.1.13",
|
|
26
|
+
"@xyo-network/account": "~2.78.3",
|
|
27
|
+
"ethers": "^5.7.2",
|
|
28
|
+
"graphql": "^16.8.1",
|
|
29
|
+
"jest": "^29.7.0",
|
|
30
|
+
"typescript": "^5.2.2"
|
|
31
|
+
},
|
|
32
|
+
"description": "Primary SDK for using XYO Protocol 2.0",
|
|
33
|
+
"docs": "dist/docs.json",
|
|
34
|
+
"types": "dist/node/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"browser": {
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/browser/index.d.cts",
|
|
40
|
+
"default": "./dist/browser/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/browser/index.d.mts",
|
|
44
|
+
"default": "./dist/browser/index.js"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"node": {
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/node/index.d.ts",
|
|
50
|
+
"default": "./dist/node/index.js"
|
|
51
|
+
},
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/node/index.d.mts",
|
|
54
|
+
"default": "./dist/node/index.mjs"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./package.json": "./package.json"
|
|
59
|
+
},
|
|
60
|
+
"main": "dist/node/index.js",
|
|
61
|
+
"module": "dist/node/index.mjs",
|
|
62
|
+
"homepage": "https://xyo.network",
|
|
63
|
+
"license": "LGPL-3.0-only",
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
},
|
|
67
|
+
"repository": {
|
|
68
|
+
"type": "git",
|
|
69
|
+
"url": "https://github.com/XYOracleNetwork/sdk-xyo-client-js.git"
|
|
70
|
+
},
|
|
71
|
+
"sideEffects": false,
|
|
72
|
+
"version": "2.78.3"
|
|
73
|
+
}
|
package/src/Plugin.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PayloadSetSchema } from '@xyo-network/payload-model'
|
|
2
|
+
import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
|
|
3
|
+
|
|
4
|
+
import { ApiGraphqlWitness, GraphqlQuerySchema } from './Witness'
|
|
5
|
+
|
|
6
|
+
export const ApiGraphqlWitnessPlugin = () =>
|
|
7
|
+
createPayloadSetWitnessPlugin<ApiGraphqlWitness>(
|
|
8
|
+
{ required: { [GraphqlQuerySchema]: 1 }, schema: PayloadSetSchema },
|
|
9
|
+
{
|
|
10
|
+
witness: async (params) => {
|
|
11
|
+
return await ApiGraphqlWitness.create(params)
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
)
|
package/src/Witness.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { AbstractWitness } from '@xyo-network/abstract-witness'
|
|
3
|
+
import { AxiosJson } from '@xyo-network/axios'
|
|
4
|
+
import { NftCollectionWitnessConfigSchema } from '@xyo-network/crypto-nft-collection-payload-plugin'
|
|
5
|
+
import { AnyConfigSchema } from '@xyo-network/module-model'
|
|
6
|
+
import { isPayloadOfSchemaType, Payload } from '@xyo-network/payload-model'
|
|
7
|
+
import { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'
|
|
8
|
+
import type { ExecutionResult } from 'graphql'
|
|
9
|
+
|
|
10
|
+
export const ApiGraphqlWitnessConfigSchema = 'network.xyo.api.witness.config'
|
|
11
|
+
export type ApiGraphqlWitnessConfigSchema = typeof ApiGraphqlWitnessConfigSchema
|
|
12
|
+
|
|
13
|
+
export type ApiGraphqlWitnessConfig = WitnessConfig<{
|
|
14
|
+
endpoint?: string
|
|
15
|
+
schema: ApiGraphqlWitnessConfigSchema
|
|
16
|
+
timeout?: number
|
|
17
|
+
}>
|
|
18
|
+
|
|
19
|
+
export type HttpHeaderValue = string | string[] | number | boolean | null
|
|
20
|
+
|
|
21
|
+
export interface HttpHeaders {
|
|
22
|
+
[key: string]: HttpHeaderValue
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ApiGraphqlWitnessParams = WitnessParams<
|
|
26
|
+
AnyConfigSchema<ApiGraphqlWitnessConfig>,
|
|
27
|
+
{
|
|
28
|
+
endpoint?: string
|
|
29
|
+
headers?: HttpHeaders
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
|
|
33
|
+
export const GraphqlQuerySchema = 'network.xyo.graphql.query'
|
|
34
|
+
export type GraphqlQuerySchema = typeof GraphqlQuerySchema
|
|
35
|
+
|
|
36
|
+
export type GraphqlQuery = Payload<
|
|
37
|
+
{
|
|
38
|
+
query: string
|
|
39
|
+
variables: Record<string, unknown>
|
|
40
|
+
},
|
|
41
|
+
GraphqlQuerySchema
|
|
42
|
+
>
|
|
43
|
+
|
|
44
|
+
export const GraphqlResultSchema = 'network.xyo.graphql.result'
|
|
45
|
+
export type GraphqlResultSchema = typeof GraphqlResultSchema
|
|
46
|
+
|
|
47
|
+
export type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Payload<
|
|
48
|
+
{
|
|
49
|
+
http?: {
|
|
50
|
+
code?: string
|
|
51
|
+
ipAddress?: string
|
|
52
|
+
status?: number
|
|
53
|
+
}
|
|
54
|
+
result?: ExecutionResult<TData, TExtensions>
|
|
55
|
+
},
|
|
56
|
+
GraphqlResultSchema
|
|
57
|
+
>
|
|
58
|
+
|
|
59
|
+
export const isGraphqlQuery = isPayloadOfSchemaType<GraphqlQuery>(GraphqlQuerySchema)
|
|
60
|
+
|
|
61
|
+
export class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<
|
|
62
|
+
TParams,
|
|
63
|
+
GraphqlQuery,
|
|
64
|
+
GraphqlResult
|
|
65
|
+
> {
|
|
66
|
+
static override configSchemas = [ApiGraphqlWitnessConfigSchema]
|
|
67
|
+
|
|
68
|
+
get endpoint() {
|
|
69
|
+
return assertEx(this.config.endpoint ?? this.params.endpoint, 'No endpoint specified')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get headers() {
|
|
73
|
+
return this.params.headers
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get timeout() {
|
|
77
|
+
return this.config.timeout
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected override async observeHandler(payloads?: GraphqlQuery[]): Promise<GraphqlResult[]> {
|
|
81
|
+
await this.started('throw')
|
|
82
|
+
const queries = payloads?.filter(isGraphqlQuery) ?? []
|
|
83
|
+
const axios = new AxiosJson({ headers: this.headers, timeout: this.timeout })
|
|
84
|
+
const observations = await Promise.all(
|
|
85
|
+
queries.map(async ({ query, variables }) => {
|
|
86
|
+
const httpResult = await axios.post(this.endpoint, { query, variables })
|
|
87
|
+
const result: GraphqlResult = {
|
|
88
|
+
http: {
|
|
89
|
+
status: httpResult.status,
|
|
90
|
+
},
|
|
91
|
+
result: httpResult.data,
|
|
92
|
+
schema: GraphqlResultSchema,
|
|
93
|
+
}
|
|
94
|
+
return result
|
|
95
|
+
}),
|
|
96
|
+
)
|
|
97
|
+
return observations.flat()
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/index.ts
ADDED