Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iannisz/node-cms

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iannisz/node-cms - npm Package Compare versions

Comparing version 0.0.70 to 0.0.71

static/root/admin-panel/img/checkbox-checked.png

2

package.json
{
"name": "@iannisz/node-cms",
"version": "0.0.70",
"version": "0.0.71",
"description": "Node CMS",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,3 +19,3 @@ import { req, res } from 'apache-js-workers'

const pageContent = req.body.pageContent as Object
const pagesDB = db(__dirname + '/../../../pages.json')

@@ -22,0 +22,0 @@ const pagesTable = pagesDB.table('pages')

@@ -7,11 +7,63 @@ "use strict";

const tableName = apache_js_workers_1.req.body.tableName;
let orderArr = apache_js_workers_1.req.body.orderArr;
if (orderArr == undefined)
orderArr = [];
let from = apache_js_workers_1.req.body.from;
let to = apache_js_workers_1.req.body.to;
let filterArr = apache_js_workers_1.req.body.filterArr ?? [];
let orderArr = apache_js_workers_1.req.body.orderArr ?? [];
let builtInFilterArr = apache_js_workers_1.req.body.builtInFilterArr;
const generateFilterFunction = (filter) => {
const { colName, operator, value } = filter;
switch (operator) {
case '==': return (row) => row[colName] == value;
case '!=': return (row) => row[colName] != value;
case '>': return (row) => row[colName] > value;
case '>=': return (row) => row[colName] >= value;
case '<': return (row) => row[colName] < value;
case '<=': return (row) => row[colName] <= value;
case 'startsWith': return (row) => row[colName].startsWith(value);
case '!startsWith': return (row) => !row[colName].startsWith(value);
case 'endsWith': return (row) => row[colName].endsWith(value);
case '!endsWith': return (row) => !row[colName].endsWith(value);
case 'contains': return (row) => row[colName].includes(value);
case '!contains': return (row) => !row[colName].includes(value);
case 'null': return (row) => row[colName] == null;
case '!null': return (row) => row[colName] != null;
}
throw new Error(`Unrecognised operator ${operator}`);
};
database_query_1.queryTable(dbName, tableName, tableFn => {
const table = tableFn.get();
const orderedTable = table.orderBy(orderArr);
const { rows, cols } = orderedTable;
let table = tableFn.get();
// Add rowNum to each row
let i = 0;
for (let row of table.rows)
row.rowNum = i++;
// Filter table
if (filterArr.length) {
for (let filter of filterArr) {
table = table.where(generateFilterFunction(filter));
}
}
for (let filter of builtInFilterArr) {
// Never let the user input a built-in filter function
const filterFunction = eval(tableFn.data.filters[filter]);
console.log(filterFunction);
if (filterFunction != null) {
table = table.where(filterFunction);
}
}
// Store the number of total rows
const totalRows = table.length;
// Order table
if (orderArr.length)
table = table.orderBy(orderArr);
// Get rows between indices
if (from == null)
from = 0;
if (to == null)
to = table.length - 1;
if (from != 0 || to != table.length - 1)
table = table.between(from, to);
// Send the table
const { rows, cols } = table;
const { data } = tableFn;
apache_js_workers_1.res.send({ rows, cols, data });
apache_js_workers_1.res.send({ rows, cols, data, totalRows });
})

@@ -18,0 +70,0 @@ .catch(err => {

import { queryTable, handleError } from './../../../../../private-workers/database-query'
import { req, res } from 'apache-js-workers'
import { DB_Table_Row_Formatted as Row } from 'node-json-database'
const dbName = req.body.dbName as string
const tableName = req.body.tableName as string
let from = req.body.from as number
let to = req.body.to as number
let orderArr = req.body.orderArr as (string | [ string, 'ASC' | 'DESC' ])[]
if (orderArr == undefined) orderArr = []
let filterArr = req.body.filterArr as Filter[] ?? []
let orderArr = req.body.orderArr as (string | [ string, 'ASC' | 'DESC' ])[] ?? []
let builtInFilterArr = req.body.builtInFilterArr as string[]
interface Filter {
colName: string
operator: string
value: string
}
const generateFilterFunction = (filter: Filter) => {
const { colName, operator, value } = filter
switch (operator) {
case '==': return (row: Row) => row[colName] == value
case '!=': return (row: Row) => row[colName] != value
case '>': return (row: Row) => row[colName] > value
case '>=': return (row: Row) => row[colName] >= value
case '<': return (row: Row) => row[colName] < value
case '<=': return (row: Row) => row[colName] <= value
case 'startsWith': return (row: Row) => row[colName].startsWith(value)
case '!startsWith': return (row: Row) => !row[colName].startsWith(value)
case 'endsWith': return (row: Row) => row[colName].endsWith(value)
case '!endsWith': return (row: Row) => !row[colName].endsWith(value)
case 'contains': return (row: Row) => row[colName].includes(value)
case '!contains': return (row: Row) => !row[colName].includes(value)
case 'null': return (row: Row) => row[colName] == null
case '!null': return (row: Row) => row[colName] != null
}
throw new Error(`Unrecognised operator ${ operator }`)
}
queryTable(

@@ -14,12 +47,52 @@ dbName,

tableFn => {
const table = tableFn.get()
const orderedTable = table.orderBy(orderArr)
const { rows, cols } = orderedTable
let table = tableFn.get()
// Add rowNum to each row
let i = 0
for (let row of table.rows) row.rowNum = i++
// Filter table
if (filterArr.length) {
for (let filter of filterArr) {
table = table.where(generateFilterFunction(filter))
}
}
for (let filter of builtInFilterArr) {
// Never let the user input a built-in filter function
const filterFunction = eval(tableFn.data.filters[filter])
console.log(filterFunction)
if (filterFunction != null) {
table = table.where(filterFunction)
}
}
// Store the number of total rows
const totalRows = table.length
// Order table
if (orderArr.length) table = table.orderBy(orderArr)
// Get rows between indices
if (from == null) from = 0
if (to == null) to = table.length - 1
if (from != 0 || to != table.length - 1) table = table.between(from, to)
// Send the table
const { rows, cols } = table
const { data } = tableFn
res.send({ rows, cols, data })
}
)
res.send({ rows, cols, data, totalRows })
})
.catch(err => {
handleError(err)
})

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

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