@xyo-network/api-graphql-plugin 5.3.1 → 5.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/api-graphql-plugin",
3
- "version": "5.3.1",
3
+ "version": "5.3.2",
4
4
  "description": "Typescript/Javascript Plugins for XYO Platform",
5
5
  "homepage": "https://xyo.network",
6
6
  "bugs": {
@@ -35,24 +35,25 @@
35
35
  "!**/*.spec.*",
36
36
  "!**/*.test.*"
37
37
  ],
38
- "dependencies": {
39
- "@xylabs/assert": "~5.0.64",
40
- "@xylabs/axios": "~5.0.64",
41
- "@xyo-network/abstract-witness": "~5.3.2",
42
- "@xyo-network/module-model": "~5.3.2",
43
- "@xyo-network/payload-model": "~5.3.2",
44
- "@xyo-network/payloadset-plugin": "~5.3.2",
45
- "@xyo-network/witness-model": "~5.3.2",
46
- "axios": "^1.13.4",
47
- "graphql": "~16.12.0"
48
- },
49
38
  "devDependencies": {
50
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
51
- "@xylabs/tsconfig": "~7.3.2",
52
- "@xylabs/vitest-extended": "~5.0.64",
53
- "ethers": "^6.16.0",
39
+ "@xylabs/sdk-js": "^5.0.90",
40
+ "@xylabs/ts-scripts-yarn3": "~7.5.10",
41
+ "@xylabs/tsconfig": "~7.5.10",
42
+ "@xylabs/vitest-extended": "~5.0.90",
43
+ "@xyo-network/abstract-witness": "~5.3.5",
44
+ "@xyo-network/module-model": "~5.3.5",
45
+ "@xyo-network/payload-model": "~5.3.5",
46
+ "@xyo-network/payloadset-plugin": "~5.3.5",
47
+ "@xyo-network/witness-model": "~5.3.5",
48
+ "axios": "^1.13.5",
49
+ "graphql": "~16.12.0",
54
50
  "typescript": "~5.9.3",
55
- "vitest": "~4.0.18"
51
+ "vitest": "~4.1.2",
52
+ "zod": "^4.3.6"
53
+ },
54
+ "peerDependencies": {
55
+ "@xylabs/sdk-js": "^5.0.79",
56
+ "zod": "^4.3.6"
56
57
  },
57
58
  "publishConfig": {
58
59
  "access": "public"
package/src/Witness.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { axiosJsonConfig } from '@xylabs/axios'
1
+ import { assertEx, axiosJsonConfig } from '@xylabs/sdk-js'
3
2
  import { AbstractWitness } from '@xyo-network/abstract-witness'
4
- import type { AnyConfigSchema } from '@xyo-network/module-model'
3
+ import { type AnyConfigSchema, creatableModule } from '@xyo-network/module-model'
5
4
  import type { Payload, Schema } from '@xyo-network/payload-model'
6
5
  import { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'
7
6
  import type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'
@@ -58,6 +57,7 @@ export type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<
58
57
 
59
58
  export const isGraphqlQuery = isPayloadOfSchemaType<GraphqlQuery>(GraphqlQuerySchema)
60
59
 
60
+ creatableModule()
61
61
  export class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<
62
62
  TParams,
63
63
  GraphqlQuery,
@@ -1,3 +0,0 @@
1
- import { ApiGraphqlWitness } from './Witness.ts';
2
- export declare const ApiGraphqlWitnessPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<ApiGraphqlWitness<import("./Witness.ts").ApiGraphqlWitnessParams>>;
3
- //# sourceMappingURL=Plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAA;AAEpE,eAAO,MAAM,uBAAuB,2IAQjC,CAAA"}
@@ -1,52 +0,0 @@
1
- import { AbstractWitness } from '@xyo-network/abstract-witness';
2
- import type { AnyConfigSchema } from '@xyo-network/module-model';
3
- import type { Payload, Schema } from '@xyo-network/payload-model';
4
- import type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
5
- import type { ExecutionResult } from 'graphql';
6
- export declare const ApiGraphqlWitnessConfigSchema: "network.xyo.api.witness.config" & {
7
- readonly __schema: true;
8
- };
9
- export type ApiGraphqlWitnessConfigSchema = typeof ApiGraphqlWitnessConfigSchema;
10
- export type ApiGraphqlWitnessConfig = WitnessConfig<{
11
- endpoint?: string;
12
- schema: ApiGraphqlWitnessConfigSchema;
13
- timeout?: number;
14
- }>;
15
- export type HttpHeaderValue = string | string[] | number | boolean | null;
16
- export interface HttpHeaders {
17
- [key: string]: HttpHeaderValue;
18
- }
19
- export interface ApiGraphqlWitnessParams extends WitnessParams<AnyConfigSchema<ApiGraphqlWitnessConfig>> {
20
- endpoint?: string;
21
- headers?: HttpHeaders;
22
- }
23
- export declare const GraphqlQuerySchema: "network.xyo.graphql.query" & {
24
- readonly __schema: true;
25
- };
26
- export type GraphqlQuerySchema = typeof GraphqlQuerySchema;
27
- export type GraphqlQuery = Payload<{
28
- query: string;
29
- variables: Record<string, unknown>;
30
- }, GraphqlQuerySchema>;
31
- export declare const GraphqlResultSchema: "network.xyo.graphql.result" & {
32
- readonly __schema: true;
33
- };
34
- export type GraphqlResultSchema = typeof GraphqlResultSchema;
35
- export type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Payload<{
36
- http?: {
37
- code?: string;
38
- ipAddress?: string;
39
- status?: number;
40
- };
41
- result?: ExecutionResult<TData, TExtensions>;
42
- }, GraphqlResultSchema>;
43
- export declare const isGraphqlQuery: (x?: unknown | null) => x is GraphqlQuery;
44
- export declare class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<TParams, GraphqlQuery, GraphqlResult> {
45
- static readonly configSchemas: Schema[];
46
- static readonly defaultConfigSchema: Schema;
47
- get endpoint(): string;
48
- get headers(): HttpHeaders | undefined;
49
- get timeout(): number | undefined;
50
- protected observeHandler(payloads?: GraphqlQuery[]): Promise<GraphqlResult[]>;
51
- }
52
- //# sourceMappingURL=Witness.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,eAAO,MAAM,6BAA6B;;CAAmD,CAAA;AAC7F,MAAM,MAAM,6BAA6B,GAAG,OAAO,6BAA6B,CAAA;AAEhF,MAAM,MAAM,uBAAuB,GAAG,aAAa,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,6BAA6B,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAEzE,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAC/B;AAED,MAAM,WAAW,uBAAwB,SAAQ,aAAa,CAC5D,eAAe,CAAC,uBAAuB,CAAC,CAAC;IAEzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED,eAAO,MAAM,kBAAkB;;CAA8C,CAAA;AAC7E,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAA;AAE1D,MAAM,MAAM,YAAY,GAAG,OAAO,CAChC;IACE,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC,EACD,kBAAkB,CACnB,CAAA;AAED,eAAO,MAAM,mBAAmB;;CAA+C,CAAA;AAC/E,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAA;AAE5D,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,OAAO,CACzG;IACE,IAAI,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,MAAM,CAAC,EAAE,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAA;CAC7C,EACD,mBAAmB,CACpB,CAAA;AAED,eAAO,MAAM,cAAc,2CAA0D,CAAA;AAErF,qBAAa,iBAAiB,CAAC,OAAO,SAAS,uBAAuB,GAAG,uBAAuB,CAAE,SAAQ,eAAe,CACvH,OAAO,EACP,YAAY,EACZ,aAAa,CACd;IACC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA0D;IAC1G,gBAAyB,mBAAmB,EAAE,MAAM,CAAgC;IAEpF,IAAI,QAAQ,WAEX;IAED,IAAI,OAAO,4BAEV;IAED,IAAI,OAAO,uBAEV;cAEwB,cAAc,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiB7F"}
@@ -1,3 +0,0 @@
1
- export { ApiGraphqlWitnessPlugin, ApiGraphqlWitnessPlugin as default } from './Plugin.ts';
2
- export * from './Witness.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA;AACzF,cAAc,cAAc,CAAA"}
@@ -1,64 +0,0 @@
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 { axiosJsonConfig } from "@xylabs/axios";
8
- import { AbstractWitness } from "@xyo-network/abstract-witness";
9
- import { asSchema, isPayloadOfSchemaType } from "@xyo-network/payload-model";
10
- import { Axios } from "axios";
11
- var ApiGraphqlWitnessConfigSchema = asSchema("network.xyo.api.witness.config", true);
12
- var GraphqlQuerySchema = asSchema("network.xyo.graphql.query", true);
13
- var GraphqlResultSchema = asSchema("network.xyo.graphql.result", true);
14
- var isGraphqlQuery = isPayloadOfSchemaType(GraphqlQuerySchema);
15
- var ApiGraphqlWitness = class extends AbstractWitness {
16
- static configSchemas = [...super.configSchemas, ApiGraphqlWitnessConfigSchema];
17
- static defaultConfigSchema = ApiGraphqlWitnessConfigSchema;
18
- get endpoint() {
19
- return assertEx(this.config.endpoint ?? this.params.endpoint, () => "No endpoint specified");
20
- }
21
- get headers() {
22
- return this.params.headers;
23
- }
24
- get timeout() {
25
- return this.config.timeout;
26
- }
27
- async observeHandler(payloads) {
28
- await this.started("throw");
29
- const queries = payloads?.filter(isGraphqlQuery) ?? [];
30
- const axios = new Axios(axiosJsonConfig({ headers: this.headers, timeout: this.timeout }));
31
- const observations = await Promise.all(
32
- queries.map(async ({ query, variables }) => {
33
- const httpResult = await axios.post(this.endpoint, { query, variables });
34
- const result = {
35
- http: { status: httpResult.status },
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
- export {
56
- ApiGraphqlWitness,
57
- ApiGraphqlWitnessConfigSchema,
58
- ApiGraphqlWitnessPlugin,
59
- GraphqlQuerySchema,
60
- GraphqlResultSchema,
61
- ApiGraphqlWitnessPlugin as default,
62
- isGraphqlQuery
63
- };
64
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Plugin.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { ApiGraphqlWitness, GraphqlQuerySchema } from './Witness.ts'\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 { axiosJsonConfig } from '@xylabs/axios'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { Axios } from 'axios'\nimport type { ExecutionResult } from 'graphql'\n\nexport const ApiGraphqlWitnessConfigSchema = asSchema('network.xyo.api.witness.config', true)\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 interface ApiGraphqlWitnessParams extends WitnessParams<\n AnyConfigSchema<ApiGraphqlWitnessConfig>>\n{\n endpoint?: string\n headers?: HttpHeaders\n}\n\nexport const GraphqlQuerySchema = asSchema('network.xyo.graphql.query', true)\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 = asSchema('network.xyo.graphql.result', true)\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 readonly configSchemas: Schema[] = [...super.configSchemas, ApiGraphqlWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 Axios(axiosJsonConfig({ 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: { status: httpResult.status },\n result: httpResult.data,\n schema: GraphqlResultSchema,\n }\n return result\n }),\n )\n return observations.flat()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,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ACrC;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;","names":[]}
@@ -1,3 +0,0 @@
1
- import { ApiGraphqlWitness } from './Witness.ts';
2
- export declare const ApiGraphqlWitnessPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<ApiGraphqlWitness<import("./Witness.ts").ApiGraphqlWitnessParams>>;
3
- //# sourceMappingURL=Plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAA;AAEpE,eAAO,MAAM,uBAAuB,2IAQjC,CAAA"}
@@ -1,52 +0,0 @@
1
- import { AbstractWitness } from '@xyo-network/abstract-witness';
2
- import type { AnyConfigSchema } from '@xyo-network/module-model';
3
- import type { Payload, Schema } from '@xyo-network/payload-model';
4
- import type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
5
- import type { ExecutionResult } from 'graphql';
6
- export declare const ApiGraphqlWitnessConfigSchema: "network.xyo.api.witness.config" & {
7
- readonly __schema: true;
8
- };
9
- export type ApiGraphqlWitnessConfigSchema = typeof ApiGraphqlWitnessConfigSchema;
10
- export type ApiGraphqlWitnessConfig = WitnessConfig<{
11
- endpoint?: string;
12
- schema: ApiGraphqlWitnessConfigSchema;
13
- timeout?: number;
14
- }>;
15
- export type HttpHeaderValue = string | string[] | number | boolean | null;
16
- export interface HttpHeaders {
17
- [key: string]: HttpHeaderValue;
18
- }
19
- export interface ApiGraphqlWitnessParams extends WitnessParams<AnyConfigSchema<ApiGraphqlWitnessConfig>> {
20
- endpoint?: string;
21
- headers?: HttpHeaders;
22
- }
23
- export declare const GraphqlQuerySchema: "network.xyo.graphql.query" & {
24
- readonly __schema: true;
25
- };
26
- export type GraphqlQuerySchema = typeof GraphqlQuerySchema;
27
- export type GraphqlQuery = Payload<{
28
- query: string;
29
- variables: Record<string, unknown>;
30
- }, GraphqlQuerySchema>;
31
- export declare const GraphqlResultSchema: "network.xyo.graphql.result" & {
32
- readonly __schema: true;
33
- };
34
- export type GraphqlResultSchema = typeof GraphqlResultSchema;
35
- export type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Payload<{
36
- http?: {
37
- code?: string;
38
- ipAddress?: string;
39
- status?: number;
40
- };
41
- result?: ExecutionResult<TData, TExtensions>;
42
- }, GraphqlResultSchema>;
43
- export declare const isGraphqlQuery: (x?: unknown | null) => x is GraphqlQuery;
44
- export declare class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<TParams, GraphqlQuery, GraphqlResult> {
45
- static readonly configSchemas: Schema[];
46
- static readonly defaultConfigSchema: Schema;
47
- get endpoint(): string;
48
- get headers(): HttpHeaders | undefined;
49
- get timeout(): number | undefined;
50
- protected observeHandler(payloads?: GraphqlQuery[]): Promise<GraphqlResult[]>;
51
- }
52
- //# sourceMappingURL=Witness.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,eAAO,MAAM,6BAA6B;;CAAmD,CAAA;AAC7F,MAAM,MAAM,6BAA6B,G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,CAAA;CAC7C,EACD,mBAAmB,CACpB,CAAA;AAED,eAAO,MAAM,cAAc,2CAA0D,CAAA;AAErF,qBAAa,iBAAiB,CAAC,OAAO,SAAS,uBAAuB,GAAG,uBAAuB,CAAE,SAAQ,eAAe,CACvH,OAAO,EACP,YAAY,EACZ,aAAa,CACd;IACC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAA0D;IAC1G,gBAAyB,mBAAmB,EAAE,MAAM,CAAgC;IAEpF,IAAI,QAAQ,WAEX;IAED,IAAI,OAAO,4BAEV;IAED,IAAI,OAAO,uBAEV;cAEwB,cAAc,CAAC,QAAQ,CAAC,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;CAiB7F"}
@@ -1,3 +0,0 @@
1
- export { ApiGraphqlWitnessPlugin, ApiGraphqlWitnessPlugin as default } from './Plugin.ts';
2
- export * from './Witness.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA;AACzF,cAAc,cAAc,CAAA"}
@@ -1,64 +0,0 @@
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 { axiosJsonConfig } from "@xylabs/axios";
8
- import { AbstractWitness } from "@xyo-network/abstract-witness";
9
- import { asSchema, isPayloadOfSchemaType } from "@xyo-network/payload-model";
10
- import { Axios } from "axios";
11
- var ApiGraphqlWitnessConfigSchema = asSchema("network.xyo.api.witness.config", true);
12
- var GraphqlQuerySchema = asSchema("network.xyo.graphql.query", true);
13
- var GraphqlResultSchema = asSchema("network.xyo.graphql.result", true);
14
- var isGraphqlQuery = isPayloadOfSchemaType(GraphqlQuerySchema);
15
- var ApiGraphqlWitness = class extends AbstractWitness {
16
- static configSchemas = [...super.configSchemas, ApiGraphqlWitnessConfigSchema];
17
- static defaultConfigSchema = ApiGraphqlWitnessConfigSchema;
18
- get endpoint() {
19
- return assertEx(this.config.endpoint ?? this.params.endpoint, () => "No endpoint specified");
20
- }
21
- get headers() {
22
- return this.params.headers;
23
- }
24
- get timeout() {
25
- return this.config.timeout;
26
- }
27
- async observeHandler(payloads) {
28
- await this.started("throw");
29
- const queries = payloads?.filter(isGraphqlQuery) ?? [];
30
- const axios = new Axios(axiosJsonConfig({ headers: this.headers, timeout: this.timeout }));
31
- const observations = await Promise.all(
32
- queries.map(async ({ query, variables }) => {
33
- const httpResult = await axios.post(this.endpoint, { query, variables });
34
- const result = {
35
- http: { status: httpResult.status },
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
- export {
56
- ApiGraphqlWitness,
57
- ApiGraphqlWitnessConfigSchema,
58
- ApiGraphqlWitnessPlugin,
59
- GraphqlQuerySchema,
60
- GraphqlResultSchema,
61
- ApiGraphqlWitnessPlugin as default,
62
- isGraphqlQuery
63
- };
64
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Plugin.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { ApiGraphqlWitness, GraphqlQuerySchema } from './Witness.ts'\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 { axiosJsonConfig } from '@xylabs/axios'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { Axios } from 'axios'\nimport type { ExecutionResult } from 'graphql'\n\nexport const ApiGraphqlWitnessConfigSchema = asSchema('network.xyo.api.witness.config', true)\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 interface ApiGraphqlWitnessParams extends WitnessParams<\n AnyConfigSchema<ApiGraphqlWitnessConfig>>\n{\n endpoint?: string\n headers?: HttpHeaders\n}\n\nexport const GraphqlQuerySchema = asSchema('network.xyo.graphql.query', true)\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 = asSchema('network.xyo.graphql.result', true)\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 readonly configSchemas: Schema[] = [...super.configSchemas, ApiGraphqlWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 Axios(axiosJsonConfig({ 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: { status: httpResult.status },\n result: httpResult.data,\n schema: GraphqlResultSchema,\n }\n return result\n }),\n )\n return observations.flat()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACD9C,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAGhC,SAAS,UAAU,6BAA6B;AAEhD,SAAS,aAAa;AAGf,IAAM,gCAAgC,SAAS,kCAAkC,IAAI;AAsBrF,IAAM,qBAAqB,SAAS,6BAA6B,IAAI;AAWrE,IAAM,sBAAsB,SAAS,8BAA8B,IAAI;AAevE,IAAM,iBAAiB,sBAAoC,kBAAkB;AAE7E,IAAM,oBAAN,cAAmG,gBAIxG;AAAA,EACA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,6BAA6B;AAAA,EACzG,OAAyB,sBAA8B;AAAA,EAEvD,IAAI,WAAW;AACb,WAAO,SAAS,KAAK,OAAO,YAAY,KAAK,OAAO,UAAU,MAAM,uBAAuB;AAAA,EAC7F;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,UAAU,UAAU,OAAO,cAAc,KAAK,CAAC;AACrD,UAAM,QAAQ,IAAI,MAAM,gBAAgB,EAAE,SAAS,KAAK,SAAS,SAAS,KAAK,QAAQ,CAAC,CAAC;AACzF,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,EAAE,QAAQ,WAAW,OAAO;AAAA,UAClC,QAAQ,WAAW;AAAA,UACnB,QAAQ;AAAA,QACV;AACA,eAAO;AAAA,MACT,CAAC;AAAA,IACH;AACA,WAAO,aAAa,KAAK;AAAA,EAC3B;AACF;;;AD5FO,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;","names":[]}
@@ -1,3 +0,0 @@
1
- import { ApiGraphqlWitness } from './Witness.ts';
2
- export declare const ApiGraphqlWitnessPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<ApiGraphqlWitness<import("./Witness.ts").ApiGraphqlWitnessParams>>;
3
- //# sourceMappingURL=Plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAA;AAEpE,eAAO,MAAM,uBAAuB,2IAQjC,CAAA"}
@@ -1,52 +0,0 @@
1
- import { AbstractWitness } from '@xyo-network/abstract-witness';
2
- import type { AnyConfigSchema } from '@xyo-network/module-model';
3
- import type { Payload, Schema } from '@xyo-network/payload-model';
4
- import type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model';
5
- import type { ExecutionResult } from 'graphql';
6
- export declare const ApiGraphqlWitnessConfigSchema: "network.xyo.api.witness.config" & {
7
- readonly __schema: true;
8
- };
9
- export type ApiGraphqlWitnessConfigSchema = typeof ApiGraphqlWitnessConfigSchema;
10
- export type ApiGraphqlWitnessConfig = WitnessConfig<{
11
- endpoint?: string;
12
- schema: ApiGraphqlWitnessConfigSchema;
13
- timeout?: number;
14
- }>;
15
- export type HttpHeaderValue = string | string[] | number | boolean | null;
16
- export interface HttpHeaders {
17
- [key: string]: HttpHeaderValue;
18
- }
19
- export interface ApiGraphqlWitnessParams extends WitnessParams<AnyConfigSchema<ApiGraphqlWitnessConfig>> {
20
- endpoint?: string;
21
- headers?: HttpHeaders;
22
- }
23
- export declare const GraphqlQuerySchema: "network.xyo.graphql.query" & {
24
- readonly __schema: true;
25
- };
26
- export type GraphqlQuerySchema = typeof GraphqlQuerySchema;
27
- export type GraphqlQuery = Payload<{
28
- query: string;
29
- variables: Record<string, unknown>;
30
- }, GraphqlQuerySchema>;
31
- export declare const GraphqlResultSchema: "network.xyo.graphql.result" & {
32
- readonly __schema: true;
33
- };
34
- export type GraphqlResultSchema = typeof GraphqlResultSchema;
35
- export type GraphqlResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Payload<{
36
- http?: {
37
- code?: string;
38
- ipAddress?: string;
39
- status?: number;
40
- };
41
- result?: ExecutionResult<TData, TExtensions>;
42
- }, GraphqlResultSchema>;
43
- export declare const isGraphqlQuery: (x?: unknown | null) => x is GraphqlQuery;
44
- export declare class ApiGraphqlWitness<TParams extends ApiGraphqlWitnessParams = ApiGraphqlWitnessParams> extends AbstractWitness<TParams, GraphqlQuery, GraphqlResult> {
45
- static readonly configSchemas: Schema[];
46
- static readonly defaultConfigSchema: Schema;
47
- get endpoint(): string;
48
- get headers(): HttpHeaders | undefined;
49
- get timeout(): number | undefined;
50
- protected observeHandler(payloads?: GraphqlQuery[]): Promise<GraphqlResult[]>;
51
- }
52
- //# sourceMappingURL=Witness.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAEjE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,eAAO,MAAM,6BAA6B;;CAAmD,CAAA;AAC7F,MAAM,MAAM,6BAA6B,GAAG,OAAO,6BAA6B,CAAA;AAEhF,MAAM,MAAM,uBAAuB,GAAG,aAAa,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,6BAA6B,CAAA;IACrC,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAC,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAEzE,MAAM,WAAW,WAAW;IAC1B,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAA;CAC/B;AAED,MAAM,WAAW,uBAAwB,SAAQ,aAAa,CAC5D,eAAe,CAAC,uBAAuB,CAAC,CAAC;IAEzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AAED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ts';
2
- export * from './Witness.ts';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,IAAI,OAAO,EAAE,MAAM,aAAa,CAAA;AACzF,cAAc,cAAc,CAAA"}
@@ -1,64 +0,0 @@
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 { axiosJsonConfig } from "@xylabs/axios";
8
- import { AbstractWitness } from "@xyo-network/abstract-witness";
9
- import { asSchema, isPayloadOfSchemaType } from "@xyo-network/payload-model";
10
- import { Axios } from "axios";
11
- var ApiGraphqlWitnessConfigSchema = asSchema("network.xyo.api.witness.config", true);
12
- var GraphqlQuerySchema = asSchema("network.xyo.graphql.query", true);
13
- var GraphqlResultSchema = asSchema("network.xyo.graphql.result", true);
14
- var isGraphqlQuery = isPayloadOfSchemaType(GraphqlQuerySchema);
15
- var ApiGraphqlWitness = class extends AbstractWitness {
16
- static configSchemas = [...super.configSchemas, ApiGraphqlWitnessConfigSchema];
17
- static defaultConfigSchema = ApiGraphqlWitnessConfigSchema;
18
- get endpoint() {
19
- return assertEx(this.config.endpoint ?? this.params.endpoint, () => "No endpoint specified");
20
- }
21
- get headers() {
22
- return this.params.headers;
23
- }
24
- get timeout() {
25
- return this.config.timeout;
26
- }
27
- async observeHandler(payloads) {
28
- await this.started("throw");
29
- const queries = payloads?.filter(isGraphqlQuery) ?? [];
30
- const axios = new Axios(axiosJsonConfig({ headers: this.headers, timeout: this.timeout }));
31
- const observations = await Promise.all(
32
- queries.map(async ({ query, variables }) => {
33
- const httpResult = await axios.post(this.endpoint, { query, variables });
34
- const result = {
35
- http: { status: httpResult.status },
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
- export {
56
- ApiGraphqlWitness,
57
- ApiGraphqlWitnessConfigSchema,
58
- ApiGraphqlWitnessPlugin,
59
- GraphqlQuerySchema,
60
- GraphqlResultSchema,
61
- ApiGraphqlWitnessPlugin as default,
62
- isGraphqlQuery
63
- };
64
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/Plugin.ts","../../src/Witness.ts"],"sourcesContent":["import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\n\nimport { ApiGraphqlWitness, GraphqlQuerySchema } from './Witness.ts'\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 { axiosJsonConfig } from '@xylabs/axios'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport { asSchema, isPayloadOfSchemaType } from '@xyo-network/payload-model'\nimport type { WitnessConfig, WitnessParams } from '@xyo-network/witness-model'\nimport { Axios } from 'axios'\nimport type { ExecutionResult } from 'graphql'\n\nexport const ApiGraphqlWitnessConfigSchema = asSchema('network.xyo.api.witness.config', true)\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 interface ApiGraphqlWitnessParams extends WitnessParams<\n AnyConfigSchema<ApiGraphqlWitnessConfig>>\n{\n endpoint?: string\n headers?: HttpHeaders\n}\n\nexport const GraphqlQuerySchema = asSchema('network.xyo.graphql.query', true)\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 = asSchema('network.xyo.graphql.result', true)\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 readonly configSchemas: Schema[] = [...super.configSchemas, ApiGraphqlWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = 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 Axios(axiosJsonConfig({ 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: { status: httpResult.status },\n result: httpResult.data,\n schema: GraphqlResultSchema,\n }\n return result\n }),\n )\n return observations.flat()\n }\n}\n"],"mappings":";AAAA,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;;;ACD9C,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAGhC,SAAS,UAAU,6BAA6B;AAEhD,SAAS,aAAa;AAGf,IAAM,gCAAgC,SAAS,kCAAkC,IAAI;AAsBrF,IAAM,qBAAqB,SAAS,6BAA6B,IAAI;AAWrE,IAAM,sBAAsB,SAAS,8BAA8B,IAAI;AAevE,IAAM,iBAAiB,sBAAoC,kBAAkB;AAE7E,IAAM,oBAAN,cAAmG,gBAIxG;AAAA,EACA,OAAyB,gBAA0B,CAAC,GAAG,MAAM,eAAe,6BAA6B;AAAA,EACzG,OAAyB,sBAA8B;AAAA,EAEvD,IAAI,WAAW;AACb,WAAO,SAAS,KAAK,OAAO,YAAY,KAAK,OAAO,UAAU,MAAM,uBAAuB;AAAA,EAC7F;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,UAAU,UAAU,OAAO,cAAc,KAAK,CAAC;AACrD,UAAM,QAAQ,IAAI,MAAM,gBAAgB,EAAE,SAAS,KAAK,SAAS,SAAS,KAAK,QAAQ,CAAC,CAAC;AACzF,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,EAAE,QAAQ,WAAW,OAAO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