arkormx 2.0.0-next.25 → 2.0.0-next.27
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 +134 -108
- package/dist/index.cjs +6139 -5860
- package/dist/index.d.cts +250 -103
- package/dist/index.d.mts +251 -104
- package/dist/index.mjs +6144 -5871
- package/package.json +1 -1
- package/stubs/model.js.stub +1 -1
- package/stubs/model.stub +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
-
import { dirname, extname, join, resolve } from "node:path";
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { createHash, randomUUID } from "node:crypto";
|
|
6
|
-
import { spawnSync } from "node:child_process";
|
|
7
|
-
import { str } from "@h3ravel/support";
|
|
8
3
|
import { createJiti } from "@rexxars/jiti";
|
|
9
4
|
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { dirname, extname, join, resolve } from "node:path";
|
|
10
6
|
import { createRequire } from "module";
|
|
11
|
-
import { copyFileSync, existsSync
|
|
7
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "fs";
|
|
12
8
|
import { fileURLToPath } from "url";
|
|
13
9
|
import path, { dirname as dirname$1, extname as extname$1, join as join$1, relative } from "path";
|
|
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
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { str } from "@h3ravel/support";
|
|
14
14
|
import { Logger } from "@h3ravel/shared";
|
|
15
15
|
import { Command, Kernel } from "@h3ravel/musket";
|
|
16
16
|
|
|
@@ -100,6 +100,18 @@ var UnsupportedAdapterFeatureException = class extends ArkormException {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/helpers/runtime-module-loader.ts
|
|
105
|
+
var RuntimeModuleLoader = class {
|
|
106
|
+
static async load(filePath) {
|
|
107
|
+
const resolvedPath = resolve(filePath);
|
|
108
|
+
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
109
|
+
interopDefault: false,
|
|
110
|
+
tsconfigPaths: true
|
|
111
|
+
}).import(resolvedPath);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
103
115
|
//#endregion
|
|
104
116
|
//#region src/helpers/migration-history.ts
|
|
105
117
|
const createEmptyAppliedMigrationsState = () => ({
|
|
@@ -119,13 +131,13 @@ const buildMigrationIdentity = (filePath, className) => {
|
|
|
119
131
|
return `${fileName.slice(0, fileName.length - extname(fileName).length)}:${className}`;
|
|
120
132
|
};
|
|
121
133
|
const computeMigrationChecksum = (filePath) => {
|
|
122
|
-
const source = readFileSync(filePath, "utf-8");
|
|
134
|
+
const source = readFileSync$1(filePath, "utf-8");
|
|
123
135
|
return createHash("sha256").update(source).digest("hex");
|
|
124
136
|
};
|
|
125
137
|
const readAppliedMigrationsState = (stateFilePath) => {
|
|
126
|
-
if (!existsSync(stateFilePath)) return createEmptyAppliedMigrationsState();
|
|
138
|
+
if (!existsSync$1(stateFilePath)) return createEmptyAppliedMigrationsState();
|
|
127
139
|
try {
|
|
128
|
-
const parsed = JSON.parse(readFileSync(stateFilePath, "utf-8"));
|
|
140
|
+
const parsed = JSON.parse(readFileSync$1(stateFilePath, "utf-8"));
|
|
129
141
|
if (!Array.isArray(parsed.migrations)) return createEmptyAppliedMigrationsState();
|
|
130
142
|
return {
|
|
131
143
|
version: 1,
|
|
@@ -146,8 +158,8 @@ const readAppliedMigrationsStateFromStore = async (adapter, stateFilePath) => {
|
|
|
146
158
|
};
|
|
147
159
|
const writeAppliedMigrationsState = (stateFilePath, state) => {
|
|
148
160
|
const directory = dirname(stateFilePath);
|
|
149
|
-
if (!existsSync(directory)) mkdirSync(directory, { recursive: true });
|
|
150
|
-
writeFileSync(stateFilePath, JSON.stringify(state, null, 2));
|
|
161
|
+
if (!existsSync$1(directory)) mkdirSync$1(directory, { recursive: true });
|
|
162
|
+
writeFileSync$1(stateFilePath, JSON.stringify(state, null, 2));
|
|
151
163
|
};
|
|
152
164
|
const writeAppliedMigrationsStateToStore = async (adapter, stateFilePath, state) => {
|
|
153
165
|
if (supportsDatabaseMigrationState(adapter)) {
|
|
@@ -1532,9 +1544,9 @@ const generateMigrationFile = (name, options = {}) => {
|
|
|
1532
1544
|
const filePath = join(directory, fileName);
|
|
1533
1545
|
const content = buildMigrationSource(className, extension);
|
|
1534
1546
|
if (options.write ?? true) {
|
|
1535
|
-
if (!existsSync(directory)) mkdirSync(directory, { recursive: true });
|
|
1536
|
-
if (existsSync(filePath)) throw new ArkormException(`Migration file already exists: ${filePath}`);
|
|
1537
|
-
writeFileSync(filePath, content);
|
|
1547
|
+
if (!existsSync$1(directory)) mkdirSync$1(directory, { recursive: true });
|
|
1548
|
+
if (existsSync$1(filePath)) throw new ArkormException(`Migration file already exists: ${filePath}`);
|
|
1549
|
+
writeFileSync$1(filePath, content);
|
|
1538
1550
|
}
|
|
1539
1551
|
return {
|
|
1540
1552
|
fileName,
|
|
@@ -1590,11 +1602,11 @@ const applyMigrationRollbackToDatabase = async (adapter, migration) => {
|
|
|
1590
1602
|
*/
|
|
1591
1603
|
const applyMigrationToPrismaSchema = async (migration, options = {}) => {
|
|
1592
1604
|
const schemaPath = options.schemaPath ?? join(process.cwd(), "prisma", "schema.prisma");
|
|
1593
|
-
if (!existsSync(schemaPath)) throw new ArkormException(`Prisma schema file not found: ${schemaPath}`);
|
|
1594
|
-
const source = readFileSync(schemaPath, "utf-8");
|
|
1605
|
+
if (!existsSync$1(schemaPath)) throw new ArkormException(`Prisma schema file not found: ${schemaPath}`);
|
|
1606
|
+
const source = readFileSync$1(schemaPath, "utf-8");
|
|
1595
1607
|
const operations = await getMigrationPlan(migration, "up");
|
|
1596
1608
|
const schema = applyOperationsToPrismaSchema(source, operations);
|
|
1597
|
-
if (options.write ?? true) writeFileSync(schemaPath, schema);
|
|
1609
|
+
if (options.write ?? true) writeFileSync$1(schemaPath, schema);
|
|
1598
1610
|
return {
|
|
1599
1611
|
schema,
|
|
1600
1612
|
schemaPath,
|
|
@@ -1610,11 +1622,11 @@ const applyMigrationToPrismaSchema = async (migration, options = {}) => {
|
|
|
1610
1622
|
*/
|
|
1611
1623
|
const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) => {
|
|
1612
1624
|
const schemaPath = options.schemaPath ?? join(process.cwd(), "prisma", "schema.prisma");
|
|
1613
|
-
if (!existsSync(schemaPath)) throw new ArkormException(`Prisma schema file not found: ${schemaPath}`);
|
|
1614
|
-
const source = readFileSync(schemaPath, "utf-8");
|
|
1625
|
+
if (!existsSync$1(schemaPath)) throw new ArkormException(`Prisma schema file not found: ${schemaPath}`);
|
|
1626
|
+
const source = readFileSync$1(schemaPath, "utf-8");
|
|
1615
1627
|
const operations = await getMigrationPlan(migration, "down");
|
|
1616
1628
|
const schema = applyOperationsToPrismaSchema(source, operations);
|
|
1617
|
-
if (options.write ?? true) writeFileSync(schemaPath, schema);
|
|
1629
|
+
if (options.write ?? true) writeFileSync$1(schemaPath, schema);
|
|
1618
1630
|
return {
|
|
1619
1631
|
schema,
|
|
1620
1632
|
schemaPath,
|
|
@@ -1737,14 +1749,14 @@ const resetPersistedColumnMappingsCache = () => {
|
|
|
1737
1749
|
};
|
|
1738
1750
|
const readPersistedColumnMappingsState = (filePath) => {
|
|
1739
1751
|
if (cachedColumnMappingsPath === filePath && cachedColumnMappingsState) return cachedColumnMappingsState;
|
|
1740
|
-
if (!existsSync(filePath)) {
|
|
1752
|
+
if (!existsSync$1(filePath)) {
|
|
1741
1753
|
const empty = createEmptyPersistedColumnMappingsState();
|
|
1742
1754
|
cachedColumnMappingsPath = filePath;
|
|
1743
1755
|
cachedColumnMappingsState = empty;
|
|
1744
1756
|
return empty;
|
|
1745
1757
|
}
|
|
1746
1758
|
try {
|
|
1747
|
-
const normalized = normalizePersistedColumnMappingsState(JSON.parse(readFileSync(filePath, "utf-8")));
|
|
1759
|
+
const normalized = normalizePersistedColumnMappingsState(JSON.parse(readFileSync$1(filePath, "utf-8")));
|
|
1748
1760
|
cachedColumnMappingsPath = filePath;
|
|
1749
1761
|
cachedColumnMappingsState = normalized;
|
|
1750
1762
|
return normalized;
|
|
@@ -1758,13 +1770,13 @@ const readPersistedColumnMappingsState = (filePath) => {
|
|
|
1758
1770
|
const writePersistedColumnMappingsState = (filePath, state) => {
|
|
1759
1771
|
const normalized = normalizePersistedColumnMappingsState(state);
|
|
1760
1772
|
const directory = dirname(filePath);
|
|
1761
|
-
if (!existsSync(directory)) mkdirSync(directory, { recursive: true });
|
|
1762
|
-
writeFileSync(filePath, JSON.stringify(normalized, null, 2));
|
|
1773
|
+
if (!existsSync$1(directory)) mkdirSync$1(directory, { recursive: true });
|
|
1774
|
+
writeFileSync$1(filePath, JSON.stringify(normalized, null, 2));
|
|
1763
1775
|
cachedColumnMappingsPath = filePath;
|
|
1764
1776
|
cachedColumnMappingsState = normalized;
|
|
1765
1777
|
};
|
|
1766
1778
|
const deletePersistedColumnMappingsState = (filePath) => {
|
|
1767
|
-
if (existsSync(filePath)) rmSync(filePath, { force: true });
|
|
1779
|
+
if (existsSync$1(filePath)) rmSync$1(filePath, { force: true });
|
|
1768
1780
|
resetPersistedColumnMappingsCache();
|
|
1769
1781
|
};
|
|
1770
1782
|
const getPersistedTableMetadata = (table, options = {}) => {
|
|
@@ -1937,18 +1949,6 @@ const getPersistedEnumTsType = (values) => {
|
|
|
1937
1949
|
return buildEnumUnionType(values);
|
|
1938
1950
|
};
|
|
1939
1951
|
|
|
1940
|
-
//#endregion
|
|
1941
|
-
//#region src/helpers/runtime-module-loader.ts
|
|
1942
|
-
var RuntimeModuleLoader = class {
|
|
1943
|
-
static async load(filePath) {
|
|
1944
|
-
const resolvedPath = resolve(filePath);
|
|
1945
|
-
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
1946
|
-
interopDefault: false,
|
|
1947
|
-
tsconfigPaths: true
|
|
1948
|
-
}).import(resolvedPath);
|
|
1949
|
-
}
|
|
1950
|
-
};
|
|
1951
|
-
|
|
1952
1952
|
//#endregion
|
|
1953
1953
|
//#region src/helpers/runtime-config.ts
|
|
1954
1954
|
const resolveDefaultStubsPath = () => {
|
|
@@ -1956,7 +1956,7 @@ const resolveDefaultStubsPath = () => {
|
|
|
1956
1956
|
while (true) {
|
|
1957
1957
|
const packageJsonPath = path.join(current, "package.json");
|
|
1958
1958
|
const stubsPath = path.join(current, "stubs");
|
|
1959
|
-
if (existsSync
|
|
1959
|
+
if (existsSync(packageJsonPath) && existsSync(stubsPath)) return stubsPath;
|
|
1960
1960
|
const parent = path.dirname(current);
|
|
1961
1961
|
if (parent === current) break;
|
|
1962
1962
|
current = parent;
|
|
@@ -1991,6 +1991,7 @@ let runtimePaginationURLDriverFactory;
|
|
|
1991
1991
|
let runtimePaginationCurrentPageResolver;
|
|
1992
1992
|
let runtimeDebugHandler;
|
|
1993
1993
|
const transactionClientStorage = new AsyncLocalStorage();
|
|
1994
|
+
const transactionAdapterStorage = new AsyncLocalStorage();
|
|
1994
1995
|
const defaultDebugHandler = (event) => {
|
|
1995
1996
|
const prefix = `[arkorm:${event.adapter}] ${event.operation}${event.target ? ` [${event.target}]` : ""}`;
|
|
1996
1997
|
const payload = {
|
|
@@ -2023,6 +2024,12 @@ const mergePathConfig = (paths) => {
|
|
|
2023
2024
|
...incoming
|
|
2024
2025
|
};
|
|
2025
2026
|
};
|
|
2027
|
+
/**
|
|
2028
|
+
* Merge the feature configuration from the base defaults, user configuration, and provided options.
|
|
2029
|
+
*
|
|
2030
|
+
* @param features
|
|
2031
|
+
* @returns
|
|
2032
|
+
*/
|
|
2026
2033
|
const mergeFeatureConfig = (features) => {
|
|
2027
2034
|
const defaults = baseConfig.features ?? {};
|
|
2028
2035
|
const current = userConfig.features ?? {};
|
|
@@ -2032,6 +2039,13 @@ const mergeFeatureConfig = (features) => {
|
|
|
2032
2039
|
...features ?? {}
|
|
2033
2040
|
};
|
|
2034
2041
|
};
|
|
2042
|
+
/**
|
|
2043
|
+
* Bind a database adapter instance to an array of models that support adapter binding.
|
|
2044
|
+
*
|
|
2045
|
+
* @param adapter
|
|
2046
|
+
* @param models
|
|
2047
|
+
* @returns
|
|
2048
|
+
*/
|
|
2035
2049
|
const bindAdapterToModels = (adapter, models) => {
|
|
2036
2050
|
models.forEach((model) => {
|
|
2037
2051
|
model.setAdapter(adapter);
|
|
@@ -2041,6 +2055,7 @@ const bindAdapterToModels = (adapter, models) => {
|
|
|
2041
2055
|
/**
|
|
2042
2056
|
* Get the user-provided ArkORM configuration.
|
|
2043
2057
|
*
|
|
2058
|
+
* @param key Optional specific configuration key to retrieve. If omitted, the entire configuration object is returned.
|
|
2044
2059
|
* @returns The user-provided ArkORM configuration object.
|
|
2045
2060
|
*/
|
|
2046
2061
|
const getUserConfig = (key) => {
|
|
@@ -2048,37 +2063,41 @@ const getUserConfig = (key) => {
|
|
|
2048
2063
|
return userConfig;
|
|
2049
2064
|
};
|
|
2050
2065
|
/**
|
|
2051
|
-
* Configure the ArkORM runtime with the provided
|
|
2052
|
-
*
|
|
2066
|
+
* Configure the ArkORM runtime with the provided runtime client resolver and
|
|
2067
|
+
* adapter-first options.
|
|
2053
2068
|
*
|
|
2054
|
-
* @param
|
|
2055
|
-
* @param
|
|
2069
|
+
* @param client
|
|
2070
|
+
* @param options
|
|
2056
2071
|
*/
|
|
2057
|
-
const configureArkormRuntime = (
|
|
2072
|
+
const configureArkormRuntime = (client, options = {}) => {
|
|
2073
|
+
const resolvedClient = client ?? options.client;
|
|
2058
2074
|
const nextConfig = {
|
|
2059
2075
|
...userConfig,
|
|
2060
2076
|
features: mergeFeatureConfig(options.features),
|
|
2061
2077
|
paths: mergePathConfig(options.paths)
|
|
2062
2078
|
};
|
|
2063
|
-
nextConfig.
|
|
2079
|
+
nextConfig.client = resolvedClient;
|
|
2080
|
+
nextConfig.prisma = resolvedClient;
|
|
2064
2081
|
if (options.pagination !== void 0) nextConfig.pagination = options.pagination;
|
|
2065
2082
|
if (options.adapter !== void 0) nextConfig.adapter = options.adapter;
|
|
2066
2083
|
if (options.boot !== void 0) nextConfig.boot = options.boot;
|
|
2067
2084
|
if (options.debug !== void 0) nextConfig.debug = options.debug;
|
|
2068
2085
|
if (options.outputExt !== void 0) nextConfig.outputExt = options.outputExt;
|
|
2069
2086
|
Object.assign(userConfig, { ...nextConfig });
|
|
2070
|
-
runtimeClientResolver =
|
|
2087
|
+
runtimeClientResolver = resolvedClient;
|
|
2071
2088
|
runtimeAdapter = options.adapter;
|
|
2072
2089
|
runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
|
|
2073
2090
|
runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
|
|
2074
2091
|
runtimeDebugHandler = resolveDebugHandler(nextConfig.debug);
|
|
2092
|
+
const bootClient = resolveClient(resolvedClient);
|
|
2075
2093
|
options.boot?.({
|
|
2076
|
-
|
|
2094
|
+
client: bootClient,
|
|
2095
|
+
prisma: bootClient,
|
|
2077
2096
|
bindAdapter: bindAdapterToModels
|
|
2078
2097
|
});
|
|
2079
2098
|
};
|
|
2080
2099
|
/**
|
|
2081
|
-
* Resolve a
|
|
2100
|
+
* Resolve a runtime client instance from the provided resolver, which can be either
|
|
2082
2101
|
* a direct client instance or a function that returns a client instance.
|
|
2083
2102
|
*
|
|
2084
2103
|
* @param resolver
|
|
@@ -2101,7 +2120,9 @@ const resolveClient = (resolver) => {
|
|
|
2101
2120
|
const resolveAndApplyConfig = (imported) => {
|
|
2102
2121
|
const config = imported?.default ?? imported;
|
|
2103
2122
|
if (!config || typeof config !== "object") return;
|
|
2104
|
-
|
|
2123
|
+
const runtimeClient = config.client ?? config.prisma;
|
|
2124
|
+
configureArkormRuntime(runtimeClient, {
|
|
2125
|
+
client: runtimeClient,
|
|
2105
2126
|
adapter: config.adapter,
|
|
2106
2127
|
boot: config.boot,
|
|
2107
2128
|
debug: config.debug,
|
|
@@ -2126,7 +2147,7 @@ const loadRuntimeConfigSync = () => {
|
|
|
2126
2147
|
const require = createRequire(import.meta.url);
|
|
2127
2148
|
const syncConfigPaths = [path.join(process.cwd(), "arkormx.config.cjs")];
|
|
2128
2149
|
for (const configPath of syncConfigPaths) {
|
|
2129
|
-
if (!existsSync
|
|
2150
|
+
if (!existsSync(configPath)) continue;
|
|
2130
2151
|
try {
|
|
2131
2152
|
resolveAndApplyConfig(require(configPath));
|
|
2132
2153
|
return true;
|
|
@@ -2148,7 +2169,7 @@ const loadArkormConfig = async () => {
|
|
|
2148
2169
|
runtimeConfigLoadingPromise = (async () => {
|
|
2149
2170
|
const configPaths = [path.join(process.cwd(), "arkormx.config.js"), path.join(process.cwd(), "arkormx.config.ts")];
|
|
2150
2171
|
for (const configPath of configPaths) {
|
|
2151
|
-
if (!existsSync
|
|
2172
|
+
if (!existsSync(configPath)) continue;
|
|
2152
2173
|
try {
|
|
2153
2174
|
resolveAndApplyConfig(await importConfigFile(configPath));
|
|
2154
2175
|
return;
|
|
@@ -2171,13 +2192,13 @@ const emitRuntimeDebugEvent = (event) => {
|
|
|
2171
2192
|
getRuntimeDebugHandler()?.(event);
|
|
2172
2193
|
};
|
|
2173
2194
|
/**
|
|
2174
|
-
* Check if a given value
|
|
2195
|
+
* Check if a given value matches Arkorm's query-schema contract
|
|
2175
2196
|
* by verifying the presence of common delegate methods.
|
|
2176
2197
|
*
|
|
2177
2198
|
* @param value The value to check.
|
|
2178
|
-
* @returns True if the value
|
|
2199
|
+
* @returns True if the value matches the query-schema contract, false otherwise.
|
|
2179
2200
|
*/
|
|
2180
|
-
const
|
|
2201
|
+
const isQuerySchemaLike = (value) => {
|
|
2181
2202
|
if (!value || typeof value !== "object") return false;
|
|
2182
2203
|
const candidate = value;
|
|
2183
2204
|
return [
|
|
@@ -2189,6 +2210,10 @@ const isDelegateLike = (value) => {
|
|
|
2189
2210
|
"count"
|
|
2190
2211
|
].every((method) => typeof candidate[method] === "function");
|
|
2191
2212
|
};
|
|
2213
|
+
/**
|
|
2214
|
+
* @deprecated Use isQuerySchemaLike instead.
|
|
2215
|
+
*/
|
|
2216
|
+
const isDelegateLike = isQuerySchemaLike;
|
|
2192
2217
|
loadArkormConfig();
|
|
2193
2218
|
|
|
2194
2219
|
//#endregion
|
|
@@ -2308,7 +2333,7 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2308
2333
|
if (!nested) return void 0;
|
|
2309
2334
|
return { NOT: nested };
|
|
2310
2335
|
}
|
|
2311
|
-
throw new UnsupportedAdapterFeatureException("Raw where clauses are not supported by the Prisma compatibility adapter.", {
|
|
2336
|
+
throw new UnsupportedAdapterFeatureException("Raw where clauses are not supported by the Prisma compatibility adapter; use a SQL-backed adapter for raw SQL predicates.", {
|
|
2312
2337
|
operation: "adapter.where",
|
|
2313
2338
|
meta: {
|
|
2314
2339
|
feature: "rawWhere",
|
|
@@ -2442,9 +2467,10 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2442
2467
|
});
|
|
2443
2468
|
}
|
|
2444
2469
|
/**
|
|
2445
|
-
*
|
|
2446
|
-
*
|
|
2447
|
-
*
|
|
2470
|
+
* Prisma can translate relation load plans on direct select/selectOne calls into
|
|
2471
|
+
* Prisma include/select arguments, but the adapter does not advertise the
|
|
2472
|
+
* adapter-owned batch relation load seam. QueryBuilder eager loads therefore stay
|
|
2473
|
+
* on Arkorm's generic relation loader on the Prisma compatibility path.
|
|
2448
2474
|
*
|
|
2449
2475
|
* @param spec
|
|
2450
2476
|
* @returns
|
|
@@ -2626,7 +2652,7 @@ var PrismaDatabaseAdapter = class PrismaDatabaseAdapter {
|
|
|
2626
2652
|
* @param _spec
|
|
2627
2653
|
*/
|
|
2628
2654
|
async loadRelations(_spec) {
|
|
2629
|
-
throw new UnsupportedAdapterFeatureException("
|
|
2655
|
+
throw new UnsupportedAdapterFeatureException("Adapter-owned relation batch loading is intentionally unavailable on the Prisma compatibility adapter; eager loading stays on Arkorm's generic loader for this path.", {
|
|
2630
2656
|
operation: "adapter.loadRelations",
|
|
2631
2657
|
meta: { feature: "relationLoads" }
|
|
2632
2658
|
});
|
|
@@ -2685,7 +2711,7 @@ var CliApp = class {
|
|
|
2685
2711
|
*/
|
|
2686
2712
|
ensureDirectory(filePath) {
|
|
2687
2713
|
const dir = dirname$1(filePath);
|
|
2688
|
-
if (!existsSync
|
|
2714
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
2689
2715
|
}
|
|
2690
2716
|
/**
|
|
2691
2717
|
* Convert absolute paths under current working directory into relative display paths.
|
|
@@ -2734,13 +2760,13 @@ var CliApp = class {
|
|
|
2734
2760
|
* @returns
|
|
2735
2761
|
*/
|
|
2736
2762
|
resolveRuntimeDirectoryPath(directoryPath) {
|
|
2737
|
-
if (existsSync
|
|
2763
|
+
if (existsSync(directoryPath)) return directoryPath;
|
|
2738
2764
|
const { buildOutput } = this.getConfig("paths") || {};
|
|
2739
2765
|
if (typeof buildOutput !== "string" || buildOutput.trim().length === 0) return directoryPath;
|
|
2740
2766
|
const relativeSource = relative(process.cwd(), directoryPath);
|
|
2741
2767
|
if (!relativeSource || relativeSource.startsWith("..")) return directoryPath;
|
|
2742
2768
|
const mappedDirectory = join$1(buildOutput, relativeSource);
|
|
2743
|
-
return existsSync
|
|
2769
|
+
return existsSync(mappedDirectory) ? mappedDirectory : directoryPath;
|
|
2744
2770
|
}
|
|
2745
2771
|
/**
|
|
2746
2772
|
* Resolve a script file path for runtime execution.
|
|
@@ -2770,7 +2796,7 @@ var CliApp = class {
|
|
|
2770
2796
|
} else candidates.push(mappedFile);
|
|
2771
2797
|
}
|
|
2772
2798
|
}
|
|
2773
|
-
const runtimeMatch = candidates.find((path) => existsSync
|
|
2799
|
+
const runtimeMatch = candidates.find((path) => existsSync(path));
|
|
2774
2800
|
if (runtimeMatch) return runtimeMatch;
|
|
2775
2801
|
return filePath;
|
|
2776
2802
|
}
|
|
@@ -2782,14 +2808,14 @@ var CliApp = class {
|
|
|
2782
2808
|
* @param replacements
|
|
2783
2809
|
*/
|
|
2784
2810
|
generateFile(stubPath, outputPath, replacements, options) {
|
|
2785
|
-
if (existsSync
|
|
2811
|
+
if (existsSync(outputPath) && !options?.force) {
|
|
2786
2812
|
this.command.error(`Error: ${this.formatPathForLog(outputPath)} already exists.`);
|
|
2787
2813
|
process.exit(1);
|
|
2788
|
-
} else if (existsSync
|
|
2789
|
-
let content = readFileSync
|
|
2814
|
+
} else if (existsSync(outputPath) && options?.force) rmSync(outputPath);
|
|
2815
|
+
let content = readFileSync(stubPath, "utf-8");
|
|
2790
2816
|
for (const [key, value] of Object.entries(replacements)) content = content.replace(new RegExp(`{{${key}}}`, "g"), value);
|
|
2791
2817
|
this.ensureDirectory(outputPath);
|
|
2792
|
-
writeFileSync
|
|
2818
|
+
writeFileSync(outputPath, content);
|
|
2793
2819
|
return outputPath;
|
|
2794
2820
|
}
|
|
2795
2821
|
/**
|
|
@@ -2881,7 +2907,7 @@ var CliApp = class {
|
|
|
2881
2907
|
makeModel(name, options = {}) {
|
|
2882
2908
|
const baseName = str(name.replace(/Model$/, "")).pascal().toString();
|
|
2883
2909
|
const modelName = `${baseName}`;
|
|
2884
|
-
const
|
|
2910
|
+
const tableName = str(baseName).camel().plural().toString();
|
|
2885
2911
|
const outputExt = this.resolveOutputExt();
|
|
2886
2912
|
const outputPath = join$1(this.resolveConfigPath("models", join$1(process.cwd(), "src", "models")), `${modelName}.${outputExt}`);
|
|
2887
2913
|
const shouldBuildFactory = options.all || options.factory;
|
|
@@ -2895,11 +2921,11 @@ var CliApp = class {
|
|
|
2895
2921
|
else stubPath = this.resolveStubPath(outputExt === "js" ? "model.js.stub" : "model.stub");
|
|
2896
2922
|
const modelPath = this.generateFile(stubPath, outputPath, {
|
|
2897
2923
|
ModelName: modelName,
|
|
2898
|
-
|
|
2924
|
+
TableName: tableName,
|
|
2899
2925
|
FactoryImport: shouldBuildFactory ? `import { ${factoryName} } from '${factoryImportPath}'\n` : "",
|
|
2900
2926
|
FactoryLink: shouldBuildFactory ? outputExt === "js" ? `\n static factoryClass = ${factoryName}` : `\n protected static override factoryClass = ${factoryName}` : ""
|
|
2901
2927
|
}, options);
|
|
2902
|
-
const prisma = this.isUsingPrismaAdapter() ? this.ensurePrismaModelEntry(modelName,
|
|
2928
|
+
const prisma = this.isUsingPrismaAdapter() ? this.ensurePrismaModelEntry(modelName, tableName) : void 0;
|
|
2903
2929
|
const created = {
|
|
2904
2930
|
model: {
|
|
2905
2931
|
name: modelName,
|
|
@@ -2916,30 +2942,30 @@ var CliApp = class {
|
|
|
2916
2942
|
modelImportPath: `./${relative(dirname$1(factoryPath), outputPath).replace(/\\/g, "/").replace(/\.(ts|tsx|mts|cts|js|mjs|cjs)$/i, "")}${outputExt === "js" ? ".js" : ""}`
|
|
2917
2943
|
});
|
|
2918
2944
|
if (shouldBuildSeeder) created.seeder = this.makeSeeder(baseName, { force: options.force });
|
|
2919
|
-
if (shouldBuildMigration) created.migration = this.makeMigration(`create ${
|
|
2945
|
+
if (shouldBuildMigration) created.migration = this.makeMigration(`create ${tableName} table`);
|
|
2920
2946
|
return created;
|
|
2921
2947
|
}
|
|
2922
2948
|
/**
|
|
2923
2949
|
* Ensure that the Prisma schema has a model entry for the given model
|
|
2924
|
-
* and
|
|
2950
|
+
* and table names.
|
|
2925
2951
|
* If the entry does not exist, it will be created with a default `id` field.
|
|
2926
2952
|
*
|
|
2927
2953
|
* @param modelName The name of the model to ensure in the Prisma schema.
|
|
2928
|
-
* @param
|
|
2954
|
+
* @param tableName The table name to ensure in the Prisma schema.
|
|
2929
2955
|
*/
|
|
2930
|
-
ensurePrismaModelEntry(modelName,
|
|
2956
|
+
ensurePrismaModelEntry(modelName, tableName) {
|
|
2931
2957
|
const schemaPath = join$1(process.cwd(), "prisma", "schema.prisma");
|
|
2932
|
-
if (!existsSync
|
|
2933
|
-
const source = readFileSync
|
|
2934
|
-
const existingByTable = findModelBlock(source,
|
|
2958
|
+
if (!existsSync(schemaPath)) return void 0;
|
|
2959
|
+
const source = readFileSync(schemaPath, "utf-8");
|
|
2960
|
+
const existingByTable = findModelBlock(source, tableName);
|
|
2935
2961
|
const existingByName = new RegExp(`model\\s+${modelName}\\s*\\{`, "m").test(source);
|
|
2936
2962
|
if (existingByTable || existingByName) return {
|
|
2937
2963
|
path: schemaPath,
|
|
2938
2964
|
updated: false
|
|
2939
2965
|
};
|
|
2940
|
-
writeFileSync
|
|
2966
|
+
writeFileSync(schemaPath, applyCreateTableOperation(source, {
|
|
2941
2967
|
type: "createTable",
|
|
2942
|
-
table:
|
|
2968
|
+
table: tableName,
|
|
2943
2969
|
columns: [{
|
|
2944
2970
|
name: "id",
|
|
2945
2971
|
type: "id",
|
|
@@ -3159,17 +3185,17 @@ var CliApp = class {
|
|
|
3159
3185
|
if (!classMatch) return null;
|
|
3160
3186
|
const className = classMatch[1];
|
|
3161
3187
|
const tableMatch = modelSource.match(/protected\s+static\s+override\s+table\s*=\s*['"]([^'"]+)['"]/) ?? modelSource.match(/static\s+table\s*=\s*['"]([^'"]+)['"]/);
|
|
3162
|
-
const
|
|
3188
|
+
const compatibilityDelegateMatch = modelSource.match(/protected\s+static\s+override\s+delegate\s*=\s*['"]([^'"]+)['"]/) ?? modelSource.match(/static\s+delegate\s*=\s*['"]([^'"]+)['"]/);
|
|
3163
3189
|
return {
|
|
3164
3190
|
className,
|
|
3165
|
-
table: tableMatch?.[1] ??
|
|
3191
|
+
table: tableMatch?.[1] ?? compatibilityDelegateMatch?.[1] ?? str(className).camel().plural().toString()
|
|
3166
3192
|
};
|
|
3167
3193
|
}
|
|
3168
3194
|
syncModelFiles(modelFiles, resolveStructure, enums) {
|
|
3169
3195
|
const updated = [];
|
|
3170
3196
|
const skipped = [];
|
|
3171
3197
|
modelFiles.forEach((filePath) => {
|
|
3172
|
-
const source = readFileSync
|
|
3198
|
+
const source = readFileSync(filePath, "utf-8");
|
|
3173
3199
|
const structure = resolveStructure(filePath, source);
|
|
3174
3200
|
if (!structure || structure.fields.length === 0) {
|
|
3175
3201
|
skipped.push(filePath);
|
|
@@ -3180,7 +3206,7 @@ var CliApp = class {
|
|
|
3180
3206
|
skipped.push(filePath);
|
|
3181
3207
|
return;
|
|
3182
3208
|
}
|
|
3183
|
-
writeFileSync
|
|
3209
|
+
writeFileSync(filePath, synced.content);
|
|
3184
3210
|
updated.push(filePath);
|
|
3185
3211
|
});
|
|
3186
3212
|
return {
|
|
@@ -3365,12 +3391,12 @@ var CliApp = class {
|
|
|
3365
3391
|
}
|
|
3366
3392
|
async syncModels(options = {}) {
|
|
3367
3393
|
const modelsDir = options.modelsDir ?? this.resolveConfigPath("models", join$1(process.cwd(), "src", "models"));
|
|
3368
|
-
if (!existsSync
|
|
3369
|
-
const modelFiles = readdirSync
|
|
3394
|
+
if (!existsSync(modelsDir)) throw new Error(`Models directory not found: ${modelsDir}`);
|
|
3395
|
+
const modelFiles = readdirSync(modelsDir).filter((file) => file.endsWith(".ts")).map((file) => join$1(modelsDir, file));
|
|
3370
3396
|
const adapter = this.getConfig("adapter");
|
|
3371
3397
|
if (adapter && typeof adapter.introspectModels === "function") {
|
|
3372
3398
|
const sources = modelFiles.reduce((all, filePath) => {
|
|
3373
|
-
const parsed = this.parseModelSyncSource(readFileSync
|
|
3399
|
+
const parsed = this.parseModelSyncSource(readFileSync(filePath, "utf-8"));
|
|
3374
3400
|
if (parsed) all.set(filePath, parsed);
|
|
3375
3401
|
return all;
|
|
3376
3402
|
}, /* @__PURE__ */ new Map());
|
|
@@ -3410,12 +3436,12 @@ var CliApp = class {
|
|
|
3410
3436
|
syncModelsFromPrisma(options = {}) {
|
|
3411
3437
|
const schemaPath = options.schemaPath ?? join$1(process.cwd(), "prisma", "schema.prisma");
|
|
3412
3438
|
const modelsDir = options.modelsDir ?? this.resolveConfigPath("models", join$1(process.cwd(), "src", "models"));
|
|
3413
|
-
if (!existsSync
|
|
3414
|
-
if (!existsSync
|
|
3415
|
-
const schema = readFileSync
|
|
3439
|
+
if (!existsSync(schemaPath)) throw new Error(`Prisma schema file not found: ${schemaPath}`);
|
|
3440
|
+
if (!existsSync(modelsDir)) throw new Error(`Models directory not found: ${modelsDir}`);
|
|
3441
|
+
const schema = readFileSync(schemaPath, "utf-8");
|
|
3416
3442
|
const prismaEnums = this.parsePrismaEnums(schema);
|
|
3417
3443
|
const prismaModels = this.parsePrismaModels(schema);
|
|
3418
|
-
const modelFiles = readdirSync
|
|
3444
|
+
const modelFiles = readdirSync(modelsDir).filter((file) => file.endsWith(".ts")).map((file) => join$1(modelsDir, file));
|
|
3419
3445
|
const result = this.syncModelFiles(modelFiles, (filePath, source) => {
|
|
3420
3446
|
const parsed = this.parseModelSyncSource(source);
|
|
3421
3447
|
if (!parsed) return void 0;
|
|
@@ -3455,18 +3481,18 @@ var InitCommand = class extends Command {
|
|
|
3455
3481
|
const stubsDir = typeof stubs === "string" && stubs.trim().length > 0 ? stubs : getDefaultStubsPath();
|
|
3456
3482
|
const preferredStubPath = join(stubsDir, "arkormx.config.stub");
|
|
3457
3483
|
const legacyStubPath = join(stubsDir, "arkorm.config.stub");
|
|
3458
|
-
const stubPath = existsSync
|
|
3459
|
-
if (existsSync
|
|
3484
|
+
const stubPath = existsSync(preferredStubPath) ? preferredStubPath : legacyStubPath;
|
|
3485
|
+
if (existsSync(outputDir) && !this.option("force")) {
|
|
3460
3486
|
this.error("Error: Arkormˣ has already been initialized. Use --force to reinitialize.");
|
|
3461
3487
|
process.exit(1);
|
|
3462
3488
|
}
|
|
3463
3489
|
this.app.ensureDirectory(outputDir);
|
|
3464
|
-
if (existsSync
|
|
3465
|
-
if (!existsSync
|
|
3490
|
+
if (existsSync(outputDir) && this.option("force")) copyFileSync(outputDir, outputDir.replace(/\.js$/, `.backup.${Date.now()}.js`));
|
|
3491
|
+
if (!existsSync(stubPath)) {
|
|
3466
3492
|
this.error(`Error: Missing config stub at ${preferredStubPath} (or ${legacyStubPath})`);
|
|
3467
3493
|
process.exit(1);
|
|
3468
3494
|
}
|
|
3469
|
-
writeFileSync
|
|
3495
|
+
writeFileSync(outputDir, readFileSync(stubPath, "utf-8"));
|
|
3470
3496
|
this.success("Arkormˣ initialized successfully!");
|
|
3471
3497
|
}
|
|
3472
3498
|
};
|
|
@@ -3641,7 +3667,7 @@ var MigrateCommand = class extends Command {
|
|
|
3641
3667
|
this.app.command = this;
|
|
3642
3668
|
const configuredMigrationsDir = this.app.getConfig("paths")?.migrations ?? join(process.cwd(), "database", "migrations");
|
|
3643
3669
|
const migrationsDir = this.app.resolveRuntimeDirectoryPath(configuredMigrationsDir);
|
|
3644
|
-
if (!existsSync(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3670
|
+
if (!existsSync$1(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3645
3671
|
const schemaPath = this.option("schema") ? resolve(String(this.option("schema"))) : join(process.cwd(), "prisma", "schema.prisma");
|
|
3646
3672
|
const classes = this.option("all") || !this.argument("name") ? await this.loadAllMigrations(migrationsDir) : (await this.loadNamedMigration(migrationsDir, this.argument("name"))).filter(([cls]) => cls !== void 0);
|
|
3647
3673
|
if (classes.length === 0) return void this.error("Error: No migration classes found to run.");
|
|
@@ -3736,7 +3762,7 @@ var MigrateCommand = class extends Command {
|
|
|
3736
3762
|
* @param migrationsDir The directory to load migration classes from.
|
|
3737
3763
|
*/
|
|
3738
3764
|
async loadAllMigrations(migrationsDir) {
|
|
3739
|
-
const files = readdirSync(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3765
|
+
const files = readdirSync$1(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3740
3766
|
return (await Promise.all(files.map(async (file) => (await this.loadMigrationClassesFromFile(file)).map((cls) => [cls, file])))).flat();
|
|
3741
3767
|
}
|
|
3742
3768
|
/**
|
|
@@ -3758,7 +3784,7 @@ var MigrateCommand = class extends Command {
|
|
|
3758
3784
|
`${base}Migration.js`,
|
|
3759
3785
|
`${base}Migration.mjs`,
|
|
3760
3786
|
`${base}Migration.cjs`
|
|
3761
|
-
].map((file) => join(migrationsDir, file)).find((file) => existsSync(file));
|
|
3787
|
+
].map((file) => join(migrationsDir, file)).find((file) => existsSync$1(file));
|
|
3762
3788
|
if (!target) return [[void 0, name]];
|
|
3763
3789
|
const runtimeTarget = this.app.resolveRuntimeScriptPath(target);
|
|
3764
3790
|
return (await this.loadMigrationClassesFromFile(runtimeTarget)).map((cls) => [cls, runtimeTarget]);
|
|
@@ -3794,7 +3820,7 @@ var MigrateFreshCommand = class extends Command {
|
|
|
3794
3820
|
this.app.command = this;
|
|
3795
3821
|
const configuredMigrationsDir = this.app.getConfig("paths")?.migrations ?? join(process.cwd(), "database", "migrations");
|
|
3796
3822
|
const migrationsDir = this.app.resolveRuntimeDirectoryPath(configuredMigrationsDir);
|
|
3797
|
-
if (!existsSync(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3823
|
+
if (!existsSync$1(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3798
3824
|
const adapter = this.app.getConfig("adapter");
|
|
3799
3825
|
const useDatabaseMigrations = supportsDatabaseMigrationExecution(adapter);
|
|
3800
3826
|
const persistedFeatures = resolvePersistedMetadataFeatures(this.app.getConfig("features"));
|
|
@@ -3815,8 +3841,8 @@ var MigrateFreshCommand = class extends Command {
|
|
|
3815
3841
|
}
|
|
3816
3842
|
await adapter.resetDatabase();
|
|
3817
3843
|
} else {
|
|
3818
|
-
if (!existsSync(schemaPath)) return void this.error(`Error: Prisma schema file not found: ${this.app.formatPathForLog(schemaPath)}`);
|
|
3819
|
-
writeFileSync(schemaPath, stripPrismaSchemaModelsAndEnums(readFileSync(schemaPath, "utf-8")));
|
|
3844
|
+
if (!existsSync$1(schemaPath)) return void this.error(`Error: Prisma schema file not found: ${this.app.formatPathForLog(schemaPath)}`);
|
|
3845
|
+
writeFileSync$1(schemaPath, stripPrismaSchemaModelsAndEnums(readFileSync$1(schemaPath, "utf-8")));
|
|
3820
3846
|
}
|
|
3821
3847
|
let appliedState = createEmptyAppliedMigrationsState();
|
|
3822
3848
|
await writeAppliedMigrationsStateToStore(adapter, stateFilePath, appliedState);
|
|
@@ -3863,7 +3889,7 @@ var MigrateFreshCommand = class extends Command {
|
|
|
3863
3889
|
migrations.forEach(([_, file]) => this.success(this.app.splitLogger("Migrated", file)));
|
|
3864
3890
|
}
|
|
3865
3891
|
async loadAllMigrations(migrationsDir) {
|
|
3866
|
-
const files = readdirSync(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3892
|
+
const files = readdirSync$1(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3867
3893
|
return (await Promise.all(files.map(async (file) => (await this.loadMigrationClassesFromFile(file)).map((cls) => [cls, file])))).flat();
|
|
3868
3894
|
}
|
|
3869
3895
|
async loadMigrationClassesFromFile(filePath) {
|
|
@@ -3902,7 +3928,7 @@ var MigrateRollbackCommand = class extends Command {
|
|
|
3902
3928
|
this.app.command = this;
|
|
3903
3929
|
const configuredMigrationsDir = this.app.getConfig("paths")?.migrations ?? join(process.cwd(), "database", "migrations");
|
|
3904
3930
|
const migrationsDir = this.app.resolveRuntimeDirectoryPath(configuredMigrationsDir);
|
|
3905
|
-
if (!existsSync(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3931
|
+
if (!existsSync$1(migrationsDir)) return void this.error(`Error: Migrations directory not found: ${this.app.formatPathForLog(configuredMigrationsDir)}`);
|
|
3906
3932
|
const schemaPath = this.option("schema") ? resolve(String(this.option("schema"))) : join(process.cwd(), "prisma", "schema.prisma");
|
|
3907
3933
|
const stateFilePath = resolveMigrationStateFilePath(process.cwd(), this.option("state-file") ? String(this.option("state-file")) : void 0);
|
|
3908
3934
|
const adapter = this.app.getConfig("adapter");
|
|
@@ -3963,7 +3989,7 @@ var MigrateRollbackCommand = class extends Command {
|
|
|
3963
3989
|
rollbackClasses.forEach(([_, file]) => this.success(this.app.splitLogger("RolledBack", file)));
|
|
3964
3990
|
}
|
|
3965
3991
|
async loadAllMigrations(migrationsDir) {
|
|
3966
|
-
const files = readdirSync(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3992
|
+
const files = readdirSync$1(migrationsDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).sort((left, right) => left.localeCompare(right)).map((file) => this.app.resolveRuntimeScriptPath(join(migrationsDir, file)));
|
|
3967
3993
|
return (await Promise.all(files.map(async (file) => (await this.loadMigrationClassesFromFile(file)).map((cls) => [cls, file])))).flat();
|
|
3968
3994
|
}
|
|
3969
3995
|
async loadMigrationClassesFromFile(filePath) {
|
|
@@ -4005,11 +4031,11 @@ var MigrationHistoryCommand = class extends Command {
|
|
|
4005
4031
|
this.success("Deleted tracked migration state from database.");
|
|
4006
4032
|
return;
|
|
4007
4033
|
}
|
|
4008
|
-
if (!existsSync(stateFilePath)) {
|
|
4034
|
+
if (!existsSync$1(stateFilePath)) {
|
|
4009
4035
|
this.success(`No migration state file found at ${this.app.formatPathForLog(stateFilePath)}`);
|
|
4010
4036
|
return;
|
|
4011
4037
|
}
|
|
4012
|
-
rmSync(stateFilePath);
|
|
4038
|
+
rmSync$1(stateFilePath);
|
|
4013
4039
|
deletePersistedColumnMappingsState(resolveColumnMappingsFilePath(process.cwd()));
|
|
4014
4040
|
this.success(`Deleted migration state file: ${this.app.formatPathForLog(stateFilePath)}`);
|
|
4015
4041
|
return;
|
|
@@ -4144,7 +4170,7 @@ var SeedCommand = class extends Command {
|
|
|
4144
4170
|
this.app.command = this;
|
|
4145
4171
|
const configuredSeedersDir = this.app.getConfig("paths")?.seeders ?? join(process.cwd(), "database", "seeders");
|
|
4146
4172
|
const seedersDir = this.app.resolveRuntimeDirectoryPath(configuredSeedersDir);
|
|
4147
|
-
if (!existsSync(seedersDir)) return void this.error(`ERROR: Seeders directory not found: ${this.app.formatPathForLog(configuredSeedersDir)}`);
|
|
4173
|
+
if (!existsSync$1(seedersDir)) return void this.error(`ERROR: Seeders directory not found: ${this.app.formatPathForLog(configuredSeedersDir)}`);
|
|
4148
4174
|
const classes = this.option("all") ? await this.loadAllSeeders(seedersDir) : await this.loadNamedSeeder(seedersDir, this.argument("name") ?? "DatabaseSeeder");
|
|
4149
4175
|
if (classes.length === 0) return void this.error("ERROR: No seeder classes found to run.");
|
|
4150
4176
|
for (const SeederClassItem of classes) await new SeederClassItem().run();
|
|
@@ -4158,7 +4184,7 @@ var SeedCommand = class extends Command {
|
|
|
4158
4184
|
* @returns
|
|
4159
4185
|
*/
|
|
4160
4186
|
async loadAllSeeders(seedersDir) {
|
|
4161
|
-
const files = readdirSync(seedersDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).map((file) => this.app.resolveRuntimeScriptPath(join(seedersDir, file)));
|
|
4187
|
+
const files = readdirSync$1(seedersDir).filter((file) => /\.(ts|js|mjs|cjs)$/i.test(file)).map((file) => this.app.resolveRuntimeScriptPath(join(seedersDir, file)));
|
|
4162
4188
|
return (await Promise.all(files.map(async (file) => await this.loadSeederClassesFromFile(file)))).flat();
|
|
4163
4189
|
}
|
|
4164
4190
|
/**
|
|
@@ -4179,7 +4205,7 @@ var SeedCommand = class extends Command {
|
|
|
4179
4205
|
`${base}Seeder.js`,
|
|
4180
4206
|
`${base}Seeder.mjs`,
|
|
4181
4207
|
`${base}Seeder.cjs`
|
|
4182
|
-
].map((file) => join(seedersDir, file)).find((file) => existsSync(file));
|
|
4208
|
+
].map((file) => join(seedersDir, file)).find((file) => existsSync$1(file));
|
|
4183
4209
|
if (!target) return [];
|
|
4184
4210
|
const runtimeTarget = this.app.resolveRuntimeScriptPath(target);
|
|
4185
4211
|
return await this.loadSeederClassesFromFile(runtimeTarget);
|