Comparing version 1.2.2 to 1.2.3
import GQLResultInterface, { GQLEdgeInterface, GQLNodeInterface } from "./faces"; | ||
export type PageCallback = (pageEdges: GQLEdgeInterface[]) => Promise<void>; | ||
export interface ArGqlInterface { | ||
run: (query: string, variables?: Record<string, unknown>) => Promise<GQLResultInterface>; | ||
all: (query: string, variables?: Record<string, unknown>) => Promise<GQLEdgeInterface[]>; | ||
all: (query: string, variables?: Record<string, unknown>, pageCallback?: PageCallback) => Promise<GQLEdgeInterface[]>; | ||
tx: (id: string) => Promise<GQLNodeInterface>; | ||
@@ -6,0 +7,0 @@ fetchTxTag: (id: string, name: string) => Promise<string | undefined>; |
@@ -86,4 +86,4 @@ "use strict"; | ||
}); }; | ||
var all = function (query, variables) { return __awaiter(_this, void 0, void 0, function () { | ||
var hasNextPage, edges, cursor, res; | ||
var all = function (query, variables, pageCallback) { return __awaiter(_this, void 0, void 0, function () { | ||
var hasNextPage, edges, cursor, pageCallbacks, res; | ||
return __generator(this, function (_a) { | ||
@@ -95,2 +95,3 @@ switch (_a.label) { | ||
cursor = ""; | ||
pageCallbacks = []; | ||
_a.label = 1; | ||
@@ -103,3 +104,8 @@ case 1: | ||
if (res.edges && res.edges.length) { | ||
edges = edges.concat(res.edges); | ||
if (typeof pageCallback === 'function') { | ||
pageCallbacks.push(pageCallback(res.edges)); | ||
} | ||
else { | ||
edges = edges.concat(res.edges); | ||
} | ||
cursor = res.edges[res.edges.length - 1].cursor; | ||
@@ -109,3 +115,6 @@ } | ||
return [3 /*break*/, 1]; | ||
case 3: return [2 /*return*/, edges]; | ||
case 3: return [4 /*yield*/, Promise.all(pageCallbacks)]; | ||
case 4: | ||
_a.sent(); | ||
return [2 /*return*/, edges]; | ||
} | ||
@@ -115,15 +124,8 @@ }); | ||
var tx = function (id) { return __awaiter(_this, void 0, void 0, function () { | ||
var isBrowser, res; | ||
var res; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
isBrowser = typeof window !== "undefined"; | ||
return [4 /*yield*/, run(tx_1["default"], { id: id })]; | ||
case 0: return [4 /*yield*/, run(tx_1["default"], { id: id })]; | ||
case 1: | ||
res = _a.sent(); | ||
// if (isBrowser && res.data.transaction.block) { | ||
// const cache = JSON.parse(localStorage.getItem("gqlCache") || "{}"); | ||
// cache[id] = res.data.transaction; | ||
// localStorage.setItem("gqlCache", JSON.stringify(cache)); | ||
// } | ||
return [2 /*return*/, res.data.transaction]; | ||
@@ -130,0 +132,0 @@ } |
{ | ||
"name": "ar-gql", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"main": "dist/index", | ||
@@ -5,0 +5,0 @@ "types": "dist/index", |
@@ -55,3 +55,3 @@ # `ar-gql` version 1 | ||
### `all(query, variables?)` | ||
### `all(query, variables?, pageCallback?)` | ||
@@ -87,2 +87,5 @@ Similar to the `run` function, the `all` function receives a query and optional variables. | ||
The optional `pageCallback` feature is the convenience functon to process pages as they are returned. The page results are processed asynchronously, and the function `all` returns after all callback functions have completed internally. | ||
> N.B When a callback function is passed to `all`, `all` returns an empty edges array once all page callbacks are complete `[]`. | ||
### `tx(id)` | ||
@@ -89,0 +92,0 @@ |
14457
234
100