vona-core 5.0.103 → 5.0.104

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.
@@ -1,3 +1,4 @@
1
1
  export * from './customKey.ts';
2
2
  export * from './retry.ts';
3
+ export * from './sqlite3.ts';
3
4
  export * from './util.ts';
@@ -1,5 +1,6 @@
1
1
  import { zodExtendOpenApi } from "./zod-openapi.js";
2
2
  export * from "./customKey.js";
3
3
  export * from "./retry.js";
4
+ export * from "./sqlite3.js";
4
5
  export * from "./util.js";
5
6
  zodExtendOpenApi();
@@ -0,0 +1,4 @@
1
+ import type { VonaApplication } from '../core/application.ts';
2
+ export declare function getSqlite3DatabaseNameDefault(app: VonaApplication): string;
3
+ export declare function getSqlite3NativeBinding(_app: VonaApplication, nativeBinding: string | undefined): any;
4
+ export declare function copySqlite3NativeBinding(projectPath: string, outDir: string, env: NodeJS.ProcessEnv): Promise<void>;
@@ -0,0 +1,38 @@
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vona-core",
3
3
  "type": "module",
4
- "version": "5.0.103",
4
+ "version": "5.0.104",
5
5
  "description": "vona",
6
6
  "publishConfig": {
7
7
  "access": "public"