orchid-orm 1.6.2 → 1.6.3
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/index.d.ts +1 -0
- package/dist/index.js +38 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -458,6 +458,7 @@ declare type AppCodeUpdaterConfig = {
|
|
|
458
458
|
baseTablePath: string;
|
|
459
459
|
baseTableName: string;
|
|
460
460
|
mainFilePath: string;
|
|
461
|
+
logger?: QueryLogOptions['logger'];
|
|
461
462
|
};
|
|
462
463
|
declare const appCodeUpdater: ({ tablePath, baseTablePath, baseTableName, mainFilePath, }: SetOptional<AppCodeUpdaterConfig, 'baseTableName'>) => AppCodeUpdater;
|
|
463
464
|
|
package/dist/index.js
CHANGED
|
@@ -1630,7 +1630,7 @@ const optionsToString = (options) => {
|
|
|
1630
1630
|
}
|
|
1631
1631
|
return lines.join("\n ");
|
|
1632
1632
|
};
|
|
1633
|
-
const updateMainFile = async (filePath, tablePath, ast, options) => {
|
|
1633
|
+
const updateMainFile = async (filePath, tablePath, ast, options, logger) => {
|
|
1634
1634
|
const result = await fs__default["default"].readFile(filePath, "utf-8").then(
|
|
1635
1635
|
(content2) => ({ error: void 0, content: content2 }),
|
|
1636
1636
|
(error) => {
|
|
@@ -1677,6 +1677,9 @@ const updateMainFile = async (filePath, tablePath, ast, options) => {
|
|
|
1677
1677
|
await fs__default["default"].mkdir(path__default["default"].dirname(filePath), { recursive: true });
|
|
1678
1678
|
}
|
|
1679
1679
|
await fs__default["default"].writeFile(filePath, write);
|
|
1680
|
+
logger == null ? void 0 : logger.log(
|
|
1681
|
+
`${result.content ? "Updated" : "Created"} ${orchidCore.pathToLog(filePath)}`
|
|
1682
|
+
);
|
|
1680
1683
|
}
|
|
1681
1684
|
};
|
|
1682
1685
|
const createTable$1 = ({ filePath, tablePath, statements, object, content, spaces }, ast) => {
|
|
@@ -1772,9 +1775,11 @@ var __objRest$2 = (source, exclude) => {
|
|
|
1772
1775
|
};
|
|
1773
1776
|
const createTable = async (_a) => {
|
|
1774
1777
|
var _b = _a, {
|
|
1775
|
-
ast
|
|
1778
|
+
ast,
|
|
1779
|
+
logger
|
|
1776
1780
|
} = _b, params = __objRest$2(_b, [
|
|
1777
|
-
"ast"
|
|
1781
|
+
"ast",
|
|
1782
|
+
"logger"
|
|
1778
1783
|
]);
|
|
1779
1784
|
const tablePath = params.tablePath(ast.name);
|
|
1780
1785
|
const baseTablePath = getImportPath(tablePath, params.baseTablePath);
|
|
@@ -1801,6 +1806,7 @@ const createTable = async (_a) => {
|
|
|
1801
1806
|
await fs__default["default"].mkdir(path__default["default"].dirname(tablePath), { recursive: true });
|
|
1802
1807
|
try {
|
|
1803
1808
|
await fs__default["default"].writeFile(tablePath, pqb.codeToString(code, "", " "), { flag: "wx" });
|
|
1809
|
+
logger == null ? void 0 : logger.log(`Created ${orchidCore.pathToLog(tablePath)}`);
|
|
1804
1810
|
} catch (err) {
|
|
1805
1811
|
if (err.code !== "EEXIST") {
|
|
1806
1812
|
throw err;
|
|
@@ -1825,9 +1831,11 @@ var __objRest$1 = (source, exclude) => {
|
|
|
1825
1831
|
};
|
|
1826
1832
|
const changeTable = async (_a) => {
|
|
1827
1833
|
var _b = _a, {
|
|
1828
|
-
ast
|
|
1834
|
+
ast,
|
|
1835
|
+
logger
|
|
1829
1836
|
} = _b, params = __objRest$1(_b, [
|
|
1830
|
-
"ast"
|
|
1837
|
+
"ast",
|
|
1838
|
+
"logger"
|
|
1831
1839
|
]);
|
|
1832
1840
|
const tablePath = params.tablePath(ast.name);
|
|
1833
1841
|
const content = await fs__default["default"].readFile(tablePath, "utf-8").catch(() => void 0);
|
|
@@ -1845,6 +1853,7 @@ const changeTable = async (_a) => {
|
|
|
1845
1853
|
addTableData(context);
|
|
1846
1854
|
}
|
|
1847
1855
|
await fs__default["default"].writeFile(tablePath, changes.apply());
|
|
1856
|
+
logger == null ? void 0 : logger.log(`Updated ${orchidCore.pathToLog(tablePath)}`);
|
|
1848
1857
|
};
|
|
1849
1858
|
function* iterateColumnsShapes(statements, className) {
|
|
1850
1859
|
var _a, _b;
|
|
@@ -2015,7 +2024,7 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
2015
2024
|
continue;
|
|
2016
2025
|
let remove = true;
|
|
2017
2026
|
if (!replaced[key]) {
|
|
2018
|
-
const code = getColumnMethodArgs(to, key);
|
|
2027
|
+
const code = getColumnMethodArgs(t, to, key);
|
|
2019
2028
|
if (code) {
|
|
2020
2029
|
changes.replace(
|
|
2021
2030
|
item.expression.expression.end,
|
|
@@ -2035,7 +2044,7 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
|
|
|
2035
2044
|
for (const key in propsToChange) {
|
|
2036
2045
|
if (changedProps[key])
|
|
2037
2046
|
continue;
|
|
2038
|
-
const code = getColumnMethodArgs(to, key);
|
|
2047
|
+
const code = getColumnMethodArgs(t, to, key);
|
|
2039
2048
|
if (code) {
|
|
2040
2049
|
append += pqb.codeToString(code, spaces + " ", " ").trim();
|
|
2041
2050
|
}
|
|
@@ -2088,7 +2097,7 @@ ${spaces}`);
|
|
|
2088
2097
|
${spaces}`);
|
|
2089
2098
|
}
|
|
2090
2099
|
};
|
|
2091
|
-
const getColumnMethodArgs = (to, key) => {
|
|
2100
|
+
const getColumnMethodArgs = (t, to, key) => {
|
|
2092
2101
|
const value = to[key];
|
|
2093
2102
|
if (!value)
|
|
2094
2103
|
return;
|
|
@@ -2102,7 +2111,7 @@ const getColumnMethodArgs = (to, key) => {
|
|
|
2102
2111
|
if (key === "collate" || key === "compression") {
|
|
2103
2112
|
orchidCore.addCode(code, orchidCore.singleQuote(value));
|
|
2104
2113
|
} else if (key === "default") {
|
|
2105
|
-
orchidCore.addCode(code, pqb.columnDefaultArgumentToCode(value));
|
|
2114
|
+
orchidCore.addCode(code, pqb.columnDefaultArgumentToCode(t, value));
|
|
2106
2115
|
} else if (key !== "nullable" && key !== "primaryKey") {
|
|
2107
2116
|
return;
|
|
2108
2117
|
}
|
|
@@ -2235,9 +2244,11 @@ var __objRest = (source, exclude) => {
|
|
|
2235
2244
|
};
|
|
2236
2245
|
const renameTable = async (_a) => {
|
|
2237
2246
|
var _b = _a, {
|
|
2238
|
-
ast
|
|
2247
|
+
ast,
|
|
2248
|
+
logger
|
|
2239
2249
|
} = _b, params = __objRest(_b, [
|
|
2240
|
-
"ast"
|
|
2250
|
+
"ast",
|
|
2251
|
+
"logger"
|
|
2241
2252
|
]);
|
|
2242
2253
|
var _a2;
|
|
2243
2254
|
const tablePath = params.tablePath(ast.from);
|
|
@@ -2282,6 +2293,7 @@ const renameTable = async (_a) => {
|
|
|
2282
2293
|
}
|
|
2283
2294
|
}
|
|
2284
2295
|
await fs__default["default"].writeFile(tablePath, changes.apply());
|
|
2296
|
+
logger == null ? void 0 : logger.log(`Updated ${orchidCore.pathToLog(tablePath)}`);
|
|
2285
2297
|
};
|
|
2286
2298
|
|
|
2287
2299
|
var __defProp$1 = Object.defineProperty;
|
|
@@ -2316,7 +2328,8 @@ const updateTableFile = async (params) => {
|
|
|
2316
2328
|
|
|
2317
2329
|
const createBaseTableFile = async ({
|
|
2318
2330
|
baseTableName,
|
|
2319
|
-
baseTablePath
|
|
2331
|
+
baseTablePath,
|
|
2332
|
+
logger
|
|
2320
2333
|
}) => {
|
|
2321
2334
|
await fs__default["default"].mkdir(path__default["default"].dirname(baseTablePath), { recursive: true });
|
|
2322
2335
|
await fs__default["default"].writeFile(
|
|
@@ -2328,7 +2341,9 @@ export const ${baseTableName} = createBaseTable();
|
|
|
2328
2341
|
{
|
|
2329
2342
|
flag: "wx"
|
|
2330
2343
|
}
|
|
2331
|
-
).
|
|
2344
|
+
).then(() => {
|
|
2345
|
+
logger == null ? void 0 : logger.log(`Created ${orchidCore.pathToLog(baseTablePath)}`);
|
|
2346
|
+
}).catch((err) => {
|
|
2332
2347
|
if (err.code === "EEXIST")
|
|
2333
2348
|
return;
|
|
2334
2349
|
throw err;
|
|
@@ -2362,7 +2377,7 @@ const appCodeUpdater = ({
|
|
|
2362
2377
|
baseTableName,
|
|
2363
2378
|
mainFilePath
|
|
2364
2379
|
}) => {
|
|
2365
|
-
return async ({ ast, options, basePath, cache: cacheObject }) => {
|
|
2380
|
+
return async ({ ast, options, basePath, cache: cacheObject, logger }) => {
|
|
2366
2381
|
const params = {
|
|
2367
2382
|
tablePath(name) {
|
|
2368
2383
|
const file = tablePath(name);
|
|
@@ -2370,10 +2385,17 @@ const appCodeUpdater = ({
|
|
|
2370
2385
|
},
|
|
2371
2386
|
baseTablePath: resolvePath(basePath, baseTablePath),
|
|
2372
2387
|
baseTableName: baseTableName || "BaseTable",
|
|
2373
|
-
mainFilePath: resolvePath(basePath, mainFilePath)
|
|
2388
|
+
mainFilePath: resolvePath(basePath, mainFilePath),
|
|
2389
|
+
logger
|
|
2374
2390
|
};
|
|
2375
2391
|
const promises = [
|
|
2376
|
-
updateMainFile(
|
|
2392
|
+
updateMainFile(
|
|
2393
|
+
params.mainFilePath,
|
|
2394
|
+
params.tablePath,
|
|
2395
|
+
ast,
|
|
2396
|
+
options,
|
|
2397
|
+
logger
|
|
2398
|
+
),
|
|
2377
2399
|
updateTableFile(__spreadProps(__spreadValues({}, params), { ast }))
|
|
2378
2400
|
];
|
|
2379
2401
|
const cache = cacheObject;
|