arkormx 2.0.0-next.11 → 2.0.0-next.13
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/cli.mjs +163 -2
- package/dist/index.cjs +37 -24
- package/dist/index.mjs +26 -12
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
|
+
import * as path from "node:path";
|
|
4
5
|
import { dirname, extname, join, resolve } from "node:path";
|
|
5
6
|
import { spawnSync } from "node:child_process";
|
|
6
7
|
import { str } from "@h3ravel/support";
|
|
7
|
-
import
|
|
8
|
+
import { dirname as dirname$1, extname as extname$1, join as join$1, relative } from "path";
|
|
8
9
|
import { copyFileSync, existsSync as existsSync$1, mkdirSync as mkdirSync$1, readFileSync as readFileSync$1, readdirSync as readdirSync$1, rmSync as rmSync$1, writeFileSync as writeFileSync$1 } from "fs";
|
|
9
10
|
import { AsyncLocalStorage } from "async_hooks";
|
|
10
11
|
import { createJiti } from "@rexxars/jiti";
|
|
11
12
|
import { pathToFileURL } from "node:url";
|
|
12
|
-
import { createRequire } from "module";
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
14
|
import { Logger } from "@h3ravel/shared";
|
|
15
|
+
import { createRequire } from "module";
|
|
15
16
|
import { Command, Kernel } from "@h3ravel/musket";
|
|
16
17
|
|
|
17
18
|
//#region src/Exceptions/ArkormException.ts
|
|
@@ -1463,14 +1464,18 @@ var RuntimeModuleLoader = class {
|
|
|
1463
1464
|
static async load(filePath) {
|
|
1464
1465
|
const resolvedPath = resolve(filePath);
|
|
1465
1466
|
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1467
|
+
fsCache: false,
|
|
1466
1468
|
interopDefault: false,
|
|
1469
|
+
moduleCache: false,
|
|
1467
1470
|
tsconfigPaths: true
|
|
1468
1471
|
}).import(resolvedPath);
|
|
1469
1472
|
}
|
|
1470
1473
|
static loadSync(filePath) {
|
|
1471
1474
|
const resolvedPath = resolve(filePath);
|
|
1472
1475
|
return createJiti(pathToFileURL(resolvedPath).href, {
|
|
1476
|
+
fsCache: false,
|
|
1473
1477
|
interopDefault: false,
|
|
1478
|
+
moduleCache: false,
|
|
1474
1479
|
tsconfigPaths: true
|
|
1475
1480
|
})(resolvedPath);
|
|
1476
1481
|
}
|
|
@@ -1913,6 +1918,17 @@ const getPersistedEnumTsType = (values) => {
|
|
|
1913
1918
|
|
|
1914
1919
|
//#endregion
|
|
1915
1920
|
//#region src/helpers/runtime-config.ts
|
|
1921
|
+
const supportedConfigExtensions = [
|
|
1922
|
+
"cjs",
|
|
1923
|
+
"js",
|
|
1924
|
+
"mjs",
|
|
1925
|
+
"ts",
|
|
1926
|
+
"cts",
|
|
1927
|
+
"mts"
|
|
1928
|
+
];
|
|
1929
|
+
const getRuntimeConfigPaths = () => {
|
|
1930
|
+
return supportedConfigExtensions.map((extension) => path.join(process.cwd(), `arkormx.config.${extension}`));
|
|
1931
|
+
};
|
|
1916
1932
|
const resolveDefaultStubsPath = () => {
|
|
1917
1933
|
let current = path.dirname(fileURLToPath(import.meta.url));
|
|
1918
1934
|
while (true) {
|
|
@@ -1945,16 +1961,160 @@ const userConfig = {
|
|
|
1945
1961
|
features: { ...baseConfig.features ?? {} },
|
|
1946
1962
|
paths: { ...baseConfig.paths ?? {} }
|
|
1947
1963
|
};
|
|
1964
|
+
let runtimeConfigLoaded = false;
|
|
1965
|
+
let runtimeConfigLoadingPromise;
|
|
1966
|
+
let runtimeClientResolver;
|
|
1967
|
+
let runtimeAdapter;
|
|
1968
|
+
let runtimePaginationURLDriverFactory;
|
|
1969
|
+
let runtimePaginationCurrentPageResolver;
|
|
1948
1970
|
const transactionClientStorage = new AsyncLocalStorage();
|
|
1971
|
+
const mergePathConfig = (paths) => {
|
|
1972
|
+
const defaults = baseConfig.paths ?? {};
|
|
1973
|
+
const current = userConfig.paths ?? {};
|
|
1974
|
+
const incoming = Object.entries(paths ?? {}).reduce((all, [key, value]) => {
|
|
1975
|
+
if (typeof value === "string" && value.trim().length > 0) all[key] = path.isAbsolute(value) ? value : path.resolve(process.cwd(), value);
|
|
1976
|
+
return all;
|
|
1977
|
+
}, {});
|
|
1978
|
+
return {
|
|
1979
|
+
...defaults,
|
|
1980
|
+
...current,
|
|
1981
|
+
...incoming
|
|
1982
|
+
};
|
|
1983
|
+
};
|
|
1984
|
+
const mergeFeatureConfig = (features) => {
|
|
1985
|
+
const defaults = baseConfig.features ?? {};
|
|
1986
|
+
const current = userConfig.features ?? {};
|
|
1987
|
+
return {
|
|
1988
|
+
...defaults,
|
|
1989
|
+
...current,
|
|
1990
|
+
...features ?? {}
|
|
1991
|
+
};
|
|
1992
|
+
};
|
|
1993
|
+
const bindAdapterToModels = (adapter, models) => {
|
|
1994
|
+
models.forEach((model) => {
|
|
1995
|
+
model.setAdapter(adapter);
|
|
1996
|
+
});
|
|
1997
|
+
return adapter;
|
|
1998
|
+
};
|
|
1949
1999
|
/**
|
|
1950
2000
|
* Get the user-provided ArkORM configuration.
|
|
1951
2001
|
*
|
|
1952
2002
|
* @returns The user-provided ArkORM configuration object.
|
|
1953
2003
|
*/
|
|
1954
2004
|
const getUserConfig = (key) => {
|
|
2005
|
+
if (!runtimeConfigLoaded) loadRuntimeConfigSync();
|
|
1955
2006
|
if (key) return userConfig[key];
|
|
1956
2007
|
return userConfig;
|
|
1957
2008
|
};
|
|
2009
|
+
/**
|
|
2010
|
+
* Configure the ArkORM runtime with the provided Prisma client resolver and
|
|
2011
|
+
* delegate mapping resolver.
|
|
2012
|
+
*
|
|
2013
|
+
* @param prisma
|
|
2014
|
+
* @param mapping
|
|
2015
|
+
*/
|
|
2016
|
+
const configureArkormRuntime = (prisma, options = {}) => {
|
|
2017
|
+
const nextConfig = {
|
|
2018
|
+
...userConfig,
|
|
2019
|
+
features: mergeFeatureConfig(options.features),
|
|
2020
|
+
paths: mergePathConfig(options.paths)
|
|
2021
|
+
};
|
|
2022
|
+
nextConfig.prisma = prisma;
|
|
2023
|
+
if (options.pagination !== void 0) nextConfig.pagination = options.pagination;
|
|
2024
|
+
if (options.adapter !== void 0) nextConfig.adapter = options.adapter;
|
|
2025
|
+
if (options.boot !== void 0) nextConfig.boot = options.boot;
|
|
2026
|
+
if (options.outputExt !== void 0) nextConfig.outputExt = options.outputExt;
|
|
2027
|
+
Object.assign(userConfig, { ...nextConfig });
|
|
2028
|
+
runtimeClientResolver = prisma;
|
|
2029
|
+
runtimeAdapter = options.adapter;
|
|
2030
|
+
runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
|
|
2031
|
+
runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
|
|
2032
|
+
runtimeConfigLoaded = true;
|
|
2033
|
+
runtimeConfigLoadingPromise = void 0;
|
|
2034
|
+
options.boot?.({
|
|
2035
|
+
prisma: resolveClient(prisma),
|
|
2036
|
+
bindAdapter: bindAdapterToModels
|
|
2037
|
+
});
|
|
2038
|
+
};
|
|
2039
|
+
/**
|
|
2040
|
+
* Resolve a Prisma client instance from the provided resolver, which can be either
|
|
2041
|
+
* a direct client instance or a function that returns a client instance.
|
|
2042
|
+
*
|
|
2043
|
+
* @param resolver
|
|
2044
|
+
* @returns
|
|
2045
|
+
*/
|
|
2046
|
+
const resolveClient = (resolver) => {
|
|
2047
|
+
if (!resolver) return void 0;
|
|
2048
|
+
const client = typeof resolver === "function" ? resolver() : resolver;
|
|
2049
|
+
if (!client || typeof client !== "object") return void 0;
|
|
2050
|
+
return client;
|
|
2051
|
+
};
|
|
2052
|
+
/**
|
|
2053
|
+
* Resolve and apply the ArkORM configuration from an imported module.
|
|
2054
|
+
* This function checks for a default export and falls back to the module itself, then validates
|
|
2055
|
+
* the configuration object and applies it to the runtime if valid.
|
|
2056
|
+
*
|
|
2057
|
+
* @param imported
|
|
2058
|
+
* @returns
|
|
2059
|
+
*/
|
|
2060
|
+
const resolveAndApplyConfig = (imported) => {
|
|
2061
|
+
const config = imported?.default ?? imported;
|
|
2062
|
+
if (!config || typeof config !== "object") return false;
|
|
2063
|
+
configureArkormRuntime(config.prisma, {
|
|
2064
|
+
adapter: config.adapter,
|
|
2065
|
+
boot: config.boot,
|
|
2066
|
+
features: config.features,
|
|
2067
|
+
pagination: config.pagination,
|
|
2068
|
+
paths: config.paths,
|
|
2069
|
+
outputExt: config.outputExt
|
|
2070
|
+
});
|
|
2071
|
+
runtimeConfigLoaded = true;
|
|
2072
|
+
return true;
|
|
2073
|
+
};
|
|
2074
|
+
/**
|
|
2075
|
+
* Dynamically import a configuration file.
|
|
2076
|
+
* A cache-busting query parameter is appended to ensure the latest version is loaded.
|
|
2077
|
+
*
|
|
2078
|
+
* @param configPath
|
|
2079
|
+
* @returns A promise that resolves to the imported configuration module.
|
|
2080
|
+
*/
|
|
2081
|
+
const importConfigFile = (configPath) => {
|
|
2082
|
+
return RuntimeModuleLoader.load(configPath);
|
|
2083
|
+
};
|
|
2084
|
+
const loadRuntimeConfigSync = () => {
|
|
2085
|
+
const syncConfigPaths = getRuntimeConfigPaths();
|
|
2086
|
+
for (const configPath of syncConfigPaths) {
|
|
2087
|
+
if (!existsSync$1(configPath)) continue;
|
|
2088
|
+
try {
|
|
2089
|
+
if (resolveAndApplyConfig(RuntimeModuleLoader.loadSync(configPath))) return true;
|
|
2090
|
+
} catch {
|
|
2091
|
+
continue;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return false;
|
|
2095
|
+
};
|
|
2096
|
+
/**
|
|
2097
|
+
* Load the ArkORM configuration by searching for configuration files in the
|
|
2098
|
+
* current working directory.
|
|
2099
|
+
* @returns
|
|
2100
|
+
*/
|
|
2101
|
+
const loadArkormConfig = async () => {
|
|
2102
|
+
if (runtimeConfigLoaded) return;
|
|
2103
|
+
if (runtimeConfigLoadingPromise) return await runtimeConfigLoadingPromise;
|
|
2104
|
+
runtimeConfigLoadingPromise = (async () => {
|
|
2105
|
+
const configPaths = getRuntimeConfigPaths();
|
|
2106
|
+
for (const configPath of configPaths) {
|
|
2107
|
+
if (!existsSync$1(configPath)) continue;
|
|
2108
|
+
try {
|
|
2109
|
+
if (resolveAndApplyConfig(await importConfigFile(configPath))) return;
|
|
2110
|
+
} catch {
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
runtimeConfigLoaded = true;
|
|
2115
|
+
})();
|
|
2116
|
+
await runtimeConfigLoadingPromise;
|
|
2117
|
+
};
|
|
1958
2118
|
const getDefaultStubsPath = () => {
|
|
1959
2119
|
return resolveDefaultStubsPath();
|
|
1960
2120
|
};
|
|
@@ -3517,6 +3677,7 @@ var logo_default = String.raw`
|
|
|
3517
3677
|
|
|
3518
3678
|
//#endregion
|
|
3519
3679
|
//#region src/cli/index.ts
|
|
3680
|
+
await loadArkormConfig();
|
|
3520
3681
|
const app = new CliApp();
|
|
3521
3682
|
await Kernel.init(app, {
|
|
3522
3683
|
logo: logo_default,
|
package/dist/index.cjs
CHANGED
|
@@ -28,19 +28,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
//#endregion
|
|
29
29
|
let kysely = require("kysely");
|
|
30
30
|
let _h3ravel_support = require("@h3ravel/support");
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path);
|
|
31
33
|
let async_hooks = require("async_hooks");
|
|
32
34
|
let _rexxars_jiti = require("@rexxars/jiti");
|
|
33
35
|
let node_url = require("node:url");
|
|
34
|
-
let node_path = require("node:path");
|
|
35
|
-
let module$1 = require("module");
|
|
36
36
|
let fs = require("fs");
|
|
37
37
|
let url = require("url");
|
|
38
38
|
let node_fs = require("node:fs");
|
|
39
39
|
let node_crypto = require("node:crypto");
|
|
40
40
|
let node_child_process = require("node:child_process");
|
|
41
41
|
let path = require("path");
|
|
42
|
-
path = __toESM(path);
|
|
43
42
|
let _h3ravel_shared = require("@h3ravel/shared");
|
|
43
|
+
let module$1 = require("module");
|
|
44
44
|
let _h3ravel_musket = require("@h3ravel/musket");
|
|
45
45
|
let _h3ravel_collect_js = require("@h3ravel/collect.js");
|
|
46
46
|
|
|
@@ -1025,14 +1025,18 @@ var RuntimeModuleLoader = class {
|
|
|
1025
1025
|
static async load(filePath) {
|
|
1026
1026
|
const resolvedPath = (0, node_path.resolve)(filePath);
|
|
1027
1027
|
return await (0, _rexxars_jiti.createJiti)((0, node_url.pathToFileURL)(resolvedPath).href, {
|
|
1028
|
+
fsCache: false,
|
|
1028
1029
|
interopDefault: false,
|
|
1030
|
+
moduleCache: false,
|
|
1029
1031
|
tsconfigPaths: true
|
|
1030
1032
|
}).import(resolvedPath);
|
|
1031
1033
|
}
|
|
1032
1034
|
static loadSync(filePath) {
|
|
1033
1035
|
const resolvedPath = (0, node_path.resolve)(filePath);
|
|
1034
1036
|
return (0, _rexxars_jiti.createJiti)((0, node_url.pathToFileURL)(resolvedPath).href, {
|
|
1037
|
+
fsCache: false,
|
|
1035
1038
|
interopDefault: false,
|
|
1039
|
+
moduleCache: false,
|
|
1036
1040
|
tsconfigPaths: true
|
|
1037
1041
|
})(resolvedPath);
|
|
1038
1042
|
}
|
|
@@ -2930,17 +2934,28 @@ const getPersistedEnumTsType = (values) => {
|
|
|
2930
2934
|
|
|
2931
2935
|
//#endregion
|
|
2932
2936
|
//#region src/helpers/runtime-config.ts
|
|
2937
|
+
const supportedConfigExtensions = [
|
|
2938
|
+
"cjs",
|
|
2939
|
+
"js",
|
|
2940
|
+
"mjs",
|
|
2941
|
+
"ts",
|
|
2942
|
+
"cts",
|
|
2943
|
+
"mts"
|
|
2944
|
+
];
|
|
2945
|
+
const getRuntimeConfigPaths = () => {
|
|
2946
|
+
return supportedConfigExtensions.map((extension) => node_path.join(process.cwd(), `arkormx.config.${extension}`));
|
|
2947
|
+
};
|
|
2933
2948
|
const resolveDefaultStubsPath = () => {
|
|
2934
|
-
let current =
|
|
2949
|
+
let current = node_path.dirname((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
2935
2950
|
while (true) {
|
|
2936
|
-
const packageJsonPath =
|
|
2937
|
-
const stubsPath =
|
|
2951
|
+
const packageJsonPath = node_path.join(current, "package.json");
|
|
2952
|
+
const stubsPath = node_path.join(current, "stubs");
|
|
2938
2953
|
if ((0, fs.existsSync)(packageJsonPath) && (0, fs.existsSync)(stubsPath)) return stubsPath;
|
|
2939
|
-
const parent =
|
|
2954
|
+
const parent = node_path.dirname(current);
|
|
2940
2955
|
if (parent === current) break;
|
|
2941
2956
|
current = parent;
|
|
2942
2957
|
}
|
|
2943
|
-
return
|
|
2958
|
+
return node_path.join(process.cwd(), "stubs");
|
|
2944
2959
|
};
|
|
2945
2960
|
const baseConfig = {
|
|
2946
2961
|
features: {
|
|
@@ -2949,11 +2964,11 @@ const baseConfig = {
|
|
|
2949
2964
|
},
|
|
2950
2965
|
paths: {
|
|
2951
2966
|
stubs: resolveDefaultStubsPath(),
|
|
2952
|
-
seeders:
|
|
2953
|
-
models:
|
|
2954
|
-
migrations:
|
|
2955
|
-
factories:
|
|
2956
|
-
buildOutput:
|
|
2967
|
+
seeders: node_path.join(process.cwd(), "database", "seeders"),
|
|
2968
|
+
models: node_path.join(process.cwd(), "src", "models"),
|
|
2969
|
+
migrations: node_path.join(process.cwd(), "database", "migrations"),
|
|
2970
|
+
factories: node_path.join(process.cwd(), "database", "factories"),
|
|
2971
|
+
buildOutput: node_path.join(process.cwd(), "dist")
|
|
2957
2972
|
},
|
|
2958
2973
|
outputExt: "ts"
|
|
2959
2974
|
};
|
|
@@ -2973,7 +2988,7 @@ const mergePathConfig = (paths) => {
|
|
|
2973
2988
|
const defaults = baseConfig.paths ?? {};
|
|
2974
2989
|
const current = userConfig.paths ?? {};
|
|
2975
2990
|
const incoming = Object.entries(paths ?? {}).reduce((all, [key, value]) => {
|
|
2976
|
-
if (typeof value === "string" && value.trim().length > 0) all[key] =
|
|
2991
|
+
if (typeof value === "string" && value.trim().length > 0) all[key] = node_path.isAbsolute(value) ? value : node_path.resolve(process.cwd(), value);
|
|
2977
2992
|
return all;
|
|
2978
2993
|
}, {});
|
|
2979
2994
|
return {
|
|
@@ -3012,6 +3027,7 @@ const bindAdapterToModels = (adapter, models) => {
|
|
|
3012
3027
|
* @returns The user-provided ArkORM configuration object.
|
|
3013
3028
|
*/
|
|
3014
3029
|
const getUserConfig = (key) => {
|
|
3030
|
+
if (!runtimeConfigLoaded) loadRuntimeConfigSync();
|
|
3015
3031
|
if (key) return userConfig[key];
|
|
3016
3032
|
return userConfig;
|
|
3017
3033
|
};
|
|
@@ -3089,7 +3105,7 @@ const resolveClient = (resolver) => {
|
|
|
3089
3105
|
*/
|
|
3090
3106
|
const resolveAndApplyConfig = (imported) => {
|
|
3091
3107
|
const config = imported?.default ?? imported;
|
|
3092
|
-
if (!config || typeof config !== "object") return;
|
|
3108
|
+
if (!config || typeof config !== "object") return false;
|
|
3093
3109
|
configureArkormRuntime(config.prisma, {
|
|
3094
3110
|
adapter: config.adapter,
|
|
3095
3111
|
boot: config.boot,
|
|
@@ -3099,6 +3115,7 @@ const resolveAndApplyConfig = (imported) => {
|
|
|
3099
3115
|
outputExt: config.outputExt
|
|
3100
3116
|
});
|
|
3101
3117
|
runtimeConfigLoaded = true;
|
|
3118
|
+
return true;
|
|
3102
3119
|
};
|
|
3103
3120
|
/**
|
|
3104
3121
|
* Dynamically import a configuration file.
|
|
@@ -3111,13 +3128,11 @@ const importConfigFile = (configPath) => {
|
|
|
3111
3128
|
return RuntimeModuleLoader.load(configPath);
|
|
3112
3129
|
};
|
|
3113
3130
|
const loadRuntimeConfigSync = () => {
|
|
3114
|
-
const
|
|
3115
|
-
const syncConfigPaths = [path.default.join(process.cwd(), "arkormx.config.cjs")];
|
|
3131
|
+
const syncConfigPaths = getRuntimeConfigPaths();
|
|
3116
3132
|
for (const configPath of syncConfigPaths) {
|
|
3117
3133
|
if (!(0, fs.existsSync)(configPath)) continue;
|
|
3118
3134
|
try {
|
|
3119
|
-
resolveAndApplyConfig(
|
|
3120
|
-
return true;
|
|
3135
|
+
if (resolveAndApplyConfig(RuntimeModuleLoader.loadSync(configPath))) return true;
|
|
3121
3136
|
} catch {
|
|
3122
3137
|
continue;
|
|
3123
3138
|
}
|
|
@@ -3132,14 +3147,12 @@ const loadRuntimeConfigSync = () => {
|
|
|
3132
3147
|
const loadArkormConfig = async () => {
|
|
3133
3148
|
if (runtimeConfigLoaded) return;
|
|
3134
3149
|
if (runtimeConfigLoadingPromise) return await runtimeConfigLoadingPromise;
|
|
3135
|
-
if (loadRuntimeConfigSync()) return;
|
|
3136
3150
|
runtimeConfigLoadingPromise = (async () => {
|
|
3137
|
-
const configPaths =
|
|
3151
|
+
const configPaths = getRuntimeConfigPaths();
|
|
3138
3152
|
for (const configPath of configPaths) {
|
|
3139
3153
|
if (!(0, fs.existsSync)(configPath)) continue;
|
|
3140
3154
|
try {
|
|
3141
|
-
resolveAndApplyConfig(await importConfigFile(configPath));
|
|
3142
|
-
return;
|
|
3155
|
+
if (resolveAndApplyConfig(await importConfigFile(configPath))) return;
|
|
3143
3156
|
} catch {
|
|
3144
3157
|
continue;
|
|
3145
3158
|
}
|
|
@@ -3880,7 +3893,7 @@ var CliApp = class {
|
|
|
3880
3893
|
} else candidates.push(mappedFile);
|
|
3881
3894
|
}
|
|
3882
3895
|
}
|
|
3883
|
-
const runtimeMatch = candidates.find((path$
|
|
3896
|
+
const runtimeMatch = candidates.find((path$1) => (0, fs.existsSync)(path$1));
|
|
3884
3897
|
if (runtimeMatch) return runtimeMatch;
|
|
3885
3898
|
return filePath;
|
|
3886
3899
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { sql } from "kysely";
|
|
2
2
|
import { str } from "@h3ravel/support";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
3
5
|
import { AsyncLocalStorage } from "async_hooks";
|
|
4
6
|
import { createJiti } from "@rexxars/jiti";
|
|
5
7
|
import { pathToFileURL } from "node:url";
|
|
6
|
-
import { dirname, extname, join, resolve } from "node:path";
|
|
7
|
-
import { createRequire } from "module";
|
|
8
8
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "fs";
|
|
9
9
|
import { fileURLToPath } from "url";
|
|
10
10
|
import { existsSync as existsSync$1, mkdirSync as mkdirSync$1, readFileSync as readFileSync$1, readdirSync as readdirSync$1, rmSync as rmSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
|
|
11
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
12
12
|
import { spawnSync } from "node:child_process";
|
|
13
|
-
import
|
|
13
|
+
import { dirname as dirname$1, extname as extname$1, join as join$1, relative } from "path";
|
|
14
14
|
import { Logger } from "@h3ravel/shared";
|
|
15
|
+
import { createRequire } from "module";
|
|
15
16
|
import { Command } from "@h3ravel/musket";
|
|
16
17
|
import { Collection } from "@h3ravel/collect.js";
|
|
17
18
|
|
|
@@ -996,14 +997,18 @@ var RuntimeModuleLoader = class {
|
|
|
996
997
|
static async load(filePath) {
|
|
997
998
|
const resolvedPath = resolve(filePath);
|
|
998
999
|
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1000
|
+
fsCache: false,
|
|
999
1001
|
interopDefault: false,
|
|
1002
|
+
moduleCache: false,
|
|
1000
1003
|
tsconfigPaths: true
|
|
1001
1004
|
}).import(resolvedPath);
|
|
1002
1005
|
}
|
|
1003
1006
|
static loadSync(filePath) {
|
|
1004
1007
|
const resolvedPath = resolve(filePath);
|
|
1005
1008
|
return createJiti(pathToFileURL(resolvedPath).href, {
|
|
1009
|
+
fsCache: false,
|
|
1006
1010
|
interopDefault: false,
|
|
1011
|
+
moduleCache: false,
|
|
1007
1012
|
tsconfigPaths: true
|
|
1008
1013
|
})(resolvedPath);
|
|
1009
1014
|
}
|
|
@@ -2901,6 +2906,17 @@ const getPersistedEnumTsType = (values) => {
|
|
|
2901
2906
|
|
|
2902
2907
|
//#endregion
|
|
2903
2908
|
//#region src/helpers/runtime-config.ts
|
|
2909
|
+
const supportedConfigExtensions = [
|
|
2910
|
+
"cjs",
|
|
2911
|
+
"js",
|
|
2912
|
+
"mjs",
|
|
2913
|
+
"ts",
|
|
2914
|
+
"cts",
|
|
2915
|
+
"mts"
|
|
2916
|
+
];
|
|
2917
|
+
const getRuntimeConfigPaths = () => {
|
|
2918
|
+
return supportedConfigExtensions.map((extension) => path.join(process.cwd(), `arkormx.config.${extension}`));
|
|
2919
|
+
};
|
|
2904
2920
|
const resolveDefaultStubsPath = () => {
|
|
2905
2921
|
let current = path.dirname(fileURLToPath(import.meta.url));
|
|
2906
2922
|
while (true) {
|
|
@@ -2983,6 +2999,7 @@ const bindAdapterToModels = (adapter, models) => {
|
|
|
2983
2999
|
* @returns The user-provided ArkORM configuration object.
|
|
2984
3000
|
*/
|
|
2985
3001
|
const getUserConfig = (key) => {
|
|
3002
|
+
if (!runtimeConfigLoaded) loadRuntimeConfigSync();
|
|
2986
3003
|
if (key) return userConfig[key];
|
|
2987
3004
|
return userConfig;
|
|
2988
3005
|
};
|
|
@@ -3060,7 +3077,7 @@ const resolveClient = (resolver) => {
|
|
|
3060
3077
|
*/
|
|
3061
3078
|
const resolveAndApplyConfig = (imported) => {
|
|
3062
3079
|
const config = imported?.default ?? imported;
|
|
3063
|
-
if (!config || typeof config !== "object") return;
|
|
3080
|
+
if (!config || typeof config !== "object") return false;
|
|
3064
3081
|
configureArkormRuntime(config.prisma, {
|
|
3065
3082
|
adapter: config.adapter,
|
|
3066
3083
|
boot: config.boot,
|
|
@@ -3070,6 +3087,7 @@ const resolveAndApplyConfig = (imported) => {
|
|
|
3070
3087
|
outputExt: config.outputExt
|
|
3071
3088
|
});
|
|
3072
3089
|
runtimeConfigLoaded = true;
|
|
3090
|
+
return true;
|
|
3073
3091
|
};
|
|
3074
3092
|
/**
|
|
3075
3093
|
* Dynamically import a configuration file.
|
|
@@ -3082,13 +3100,11 @@ const importConfigFile = (configPath) => {
|
|
|
3082
3100
|
return RuntimeModuleLoader.load(configPath);
|
|
3083
3101
|
};
|
|
3084
3102
|
const loadRuntimeConfigSync = () => {
|
|
3085
|
-
const
|
|
3086
|
-
const syncConfigPaths = [path.join(process.cwd(), "arkormx.config.cjs")];
|
|
3103
|
+
const syncConfigPaths = getRuntimeConfigPaths();
|
|
3087
3104
|
for (const configPath of syncConfigPaths) {
|
|
3088
3105
|
if (!existsSync(configPath)) continue;
|
|
3089
3106
|
try {
|
|
3090
|
-
resolveAndApplyConfig(
|
|
3091
|
-
return true;
|
|
3107
|
+
if (resolveAndApplyConfig(RuntimeModuleLoader.loadSync(configPath))) return true;
|
|
3092
3108
|
} catch {
|
|
3093
3109
|
continue;
|
|
3094
3110
|
}
|
|
@@ -3103,14 +3119,12 @@ const loadRuntimeConfigSync = () => {
|
|
|
3103
3119
|
const loadArkormConfig = async () => {
|
|
3104
3120
|
if (runtimeConfigLoaded) return;
|
|
3105
3121
|
if (runtimeConfigLoadingPromise) return await runtimeConfigLoadingPromise;
|
|
3106
|
-
if (loadRuntimeConfigSync()) return;
|
|
3107
3122
|
runtimeConfigLoadingPromise = (async () => {
|
|
3108
|
-
const configPaths =
|
|
3123
|
+
const configPaths = getRuntimeConfigPaths();
|
|
3109
3124
|
for (const configPath of configPaths) {
|
|
3110
3125
|
if (!existsSync(configPath)) continue;
|
|
3111
3126
|
try {
|
|
3112
|
-
resolveAndApplyConfig(await importConfigFile(configPath));
|
|
3113
|
-
return;
|
|
3127
|
+
if (resolveAndApplyConfig(await importConfigFile(configPath))) return;
|
|
3114
3128
|
} catch {
|
|
3115
3129
|
continue;
|
|
3116
3130
|
}
|