antelopeql 3.0.0-alpha.4 → 3.0.0-alpha.6

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.
@@ -0,0 +1,52 @@
1
+ // antelopeql.d.ts
2
+
3
+ export function AntelopeQL(
4
+ params: AntelopeQLParams
5
+ ): Promise<{ data: any; errors: any[] }>;
6
+
7
+ export interface AntelopeQLParams {
8
+ query: string;
9
+ variableValues?: Record<string, any>;
10
+ operationName?: string;
11
+ signTransaction?: boolean;
12
+ contracts?: string[];
13
+ ABIs?: ABI[];
14
+ rpc_url?: URL | string;
15
+ headers?: HeadersInit;
16
+ signal?: AbortSignal;
17
+ }
18
+
19
+ export interface Types {
20
+ new_type_name: string;
21
+ type: string;
22
+ }
23
+
24
+ export interface Field {
25
+ name: string;
26
+ type: string;
27
+ }
28
+
29
+ export interface Struct {
30
+ name: string;
31
+ base: string;
32
+ fields: Field[];
33
+ }
34
+
35
+ export interface Action {
36
+ name: string;
37
+ type: string;
38
+ ricardian_contract?: string;
39
+ }
40
+
41
+ export interface Table {
42
+ name: string;
43
+ index_type: string;
44
+ type: string;
45
+ }
46
+
47
+ export interface ABI {
48
+ types: Types[];
49
+ structs: Struct[];
50
+ actions: Action[];
51
+ tables: Table[];
52
+ }
@@ -31,7 +31,7 @@ function handleBaseFields(base, structs) {
31
31
  * @param {Object} structs ABI structs
32
32
  * @returns {Object} Struct AST that will be consumed by [eosio_abi_to_graphql_ast](./eosio_abi_to_graphql_ast.mjs).
33
33
  */
34
- function handleStructs(structs) {
34
+ function handleStructs(structs, type_alias) {
35
35
  let graphql_ast_structs = {};
36
36
 
37
37
  for (const struct of structs) {
@@ -47,6 +47,8 @@ function handleStructs(structs) {
47
47
  const variant = !!field.type.match(/@/gmu);
48
48
  const list = !!field.type.match(/\[\]/gmu);
49
49
  let type = field.type.replace(/[[\]?$@]/gmu, "");
50
+ type = type_alias[type] ?? type;
51
+
50
52
  const object = !eosio_types[type];
51
53
  ast_fields[i] = {
52
54
  name: field.name,
@@ -67,6 +69,7 @@ function handleStructs(structs) {
67
69
  */
68
70
  export function eosio_abi_to_graphql_ast(abi) {
69
71
  const { types, variants, structs } = abi;
72
+ const type_alias = {};
70
73
  const new_structs = structs;
71
74
 
72
75
  if (variants?.length)
@@ -78,14 +81,35 @@ export function eosio_abi_to_graphql_ast(abi) {
78
81
  });
79
82
 
80
83
  if (types?.length) {
81
- for (const { type: real_type, new_type_name } of types)
84
+ for (const { type: real_type, new_type_name } of types) {
85
+ if (eosio_types[real_type]) {
86
+ type_alias[new_type_name] = real_type;
87
+ continue;
88
+ }
89
+
90
+ if (real_type.endsWith("[]")) {
91
+ new_structs.push({
92
+ name: new_type_name,
93
+ base: "",
94
+ fields: [
95
+ {
96
+ name: real_type.replace("[]", ""),
97
+ type: real_type
98
+ }
99
+ ]
100
+ });
101
+
102
+ continue;
103
+ }
104
+
82
105
  new_structs.push({
83
106
  ...new_structs.find((x) => x.name == real_type),
84
107
  name: new_type_name
85
108
  });
109
+ }
86
110
  }
87
111
 
88
- const structs_ast = handleStructs(new_structs);
112
+ const structs_ast = handleStructs(new_structs, type_alias);
89
113
 
90
114
  return Object.freeze(structs_ast);
91
115
  }
@@ -1,18 +1,11 @@
1
1
  import {
2
+ GraphQLBoolean,
2
3
  GraphQLEnumType,
3
4
  GraphQLInputObjectType,
4
5
  GraphQLInt,
5
6
  GraphQLString
6
7
  } from "graphql";
7
8
 
8
- const index_position_enum_type = new GraphQLEnumType({
9
- name: "index_position_enum_type",
10
- values: {
11
- primary: { value: "primary" },
12
- secondary: { value: "secondary" }
13
- }
14
- });
15
-
16
9
  const key_type_enum_type = new GraphQLEnumType({
17
10
  name: "key_type_enum",
18
11
  description: `Primary only supports i64. All others support i64, i128, i256, float64, float128, ripemd160, sha256.`,
@@ -48,9 +41,9 @@ const query_arg_fields = new GraphQLInputObjectType({
48
41
  defaultValue: ""
49
42
  },
50
43
  index_position: {
51
- type: index_position_enum_type,
52
- description: "Position of the index used.",
53
- defaultValue: "primary"
44
+ type: GraphQLInt,
45
+ description: "Position of the multiindex table used.",
46
+ defaultValue: 1
54
47
  },
55
48
  key_type: {
56
49
  type: key_type_enum_type,
@@ -75,6 +68,9 @@ const query_arg_fields = new GraphQLInputObjectType({
75
68
  limit: {
76
69
  type: GraphQLInt,
77
70
  description: "The maximum number of items to return"
71
+ },
72
+ reverse: {
73
+ type: GraphQLBoolean
78
74
  }
79
75
  }
80
76
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antelopeql",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "A GraphQL implementation for interacting with Antelope based blockchains.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,6 +32,7 @@
32
32
  "graphql_input_types/*.mjs",
33
33
  "graphql_object_types/*.mjs",
34
34
  "antelopeql.mjs",
35
+ "antelopeql.d.ts",
35
36
  "blockchain_query_field.mjs",
36
37
  "build_graphql_fields_from_abis.mjs",
37
38
  "eosio_abi_to_graphql_ast.mjs",
@@ -48,11 +49,14 @@
48
49
  ],
49
50
  "sideEffects": false,
50
51
  "exports": {
52
+ "./antelopeql.mjs": {
53
+ "import": "./antelopeql.mjs",
54
+ "types": "./antelopeql.d.ts"
55
+ },
51
56
  "./blockchain/*.mjs": "./blockchain/*.mjs",
52
57
  "./eosio_types/*.mjs": "./eosio_types/*.mjs",
53
58
  "./graphql_input_types/*.mjs": "./graphql_input_types/*.mjs",
54
59
  "./graphql_object_types/*.mjs": "./graphql_object_types/*.mjs",
55
- "./antelopeql.mjs": "./antelopeql.mjs",
56
60
  "./blockchain_query_field.mjs": "./blockchain_query_field.mjs",
57
61
  "./build_graphql_fields_from_abis.mjs": "./build_graphql_fields_from_abis.mjs",
58
62
  "./eosio_abi_to_graphql_ast.mjs": "./eosio_abi_to_graphql_ast.mjs",
@@ -86,6 +90,7 @@
86
90
  "coverage-node": "^8.0.0",
87
91
  "eslint": "^8.34.0",
88
92
  "eslint-plugin-simple-import-sort": "^10.0.0",
93
+ "graphql": "^16.11.0",
89
94
  "nodemon": "^3.0.1",
90
95
  "prettier": "^2.8.4",
91
96
  "snapshot-assertion": "^5.0.0",