Socket
Socket
Sign inDemoInstall

@hubspot/cms-lib

Package Overview
Dependencies
Maintainers
13
Versions
115
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hubspot/cms-lib - npm Package Compare versions

Comparing version 2.2.1-beta.0 to 2.2.1-beta.1

__tests__/fixtures/hubdb/hubdbFetchRowsWithPaging.json

3

__tests__/fixtures/hubdb/hubdbFetchRowsResponse.json

@@ -13,3 +13,4 @@ {

}
]
],
"paging": null
}

@@ -7,2 +7,3 @@ const fs = require('fs-extra');

const hubdbFetchRowResponse = require('./fixtures/hubdb/hubdbFetchRowsResponse.json');
const hubdbFetchRowsWithPagingResponse = require('./fixtures/hubdb/hubdbFetchRowsWithPaging.json');
const hubdbFetchTableResponse = require('./fixtures/hubdb/hubdbFetchTableResponse.json');

@@ -47,2 +48,24 @@ const hubdbCreateTableResponse = require('./fixtures/hubdb/hubdbCreateTableResponse.json');

describe('paging', () => {
it('fetches all results', async () => {
const accountId = 123;
const tableId = 456;
const destPath = 'tmp.json';
const projectCwd = '/home/tom/projects';
getCwd.mockReturnValue(projectCwd);
hubdb.fetchRows.mockReturnValue(hubdbFetchRowResponse);
hubdb.fetchTable.mockReturnValue(hubdbFetchTableResponse);
hubdb.fetchRows.mockReturnValueOnce(hubdbFetchRowsWithPagingResponse);
await downloadHubDbTable(accountId, tableId, destPath);
const fileOutput = JSON.parse(fs.outputFile.mock.results[1].value);
expect(fileOutput.rows.length).toEqual(6);
expect(fileOutput.rows[0].name).toMatchInlineSnapshot(`"Paging 1"`);
expect(fileOutput.rows[5].name).toMatchInlineSnapshot(`"My Best Event"`);
});
});
it('uploads hubdb table', async () => {

@@ -49,0 +72,0 @@ const accountId = 123;

@@ -10,5 +10,3 @@ const http = require('../http');

uri: `${RESULTS_API_PATH}/${functionId}`,
query: {
limit,
},
query: { ...query, limit },
});

@@ -15,0 +13,0 @@ }

@@ -127,2 +127,19 @@ const path = require('path');

async function fetchAllRows(accountId, tableId) {
let rows = [];
let after = null;
do {
const { paging, results } = await fetchRows(
accountId,
tableId,
after ? { after } : null
);
rows = rows.concat(results);
after = paging && paging.next ? paging.next.after : null;
} while (after !== null);
return rows;
}
async function downloadHubDbTable(accountId, tableId, dest) {

@@ -139,17 +156,3 @@ const table = await fetchTable(accountId, tableId);

let totalRows = null;
let rows = [];
let count = 0;
let offset = 0;
while (totalRows === null || count < totalRows) {
const response = await fetchRows(accountId, tableId, { offset });
if (totalRows === null) {
totalRows = response.total;
}
count += response.results.length;
offset += response.results.length;
rows = rows.concat(response.results);
}
const rows = await fetchAllRows(accountId, tableId);
const tableToWrite = JSON.stringify(convertToJSON(table, rows));

@@ -166,19 +169,9 @@ const tableJson = prettier.format(tableToWrite, {

async function clearHubDbTableRows(accountId, tableId) {
let totalRows = null;
let rows = [];
let count = 0;
let offset = 0;
while (totalRows === null || count < totalRows) {
const response = await fetchRows(accountId, tableId, { offset });
if (totalRows === null) {
totalRows = response.total;
}
const rows = await fetchAllRows(accountId, tableId);
await deleteRows(
accountId,
tableId,
rows.map(row => row.id)
);
count += response.results.length;
offset += response.results.length;
const rowIds = response.results.map(row => row.id);
rows = rows.concat(rowIds);
}
await deleteRows(accountId, tableId, rows);
return {

@@ -185,0 +178,0 @@ deletedRowCount: rows.length,

{
"name": "@hubspot/cms-lib",
"version": "2.2.1-beta.0",
"version": "2.2.1-beta.1",
"description": "Library for working with the HubSpot CMS",

@@ -34,3 +34,3 @@ "license": "Apache-2.0",

},
"gitHead": "107557ac93c35dbb84e4d5292d50849a241db660"
"gitHead": "0f4c21147ac4017d10423123b5cf2c70dfa1c599"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc