aiex-cli 0.0.0

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 (116) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +118 -0
  3. package/bin/cli.mjs +2 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/cli.mjs +9948 -0
  6. package/dist/core/schema-sqlite/migrate-helper.d.mts +1 -0
  7. package/dist/core/schema-sqlite/migrate-helper.mjs +190 -0
  8. package/dist/doctor-Wic10PLt.mjs +711 -0
  9. package/dist/index.d.mts +281 -0
  10. package/dist/index.mjs +3 -0
  11. package/dist/table-schema.json +220 -0
  12. package/dist/web/assets/abap-Cry0R76c.js +1 -0
  13. package/dist/web/assets/apex-xqbJ58nJ.js +1 -0
  14. package/dist/web/assets/azcli-D7JTNGKs.js +1 -0
  15. package/dist/web/assets/bat-Cuq6hn0K.js +1 -0
  16. package/dist/web/assets/bicep-eTuQjz9F.js +2 -0
  17. package/dist/web/assets/cameligo-DKgCRl36.js +1 -0
  18. package/dist/web/assets/chunk-BEqpzyXh.js +1 -0
  19. package/dist/web/assets/clojure-B_aTBtVh.js +1 -0
  20. package/dist/web/assets/codicon-DCmgc-ay.ttf +0 -0
  21. package/dist/web/assets/coffee-BWAYpIPu.js +1 -0
  22. package/dist/web/assets/cpp-BduBQE8d.js +1 -0
  23. package/dist/web/assets/csharp-CMqOVYKK.js +1 -0
  24. package/dist/web/assets/csp-6cGliXw2.js +1 -0
  25. package/dist/web/assets/css-CHnKqS9Q.js +3 -0
  26. package/dist/web/assets/cssMode-BloHqzZF.js +4 -0
  27. package/dist/web/assets/cypher-DMzZBj2L.js +1 -0
  28. package/dist/web/assets/dart-7hYfJ1Dv.js +1 -0
  29. package/dist/web/assets/dockerfile-BflvjnJW.js +1 -0
  30. package/dist/web/assets/ecl-BEt6xb2p.js +1 -0
  31. package/dist/web/assets/editor-BR-TvLsg.css +1 -0
  32. package/dist/web/assets/editor-DPKWm9GW.css +1 -0
  33. package/dist/web/assets/editor.api-BG499EJF.js +642 -0
  34. package/dist/web/assets/editor.main-BhEWG0_P.js +53 -0
  35. package/dist/web/assets/editor.worker-DwXe4U6w.js +12 -0
  36. package/dist/web/assets/elixir-CnrQCt6o.js +1 -0
  37. package/dist/web/assets/flow9-CfLCoUuB.js +1 -0
  38. package/dist/web/assets/freemarker2-DOHaFATh.js +3 -0
  39. package/dist/web/assets/fsharp-BQqR9uQ6.js +1 -0
  40. package/dist/web/assets/go-C3AlMVwy.js +1 -0
  41. package/dist/web/assets/graphql-O_-hDldf.js +1 -0
  42. package/dist/web/assets/handlebars-BIFWety9.js +1 -0
  43. package/dist/web/assets/hcl-BQQD6Mtj.js +1 -0
  44. package/dist/web/assets/html-YGaqGZNd.js +1 -0
  45. package/dist/web/assets/htmlMode-Bu3PyHjq.js +4 -0
  46. package/dist/web/assets/index-Bi376XVf.css +2 -0
  47. package/dist/web/assets/index-c6KB-9C-.js +3262 -0
  48. package/dist/web/assets/ini-Bf0RDfP_.js +1 -0
  49. package/dist/web/assets/java-nqX2KEDD.js +1 -0
  50. package/dist/web/assets/javascript-N0gZqDK0.js +1 -0
  51. package/dist/web/assets/json.worker-DhD1Scrm.js +51 -0
  52. package/dist/web/assets/jsonMode-z5YscjcG.js +10 -0
  53. package/dist/web/assets/julia-B6P9U5er.js +1 -0
  54. package/dist/web/assets/kotlin-B-LRk09-.js +1 -0
  55. package/dist/web/assets/less-CEaIdW1f.js +2 -0
  56. package/dist/web/assets/lexon-Qv4pvFSW.js +1 -0
  57. package/dist/web/assets/liquid-BHfNNVLs.js +1 -0
  58. package/dist/web/assets/lua-CFpyR7YN.js +1 -0
  59. package/dist/web/assets/m3-CvKhVPQn.js +1 -0
  60. package/dist/web/assets/markdown-qldG3Vc4.js +1 -0
  61. package/dist/web/assets/mdx-Dqu2t0et.js +1 -0
  62. package/dist/web/assets/mips-0D8PRyHq.js +1 -0
  63. package/dist/web/assets/monaco.contribution-ByQ3yI-W.js +2 -0
  64. package/dist/web/assets/msdax-DwZXSC5M.js +1 -0
  65. package/dist/web/assets/mysql-BWq85KY4.js +1 -0
  66. package/dist/web/assets/objective-c-D653JUMG.js +1 -0
  67. package/dist/web/assets/pascal-rWjRDdnR.js +1 -0
  68. package/dist/web/assets/pascaligo-Db8EehaF.js +1 -0
  69. package/dist/web/assets/perl-C68oq8-D.js +1 -0
  70. package/dist/web/assets/pgsql-BXeHe33s.js +1 -0
  71. package/dist/web/assets/php-CDVsAbfl.js +1 -0
  72. package/dist/web/assets/pla-DnryFT0q.js +1 -0
  73. package/dist/web/assets/postiats-CDg_4Ev-.js +1 -0
  74. package/dist/web/assets/powerquery-CWPi8ROz.js +1 -0
  75. package/dist/web/assets/powershell-C5A0QX3-.js +1 -0
  76. package/dist/web/assets/preload-helper-DSXbuxSR.js +1 -0
  77. package/dist/web/assets/primeicons-C6QP2o4f.woff2 +0 -0
  78. package/dist/web/assets/primeicons-DMOk5skT.eot +0 -0
  79. package/dist/web/assets/primeicons-Dr5RGzOO.svg +345 -0
  80. package/dist/web/assets/primeicons-MpK4pl85.ttf +0 -0
  81. package/dist/web/assets/primeicons-WjwUDZjB.woff +0 -0
  82. package/dist/web/assets/protobuf-Cgt-BQbL.js +2 -0
  83. package/dist/web/assets/pug-RPYJC9QB.js +1 -0
  84. package/dist/web/assets/python-icfse9Ji.js +1 -0
  85. package/dist/web/assets/qsharp-BZ3S7fu_.js +1 -0
  86. package/dist/web/assets/r-CN875f1X.js +1 -0
  87. package/dist/web/assets/razor-DwVkryG9.js +1 -0
  88. package/dist/web/assets/redis-BLesvTwR.js +1 -0
  89. package/dist/web/assets/redshift-Byf_0XqD.js +1 -0
  90. package/dist/web/assets/restructuredtext-DYg_6BiZ.js +1 -0
  91. package/dist/web/assets/ruby-C4OkxbC-.js +1 -0
  92. package/dist/web/assets/rust-xAoaEFMh.js +1 -0
  93. package/dist/web/assets/sb-C8dHOW_y.js +1 -0
  94. package/dist/web/assets/scala-Spx0wP1o.js +1 -0
  95. package/dist/web/assets/scheme-D2mZlAUz.js +1 -0
  96. package/dist/web/assets/scss-DDCn3Ylu.js +3 -0
  97. package/dist/web/assets/shell-M6px0EWn.js +1 -0
  98. package/dist/web/assets/solidity-DUWMJi-f.js +1 -0
  99. package/dist/web/assets/sophia-DwJbUG-2.js +1 -0
  100. package/dist/web/assets/sparql-ClQxbRPI.js +1 -0
  101. package/dist/web/assets/sql-BQdjW7Vy.js +1 -0
  102. package/dist/web/assets/st-BpISyZ_v.js +1 -0
  103. package/dist/web/assets/swift-CMbl5gM4.js +1 -0
  104. package/dist/web/assets/systemverilog-jx2Xs7uO.js +1 -0
  105. package/dist/web/assets/tcl-GIGnfs89.js +1 -0
  106. package/dist/web/assets/tsMode-CLrI3bdf.js +11 -0
  107. package/dist/web/assets/twig-Bc0mxc_m.js +1 -0
  108. package/dist/web/assets/typescript-BzuZVF7m.js +1 -0
  109. package/dist/web/assets/typespec-CEioAsEm.js +1 -0
  110. package/dist/web/assets/vb-BPk67J-d.js +1 -0
  111. package/dist/web/assets/wgsl-DOnyt8_J.js +298 -0
  112. package/dist/web/assets/xml-Cr85kdqA.js +1 -0
  113. package/dist/web/assets/yaml-D3RbJnnO.js +1 -0
  114. package/dist/web/index.html +25 -0
  115. package/package.json +86 -0
  116. package/src/core/schema-sqlite/migrate-helper.ts +246 -0
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,190 @@
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import process from "node:process";
4
+ import { fileURLToPath } from "node:url";
5
+ import fs from "node:fs/promises";
6
+ import Database from "better-sqlite3";
7
+ import * as esbuild from "esbuild";
8
+
9
+ //#region src/core/schema-sqlite/migrate-helper.ts
10
+ const require = createRequire(import.meta.url);
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+ const { generateSQLiteDrizzleJson, generateSQLiteMigration } = require("drizzle-kit/api");
14
+ const EMPTY_SNAPSHOT = {
15
+ version: "6",
16
+ dialect: "sqlite",
17
+ tables: {},
18
+ views: {},
19
+ enums: {},
20
+ _meta: {
21
+ tables: {},
22
+ columns: {}
23
+ },
24
+ internal: { indexes: {} },
25
+ id: "00000000-0000-0000-0000-000000000000",
26
+ prevId: "00000000-0000-0000-0000-000000000000"
27
+ };
28
+ async function loadSchemaExports(schemaPath) {
29
+ let cliDir;
30
+ try {
31
+ const pkgPath = require.resolve("aiex-cli/package.json");
32
+ cliDir = path.dirname(pkgPath);
33
+ } catch {
34
+ cliDir = path.dirname(path.dirname(path.dirname(path.dirname(__dirname))));
35
+ }
36
+ const result = await esbuild.build({
37
+ entryPoints: [schemaPath],
38
+ bundle: true,
39
+ platform: "node",
40
+ format: "cjs",
41
+ write: false,
42
+ nodePaths: [path.join(cliDir, "node_modules")]
43
+ });
44
+ const tempPath = schemaPath.replace(".ts", ".__bundled__.cjs");
45
+ await fs.writeFile(tempPath, result.outputFiles[0].text);
46
+ try {
47
+ const exports = require(tempPath);
48
+ await fs.unlink(tempPath);
49
+ return exports;
50
+ } catch (e) {
51
+ await fs.unlink(tempPath).catch(() => {});
52
+ throw e;
53
+ }
54
+ }
55
+ async function loadPrevSnapshot(migrationsPath) {
56
+ const metaPath = path.join(migrationsPath, "meta", "_journal.json");
57
+ try {
58
+ const journal = JSON.parse(await fs.readFile(metaPath, "utf-8"));
59
+ if (!journal.entries?.length) return null;
60
+ const latestEntry = journal.entries[journal.entries.length - 1];
61
+ const snapshotPath = path.join(migrationsPath, "meta", `${latestEntry.tag}_snapshot.json`);
62
+ return JSON.parse(await fs.readFile(snapshotPath, "utf-8"));
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+ async function saveSnapshot(migrationsPath, snapshot) {
68
+ const metaPath = path.join(migrationsPath, "meta");
69
+ await fs.mkdir(metaPath, { recursive: true });
70
+ const journalPath = path.join(metaPath, "_journal.json");
71
+ let journal;
72
+ try {
73
+ journal = JSON.parse(await fs.readFile(journalPath, "utf-8"));
74
+ } catch {
75
+ journal = {
76
+ version: "6",
77
+ dialect: "sqlite",
78
+ entries: []
79
+ };
80
+ }
81
+ const idx = journal.entries.length + 1;
82
+ const tag = `${String(idx).padStart(4, "0")}_${snapshot.id.replace(/-/g, "_").substring(0, 8)}`;
83
+ const snapshotPath = path.join(metaPath, `${tag}_snapshot.json`);
84
+ await fs.writeFile(snapshotPath, JSON.stringify(snapshot, null, 2));
85
+ journal.entries.push({
86
+ idx,
87
+ version: snapshot.id,
88
+ when: Date.now(),
89
+ tag,
90
+ breakpoints: true
91
+ });
92
+ await fs.writeFile(journalPath, JSON.stringify(journal, null, 2));
93
+ return tag;
94
+ }
95
+ async function saveMigrationFile(migrationsPath, tag, sqlStatements) {
96
+ await fs.mkdir(migrationsPath, { recursive: true });
97
+ const sqlPath = path.join(migrationsPath, `${tag}.sql`);
98
+ const sqlContent = sqlStatements.join("\n--> statement-breakpoint\n");
99
+ await fs.writeFile(sqlPath, sqlContent);
100
+ return sqlPath;
101
+ }
102
+ function applyMigrationWithTransaction(dbPath, sqlStatements) {
103
+ const db = new Database(dbPath);
104
+ const transaction = db.transaction(() => {
105
+ for (const sql of sqlStatements) db.exec(sql);
106
+ });
107
+ try {
108
+ transaction();
109
+ } finally {
110
+ db.close();
111
+ }
112
+ }
113
+ const LOCK_FILE = ".migrate.lock";
114
+ async function acquireLock(aiexDir) {
115
+ const lockPath = path.join(aiexDir, LOCK_FILE);
116
+ await fs.mkdir(aiexDir, { recursive: true });
117
+ try {
118
+ const fd = await fs.open(lockPath, "wx");
119
+ await fd.write(`${process.pid}\n${Date.now()}`);
120
+ await fd.close();
121
+ } catch (e) {
122
+ if (e.code === "EEXIST") try {
123
+ const [pidStr, timestampStr] = (await fs.readFile(lockPath, "utf-8")).split("\n");
124
+ const lockPid = Number.parseInt(pidStr, 10);
125
+ const lockTime = Number.parseInt(timestampStr, 10);
126
+ const lockAge = Date.now() - lockTime;
127
+ if (lockAge > 3e5) {
128
+ await fs.unlink(lockPath);
129
+ return acquireLock(aiexDir);
130
+ }
131
+ 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.`);
132
+ } catch {
133
+ await fs.unlink(lockPath).catch(() => {});
134
+ return acquireLock(aiexDir);
135
+ }
136
+ throw e;
137
+ }
138
+ }
139
+ async function releaseLock(aiexDir) {
140
+ const lockPath = path.join(aiexDir, LOCK_FILE);
141
+ await fs.unlink(lockPath).catch(() => {});
142
+ }
143
+ async function main() {
144
+ const args = process.argv.slice(2);
145
+ const schemaPath = args[0];
146
+ const migrationsPath = args[1];
147
+ const dbPath = args[2];
148
+ if (!schemaPath || !migrationsPath || !dbPath) {
149
+ console.error("Usage: migrate-helper.ts <schemaPath> <migrationsPath> <dbPath>");
150
+ process.exit(1);
151
+ }
152
+ try {
153
+ const aiexDir = path.dirname(path.dirname(migrationsPath));
154
+ await acquireLock(aiexDir);
155
+ try {
156
+ const exports = await loadSchemaExports(schemaPath);
157
+ const prevSnapshot = await loadPrevSnapshot(migrationsPath);
158
+ const currentSnapshot = await generateSQLiteDrizzleJson(exports, prevSnapshot?.id);
159
+ const sqlStatements = await generateSQLiteMigration(prevSnapshot || EMPTY_SNAPSHOT, currentSnapshot);
160
+ if (sqlStatements.length === 0) {
161
+ console.log(JSON.stringify({
162
+ success: true,
163
+ changes: 0
164
+ }));
165
+ return;
166
+ }
167
+ applyMigrationWithTransaction(dbPath, sqlStatements);
168
+ const tag = await saveSnapshot(migrationsPath, currentSnapshot);
169
+ await saveMigrationFile(migrationsPath, tag, sqlStatements);
170
+ console.log(JSON.stringify({
171
+ success: true,
172
+ changes: sqlStatements.length,
173
+ tag
174
+ }));
175
+ } finally {
176
+ await releaseLock(aiexDir);
177
+ }
178
+ } catch (error) {
179
+ const message = error instanceof Error ? error.message : String(error);
180
+ console.error(JSON.stringify({
181
+ success: false,
182
+ error: message
183
+ }));
184
+ process.exit(1);
185
+ }
186
+ }
187
+ main();
188
+
189
+ //#endregion
190
+ export { };