arkormx 2.0.0-next.7 → 2.0.0-next.8
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 +24 -158
- package/dist/index.cjs +3074 -2962
- package/dist/index.d.cts +27 -1
- package/dist/index.d.mts +27 -1
- package/dist/index.mjs +3138 -3027
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -9,9 +9,9 @@ import { copyFileSync, existsSync as existsSync$1, mkdirSync as mkdirSync$1, rea
|
|
|
9
9
|
import { AsyncLocalStorage } from "async_hooks";
|
|
10
10
|
import { createJiti } from "@rexxars/jiti";
|
|
11
11
|
import { pathToFileURL } from "node:url";
|
|
12
|
-
import { createRequire } from "module";
|
|
13
12
|
import { fileURLToPath } from "url";
|
|
14
13
|
import { Logger } from "@h3ravel/shared";
|
|
14
|
+
import { createRequire } from "module";
|
|
15
15
|
import { Command, Kernel } from "@h3ravel/musket";
|
|
16
16
|
|
|
17
17
|
//#region src/Exceptions/ArkormException.ts
|
|
@@ -1457,6 +1457,29 @@ const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) =>
|
|
|
1457
1457
|
};
|
|
1458
1458
|
};
|
|
1459
1459
|
|
|
1460
|
+
//#endregion
|
|
1461
|
+
//#region src/helpers/runtime-module-loader.ts
|
|
1462
|
+
var RuntimeModuleLoader = class {
|
|
1463
|
+
static async load(filePath) {
|
|
1464
|
+
const resolvedPath = resolve(filePath);
|
|
1465
|
+
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1466
|
+
fsCache: false,
|
|
1467
|
+
interopDefault: false,
|
|
1468
|
+
moduleCache: false,
|
|
1469
|
+
tsconfigPaths: true
|
|
1470
|
+
}).import(resolvedPath);
|
|
1471
|
+
}
|
|
1472
|
+
static loadSync(filePath) {
|
|
1473
|
+
const resolvedPath = resolve(filePath);
|
|
1474
|
+
return createJiti(pathToFileURL(resolvedPath).href, {
|
|
1475
|
+
fsCache: false,
|
|
1476
|
+
interopDefault: false,
|
|
1477
|
+
moduleCache: false,
|
|
1478
|
+
tsconfigPaths: true
|
|
1479
|
+
})(resolvedPath);
|
|
1480
|
+
}
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1460
1483
|
//#endregion
|
|
1461
1484
|
//#region src/helpers/migration-history.ts
|
|
1462
1485
|
const createEmptyAppliedMigrationsState = () => ({
|
|
@@ -1892,18 +1915,6 @@ const getPersistedEnumTsType = (values) => {
|
|
|
1892
1915
|
return buildEnumUnionType(values);
|
|
1893
1916
|
};
|
|
1894
1917
|
|
|
1895
|
-
//#endregion
|
|
1896
|
-
//#region src/helpers/runtime-module-loader.ts
|
|
1897
|
-
var RuntimeModuleLoader = class {
|
|
1898
|
-
static async load(filePath) {
|
|
1899
|
-
const resolvedPath = resolve(filePath);
|
|
1900
|
-
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1901
|
-
interopDefault: false,
|
|
1902
|
-
tsconfigPaths: true
|
|
1903
|
-
}).import(resolvedPath);
|
|
1904
|
-
}
|
|
1905
|
-
};
|
|
1906
|
-
|
|
1907
1918
|
//#endregion
|
|
1908
1919
|
//#region src/helpers/runtime-config.ts
|
|
1909
1920
|
const resolveDefaultStubsPath = () => {
|
|
@@ -1938,41 +1949,7 @@ const userConfig = {
|
|
|
1938
1949
|
features: { ...baseConfig.features ?? {} },
|
|
1939
1950
|
paths: { ...baseConfig.paths ?? {} }
|
|
1940
1951
|
};
|
|
1941
|
-
let runtimeConfigLoaded = false;
|
|
1942
|
-
let runtimeConfigLoadingPromise;
|
|
1943
|
-
let runtimeClientResolver;
|
|
1944
|
-
let runtimeAdapter;
|
|
1945
|
-
let runtimePaginationURLDriverFactory;
|
|
1946
|
-
let runtimePaginationCurrentPageResolver;
|
|
1947
1952
|
const transactionClientStorage = new AsyncLocalStorage();
|
|
1948
|
-
const mergePathConfig = (paths) => {
|
|
1949
|
-
const defaults = baseConfig.paths ?? {};
|
|
1950
|
-
const current = userConfig.paths ?? {};
|
|
1951
|
-
const incoming = Object.entries(paths ?? {}).reduce((all, [key, value]) => {
|
|
1952
|
-
if (typeof value === "string" && value.trim().length > 0) all[key] = path.isAbsolute(value) ? value : path.resolve(process.cwd(), value);
|
|
1953
|
-
return all;
|
|
1954
|
-
}, {});
|
|
1955
|
-
return {
|
|
1956
|
-
...defaults,
|
|
1957
|
-
...current,
|
|
1958
|
-
...incoming
|
|
1959
|
-
};
|
|
1960
|
-
};
|
|
1961
|
-
const mergeFeatureConfig = (features) => {
|
|
1962
|
-
const defaults = baseConfig.features ?? {};
|
|
1963
|
-
const current = userConfig.features ?? {};
|
|
1964
|
-
return {
|
|
1965
|
-
...defaults,
|
|
1966
|
-
...current,
|
|
1967
|
-
...features ?? {}
|
|
1968
|
-
};
|
|
1969
|
-
};
|
|
1970
|
-
const bindAdapterToModels = (adapter, models) => {
|
|
1971
|
-
models.forEach((model) => {
|
|
1972
|
-
model.setAdapter(adapter);
|
|
1973
|
-
});
|
|
1974
|
-
return adapter;
|
|
1975
|
-
};
|
|
1976
1953
|
/**
|
|
1977
1954
|
* Get the user-provided ArkORM configuration.
|
|
1978
1955
|
*
|
|
@@ -1982,120 +1959,9 @@ const getUserConfig = (key) => {
|
|
|
1982
1959
|
if (key) return userConfig[key];
|
|
1983
1960
|
return userConfig;
|
|
1984
1961
|
};
|
|
1985
|
-
/**
|
|
1986
|
-
* Configure the ArkORM runtime with the provided Prisma client resolver and
|
|
1987
|
-
* delegate mapping resolver.
|
|
1988
|
-
*
|
|
1989
|
-
* @param prisma
|
|
1990
|
-
* @param mapping
|
|
1991
|
-
*/
|
|
1992
|
-
const configureArkormRuntime = (prisma, options = {}) => {
|
|
1993
|
-
const nextConfig = {
|
|
1994
|
-
...userConfig,
|
|
1995
|
-
features: mergeFeatureConfig(options.features),
|
|
1996
|
-
paths: mergePathConfig(options.paths)
|
|
1997
|
-
};
|
|
1998
|
-
nextConfig.prisma = prisma;
|
|
1999
|
-
if (options.pagination !== void 0) nextConfig.pagination = options.pagination;
|
|
2000
|
-
if (options.adapter !== void 0) nextConfig.adapter = options.adapter;
|
|
2001
|
-
if (options.boot !== void 0) nextConfig.boot = options.boot;
|
|
2002
|
-
if (options.outputExt !== void 0) nextConfig.outputExt = options.outputExt;
|
|
2003
|
-
Object.assign(userConfig, { ...nextConfig });
|
|
2004
|
-
runtimeClientResolver = prisma;
|
|
2005
|
-
runtimeAdapter = options.adapter;
|
|
2006
|
-
runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
|
|
2007
|
-
runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
|
|
2008
|
-
options.boot?.({
|
|
2009
|
-
prisma: resolveClient(prisma),
|
|
2010
|
-
bindAdapter: bindAdapterToModels
|
|
2011
|
-
});
|
|
2012
|
-
};
|
|
2013
|
-
/**
|
|
2014
|
-
* Resolve a Prisma client instance from the provided resolver, which can be either
|
|
2015
|
-
* a direct client instance or a function that returns a client instance.
|
|
2016
|
-
*
|
|
2017
|
-
* @param resolver
|
|
2018
|
-
* @returns
|
|
2019
|
-
*/
|
|
2020
|
-
const resolveClient = (resolver) => {
|
|
2021
|
-
if (!resolver) return void 0;
|
|
2022
|
-
const client = typeof resolver === "function" ? resolver() : resolver;
|
|
2023
|
-
if (!client || typeof client !== "object") return void 0;
|
|
2024
|
-
return client;
|
|
2025
|
-
};
|
|
2026
|
-
/**
|
|
2027
|
-
* Resolve and apply the ArkORM configuration from an imported module.
|
|
2028
|
-
* This function checks for a default export and falls back to the module itself, then validates
|
|
2029
|
-
* the configuration object and applies it to the runtime if valid.
|
|
2030
|
-
*
|
|
2031
|
-
* @param imported
|
|
2032
|
-
* @returns
|
|
2033
|
-
*/
|
|
2034
|
-
const resolveAndApplyConfig = (imported) => {
|
|
2035
|
-
const config = imported?.default ?? imported;
|
|
2036
|
-
if (!config || typeof config !== "object") return;
|
|
2037
|
-
configureArkormRuntime(config.prisma, {
|
|
2038
|
-
adapter: config.adapter,
|
|
2039
|
-
boot: config.boot,
|
|
2040
|
-
features: config.features,
|
|
2041
|
-
pagination: config.pagination,
|
|
2042
|
-
paths: config.paths,
|
|
2043
|
-
outputExt: config.outputExt
|
|
2044
|
-
});
|
|
2045
|
-
runtimeConfigLoaded = true;
|
|
2046
|
-
};
|
|
2047
|
-
/**
|
|
2048
|
-
* Dynamically import a configuration file.
|
|
2049
|
-
* A cache-busting query parameter is appended to ensure the latest version is loaded.
|
|
2050
|
-
*
|
|
2051
|
-
* @param configPath
|
|
2052
|
-
* @returns A promise that resolves to the imported configuration module.
|
|
2053
|
-
*/
|
|
2054
|
-
const importConfigFile = (configPath) => {
|
|
2055
|
-
return RuntimeModuleLoader.load(configPath);
|
|
2056
|
-
};
|
|
2057
|
-
const loadRuntimeConfigSync = () => {
|
|
2058
|
-
const require = createRequire(import.meta.url);
|
|
2059
|
-
const syncConfigPaths = [path.join(process.cwd(), "arkormx.config.cjs")];
|
|
2060
|
-
for (const configPath of syncConfigPaths) {
|
|
2061
|
-
if (!existsSync$1(configPath)) continue;
|
|
2062
|
-
try {
|
|
2063
|
-
resolveAndApplyConfig(require(configPath));
|
|
2064
|
-
return true;
|
|
2065
|
-
} catch {
|
|
2066
|
-
continue;
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
return false;
|
|
2070
|
-
};
|
|
2071
|
-
/**
|
|
2072
|
-
* Load the ArkORM configuration by searching for configuration files in the
|
|
2073
|
-
* current working directory.
|
|
2074
|
-
* @returns
|
|
2075
|
-
*/
|
|
2076
|
-
const loadArkormConfig = async () => {
|
|
2077
|
-
if (runtimeConfigLoaded) return;
|
|
2078
|
-
if (runtimeConfigLoadingPromise) return await runtimeConfigLoadingPromise;
|
|
2079
|
-
if (loadRuntimeConfigSync()) return;
|
|
2080
|
-
runtimeConfigLoadingPromise = (async () => {
|
|
2081
|
-
const configPaths = [path.join(process.cwd(), "arkormx.config.js"), path.join(process.cwd(), "arkormx.config.ts")];
|
|
2082
|
-
for (const configPath of configPaths) {
|
|
2083
|
-
if (!existsSync$1(configPath)) continue;
|
|
2084
|
-
try {
|
|
2085
|
-
resolveAndApplyConfig(await importConfigFile(configPath));
|
|
2086
|
-
return;
|
|
2087
|
-
} catch {
|
|
2088
|
-
continue;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
runtimeConfigLoaded = true;
|
|
2092
|
-
})();
|
|
2093
|
-
await runtimeConfigLoadingPromise;
|
|
2094
|
-
};
|
|
2095
1962
|
const getDefaultStubsPath = () => {
|
|
2096
1963
|
return resolveDefaultStubsPath();
|
|
2097
1964
|
};
|
|
2098
|
-
loadArkormConfig();
|
|
2099
1965
|
|
|
2100
1966
|
//#endregion
|
|
2101
1967
|
//#region src/cli/CliApp.ts
|