Socket
Socket
Sign inDemoInstall

@mrnafisia/type-query

Package Overview
Dependencies
2
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.7 to 2.0.8

34

dist/src/entity.d.ts

@@ -14,9 +14,13 @@ import { ClientBase } from 'pg';

};
type By<S extends Schema> = (keyof S & string) | {
expression: unknown;
};
type Order<S extends Schema> = {
by: By<S>;
direction: OrderDirection;
};
type SelectOptions<S extends Schema = Schema> = {
distinct?: true | (keyof S & string)[];
groupBy?: unknown[] | ((context: Context<S>) => unknown[]);
orders?: {
by: keyof S & string;
direction: OrderDirection;
}[];
groupBy?: By<S>[] | ((context: Context<S>) => By<S>[]);
orders?: Order<S>[] | ((context: Context<S>) => Order<S>[]);
start?: bigint;

@@ -63,9 +67,13 @@ step?: number;

};
type JoinSelectOptions<Ss extends Record<string, Schema> = Record<string, Schema>> = {
distinct?: true | SchemaMapKeys<Ss>[];
groupBy?: unknown[] | ((contexts: SchemaMapContexts<Ss>) => unknown[]);
orders?: {
by: SchemaMapKeys<Ss>;
direction: OrderDirection;
}[];
type JoinBy<SMap extends Record<string, Schema>> = SchemaMapKeys<SMap> | {
expression: unknown;
};
type JoinOrder<SMap extends Record<string, Schema>> = {
by: JoinBy<SMap>;
direction: OrderDirection;
};
type JoinSelectOptions<SMap extends Record<string, Schema> = Record<string, Schema>> = {
distinct?: true | SchemaMapKeys<SMap>[];
groupBy?: JoinBy<SMap>[] | ((contexts: SchemaMapContexts<SMap>) => JoinBy<SMap>[]);
orders?: JoinOrder<SMap>[] | ((contexts: SchemaMapContexts<SMap>) => JoinOrder<SMap>[]);
start?: bigint;

@@ -101,3 +109,3 @@ step?: number;

export { createEntity, createSelectQuery, createInsertQuery, createUpdateQuery, createDeleteQuery, createJoinSelectEntity, createJoinSelectQuery, getTableDataOfJoinSelectColumn, createQuery };
export type { SelectOptions, InsertOptions, InsertingRow, UpdateSets, JoinType, TableWithAlias, JoinData, SchemaMapKeys, SchemaMapContexts, PrefixAliasOnSchema, JoinEntity, JoinSelectOptions, OrderDirection, Mode, CustomColumn, NullableAndDefaultColumns, Query, QueryData, QueryResult, QueryResultRow, ReturningRows };
export type { By, Order, SelectOptions, InsertOptions, InsertingRow, UpdateSets, JoinType, TableWithAlias, JoinData, SchemaMapKeys, SchemaMapContexts, PrefixAliasOnSchema, JoinEntity, JoinBy, JoinOrder, JoinSelectOptions, OrderDirection, Mode, CustomColumn, NullableAndDefaultColumns, Query, QueryData, QueryResult, QueryResultRow, ReturningRows };
//# sourceMappingURL=entity.d.ts.map

@@ -93,16 +93,32 @@ "use strict";

for (const aGroupBy of _groupBy) {
const resolvedGroupBy = (0, resolve_1.resolveExpression)(aGroupBy, params.length + 1, false);
if (!resolvedGroupBy.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> groupBy -> ${_groupBy.indexOf(aGroupBy)} -> ${resolvedGroupBy.error}`);
if (typeof aGroupBy === 'object') {
const resolvedExpression = (0, resolve_1.resolveExpression)(aGroupBy.expression, params.length + 1, false);
if (!resolvedExpression.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> groupBy -> ${_groupBy.indexOf(aGroupBy)} -> ${resolvedExpression.error}`);
}
params.push(...resolvedExpression.value.params);
groupByTextArray.push(resolvedExpression.value.text);
}
params.push(...resolvedGroupBy.value.params);
groupByTextArray.push(resolvedGroupBy.value.text);
else {
groupByTextArray.push((0, resolve_1.resolveColumn)(table, aGroupBy, false));
}
}
tokens.push('GROUP BY', groupByTextArray.join(', '));
}
if (orders.length !== 0) {
const _orders = typeof orders === 'function' ? orders(context) : orders;
if (_orders.length !== 0) {
const ordersTextArray = [];
for (const order of orders) {
for (const order of _orders) {
const { by, direction } = order;
ordersTextArray.push(`${(0, resolve_1.resolveColumn)(table, by, false)} ${keywords_1.Dictionary.OrderDirection[direction]}`);
if (typeof by === 'object') {
const resolvedExpression = (0, resolve_1.resolveExpression)(by.expression, params.length + 1, false);
if (!resolvedExpression.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> orderBy -> ${_orders.indexOf(order)} -> by -> ${resolvedExpression.error}`);
}
params.push(...resolvedExpression.value.params);
ordersTextArray.push(`${resolvedExpression.value.text} ${keywords_1.Dictionary.OrderDirection[direction]}`);
}
else {
ordersTextArray.push(`${(0, resolve_1.resolveColumn)(table, by, false)} ${keywords_1.Dictionary.OrderDirection[direction]}`);
}
}

@@ -348,17 +364,34 @@ tokens.push('ORDER BY', ordersTextArray.join(', '));

for (const aGroupBy of _groupBy) {
const resolvedGroupBy = (0, resolve_1.resolveExpression)(aGroupBy, params.length + 1, false);
if (!resolvedGroupBy.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> groupBy -> ${_groupBy.indexOf(aGroupBy)} -> ${resolvedGroupBy.error}`);
if (typeof aGroupBy === 'object') {
const resolvedGroupBy = (0, resolve_1.resolveExpression)(aGroupBy.expression, params.length + 1, false);
if (!resolvedGroupBy.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> groupBy -> ${_groupBy.indexOf(aGroupBy)} -> ${resolvedGroupBy.error}`);
}
params.push(...resolvedGroupBy.value.params);
groupByTextArray.push(resolvedGroupBy.value.text);
}
params.push(...resolvedGroupBy.value.params);
groupByTextArray.push(resolvedGroupBy.value.text);
else {
const { table, alias } = getTableDataOfJoinSelectColumn(allTables, aGroupBy);
groupByTextArray.push((0, resolve_1.resolveColumn)(table, aGroupBy.substring((alias + '_').length), true, alias));
}
}
tokens.push('GROUP BY', groupByTextArray.join(', '));
}
if (orders.length !== 0) {
const _orders = typeof orders === 'function' ? orders(contexts) : orders;
if (_orders.length !== 0) {
const ordersTextArray = [];
for (const order of orders) {
for (const order of _orders) {
const { by, direction } = order;
const { table, alias } = getTableDataOfJoinSelectColumn(allTables, by);
ordersTextArray.push(`${(0, resolve_1.resolveColumn)(table, by.substring((alias + '_').length), true, alias)} ${keywords_1.Dictionary.OrderDirection[direction]}`);
if (typeof by === 'object') {
const resolvedGroupBy = (0, resolve_1.resolveExpression)(by.expression, params.length + 1, false);
if (!resolvedGroupBy.ok) {
return (0, never_catch_1.err)(`${errorPrefix} -> orderBy -> ${_orders.indexOf(order)} -> by -> ${resolvedGroupBy.error}`);
}
params.push(...resolvedGroupBy.value.params);
ordersTextArray.push(`${resolvedGroupBy.value.text} ${keywords_1.Dictionary.OrderDirection[direction]}`);
}
else {
const { table, alias } = getTableDataOfJoinSelectColumn(allTables, by);
ordersTextArray.push(`${(0, resolve_1.resolveColumn)(table, by.substring((alias + '_').length), true, alias)} ${keywords_1.Dictionary.OrderDirection[direction]}`);
}
}

@@ -365,0 +398,0 @@ tokens.push('ORDER BY', ordersTextArray.join(', '));

{
"name": "@mrnafisia/type-query",
"version": "2.0.7",
"version": "2.0.8",
"description": "mini-orm with full type support for postgres.",

@@ -5,0 +5,0 @@ "keywords": [

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc