@volcanicminds/typeorm 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -147
- package/dist/index.js.map +1 -1
- package/dist/lib/entities/change.d.ts +1 -0
- package/dist/lib/entities/change.d.ts.map +1 -0
- package/dist/lib/entities/change.js +2 -6
- package/dist/lib/entities/change.js.map +1 -1
- package/dist/lib/entities/token.d.ts +1 -0
- package/dist/lib/entities/token.d.ts.map +1 -0
- package/dist/lib/entities/token.js +2 -6
- package/dist/lib/entities/token.js.map +1 -1
- package/dist/lib/entities/user.d.ts +1 -0
- package/dist/lib/entities/user.d.ts.map +1 -0
- package/dist/lib/entities/user.js +2 -6
- package/dist/lib/entities/user.js.map +1 -1
- package/dist/lib/loader/dataBaseManager.d.ts +1 -0
- package/dist/lib/loader/dataBaseManager.d.ts.map +1 -0
- package/dist/lib/loader/dataBaseManager.js +29 -83
- package/dist/lib/loader/dataBaseManager.js.map +1 -1
- package/dist/lib/loader/entities.d.ts +1 -0
- package/dist/lib/loader/entities.d.ts.map +1 -0
- package/dist/lib/loader/entities.js +10 -8
- package/dist/lib/loader/entities.js.map +1 -1
- package/dist/lib/loader/tokenManager.d.ts +1 -0
- package/dist/lib/loader/tokenManager.d.ts.map +1 -0
- package/dist/lib/loader/tokenManager.js +101 -138
- package/dist/lib/loader/tokenManager.js.map +1 -1
- package/dist/lib/loader/userManager.d.ts +1 -0
- package/dist/lib/loader/userManager.d.ts.map +1 -0
- package/dist/lib/loader/userManager.js +234 -321
- package/dist/lib/loader/userManager.js.map +1 -1
- package/dist/lib/query/builder.d.ts +1 -0
- package/dist/lib/query/builder.d.ts.map +1 -0
- package/dist/lib/query/builder.js +4 -8
- package/dist/lib/query/builder.js.map +1 -1
- package/dist/lib/query/parser.d.ts +1 -0
- package/dist/lib/query/parser.d.ts.map +1 -0
- package/dist/lib/query/parser.js +2 -7
- package/dist/lib/query/parser.js.map +1 -1
- package/dist/lib/query.d.ts +1 -0
- package/dist/lib/query.d.ts.map +1 -0
- package/dist/lib/query.js +78 -110
- package/dist/lib/query.js.map +1 -1
- package/dist/lib/util/error.d.ts +5 -0
- package/dist/lib/util/error.d.ts.map +1 -0
- package/dist/lib/util/error.js +8 -0
- package/dist/lib/util/error.js.map +1 -0
- package/dist/lib/util/logger.d.ts +1 -0
- package/dist/lib/util/logger.d.ts.map +1 -0
- package/dist/lib/util/logger.js +12 -26
- package/dist/lib/util/logger.js.map +1 -1
- package/dist/lib/util/yn.d.ts +1 -0
- package/dist/lib/util/yn.d.ts.map +1 -0
- package/dist/lib/util/yn.js +1 -3
- package/dist/lib/util/yn.js.map +1 -1
- package/lib/entities/change.ts +11 -0
- package/lib/entities/token.ts +17 -0
- package/lib/entities/user.ts +24 -0
- package/lib/loader/dataBaseManager.ts +37 -0
- package/lib/loader/entities.ts +35 -0
- package/lib/loader/tokenManager.ts +128 -0
- package/lib/loader/userManager.ts +304 -0
- package/lib/query/builder.ts +38 -0
- package/lib/query/parser.ts +29 -0
- package/lib/query.ts +244 -0
- package/lib/util/error.ts +7 -0
- package/lib/util/logger.ts +23 -0
- package/lib/util/yn.ts +19 -0
- package/package.json +18 -26
- package/esm/index.d.ts +0 -12
- package/esm/index.js +0 -140
- package/esm/index.js.map +0 -1
- package/esm/lib/entities/change.d.ts +0 -10
- package/esm/lib/entities/change.js +0 -8
- package/esm/lib/entities/change.js.map +0 -1
- package/esm/lib/entities/token.d.ts +0 -15
- package/esm/lib/entities/token.js +0 -8
- package/esm/lib/entities/token.js.map +0 -1
- package/esm/lib/entities/user.d.ts +0 -22
- package/esm/lib/entities/user.js +0 -8
- package/esm/lib/entities/user.js.map +0 -1
- package/esm/lib/loader/dataBaseManager.d.ts +0 -4
- package/esm/lib/loader/dataBaseManager.js +0 -76
- package/esm/lib/loader/dataBaseManager.js.map +0 -1
- package/esm/lib/loader/entities.d.ts +0 -5
- package/esm/lib/loader/entities.js +0 -28
- package/esm/lib/loader/entities.js.map +0 -1
- package/esm/lib/loader/tokenManager.d.ts +0 -21
- package/esm/lib/loader/tokenManager.js +0 -128
- package/esm/lib/loader/tokenManager.js.map +0 -1
- package/esm/lib/loader/userManager.d.ts +0 -32
- package/esm/lib/loader/userManager.js +0 -341
- package/esm/lib/loader/userManager.js.map +0 -1
- package/esm/lib/query/builder.d.ts +0 -1
- package/esm/lib/query/builder.js +0 -37
- package/esm/lib/query/builder.js.map +0 -1
- package/esm/lib/query/parser.d.ts +0 -1
- package/esm/lib/query/parser.js +0 -32
- package/esm/lib/query/parser.js.map +0 -1
- package/esm/lib/query.d.ts +0 -33
- package/esm/lib/query.js +0 -210
- package/esm/lib/query.js.map +0 -1
- package/esm/lib/util/logger.d.ts +0 -6
- package/esm/lib/util/logger.js +0 -33
- package/esm/lib/util/logger.js.map +0 -1
- package/esm/lib/util/yn.d.ts +0 -1
- package/esm/lib/util/yn.js +0 -17
- package/esm/lib/util/yn.js.map +0 -1
package/lib/query.ts
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Not,
|
|
3
|
+
Like,
|
|
4
|
+
ILike,
|
|
5
|
+
Raw,
|
|
6
|
+
Equal,
|
|
7
|
+
IsNull,
|
|
8
|
+
In,
|
|
9
|
+
Between,
|
|
10
|
+
MoreThan,
|
|
11
|
+
MoreThanOrEqual,
|
|
12
|
+
LessThan,
|
|
13
|
+
LessThanOrEqual
|
|
14
|
+
} from 'typeorm'
|
|
15
|
+
import { parseLogicExpression } from './query/parser.js'
|
|
16
|
+
import { buildWhereFromAst } from './query/builder.js'
|
|
17
|
+
|
|
18
|
+
const evalOrder = (val: string = '') => (['desc', 'd', 'false', '1'].includes(val.toLowerCase()) ? 'desc' : 'asc')
|
|
19
|
+
|
|
20
|
+
export const useOrder = (order: string[] = []) => {
|
|
21
|
+
const result = {}
|
|
22
|
+
order
|
|
23
|
+
.filter((o) => !!o)
|
|
24
|
+
.forEach((o: string) => {
|
|
25
|
+
const parts = o.split(':')
|
|
26
|
+
const fieldFullPath = parts[0].split('.')
|
|
27
|
+
const sortType = evalOrder(parts[1])
|
|
28
|
+
|
|
29
|
+
let target = result
|
|
30
|
+
while (fieldFullPath.length > 1) {
|
|
31
|
+
const fieldPath: string = fieldFullPath.shift() || ''
|
|
32
|
+
target = target[fieldPath] = target[fieldPath] || {}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const fieldName = fieldFullPath[0]
|
|
36
|
+
|
|
37
|
+
target[fieldName] = sortType
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
return result
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const typecastValue = (value: any) => {
|
|
44
|
+
if (typeof value !== 'string') return value
|
|
45
|
+
const lowerValue = value.toLowerCase()
|
|
46
|
+
if (lowerValue === 'true') return true
|
|
47
|
+
if (lowerValue === 'false') return false
|
|
48
|
+
if (lowerValue === 'null') return null
|
|
49
|
+
return value
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const useWhere = (where: any, repo?: any) => {
|
|
53
|
+
const aliasMap = new Map<string, any>()
|
|
54
|
+
const isTargetMongo = isMongo(repo)
|
|
55
|
+
const val = (v) => v || 'notFound'
|
|
56
|
+
|
|
57
|
+
const reservedOperators = {
|
|
58
|
+
':null': (v) => (typecastValue(v) === false ? Not(IsNull()) : IsNull()),
|
|
59
|
+
':notNull': (v) => (typecastValue(v) === true ? Not(IsNull()) : IsNull()),
|
|
60
|
+
':raw': (v) => Raw((alias) => `${alias} ${v}`),
|
|
61
|
+
':in': (v) => In(val(v).split(',').map(typecastValue)),
|
|
62
|
+
':nin': (v) => Not(In(val(v).split(',').map(typecastValue))),
|
|
63
|
+
':likei': (v) => (isTargetMongo ? new RegExp(val(v), 'i') : ILike(`%${val(v)}%`)),
|
|
64
|
+
':containsi': (v) => (isTargetMongo ? new RegExp(val(v), 'i') : ILike(`%${val(v)}%`)),
|
|
65
|
+
':ncontainsi': (v) => (isTargetMongo ? Not(new RegExp(val(v), 'i')) : Not(ILike(`%${val(v)}%`))),
|
|
66
|
+
':startsi': (v) => (isTargetMongo ? new RegExp(`^${val(v)}`, 'i') : ILike(`${val(v)}%`)),
|
|
67
|
+
':endsi': (v) => (isTargetMongo ? new RegExp(`${val(v)}$`, 'i') : ILike(`%${val(v)}`)),
|
|
68
|
+
':eqi': (v) => (isTargetMongo ? new RegExp(`^${val(v)}$`, 'i') : ILike(v)),
|
|
69
|
+
':neqi': (v) => (isTargetMongo ? Not(new RegExp(`^${val(v)}$`, 'i')) : Not(ILike(v))),
|
|
70
|
+
':like': (v) => Like(`${val(v)}`),
|
|
71
|
+
':contains': (v) => Like(`%${val(v)}%`),
|
|
72
|
+
':ncontains': (v) => Not(Like(`%${val(v)}%`)),
|
|
73
|
+
':starts': (v) => Like(`${val(v)}%`),
|
|
74
|
+
':ends': (v) => Like(`%${val(v)}`),
|
|
75
|
+
':eq': (v) => {
|
|
76
|
+
const typedValue = typecastValue(v)
|
|
77
|
+
if (typedValue === null) return IsNull()
|
|
78
|
+
return isTargetMongo ? typedValue : Equal(typedValue)
|
|
79
|
+
},
|
|
80
|
+
':neq': (v) => Not(Equal(typecastValue(v))),
|
|
81
|
+
':gt': (v) => MoreThan(v),
|
|
82
|
+
':ge': (v) => MoreThanOrEqual(v),
|
|
83
|
+
':lt': (v) => LessThan(v),
|
|
84
|
+
':le': (v) => LessThanOrEqual(v),
|
|
85
|
+
':between': (v) => {
|
|
86
|
+
const s = v?.split(':')
|
|
87
|
+
return s?.length == 2 ? Between(s[0], s[1]) : v
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const reservedWords = Object.keys(reservedOperators).join('|')
|
|
92
|
+
const aliasRegex = /\[([^\]]+)\]$/
|
|
93
|
+
|
|
94
|
+
const allConditions = {}
|
|
95
|
+
|
|
96
|
+
for (const rawKey in where) {
|
|
97
|
+
let alias = ''
|
|
98
|
+
let key = rawKey
|
|
99
|
+
|
|
100
|
+
const aliasMatch = rawKey.match(aliasRegex)
|
|
101
|
+
if (aliasMatch) {
|
|
102
|
+
alias = aliasMatch[1]
|
|
103
|
+
key = rawKey.replace(aliasRegex, '')
|
|
104
|
+
} else {
|
|
105
|
+
alias = key
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const m = key.match(new RegExp(`(${reservedWords})\\b`, 'ig'))
|
|
109
|
+
const operator = m?.length ? m[0] : ':eq'
|
|
110
|
+
const fullPath = key.replace(operator, '')
|
|
111
|
+
const parts = fullPath.split('.')
|
|
112
|
+
let value = where[rawKey]
|
|
113
|
+
|
|
114
|
+
if (operator && reservedOperators[operator]) {
|
|
115
|
+
value = reservedOperators[operator](value)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let condition = {}
|
|
119
|
+
let target = condition
|
|
120
|
+
while (parts.length > 1) {
|
|
121
|
+
const part: string = parts.shift() || ''
|
|
122
|
+
target = target[part] = target[part] || {}
|
|
123
|
+
}
|
|
124
|
+
target[parts[0]] = value
|
|
125
|
+
|
|
126
|
+
aliasMap.set(alias, condition)
|
|
127
|
+
Object.assign(allConditions, condition)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { allConditions, aliasMap }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function applyQuery(data, extraWhere, repo) {
|
|
134
|
+
const { page: p = 1, pageSize = 25, skip: sk = 0, take: tk = 0, sort: s, _logic, ...where } = data
|
|
135
|
+
const page: number = (p < 1 ? 1 : p) - 1
|
|
136
|
+
const take: number = tk || pageSize
|
|
137
|
+
const skip: number = sk || page * pageSize
|
|
138
|
+
const order: string[] = !Array.isArray(s) ? [s] : s
|
|
139
|
+
|
|
140
|
+
const query = {} as {
|
|
141
|
+
skip?: number
|
|
142
|
+
take?: number
|
|
143
|
+
order?: object
|
|
144
|
+
where?: object | object[]
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (skip) query.skip = skip
|
|
148
|
+
if (take) query.take = take
|
|
149
|
+
if (order) query.order = useOrder(order)
|
|
150
|
+
|
|
151
|
+
const { allConditions, aliasMap } = useWhere(where, repo)
|
|
152
|
+
|
|
153
|
+
if (_logic) {
|
|
154
|
+
try {
|
|
155
|
+
const ast = parseLogicExpression(_logic)
|
|
156
|
+
query.where = buildWhereFromAst(ast, aliasMap, isMongo(repo))
|
|
157
|
+
} catch (e) {
|
|
158
|
+
console.error('Volcanic-TypeORM: Error parsing _logic parameter.', e)
|
|
159
|
+
query.where = allConditions
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
query.where = allConditions
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (extraWhere) {
|
|
166
|
+
const { allConditions: extraConditions } = useWhere(extraWhere, repo)
|
|
167
|
+
if (query.where && Object.keys(query.where).length > 0) {
|
|
168
|
+
if (isMongo(repo)) {
|
|
169
|
+
query.where = { $and: [query.where, extraConditions] }
|
|
170
|
+
} else {
|
|
171
|
+
query.where = { ...query.where, ...extraConditions }
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
query.where = extraConditions
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return query
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export async function executeFindQuery(
|
|
182
|
+
repo: any,
|
|
183
|
+
relations: any = {},
|
|
184
|
+
data: any = {},
|
|
185
|
+
extraWhere: any = {},
|
|
186
|
+
extraOptions: any = {}
|
|
187
|
+
) {
|
|
188
|
+
const extra = applyQuery(data, extraWhere, repo)
|
|
189
|
+
|
|
190
|
+
const [records = [], totalCount] = await repo.findAndCount({
|
|
191
|
+
relations: relations,
|
|
192
|
+
...extra,
|
|
193
|
+
...extraOptions
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return {
|
|
197
|
+
records,
|
|
198
|
+
headers: {
|
|
199
|
+
'v-count': records.length,
|
|
200
|
+
'v-total': totalCount,
|
|
201
|
+
'v-page': data.page || 1,
|
|
202
|
+
'v-pageSize': extra.take,
|
|
203
|
+
'v-pageCount': Math.ceil(extra.take ? totalCount / extra.take : 1)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function executeFindView(viewEntity: any, data: any = {}, extraWhere: any = {}, extraOptions: any = {}) {
|
|
209
|
+
const extra = applyQuery(data, extraWhere, null)
|
|
210
|
+
|
|
211
|
+
const [records = [], totalCount] = await global.connection.manager.findAndCount(viewEntity, {
|
|
212
|
+
...extra,
|
|
213
|
+
...extraOptions
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
records,
|
|
218
|
+
headers: {
|
|
219
|
+
'v-count': records.length,
|
|
220
|
+
'v-total': totalCount,
|
|
221
|
+
'v-page': data.page || 1,
|
|
222
|
+
'v-pageSize': extra.take,
|
|
223
|
+
'v-pageCount': Math.ceil(extra.take ? totalCount / extra.take : 1)
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export async function executeCountQuery(repo: any, data = {}, extraWhere: any = {}) {
|
|
229
|
+
const { where = {} } = applyQuery(data, extraWhere, repo)
|
|
230
|
+
return await repo.count(isMongo(repo) ? where : { where: where })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export async function executeCountView(viewEntity: any, data = {}, extraWhere: any = {}) {
|
|
234
|
+
const { where = {} } = applyQuery(data, extraWhere, null)
|
|
235
|
+
return await global.connection.manager.count(viewEntity, { where: where })
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function getType(repo) {
|
|
239
|
+
return repo?.manager?.connection?.options?.type || 'pg'
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function isMongo(repo) {
|
|
243
|
+
return getType(repo) === 'mongodb'
|
|
244
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function trace(data) {
|
|
2
|
+
global.isLoggingEnabled && global.log?.trace && global.log.trace(data)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function debug(data) {
|
|
6
|
+
global.isLoggingEnabled && global.log?.debug && global.log.debug(data)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function info(data) {
|
|
10
|
+
global.isLoggingEnabled && global.log?.info && global.log.info(data)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function warn(data) {
|
|
14
|
+
global.isLoggingEnabled && global.log?.warn && global.log.warn(data)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function error(data) {
|
|
18
|
+
global.isLoggingEnabled && global.log?.error && global.log.error(data)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function fatal(data) {
|
|
22
|
+
global.isLoggingEnabled && global.log?.fatal && global.log.fatal(data)
|
|
23
|
+
}
|
package/lib/util/yn.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
export default function yn(value: any, defaultValue: boolean): boolean {
|
|
4
|
+
if (value === undefined || value === null) {
|
|
5
|
+
return defaultValue
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const val = String(value).trim()
|
|
9
|
+
|
|
10
|
+
if (/^(?:y|yes|true|1|on)$/i.test(val)) {
|
|
11
|
+
return true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (/^(?:n|no|false|0|off)$/i.test(val)) {
|
|
15
|
+
return false
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return defaultValue || false
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volcanicminds/typeorm",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"license": "MIT",
|
|
5
6
|
"description": "TypeORM for the volcanic (minds) backend",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"volcanic",
|
|
8
|
-
"open source",
|
|
9
9
|
"database",
|
|
10
10
|
"typeorm",
|
|
11
11
|
"typescript",
|
|
12
|
-
"
|
|
12
|
+
"esm"
|
|
13
13
|
],
|
|
14
14
|
"main": "dist/index.js",
|
|
15
|
-
"module": "
|
|
15
|
+
"module": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
16
25
|
"files": [
|
|
17
26
|
"dist",
|
|
18
|
-
"
|
|
19
|
-
"src"
|
|
27
|
+
"lib"
|
|
20
28
|
],
|
|
21
29
|
"scripts": {
|
|
22
|
-
"clean": "rm -rf dist
|
|
30
|
+
"clean": "rm -rf dist",
|
|
23
31
|
"prebuild": "npm run clean",
|
|
24
|
-
"build
|
|
25
|
-
"
|
|
26
|
-
"build": "npm run build:esm && npm run build:cjs",
|
|
27
|
-
"compile": "npm run build",
|
|
28
|
-
"reset": "npm install && npm update && npm run compile",
|
|
32
|
+
"build": "tsc",
|
|
33
|
+
"reset": "npm install && npm update && npm run build",
|
|
29
34
|
"upgrade-deps": "npx npm-check-updates -u",
|
|
30
35
|
"combine": "node combine.js"
|
|
31
36
|
},
|
|
@@ -38,26 +43,13 @@
|
|
|
38
43
|
},
|
|
39
44
|
"devDependencies": {
|
|
40
45
|
"@types/node": "^24.10.0",
|
|
41
|
-
"
|
|
46
|
+
"tsx": "^4.19.2",
|
|
42
47
|
"typescript": "^5.9.3"
|
|
43
48
|
},
|
|
44
49
|
"repository": {
|
|
45
50
|
"type": "git",
|
|
46
51
|
"url": "git+https://github.com/volcanicminds/volcanic-database-typeorm.git"
|
|
47
52
|
},
|
|
48
|
-
"homepage": "https://volcanicminds.com",
|
|
49
|
-
"bugs": {
|
|
50
|
-
"url": "https://github.com/volcanicminds/volcanic-backend/issues"
|
|
51
|
-
},
|
|
52
|
-
"author": "Volcanic Minds <developers@volcanicminds.com> (https://volcanicminds.com)",
|
|
53
|
-
"maintainers": [
|
|
54
|
-
"Developers <developers@volcanicminds.com> (https://volcanicminds.com)"
|
|
55
|
-
],
|
|
56
|
-
"types": "./dist/index.d.ts",
|
|
57
|
-
"directories": {
|
|
58
|
-
"lib": "lib",
|
|
59
|
-
"test": "test"
|
|
60
|
-
},
|
|
61
53
|
"engines": {
|
|
62
54
|
"node": ">=24"
|
|
63
55
|
}
|
package/esm/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { DataSource } from 'typeorm';
|
|
3
|
-
import * as userManager from './lib/loader/userManager';
|
|
4
|
-
import * as tokenManager from './lib/loader/tokenManager';
|
|
5
|
-
import * as dataBaseManager from './lib/loader/dataBaseManager';
|
|
6
|
-
import { User } from './lib/entities/user';
|
|
7
|
-
import { Token } from './lib/entities/token';
|
|
8
|
-
import { Change } from './lib/entities/change';
|
|
9
|
-
import { applyQuery, executeCountQuery, executeCountView, executeFindQuery, executeFindView, useOrder, useWhere } from './lib/query';
|
|
10
|
-
declare function start(options: any): Promise<DataSource>;
|
|
11
|
-
export { Database } from './types/global';
|
|
12
|
-
export { start, User, Token, Change, userManager, tokenManager, dataBaseManager, DataSource, applyQuery, executeCountQuery, executeCountView, executeFindQuery, executeFindView, useOrder, useWhere };
|
package/esm/index.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.useWhere = exports.useOrder = exports.executeFindView = exports.executeFindQuery = exports.executeCountView = exports.executeCountQuery = exports.applyQuery = exports.DataSource = exports.dataBaseManager = exports.tokenManager = exports.userManager = exports.Change = exports.Token = exports.User = void 0;
|
|
40
|
-
exports.start = start;
|
|
41
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
42
|
-
dotenv_1.default.config();
|
|
43
|
-
require("reflect-metadata");
|
|
44
|
-
const typeorm_1 = require("typeorm");
|
|
45
|
-
Object.defineProperty(exports, "DataSource", { enumerable: true, get: function () { return typeorm_1.DataSource; } });
|
|
46
|
-
const loaderEntities = __importStar(require("./lib/loader/entities"));
|
|
47
|
-
const userManager = __importStar(require("./lib/loader/userManager"));
|
|
48
|
-
exports.userManager = userManager;
|
|
49
|
-
const tokenManager = __importStar(require("./lib/loader/tokenManager"));
|
|
50
|
-
exports.tokenManager = tokenManager;
|
|
51
|
-
const dataBaseManager = __importStar(require("./lib/loader/dataBaseManager"));
|
|
52
|
-
exports.dataBaseManager = dataBaseManager;
|
|
53
|
-
const user_1 = require("./lib/entities/user");
|
|
54
|
-
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_1.User; } });
|
|
55
|
-
const token_1 = require("./lib/entities/token");
|
|
56
|
-
Object.defineProperty(exports, "Token", { enumerable: true, get: function () { return token_1.Token; } });
|
|
57
|
-
const change_1 = require("./lib/entities/change");
|
|
58
|
-
Object.defineProperty(exports, "Change", { enumerable: true, get: function () { return change_1.Change; } });
|
|
59
|
-
const query_1 = require("./lib/query");
|
|
60
|
-
Object.defineProperty(exports, "applyQuery", { enumerable: true, get: function () { return query_1.applyQuery; } });
|
|
61
|
-
Object.defineProperty(exports, "executeCountQuery", { enumerable: true, get: function () { return query_1.executeCountQuery; } });
|
|
62
|
-
Object.defineProperty(exports, "executeCountView", { enumerable: true, get: function () { return query_1.executeCountView; } });
|
|
63
|
-
Object.defineProperty(exports, "executeFindQuery", { enumerable: true, get: function () { return query_1.executeFindQuery; } });
|
|
64
|
-
Object.defineProperty(exports, "executeFindView", { enumerable: true, get: function () { return query_1.executeFindView; } });
|
|
65
|
-
Object.defineProperty(exports, "useOrder", { enumerable: true, get: function () { return query_1.useOrder; } });
|
|
66
|
-
Object.defineProperty(exports, "useWhere", { enumerable: true, get: function () { return query_1.useWhere; } });
|
|
67
|
-
const log = __importStar(require("./lib/util/logger"));
|
|
68
|
-
const yn_1 = __importDefault(require("./lib/util/yn"));
|
|
69
|
-
async function start(options) {
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
if (global.npmDebugServerStarted) {
|
|
72
|
-
options = {
|
|
73
|
-
type: 'postgres',
|
|
74
|
-
host: '127.0.0.1',
|
|
75
|
-
port: 5432,
|
|
76
|
-
username: 'vminds',
|
|
77
|
-
password: 'vminds',
|
|
78
|
-
database: 'vminds',
|
|
79
|
-
synchronize: true,
|
|
80
|
-
logging: true,
|
|
81
|
-
logger: ''
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
if (options == null || Object.keys(options).length == 0) {
|
|
85
|
-
throw new Error('Volcanic Database: options not specified');
|
|
86
|
-
}
|
|
87
|
-
const { LOG_DB_LEVEL = 'warn', LOG_COLORIZE = true, DB_SYNCHRONIZE_SCHEMA_AT_STARTUP = false } = process.env;
|
|
88
|
-
const logLevel = LOG_DB_LEVEL === 'trace'
|
|
89
|
-
? 'all'
|
|
90
|
-
: LOG_DB_LEVEL === 'debug'
|
|
91
|
-
? 'query'
|
|
92
|
-
: LOG_DB_LEVEL === 'info'
|
|
93
|
-
? 'info'
|
|
94
|
-
: LOG_DB_LEVEL === 'warn'
|
|
95
|
-
? 'warn'
|
|
96
|
-
: LOG_DB_LEVEL === 'error'
|
|
97
|
-
? 'error'
|
|
98
|
-
: LOG_DB_LEVEL;
|
|
99
|
-
global.cacheTimeout = (options === null || options === void 0 ? void 0 : options.cacheTimeout) || 30000;
|
|
100
|
-
global.isLoggingEnabled = (options === null || options === void 0 ? void 0 : options.logging) || true;
|
|
101
|
-
const { classes, repositories, entities } = loaderEntities.load();
|
|
102
|
-
options.entities = [...(options.entities || []), ...(entities || [])];
|
|
103
|
-
options.logger = LOG_COLORIZE ? 'advanced-console' : 'simple-console';
|
|
104
|
-
options.logging = logLevel;
|
|
105
|
-
options.synchronize = false;
|
|
106
|
-
return new typeorm_1.DataSource(options)
|
|
107
|
-
.initialize()
|
|
108
|
-
.then(async (ds) => {
|
|
109
|
-
if ((0, yn_1.default)(DB_SYNCHRONIZE_SCHEMA_AT_STARTUP, false)) {
|
|
110
|
-
log.warn('Database schema synchronization started');
|
|
111
|
-
await ds.synchronize();
|
|
112
|
-
log.warn('Database schema synchronization finished');
|
|
113
|
-
}
|
|
114
|
-
const repository = {};
|
|
115
|
-
Object.keys(repositories).map((r) => (repository[r] = ds.getRepository(repositories[r])));
|
|
116
|
-
global.connection = ds;
|
|
117
|
-
global.entity = classes;
|
|
118
|
-
global.repository = repository;
|
|
119
|
-
return resolve(ds);
|
|
120
|
-
})
|
|
121
|
-
.catch((error) => reject(error));
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
module.exports = {
|
|
125
|
-
start,
|
|
126
|
-
User: user_1.User,
|
|
127
|
-
Token: token_1.Token,
|
|
128
|
-
Change: change_1.Change,
|
|
129
|
-
userManager,
|
|
130
|
-
tokenManager,
|
|
131
|
-
dataBaseManager,
|
|
132
|
-
applyQuery: query_1.applyQuery,
|
|
133
|
-
executeCountQuery: query_1.executeCountQuery,
|
|
134
|
-
executeCountView: query_1.executeCountView,
|
|
135
|
-
executeFindQuery: query_1.executeFindQuery,
|
|
136
|
-
executeFindView: query_1.executeFindView,
|
|
137
|
-
useOrder: query_1.useOrder,
|
|
138
|
-
useWhere: query_1.useWhere
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGV,sBAAK;AAlGP,oDAA2B;AAC3B,gBAAM,CAAC,MAAM,EAAE,CAAA;AAEf,4BAAyB;AACzB,qCAAoC;AAqGlC,2FArGO,oBAAU,OAqGP;AApGZ,sEAAuD;AACvD,sEAAuD;AAgGrD,kCAAW;AA/Fb,wEAAyD;AAgGvD,oCAAY;AA/Fd,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rB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAEzF,MAAM,CAAC,UAAU,GAAG,EAAE,CAAA;YACtB,MAAM,CAAC,MAAM,GAAG,OAAO,CAAA;YACvB,MAAM,CAAC,UAAU,GAAG,UAAU,CAAA;YAC9B,OAAO,OAAO,CAAC,EAAE,CAAC,CAAA;QACpB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC;AAqBD,MAAM,CAAC,OAAO,GAAG;IACf,KAAK;IACL,IAAI,EAAJ,WAAI;IACJ,KAAK,EAAL,aAAK;IACL,MAAM,EAAN,eAAM;IACN,WAAW;IACX,YAAY;IACZ,eAAe;IACf,UAAU,EAAV,kBAAU;IACV,iBAAiB,EAAjB,yBAAiB;IACjB,gBAAgB,EAAhB,wBAAgB;IAChB,gBAAgB,EAAhB,wBAAgB;IAChB,eAAe,EAAf,uBAAe;IACf,QAAQ,EAAR,gBAAQ;IACR,QAAQ,EAAR,gBAAQ;CACT,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BaseEntity } from 'typeorm';
|
|
2
|
-
export declare abstract class Change extends BaseEntity {
|
|
3
|
-
abstract createdAt: Date;
|
|
4
|
-
abstract updatedAt: Date;
|
|
5
|
-
abstract userId: string;
|
|
6
|
-
abstract status: string;
|
|
7
|
-
abstract entityName: string;
|
|
8
|
-
abstract entityId: string;
|
|
9
|
-
abstract contents: object;
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"change.js","sourceRoot":"","sources":["../../../lib/entities/change.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,MAAO,SAAQ,oBAAU;CAQ9C;AARD,wBAQC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseEntity } from 'typeorm';
|
|
2
|
-
export declare abstract class Token extends BaseEntity {
|
|
3
|
-
abstract externalId: string;
|
|
4
|
-
abstract name: string;
|
|
5
|
-
abstract description: string;
|
|
6
|
-
abstract blocked: boolean;
|
|
7
|
-
abstract blockedReason: string;
|
|
8
|
-
abstract blockedAt: Date;
|
|
9
|
-
abstract roles: string[];
|
|
10
|
-
abstract createdAt: Date;
|
|
11
|
-
abstract updatedAt: Date;
|
|
12
|
-
abstract deletedAt: Date;
|
|
13
|
-
abstract setId(id: any): any;
|
|
14
|
-
abstract getId(): any;
|
|
15
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token.js","sourceRoot":"","sources":["../../../lib/entities/token.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,KAAM,SAAQ,oBAAU;CAc7C;AAdD,sBAcC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { BaseEntity } from 'typeorm';
|
|
2
|
-
export declare abstract class User extends BaseEntity {
|
|
3
|
-
abstract externalId: string;
|
|
4
|
-
abstract username: string;
|
|
5
|
-
abstract email: string;
|
|
6
|
-
abstract password: string;
|
|
7
|
-
abstract confirmed: boolean;
|
|
8
|
-
abstract confirmedAt: Date;
|
|
9
|
-
abstract passwordChangedAt: Date;
|
|
10
|
-
abstract blocked: boolean;
|
|
11
|
-
abstract blockedReason: string;
|
|
12
|
-
abstract blockedAt: Date;
|
|
13
|
-
abstract resetPasswordToken: string;
|
|
14
|
-
abstract confirmationToken: string;
|
|
15
|
-
abstract roles: string[];
|
|
16
|
-
abstract version: number;
|
|
17
|
-
abstract createdAt: Date;
|
|
18
|
-
abstract updatedAt: Date;
|
|
19
|
-
abstract deletedAt: Date;
|
|
20
|
-
abstract setId(id: any): any;
|
|
21
|
-
abstract getId(): any;
|
|
22
|
-
}
|
package/esm/lib/entities/user.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../lib/entities/user.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAEpC,MAAsB,IAAK,SAAQ,oBAAU;CAqB5C;AArBD,oBAqBC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare function isImplemented(): boolean;
|
|
2
|
-
export declare function synchronizeSchemas(): Promise<boolean>;
|
|
3
|
-
export declare function retrieveBy(entityName: any, entityId: any): Promise<any>;
|
|
4
|
-
export declare function addChange(entityName: any, entityId: any, status: any, userId: any, contents: any, changeEntity?: string): Promise<any>;
|