Socket
Socket
Sign inDemoInstall

@simplysm/sd-orm-common

Package Overview
Dependencies
Maintainers
0
Versions
585
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@simplysm/sd-orm-common - npm Package Compare versions

Comparing version 12.5.17 to 12.5.18

5

dist/QueryBuilder.js
import { NeverEntryError, Uuid } from "@simplysm/sd-core-common";
import { QueryHelper } from "./QueryHelper";
import { SdOrmUtil } from "./utils/SdOrmUtil";
export class QueryBuilder {

@@ -825,5 +826,5 @@ constructor(_dialect) {

SET @sql = CONCAT('${`DELETE ${def.as} FROM ${def.from} as ${def.as} JOIN (
SET @sql = CONCAT('${SdOrmUtil.replaceString(`DELETE ${def.as} FROM ${def.from} as ${def.as} JOIN (
${this.select(def).replace(/\n/g, "\n ").replace("*", def.as + ".*")}
) ${"`_" + def.as.slice(1)} ON 1 = 1 WHERE `.replace(/'/g, "''")}', @cols, ';');
) ${"`_" + def.as.slice(1)} ON 1 = 1 WHERE `)}', @cols, ';');
SELECT @sql;

@@ -830,0 +831,0 @@

4

dist/QueryHelper.js

@@ -404,6 +404,6 @@ import { QueryUnit } from "./QueryUnit";

if (this._dialect === "mysql" || this._dialect === "sqlite") {
return `'${value.replace(/'/g, "''")}'`;
return `'${SdOrmUtil.replaceString(value)}'`;
}
else {
return `N'${value.replace(/'/g, "''")}'`;
return `N'${SdOrmUtil.replaceString(value)}'`;
}

@@ -410,0 +410,0 @@ }

import { IQueryResultParseOption, TEntity, TEntityValue, TQueryValue } from "../commons";
import { Type } from "@simplysm/sd-core-common";
export declare class SdOrmUtil {
static replaceString(str: string): string;
static canConvertToQueryValue(value: any): value is TEntityValue<TQueryValue>;

@@ -5,0 +6,0 @@ static getQueryValueType<T extends TQueryValue>(value: TEntityValue<T>): Type<T> | undefined;

import { DateOnly, DateTime, JsonConvert, Time, Uuid } from "@simplysm/sd-core-common";
import { QueryUnit } from "../QueryUnit";
export class SdOrmUtil {
static replaceString(str) {
return str.replace(/'/g, "''").replace(/\\/g, "\\\\");
}
static canConvertToQueryValue(value) {
return ["undefined", "boolean", "number", "string"].includes(typeof value)
|| value instanceof QueryUnit
|| value instanceof Number
|| value instanceof String
|| value instanceof Boolean
|| value instanceof DateOnly
|| value instanceof DateTime
|| value instanceof Time
|| value instanceof Uuid
|| value instanceof Buffer;
return (["undefined", "boolean", "number", "string"].includes(typeof value) ||
value instanceof QueryUnit ||
value instanceof Number ||
value instanceof String ||
value instanceof Boolean ||
value instanceof DateOnly ||
value instanceof DateTime ||
value instanceof Time ||
value instanceof Uuid ||
value instanceof Buffer);
}

@@ -63,3 +66,5 @@ static getQueryValueType(value) {

// 타입 변환
const data = orgResults.flat().map((item) => {
const data = orgResults
.flat()
.map((item) => {
const obj = {};

@@ -95,8 +100,11 @@ for (const key of Object.keys(item)) {

return obj;
}).filterExists();
})
.filterExists();
// JOIN 에 따른 데이터 구조 설정
const allJoinInfos = option?.joins ? Object.keys(option.joins).map((key) => ({
key,
isSingle: option.joins[key].isSingle
})) : [];
const allJoinInfos = option?.joins
? Object.keys(option.joins).map((key) => ({
key,
isSingle: option.joins[key].isSingle,
}))
: [];
const rootJoinInfos = allJoinInfos.filter((item) => !item.key.includes("."));

@@ -108,11 +116,11 @@ if (rootJoinInfos.length > 0) {

const sourceItemValue = sourceItem[sourceItemKey];
if (["undefined", "boolean", "number", "string"].includes(typeof sourceItemValue)
|| sourceItemValue instanceof Number
|| sourceItemValue instanceof String
|| sourceItemValue instanceof Boolean
|| sourceItemValue instanceof DateOnly
|| sourceItemValue instanceof DateTime
|| sourceItemValue instanceof Time
|| sourceItemValue instanceof Uuid
|| sourceItemValue instanceof Buffer) {
if (["undefined", "boolean", "number", "string"].includes(typeof sourceItemValue) ||
sourceItemValue instanceof Number ||
sourceItemValue instanceof String ||
sourceItemValue instanceof Boolean ||
sourceItemValue instanceof DateOnly ||
sourceItemValue instanceof DateTime ||
sourceItemValue instanceof Time ||
sourceItemValue instanceof Uuid ||
sourceItemValue instanceof Buffer) {
result.push(sourceItemKey + ":" + JsonConvert.stringify(sourceItemValue));

@@ -136,3 +144,4 @@ }

const getObjOrUndefined = (sourceItem) => {
return sourceItem === undefined || Object.keys(sourceItem).every((key) => (sourceItem[key] === undefined /* ||
return sourceItem === undefined ||
Object.keys(sourceItem).every((key) => sourceItem[key] === undefined /* ||
(sourceItem[key] instanceof Array && sourceItem[key].length === 0) ||

@@ -152,3 +161,5 @@ (

getObjOrUndefined(sourceItem[key]) === undefined
)*/)) ? undefined : sourceItem;
)*/)
? undefined
: sourceItem;
};

@@ -214,3 +225,3 @@ const joinToObj = (source, joinKeys) => {

key: item.key.slice(fullJoinKey.length + 1),
isSingle: item.isSingle
isSingle: item.isSingle,
}));

@@ -217,0 +228,0 @@ const joinValue = resultItem[joinInfo.key];

{
"name": "@simplysm/sd-orm-common",
"version": "12.5.17",
"version": "12.5.18",
"description": "심플리즘 패키지 - ORM 모듈 (common)",

@@ -15,8 +15,5 @@ "author": "김석래",

"types": "./dist/index.d.ts",
"engines": {
"node": "20.16.0"
},
"dependencies": {
"@simplysm/sd-core-common": "12.5.17"
"@simplysm/sd-core-common": "12.5.18"
}
}

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

import {TDbContextOption} from "./DbContext";
import { SdOrmUtil } from "./utils/SdOrmUtil";

@@ -992,5 +993,5 @@ export class QueryBuilder {

SET @sql = CONCAT('${`DELETE ${def.as} FROM ${def.from} as ${def.as} JOIN (
SET @sql = CONCAT('${SdOrmUtil.replaceString(`DELETE ${def.as} FROM ${def.from} as ${def.as} JOIN (
${this.select(def).replace(/\n/g, "\n ").replace("*", def.as + ".*")}
) ${"`_" + def.as.slice(1)} ON 1 = 1 WHERE `.replace(/'/g, "''")}', @cols, ';');
) ${"`_" + def.as.slice(1)} ON 1 = 1 WHERE `)}', @cols, ';');
SELECT @sql;

@@ -997,0 +998,0 @@

@@ -492,6 +492,6 @@ import {

if (this._dialect === "mysql" || this._dialect === "sqlite") {
return `'${value.replace(/'/g, "''")}'`;
return `'${SdOrmUtil.replaceString(value)}'`;
}
else {
return `N'${value.replace(/'/g, "''")}'`;
return `N'${SdOrmUtil.replaceString(value)}'`;
}

@@ -498,0 +498,0 @@ }

@@ -1,17 +0,23 @@

import {IQueryResultParseOption, TEntity, TEntityValue, TQueryValue} from "../commons";
import {DateOnly, DateTime, JsonConvert, Time, Type, Uuid} from "@simplysm/sd-core-common";
import {QueryUnit} from "../QueryUnit";
import { IQueryResultParseOption, TEntity, TEntityValue, TQueryValue } from "../commons";
import { DateOnly, DateTime, JsonConvert, Time, Type, Uuid } from "@simplysm/sd-core-common";
import { QueryUnit } from "../QueryUnit";
export class SdOrmUtil {
public static replaceString(str: string) {
return str.replace(/'/g, "''").replace(/\\/g, "\\\\");
}
public static canConvertToQueryValue(value: any): value is TEntityValue<TQueryValue> {
return ["undefined", "boolean", "number", "string"].includes(typeof value)
|| value instanceof QueryUnit
|| value instanceof Number
|| value instanceof String
|| value instanceof Boolean
|| value instanceof DateOnly
|| value instanceof DateTime
|| value instanceof Time
|| value instanceof Uuid
|| value instanceof Buffer;
return (
["undefined", "boolean", "number", "string"].includes(typeof value) ||
value instanceof QueryUnit ||
value instanceof Number ||
value instanceof String ||
value instanceof Boolean ||
value instanceof DateOnly ||
value instanceof DateTime ||
value instanceof Time ||
value instanceof Uuid ||
value instanceof Buffer
);
}

@@ -22,31 +28,21 @@

return value.type as any;
}
else if (value instanceof Number || typeof value === "number") {
} else if (value instanceof Number || typeof value === "number") {
return Number as any;
}
else if (value instanceof String || typeof value === "string") {
} else if (value instanceof String || typeof value === "string") {
return String as any;
}
else if (value instanceof Boolean || typeof value === "boolean") {
} else if (value instanceof Boolean || typeof value === "boolean") {
return Boolean as any;
}
else if (value instanceof DateOnly) {
} else if (value instanceof DateOnly) {
return DateOnly as any;
}
else if (value instanceof DateTime) {
} else if (value instanceof DateTime) {
return DateTime as any;
}
else if (value instanceof Time) {
} else if (value instanceof Time) {
return Time as any;
}
else if (value instanceof Uuid) {
} else if (value instanceof Uuid) {
return Uuid as any;
}
else if (value instanceof Buffer) {
} else if (value instanceof Buffer) {
return Buffer as any;
}
else if (value === undefined) {
} else if (value === undefined) {
return undefined;
}
else {
} else {
throw new Error(`QueryValue 를 추출할 수 있는 타입이 아닙니다: ${JSON.stringify(value)}`);

@@ -70,40 +66,38 @@ }

// 타입 변환
const data: Record<string, any>[] = orgResults.flat().map((item) => {
const obj: Record<string, any> = {};
for (const key of Object.keys(item)) {
if (item[key] == null) {
obj[key] = undefined;
const data: Record<string, any>[] = orgResults
.flat()
.map((item) => {
const obj: Record<string, any> = {};
for (const key of Object.keys(item)) {
if (item[key] == null) {
obj[key] = undefined;
} else if (option?.columns?.[key]?.dataType === "DateTime") {
obj[key] = DateTime.parse(item[key]);
} else if (option?.columns?.[key]?.dataType === "DateOnly") {
obj[key] = DateOnly.parse(item[key]);
} else if (option?.columns?.[key]?.dataType === "Time") {
obj[key] = Time.parse(item[key]);
} else if (option?.columns?.[key]?.dataType === "Uuid") {
obj[key] = new Uuid(item[key]);
} else if (option?.columns?.[key]?.dataType === "Boolean") {
obj[key] = Boolean(item[key]);
} else if (option?.columns?.[key]?.dataType === "Number") {
obj[key] = Number.parseFloat(item[key]);
} else {
obj[key] = item[key];
}
}
else if (option?.columns?.[key]?.dataType === "DateTime") {
obj[key] = DateTime.parse(item[key]);
}
else if (option?.columns?.[key]?.dataType === "DateOnly") {
obj[key] = DateOnly.parse(item[key]);
}
else if (option?.columns?.[key]?.dataType === "Time") {
obj[key] = Time.parse(item[key]);
}
else if (option?.columns?.[key]?.dataType === "Uuid") {
obj[key] = new Uuid(item[key]);
}
else if (option?.columns?.[key]?.dataType === "Boolean") {
obj[key] = Boolean(item[key]);
}
else if (option?.columns?.[key]?.dataType === "Number") {
obj[key] = Number.parseFloat(item[key]);
}
else {
obj[key] = item[key];
}
}
if (Object.keys(obj).length === 0) return undefined;
if (Object.keys(obj).length === 0) return undefined;
return obj;
}).filterExists();
return obj;
})
.filterExists();
// JOIN 에 따른 데이터 구조 설정
const allJoinInfos = option?.joins ? Object.keys(option.joins).map((key) => ({
key,
isSingle: option.joins![key].isSingle
})) : [];
const allJoinInfos = option?.joins
? Object.keys(option.joins).map((key) => ({
key,
isSingle: option.joins![key].isSingle,
}))
: [];
const rootJoinInfos = allJoinInfos.filter((item) => !item.key.includes("."));

@@ -116,15 +110,14 @@ if (rootJoinInfos.length > 0) {

if (
["undefined", "boolean", "number", "string"].includes(typeof sourceItemValue)
|| sourceItemValue instanceof Number
|| sourceItemValue instanceof String
|| sourceItemValue instanceof Boolean
|| sourceItemValue instanceof DateOnly
|| sourceItemValue instanceof DateTime
|| sourceItemValue instanceof Time
|| sourceItemValue instanceof Uuid
|| sourceItemValue instanceof Buffer
["undefined", "boolean", "number", "string"].includes(typeof sourceItemValue) ||
sourceItemValue instanceof Number ||
sourceItemValue instanceof String ||
sourceItemValue instanceof Boolean ||
sourceItemValue instanceof DateOnly ||
sourceItemValue instanceof DateTime ||
sourceItemValue instanceof Time ||
sourceItemValue instanceof Uuid ||
sourceItemValue instanceof Buffer
) {
result.push(sourceItemKey + ":" + JsonConvert.stringify(sourceItemValue));
}
else {
} else {
result.push(sourceItemKey + ":" + getObjKeyString(sourceItemValue));

@@ -139,3 +132,4 @@ }

for (const sourceItemKey of Object.keys(sourceItem)) {
if (joinKeys.some((joinKey) => sourceItemKey === joinKey || sourceItemKey.startsWith(joinKey + "."))) continue;
if (joinKeys.some((joinKey) => sourceItemKey === joinKey || sourceItemKey.startsWith(joinKey + ".")))
continue;
result[sourceItemKey] = sourceItem[sourceItemKey];

@@ -147,4 +141,6 @@ }

const getObjOrUndefined = (sourceItem: Record<string, any> | undefined): Record<string, any> | undefined => {
return sourceItem === undefined || Object.keys(sourceItem).every((key) => (
sourceItem[key] === undefined/* ||
return sourceItem === undefined ||
Object.keys(sourceItem).every(
(key) =>
sourceItem[key] === undefined /* ||
(sourceItem[key] instanceof Array && sourceItem[key].length === 0) ||

@@ -164,4 +160,6 @@ (

getObjOrUndefined(sourceItem[key]) === undefined
)*/
)) ? undefined : sourceItem;
)*/,
)
? undefined
: sourceItem;
};

@@ -178,4 +176,3 @@

resultItem[joinKey][sourceItemKey.slice(joinKey.length + 1)] = sourceItem[sourceItemKey];
}
else {
} else {
resultItem[sourceItemKey] = sourceItem[sourceItemKey];

@@ -204,5 +201,4 @@ }

}
}
else {
const newGroupedItem: Record<string, any> = {...groupedKeyObj};
} else {
const newGroupedItem: Record<string, any> = { ...groupedKeyObj };
for (const joinKey of joinKeys) {

@@ -225,6 +221,10 @@ const sourceItemValue = getObjOrUndefined(sourceItem[joinKey]);

const doing = (source: Record<string, any>[], joinInfos: {
key: string;
isSingle: boolean
}[], parentKey?: string): Record<string, any>[] => {
const doing = (
source: Record<string, any>[],
joinInfos: {
key: string;
isSingle: boolean;
}[],
parentKey?: string,
): Record<string, any>[] => {
const joinKeys = joinInfos.map((item) => item.key);

@@ -236,6 +236,9 @@ const result = grouping(joinToObj(source, joinKeys), joinKeys);

const childJoinInfos = allJoinInfos
.filter((item) => item.key.startsWith(fullJoinKey + ".") && !item.key.slice(fullJoinKey.length + 1).includes("."))
.filter(
(item) =>
item.key.startsWith(fullJoinKey + ".") && !item.key.slice(fullJoinKey.length + 1).includes("."),
)
.map((item) => ({
key: item.key.slice(fullJoinKey.length + 1),
isSingle: item.isSingle
isSingle: item.isSingle,
}));

@@ -248,21 +251,16 @@ const joinValue = resultItem[joinInfo.key];

throw new Error("중복");
}
else {
} else {
resultItem[joinInfo.key] = childJoinValue[0];
}
}
else {
} else {
resultItem[joinInfo.key] = childJoinValue;
}
}
else {
} else {
if (joinInfo.isSingle) {
if (joinValue.length > 1) {
throw new Error("중복");
}
else {
} else {
resultItem[joinInfo.key] = joinValue[0];
}
}
else {
} else {
resultItem[joinInfo.key] = joinValue;

@@ -269,0 +267,0 @@ }

{
"extends": "../../tsconfig.json",
"extends": "../tsconfig.json",
"compilerOptions": {
"lib": [
"ES2021"
],
"outDir": "./dist"
}
"lib": ["ES2021"],
"outDir": "./dist",
"types": ["node"]
},
"files": ["./src/index.ts"]
}

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