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.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { columnTypes, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSqlCacheKey, NotFoundError, relationQueryKey, Db, Adapter, anyShape, getClonedQueryData, columnsShapeToCode, codeToString, primaryKeyToCode, indexToCode, foreignKeyToCode, columnIndexesToCode, columnForeignKeysToCode, columnDefaultArgumentToCode } from 'pqb';
2
2
  export { columnTypes } from 'pqb';
3
- import { snakeCaseKey, emptyObject, singleQuote, quoteObjectKey, addCode } from 'orchid-core';
3
+ import { snakeCaseKey, emptyObject, pathToLog, singleQuote, quoteObjectKey, addCode } from 'orchid-core';
4
4
  import * as path from 'path';
5
5
  import path__default from 'path';
6
6
  import fs from 'fs/promises';
@@ -1603,7 +1603,7 @@ const optionsToString = (options) => {
1603
1603
  }
1604
1604
  return lines.join("\n ");
1605
1605
  };
1606
- const updateMainFile = async (filePath, tablePath, ast, options) => {
1606
+ const updateMainFile = async (filePath, tablePath, ast, options, logger) => {
1607
1607
  const result = await fs.readFile(filePath, "utf-8").then(
1608
1608
  (content2) => ({ error: void 0, content: content2 }),
1609
1609
  (error) => {
@@ -1650,6 +1650,9 @@ const updateMainFile = async (filePath, tablePath, ast, options) => {
1650
1650
  await fs.mkdir(path__default.dirname(filePath), { recursive: true });
1651
1651
  }
1652
1652
  await fs.writeFile(filePath, write);
1653
+ logger == null ? void 0 : logger.log(
1654
+ `${result.content ? "Updated" : "Created"} ${pathToLog(filePath)}`
1655
+ );
1653
1656
  }
1654
1657
  };
1655
1658
  const createTable$1 = ({ filePath, tablePath, statements, object, content, spaces }, ast) => {
@@ -1745,9 +1748,11 @@ var __objRest$2 = (source, exclude) => {
1745
1748
  };
1746
1749
  const createTable = async (_a) => {
1747
1750
  var _b = _a, {
1748
- ast
1751
+ ast,
1752
+ logger
1749
1753
  } = _b, params = __objRest$2(_b, [
1750
- "ast"
1754
+ "ast",
1755
+ "logger"
1751
1756
  ]);
1752
1757
  const tablePath = params.tablePath(ast.name);
1753
1758
  const baseTablePath = getImportPath(tablePath, params.baseTablePath);
@@ -1774,6 +1779,7 @@ const createTable = async (_a) => {
1774
1779
  await fs.mkdir(path__default.dirname(tablePath), { recursive: true });
1775
1780
  try {
1776
1781
  await fs.writeFile(tablePath, codeToString(code, "", " "), { flag: "wx" });
1782
+ logger == null ? void 0 : logger.log(`Created ${pathToLog(tablePath)}`);
1777
1783
  } catch (err) {
1778
1784
  if (err.code !== "EEXIST") {
1779
1785
  throw err;
@@ -1798,9 +1804,11 @@ var __objRest$1 = (source, exclude) => {
1798
1804
  };
1799
1805
  const changeTable = async (_a) => {
1800
1806
  var _b = _a, {
1801
- ast
1807
+ ast,
1808
+ logger
1802
1809
  } = _b, params = __objRest$1(_b, [
1803
- "ast"
1810
+ "ast",
1811
+ "logger"
1804
1812
  ]);
1805
1813
  const tablePath = params.tablePath(ast.name);
1806
1814
  const content = await fs.readFile(tablePath, "utf-8").catch(() => void 0);
@@ -1818,6 +1826,7 @@ const changeTable = async (_a) => {
1818
1826
  addTableData(context);
1819
1827
  }
1820
1828
  await fs.writeFile(tablePath, changes.apply());
1829
+ logger == null ? void 0 : logger.log(`Updated ${pathToLog(tablePath)}`);
1821
1830
  };
1822
1831
  function* iterateColumnsShapes(statements, className) {
1823
1832
  var _a, _b;
@@ -1988,7 +1997,7 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
1988
1997
  continue;
1989
1998
  let remove = true;
1990
1999
  if (!replaced[key]) {
1991
- const code = getColumnMethodArgs(to, key);
2000
+ const code = getColumnMethodArgs(t, to, key);
1992
2001
  if (code) {
1993
2002
  changes.replace(
1994
2003
  item.expression.expression.end,
@@ -2008,7 +2017,7 @@ const changeColumn = ({ changes, t, spaces }, changeItem, prop) => {
2008
2017
  for (const key in propsToChange) {
2009
2018
  if (changedProps[key])
2010
2019
  continue;
2011
- const code = getColumnMethodArgs(to, key);
2020
+ const code = getColumnMethodArgs(t, to, key);
2012
2021
  if (code) {
2013
2022
  append += codeToString(code, spaces + " ", " ").trim();
2014
2023
  }
@@ -2061,7 +2070,7 @@ ${spaces}`);
2061
2070
  ${spaces}`);
2062
2071
  }
2063
2072
  };
2064
- const getColumnMethodArgs = (to, key) => {
2073
+ const getColumnMethodArgs = (t, to, key) => {
2065
2074
  const value = to[key];
2066
2075
  if (!value)
2067
2076
  return;
@@ -2075,7 +2084,7 @@ const getColumnMethodArgs = (to, key) => {
2075
2084
  if (key === "collate" || key === "compression") {
2076
2085
  addCode(code, singleQuote(value));
2077
2086
  } else if (key === "default") {
2078
- addCode(code, columnDefaultArgumentToCode(value));
2087
+ addCode(code, columnDefaultArgumentToCode(t, value));
2079
2088
  } else if (key !== "nullable" && key !== "primaryKey") {
2080
2089
  return;
2081
2090
  }
@@ -2208,9 +2217,11 @@ var __objRest = (source, exclude) => {
2208
2217
  };
2209
2218
  const renameTable = async (_a) => {
2210
2219
  var _b = _a, {
2211
- ast
2220
+ ast,
2221
+ logger
2212
2222
  } = _b, params = __objRest(_b, [
2213
- "ast"
2223
+ "ast",
2224
+ "logger"
2214
2225
  ]);
2215
2226
  var _a2;
2216
2227
  const tablePath = params.tablePath(ast.from);
@@ -2255,6 +2266,7 @@ const renameTable = async (_a) => {
2255
2266
  }
2256
2267
  }
2257
2268
  await fs.writeFile(tablePath, changes.apply());
2269
+ logger == null ? void 0 : logger.log(`Updated ${pathToLog(tablePath)}`);
2258
2270
  };
2259
2271
 
2260
2272
  var __defProp$1 = Object.defineProperty;
@@ -2289,7 +2301,8 @@ const updateTableFile = async (params) => {
2289
2301
 
2290
2302
  const createBaseTableFile = async ({
2291
2303
  baseTableName,
2292
- baseTablePath
2304
+ baseTablePath,
2305
+ logger
2293
2306
  }) => {
2294
2307
  await fs.mkdir(path__default.dirname(baseTablePath), { recursive: true });
2295
2308
  await fs.writeFile(
@@ -2301,7 +2314,9 @@ export const ${baseTableName} = createBaseTable();
2301
2314
  {
2302
2315
  flag: "wx"
2303
2316
  }
2304
- ).catch((err) => {
2317
+ ).then(() => {
2318
+ logger == null ? void 0 : logger.log(`Created ${pathToLog(baseTablePath)}`);
2319
+ }).catch((err) => {
2305
2320
  if (err.code === "EEXIST")
2306
2321
  return;
2307
2322
  throw err;
@@ -2335,7 +2350,7 @@ const appCodeUpdater = ({
2335
2350
  baseTableName,
2336
2351
  mainFilePath
2337
2352
  }) => {
2338
- return async ({ ast, options, basePath, cache: cacheObject }) => {
2353
+ return async ({ ast, options, basePath, cache: cacheObject, logger }) => {
2339
2354
  const params = {
2340
2355
  tablePath(name) {
2341
2356
  const file = tablePath(name);
@@ -2343,10 +2358,17 @@ const appCodeUpdater = ({
2343
2358
  },
2344
2359
  baseTablePath: resolvePath(basePath, baseTablePath),
2345
2360
  baseTableName: baseTableName || "BaseTable",
2346
- mainFilePath: resolvePath(basePath, mainFilePath)
2361
+ mainFilePath: resolvePath(basePath, mainFilePath),
2362
+ logger
2347
2363
  };
2348
2364
  const promises = [
2349
- updateMainFile(params.mainFilePath, params.tablePath, ast, options),
2365
+ updateMainFile(
2366
+ params.mainFilePath,
2367
+ params.tablePath,
2368
+ ast,
2369
+ options,
2370
+ logger
2371
+ ),
2350
2372
  updateTableFile(__spreadProps(__spreadValues({}, params), { ast }))
2351
2373
  ];
2352
2374
  const cache = cacheObject;