New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@saulx/selva

Package Overview
Dependencies
Maintainers
1
Versions
263
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saulx/selva - npm Package Compare versions

Comparing version 20.6.0 to 21.0.0

131

dist/src/get/executeGetOperations/aggregate.js

@@ -19,127 +19,2 @@ "use strict";

};
function findTimebased(ast) {
if (!ast) {
return [];
}
const parse = (fork, filters) => {
if (fork.$and) {
for (const f of fork.$and) {
if ((0, selva_query_ast_parser_1.isFork)(f)) {
parse(f, filters);
}
else if (f.hasNow) {
filters.push(f);
}
}
}
else if (fork.$or) {
for (const f of fork.$or) {
if ((0, selva_query_ast_parser_1.isFork)(f)) {
parse(f, filters);
}
else if (f.hasNow) {
filters.push(f);
}
}
}
};
const res = [];
parse(ast, res);
return res;
}
function excludeTimebased(ast) {
if (!(0, selva_query_ast_parser_1.isFork)(ast)) {
return ast;
}
const newFork = Object.assign({}, ast);
const filters = [];
if (ast.$or) {
for (const f of ast.$or) {
if ((0, selva_query_ast_parser_1.isFork)(f)) {
const n = excludeTimebased(f);
if (n) {
filters.push(n);
}
}
else if (!f.hasNow) {
filters.push(f);
}
}
newFork.$or = filters;
}
else if (ast.$and) {
for (const f of ast.$and) {
if ((0, selva_query_ast_parser_1.isFork)(f)) {
const n = excludeTimebased(f);
if (n) {
filters.push(n);
}
}
else if (!f.hasNow) {
filters.push(f);
}
}
newFork.$and = filters;
}
if (!filters.length) {
return null;
}
return newFork;
}
async function checkForNextRefresh(ctx, client, sourceField, paddedIds, ast, lang) {
if (!ctx.subId) {
return;
}
const uniq = new Set();
const timebased = findTimebased(ast).filter((f) => {
if (uniq.has(f.$field)) {
return false;
}
uniq.add(f.$field);
return true;
});
if (!timebased.length) {
return;
}
const withoutTimebased = excludeTimebased(ast);
await Promise.all(timebased.map(async (f) => {
// console.log('TRYING TIMEBASED')
const newFilter = {
$operator: '>',
$value: f.$value,
$field: f.$field,
};
let newFork = {
isFork: true,
$and: [withoutTimebased, newFilter],
};
if (!withoutTimebased) {
newFork.$and = [newFilter];
}
const args = (0, selva_query_ast_parser_1.ast2rpn)(client.schemas[ctx.db].types, newFork, lang);
// TODO
const ids = await client.redis.selva_hierarchy_find(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy',
// TODO proper dir, needs byType
...(0, _1.sourceFieldToFindArgs)(client.schemas[ctx.db], null, sourceField, false), 'order', f.$field, 'asc', 'offset', 0, 'limit', 1, paddedIds, ...args);
if (!ids || !ids.length) {
return;
}
const [id] = ids;
const time = Number(await client.redis.selva_object_get(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), id, f.$field));
let v = f.$value;
if (v.startsWith('now-')) {
v = v.replace('now-', 'now+');
}
else if (v.startsWith('now+')) {
v = v.replace('now+', 'now-');
}
let converted = (0, selva_query_ast_parser_1.convertNow)(v, time);
// console.log('TIME NOW', Date.now())
// console.log('NEXT TIME', time)
// console.log('ADJUSTED', converted)
if (!ctx.meta.___refreshAt || ctx.meta.___refreshAt > converted) {
ctx.meta.___refreshAt = converted;
}
}));
}
// TODO: implement recursive version

@@ -214,3 +89,3 @@ const executeAggregateOperation = async (client, op, lang, ctx, passedSchema) => {

const agg = await client.redis.selva_hierarchy_aggregatein(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy', FN_TO_ENUM[op.function.name] || '0', 'order', ((_a = op.options.sort) === null || _a === void 0 ? void 0 : _a.$field) || '', ((_b = op.options.sort) === null || _b === void 0 ? void 0 : _b.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, 'fields', (op.function.args || []).join('|'), (0, util_1.joinIds)(op.inKeys), ...args);
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang);
(0, find_1.bufferRefreshCheck)(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang);
return Number(agg);

@@ -236,3 +111,3 @@ }

(0, _1.bufferFindMarker)(ctx, Object.assign(Object.assign({}, (0, _1.sourceFieldToDir)(schema, sourceFieldSchema, sourceField, op.recursive, op.byType)), { id: id, fields: op.props.$all === true ? [] : Object.keys(realOpts), rpn: args }));
await checkForNextRefresh(ctx, client, sourceField, id, op.filter, lang);
(0, find_1.bufferRefreshCheck)(ctx, client, sourceField, id, op.filter, lang);
}

@@ -250,3 +125,3 @@ }

const agg = await client.redis.selva_hierarchy_aggregate(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy', FN_TO_ENUM[op.function.name] || '0', ...(0, _1.sourceFieldToFindArgs)(client.schemas[ctx.db], sourceFieldSchema, sourceField, false, op.byType), ...(0, indexing_1.mkIndex)(schema, op), 'order', ((_c = op.options.sort) === null || _c === void 0 ? void 0 : _c.$field) || '', ((_d = op.options.sort) === null || _d === void 0 ? void 0 : _d.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, 'fields', (op.function.args || []).join('|'), (0, util_1.padId)(op.id), ...args);
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
(0, find_1.bufferRefreshCheck)(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
return Number(agg);

@@ -253,0 +128,0 @@ }

3

dist/src/get/executeGetOperations/find.d.ts
import { Schema, SelvaClient } from '../../';
import { GetOperationFind, GetResult } from '../types';
import { ExecContext } from './';
import { Fork } from '@saulx/selva-query-ast-parser';
export declare function bufferRefreshCheck(ctx: ExecContext, client: SelvaClient, sourceField: string, paddedIds: string, ast: Fork, lang?: string, passedSchema?: Schema): void;
export declare function checkForNextRefresh(ctx: ExecContext, client: SelvaClient, sourceField: string, paddedIds: string, ast: Fork, lang?: string, passedSchema?: Schema): Promise<void>;
export declare const findIds: (client: SelvaClient, op: GetOperationFind, lang: string, ctx: ExecContext, passedSchema?: Schema) => Promise<string[]>;
declare const executeFindOperation: (client: SelvaClient, op: GetOperationFind, lang: string, ctx: ExecContext, passedSchema?: Schema) => Promise<GetResult>;
export default executeFindOperation;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findIds = void 0;
exports.findIds = exports.checkForNextRefresh = exports.bufferRefreshCheck = void 0;
const _1 = require("./");

@@ -290,2 +290,13 @@ const selva_query_ast_parser_1 = require("@saulx/selva-query-ast-parser");

}
function bufferRefreshCheck(ctx, client, sourceField, paddedIds, ast, lang, passedSchema) {
if (!ctx.subId) {
return;
}
const p = checkForNextRefresh(ctx, client, sourceField, paddedIds, ast, lang, passedSchema);
if (!ctx.refreshChecks) {
ctx.refreshChecks = [];
}
ctx.refreshChecks.push(p);
}
exports.bufferRefreshCheck = bufferRefreshCheck;
async function checkForNextRefresh(ctx, client, sourceField, paddedIds, ast, lang, passedSchema) {

@@ -348,2 +359,3 @@ if (!ctx.subId) {

}
exports.checkForNextRefresh = checkForNextRefresh;
const findIds = async (client, op, lang, ctx, passedSchema) => {

@@ -370,3 +382,3 @@ var _a, _b, _c, _d;

const ids = await client.redis.selva_hierarchy_find(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy', 'node', 'order', ((_a = op.options.sort) === null || _a === void 0 ? void 0 : _a.$field) || '', ((_b = op.options.sort) === null || _b === void 0 ? void 0 : _b.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, (0, util_1.joinIds)(op.inKeys), ...args);
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang);
bufferRefreshCheck(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang);
return ids;

@@ -392,3 +404,3 @@ }

(0, _1.bufferFindMarker)(ctx, Object.assign(Object.assign({}, (0, _1.sourceFieldToDir)(schema, sourceFieldSchema, sourceField, op.recursive, op.byType)), { id: id, fields: op.props.$all === true ? [] : Object.keys(realOpts), rpn: args }));
await checkForNextRefresh(ctx, client, sourceField, id, op.filter, lang);
bufferRefreshCheck(ctx, client, sourceField, id, op.filter, lang);
}

@@ -413,3 +425,3 @@ }

const ids = await client.redis.selva_hierarchy_find(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(schema.languages, lang), '___selva_hierarchy', ...(0, _1.sourceFieldToFindArgs)(schema, sourceFieldSchema, sourceField, op.recursive, op.byType), ...(0, indexing_1.mkIndex)(schema, op), 'order', ((_c = op.options.sort) === null || _c === void 0 ? void 0 : _c.$field) || '', ((_d = op.options.sort) === null || _d === void 0 ? void 0 : _d.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, (0, util_1.padId)(op.id), ...args);
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
bufferRefreshCheck(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
return ids;

@@ -451,3 +463,3 @@ }

const result = await client.redis.selva_hierarchy_find(ctx.originDescriptors[ctx.db] || { name: ctx.db }, (0, util_2.makeLangArg)(client.schemas[ctx.db].languages, lang), '___selva_hierarchy', 'node', 'order', ((_a = op.options.sort) === null || _a === void 0 ? void 0 : _a.$field) || '', ((_b = op.options.sort) === null || _b === void 0 ? void 0 : _b.$order) || 'none', 'offset', op.options.offset, 'limit', op.options.limit, ...makeFieldsString(passedSchema || client.schemas[ctx.db], fieldsOpt, isInherit), (0, util_1.joinIds)(op.inKeys), ...args);
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang, passedSchema);
bufferRefreshCheck(ctx, client, sourceField, (0, util_1.joinIds)(op.inKeys), op.filter, lang, passedSchema);
return result;

@@ -474,3 +486,3 @@ }

(0, _1.bufferFindMarker)(ctx, Object.assign(Object.assign({}, (0, _1.sourceFieldToDir)(schema, sourceFieldSchema, sourceField, op.recursive, op.byType)), { id: id, fields: op.props.$all === true ? [] : Object.keys(realOpts), rpn: args }));
await checkForNextRefresh(ctx, client, sourceField, id, op.filter, lang);
bufferRefreshCheck(ctx, client, sourceField, id, op.filter, lang);
}

@@ -527,3 +539,3 @@ }

}
await checkForNextRefresh(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
bufferRefreshCheck(ctx, client, sourceField, (0, util_1.padId)(op.id), op.filter, lang);
return result;

@@ -530,0 +542,0 @@ }

@@ -19,2 +19,3 @@ import { SelvaClient } from '../../';

}[];
refreshChecks?: Promise<void>[];
};

@@ -21,0 +22,0 @@ export declare type TraversalType = 'none' | 'node' | 'array' | 'children' | 'parents' | 'ancestors' | 'descendants' | 'ref' | 'edge_field' | 'bfs_edge_field' | 'bfs_expression' | 'expression';

@@ -164,2 +164,5 @@ "use strict";

}
if (ctx.refreshChecks) {
await Promise.all(ctx.refreshChecks);
}
}

@@ -166,0 +169,0 @@ catch (e) {

{
"name": "@saulx/selva",
"version": "20.6.0",
"version": "21.0.0",
"license": "MIT",

@@ -54,3 +54,3 @@ "main": "dist/src/index.js",

"@types/pg": "^8.6.1",
"@saulx/selva-server": "20.6.0",
"@saulx/selva-server": "21.0.0",
"before-exit": "1.0.0",

@@ -57,0 +57,0 @@ "async-exec": "^1.1.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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