Comparing version 0.49.28 to 0.49.29
import { PageInfo } from "./schema"; | ||
export interface IResultPageInterface<T> { | ||
import { FetchOptions } from "./types"; | ||
export interface IResultPageInterface<T, FetchOptionsType = FetchOptions, RestArgs extends any[] = any[]> { | ||
items: T[]; | ||
pageInfo: PageInfo; | ||
nextPage?: () => Promise<IResultPageInterface<T>>; | ||
previousPage?: () => Promise<IResultPageInterface<T>>; | ||
nextPage?: () => Promise<IResultPageInterface<T, FetchOptionsType, RestArgs>>; | ||
previousPage?: () => Promise<IResultPageInterface<T, FetchOptionsType, RestArgs>>; | ||
} | ||
export interface IFetch<ModelType, FetchOptionsType> { | ||
fetch(args?: FetchOptionsType): Promise<IResultPageInterface<ModelType>>; | ||
export interface IFetch<ModelType, FetchOptionsType, RestArgs extends any[] = any[]> { | ||
fetch(args?: FetchOptionsType, ...rest: RestArgs): Promise<IResultPageInterface<ModelType, FetchOptionsType, RestArgs>>; | ||
} |
import { IFetch } from "./interfaces"; | ||
import { PageInfo } from "./schema"; | ||
import { FetchOptions } from "./types"; | ||
export declare class ResultPage<ModelType, FetchOptionsType = FetchOptions> { | ||
export declare class ResultPage<ModelType, FetchOptionsType = FetchOptions, RestArgs extends any[] = any[]> { | ||
items: ModelType[]; | ||
pageInfo: PageInfo; | ||
nextPage?: () => Promise<ResultPage<ModelType, FetchOptionsType>>; | ||
previousPage?: () => Promise<ResultPage<ModelType, FetchOptionsType>>; | ||
constructor(model: IFetch<ModelType, FetchOptionsType>, items: ModelType[], pageInfo: PageInfo, args: FetchOptionsType); | ||
nextPage?: () => Promise<ResultPage<ModelType, FetchOptionsType, RestArgs>>; | ||
previousPage?: () => Promise<ResultPage<ModelType, FetchOptionsType, RestArgs>>; | ||
constructor(model: IFetch<ModelType, FetchOptionsType, RestArgs>, items: ModelType[], pageInfo: PageInfo, args: FetchOptionsType, ...rest: RestArgs); | ||
} |
@@ -13,2 +13,11 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,2 +27,6 @@ exports.ResultPage = void 0; | ||
function ResultPage(model, items, pageInfo, args) { | ||
var rest = []; | ||
for (var _i = 4; _i < arguments.length; _i++) { | ||
rest[_i - 4] = arguments[_i]; | ||
} | ||
this.items = items; | ||
@@ -23,3 +36,3 @@ this.pageInfo = pageInfo; | ||
this.nextPage = function () { | ||
return model.fetch(__assign(__assign({}, args), { after: pageInfo.endCursor })); | ||
return model.fetch.apply(model, __spreadArray([__assign(__assign({}, args), { after: pageInfo.endCursor })], rest, false)); | ||
}; | ||
@@ -29,3 +42,3 @@ } | ||
this.previousPage = function () { | ||
return model.fetch(__assign(__assign({}, args), { before: pageInfo.startCursor })); | ||
return model.fetch.apply(model, __spreadArray([__assign(__assign({}, args), { before: pageInfo.startCursor })], rest, false)); | ||
}; | ||
@@ -32,0 +45,0 @@ } |
@@ -5,2 +5,3 @@ import { IterableModel } from "./iterableModel"; | ||
import { FetchOptions, Subscription, SearchFilter } from "./types"; | ||
export declare const TRANSACTION_FIELDS = "\n id\n amount\n name\n iban\n type\n bookingDate\n valutaDate\n paymentMethod\n category\n categoryCode\n vatCategoryCode\n vatRate\n categorizationType\n userSelectedBookingDate\n purpose\n personalNote\n originalAmount\n foreignCurrency\n createdAt\n splits {\n id\n amount\n category\n userSelectedBookingDate\n categorizationType\n }\n recurlyInvoiceNumber\n canBeRecategorized\n"; | ||
export declare const NEW_TRANSACTION_SUBSCRIPTION: string; | ||
@@ -7,0 +8,0 @@ export declare const getUpdateTransactionMutation: (fields: string) => string; |
@@ -74,3 +74,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Transaction = exports.DELETE_TRANSACTION_ASSET = exports.FINALIZE_TRANSACTION_ASSET = exports.CREATE_TRANSACTION_ASSET = exports.getUpdateSplitTransactionMutation = exports.getDeleteSplitTransactionMutation = exports.getCreateSplitTransactionMutation = exports.getUpdateTransactionMutation = exports.NEW_TRANSACTION_SUBSCRIPTION = void 0; | ||
exports.Transaction = exports.DELETE_TRANSACTION_ASSET = exports.FINALIZE_TRANSACTION_ASSET = exports.CREATE_TRANSACTION_ASSET = exports.getUpdateSplitTransactionMutation = exports.getDeleteSplitTransactionMutation = exports.getCreateSplitTransactionMutation = exports.getUpdateTransactionMutation = exports.NEW_TRANSACTION_SUBSCRIPTION = exports.TRANSACTION_FIELDS = void 0; | ||
var iterableModel_1 = require("./iterableModel"); | ||
@@ -83,10 +83,10 @@ var resultPage_1 = require("./resultPage"); | ||
var ASSET_FIELDS = "\n id\n name\n filetype\n thumbnail\n fullsize\n"; | ||
var TRANSACTION_FIELDS = "\n id\n amount\n name\n iban\n type\n bookingDate\n valutaDate\n paymentMethod\n category\n categoryCode\n vatCategoryCode\n vatRate\n categorizationType\n userSelectedBookingDate\n purpose\n personalNote\n originalAmount\n foreignCurrency\n createdAt\n splits {\n id\n amount\n category\n userSelectedBookingDate\n categorizationType\n }\n recurlyInvoiceNumber\n canBeRecategorized\n"; | ||
exports.TRANSACTION_FIELDS = "\n id\n amount\n name\n iban\n type\n bookingDate\n valutaDate\n paymentMethod\n category\n categoryCode\n vatCategoryCode\n vatRate\n categorizationType\n userSelectedBookingDate\n purpose\n personalNote\n originalAmount\n foreignCurrency\n createdAt\n splits {\n id\n amount\n category\n userSelectedBookingDate\n categorizationType\n }\n recurlyInvoiceNumber\n canBeRecategorized\n"; | ||
var TRANSACTION_DETAILS = "\n assets {\n ".concat(ASSET_FIELDS, "\n }\n documentNumber\n documentPreviewUrl\n documentDownloadUrl\n documentType\n e2eId\n mandateNumber\n"); | ||
var getFetchTransactionsQuery = function (fields) { return "\n query fetchTransactions ($first: Int, $last: Int, $after: String, $before: String, $filter: TransactionFilter, $preset: FilterPresetInput) {\n viewer {\n mainAccount {\n transactions(first: $first, last: $last, after: $after, before: $before, filter: $filter, preset: $preset) {\n edges {\n node {\n ".concat(fields, "\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n }\n }\n }\n }\n"); }; | ||
var getFetchTransactionQuery = function (fields) { return "\n query fetchTransaction ($id: ID!) {\n viewer {\n mainAccount {\n transaction(id: $id) {\n ".concat(fields, "\n }\n }\n }\n }\n"); }; | ||
exports.NEW_TRANSACTION_SUBSCRIPTION = "subscription {\n newTransaction {\n ".concat(TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS, "\n }\n}"); | ||
exports.NEW_TRANSACTION_SUBSCRIPTION = "subscription {\n newTransaction {\n ".concat(exports.TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS, "\n }\n}"); | ||
var getUpdateTransactionMutation = function (fields) { return "mutation updateTransaction(\n $id: String!\n $category: TransactionCategory,\n $userSelectedBookingDate: DateTime,\n $personalNote: String,\n $vatRate: VatRate,\n $categoryCode: String,\n $vatCategoryCode: String,\n $splits: [UpdateTransactionSplitsInput!],\n) {\n updateTransaction(\n id: $id\n category: $category\n userSelectedBookingDate: $userSelectedBookingDate\n personalNote: $personalNote\n vatRate: $vatRate\n categoryCode: $categoryCode\n vatCategoryCode: $vatCategoryCode\n splits: $splits\n ) {\n ".concat(fields, "\n }\n}"); }; | ||
exports.getUpdateTransactionMutation = getUpdateTransactionMutation; | ||
var DEFAULT_SPLIT_TRANSACTION_FIELDS = "\n".concat(TRANSACTION_FIELDS, "\n").concat(TRANSACTION_DETAILS, "\n"); | ||
var DEFAULT_SPLIT_TRANSACTION_FIELDS = "\n".concat(exports.TRANSACTION_FIELDS, "\n").concat(TRANSACTION_DETAILS, "\n"); | ||
var getCreateSplitTransactionMutation = function (fields) { | ||
@@ -127,3 +127,3 @@ if (fields === void 0) { fields = DEFAULT_SPLIT_TRANSACTION_FIELDS; } | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
if (fields === void 0) { fields = TRANSACTION_FIELDS; } | ||
if (fields === void 0) { fields = exports.TRANSACTION_FIELDS; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -141,3 +141,3 @@ var result, transactions, pageInfo; | ||
}; | ||
return [2 /*return*/, new resultPage_1.ResultPage(this, transactions, pageInfo, args)]; | ||
return [2 /*return*/, new resultPage_1.ResultPage(this, transactions, pageInfo, args, fields)]; | ||
} | ||
@@ -183,3 +183,3 @@ }); | ||
var _a, _b; | ||
if (fields === void 0) { fields = "".concat(TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS); } | ||
if (fields === void 0) { fields = "".concat(exports.TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -213,3 +213,3 @@ var result; | ||
Transaction.prototype.update = function (args, fields) { | ||
if (fields === void 0) { fields = "".concat(TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS); } | ||
if (fields === void 0) { fields = "".concat(exports.TRANSACTION_FIELDS, "\n ").concat(TRANSACTION_DETAILS); } | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -216,0 +216,0 @@ var result; |
{ | ||
"name": "kontist", | ||
"version": "0.49.28", | ||
"version": "0.49.29", | ||
"description": "Kontist client SDK", | ||
@@ -5,0 +5,0 @@ "main": "dist/lib/index.js", |
@@ -19,2 +19,3 @@ import { expect } from "chai"; | ||
DELETE_TRANSACTION_ASSET, | ||
TRANSACTION_FIELDS, | ||
} from "../../lib/graphql/transaction"; | ||
@@ -35,3 +36,4 @@ import { SubscriptionType } from "../../lib/graphql/types"; | ||
let thirdTransaction: Transaction; | ||
let stub: any; | ||
let stub: sinon.SinonStub; | ||
let fetchSpy: sinon.SinonSpy; | ||
@@ -41,2 +43,3 @@ beforeEach(() => { | ||
stub = sinon.stub(client.graphQL, "rawQuery"); | ||
fetchSpy = sinon.spy(client.models.transaction, "fetch"); | ||
@@ -72,2 +75,3 @@ firstTransaction = createTransaction({ | ||
stub.restore(); | ||
fetchSpy.restore(); | ||
}); | ||
@@ -86,4 +90,12 @@ | ||
expect(fetchSpy.callCount).to.equal(1); | ||
const secondPage = firstPage.nextPage && (await firstPage.nextPage()); | ||
expect(secondPage?.items).to.deep.equal([thirdTransaction]); | ||
expect(fetchSpy.callCount).to.equal(2); | ||
expect(fetchSpy.lastCall.args).to.deep.eq([ | ||
{ first: 2, after: "22222" }, | ||
TRANSACTION_FIELDS, | ||
]); | ||
}); | ||
@@ -90,0 +102,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1045070
18442