arkormx 2.0.0-next.6 → 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 +70 -165
- package/dist/index.cjs +3078 -2905
- package/dist/index.d.cts +45 -1
- package/dist/index.d.mts +45 -1
- package/dist/index.mjs +3185 -3014
- 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 = () => ({
|
|
@@ -1613,7 +1636,7 @@ const normalizePersistedTableMetadata = (table) => {
|
|
|
1613
1636
|
enums: {}
|
|
1614
1637
|
};
|
|
1615
1638
|
const candidate = table;
|
|
1616
|
-
if (!(Object.prototype.hasOwnProperty.call(candidate, "columns") || Object.prototype.hasOwnProperty.call(candidate, "enums"))) return {
|
|
1639
|
+
if (!(Object.prototype.hasOwnProperty.call(candidate, "columns") || Object.prototype.hasOwnProperty.call(candidate, "enums") || Object.prototype.hasOwnProperty.call(candidate, "primaryKeyGeneration") || Object.prototype.hasOwnProperty.call(candidate, "timestampColumns"))) return {
|
|
1617
1640
|
columns: normalizeLegacyTableColumns(candidate),
|
|
1618
1641
|
enums: {}
|
|
1619
1642
|
};
|
|
@@ -1625,7 +1648,8 @@ const normalizePersistedTableMetadata = (table) => {
|
|
|
1625
1648
|
if (normalizedValues.length > 0) all[columnName] = normalizedValues;
|
|
1626
1649
|
return all;
|
|
1627
1650
|
}, {}),
|
|
1628
|
-
primaryKeyGeneration: normalizePersistedPrimaryKeyGeneration(candidate.primaryKeyGeneration)
|
|
1651
|
+
primaryKeyGeneration: normalizePersistedPrimaryKeyGeneration(candidate.primaryKeyGeneration),
|
|
1652
|
+
timestampColumns: normalizePersistedTimestampColumns(candidate.timestampColumns)
|
|
1629
1653
|
};
|
|
1630
1654
|
};
|
|
1631
1655
|
const normalizePersistedPrimaryKeyGeneration = (value) => {
|
|
@@ -1640,13 +1664,28 @@ const normalizePersistedPrimaryKeyGeneration = (value) => {
|
|
|
1640
1664
|
runtimeFactory: candidate.runtimeFactory === "uuid" ? "uuid" : void 0
|
|
1641
1665
|
};
|
|
1642
1666
|
};
|
|
1667
|
+
const normalizePersistedTimestampColumns = (value) => {
|
|
1668
|
+
if (!Array.isArray(value)) return void 0;
|
|
1669
|
+
const columns = value.reduce((all, entry) => {
|
|
1670
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return all;
|
|
1671
|
+
const candidate = entry;
|
|
1672
|
+
if (typeof candidate.column !== "string" || candidate.column.trim().length === 0) return all;
|
|
1673
|
+
const normalized = { column: candidate.column };
|
|
1674
|
+
if (candidate.default === "now()") normalized.default = "now()";
|
|
1675
|
+
if (candidate.updatedAt === true) normalized.updatedAt = true;
|
|
1676
|
+
if (!normalized.default && !normalized.updatedAt) return all;
|
|
1677
|
+
all.push(normalized);
|
|
1678
|
+
return all;
|
|
1679
|
+
}, []);
|
|
1680
|
+
return columns.length > 0 ? columns : void 0;
|
|
1681
|
+
};
|
|
1643
1682
|
const normalizePersistedColumnMappingsState = (state) => {
|
|
1644
1683
|
return {
|
|
1645
1684
|
version: 1,
|
|
1646
1685
|
tables: Object.entries(state?.tables ?? {}).reduce((all, [tableName, tableMetadata]) => {
|
|
1647
1686
|
if (tableName.trim().length === 0) return all;
|
|
1648
1687
|
const normalized = normalizePersistedTableMetadata(tableMetadata);
|
|
1649
|
-
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0 || normalized.primaryKeyGeneration) all[tableName] = normalized;
|
|
1688
|
+
if (Object.keys(normalized.columns).length > 0 || Object.keys(normalized.enums).length > 0 || normalized.primaryKeyGeneration || normalized.timestampColumns?.length) all[tableName] = normalized;
|
|
1650
1689
|
return all;
|
|
1651
1690
|
}, {})
|
|
1652
1691
|
};
|
|
@@ -1718,7 +1757,8 @@ const getPersistedTableMetadata = (table, options = {}) => {
|
|
|
1718
1757
|
all[columnName] = [...values];
|
|
1719
1758
|
return all;
|
|
1720
1759
|
}, {}),
|
|
1721
|
-
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
1760
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0,
|
|
1761
|
+
timestampColumns: metadata.timestampColumns?.map((column) => ({ ...column }))
|
|
1722
1762
|
};
|
|
1723
1763
|
};
|
|
1724
1764
|
const applyMappedColumn = (tableColumns, column, features, table) => {
|
|
@@ -1745,6 +1785,10 @@ const removePersistedColumnMetadata = (tableMetadata, columnName) => {
|
|
|
1745
1785
|
if (mappedColumn === columnName) delete tableMetadata.columns[attribute];
|
|
1746
1786
|
});
|
|
1747
1787
|
if (tableMetadata.primaryKeyGeneration?.column === columnName) delete tableMetadata.primaryKeyGeneration;
|
|
1788
|
+
if (tableMetadata.timestampColumns) {
|
|
1789
|
+
tableMetadata.timestampColumns = tableMetadata.timestampColumns.filter((column) => column.column !== columnName);
|
|
1790
|
+
if (tableMetadata.timestampColumns.length === 0) delete tableMetadata.timestampColumns;
|
|
1791
|
+
}
|
|
1748
1792
|
};
|
|
1749
1793
|
const applyPrimaryKeyGeneration = (tableMetadata, column) => {
|
|
1750
1794
|
if (!column.primary || !column.primaryKeyGeneration) {
|
|
@@ -1756,6 +1800,21 @@ const applyPrimaryKeyGeneration = (tableMetadata, column) => {
|
|
|
1756
1800
|
...column.primaryKeyGeneration
|
|
1757
1801
|
};
|
|
1758
1802
|
};
|
|
1803
|
+
const applyTimestampColumn = (tableMetadata, column) => {
|
|
1804
|
+
if (column.type !== "timestamp" || column.default !== "now()" && column.updatedAt !== true) {
|
|
1805
|
+
if (tableMetadata.timestampColumns) {
|
|
1806
|
+
tableMetadata.timestampColumns = tableMetadata.timestampColumns.filter((entry) => entry.column !== column.name);
|
|
1807
|
+
if (tableMetadata.timestampColumns.length === 0) delete tableMetadata.timestampColumns;
|
|
1808
|
+
}
|
|
1809
|
+
return;
|
|
1810
|
+
}
|
|
1811
|
+
const nextColumn = {
|
|
1812
|
+
column: column.name,
|
|
1813
|
+
...column.default === "now()" ? { default: "now()" } : {},
|
|
1814
|
+
...column.updatedAt ? { updatedAt: true } : {}
|
|
1815
|
+
};
|
|
1816
|
+
tableMetadata.timestampColumns = [...(tableMetadata.timestampColumns ?? []).filter((entry) => entry.column !== column.name), nextColumn];
|
|
1817
|
+
};
|
|
1759
1818
|
const applyOperationsToPersistedColumnMappingsState = (state, operations, features = resolvePersistedMetadataFeatures()) => {
|
|
1760
1819
|
const nextTables = Object.entries(state.tables).reduce((all, [table, metadata]) => {
|
|
1761
1820
|
all[table] = {
|
|
@@ -1764,7 +1823,8 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1764
1823
|
nextEnums[columnName] = [...values];
|
|
1765
1824
|
return nextEnums;
|
|
1766
1825
|
}, {}),
|
|
1767
|
-
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0
|
|
1826
|
+
primaryKeyGeneration: metadata.primaryKeyGeneration ? { ...metadata.primaryKeyGeneration } : void 0,
|
|
1827
|
+
timestampColumns: metadata.timestampColumns?.map((column) => ({ ...column }))
|
|
1768
1828
|
};
|
|
1769
1829
|
return all;
|
|
1770
1830
|
}, {});
|
|
@@ -1778,8 +1838,9 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1778
1838
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
1779
1839
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
1780
1840
|
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
1841
|
+
applyTimestampColumn(tableMetadata, column);
|
|
1781
1842
|
});
|
|
1782
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
1843
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration || tableMetadata.timestampColumns?.length) nextTables[operation.table] = tableMetadata;
|
|
1783
1844
|
else delete nextTables[operation.table];
|
|
1784
1845
|
return;
|
|
1785
1846
|
}
|
|
@@ -1792,11 +1853,12 @@ const applyOperationsToPersistedColumnMappingsState = (state, operations, featur
|
|
|
1792
1853
|
applyMappedColumn(tableMetadata.columns, column, features, operation.table);
|
|
1793
1854
|
applyEnumColumn(tableMetadata.enums, column, features, operation.table);
|
|
1794
1855
|
applyPrimaryKeyGeneration(tableMetadata, column);
|
|
1856
|
+
applyTimestampColumn(tableMetadata, column);
|
|
1795
1857
|
});
|
|
1796
1858
|
operation.dropColumns.forEach((columnName) => {
|
|
1797
1859
|
removePersistedColumnMetadata(tableMetadata, columnName);
|
|
1798
1860
|
});
|
|
1799
|
-
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration) nextTables[operation.table] = tableMetadata;
|
|
1861
|
+
if (Object.keys(tableMetadata.columns).length > 0 || Object.keys(tableMetadata.enums).length > 0 || tableMetadata.primaryKeyGeneration || tableMetadata.timestampColumns?.length) nextTables[operation.table] = tableMetadata;
|
|
1800
1862
|
else delete nextTables[operation.table];
|
|
1801
1863
|
return;
|
|
1802
1864
|
}
|
|
@@ -1853,18 +1915,6 @@ const getPersistedEnumTsType = (values) => {
|
|
|
1853
1915
|
return buildEnumUnionType(values);
|
|
1854
1916
|
};
|
|
1855
1917
|
|
|
1856
|
-
//#endregion
|
|
1857
|
-
//#region src/helpers/runtime-module-loader.ts
|
|
1858
|
-
var RuntimeModuleLoader = class {
|
|
1859
|
-
static async load(filePath) {
|
|
1860
|
-
const resolvedPath = resolve(filePath);
|
|
1861
|
-
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1862
|
-
interopDefault: false,
|
|
1863
|
-
tsconfigPaths: true
|
|
1864
|
-
}).import(resolvedPath);
|
|
1865
|
-
}
|
|
1866
|
-
};
|
|
1867
|
-
|
|
1868
1918
|
//#endregion
|
|
1869
1919
|
//#region src/helpers/runtime-config.ts
|
|
1870
1920
|
const resolveDefaultStubsPath = () => {
|
|
@@ -1899,41 +1949,7 @@ const userConfig = {
|
|
|
1899
1949
|
features: { ...baseConfig.features ?? {} },
|
|
1900
1950
|
paths: { ...baseConfig.paths ?? {} }
|
|
1901
1951
|
};
|
|
1902
|
-
let runtimeConfigLoaded = false;
|
|
1903
|
-
let runtimeConfigLoadingPromise;
|
|
1904
|
-
let runtimeClientResolver;
|
|
1905
|
-
let runtimeAdapter;
|
|
1906
|
-
let runtimePaginationURLDriverFactory;
|
|
1907
|
-
let runtimePaginationCurrentPageResolver;
|
|
1908
1952
|
const transactionClientStorage = new AsyncLocalStorage();
|
|
1909
|
-
const mergePathConfig = (paths) => {
|
|
1910
|
-
const defaults = baseConfig.paths ?? {};
|
|
1911
|
-
const current = userConfig.paths ?? {};
|
|
1912
|
-
const incoming = Object.entries(paths ?? {}).reduce((all, [key, value]) => {
|
|
1913
|
-
if (typeof value === "string" && value.trim().length > 0) all[key] = path.isAbsolute(value) ? value : path.resolve(process.cwd(), value);
|
|
1914
|
-
return all;
|
|
1915
|
-
}, {});
|
|
1916
|
-
return {
|
|
1917
|
-
...defaults,
|
|
1918
|
-
...current,
|
|
1919
|
-
...incoming
|
|
1920
|
-
};
|
|
1921
|
-
};
|
|
1922
|
-
const mergeFeatureConfig = (features) => {
|
|
1923
|
-
const defaults = baseConfig.features ?? {};
|
|
1924
|
-
const current = userConfig.features ?? {};
|
|
1925
|
-
return {
|
|
1926
|
-
...defaults,
|
|
1927
|
-
...current,
|
|
1928
|
-
...features ?? {}
|
|
1929
|
-
};
|
|
1930
|
-
};
|
|
1931
|
-
const bindAdapterToModels = (adapter, models) => {
|
|
1932
|
-
models.forEach((model) => {
|
|
1933
|
-
model.setAdapter(adapter);
|
|
1934
|
-
});
|
|
1935
|
-
return adapter;
|
|
1936
|
-
};
|
|
1937
1953
|
/**
|
|
1938
1954
|
* Get the user-provided ArkORM configuration.
|
|
1939
1955
|
*
|
|
@@ -1943,120 +1959,9 @@ const getUserConfig = (key) => {
|
|
|
1943
1959
|
if (key) return userConfig[key];
|
|
1944
1960
|
return userConfig;
|
|
1945
1961
|
};
|
|
1946
|
-
/**
|
|
1947
|
-
* Configure the ArkORM runtime with the provided Prisma client resolver and
|
|
1948
|
-
* delegate mapping resolver.
|
|
1949
|
-
*
|
|
1950
|
-
* @param prisma
|
|
1951
|
-
* @param mapping
|
|
1952
|
-
*/
|
|
1953
|
-
const configureArkormRuntime = (prisma, options = {}) => {
|
|
1954
|
-
const nextConfig = {
|
|
1955
|
-
...userConfig,
|
|
1956
|
-
features: mergeFeatureConfig(options.features),
|
|
1957
|
-
paths: mergePathConfig(options.paths)
|
|
1958
|
-
};
|
|
1959
|
-
nextConfig.prisma = prisma;
|
|
1960
|
-
if (options.pagination !== void 0) nextConfig.pagination = options.pagination;
|
|
1961
|
-
if (options.adapter !== void 0) nextConfig.adapter = options.adapter;
|
|
1962
|
-
if (options.boot !== void 0) nextConfig.boot = options.boot;
|
|
1963
|
-
if (options.outputExt !== void 0) nextConfig.outputExt = options.outputExt;
|
|
1964
|
-
Object.assign(userConfig, { ...nextConfig });
|
|
1965
|
-
runtimeClientResolver = prisma;
|
|
1966
|
-
runtimeAdapter = options.adapter;
|
|
1967
|
-
runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
|
|
1968
|
-
runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
|
|
1969
|
-
options.boot?.({
|
|
1970
|
-
prisma: resolveClient(prisma),
|
|
1971
|
-
bindAdapter: bindAdapterToModels
|
|
1972
|
-
});
|
|
1973
|
-
};
|
|
1974
|
-
/**
|
|
1975
|
-
* Resolve a Prisma client instance from the provided resolver, which can be either
|
|
1976
|
-
* a direct client instance or a function that returns a client instance.
|
|
1977
|
-
*
|
|
1978
|
-
* @param resolver
|
|
1979
|
-
* @returns
|
|
1980
|
-
*/
|
|
1981
|
-
const resolveClient = (resolver) => {
|
|
1982
|
-
if (!resolver) return void 0;
|
|
1983
|
-
const client = typeof resolver === "function" ? resolver() : resolver;
|
|
1984
|
-
if (!client || typeof client !== "object") return void 0;
|
|
1985
|
-
return client;
|
|
1986
|
-
};
|
|
1987
|
-
/**
|
|
1988
|
-
* Resolve and apply the ArkORM configuration from an imported module.
|
|
1989
|
-
* This function checks for a default export and falls back to the module itself, then validates
|
|
1990
|
-
* the configuration object and applies it to the runtime if valid.
|
|
1991
|
-
*
|
|
1992
|
-
* @param imported
|
|
1993
|
-
* @returns
|
|
1994
|
-
*/
|
|
1995
|
-
const resolveAndApplyConfig = (imported) => {
|
|
1996
|
-
const config = imported?.default ?? imported;
|
|
1997
|
-
if (!config || typeof config !== "object") return;
|
|
1998
|
-
configureArkormRuntime(config.prisma, {
|
|
1999
|
-
adapter: config.adapter,
|
|
2000
|
-
boot: config.boot,
|
|
2001
|
-
features: config.features,
|
|
2002
|
-
pagination: config.pagination,
|
|
2003
|
-
paths: config.paths,
|
|
2004
|
-
outputExt: config.outputExt
|
|
2005
|
-
});
|
|
2006
|
-
runtimeConfigLoaded = true;
|
|
2007
|
-
};
|
|
2008
|
-
/**
|
|
2009
|
-
* Dynamically import a configuration file.
|
|
2010
|
-
* A cache-busting query parameter is appended to ensure the latest version is loaded.
|
|
2011
|
-
*
|
|
2012
|
-
* @param configPath
|
|
2013
|
-
* @returns A promise that resolves to the imported configuration module.
|
|
2014
|
-
*/
|
|
2015
|
-
const importConfigFile = (configPath) => {
|
|
2016
|
-
return RuntimeModuleLoader.load(configPath);
|
|
2017
|
-
};
|
|
2018
|
-
const loadRuntimeConfigSync = () => {
|
|
2019
|
-
const require = createRequire(import.meta.url);
|
|
2020
|
-
const syncConfigPaths = [path.join(process.cwd(), "arkormx.config.cjs")];
|
|
2021
|
-
for (const configPath of syncConfigPaths) {
|
|
2022
|
-
if (!existsSync$1(configPath)) continue;
|
|
2023
|
-
try {
|
|
2024
|
-
resolveAndApplyConfig(require(configPath));
|
|
2025
|
-
return true;
|
|
2026
|
-
} catch {
|
|
2027
|
-
continue;
|
|
2028
|
-
}
|
|
2029
|
-
}
|
|
2030
|
-
return false;
|
|
2031
|
-
};
|
|
2032
|
-
/**
|
|
2033
|
-
* Load the ArkORM configuration by searching for configuration files in the
|
|
2034
|
-
* current working directory.
|
|
2035
|
-
* @returns
|
|
2036
|
-
*/
|
|
2037
|
-
const loadArkormConfig = async () => {
|
|
2038
|
-
if (runtimeConfigLoaded) return;
|
|
2039
|
-
if (runtimeConfigLoadingPromise) return await runtimeConfigLoadingPromise;
|
|
2040
|
-
if (loadRuntimeConfigSync()) return;
|
|
2041
|
-
runtimeConfigLoadingPromise = (async () => {
|
|
2042
|
-
const configPaths = [path.join(process.cwd(), "arkormx.config.js"), path.join(process.cwd(), "arkormx.config.ts")];
|
|
2043
|
-
for (const configPath of configPaths) {
|
|
2044
|
-
if (!existsSync$1(configPath)) continue;
|
|
2045
|
-
try {
|
|
2046
|
-
resolveAndApplyConfig(await importConfigFile(configPath));
|
|
2047
|
-
return;
|
|
2048
|
-
} catch {
|
|
2049
|
-
continue;
|
|
2050
|
-
}
|
|
2051
|
-
}
|
|
2052
|
-
runtimeConfigLoaded = true;
|
|
2053
|
-
})();
|
|
2054
|
-
await runtimeConfigLoadingPromise;
|
|
2055
|
-
};
|
|
2056
1962
|
const getDefaultStubsPath = () => {
|
|
2057
1963
|
return resolveDefaultStubsPath();
|
|
2058
1964
|
};
|
|
2059
|
-
loadArkormConfig();
|
|
2060
1965
|
|
|
2061
1966
|
//#endregion
|
|
2062
1967
|
//#region src/cli/CliApp.ts
|