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

@minatojs/sql-utils

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@minatojs/sql-utils - npm Package Compare versions

Comparing version 5.0.0-alpha.0 to 5.0.0

50

lib/index.js

@@ -21,3 +21,3 @@ "use strict";

// minato/packages/sql-utils/src/index.ts
// src/index.ts
var src_exports = {};

@@ -40,3 +40,6 @@ __export(src_exports, {

__name(isBracketed, "isBracketed");
var _Builder = class _Builder {
var Builder = class {
static {
__name(this, "Builder");
}
escapeMap = {};

@@ -91,6 +94,5 @@ escapeRegExp;

$size: (key, value) => {
var _a;
if (!value)
return this.logicalNot(key);
if (((_a = this.state.sqlTypes) == null ? void 0 : _a[this.unescapeId(key)]) === "json") {
if (this.state.sqlTypes?.[this.unescapeId(key)] === "json") {
return `${this.jsonLength(key)} = ${this.escape(value)}`;

@@ -187,4 +189,3 @@ } else {

createElementQuery(key, value) {
var _a;
if (((_a = this.state.sqlTypes) == null ? void 0 : _a[this.unescapeId(key)]) === "json") {
if (this.state.sqlTypes?.[this.unescapeId(key)] === "json") {
return this.jsonContains(key, this.quote(JSON.stringify(value)));

@@ -335,5 +336,4 @@ } else {

transformKey(key, fields, prefix, fullKey) {
var _a, _b;
if (key in fields || !key.includes(".")) {
if (((_a = this.state.sqlTypes) == null ? void 0 : _a[key]) || ((_b = this.state.sqlTypes) == null ? void 0 : _b[fullKey])) {
if (this.state.sqlTypes?.[key] || this.state.sqlTypes?.[fullKey]) {
this.state.sqlType = this.state.sqlTypes[key] || this.state.sqlTypes[fullKey];

@@ -348,3 +348,2 @@ }

getRecursive(args) {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
if (typeof args === "string") {

@@ -354,9 +353,9 @@ return this.getRecursive(["_", args]);

const [table, key] = args;
const fields = ((_b = (_a = this.state.tables) == null ? void 0 : _a[table]) == null ? void 0 : _b.fields) || {};
const fields = this.state.tables?.[table]?.fields || {};
const fkey = Object.keys(fields).find((field) => key === field || key.startsWith(field + "."));
if (fkey && ((_c = fields[fkey]) == null ? void 0 : _c.expr)) {
if (fkey && fields[fkey]?.expr) {
if (key === fkey) {
return this.parseEvalExpr((_d = fields[fkey]) == null ? void 0 : _d.expr);
return this.parseEvalExpr(fields[fkey]?.expr);
} else {
const field = this.parseEvalExpr((_e = fields[fkey]) == null ? void 0 : _e.expr);
const field = this.parseEvalExpr(fields[fkey]?.expr);
const rest = key.slice(fkey.length + 1).split(".");

@@ -366,11 +365,11 @@ return this.transformJsonField(`${field}`, rest.map((key2) => `.${this.escapeKey(key2)}`).join(""));

}
const prefix = this.modifiedTable ? `${this.escapeId((_h = (_g = (_f = this.state.tables) == null ? void 0 : _f[table]) == null ? void 0 : _g.name) != null ? _h : this.modifiedTable)}.` : !this.state.tables || table === "_" || key in fields || Object.keys(this.state.tables).length === 1 && table in this.state.tables ? "" : `${this.escapeId(table)}.`;
const prefix = this.modifiedTable ? `${this.escapeId(this.state.tables?.[table]?.name ?? this.modifiedTable)}.` : !this.state.tables || table === "_" || key in fields || Object.keys(this.state.tables).length === 1 && table in this.state.tables ? "" : `${this.escapeId(table)}.`;
if (!(table in (this.state.tables || {})) && table in (this.state.refTables || {})) {
const fields2 = ((_j = (_i = this.state.refTables) == null ? void 0 : _i[table]) == null ? void 0 : _j.fields) || {};
const res = ((_k = fields2[key]) == null ? void 0 : _k.expr) ? this.parseEvalExpr((_l = fields2[key]) == null ? void 0 : _l.expr) : this.transformKey(key, fields2, `${this.escapeId(table)}.`, `${table}.${key}`);
const fields2 = this.state.refTables?.[table]?.fields || {};
const res = fields2[key]?.expr ? this.parseEvalExpr(fields2[key]?.expr) : this.transformKey(key, fields2, `${this.escapeId(table)}.`, `${table}.${key}`);
if (this.state.wrappedSubquery) {
if (res in ((_m = this.state.refFields) != null ? _m : {}))
if (res in (this.state.refFields ?? {}))
return this.state.refFields[res];
const key2 = `minato_tvar_${(0, import_minato.randomId)()}`;
((_o = (_n = this.state).refFields) != null ? _o : _n.refFields = {})[res] = key2;
(this.state.refFields ??= {})[res] = key2;
this.state.sqlType = "json";

@@ -401,3 +400,3 @@ return this.escapeId(key2);

let sql = "";
if (group == null ? void 0 : group.length) {
if (group?.length) {
sql += ` GROUP BY ${group.map(this.escapeId).join(", ")}`;

@@ -420,3 +419,2 @@ const filter = this.parseEval(having);

get(sel, inline = false, group = false, addref = true) {
var _a;
const { args, table, query, ref, model } = sel;

@@ -461,3 +459,3 @@ let prefix;

const sqlTypes = {};
const fields = (_a = args[0].fields) != null ? _a : Object.fromEntries(Object.entries(model.fields).filter(([, field]) => !field.deprecated).map(([key]) => [key, { $: [ref, key] }]));
const fields = args[0].fields ?? Object.fromEntries(Object.entries(model.fields).filter(([, field]) => !field.deprecated).map(([key]) => [key, { $: [ref, key] }]));
const keys = Object.entries(fields).map(([key, value]) => {

@@ -494,3 +492,2 @@ value = this.parseEval(value, false);

load(model, obj) {
var _a, _b;
if (!obj) {

@@ -505,3 +502,3 @@ const converter = this.types[this.state.sqlType];

const { type, initial } = model.fields[key];
const converter = ((_b = (_a = this.state.sqlTypes) == null ? void 0 : _a[key]) != null ? _b : "raw") === "raw" ? this.types[type] : this.types[this.state.sqlTypes[key]];
const converter = (this.state.sqlTypes?.[key] ?? "raw") === "raw" ? this.types[type] : this.types[this.state.sqlTypes[key]];
result[key] = converter ? converter.load(obj[key], initial) : obj[key];

@@ -532,8 +529,7 @@ }

stringify(value, field) {
const converter = this.types[field == null ? void 0 : field.type];
const converter = this.types[field?.type];
return converter ? converter.dump(value) : value;
}
quote(value) {
var _a;
(_a = this.escapeRegExp) != null ? _a : this.escapeRegExp = new RegExp(`[${Object.values(this.escapeMap).join("")}]`, "g");
this.escapeRegExp ??= new RegExp(`[${Object.values(this.escapeMap).join("")}]`, "g");
let chunkIndex = this.escapeRegExp.lastIndex = 0;

@@ -555,4 +551,2 @@ let escapedVal = "";

};
__name(_Builder, "Builder");
var Builder = _Builder;
// Annotate the CommonJS export names for ESM import in node:

@@ -559,0 +553,0 @@ 0 && (module.exports = {

{
"name": "@minatojs/sql-utils",
"version": "5.0.0-alpha.0",
"version": "5.0.0",
"description": "SQL Utilities for Minato",

@@ -33,3 +33,3 @@ "main": "lib/index.js",

"peerDependencies": {
"minato": "^3.0.0-alpha.0"
"minato": "^3.0.0"
},

@@ -36,0 +36,0 @@ "dependencies": {

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