aiex-cli 0.0.1-beta.9 → 0.0.2-beta.1

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.
Files changed (127) hide show
  1. package/README.md +50 -26
  2. package/dist/cli.mjs +1776 -626
  3. package/dist/{completions-ygS1okck.mjs → completions-C3rmTwXZ.mjs} +2 -2
  4. package/dist/core/schema-sqlite/migrate-helper.mjs +35 -37
  5. package/dist/{doctor-BiU1lDp-.mjs → doctor-collector-Cbqgwx__.mjs} +309 -223
  6. package/dist/index.d.mts +15 -15
  7. package/dist/index.mjs +1 -1
  8. package/dist/table-schema.json +4 -0
  9. package/dist/web/assets/AISettings-Cm8fAfaG.js +205 -0
  10. package/dist/web/assets/DataBrowser-DQwOvooY.js +6 -0
  11. package/dist/web/assets/ExtractRunner-CzfLlCCf.js +1 -0
  12. package/dist/web/assets/ExtractionViewer-D7tghmR-.js +1 -0
  13. package/dist/web/assets/JsonSchemaEditor-DXhYW-Un.js +570 -0
  14. package/dist/web/assets/api-client-CIC2X8_4.js +1 -0
  15. package/dist/web/assets/baseinput-B7PU5-38.js +2 -0
  16. package/dist/web/assets/button-Cdgr9Igy.js +927 -0
  17. package/dist/web/assets/checkbox-CCQwMfLd.js +142 -0
  18. package/dist/web/assets/{cssMode-DAbG0CMn.js → cssMode-CCz1uj8b.js} +1 -1
  19. package/dist/web/assets/dialog-8xaIXBKO.js +108 -0
  20. package/dist/web/assets/dist-B5Yem2Jn.js +1 -0
  21. package/dist/web/assets/{editor.main-BqhfoHxy.js → editor.main-DOue-nGf.js} +2 -2
  22. package/dist/web/assets/{freemarker2-B9_5ct2b.js → freemarker2-C87H7V8i.js} +1 -1
  23. package/dist/web/assets/{handlebars-TY59WcoQ.js → handlebars-TLnoktZW.js} +1 -1
  24. package/dist/web/assets/{html-CLULsh27.js → html-Rewbtgcp.js} +1 -1
  25. package/dist/web/assets/{htmlMode-BvG7RNbU.js → htmlMode-Cr9y3YUi.js} +1 -1
  26. package/dist/web/assets/index-BEorm4a5.css +2 -0
  27. package/dist/web/assets/{index-CKUXTDYj.js → index-CWy8KajQ.js} +38 -38
  28. package/dist/web/assets/{javascript-DHrLp6gu.js → javascript-BO8DPECx.js} +1 -1
  29. package/dist/web/assets/{jsonMode-DBDhdzl1.js → jsonMode-B78m_Y1l.js} +1 -1
  30. package/dist/web/assets/{liquid-tGeb-nqF.js → liquid-CDp_8YUE.js} +1 -1
  31. package/dist/web/assets/{mdx-Cmdz78VU.js → mdx-CeR1GULE.js} +1 -1
  32. package/dist/web/assets/{monaco.contribution-CroYPUF5.js → monaco.contribution-tCitzj1_.js} +2 -2
  33. package/dist/web/assets/object-utils-Cm2M3fPO.js +1 -0
  34. package/dist/web/assets/{python-Dmfz4iDE.js → python-DWmB1hQ6.js} +1 -1
  35. package/dist/web/assets/{razor-BJicZHJs.js → razor-BVk762Lq.js} +1 -1
  36. package/dist/web/assets/runtime-dom.esm-bundler-DZwuSnld.js +1 -0
  37. package/dist/web/assets/select-DKPPF403.js +438 -0
  38. package/dist/web/assets/{tsMode-DYqTyE66.js → tsMode-Gjs5D1gt.js} +1 -1
  39. package/dist/web/assets/{typescript-DLnTe9Hf.js → typescript-Cw6YtwrM.js} +1 -1
  40. package/dist/web/assets/utils-CZhxh2Ya.js +2 -0
  41. package/dist/web/assets/{xml-BIYqLORk.js → xml-guZq0YZJ.js} +1 -1
  42. package/dist/web/assets/{yaml-BjmulkMX.js → yaml-B9TbU-LX.js} +1 -1
  43. package/dist/web/index.html +11 -8
  44. package/package.json +17 -1
  45. package/src/core/schema-sqlite/migrate-helper.ts +32 -46
  46. package/dist/web/assets/AISettings-DOzonIux.js +0 -334
  47. package/dist/web/assets/DataBrowser-rznfVRaV.js +0 -3
  48. package/dist/web/assets/JsonSchemaEditor-C9iyQs7N.js +0 -929
  49. package/dist/web/assets/api-client-Dsg4WOM9.js +0 -1
  50. package/dist/web/assets/button-kTMweGMc.js +0 -927
  51. package/dist/web/assets/dialog-CWuu7WjI.js +0 -108
  52. package/dist/web/assets/index-DDFnprdM.css +0 -2
  53. package/dist/web/assets/lib-C30cIFrm.js +0 -1
  54. package/dist/web/assets/overlayeventbus-AtOpmI6n.js +0 -80
  55. package/dist/web/assets/table-schema-mJrrf9qw.js +0 -2
  56. /package/dist/web/assets/{abap-DrZwwXZX.js → abap-C3UM4cME.js} +0 -0
  57. /package/dist/web/assets/{apex-CrCz0btt.js → apex-BQBZvQmN.js} +0 -0
  58. /package/dist/web/assets/{azcli-BapzKHay.js → azcli-Dn9Awrok.js} +0 -0
  59. /package/dist/web/assets/{bat-C_NRAiA1.js → bat-JgEezSDo.js} +0 -0
  60. /package/dist/web/assets/{bicep-C7pp2CNk.js → bicep-vcQeC7wE.js} +0 -0
  61. /package/dist/web/assets/{cameligo-BhhK9vxZ.js → cameligo-C0cr0T3L.js} +0 -0
  62. /package/dist/web/assets/{clojure-D0ujmUyE.js → clojure-Brc1-rbW.js} +0 -0
  63. /package/dist/web/assets/{coffee-DHEl7Jbb.js → coffee-BiZYU83a.js} +0 -0
  64. /package/dist/web/assets/{cpp-Iil-3nzZ.js → cpp-ikWHCInz.js} +0 -0
  65. /package/dist/web/assets/{csharp-Dh0Ee7SY.js → csharp-BRWs_LfH.js} +0 -0
  66. /package/dist/web/assets/{csp-mwzjw0JL.js → csp-CcAumoJw.js} +0 -0
  67. /package/dist/web/assets/{css-COIa8ZTR.js → css-BZm6paiA.js} +0 -0
  68. /package/dist/web/assets/{cypher-GVc17FC4.js → cypher-CDQMONdb.js} +0 -0
  69. /package/dist/web/assets/{dart-phiCaE7_.js → dart-Ci4SZdF1.js} +0 -0
  70. /package/dist/web/assets/{dockerfile-BMaDhdim.js → dockerfile-BV0tAr-M.js} +0 -0
  71. /package/dist/web/assets/{ecl-Cj47kvqp.js → ecl-CP7nM2KN.js} +0 -0
  72. /package/dist/web/assets/{editor.api-DLXGyrN1.js → editor.api-BU_q4v8i.js} +0 -0
  73. /package/dist/web/assets/{elixir-DBbstcE1.js → elixir-GcA6wFiI.js} +0 -0
  74. /package/dist/web/assets/{flow9-ChHb1adO.js → flow9-CIb9youF.js} +0 -0
  75. /package/dist/web/assets/{fsharp-CMk2OIJN.js → fsharp-BVaBE4co.js} +0 -0
  76. /package/dist/web/assets/{go-BrMkuJg0.js → go-Bbqf306x.js} +0 -0
  77. /package/dist/web/assets/{graphql-PSR1UKGv.js → graphql-DJPrC4l-.js} +0 -0
  78. /package/dist/web/assets/{hcl-DAQrbDOW.js → hcl-QyfWVWpM.js} +0 -0
  79. /package/dist/web/assets/{ini-0TG5BxW0.js → ini-CgstZeS8.js} +0 -0
  80. /package/dist/web/assets/{java-rgorz17v.js → java-D4AG88ZY.js} +0 -0
  81. /package/dist/web/assets/{julia-C8VMdHm8.js → julia-CN8U9648.js} +0 -0
  82. /package/dist/web/assets/{kotlin-CllWo3gX.js → kotlin-gNNgpJhY.js} +0 -0
  83. /package/dist/web/assets/{less-Cgca25AP.js → less-C3SY2L8t.js} +0 -0
  84. /package/dist/web/assets/{lexon-D0GHdBaw.js → lexon-CznnqzUX.js} +0 -0
  85. /package/dist/web/assets/{lua-DmRsNG-P.js → lua-f3xyJgy5.js} +0 -0
  86. /package/dist/web/assets/{m3-BgL5dNKT.js → m3-Cl7J89p-.js} +0 -0
  87. /package/dist/web/assets/{markdown-BuJfycGS.js → markdown-Bv2fnzzT.js} +0 -0
  88. /package/dist/web/assets/{mips-C9m_93PR.js → mips-D6rXUTWa.js} +0 -0
  89. /package/dist/web/assets/{msdax-CpFHC9OI.js → msdax-Bb1N2x5J.js} +0 -0
  90. /package/dist/web/assets/{mysql-qFvltsqN.js → mysql-DXSr6oD7.js} +0 -0
  91. /package/dist/web/assets/{objective-c-Bnmr858J.js → objective-c-CEJiVkDa.js} +0 -0
  92. /package/dist/web/assets/{pascal-WP0_D5AO.js → pascal-BtkMEIba.js} +0 -0
  93. /package/dist/web/assets/{pascaligo-Blom4Rij.js → pascaligo-C7FAwqk7.js} +0 -0
  94. /package/dist/web/assets/{perl-B-vk8g64.js → perl-D9kqkBbN.js} +0 -0
  95. /package/dist/web/assets/{pgsql-Cgvz6v67.js → pgsql-BjGTBL1W.js} +0 -0
  96. /package/dist/web/assets/{php-8a3Lrw9m.js → php-BN0c0noA.js} +0 -0
  97. /package/dist/web/assets/{pla-DuFqEZ8V.js → pla-B94QTqOt.js} +0 -0
  98. /package/dist/web/assets/{postiats-DkLtSgkp.js → postiats-DH91dqBs.js} +0 -0
  99. /package/dist/web/assets/{powerquery-BJ1aNepW.js → powerquery-D7P0oUen.js} +0 -0
  100. /package/dist/web/assets/{powershell-rE98k687.js → powershell-CCVHmJax.js} +0 -0
  101. /package/dist/web/assets/{preload-helper-DWTEM3RW.js → preload-helper-DgFuoWHe.js} +0 -0
  102. /package/dist/web/assets/{protobuf-CUheFacr.js → protobuf-BIP7pixC.js} +0 -0
  103. /package/dist/web/assets/{pug-LDcAMD8w.js → pug-DcbLK7HH.js} +0 -0
  104. /package/dist/web/assets/{qsharp-IHfqKOfK.js → qsharp-B-VY_WOG.js} +0 -0
  105. /package/dist/web/assets/{r-D-QApv87.js → r-DwRtsJsj.js} +0 -0
  106. /package/dist/web/assets/{redis-SXdDyWR9.js → redis-CaW0tkwu.js} +0 -0
  107. /package/dist/web/assets/{redshift-Y6lsCryn.js → redshift-3tS8G0ME.js} +0 -0
  108. /package/dist/web/assets/{restructuredtext-edObr9a8.js → restructuredtext-_TNyGyK0.js} +0 -0
  109. /package/dist/web/assets/{ruby-CNnUfF-8.js → ruby-A-MwVfO4.js} +0 -0
  110. /package/dist/web/assets/{rust-IHUZWzBr.js → rust-oemlUIvG.js} +0 -0
  111. /package/dist/web/assets/{sb-DrUvY44N.js → sb-BDZuaI3W.js} +0 -0
  112. /package/dist/web/assets/{scala-B4hbXGLM.js → scala-Bfo2loK4.js} +0 -0
  113. /package/dist/web/assets/{scheme-BGrd12j3.js → scheme-N2eo7rjB.js} +0 -0
  114. /package/dist/web/assets/{scss-x5G1ES4U.js → scss-vjjSCTgN.js} +0 -0
  115. /package/dist/web/assets/{shell-DOehe2Y8.js → shell-Bfb9Yq6w.js} +0 -0
  116. /package/dist/web/assets/{solidity-BeRvcwWV.js → solidity-C9RbukzG.js} +0 -0
  117. /package/dist/web/assets/{sophia-DZbkUNjy.js → sophia-DWV_MWOg.js} +0 -0
  118. /package/dist/web/assets/{sparql-B7_oi5-h.js → sparql-iMXILWhh.js} +0 -0
  119. /package/dist/web/assets/{sql-CTlsFWVE.js → sql-CJDj31JM.js} +0 -0
  120. /package/dist/web/assets/{st-DJVEJdPE.js → st-BG9AQ1OO.js} +0 -0
  121. /package/dist/web/assets/{swift-CwhT3fYa.js → swift-B579DvHm.js} +0 -0
  122. /package/dist/web/assets/{systemverilog-BQN63pkN.js → systemverilog-BNgaF3ZX.js} +0 -0
  123. /package/dist/web/assets/{tcl-DqwfpskA.js → tcl-grdtJiUA.js} +0 -0
  124. /package/dist/web/assets/{twig-BiyenUgc.js → twig-JAsFXBZw.js} +0 -0
  125. /package/dist/web/assets/{typespec-CWOJribt.js → typespec-D3hIQXEU.js} +0 -0
  126. /package/dist/web/assets/{vb-Cq5F87m3.js → vb-H38jRcEz.js} +0 -0
  127. /package/dist/web/assets/{wgsl-BAvW2lVr.js → wgsl-BC5Grc5r.js} +0 -0
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
2
  import process from "node:process";
3
+ import { readFileSync } from "jsonfile";
3
4
  import fs from "node:fs";
4
5
 
5
6
  //#region src/core/completions.ts
@@ -27,8 +28,7 @@ function getFileCompletions(pattern) {
27
28
  }
28
29
  function getJsonModelNames(configPath) {
29
30
  try {
30
- const content = fs.readFileSync(configPath, "utf-8");
31
- const config = JSON.parse(content);
31
+ const config = readFileSync(configPath);
32
32
  if (config.provider?.models) return config.provider.models.map((m) => m.name);
33
33
  } catch {}
34
34
  return [];
@@ -1,10 +1,12 @@
1
1
  import { createRequire } from "node:module";
2
+ import fs from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import process from "node:process";
5
+ import { readFile, writeFile } from "jsonfile";
4
6
  import { fileURLToPath } from "node:url";
5
- import fs from "node:fs/promises";
6
7
  import Database from "better-sqlite3";
7
8
  import * as esbuild from "esbuild";
9
+ import lockfile from "proper-lockfile";
8
10
 
9
11
  //#region src/core/schema-sqlite/migration-name.ts
10
12
  function sanitizeMigrationName(name) {
@@ -62,11 +64,10 @@ async function loadSchemaExports(schemaPath) {
62
64
  async function loadPrevSnapshot(migrationsPath) {
63
65
  const metaPath = path.join(migrationsPath, "meta", "_journal.json");
64
66
  try {
65
- const journal = JSON.parse(await fs.readFile(metaPath, "utf-8"));
67
+ const journal = await readFile(metaPath);
66
68
  if (!journal.entries?.length) return null;
67
69
  const latestEntry = journal.entries[journal.entries.length - 1];
68
- const snapshotPath = path.join(migrationsPath, "meta", `${latestEntry.tag}_snapshot.json`);
69
- return JSON.parse(await fs.readFile(snapshotPath, "utf-8"));
70
+ return await readFile(path.join(migrationsPath, "meta", `${latestEntry.tag}_snapshot.json`));
70
71
  } catch {
71
72
  return null;
72
73
  }
@@ -77,7 +78,7 @@ async function saveSnapshot(migrationsPath, snapshot, migrationName) {
77
78
  const journalPath = path.join(metaPath, "_journal.json");
78
79
  let journal;
79
80
  try {
80
- journal = JSON.parse(await fs.readFile(journalPath, "utf-8"));
81
+ journal = await readFile(journalPath);
81
82
  } catch {
82
83
  journal = {
83
84
  version: "6",
@@ -88,8 +89,10 @@ async function saveSnapshot(migrationsPath, snapshot, migrationName) {
88
89
  const idx = journal.entries.length + 1;
89
90
  const suffix = sanitizeMigrationName(migrationName) || snapshot.id.replace(/-/g, "_").substring(0, 8);
90
91
  const tag = `${String(idx).padStart(4, "0")}_${suffix}`;
91
- const snapshotPath = path.join(metaPath, `${tag}_snapshot.json`);
92
- await fs.writeFile(snapshotPath, JSON.stringify(snapshot, null, 2));
92
+ await writeFile(path.join(metaPath, `${tag}_snapshot.json`), snapshot, {
93
+ spaces: 2,
94
+ EOL: "\n"
95
+ });
93
96
  journal.entries.push({
94
97
  idx,
95
98
  version: snapshot.id,
@@ -97,7 +100,10 @@ async function saveSnapshot(migrationsPath, snapshot, migrationName) {
97
100
  tag,
98
101
  breakpoints: true
99
102
  });
100
- await fs.writeFile(journalPath, JSON.stringify(journal, null, 2));
103
+ await writeFile(journalPath, journal, {
104
+ spaces: 2,
105
+ EOL: "\n"
106
+ });
101
107
  return tag;
102
108
  }
103
109
  async function saveMigrationFile(migrationsPath, tag, sqlStatements) {
@@ -119,35 +125,22 @@ function applyMigrationWithTransaction(dbPath, sqlStatements) {
119
125
  }
120
126
  }
121
127
  const LOCK_FILE = ".migrate.lock";
122
- async function acquireLock(aiexDir) {
123
- const lockPath = path.join(aiexDir, LOCK_FILE);
128
+ async function acquireMigrationLock(aiexDir) {
124
129
  await fs.mkdir(aiexDir, { recursive: true });
125
130
  try {
126
- const fd = await fs.open(lockPath, "wx");
127
- await fd.write(`${process.pid}\n${Date.now()}`);
128
- await fd.close();
129
- } catch (e) {
130
- if (e.code === "EEXIST") try {
131
- const [pidStr, timestampStr] = (await fs.readFile(lockPath, "utf-8")).split("\n");
132
- const lockPid = Number.parseInt(pidStr, 10);
133
- const lockTime = Number.parseInt(timestampStr, 10);
134
- const lockAge = Date.now() - lockTime;
135
- if (lockAge > 3e5) {
136
- await fs.unlink(lockPath);
137
- return acquireLock(aiexDir);
138
- }
139
- throw new Error(`Migration is already running (PID ${lockPid}, started ${Math.round(lockAge / 1e3)}s ago). Wait for it to complete or remove ${lockPath} if stale.`);
140
- } catch {
141
- await fs.unlink(lockPath).catch(() => {});
142
- return acquireLock(aiexDir);
143
- }
144
- throw e;
131
+ return await lockfile.lock(aiexDir, {
132
+ lockfilePath: path.join(aiexDir, LOCK_FILE),
133
+ realpath: false,
134
+ stale: 3e5,
135
+ update: 1e4,
136
+ retries: 0
137
+ });
138
+ } catch (error) {
139
+ const lockPath = path.join(aiexDir, LOCK_FILE);
140
+ const message = error instanceof Error ? error.message : String(error);
141
+ throw new Error(`Migration is already running or the lock could not be acquired. Wait for it to complete or remove ${lockPath} if stale. ${message}`);
145
142
  }
146
143
  }
147
- async function releaseLock(aiexDir) {
148
- const lockPath = path.join(aiexDir, LOCK_FILE);
149
- await fs.unlink(lockPath).catch(() => {});
150
- }
151
144
  async function main() {
152
145
  const args = process.argv.slice(2);
153
146
  const schemaPath = args[0];
@@ -159,11 +152,16 @@ async function main() {
159
152
  process.exit(1);
160
153
  }
161
154
  try {
162
- const aiexDir = path.dirname(path.dirname(migrationsPath));
163
- await acquireLock(aiexDir);
155
+ const releaseLock = await acquireMigrationLock(path.dirname(path.dirname(migrationsPath)));
164
156
  try {
165
157
  const exports = await loadSchemaExports(schemaPath);
166
- const prevSnapshot = await loadPrevSnapshot(migrationsPath);
158
+ let dbMissing = false;
159
+ try {
160
+ await fs.access(dbPath);
161
+ } catch {
162
+ dbMissing = true;
163
+ }
164
+ const prevSnapshot = dbMissing ? null : await loadPrevSnapshot(migrationsPath);
167
165
  const currentSnapshot = await generateSQLiteDrizzleJson(exports, prevSnapshot?.id);
168
166
  const sqlStatements = await generateSQLiteMigration(prevSnapshot || EMPTY_SNAPSHOT, currentSnapshot);
169
167
  if (sqlStatements.length === 0) {
@@ -182,7 +180,7 @@ async function main() {
182
180
  tag
183
181
  }));
184
182
  } finally {
185
- await releaseLock(aiexDir);
183
+ await releaseLock();
186
184
  }
187
185
  } catch (error) {
188
186
  const message = error instanceof Error ? error.message : String(error);