vona-core 5.1.30 → 5.1.31

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 CHANGED
@@ -9,6 +9,9 @@ import crypto from 'node:crypto';
9
9
  import { createRequire } from 'node:module';
10
10
  import { pathToFileURL } from 'node:url';
11
11
  import * as uuid from 'uuid';
12
+ import fs from 'node:fs';
13
+ import { getPlatformArch as getPlatformArch$1 } from 'vona';
14
+ import os from 'node:os';
12
15
  import { setLocaleErrors, setLocaleAdapter, translateError } from '@cabloy/zod-errors-custom';
13
16
  import { ZodMetadata } from '@cabloy/zod-openapi';
14
17
  import { setParseAdapter } from '@cabloy/zod-query';
@@ -21,7 +24,6 @@ import { AsyncLocalStorage } from 'node:async_hooks';
21
24
  import chalk from 'chalk';
22
25
  import * as Winston from 'winston';
23
26
  import DailyRotateFile from 'winston-daily-rotate-file';
24
- import os from 'node:os';
25
27
  import { MESSAGE, LEVEL } from 'triple-beam';
26
28
  import cluster from 'node:cluster';
27
29
  import React from 'react';
@@ -51,6 +53,161 @@ const EnumAppEvent = {
51
53
  AppStartError: 'eb:event:appStartError'
52
54
  };
53
55
 
56
+ function resolverSharp(projectPath) {
57
+ // src
58
+ const require = createRequire(pathToHref(path.join(projectPath, '/')));
59
+ const sharpPath = require.resolve('sharp');
60
+ const requireSharp = createRequire(pathToHref(sharpPath));
61
+ const modulePath = requireSharp.resolve(`@img/sharp-${getPlatformArch$1()}/sharp.node`);
62
+ const libPath = path.join(path.dirname(modulePath), 'lib');
63
+ const fileName = fs.readdirSync(libPath).find(item => item.endsWith('.node'));
64
+ if (!fileName) {
65
+ throw new Error(`Sharp native binding not found: ${libPath}`);
66
+ }
67
+ return path.join(libPath, fileName);
68
+ }
69
+ function resolverSharpLibvips(projectPath) {
70
+ // src
71
+ const require = createRequire(pathToHref(path.join(projectPath, '/')));
72
+ const sharpPath = require.resolve('sharp');
73
+ const requireSharp = createRequire(pathToHref(sharpPath));
74
+ const modulePath = requireSharp.resolve(`@img/sharp-libvips-${getPlatformArch$1()}/package`);
75
+ const libPath = path.join(path.dirname(modulePath), 'lib');
76
+ const fileName = fs.readdirSync(libPath).find(_matchSharpLibvipsFileName);
77
+ if (!fileName) {
78
+ // eslint-disable-next-line
79
+ console.log(fs.readdirSync(libPath));
80
+ throw new Error(`Sharp libvips native binding not found: ${libPath}`);
81
+ }
82
+ return path.join(libPath, fileName);
83
+ }
84
+ function _matchSharpLibvipsFileName(fileName) {
85
+ if (process.platform === 'darwin') {
86
+ return fileName.endsWith('.dylib');
87
+ }
88
+ if (process.platform === 'win32') {
89
+ return /\.dll$/i.test(fileName);
90
+ }
91
+ return /\.so(?:\..+)?$/.test(fileName);
92
+ }
93
+
94
+ async function combineConfigDefault(app, configDefault, configDev, configProd, configTest) {
95
+ let config = await configDefault(app);
96
+ const mode = app.meta.env.META_MODE;
97
+ if (mode === 'dev' && configDev) {
98
+ config = deepExtend(config, await configDev(app));
99
+ } else if (mode === 'prod' && configProd) {
100
+ config = deepExtend(config, await configProd(app));
101
+ } else if (mode === 'test' && configTest) {
102
+ config = deepExtend(config, await configTest(app));
103
+ }
104
+ return config;
105
+ }
106
+ function getLoggerPathPhysicalRoot(app) {
107
+ const mode = app.meta.env.META_MODE;
108
+ let loggerDir;
109
+ if (mode === 'test' || mode === 'dev') {
110
+ loggerDir = path.join(app.projectPath, '.app/logs');
111
+ } else {
112
+ loggerDir = path.join(getHomeVonaAppDir(app), 'logs');
113
+ }
114
+ fse.ensureDirSync(loggerDir);
115
+ return loggerDir;
116
+ }
117
+ function getPublicPathPhysicalRoot(app) {
118
+ const mode = app.meta.env.META_MODE;
119
+ let publicDir;
120
+ if (mode === 'test' || mode === 'dev') {
121
+ publicDir = path.join(app.projectPath, '.app/public');
122
+ } else {
123
+ publicDir = path.join(getHomeVonaAppDir(app), 'public');
124
+ }
125
+ fse.ensureDirSync(publicDir);
126
+ return publicDir;
127
+ }
128
+ function getRuntimePathPhysicalRoot(app) {
129
+ const mode = app.meta.env.META_MODE;
130
+ let runtimeDir;
131
+ if (mode === 'test' || mode === 'dev') {
132
+ runtimeDir = path.join(app.options.projectPath, '.app/runtime');
133
+ } else {
134
+ runtimeDir = path.join(getHomeVonaAppDir(app), 'runtime');
135
+ }
136
+ fse.ensureDirSync(runtimeDir);
137
+ return runtimeDir;
138
+ }
139
+ function getHomeVonaAppDir(app) {
140
+ return path.join(os.homedir(), '.vona', app.name);
141
+ }
142
+
143
+ function getSqlite3DatabaseNameDefault(app) {
144
+ const mode = app.meta.env.META_MODE;
145
+ if (mode !== 'prod') return '';
146
+ const dbPath = path.join(getHomeVonaAppDir(app), 'sqlite3');
147
+ fse.ensureDirSync(dbPath);
148
+ return path.join(dbPath, `${app.name}.db`);
149
+ }
150
+ function resolverSqlite3(projectPath) {
151
+ // src
152
+ const require = createRequire(pathToHref(path.join(projectPath, '/')));
153
+ const modulePath = require.resolve('better-sqlite3/package.json');
154
+ return path.join(path.dirname(modulePath), 'build/Release/better_sqlite3.node');
155
+ }
156
+
157
+ function getPlatformArch() {
158
+ const platform = process.platform;
159
+ const arch = process.arch;
160
+ return `${platform}-${arch}`;
161
+ }
162
+ async function copyAddon({
163
+ addonName,
164
+ resolver,
165
+ projectPath,
166
+ outDir,
167
+ env
168
+ }) {
169
+ const envName = `BUILD_ADDON_${addonName}`.toUpperCase();
170
+ const envValue = env[envName];
171
+ if (envValue === 'false') return;
172
+ // manual
173
+ const addonDirSrc = path.join(projectPath, 'src/backend/addon', addonName);
174
+ if (fse.existsSync(addonDirSrc)) {
175
+ const addonDirDest = path.join(outDir, 'addon', addonName);
176
+ await fse.copy(addonDirSrc, addonDirDest);
177
+ }
178
+ // auto
179
+ const envAutoName = `BUILD_ADDON_AUTO_${addonName}`.toUpperCase();
180
+ const envAutoValue = env[envAutoName];
181
+ if (envAutoValue === 'false') return;
182
+ const platformArch = getPlatformArch();
183
+ const addonFile = _resolverAddonFile(addonName, projectPath, resolver);
184
+ if (addonFile) {
185
+ const fileDest = path.join(outDir, 'addon', addonName, `${platformArch}.node`);
186
+ await fse.copy(addonFile, fileDest);
187
+ }
188
+ }
189
+ function requireAddon(addonName) {
190
+ const addonFile = resolveAddon(addonName);
191
+ const require = createRequire(import.meta.url);
192
+ return require(addonFile);
193
+ }
194
+ function resolveAddon(addonName) {
195
+ const platformArch = getPlatformArch();
196
+ const addonFile = path.join(import.meta.dirname, 'addon', addonName, `${platformArch}.node`);
197
+ return addonFile;
198
+ }
199
+ function _resolverAddonFile(addonName, projectPath, resolver) {
200
+ const addonFile = resolver?.(addonName, projectPath);
201
+ if (addonFile) return addonFile;
202
+ if (addonName === 'sqlite3') {
203
+ return resolverSqlite3(projectPath);
204
+ } else if (addonName === 'sharp') {
205
+ return resolverSharp(projectPath);
206
+ } else if (addonName === 'sharpLibvips') {
207
+ return resolverSharpLibvips(projectPath);
208
+ }
209
+ }
210
+
54
211
  function zodEnhance() {
55
212
  setLocaleAdapter((text, iss) => {
56
213
  const app = useApp();
@@ -246,6 +403,9 @@ class AppUtil extends BeanSimple {
246
403
  setLocaleErrors(localeErrors, localeDefault) {
247
404
  return zodSetLocaleErrors(this.app, localeErrors, localeDefault);
248
405
  }
406
+ requireAddon(addonName) {
407
+ return requireAddon(addonName);
408
+ }
249
409
  }
250
410
  function compose(chains, adapter) {
251
411
  return compose$1(chains, adapter);
@@ -2517,55 +2677,6 @@ class VonaApplication extends KoaApplication {
2517
2677
  }
2518
2678
  }
2519
2679
 
2520
- async function combineConfigDefault(app, configDefault, configDev, configProd, configTest) {
2521
- let config = await configDefault(app);
2522
- const mode = app.meta.env.META_MODE;
2523
- if (mode === 'dev' && configDev) {
2524
- config = deepExtend(config, await configDev(app));
2525
- } else if (mode === 'prod' && configProd) {
2526
- config = deepExtend(config, await configProd(app));
2527
- } else if (mode === 'test' && configTest) {
2528
- config = deepExtend(config, await configTest(app));
2529
- }
2530
- return config;
2531
- }
2532
- function getLoggerPathPhysicalRoot(app) {
2533
- const mode = app.meta.env.META_MODE;
2534
- let loggerDir;
2535
- if (mode === 'test' || mode === 'dev') {
2536
- loggerDir = path.join(app.projectPath, '.app/logs');
2537
- } else {
2538
- loggerDir = path.join(getHomeVonaAppDir(app), 'logs');
2539
- }
2540
- fse.ensureDirSync(loggerDir);
2541
- return loggerDir;
2542
- }
2543
- function getPublicPathPhysicalRoot(app) {
2544
- const mode = app.meta.env.META_MODE;
2545
- let publicDir;
2546
- if (mode === 'test' || mode === 'dev') {
2547
- publicDir = path.join(app.projectPath, '.app/public');
2548
- } else {
2549
- publicDir = path.join(getHomeVonaAppDir(app), 'public');
2550
- }
2551
- fse.ensureDirSync(publicDir);
2552
- return publicDir;
2553
- }
2554
- function getRuntimePathPhysicalRoot(app) {
2555
- const mode = app.meta.env.META_MODE;
2556
- let runtimeDir;
2557
- if (mode === 'test' || mode === 'dev') {
2558
- runtimeDir = path.join(app.options.projectPath, '.app/runtime');
2559
- } else {
2560
- runtimeDir = path.join(getHomeVonaAppDir(app), 'runtime');
2561
- }
2562
- fse.ensureDirSync(runtimeDir);
2563
- return runtimeDir;
2564
- }
2565
- function getHomeVonaAppDir(app) {
2566
- return path.join(os.homedir(), '.vona', app.name);
2567
- }
2568
-
2569
2680
  var enUs = {
2570
2681
  ...errorsInternal,
2571
2682
  ValidationFailedDev: 'controller: %s, method: %s, argument: %d'
@@ -3327,41 +3438,7 @@ async function retry(options, fn) {
3327
3438
  });
3328
3439
  }
3329
3440
 
3330
- function getSqlite3DatabaseNameDefault(app) {
3331
- const mode = app.meta.env.META_MODE;
3332
- if (mode !== 'prod') return '';
3333
- const dbPath = path.join(getHomeVonaAppDir(app), 'sqlite3');
3334
- fse.ensureDirSync(dbPath);
3335
- return path.join(dbPath, `${app.name}.db`);
3336
- }
3337
-
3338
- // string/true/false
3339
- function getSqlite3NativeBinding(_app, nativeBinding) {
3340
- nativeBinding = prepareNativeBinding(nativeBinding);
3341
- if (!nativeBinding) return nativeBinding;
3342
- const nativeBindingPath = path.isAbsolute(nativeBinding) ? nativeBinding : path.join(import.meta.dirname, nativeBinding);
3343
- const require = createRequire(import.meta.url);
3344
- const addon = require(nativeBindingPath);
3345
- return addon;
3346
- }
3347
- async function copySqlite3NativeBinding(projectPath, outDir, env) {
3348
- // dest
3349
- const nativeBinding = prepareNativeBinding(env.DATABASE_CLIENT_SQLITE3_NATIVEBINDING);
3350
- if (!nativeBinding || path.isAbsolute(nativeBinding)) return;
3351
- const fileDest = path.join(outDir, nativeBinding);
3352
- // src
3353
- const require = createRequire(pathToHref(path.join(projectPath, '/')));
3354
- const modulePath = require.resolve('better-sqlite3/package.json');
3355
- const fileSrc = path.join(path.dirname(modulePath), 'build/Release/better_sqlite3.node');
3356
- // copy
3357
- await fse.copy(fileSrc, fileDest);
3358
- }
3359
- function prepareNativeBinding(nativeBinding) {
3360
- if (!nativeBinding || nativeBinding === 'false') return null;
3361
- return nativeBinding === 'true' ? 'node/better_sqlite3.node' : nativeBinding;
3362
- }
3363
-
3364
3441
  zodExtendOpenApi();
3365
3442
 
3366
- export { $Class, $localeScope, $makeLocaleMagic, $protocolKey, AppHmr, AppHmrDeps, AppLocale, AppLogger, AppMeta, AppMetadata, AppResource, AppUtil, BeanAopBase, BeanAopMethodBase, BeanBase, BeanBaseSimple, BeanContainer, BeanInfo, BeanScopeBase, BeanScopeContainer, BeanScopeError, BeanScopeErrorImpl, BeanScopeLocale, BeanScopeScene, BeanScopeUtil, BeanSimple, EnumAppEvent, ErrorClass, Global, LocaleModuleNameSeparator, PickClassInner, ProxyDisable, SymbolBeanContainerInstances, SymbolBeanFullName, SymbolBeanInstanceKey, SymbolBeanInstancePropsLazy, SymbolCacheAopChains, SymbolCacheAopChainsKey, SymbolDecoratorBeanFullName, SymbolDecoratorBeanInfo, SymbolDecoratorGlobal, SymbolDecoratorProxyDisable, SymbolDecoratorUse, SymbolDecoratorVirtual, SymbolHmrStateLoad, SymbolHmrStateSave, SymbolMappedClassMetadataKeys, SymbolModuleBelong, SymbolModuleName, Use, Virtual, VonaApplication, __prepareInjectSelectorInfo, appHmrDeps, appMetadata, appResource, beanFullNameFromOnionName, bootstrap, cast, closeApp, combineConfigDefault, combineFilePathSafe, compose, copyMetadataOfClasses, copyProperties, copyPropertiesOfClasses, copySqlite3NativeBinding, createApp, createAppMaster, createBeanDecorator, createGeneralApp, createHash, deepExtend, disposeInstance, errorsInternal, filterHeaders, formatLoggerAxiosError, formatLoggerConsole, formatLoggerCtx, formatLoggerDummy, formatLoggerErrors, formatLoggerFilter, functionNoop, getHomeVonaAppDir, getLoggerPathPhysicalRoot, getMappedClassMetadataKeys, getPublicPathPhysicalRoot, getRuntimePathPhysicalRoot, getSqlite3DatabaseNameDefault, getSqlite3NativeBinding, instanceDesp, isLocaleMagic, loadJSONFile, onionNameFromBeanFullName, pathToHref, polyfillDispose, prepareEnv, registerMappedClassMetadataKey, requireDynamic, retry, saveJSONFile, setMappedClassMetadataKeys, text, useApp, usePrepareArg, usePrepareArgs, uuidv4 };
3443
+ export { $Class, $localeScope, $makeLocaleMagic, $protocolKey, AppHmr, AppHmrDeps, AppLocale, AppLogger, AppMeta, AppMetadata, AppResource, AppUtil, BeanAopBase, BeanAopMethodBase, BeanBase, BeanBaseSimple, BeanContainer, BeanInfo, BeanScopeBase, BeanScopeContainer, BeanScopeError, BeanScopeErrorImpl, BeanScopeLocale, BeanScopeScene, BeanScopeUtil, BeanSimple, EnumAppEvent, ErrorClass, Global, LocaleModuleNameSeparator, PickClassInner, ProxyDisable, SymbolBeanContainerInstances, SymbolBeanFullName, SymbolBeanInstanceKey, SymbolBeanInstancePropsLazy, SymbolCacheAopChains, SymbolCacheAopChainsKey, SymbolDecoratorBeanFullName, SymbolDecoratorBeanInfo, SymbolDecoratorGlobal, SymbolDecoratorProxyDisable, SymbolDecoratorUse, SymbolDecoratorVirtual, SymbolHmrStateLoad, SymbolHmrStateSave, SymbolMappedClassMetadataKeys, SymbolModuleBelong, SymbolModuleName, Use, Virtual, VonaApplication, __prepareInjectSelectorInfo, appHmrDeps, appMetadata, appResource, beanFullNameFromOnionName, bootstrap, cast, closeApp, combineConfigDefault, combineFilePathSafe, compose, copyAddon, copyMetadataOfClasses, copyProperties, copyPropertiesOfClasses, createApp, createAppMaster, createBeanDecorator, createGeneralApp, createHash, deepExtend, disposeInstance, errorsInternal, filterHeaders, formatLoggerAxiosError, formatLoggerConsole, formatLoggerCtx, formatLoggerDummy, formatLoggerErrors, formatLoggerFilter, functionNoop, getHomeVonaAppDir, getLoggerPathPhysicalRoot, getMappedClassMetadataKeys, getPlatformArch, getPublicPathPhysicalRoot, getRuntimePathPhysicalRoot, getSqlite3DatabaseNameDefault, instanceDesp, isLocaleMagic, loadJSONFile, onionNameFromBeanFullName, pathToHref, polyfillDispose, prepareEnv, registerMappedClassMetadataKey, requireAddon, requireDynamic, resolveAddon, resolverSharp, resolverSharpLibvips, resolverSqlite3, retry, saveJSONFile, setMappedClassMetadataKeys, text, useApp, usePrepareArg, usePrepareArgs, uuidv4 };
3367
3444
  //# sourceMappingURL=index.js.map