arkormx 2.0.0-next.10 → 2.0.0-next.12

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 CHANGED
@@ -1918,6 +1918,17 @@ const getPersistedEnumTsType = (values) => {
1918
1918
 
1919
1919
  //#endregion
1920
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
+ };
1921
1932
  const resolveDefaultStubsPath = () => {
1922
1933
  let current = path.dirname(fileURLToPath(import.meta.url));
1923
1934
  while (true) {
@@ -1950,16 +1961,128 @@ const userConfig = {
1950
1961
  features: { ...baseConfig.features ?? {} },
1951
1962
  paths: { ...baseConfig.paths ?? {} }
1952
1963
  };
1964
+ let runtimeConfigLoaded = false;
1965
+ let runtimeConfigLoadingPromise;
1966
+ let runtimeClientResolver;
1967
+ let runtimeAdapter;
1968
+ let runtimePaginationURLDriverFactory;
1969
+ let runtimePaginationCurrentPageResolver;
1953
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
+ };
1954
1999
  /**
1955
2000
  * Get the user-provided ArkORM configuration.
1956
2001
  *
1957
2002
  * @returns The user-provided ArkORM configuration object.
1958
2003
  */
1959
2004
  const getUserConfig = (key) => {
2005
+ if (!runtimeConfigLoaded) loadRuntimeConfigSync();
1960
2006
  if (key) return userConfig[key];
1961
2007
  return userConfig;
1962
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
+ const loadRuntimeConfigSync = () => {
2075
+ const syncConfigPaths = getRuntimeConfigPaths();
2076
+ for (const configPath of syncConfigPaths) {
2077
+ if (!existsSync$1(configPath)) continue;
2078
+ try {
2079
+ if (resolveAndApplyConfig(RuntimeModuleLoader.loadSync(configPath))) return true;
2080
+ } catch {
2081
+ continue;
2082
+ }
2083
+ }
2084
+ return false;
2085
+ };
1963
2086
  const getDefaultStubsPath = () => {
1964
2087
  return resolveDefaultStubsPath();
1965
2088
  };
package/dist/index.cjs CHANGED
@@ -28,11 +28,11 @@ 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
- node_path = __toESM(node_path);
36
36
  let fs = require("fs");
37
37
  let url = require("url");
38
38
  let node_fs = require("node:fs");
@@ -3027,6 +3027,7 @@ const bindAdapterToModels = (adapter, models) => {
3027
3027
  * @returns The user-provided ArkORM configuration object.
3028
3028
  */
3029
3029
  const getUserConfig = (key) => {
3030
+ if (!runtimeConfigLoaded) loadRuntimeConfigSync();
3030
3031
  if (key) return userConfig[key];
3031
3032
  return userConfig;
3032
3033
  };
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
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 * as path from "node:path";
7
- import { dirname, extname, join, resolve } from "node:path";
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";
@@ -2999,6 +2999,7 @@ const bindAdapterToModels = (adapter, models) => {
2999
2999
  * @returns The user-provided ArkORM configuration object.
3000
3000
  */
3001
3001
  const getUserConfig = (key) => {
3002
+ if (!runtimeConfigLoaded) loadRuntimeConfigSync();
3002
3003
  if (key) return userConfig[key];
3003
3004
  return userConfig;
3004
3005
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.0.0-next.10",
3
+ "version": "2.0.0-next.12",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",