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

kmore

Package Overview
Dependencies
Maintainers
1
Versions
272
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kmore - npm Package Compare versions

Comparing version 41.0.0 to 42.0.0

dist/lib/proxy.apply.d.ts

11

dist/lib/base.d.ts

@@ -1,4 +0,8 @@

import { CaseType, DbQueryBuilder, KmoreQueryBuilder, KmoreTransaction, KmoreTransactionConfig, QueryContext } from './types.js';
import { CaseType, DbQueryBuilder, KmoreQueryBuilder, KmoreTransaction, KmoreTransactionConfig, QueryContext, TrxIdQueryMap } from './types.js';
export declare abstract class KmoreBase<D = any, Context = any> {
/**
* kmoreTrxId => Set<kmoreQueryId>
*/
readonly abstract trxIdQueryMap: TrxIdQueryMap;
/**
* Start a transaction.

@@ -18,8 +22,3 @@ * @param id - For generation of kmoreTrxId

protected abstract extRefTableFnPropertyCallback(refTable: KmoreQueryBuilder, caseConvert: CaseType, ctx: Context | object, kmoreQueryId: symbol): KmoreQueryBuilder;
protected abstract extRefTableFnPropertyTransacting(refTable: KmoreQueryBuilder, ctx: Context | object): KmoreQueryBuilder;
protected abstract postProcessResponse(result: any, queryContext?: QueryContext): unknown;
/**
* Create a proxy for `then` method on QueryBuilder, not on QueryResponse
*/
protected abstract proxyGetThen(options: ProxyGetOptions): KmoreQueryBuilder['then'];
}

@@ -26,0 +25,0 @@ export interface ProxyGetOptions {

import type { DbDict } from 'kmore-types';
import type { Knex } from 'knex';
import { KmoreBase, ProxyGetOptions } from './base.js';
import { KmoreBase } from './base.js';
import { postProcessResponse } from './helper.js';

@@ -78,8 +78,3 @@ import { CaseType, DbQueryBuilder, EventCallbacks, KmoreQueryBuilder, KmoreTransaction, KmoreTransactionConfig, KnexConfig, QueryContext, TrxIdQueryMap } from './types.js';

protected extRefTableFnPropertyCallback(refTable: KmoreQueryBuilder, caseConvert: CaseType, ctx: Context | object, kmoreQueryId: symbol): KmoreQueryBuilder;
protected extRefTableFnPropertyTransacting(refTable: KmoreQueryBuilder, ctx: Context | object): KmoreQueryBuilder;
protected postProcessResponse(result: any, queryContext?: QueryContext): unknown;
/**
* Create a proxy for `then` method on QueryBuilder, not on QueryResponse
*/
protected proxyGetThen(options: ProxyGetOptions): KmoreQueryBuilder['then'];
}

@@ -86,0 +81,0 @@ export interface KmoreFactoryOpts<D, Ctx = unknown> {

@@ -11,5 +11,6 @@ /* eslint-disable max-lines-per-function */

import { postProcessResponse, wrapIdentifier } from './helper.js';
import { builderApplyTransactingProxy } from './proxy.apply.js';
import { createQueryBuilderGetProxy } from './proxy.get.js';
import { extRefTableFnPropertySmartJoin } from './smart-join.js';
import { CaseType, KmoreProxyKey, } from './types.js';
import { CaseType, } from './types.js';
export class Kmore extends KmoreBase {

@@ -276,3 +277,3 @@ /**

refTable = this.extRefTableFnPropertyCallback(refTable, caseConvert, ctx, kmoreQueryId);
refTable = this.extRefTableFnPropertyTransacting(refTable, ctx);
refTable = builderApplyTransactingProxy(this, refTable, ctx);
refTable = extRefTableFnPropertySmartJoin(refTable);

@@ -339,27 +340,2 @@ // refTable = this.extRefTableFnPropertyThen(refTable)

}
extRefTableFnPropertyTransacting(refTable, ctx) {
// eslint-disable-next-line @typescript-eslint/unbound-method
const applyTransactingProxy = new Proxy(refTable.transacting, {
apply: (target, ctx2, args) => {
const [trx] = args;
assert(trx?.isTransaction === true, 'trx must be a transaction');
const { kmoreTrxId } = trx;
const qid = ctx2.kmoreQueryId;
if (qid && kmoreTrxId) {
const st = this.trxIdQueryMap.get(kmoreTrxId);
assert(st, 'Transaction already completed, may committed or rollbacked already. trxIdQueryMap not contains kmoreTrxId:'
+ kmoreTrxId.toString());
st.add(qid);
this.setCtxTrxIdMap(ctx, kmoreTrxId);
}
return Reflect.apply(target, ctx2, args);
},
});
void Object.defineProperty(refTable, 'transacting', {
...defaultPropDescriptor,
writable: true,
value: applyTransactingProxy,
});
return refTable;
}
postProcessResponse(result, queryContext) {

@@ -372,56 +348,2 @@ let ret = result;

}
/**
* Create a proxy for `then` method on QueryBuilder, not on QueryResponse
*/
proxyGetThen(options) {
const { target, propKey } = options;
assert(propKey === 'then', `propKey should be "then", but got: ${propKey.toString()}`);
const getThenProxy = async (done, reject) => {
try {
// query response or response data
const resp = await Reflect.apply(target.then, target, []);
if (typeof resp === 'object' && resp !== null) {
Object.defineProperty(resp, KmoreProxyKey.getThenProxyProcessed, {
...defaultPropDescriptor,
enumerable: false,
writable: true,
value: true,
});
}
if (typeof done === 'function') {
const data = await done(resp); // await for try/catch
return data;
}
return resp;
}
catch (ex) {
const qid = target.kmoreQueryId;
assert(qid, 'kmoreQueryId should be set on QueryBuilder');
const trx = this.getTrxByKmoreQueryId(qid);
if (trx) {
await this.finishTransaction(trx);
}
if (typeof reject === 'function') {
// @ts-ignore
return reject(ex);
}
if (ex instanceof Error) {
throw ex;
}
else if (typeof ex === 'string') {
throw new Error(ex);
}
else {
throw new Error('Kmore Error when executing then()', {
cause: ex,
});
}
}
};
void Object.defineProperty(getThenProxy, KmoreProxyKey.getThenProxy, {
...defaultPropDescriptor,
value: Date.now(),
});
return getThenProxy.bind(target);
}
}

@@ -428,0 +350,0 @@ export function KmoreFactory(options) {

@@ -75,2 +75,36 @@ import assert from 'assert';

}
/*
protected extRefTableFnPropertyThen(refTable: KmoreQueryBuilder): KmoreQueryBuilder {
// eslint-disable-next-line @typescript-eslint/unbound-method
const applyThenProxy = new Proxy(refTable.then, {
apply: async (
target: () => Promise<unknown>,
ctx2: KmoreQueryBuilder,
args: unknown[],
) => {
try {
// query response or response data
// undefined means calling builder without tailing then(),
const resp = await Reflect.apply(target, ctx2, args) as unknown
return resp
}
catch (ex) {
const qid = ctx2.kmoreQueryId
const trx = this.getTrxByKmoreQueryId(qid)
if (trx) {
await this.finishTransaction(trx)
}
throw ex
}
},
})
void Object.defineProperty(refTable, 'then', {
...defaultPropDescriptor,
configurable: true,
value: applyThenProxy,
})
return refTable
} */
//# sourceMappingURL=proxy.get.js.map
{
"name": "kmore",
"author": "waiting",
"version": "41.0.0",
"version": "42.0.0",
"description": "A SQL query builder based on knex with powerful TypeScript type support",

@@ -46,4 +46,4 @@ "keywords": [

"cross-env": "7",
"kmore-cli": "^41.0.0",
"kmore-types": "^41.0.0",
"kmore-cli": "^42.0.0",
"kmore-types": "^42.0.0",
"knex": "^2.3.0",

@@ -82,3 +82,3 @@ "pg": "^8.7.3"

},
"gitHead": "8a5bc07b7eab21a8df46b7420779b47f996992e0"
"gitHead": "2c2556670fb197f4c6fbace3fc1737425e34bfa0"
}

@@ -9,2 +9,3 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

QueryContext,
TrxIdQueryMap,
} from './types.js'

@@ -16,2 +17,7 @@

/**
* kmoreTrxId => Set<kmoreQueryId>
*/
readonly abstract trxIdQueryMap: TrxIdQueryMap
/**
* Start a transaction.

@@ -64,7 +70,2 @@ * @param id - For generation of kmoreTrxId

protected abstract extRefTableFnPropertyTransacting(
refTable: KmoreQueryBuilder,
ctx: Context | object,
): KmoreQueryBuilder
protected abstract postProcessResponse(

@@ -75,7 +76,2 @@ result: any,

/**
* Create a proxy for `then` method on QueryBuilder, not on QueryResponse
*/
protected abstract proxyGetThen(options: ProxyGetOptions): KmoreQueryBuilder['then']
}

@@ -82,0 +78,0 @@

@@ -11,3 +11,3 @@ /* eslint-disable max-lines-per-function */

import { KmoreBase, ProxyGetOptions } from './base.js'
import { KmoreBase } from './base.js'
import { defaultPropDescriptor, initialConfig } from './config.js'

@@ -22,2 +22,3 @@ import {

import { PostProcessInput, postProcessResponse, wrapIdentifier } from './helper.js'
import { builderApplyTransactingProxy } from './proxy.apply.js'
import { createQueryBuilderGetProxy } from './proxy.get.js'

@@ -37,3 +38,2 @@ import { extRefTableFnPropertySmartJoin } from './smart-join.js'

OnQueryRespRaw,
KmoreProxyKey,
QueryContext,

@@ -384,3 +384,3 @@ QueryResponse,

)
refTable = this.extRefTableFnPropertyTransacting(refTable, ctx)
refTable = builderApplyTransactingProxy(this, refTable, ctx)
refTable = extRefTableFnPropertySmartJoin(refTable)

@@ -474,41 +474,2 @@ // refTable = this.extRefTableFnPropertyThen(refTable)

protected extRefTableFnPropertyTransacting(
refTable: KmoreQueryBuilder,
ctx: Context | object,
): KmoreQueryBuilder {
// eslint-disable-next-line @typescript-eslint/unbound-method
const applyTransactingProxy = new Proxy(refTable.transacting, {
apply: (
target: KmoreQueryBuilder['transacting'],
ctx2: KmoreQueryBuilder,
args: [KmoreTransaction],
) => {
const [trx] = args
assert(trx?.isTransaction === true, 'trx must be a transaction')
const { kmoreTrxId } = trx
const qid = ctx2.kmoreQueryId as symbol | undefined
if (qid && kmoreTrxId) {
const st = this.trxIdQueryMap.get(kmoreTrxId)
assert(
st,
'Transaction already completed, may committed or rollbacked already. trxIdQueryMap not contains kmoreTrxId:'
+ kmoreTrxId.toString(),
)
st.add(qid)
this.setCtxTrxIdMap(ctx, kmoreTrxId)
}
return Reflect.apply(target, ctx2, args)
},
})
void Object.defineProperty(refTable, 'transacting', {
...defaultPropDescriptor,
writable: true,
value: applyTransactingProxy,
})
return refTable
}
protected postProcessResponse(

@@ -526,102 +487,2 @@ result: any,

/**
* Create a proxy for `then` method on QueryBuilder, not on QueryResponse
*/
protected proxyGetThen(options: ProxyGetOptions): KmoreQueryBuilder['then'] {
const { target, propKey } = options
assert(propKey === 'then', `propKey should be "then", but got: ${propKey.toString()}`)
const getThenProxy = async (
done?: PromiseLike<unknown> | unknown,
reject?: PromiseLike<unknown> | undefined,
) => {
try {
// query response or response data
const resp = await Reflect.apply(target.then, target, []) as unknown
if (typeof resp === 'object' && resp !== null) {
Object.defineProperty(resp, KmoreProxyKey.getThenProxyProcessed, {
...defaultPropDescriptor,
enumerable: false,
writable: true,
value: true,
})
}
if (typeof done === 'function') {
const data = await done(resp) // await for try/catch
return data
}
return resp
}
catch (ex) {
const qid = target.kmoreQueryId
assert(qid, 'kmoreQueryId should be set on QueryBuilder')
const trx = this.getTrxByKmoreQueryId(qid)
if (trx) {
await this.finishTransaction(trx)
}
if (typeof reject === 'function') {
// @ts-ignore
return reject(ex)
}
if (ex instanceof Error) {
throw ex
}
else if (typeof ex === 'string') {
throw new Error(ex)
}
else {
throw new Error('Kmore Error when executing then()', {
cause: ex,
})
}
}
}
void Object.defineProperty(getThenProxy, KmoreProxyKey.getThenProxy, {
...defaultPropDescriptor,
value: Date.now(),
})
return getThenProxy.bind(target) as KmoreQueryBuilder['then']
}
/*
protected extRefTableFnPropertyThen(refTable: KmoreQueryBuilder): KmoreQueryBuilder {
// eslint-disable-next-line @typescript-eslint/unbound-method
const applyThenProxy = new Proxy(refTable.then, {
apply: async (
target: () => Promise<unknown>,
ctx2: KmoreQueryBuilder,
args: unknown[],
) => {
try {
// query response or response data
// undefined means calling builder without tailing then(),
const resp = await Reflect.apply(target, ctx2, args) as unknown
return resp
}
catch (ex) {
const qid = ctx2.kmoreQueryId
const trx = this.getTrxByKmoreQueryId(qid)
if (trx) {
await this.finishTransaction(trx)
}
throw ex
}
},
})
void Object.defineProperty(refTable, 'then', {
...defaultPropDescriptor,
configurable: true,
value: applyThenProxy,
})
return refTable
} */
}

@@ -628,0 +489,0 @@

@@ -97,1 +97,37 @@ import assert from 'assert'

}
/*
protected extRefTableFnPropertyThen(refTable: KmoreQueryBuilder): KmoreQueryBuilder {
// eslint-disable-next-line @typescript-eslint/unbound-method
const applyThenProxy = new Proxy(refTable.then, {
apply: async (
target: () => Promise<unknown>,
ctx2: KmoreQueryBuilder,
args: unknown[],
) => {
try {
// query response or response data
// undefined means calling builder without tailing then(),
const resp = await Reflect.apply(target, ctx2, args) as unknown
return resp
}
catch (ex) {
const qid = ctx2.kmoreQueryId
const trx = this.getTrxByKmoreQueryId(qid)
if (trx) {
await this.finishTransaction(trx)
}
throw ex
}
},
})
void Object.defineProperty(refTable, 'then', {
...defaultPropDescriptor,
configurable: true,
value: applyThenProxy,
})
return refTable
} */

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

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