vona-core 5.0.104 → 5.0.106
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/dist/index.js +3196 -2
- package/dist/lib/bean/beanBase.d.ts +1 -0
- package/dist/lib/bean/beanBaseSimple.d.ts +0 -2
- package/dist/lib/bean/beanContainer.d.ts +9 -5
- package/dist/lib/core/hmr.d.ts +20 -0
- package/dist/lib/core/hmrDeps.d.ts +12 -0
- package/dist/lib/core/index.d.ts +2 -0
- package/dist/lib/core/meta.d.ts +5 -1
- package/dist/lib/core/response.d.ts +7 -0
- package/dist/lib/decorator/class/util.d.ts +1 -0
- package/dist/lib/decorator/interface/beanOptions.d.ts +1 -0
- package/dist/lib/decorator/type/containerScope.d.ts +1 -0
- package/dist/lib/mappedClass/extendClass.d.ts +2 -0
- package/dist/lib/mappedClass/mappedClass.d.ts +2 -0
- package/package.json +13 -14
- package/dist/lib/bean/beanAopBase.js +0 -3
- package/dist/lib/bean/beanAopMethodBase.js +0 -3
- package/dist/lib/bean/beanBase.js +0 -41
- package/dist/lib/bean/beanBaseSimple.js +0 -32
- package/dist/lib/bean/beanContainer.js +0 -586
- package/dist/lib/bean/beanSimple.js +0 -9
- package/dist/lib/bean/index.js +0 -9
- package/dist/lib/bean/resource/config/index.js +0 -1
- package/dist/lib/bean/resource/config/type.js +0 -1
- package/dist/lib/bean/resource/constant/index.js +0 -1
- package/dist/lib/bean/resource/constant/type.js +0 -1
- package/dist/lib/bean/resource/error/beanScopeError.js +0 -17
- package/dist/lib/bean/resource/error/beanScopeErrorImpl.js +0 -18
- package/dist/lib/bean/resource/error/errorApplication.js +0 -1
- package/dist/lib/bean/resource/error/errorClass.js +0 -75
- package/dist/lib/bean/resource/error/errorGlobal.js +0 -1
- package/dist/lib/bean/resource/error/errorInternal.js +0 -68
- package/dist/lib/bean/resource/error/errorObject.js +0 -1
- package/dist/lib/bean/resource/error/index.js +0 -8
- package/dist/lib/bean/resource/error/type.js +0 -1
- package/dist/lib/bean/resource/index.js +0 -4
- package/dist/lib/bean/resource/locale/appLocale.js +0 -51
- package/dist/lib/bean/resource/locale/beanScopeLocale.js +0 -16
- package/dist/lib/bean/resource/locale/index.js +0 -4
- package/dist/lib/bean/resource/locale/type.js +0 -1
- package/dist/lib/bean/resource/locale/utils.js +0 -3
- package/dist/lib/bean/scope/beanScopeBase.js +0 -97
- package/dist/lib/bean/scope/beanScopeContainer.js +0 -15
- package/dist/lib/bean/scope/beanScopeScene.js +0 -20
- package/dist/lib/bean/scope/beanScopeUtil.js +0 -18
- package/dist/lib/bean/scope/index.js +0 -4
- package/dist/lib/bean/type.js +0 -2
- package/dist/lib/core/application.js +0 -86
- package/dist/lib/core/asyncLocalStorage.js +0 -23
- package/dist/lib/core/config.js +0 -54
- package/dist/lib/core/context.js +0 -121
- package/dist/lib/core/ctxCounter.js +0 -20
- package/dist/lib/core/index.js +0 -7
- package/dist/lib/core/locales.js +0 -6
- package/dist/lib/core/logger/appLogger.js +0 -103
- package/dist/lib/core/logger/index.js +0 -2
- package/dist/lib/core/logger/utils.js +0 -76
- package/dist/lib/core/meta.js +0 -120
- package/dist/lib/core/metadata.js +0 -80
- package/dist/lib/core/resource.js +0 -146
- package/dist/lib/decorator/class/beanInfo.js +0 -8
- package/dist/lib/decorator/class/createBeanDecorator.js +0 -22
- package/dist/lib/decorator/class/index.js +0 -5
- package/dist/lib/decorator/class/proxyDisable.js +0 -8
- package/dist/lib/decorator/class/use.js +0 -74
- package/dist/lib/decorator/class/util.js +0 -9
- package/dist/lib/decorator/class/virtual.js +0 -8
- package/dist/lib/decorator/index.js +0 -3
- package/dist/lib/decorator/interface/beanOptions.js +0 -1
- package/dist/lib/decorator/interface/index.js +0 -2
- package/dist/lib/decorator/interface/useOptions.js +0 -1
- package/dist/lib/decorator/type/constructable.js +0 -1
- package/dist/lib/decorator/type/containerScope.js +0 -1
- package/dist/lib/decorator/type/function.js +0 -1
- package/dist/lib/decorator/type/index.js +0 -4
- package/dist/lib/decorator/type/injectionScope.js +0 -1
- package/dist/lib/framework/bootstrap.js +0 -13
- package/dist/lib/framework/cluster.js +0 -33
- package/dist/lib/framework/createApp.js +0 -73
- package/dist/lib/framework/index.js +0 -4
- package/dist/lib/framework/process.js +0 -44
- package/dist/lib/framework/start.js +0 -79
- package/dist/lib/framework/useApp.js +0 -61
- package/dist/lib/index.js +0 -6
- package/dist/lib/locale/en-us.js +0 -5
- package/dist/lib/locale/zh-cn.js +0 -69
- package/dist/lib/mappedClass/index.js +0 -4
- package/dist/lib/mappedClass/mappedClass.js +0 -10
- package/dist/lib/mappedClass/mixinClass.js +0 -8
- package/dist/lib/mappedClass/omitClass.js +0 -14
- package/dist/lib/mappedClass/partialClass.js +0 -16
- package/dist/lib/mappedClass/pickClass.js +0 -6
- package/dist/lib/mappedClass/pickClassInner.js +0 -12
- package/dist/lib/mappedClass/type.js +0 -1
- package/dist/lib/mappedClass/utils.js +0 -80
- package/dist/lib/module/config.js +0 -17
- package/dist/lib/module/constant.js +0 -16
- package/dist/lib/module/errors.js +0 -29
- package/dist/lib/module/loader.js +0 -25
- package/dist/lib/module/locales.js +0 -49
- package/dist/lib/module/module.js +0 -32
- package/dist/lib/utils/customKey.js +0 -3
- package/dist/lib/utils/index.js +0 -6
- package/dist/lib/utils/retry.js +0 -16
- package/dist/lib/utils/sqlite3.js +0 -38
- package/dist/lib/utils/util.js +0 -316
- package/dist/lib/utils/zod-enhance.js +0 -18
- package/dist/lib/utils/zod-openapi.js +0 -29
- package/dist/types/application/app.js +0 -1
- package/dist/types/application/index.js +0 -1
- package/dist/types/config/config.js +0 -1
- package/dist/types/config/index.js +0 -3
- package/dist/types/config/instance.js +0 -1
- package/dist/types/config/locale.js +0 -3
- package/dist/types/context/contextBase.js +0 -1
- package/dist/types/context/contextConfig.js +0 -1
- package/dist/types/context/contextOthers.js +0 -1
- package/dist/types/context/contextState.js +0 -1
- package/dist/types/context/index.js +0 -1
- package/dist/types/enum/appEvent.js +0 -4
- package/dist/types/enum/index.js +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/interface/bootstrap.js +0 -1
- package/dist/types/interface/index.js +0 -4
- package/dist/types/interface/logger.js +0 -1
- package/dist/types/interface/module.js +0 -1
- package/dist/types/interface/monkey.js +0 -1
- package/dist/types/utils/cast.js +0 -3
- package/dist/types/utils/demo.js +0 -1
- package/dist/types/utils/env.js +0 -1
- package/dist/types/utils/index.js +0 -6
- package/dist/types/utils/omitNever.js +0 -1
- package/dist/types/utils/powerPartial.js +0 -8
- package/dist/types/utils/type.js +0 -1
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { appMetadata } from "../core/metadata.js";
|
|
2
|
-
import { SymbolMappedClassMetadataKeys } from "./type.js";
|
|
3
|
-
export function registerMappedClassMetadataKey(target, metadataKey, options) {
|
|
4
|
-
const metadataKeys = appMetadata.getOwnMetadataMap(true, SymbolMappedClassMetadataKeys, target);
|
|
5
|
-
if (!Object.hasOwn(metadataKeys, metadataKey)) {
|
|
6
|
-
metadataKeys[metadataKey] = options;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export function getMappedClassMetadataKeys(target) {
|
|
10
|
-
return appMetadata.getMetadata(SymbolMappedClassMetadataKeys, target);
|
|
11
|
-
}
|
|
12
|
-
export function setMappedClassMetadataKeys(target, metadataKeys) {
|
|
13
|
-
return appMetadata.defineMetadata(SymbolMappedClassMetadataKeys, metadataKeys, target);
|
|
14
|
-
}
|
|
15
|
-
export function copyPropertiesOfClasses(target, sources, filter) {
|
|
16
|
-
for (const source of sources) {
|
|
17
|
-
copyProperties(target, source, ['constructor', 'prototype', 'length', 'name'], filter); // copy static
|
|
18
|
-
copyProperties(target.prototype, source.prototype, ['constructor', 'prototype'], filter); // copy prototype
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function copyProperties(target, source, keysIgnore, filter) {
|
|
22
|
-
const protos = [];
|
|
23
|
-
let _proto = source;
|
|
24
|
-
while (_proto) {
|
|
25
|
-
if (!['Object'].includes(_proto.constructor?.name) && !Object.hasOwn(_proto, 'arguments')) {
|
|
26
|
-
protos.unshift(_proto);
|
|
27
|
-
}
|
|
28
|
-
_proto = Object.getPrototypeOf(_proto);
|
|
29
|
-
}
|
|
30
|
-
for (const proto of protos) {
|
|
31
|
-
for (const key of Reflect.ownKeys(proto)) {
|
|
32
|
-
if (keysIgnore.includes(key))
|
|
33
|
-
continue;
|
|
34
|
-
if (filter && !filter(key))
|
|
35
|
-
continue;
|
|
36
|
-
// desc
|
|
37
|
-
const desc = Object.getOwnPropertyDescriptor(proto, key);
|
|
38
|
-
Object.defineProperty(target, key, desc);
|
|
39
|
-
// metadata
|
|
40
|
-
const metaKeys = Reflect.getOwnMetadataKeys(proto, key);
|
|
41
|
-
for (const metaKey of metaKeys) {
|
|
42
|
-
const metaValue = Reflect.getOwnMetadata(metaKey, proto, key);
|
|
43
|
-
Reflect.defineMetadata(metaKey, metaValue, target, key);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export function copyMetadataOfClasses(target, sources, transform) {
|
|
49
|
-
//
|
|
50
|
-
const metadataKeys = {};
|
|
51
|
-
for (const source of sources) {
|
|
52
|
-
const _metadataKeys = getMappedClassMetadataKeys(source);
|
|
53
|
-
if (_metadataKeys) {
|
|
54
|
-
Object.assign(metadataKeys, _metadataKeys);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
setMappedClassMetadataKeys(target, metadataKeys);
|
|
58
|
-
//
|
|
59
|
-
for (const metadataKey of Object.getOwnPropertySymbols(metadataKeys)) {
|
|
60
|
-
const metadataKeyOptions = metadataKeys[metadataKey];
|
|
61
|
-
const rulesNew = {};
|
|
62
|
-
for (const source of sources) {
|
|
63
|
-
const rules = appMetadata.getMetadata(metadataKey, source);
|
|
64
|
-
if (!rules)
|
|
65
|
-
continue;
|
|
66
|
-
if (!transform) {
|
|
67
|
-
Object.assign(rulesNew, rules);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
for (const key in rules) {
|
|
71
|
-
const ruleNew = transform(rules, key, metadataKeyOptions);
|
|
72
|
-
if (ruleNew !== undefined) {
|
|
73
|
-
rulesNew[key] = ruleNew;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
appMetadata.defineMetadata(metadataKey, rulesNew, target);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { deepExtend } from "../utils/util.js";
|
|
2
|
-
export default async function (app, modules) {
|
|
3
|
-
// load configs
|
|
4
|
-
await loadConfigs();
|
|
5
|
-
async function loadConfigs() {
|
|
6
|
-
for (const key in modules) {
|
|
7
|
-
const module = modules[key];
|
|
8
|
-
// module config
|
|
9
|
-
if (module.resource.config) {
|
|
10
|
-
const configModule = await module.resource.config(app, app.options.env);
|
|
11
|
-
// configNew is not used by now
|
|
12
|
-
await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, 'configLoaded', module, configModule);
|
|
13
|
-
app.config.modules[module.info.relativeName] = deepExtend({}, configModule, app.config.modules[module.info.relativeName]);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { deepExtend } from "../utils/util.js";
|
|
2
|
-
export default function (app, modules) {
|
|
3
|
-
// all constants
|
|
4
|
-
const ebConstants = (app.meta.constants = {});
|
|
5
|
-
// load constants
|
|
6
|
-
loadConstants();
|
|
7
|
-
function loadConstants() {
|
|
8
|
-
for (const key in modules) {
|
|
9
|
-
const module = modules[key];
|
|
10
|
-
const ebConstant = (ebConstants[module.info.relativeName] = {});
|
|
11
|
-
// module constants
|
|
12
|
-
if (module.resource.constants)
|
|
13
|
-
deepExtend(ebConstant, module.resource.constants);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ErrorClass } from "../bean/resource/error/errorClass.js";
|
|
2
|
-
import { deepExtend } from "../utils/util.js";
|
|
3
|
-
export default function (app, modules) {
|
|
4
|
-
// all errors
|
|
5
|
-
const ebErrors = {};
|
|
6
|
-
// load errors
|
|
7
|
-
loadErrors();
|
|
8
|
-
// patch Error
|
|
9
|
-
patchError();
|
|
10
|
-
function patchError() {
|
|
11
|
-
// error
|
|
12
|
-
app.meta.error = app.bean._newBean(ErrorClass, ebErrors);
|
|
13
|
-
// methods
|
|
14
|
-
['success', 'fail', 'throw', 'parseFail', 'parseSuccess', 'parseCode'].forEach(key => {
|
|
15
|
-
app[key] = function (...args) {
|
|
16
|
-
return app.meta.error[key](undefined, ...args);
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function loadErrors() {
|
|
21
|
-
for (const key in modules) {
|
|
22
|
-
const module = modules[key];
|
|
23
|
-
const ebError = (ebErrors[module.info.relativeName] = {});
|
|
24
|
-
// module errors
|
|
25
|
-
if (module.resource.errors)
|
|
26
|
-
deepExtend(ebError, module.resource.errors);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BeanSimple } from "../bean/beanSimple.js";
|
|
2
|
-
import loadConfig from "./config.js";
|
|
3
|
-
import loadConstants from "./constant.js";
|
|
4
|
-
import loadErrors from "./errors.js";
|
|
5
|
-
import loadLocales from "./locales.js";
|
|
6
|
-
import { ModuleTools } from "./module.js";
|
|
7
|
-
export class ModuleLoader extends BeanSimple {
|
|
8
|
-
async execute() {
|
|
9
|
-
const app = this.app;
|
|
10
|
-
// modules
|
|
11
|
-
const moduleTools = app.bean._newBean(ModuleTools);
|
|
12
|
-
// prepare
|
|
13
|
-
const modules = await moduleTools.prepare();
|
|
14
|
-
// load modules
|
|
15
|
-
await moduleTools.load();
|
|
16
|
-
// monkey modules
|
|
17
|
-
await moduleTools.monkey('moduleLoading');
|
|
18
|
-
await loadConfig(app, modules);
|
|
19
|
-
await loadLocales(app, modules);
|
|
20
|
-
loadErrors(app, modules);
|
|
21
|
-
loadConstants(app, modules);
|
|
22
|
-
// monkey modules
|
|
23
|
-
await moduleTools.monkey('moduleLoaded');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import localesDefault from "../core/locales.js";
|
|
2
|
-
export default async function (app, modules) {
|
|
3
|
-
// all locales
|
|
4
|
-
app.meta.locales = localesDefault;
|
|
5
|
-
app.meta.localeModules = {};
|
|
6
|
-
// load locales
|
|
7
|
-
await loadLocales();
|
|
8
|
-
async function loadLocales() {
|
|
9
|
-
const locales = (await app.options.locales()).locales;
|
|
10
|
-
// project locales
|
|
11
|
-
for (const locale in locales) {
|
|
12
|
-
_initLocales(locale, locales[locale]);
|
|
13
|
-
}
|
|
14
|
-
// module locales
|
|
15
|
-
for (const moduleName in modules) {
|
|
16
|
-
const module = modules[moduleName];
|
|
17
|
-
_registerLocales(moduleName, module.resource.locales);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function _initLocales(locale, locales) {
|
|
21
|
-
if (!locales)
|
|
22
|
-
return;
|
|
23
|
-
if (!locales.modules) {
|
|
24
|
-
// override
|
|
25
|
-
app.meta.locales[locale] = Object.assign({}, app.meta.locales[locale], locales);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
const moduleMap = locales.modules;
|
|
29
|
-
for (const moduleName in moduleMap) {
|
|
30
|
-
_registerLocale(moduleName, locale, moduleMap[moduleName]);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function _registerLocales(moduleName, locales) {
|
|
35
|
-
if (!locales)
|
|
36
|
-
return;
|
|
37
|
-
for (const locale in locales) {
|
|
38
|
-
_registerLocale(moduleName, locale, locales[locale]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function _registerLocale(moduleName, locale, moduleLocales) {
|
|
42
|
-
// locales: not override
|
|
43
|
-
app.meta.locales[locale] = Object.assign({}, moduleLocales, app.meta.locales[locale]);
|
|
44
|
-
// localeModules
|
|
45
|
-
if (!app.meta.localeModules[moduleName])
|
|
46
|
-
app.meta.localeModules[moduleName] = {};
|
|
47
|
-
app.meta.localeModules[moduleName][locale] = Object.assign({}, moduleLocales, app.meta.localeModules[moduleName][locale]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { BeanSimple } from "../bean/beanSimple.js";
|
|
2
|
-
export class ModuleTools extends BeanSimple {
|
|
3
|
-
async prepare() {
|
|
4
|
-
const app = this.app;
|
|
5
|
-
const modulesMeta = await app.options.modulesMeta();
|
|
6
|
-
const modules = modulesMeta.modulesMeta.modules;
|
|
7
|
-
const modulesArray = modulesMeta.modulesMeta.moduleNames.map(relativeName => modules[relativeName]);
|
|
8
|
-
app.meta.modules = modules;
|
|
9
|
-
app.meta.modulesArray = modulesArray;
|
|
10
|
-
app.meta.modulesMonkey = {};
|
|
11
|
-
return modules;
|
|
12
|
-
}
|
|
13
|
-
async load() {
|
|
14
|
-
const app = this.app;
|
|
15
|
-
// main / monkey
|
|
16
|
-
for (const module of app.meta.modulesArray) {
|
|
17
|
-
if (module.resource.Main) {
|
|
18
|
-
module.mainInstance = app.bean._newBean(module.resource.Main, module);
|
|
19
|
-
}
|
|
20
|
-
if (module.resource.Monkey) {
|
|
21
|
-
module.monkeyInstance = app.bean._newBean(module.resource.Monkey, module);
|
|
22
|
-
app.meta.modulesMonkey[module.info.relativeName] = module;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async monkey(monkeyName) {
|
|
27
|
-
const app = this.app;
|
|
28
|
-
for (const module of app.meta.modulesArray) {
|
|
29
|
-
await app.util.monkeyModule(app.meta.appMonkey, app.meta.modulesMonkey, monkeyName, module);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
package/dist/lib/utils/index.js
DELETED
package/dist/lib/utils/retry.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as Retry from 'retry';
|
|
2
|
-
export * as Retry from 'retry';
|
|
3
|
-
export async function retry(options, fn) {
|
|
4
|
-
return new Promise((resolve, reject) => {
|
|
5
|
-
const operation = Retry.operation(options);
|
|
6
|
-
operation.attempt(currentAttempt => {
|
|
7
|
-
fn(currentAttempt)
|
|
8
|
-
.then(data => resolve(data))
|
|
9
|
-
.catch(err => {
|
|
10
|
-
if (operation.retry(err))
|
|
11
|
-
return;
|
|
12
|
-
reject(err);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import fse from 'fs-extra';
|
|
5
|
-
import { pathToHref } from "./util.js";
|
|
6
|
-
export function getSqlite3DatabaseNameDefault(app) {
|
|
7
|
-
const mode = app.configMeta.mode;
|
|
8
|
-
if (mode !== 'prod')
|
|
9
|
-
return '';
|
|
10
|
-
const dbPath = path.join(os.homedir(), 'vona', app.name, 'sqlite3');
|
|
11
|
-
fse.ensureDirSync(dbPath);
|
|
12
|
-
return path.join(dbPath, `${app.name}.db`);
|
|
13
|
-
}
|
|
14
|
-
export function getSqlite3NativeBinding(_app, nativeBinding) {
|
|
15
|
-
if (!nativeBinding)
|
|
16
|
-
return null;
|
|
17
|
-
const nativeBindingPath = path.isAbsolute(nativeBinding) ? nativeBinding : path.join(import.meta.dirname, nativeBinding);
|
|
18
|
-
const require = createRequire(import.meta.url);
|
|
19
|
-
const addon = require(nativeBindingPath);
|
|
20
|
-
return addon;
|
|
21
|
-
}
|
|
22
|
-
export async function copySqlite3NativeBinding(projectPath, outDir, env) {
|
|
23
|
-
// check env.DATABASE_CLIENT_SQLITE3_NATIVEBINDING rather than env.DATABASE_DEFAULT_CLIENT
|
|
24
|
-
// if (env.DATABASE_DEFAULT_CLIENT !== 'sqlite3') return;
|
|
25
|
-
// dest
|
|
26
|
-
let fileDest = env.DATABASE_CLIENT_SQLITE3_NATIVEBINDING;
|
|
27
|
-
if (!fileDest)
|
|
28
|
-
return;
|
|
29
|
-
if (path.isAbsolute(fileDest))
|
|
30
|
-
return;
|
|
31
|
-
fileDest = path.join(outDir, fileDest);
|
|
32
|
-
// src
|
|
33
|
-
const require = createRequire(pathToHref(path.join(projectPath, '/')));
|
|
34
|
-
const modulePath = require.resolve('better-sqlite3/package.json');
|
|
35
|
-
const fileSrc = path.join(path.dirname(modulePath), 'build/Release/better_sqlite3.node');
|
|
36
|
-
// copy
|
|
37
|
-
await fse.copy(fileSrc, fileDest);
|
|
38
|
-
}
|
package/dist/lib/utils/util.js
DELETED
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import crypto from 'node:crypto';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { compose as _compose } from '@cabloy/compose';
|
|
6
|
-
import { extend } from '@cabloy/extend';
|
|
7
|
-
import { combineApiPath, combineApiPathControllerAndAction, combineApiPathControllerAndActionRaw, combineResourceName } from '@cabloy/utils';
|
|
8
|
-
import fse from 'fs-extra';
|
|
9
|
-
import * as uuid from 'uuid';
|
|
10
|
-
import { cast } from "../../types/index.js";
|
|
11
|
-
import { BeanSimple } from "../bean/beanSimple.js";
|
|
12
|
-
import { zodSetLocaleErrors } from "./zod-enhance.js";
|
|
13
|
-
const SymbolProdRootPath = Symbol('SymbolProdRootPath');
|
|
14
|
-
export class AppUtil extends BeanSimple {
|
|
15
|
-
[SymbolProdRootPath];
|
|
16
|
-
instanceStarted(instanceName) {
|
|
17
|
-
return this.app.meta.appReadyInstances && this.app.meta.appReadyInstances[instanceName];
|
|
18
|
-
}
|
|
19
|
-
get protocol() {
|
|
20
|
-
const config = this.ctx ? this.ctx.config : this.app.config;
|
|
21
|
-
return config.server.serve.protocol || this.ctx?.protocol;
|
|
22
|
-
}
|
|
23
|
-
get host() {
|
|
24
|
-
const config = this.ctx ? this.ctx.config : this.app.config;
|
|
25
|
-
return config.server.serve.host || this.ctx?.host;
|
|
26
|
-
}
|
|
27
|
-
getAbsoluteUrl(path) {
|
|
28
|
-
const prefix = this.host ? `${this.protocol}://${this.host}` : '';
|
|
29
|
-
return `${prefix}${path || ''}`;
|
|
30
|
-
}
|
|
31
|
-
getAbsoluteUrlByApiPath(path) {
|
|
32
|
-
return this.getAbsoluteUrl(this.combineApiPath(path, '', true, true));
|
|
33
|
-
}
|
|
34
|
-
combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, simplify) {
|
|
35
|
-
return combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, simplify);
|
|
36
|
-
}
|
|
37
|
-
combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, prefix, simplify) {
|
|
38
|
-
return combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, prefix, simplify, this.app.config.server.globalPrefix);
|
|
39
|
-
}
|
|
40
|
-
combineApiPath(path, moduleName, prefix, simplify) {
|
|
41
|
-
return combineApiPath(path, moduleName, prefix, simplify, this.app.config.server.globalPrefix);
|
|
42
|
-
}
|
|
43
|
-
combineStaticPath(staticPath, moduleName) {
|
|
44
|
-
const globalPrefix = '/api/static';
|
|
45
|
-
if (!staticPath)
|
|
46
|
-
staticPath = '';
|
|
47
|
-
// safe
|
|
48
|
-
staticPath = path.normalize(staticPath);
|
|
49
|
-
if (staticPath.includes('..'))
|
|
50
|
-
throw new Error(`unsafe path: ${staticPath}`);
|
|
51
|
-
// ignore globalPrefix
|
|
52
|
-
if (staticPath.startsWith('//'))
|
|
53
|
-
return staticPath.substring(1);
|
|
54
|
-
// ignore module path
|
|
55
|
-
if (staticPath.startsWith('/'))
|
|
56
|
-
return `${globalPrefix}${staticPath}`;
|
|
57
|
-
// globalPrefix + module path + arg
|
|
58
|
-
if (!moduleName)
|
|
59
|
-
throw new Error('should specify the moduleName');
|
|
60
|
-
if (typeof moduleName !== 'string')
|
|
61
|
-
moduleName = moduleName.relativeName;
|
|
62
|
-
const parts = moduleName.split('-');
|
|
63
|
-
// path
|
|
64
|
-
return `${globalPrefix}/${parts[0]}/${parts[1]}/${staticPath}`;
|
|
65
|
-
}
|
|
66
|
-
combineResourceName(resourceName, moduleName, simplify, simplifyProviderId) {
|
|
67
|
-
return combineResourceName(resourceName, moduleName, simplify, simplifyProviderId);
|
|
68
|
-
}
|
|
69
|
-
async getPublicPathPhysical(subdir, ensure) {
|
|
70
|
-
const rootPath = this.app.config.server.publicDir;
|
|
71
|
-
// use instance.id, not instanceName
|
|
72
|
-
const dir = combineFilePathSafe(path.join(rootPath, cast(this.ctx).instance.id.toString()), subdir || '');
|
|
73
|
-
if (!dir)
|
|
74
|
-
throw new Error('not valid path');
|
|
75
|
-
if (ensure) {
|
|
76
|
-
await fse.ensureDir(dir);
|
|
77
|
-
}
|
|
78
|
-
return dir;
|
|
79
|
-
}
|
|
80
|
-
get prodRootPath() {
|
|
81
|
-
if (!this.app.meta.isProd)
|
|
82
|
-
throw new Error('only invoked in prod');
|
|
83
|
-
if (!this[SymbolProdRootPath]) {
|
|
84
|
-
this[SymbolProdRootPath] = import.meta.dirname;
|
|
85
|
-
}
|
|
86
|
-
return this[SymbolProdRootPath];
|
|
87
|
-
}
|
|
88
|
-
getAssetPathPhysical(moduleName, scene, assetPath) {
|
|
89
|
-
if (typeof moduleName !== 'string')
|
|
90
|
-
moduleName = moduleName.relativeName;
|
|
91
|
-
if (this.app.meta.isProd) {
|
|
92
|
-
return combineFilePathSafe(path.join(this.prodRootPath, 'assets', scene, moduleName), assetPath || '');
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
const module = this.app.meta.modules[moduleName];
|
|
96
|
-
if (!module)
|
|
97
|
-
throw new Error('module not found');
|
|
98
|
-
return combineFilePathSafe(path.join(module.root, 'assets', scene), assetPath || '');
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
createError(data, returnObject) {
|
|
102
|
-
const error = returnObject ? {} : new Error();
|
|
103
|
-
error.code = data.code !== undefined ? data.code : 500;
|
|
104
|
-
if (data.message && typeof data.message === 'object') {
|
|
105
|
-
error.message = JSON.stringify(data.message, null, 2);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
error.message = data.message;
|
|
109
|
-
}
|
|
110
|
-
if (!this.app.meta.isProd) {
|
|
111
|
-
if (data.stack)
|
|
112
|
-
error.stack = data.stack;
|
|
113
|
-
if (data.name)
|
|
114
|
-
error.name = data.name;
|
|
115
|
-
if (data.errno)
|
|
116
|
-
error.errno = data.errno;
|
|
117
|
-
if (data.sqlMessage)
|
|
118
|
-
error.sqlMessage = data.sqlMessage;
|
|
119
|
-
if (data.sqlState)
|
|
120
|
-
error.sqlState = data.sqlState;
|
|
121
|
-
if (data.index)
|
|
122
|
-
error.index = data.index;
|
|
123
|
-
if (data.sql)
|
|
124
|
-
error.sql = data.sql;
|
|
125
|
-
}
|
|
126
|
-
return error;
|
|
127
|
-
}
|
|
128
|
-
async monkeyModule(ebAppMonkey, ebModulesMonkey, monkeyName, moduleTarget, ...monkeyData) {
|
|
129
|
-
// self: main
|
|
130
|
-
if (moduleTarget && moduleTarget.mainInstance && moduleTarget.mainInstance[monkeyName]) {
|
|
131
|
-
// @ts-ignore ignore
|
|
132
|
-
await moduleTarget.mainInstance[monkeyName](...monkeyData);
|
|
133
|
-
}
|
|
134
|
-
// module monkey
|
|
135
|
-
for (const key in ebModulesMonkey) {
|
|
136
|
-
const moduleMonkey = ebModulesMonkey[key];
|
|
137
|
-
if (moduleMonkey.monkeyInstance && moduleMonkey.monkeyInstance[monkeyName]) {
|
|
138
|
-
if (moduleTarget === undefined) {
|
|
139
|
-
// @ts-ignore ignore
|
|
140
|
-
await moduleMonkey.monkeyInstance[monkeyName](...monkeyData);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
// @ts-ignore ignore
|
|
144
|
-
await moduleMonkey.monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
// app monkey
|
|
149
|
-
if (ebAppMonkey && ebAppMonkey[monkeyName]) {
|
|
150
|
-
if (moduleTarget === undefined) {
|
|
151
|
-
await ebAppMonkey[monkeyName](...monkeyData);
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
await ebAppMonkey[monkeyName](moduleTarget, ...monkeyData);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
monkeyModuleSync(ebAppMonkey, ebModulesMonkey, monkeyName, moduleTarget, ...monkeyData) {
|
|
159
|
-
// self: main
|
|
160
|
-
if (moduleTarget && moduleTarget.mainInstance && moduleTarget.mainInstance[monkeyName]) {
|
|
161
|
-
// @ts-ignore ignore
|
|
162
|
-
moduleTarget.mainInstance[monkeyName](...monkeyData);
|
|
163
|
-
}
|
|
164
|
-
// module monkey
|
|
165
|
-
for (const key in ebModulesMonkey) {
|
|
166
|
-
const moduleMonkey = ebModulesMonkey[key];
|
|
167
|
-
if (moduleMonkey.monkeyInstance && moduleMonkey.monkeyInstance[monkeyName]) {
|
|
168
|
-
if (moduleTarget === undefined) {
|
|
169
|
-
// @ts-ignore ignore
|
|
170
|
-
moduleMonkey.monkeyInstance[monkeyName](...monkeyData);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// @ts-ignore ignore
|
|
174
|
-
moduleMonkey.monkeyInstance[monkeyName](moduleTarget, ...monkeyData);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// app monkey
|
|
179
|
-
if (ebAppMonkey && ebAppMonkey[monkeyName]) {
|
|
180
|
-
if (moduleTarget === undefined) {
|
|
181
|
-
ebAppMonkey[monkeyName](...monkeyData);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
ebAppMonkey[monkeyName](moduleTarget, ...monkeyData);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
detectErrorMessage(err) {
|
|
189
|
-
// detect json parse error
|
|
190
|
-
if (err.status === 400 &&
|
|
191
|
-
err.name === 'SyntaxError' &&
|
|
192
|
-
this.ctx.request.is('application/json', 'application/vnd.api+json', 'application/csp-report')) {
|
|
193
|
-
return 'Problems parsing JSON';
|
|
194
|
-
}
|
|
195
|
-
return err.message;
|
|
196
|
-
}
|
|
197
|
-
detectStatus(err) {
|
|
198
|
-
// detect status
|
|
199
|
-
let status = err.status || 500;
|
|
200
|
-
if (typeof status !== 'number')
|
|
201
|
-
status = Number(status);
|
|
202
|
-
if (status < 200) {
|
|
203
|
-
// invalid status consider as 500, like urllib will return -1 status
|
|
204
|
-
status = 500;
|
|
205
|
-
}
|
|
206
|
-
return status;
|
|
207
|
-
}
|
|
208
|
-
accepts() {
|
|
209
|
-
if (this.ctx.acceptJSON)
|
|
210
|
-
return 'json';
|
|
211
|
-
return 'html';
|
|
212
|
-
}
|
|
213
|
-
getModuleConfigRaw(moduleName) {
|
|
214
|
-
return this.app.config.modules[moduleName];
|
|
215
|
-
}
|
|
216
|
-
setLocaleErrors(localeErrors, localeDefault) {
|
|
217
|
-
return zodSetLocaleErrors(this.app, localeErrors, localeDefault);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
export function compose(chains, adapter) {
|
|
221
|
-
return _compose(chains, adapter);
|
|
222
|
-
}
|
|
223
|
-
export function instanceDesp(instanceName) {
|
|
224
|
-
if (instanceName === undefined || instanceName === null)
|
|
225
|
-
return '~';
|
|
226
|
-
return instanceName || '-';
|
|
227
|
-
}
|
|
228
|
-
export function requireDynamic(file) {
|
|
229
|
-
if (!file)
|
|
230
|
-
throw new Error('file should not empty');
|
|
231
|
-
const require = createRequire(import.meta.url);
|
|
232
|
-
let instance = require(file);
|
|
233
|
-
const mtime = _requireDynamic_getFileTime(file);
|
|
234
|
-
if (instance.__requireDynamic_mtime === undefined) {
|
|
235
|
-
instance.__requireDynamic_mtime = mtime;
|
|
236
|
-
}
|
|
237
|
-
else if (instance.__requireDynamic_mtime !== mtime) {
|
|
238
|
-
delete require.cache[require.resolve(file)];
|
|
239
|
-
instance = require(file);
|
|
240
|
-
instance.__requireDynamic_mtime = mtime;
|
|
241
|
-
}
|
|
242
|
-
return instance;
|
|
243
|
-
}
|
|
244
|
-
function _requireDynamic_getFileTime(file) {
|
|
245
|
-
if (!path.isAbsolute(file))
|
|
246
|
-
return null;
|
|
247
|
-
const exists = fse.pathExistsSync(file);
|
|
248
|
-
if (!exists)
|
|
249
|
-
return null;
|
|
250
|
-
// stat
|
|
251
|
-
const stat = fse.statSync(file);
|
|
252
|
-
return stat.mtime.valueOf();
|
|
253
|
-
}
|
|
254
|
-
export function deepExtend(target, ...args) {
|
|
255
|
-
return extend(true, target, ...args);
|
|
256
|
-
}
|
|
257
|
-
export function uuidv4() {
|
|
258
|
-
return uuid.v4();
|
|
259
|
-
}
|
|
260
|
-
export function createHash(str, encoding, algorithm, options) {
|
|
261
|
-
const hash = crypto.createHash(algorithm ?? 'sha256', options);
|
|
262
|
-
hash.update(str);
|
|
263
|
-
return hash.digest(encoding ?? 'hex');
|
|
264
|
-
}
|
|
265
|
-
export async function disposeInstance(instance) {
|
|
266
|
-
await instance?.__dispose__?.();
|
|
267
|
-
}
|
|
268
|
-
export function polyfillDispose(instance) {
|
|
269
|
-
if (!instance || instance.__dispose__)
|
|
270
|
-
return;
|
|
271
|
-
Object.getPrototypeOf(instance).__dispose__ = () => { };
|
|
272
|
-
}
|
|
273
|
-
export function pathToHref(fileName) {
|
|
274
|
-
return pathToFileURL(fileName).href;
|
|
275
|
-
// return Path.sep === '\\' ? pathToFileURL(fileName).href : fileName;
|
|
276
|
-
}
|
|
277
|
-
export function prepareEnv(env) {
|
|
278
|
-
const env2 = { ...env };
|
|
279
|
-
for (const key of Object.keys(env2)) {
|
|
280
|
-
if (process.env[key] !== undefined) {
|
|
281
|
-
env2[key] = process.env[key];
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return env2;
|
|
285
|
-
}
|
|
286
|
-
export function beanFullNameFromOnionName(onionName, sceneName) {
|
|
287
|
-
return onionName.replace(':', `.${sceneName}.`);
|
|
288
|
-
}
|
|
289
|
-
export function onionNameFromBeanFullName(beanFullName, sceneName) {
|
|
290
|
-
return beanFullName.replace(`.${sceneName}.`, ':');
|
|
291
|
-
}
|
|
292
|
-
export function filterHeaders(headers, whitelist) {
|
|
293
|
-
if (!headers)
|
|
294
|
-
return;
|
|
295
|
-
const res = {};
|
|
296
|
-
for (const key in headers) {
|
|
297
|
-
if (whitelist.includes(key)) {
|
|
298
|
-
res[key] = headers[key];
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
return res;
|
|
302
|
-
}
|
|
303
|
-
export function combineFilePathSafe(dir, file) {
|
|
304
|
-
const fullPath = path.normalize(path.join(dir, file));
|
|
305
|
-
// files that can be accessd should be under options.dir
|
|
306
|
-
if (fullPath.indexOf(dir) !== 0)
|
|
307
|
-
throw new Error(`unsafe dir: ${dir}`);
|
|
308
|
-
return fullPath;
|
|
309
|
-
}
|
|
310
|
-
export async function loadJSONFile(fileName) {
|
|
311
|
-
const pkgContent = (await fse.readFile(fileName)).toString();
|
|
312
|
-
return JSON.parse(pkgContent);
|
|
313
|
-
}
|
|
314
|
-
export async function saveJSONFile(fileName, json) {
|
|
315
|
-
await fse.writeFile(fileName, `${JSON.stringify(json, null, 2)}\n`);
|
|
316
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { setLocaleAdapter, setLocaleErrors, translateError } from '@cabloy/zod-errors-custom';
|
|
2
|
-
import { ZodMetadata } from '@cabloy/zod-openapi';
|
|
3
|
-
import { setParseAdapter } from '@cabloy/zod-query';
|
|
4
|
-
import { useApp } from "../framework/useApp.js";
|
|
5
|
-
export function zodEnhance() {
|
|
6
|
-
setLocaleAdapter((text, iss) => {
|
|
7
|
-
const app = useApp();
|
|
8
|
-
return translateError((text, ...args) => {
|
|
9
|
-
return app.meta.text(text, ...args);
|
|
10
|
-
}, text, iss);
|
|
11
|
-
});
|
|
12
|
-
setParseAdapter(ZodMetadata);
|
|
13
|
-
}
|
|
14
|
-
export function zodSetLocaleErrors(app, localeErrors, localeDefault) {
|
|
15
|
-
setLocaleErrors(() => {
|
|
16
|
-
return app.meta.locale.current;
|
|
17
|
-
}, localeErrors, localeDefault);
|
|
18
|
-
}
|