relq 1.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 (305) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +862 -0
  3. package/dist/addons/buffer.js +1869 -0
  4. package/dist/addons/pg-cursor.js +1425 -0
  5. package/dist/addons/pg-format.js +2248 -0
  6. package/dist/addons/pg.js +4790 -0
  7. package/dist/bin/relq.js +2 -0
  8. package/dist/cjs/cache/index.cjs +9 -0
  9. package/dist/cjs/cache/query-cache.cjs +311 -0
  10. package/dist/cjs/cli/commands/add.cjs +82 -0
  11. package/dist/cjs/cli/commands/commit.cjs +145 -0
  12. package/dist/cjs/cli/commands/diff.cjs +84 -0
  13. package/dist/cjs/cli/commands/export.cjs +333 -0
  14. package/dist/cjs/cli/commands/fetch.cjs +59 -0
  15. package/dist/cjs/cli/commands/generate.cjs +242 -0
  16. package/dist/cjs/cli/commands/history.cjs +165 -0
  17. package/dist/cjs/cli/commands/import.cjs +524 -0
  18. package/dist/cjs/cli/commands/init.cjs +437 -0
  19. package/dist/cjs/cli/commands/introspect.cjs +142 -0
  20. package/dist/cjs/cli/commands/log.cjs +62 -0
  21. package/dist/cjs/cli/commands/migrate.cjs +167 -0
  22. package/dist/cjs/cli/commands/pull.cjs +410 -0
  23. package/dist/cjs/cli/commands/push.cjs +165 -0
  24. package/dist/cjs/cli/commands/rollback.cjs +169 -0
  25. package/dist/cjs/cli/commands/status.cjs +110 -0
  26. package/dist/cjs/cli/commands/sync.cjs +79 -0
  27. package/dist/cjs/cli/index.cjs +275 -0
  28. package/dist/cjs/cli/utils/change-tracker.cjs +446 -0
  29. package/dist/cjs/cli/utils/commit-manager.cjs +239 -0
  30. package/dist/cjs/cli/utils/config-loader.cjs +127 -0
  31. package/dist/cjs/cli/utils/env-loader.cjs +62 -0
  32. package/dist/cjs/cli/utils/fast-introspect.cjs +398 -0
  33. package/dist/cjs/cli/utils/git-utils.cjs +404 -0
  34. package/dist/cjs/cli/utils/migration-generator.cjs +269 -0
  35. package/dist/cjs/cli/utils/relqignore.cjs +114 -0
  36. package/dist/cjs/cli/utils/repo-manager.cjs +515 -0
  37. package/dist/cjs/cli/utils/schema-comparator.cjs +313 -0
  38. package/dist/cjs/cli/utils/schema-diff.cjs +284 -0
  39. package/dist/cjs/cli/utils/schema-hash.cjs +108 -0
  40. package/dist/cjs/cli/utils/schema-introspect.cjs +455 -0
  41. package/dist/cjs/cli/utils/snapshot-manager.cjs +223 -0
  42. package/dist/cjs/cli/utils/spinner.cjs +108 -0
  43. package/dist/cjs/cli/utils/sql-generator.cjs +520 -0
  44. package/dist/cjs/cli/utils/sql-parser.cjs +999 -0
  45. package/dist/cjs/cli/utils/type-generator.cjs +2061 -0
  46. package/dist/cjs/condition/array-condition-builder.cjs +503 -0
  47. package/dist/cjs/condition/array-numeric-condition-builder.cjs +186 -0
  48. package/dist/cjs/condition/array-specialized-condition-builder.cjs +206 -0
  49. package/dist/cjs/condition/array-string-condition-builder.cjs +146 -0
  50. package/dist/cjs/condition/base-condition-builder.cjs +2 -0
  51. package/dist/cjs/condition/condition-collector.cjs +284 -0
  52. package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
  53. package/dist/cjs/condition/geometric-condition-builder.cjs +208 -0
  54. package/dist/cjs/condition/index.cjs +25 -0
  55. package/dist/cjs/condition/jsonb-condition-builder.cjs +160 -0
  56. package/dist/cjs/condition/network-condition-builder.cjs +230 -0
  57. package/dist/cjs/condition/range-condition-builder.cjs +82 -0
  58. package/dist/cjs/config/config.cjs +190 -0
  59. package/dist/cjs/config/index.cjs +9 -0
  60. package/dist/cjs/constants/pg-values.cjs +68 -0
  61. package/dist/cjs/copy/copy-builder.cjs +316 -0
  62. package/dist/cjs/copy/index.cjs +6 -0
  63. package/dist/cjs/core/query-builder.cjs +440 -0
  64. package/dist/cjs/core/relq-client.cjs +1831 -0
  65. package/dist/cjs/core/typed-kuery-client.cjs +2 -0
  66. package/dist/cjs/count/count-builder.cjs +88 -0
  67. package/dist/cjs/count/index.cjs +5 -0
  68. package/dist/cjs/cte/cte-builder.cjs +89 -0
  69. package/dist/cjs/cte/index.cjs +5 -0
  70. package/dist/cjs/ddl/function.cjs +48 -0
  71. package/dist/cjs/ddl/index.cjs +7 -0
  72. package/dist/cjs/ddl/sql.cjs +54 -0
  73. package/dist/cjs/delete/delete-builder.cjs +135 -0
  74. package/dist/cjs/delete/index.cjs +5 -0
  75. package/dist/cjs/errors/relq-errors.cjs +329 -0
  76. package/dist/cjs/examples/fulltext-search-test.cjs +122 -0
  77. package/dist/cjs/explain/explain-builder.cjs +99 -0
  78. package/dist/cjs/explain/index.cjs +5 -0
  79. package/dist/cjs/function/create-function-builder.cjs +196 -0
  80. package/dist/cjs/function/index.cjs +6 -0
  81. package/dist/cjs/functions/advanced-functions.cjs +241 -0
  82. package/dist/cjs/functions/case-builder.cjs +66 -0
  83. package/dist/cjs/functions/geometric-functions.cjs +104 -0
  84. package/dist/cjs/functions/index.cjs +184 -0
  85. package/dist/cjs/functions/network-functions.cjs +86 -0
  86. package/dist/cjs/functions/sql-functions.cjs +431 -0
  87. package/dist/cjs/index.cjs +164 -0
  88. package/dist/cjs/indexing/create-index-builder.cjs +187 -0
  89. package/dist/cjs/indexing/drop-index-builder.cjs +89 -0
  90. package/dist/cjs/indexing/index-types.cjs +2 -0
  91. package/dist/cjs/indexing/index.cjs +8 -0
  92. package/dist/cjs/insert/conflict-builder.cjs +173 -0
  93. package/dist/cjs/insert/index.cjs +5 -0
  94. package/dist/cjs/insert/insert-builder.cjs +254 -0
  95. package/dist/cjs/introspect/index.cjs +229 -0
  96. package/dist/cjs/maintenance/index.cjs +6 -0
  97. package/dist/cjs/maintenance/vacuum-builder.cjs +166 -0
  98. package/dist/cjs/pubsub/index.cjs +7 -0
  99. package/dist/cjs/pubsub/listen-notify-builder.cjs +57 -0
  100. package/dist/cjs/pubsub/listener-connection.cjs +180 -0
  101. package/dist/cjs/raw/index.cjs +5 -0
  102. package/dist/cjs/raw/raw-query-builder.cjs +27 -0
  103. package/dist/cjs/schema/index.cjs +15 -0
  104. package/dist/cjs/schema/schema-builder.cjs +1167 -0
  105. package/dist/cjs/schema-builder.cjs +21 -0
  106. package/dist/cjs/schema-definition/column-types.cjs +829 -0
  107. package/dist/cjs/schema-definition/index.cjs +62 -0
  108. package/dist/cjs/schema-definition/introspection.cjs +620 -0
  109. package/dist/cjs/schema-definition/partitions.cjs +129 -0
  110. package/dist/cjs/schema-definition/pg-enum.cjs +76 -0
  111. package/dist/cjs/schema-definition/pg-function.cjs +91 -0
  112. package/dist/cjs/schema-definition/pg-sequence.cjs +56 -0
  113. package/dist/cjs/schema-definition/pg-trigger.cjs +108 -0
  114. package/dist/cjs/schema-definition/relations.cjs +98 -0
  115. package/dist/cjs/schema-definition/sql-expressions.cjs +202 -0
  116. package/dist/cjs/schema-definition/table-definition.cjs +636 -0
  117. package/dist/cjs/select/aggregate-builder.cjs +179 -0
  118. package/dist/cjs/select/index.cjs +5 -0
  119. package/dist/cjs/select/select-builder.cjs +233 -0
  120. package/dist/cjs/sequence/index.cjs +7 -0
  121. package/dist/cjs/sequence/sequence-builder.cjs +264 -0
  122. package/dist/cjs/table/alter-table-builder.cjs +146 -0
  123. package/dist/cjs/table/constraint-builder.cjs +102 -0
  124. package/dist/cjs/table/create-table-builder.cjs +248 -0
  125. package/dist/cjs/table/index.cjs +17 -0
  126. package/dist/cjs/table/partition-builder.cjs +131 -0
  127. package/dist/cjs/table/truncate-builder.cjs +70 -0
  128. package/dist/cjs/transaction/index.cjs +6 -0
  129. package/dist/cjs/transaction/transaction-builder.cjs +78 -0
  130. package/dist/cjs/trigger/create-trigger-builder.cjs +174 -0
  131. package/dist/cjs/trigger/index.cjs +6 -0
  132. package/dist/cjs/types/aggregate-types.cjs +2 -0
  133. package/dist/cjs/types/config-types.cjs +40 -0
  134. package/dist/cjs/types/inference-types.cjs +18 -0
  135. package/dist/cjs/types/pagination-types.cjs +7 -0
  136. package/dist/cjs/types/result-types.cjs +2 -0
  137. package/dist/cjs/types/schema-types.cjs +2 -0
  138. package/dist/cjs/types/subscription-types.cjs +2 -0
  139. package/dist/cjs/types.cjs +2 -0
  140. package/dist/cjs/update/array-update-builder.cjs +205 -0
  141. package/dist/cjs/update/index.cjs +13 -0
  142. package/dist/cjs/update/update-builder.cjs +195 -0
  143. package/dist/cjs/utils/case-converter.cjs +58 -0
  144. package/dist/cjs/utils/environment-detection.cjs +120 -0
  145. package/dist/cjs/utils/index.cjs +10 -0
  146. package/dist/cjs/utils/pool-defaults.cjs +106 -0
  147. package/dist/cjs/utils/type-coercion.cjs +118 -0
  148. package/dist/cjs/view/create-view-builder.cjs +180 -0
  149. package/dist/cjs/view/index.cjs +7 -0
  150. package/dist/cjs/window/index.cjs +5 -0
  151. package/dist/cjs/window/window-builder.cjs +80 -0
  152. package/dist/config.cjs +1 -0
  153. package/dist/config.d.ts +655 -0
  154. package/dist/config.js +1 -0
  155. package/dist/esm/cache/index.js +1 -0
  156. package/dist/esm/cache/query-cache.js +303 -0
  157. package/dist/esm/cli/commands/add.js +78 -0
  158. package/dist/esm/cli/commands/commit.js +109 -0
  159. package/dist/esm/cli/commands/diff.js +81 -0
  160. package/dist/esm/cli/commands/export.js +297 -0
  161. package/dist/esm/cli/commands/fetch.js +56 -0
  162. package/dist/esm/cli/commands/generate.js +206 -0
  163. package/dist/esm/cli/commands/history.js +129 -0
  164. package/dist/esm/cli/commands/import.js +488 -0
  165. package/dist/esm/cli/commands/init.js +401 -0
  166. package/dist/esm/cli/commands/introspect.js +106 -0
  167. package/dist/esm/cli/commands/log.js +59 -0
  168. package/dist/esm/cli/commands/migrate.js +131 -0
  169. package/dist/esm/cli/commands/pull.js +374 -0
  170. package/dist/esm/cli/commands/push.js +129 -0
  171. package/dist/esm/cli/commands/rollback.js +133 -0
  172. package/dist/esm/cli/commands/status.js +107 -0
  173. package/dist/esm/cli/commands/sync.js +76 -0
  174. package/dist/esm/cli/index.js +240 -0
  175. package/dist/esm/cli/utils/change-tracker.js +405 -0
  176. package/dist/esm/cli/utils/commit-manager.js +191 -0
  177. package/dist/esm/cli/utils/config-loader.js +86 -0
  178. package/dist/esm/cli/utils/env-loader.js +57 -0
  179. package/dist/esm/cli/utils/fast-introspect.js +362 -0
  180. package/dist/esm/cli/utils/git-utils.js +347 -0
  181. package/dist/esm/cli/utils/migration-generator.js +263 -0
  182. package/dist/esm/cli/utils/relqignore.js +74 -0
  183. package/dist/esm/cli/utils/repo-manager.js +444 -0
  184. package/dist/esm/cli/utils/schema-comparator.js +307 -0
  185. package/dist/esm/cli/utils/schema-diff.js +276 -0
  186. package/dist/esm/cli/utils/schema-hash.js +69 -0
  187. package/dist/esm/cli/utils/schema-introspect.js +418 -0
  188. package/dist/esm/cli/utils/snapshot-manager.js +179 -0
  189. package/dist/esm/cli/utils/spinner.js +101 -0
  190. package/dist/esm/cli/utils/sql-generator.js +504 -0
  191. package/dist/esm/cli/utils/sql-parser.js +992 -0
  192. package/dist/esm/cli/utils/type-generator.js +2058 -0
  193. package/dist/esm/condition/array-condition-builder.js +495 -0
  194. package/dist/esm/condition/array-numeric-condition-builder.js +182 -0
  195. package/dist/esm/condition/array-specialized-condition-builder.js +200 -0
  196. package/dist/esm/condition/array-string-condition-builder.js +142 -0
  197. package/dist/esm/condition/base-condition-builder.js +1 -0
  198. package/dist/esm/condition/condition-collector.js +275 -0
  199. package/dist/esm/condition/fulltext-condition-builder.js +53 -0
  200. package/dist/esm/condition/geometric-condition-builder.js +200 -0
  201. package/dist/esm/condition/index.js +7 -0
  202. package/dist/esm/condition/jsonb-condition-builder.js +152 -0
  203. package/dist/esm/condition/network-condition-builder.js +222 -0
  204. package/dist/esm/condition/range-condition-builder.js +74 -0
  205. package/dist/esm/config/config.js +150 -0
  206. package/dist/esm/config/index.js +1 -0
  207. package/dist/esm/constants/pg-values.js +63 -0
  208. package/dist/esm/copy/copy-builder.js +308 -0
  209. package/dist/esm/copy/index.js +1 -0
  210. package/dist/esm/core/query-builder.js +426 -0
  211. package/dist/esm/core/relq-client.js +1791 -0
  212. package/dist/esm/core/typed-kuery-client.js +1 -0
  213. package/dist/esm/count/count-builder.js +81 -0
  214. package/dist/esm/count/index.js +1 -0
  215. package/dist/esm/cte/cte-builder.js +82 -0
  216. package/dist/esm/cte/index.js +1 -0
  217. package/dist/esm/ddl/function.js +45 -0
  218. package/dist/esm/ddl/index.js +2 -0
  219. package/dist/esm/ddl/sql.js +51 -0
  220. package/dist/esm/delete/delete-builder.js +128 -0
  221. package/dist/esm/delete/index.js +1 -0
  222. package/dist/esm/errors/relq-errors.js +310 -0
  223. package/dist/esm/examples/fulltext-search-test.js +117 -0
  224. package/dist/esm/explain/explain-builder.js +95 -0
  225. package/dist/esm/explain/index.js +1 -0
  226. package/dist/esm/function/create-function-builder.js +188 -0
  227. package/dist/esm/function/index.js +1 -0
  228. package/dist/esm/functions/advanced-functions.js +231 -0
  229. package/dist/esm/functions/case-builder.js +58 -0
  230. package/dist/esm/functions/geometric-functions.js +97 -0
  231. package/dist/esm/functions/index.js +171 -0
  232. package/dist/esm/functions/network-functions.js +79 -0
  233. package/dist/esm/functions/sql-functions.js +421 -0
  234. package/dist/esm/index.js +34 -0
  235. package/dist/esm/indexing/create-index-builder.js +180 -0
  236. package/dist/esm/indexing/drop-index-builder.js +81 -0
  237. package/dist/esm/indexing/index-types.js +1 -0
  238. package/dist/esm/indexing/index.js +2 -0
  239. package/dist/esm/insert/conflict-builder.js +162 -0
  240. package/dist/esm/insert/index.js +1 -0
  241. package/dist/esm/insert/insert-builder.js +247 -0
  242. package/dist/esm/introspect/index.js +224 -0
  243. package/dist/esm/maintenance/index.js +1 -0
  244. package/dist/esm/maintenance/vacuum-builder.js +158 -0
  245. package/dist/esm/pubsub/index.js +1 -0
  246. package/dist/esm/pubsub/listen-notify-builder.js +48 -0
  247. package/dist/esm/pubsub/listener-connection.js +173 -0
  248. package/dist/esm/raw/index.js +1 -0
  249. package/dist/esm/raw/raw-query-builder.js +20 -0
  250. package/dist/esm/schema/index.js +1 -0
  251. package/dist/esm/schema/schema-builder.js +1150 -0
  252. package/dist/esm/schema-builder.js +2 -0
  253. package/dist/esm/schema-definition/column-types.js +738 -0
  254. package/dist/esm/schema-definition/index.js +10 -0
  255. package/dist/esm/schema-definition/introspection.js +614 -0
  256. package/dist/esm/schema-definition/partitions.js +123 -0
  257. package/dist/esm/schema-definition/pg-enum.js +70 -0
  258. package/dist/esm/schema-definition/pg-function.js +85 -0
  259. package/dist/esm/schema-definition/pg-sequence.js +50 -0
  260. package/dist/esm/schema-definition/pg-trigger.js +102 -0
  261. package/dist/esm/schema-definition/relations.js +90 -0
  262. package/dist/esm/schema-definition/sql-expressions.js +193 -0
  263. package/dist/esm/schema-definition/table-definition.js +630 -0
  264. package/dist/esm/select/aggregate-builder.js +172 -0
  265. package/dist/esm/select/index.js +1 -0
  266. package/dist/esm/select/select-builder.js +226 -0
  267. package/dist/esm/sequence/index.js +1 -0
  268. package/dist/esm/sequence/sequence-builder.js +255 -0
  269. package/dist/esm/table/alter-table-builder.js +138 -0
  270. package/dist/esm/table/constraint-builder.js +95 -0
  271. package/dist/esm/table/create-table-builder.js +241 -0
  272. package/dist/esm/table/index.js +5 -0
  273. package/dist/esm/table/partition-builder.js +121 -0
  274. package/dist/esm/table/truncate-builder.js +63 -0
  275. package/dist/esm/transaction/index.js +1 -0
  276. package/dist/esm/transaction/transaction-builder.js +70 -0
  277. package/dist/esm/trigger/create-trigger-builder.js +166 -0
  278. package/dist/esm/trigger/index.js +1 -0
  279. package/dist/esm/types/aggregate-types.js +1 -0
  280. package/dist/esm/types/config-types.js +36 -0
  281. package/dist/esm/types/inference-types.js +12 -0
  282. package/dist/esm/types/pagination-types.js +4 -0
  283. package/dist/esm/types/result-types.js +1 -0
  284. package/dist/esm/types/schema-types.js +1 -0
  285. package/dist/esm/types/subscription-types.js +1 -0
  286. package/dist/esm/types.js +1 -0
  287. package/dist/esm/update/array-update-builder.js +192 -0
  288. package/dist/esm/update/index.js +2 -0
  289. package/dist/esm/update/update-builder.js +188 -0
  290. package/dist/esm/utils/case-converter.js +55 -0
  291. package/dist/esm/utils/environment-detection.js +113 -0
  292. package/dist/esm/utils/index.js +2 -0
  293. package/dist/esm/utils/pool-defaults.js +100 -0
  294. package/dist/esm/utils/type-coercion.js +110 -0
  295. package/dist/esm/view/create-view-builder.js +171 -0
  296. package/dist/esm/view/index.js +1 -0
  297. package/dist/esm/window/index.js +1 -0
  298. package/dist/esm/window/window-builder.js +73 -0
  299. package/dist/index.cjs +1 -0
  300. package/dist/index.d.ts +10341 -0
  301. package/dist/index.js +1 -0
  302. package/dist/schema-builder.cjs +1 -0
  303. package/dist/schema-builder.d.ts +2272 -0
  304. package/dist/schema-builder.js +1 -0
  305. package/package.json +55 -0
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.loadRelqignore = loadRelqignore;
37
+ exports.createDefaultRelqignore = createDefaultRelqignore;
38
+ exports.isIgnored = isIgnored;
39
+ exports.filterIgnored = filterIgnored;
40
+ exports.getIgnorePatterns = getIgnorePatterns;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const DEFAULT_PATTERNS = [
44
+ '_relq_*',
45
+ 'pg_*',
46
+ '_temp_*',
47
+ 'tmp_*',
48
+ ];
49
+ function loadRelqignore(projectRoot = process.cwd()) {
50
+ const ignorePath = path.join(projectRoot, '.relqignore');
51
+ const patterns = [...DEFAULT_PATTERNS];
52
+ if (fs.existsSync(ignorePath)) {
53
+ const content = fs.readFileSync(ignorePath, 'utf-8');
54
+ const lines = content.split('\n');
55
+ for (const line of lines) {
56
+ const trimmed = line.trim();
57
+ if (!trimmed || trimmed.startsWith('#')) {
58
+ continue;
59
+ }
60
+ patterns.push(trimmed);
61
+ }
62
+ }
63
+ return patterns;
64
+ }
65
+ function createDefaultRelqignore(projectRoot = process.cwd()) {
66
+ const ignorePath = path.join(projectRoot, '.relqignore');
67
+ if (fs.existsSync(ignorePath)) {
68
+ return;
69
+ }
70
+ const content = `# Relq Ignore File
71
+ # Tables and functions matching these patterns will be ignored
72
+
73
+ # Relq internal tables (always ignored)
74
+ _relq_*
75
+
76
+ # PostgreSQL system tables
77
+ pg_*
78
+
79
+ # Temporary tables
80
+ _temp_*
81
+ tmp_*
82
+
83
+ # Add your tables/functions to ignore below:
84
+ # analytics_raw
85
+ # debug_*
86
+ # test_*
87
+ `;
88
+ fs.writeFileSync(ignorePath, content, 'utf-8');
89
+ }
90
+ function isIgnored(name, patterns) {
91
+ for (const pattern of patterns) {
92
+ if (matchPattern(name, pattern)) {
93
+ return true;
94
+ }
95
+ }
96
+ return false;
97
+ }
98
+ function filterIgnored(items, patterns) {
99
+ return items.filter(item => !isIgnored(item.name, patterns));
100
+ }
101
+ function matchPattern(name, pattern) {
102
+ if (pattern.startsWith('!')) {
103
+ return !matchPattern(name, pattern.slice(1));
104
+ }
105
+ const regexPattern = pattern
106
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
107
+ .replace(/\*/g, '.*')
108
+ .replace(/\?/g, '.');
109
+ const regex = new RegExp(`^${regexPattern}$`, 'i');
110
+ return regex.test(name);
111
+ }
112
+ function getIgnorePatterns(projectRoot = process.cwd()) {
113
+ return loadRelqignore(projectRoot);
114
+ }
@@ -0,0 +1,515 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.isInitialized = isInitialized;
37
+ exports.initRepository = initRepository;
38
+ exports.getHead = getHead;
39
+ exports.setHead = setHead;
40
+ exports.getFetchHead = getFetchHead;
41
+ exports.setFetchHead = setFetchHead;
42
+ exports.generateHash = generateHash;
43
+ exports.shortHash = shortHash;
44
+ exports.saveCommit = saveCommit;
45
+ exports.loadCommit = loadCommit;
46
+ exports.getAllCommits = getAllCommits;
47
+ exports.getCommitHistory = getCommitHistory;
48
+ exports.createCommit = createCommit;
49
+ exports.getStaged = getStaged;
50
+ exports.setStaged = setStaged;
51
+ exports.clearStaged = clearStaged;
52
+ exports.hasStaged = hasStaged;
53
+ exports.loadSnapshot = loadSnapshot;
54
+ exports.saveSnapshot = saveSnapshot;
55
+ exports.loadWorkingState = loadWorkingState;
56
+ exports.saveWorkingState = saveWorkingState;
57
+ exports.getOrCreateWorkingState = getOrCreateWorkingState;
58
+ exports.addUnstagedChanges = addUnstagedChanges;
59
+ exports.stageChanges = stageChanges;
60
+ exports.unstageChanges = unstageChanges;
61
+ exports.clearWorkingState = clearWorkingState;
62
+ exports.getStagedChanges = getStagedChanges;
63
+ exports.getUnstagedChanges = getUnstagedChanges;
64
+ exports.hasUncommittedChanges = hasUncommittedChanges;
65
+ exports.ensureRemoteTable = ensureRemoteTable;
66
+ exports.fetchRemoteCommits = fetchRemoteCommits;
67
+ exports.getRemoteHead = getRemoteHead;
68
+ exports.pushCommit = pushCommit;
69
+ exports.getRepoStatus = getRepoStatus;
70
+ exports.createEmptySchema = createEmptySchema;
71
+ exports.migrateSnapshot = migrateSnapshot;
72
+ const fs = __importStar(require("fs"));
73
+ const path = __importStar(require("path"));
74
+ const crypto = __importStar(require("crypto"));
75
+ const RELQ_DIR = '.relq';
76
+ const HEAD_FILE = 'HEAD';
77
+ const FETCH_HEAD_FILE = 'FETCH_HEAD';
78
+ const STAGED_FILE = 'staged.json';
79
+ const WORKING_FILE = 'working.json';
80
+ const SNAPSHOT_FILE = 'snapshot.json';
81
+ const COMMITS_DIR = 'commits';
82
+ function isInitialized(projectRoot = process.cwd()) {
83
+ const relqPath = path.join(projectRoot, RELQ_DIR);
84
+ const headPath = path.join(relqPath, HEAD_FILE);
85
+ return fs.existsSync(relqPath) && fs.existsSync(headPath);
86
+ }
87
+ function initRepository(projectRoot = process.cwd()) {
88
+ const relqPath = path.join(projectRoot, RELQ_DIR);
89
+ const commitsPath = path.join(relqPath, COMMITS_DIR);
90
+ if (!fs.existsSync(relqPath)) {
91
+ fs.mkdirSync(relqPath, { recursive: true });
92
+ }
93
+ if (!fs.existsSync(commitsPath)) {
94
+ fs.mkdirSync(commitsPath, { recursive: true });
95
+ }
96
+ const headPath = path.join(relqPath, HEAD_FILE);
97
+ if (!fs.existsSync(headPath)) {
98
+ fs.writeFileSync(headPath, '', 'utf-8');
99
+ }
100
+ const workingPath = path.join(relqPath, WORKING_FILE);
101
+ if (!fs.existsSync(workingPath)) {
102
+ const initialState = {
103
+ timestamp: new Date().toISOString(),
104
+ staged: [],
105
+ unstaged: [],
106
+ };
107
+ fs.writeFileSync(workingPath, JSON.stringify(initialState, null, 2), 'utf-8');
108
+ }
109
+ }
110
+ function getHead(projectRoot = process.cwd()) {
111
+ const headPath = path.join(projectRoot, RELQ_DIR, HEAD_FILE);
112
+ if (!fs.existsSync(headPath)) {
113
+ return null;
114
+ }
115
+ const content = fs.readFileSync(headPath, 'utf-8').trim();
116
+ return content || null;
117
+ }
118
+ function setHead(hash, projectRoot = process.cwd()) {
119
+ const headPath = path.join(projectRoot, RELQ_DIR, HEAD_FILE);
120
+ fs.writeFileSync(headPath, hash, 'utf-8');
121
+ }
122
+ function getFetchHead(projectRoot = process.cwd()) {
123
+ const fetchPath = path.join(projectRoot, RELQ_DIR, FETCH_HEAD_FILE);
124
+ if (!fs.existsSync(fetchPath)) {
125
+ return null;
126
+ }
127
+ return fs.readFileSync(fetchPath, 'utf-8').trim() || null;
128
+ }
129
+ function setFetchHead(hash, projectRoot = process.cwd()) {
130
+ const fetchPath = path.join(projectRoot, RELQ_DIR, FETCH_HEAD_FILE);
131
+ fs.writeFileSync(fetchPath, hash, 'utf-8');
132
+ }
133
+ function generateHash(schema) {
134
+ const normalized = JSON.stringify(schema, Object.keys(schema).sort());
135
+ return crypto.createHash('sha1').update(normalized).digest('hex');
136
+ }
137
+ function shortHash(hash) {
138
+ return hash.substring(0, 7);
139
+ }
140
+ function saveCommit(commit, projectRoot = process.cwd()) {
141
+ const commitsPath = path.join(projectRoot, RELQ_DIR, COMMITS_DIR);
142
+ const commitPath = path.join(commitsPath, `${commit.hash}.json`);
143
+ fs.writeFileSync(commitPath, JSON.stringify(commit, null, 2), 'utf-8');
144
+ }
145
+ function loadCommit(hash, projectRoot = process.cwd()) {
146
+ const commitPath = path.join(projectRoot, RELQ_DIR, COMMITS_DIR, `${hash}.json`);
147
+ if (!fs.existsSync(commitPath)) {
148
+ return null;
149
+ }
150
+ return JSON.parse(fs.readFileSync(commitPath, 'utf-8'));
151
+ }
152
+ function getAllCommits(projectRoot = process.cwd()) {
153
+ const commitsPath = path.join(projectRoot, RELQ_DIR, COMMITS_DIR);
154
+ if (!fs.existsSync(commitsPath)) {
155
+ return [];
156
+ }
157
+ const files = fs.readdirSync(commitsPath).filter(f => f.endsWith('.json'));
158
+ const commits = [];
159
+ for (const file of files) {
160
+ const content = fs.readFileSync(path.join(commitsPath, file), 'utf-8');
161
+ commits.push(JSON.parse(content));
162
+ }
163
+ commits.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
164
+ return commits;
165
+ }
166
+ function getCommitHistory(limit = 20, projectRoot = process.cwd()) {
167
+ const head = getHead(projectRoot);
168
+ if (!head)
169
+ return [];
170
+ const history = [];
171
+ let currentHash = head;
172
+ while (currentHash && history.length < limit) {
173
+ const commit = loadCommit(currentHash, projectRoot);
174
+ if (!commit)
175
+ break;
176
+ history.push(commit);
177
+ currentHash = commit.parentHash;
178
+ }
179
+ return history;
180
+ }
181
+ function createCommit(schema, author, message, projectRoot = process.cwd()) {
182
+ const hash = generateHash(schema);
183
+ const parentHash = getHead(projectRoot);
184
+ const commit = {
185
+ hash,
186
+ parentHash,
187
+ author,
188
+ message,
189
+ timestamp: new Date().toISOString(),
190
+ schema,
191
+ stats: {
192
+ tables: schema.tables.length,
193
+ columns: schema.tables.reduce((acc, t) => acc + t.columns.length, 0),
194
+ indexes: schema.tables.reduce((acc, t) => acc + t.indexes.length, 0),
195
+ enums: schema.enums?.length || 0,
196
+ domains: schema.domains?.length || 0,
197
+ compositeTypes: schema.compositeTypes?.length || 0,
198
+ sequences: schema.sequences?.length || 0,
199
+ functions: schema.functions?.length || 0,
200
+ triggers: schema.triggers?.length || 0,
201
+ },
202
+ };
203
+ saveCommit(commit, projectRoot);
204
+ setHead(hash, projectRoot);
205
+ clearStaged(projectRoot);
206
+ return commit;
207
+ }
208
+ function getStaged(projectRoot = process.cwd()) {
209
+ const stagedPath = path.join(projectRoot, RELQ_DIR, STAGED_FILE);
210
+ if (!fs.existsSync(stagedPath)) {
211
+ return null;
212
+ }
213
+ const content = fs.readFileSync(stagedPath, 'utf-8');
214
+ return content === 'null' ? null : JSON.parse(content);
215
+ }
216
+ function setStaged(staged, projectRoot = process.cwd()) {
217
+ const stagedPath = path.join(projectRoot, RELQ_DIR, STAGED_FILE);
218
+ fs.writeFileSync(stagedPath, staged ? JSON.stringify(staged, null, 2) : 'null', 'utf-8');
219
+ }
220
+ function clearStaged(projectRoot = process.cwd()) {
221
+ setStaged(null, projectRoot);
222
+ }
223
+ function hasStaged(projectRoot = process.cwd()) {
224
+ const staged = getStaged(projectRoot);
225
+ if (!staged)
226
+ return false;
227
+ return (staged.tables.added.length > 0 ||
228
+ staged.tables.modified.length > 0 ||
229
+ staged.tables.removed.length > 0 ||
230
+ staged.functions.added.length > 0 ||
231
+ staged.functions.modified.length > 0 ||
232
+ staged.functions.removed.length > 0);
233
+ }
234
+ function loadSnapshot(projectRoot = process.cwd()) {
235
+ const snapshotPath = path.join(projectRoot, RELQ_DIR, SNAPSHOT_FILE);
236
+ if (!fs.existsSync(snapshotPath)) {
237
+ return null;
238
+ }
239
+ const raw = JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'));
240
+ return migrateSnapshot(raw);
241
+ }
242
+ function saveSnapshot(schema, projectRoot = process.cwd()) {
243
+ const snapshotPath = path.join(projectRoot, RELQ_DIR, SNAPSHOT_FILE);
244
+ fs.writeFileSync(snapshotPath, JSON.stringify(schema, null, 2), 'utf-8');
245
+ }
246
+ function loadWorkingState(projectRoot = process.cwd()) {
247
+ const workingPath = path.join(projectRoot, RELQ_DIR, WORKING_FILE);
248
+ if (!fs.existsSync(workingPath)) {
249
+ return null;
250
+ }
251
+ const content = fs.readFileSync(workingPath, 'utf-8');
252
+ return content === 'null' ? null : JSON.parse(content);
253
+ }
254
+ function saveWorkingState(state, projectRoot = process.cwd()) {
255
+ const workingPath = path.join(projectRoot, RELQ_DIR, WORKING_FILE);
256
+ fs.writeFileSync(workingPath, JSON.stringify(state, null, 2), 'utf-8');
257
+ }
258
+ function getOrCreateWorkingState(projectRoot = process.cwd()) {
259
+ const existing = loadWorkingState(projectRoot);
260
+ if (existing)
261
+ return existing;
262
+ return {
263
+ timestamp: new Date().toISOString(),
264
+ staged: [],
265
+ unstaged: [],
266
+ };
267
+ }
268
+ function addUnstagedChanges(changes, projectRoot = process.cwd()) {
269
+ const state = getOrCreateWorkingState(projectRoot);
270
+ const existingIds = new Set(state.unstaged.map(c => c.id));
271
+ for (const change of changes) {
272
+ if (!existingIds.has(change.id)) {
273
+ state.unstaged.push(change);
274
+ existingIds.add(change.id);
275
+ }
276
+ }
277
+ state.timestamp = new Date().toISOString();
278
+ saveWorkingState(state, projectRoot);
279
+ }
280
+ function stageChanges(patterns, projectRoot = process.cwd()) {
281
+ const state = getOrCreateWorkingState(projectRoot);
282
+ const staged = [];
283
+ const remaining = [];
284
+ const isAll = patterns.includes('*') || patterns.includes('.');
285
+ for (const change of state.unstaged) {
286
+ const matchesPattern = isAll || patterns.some(p => {
287
+ const fullName = change.parentName
288
+ ? `${change.parentName}.${change.objectName}`
289
+ : change.objectName;
290
+ return fullName.includes(p) ||
291
+ change.objectName === p ||
292
+ change.objectType.toLowerCase() === p.toLowerCase();
293
+ });
294
+ if (matchesPattern) {
295
+ staged.push(change);
296
+ }
297
+ else {
298
+ remaining.push(change);
299
+ }
300
+ }
301
+ state.staged.push(...staged);
302
+ state.unstaged = remaining;
303
+ state.timestamp = new Date().toISOString();
304
+ saveWorkingState(state, projectRoot);
305
+ return staged;
306
+ }
307
+ function unstageChanges(patterns, projectRoot = process.cwd()) {
308
+ const state = getOrCreateWorkingState(projectRoot);
309
+ const unstaged = [];
310
+ const remaining = [];
311
+ const isAll = patterns.includes('*') || patterns.includes('.');
312
+ for (const change of state.staged) {
313
+ const matchesPattern = isAll || patterns.some(p => {
314
+ const fullName = change.parentName
315
+ ? `${change.parentName}.${change.objectName}`
316
+ : change.objectName;
317
+ return fullName.includes(p) || change.objectName === p;
318
+ });
319
+ if (matchesPattern) {
320
+ unstaged.push(change);
321
+ }
322
+ else {
323
+ remaining.push(change);
324
+ }
325
+ }
326
+ state.unstaged.push(...unstaged);
327
+ state.staged = remaining;
328
+ state.timestamp = new Date().toISOString();
329
+ saveWorkingState(state, projectRoot);
330
+ return unstaged;
331
+ }
332
+ function clearWorkingState(projectRoot = process.cwd()) {
333
+ const workingPath = path.join(projectRoot, RELQ_DIR, WORKING_FILE);
334
+ if (fs.existsSync(workingPath)) {
335
+ fs.unlinkSync(workingPath);
336
+ }
337
+ }
338
+ function getStagedChanges(projectRoot = process.cwd()) {
339
+ const state = loadWorkingState(projectRoot);
340
+ return state?.staged || [];
341
+ }
342
+ function getUnstagedChanges(projectRoot = process.cwd()) {
343
+ const state = loadWorkingState(projectRoot);
344
+ return state?.unstaged || [];
345
+ }
346
+ function hasUncommittedChanges(projectRoot = process.cwd()) {
347
+ const state = loadWorkingState(projectRoot);
348
+ if (!state)
349
+ return false;
350
+ return state.staged.length > 0 || state.unstaged.length > 0;
351
+ }
352
+ async function ensureRemoteTable(connection) {
353
+ const { Pool } = await Promise.resolve().then(() => __importStar(require("../../../addons/pg.js")));
354
+ const pool = new Pool({
355
+ host: connection.host,
356
+ port: connection.port || 5432,
357
+ database: connection.database,
358
+ user: connection.user,
359
+ password: connection.password,
360
+ connectionString: connection.url,
361
+ ssl: connection.ssl,
362
+ });
363
+ try {
364
+ await pool.query(`
365
+ CREATE TABLE IF NOT EXISTS _relq_commits (
366
+ id SERIAL PRIMARY KEY,
367
+ hash VARCHAR(40) UNIQUE NOT NULL,
368
+ parent_hash VARCHAR(40),
369
+ author VARCHAR(255) NOT NULL,
370
+ message TEXT,
371
+ schema_snapshot JSONB NOT NULL,
372
+ stats JSONB,
373
+ created_at TIMESTAMPTZ DEFAULT NOW()
374
+ );
375
+
376
+ CREATE INDEX IF NOT EXISTS idx_relq_commits_hash ON _relq_commits(hash);
377
+ CREATE INDEX IF NOT EXISTS idx_relq_commits_created ON _relq_commits(created_at DESC);
378
+ `);
379
+ }
380
+ finally {
381
+ await pool.end();
382
+ }
383
+ }
384
+ async function fetchRemoteCommits(connection, limit = 100) {
385
+ const { Pool } = await Promise.resolve().then(() => __importStar(require("../../../addons/pg.js")));
386
+ const pool = new Pool({
387
+ host: connection.host,
388
+ port: connection.port || 5432,
389
+ database: connection.database,
390
+ user: connection.user,
391
+ password: connection.password,
392
+ connectionString: connection.url,
393
+ ssl: connection.ssl,
394
+ });
395
+ try {
396
+ const result = await pool.query(`
397
+ SELECT hash, parent_hash, author, message, schema_snapshot, stats, created_at
398
+ FROM _relq_commits
399
+ ORDER BY created_at DESC
400
+ LIMIT $1
401
+ `, [limit]);
402
+ return result.rows.map(row => ({
403
+ hash: row.hash,
404
+ parentHash: row.parent_hash,
405
+ author: row.author,
406
+ message: row.message || '',
407
+ timestamp: row.created_at.toISOString(),
408
+ schema: row.schema_snapshot,
409
+ stats: row.stats || { tables: 0, columns: 0, indexes: 0, functions: 0, triggers: 0 },
410
+ }));
411
+ }
412
+ finally {
413
+ await pool.end();
414
+ }
415
+ }
416
+ async function getRemoteHead(connection) {
417
+ const commits = await fetchRemoteCommits(connection, 1);
418
+ return commits.length > 0 ? commits[0].hash : null;
419
+ }
420
+ async function pushCommit(connection, commit) {
421
+ const { Pool } = await Promise.resolve().then(() => __importStar(require("../../../addons/pg.js")));
422
+ const pool = new Pool({
423
+ host: connection.host,
424
+ port: connection.port || 5432,
425
+ database: connection.database,
426
+ user: connection.user,
427
+ password: connection.password,
428
+ connectionString: connection.url,
429
+ ssl: connection.ssl,
430
+ });
431
+ try {
432
+ await pool.query(`
433
+ INSERT INTO _relq_commits (hash, parent_hash, author, message, schema_snapshot, stats)
434
+ VALUES ($1, $2, $3, $4, $5, $6)
435
+ ON CONFLICT (hash) DO NOTHING
436
+ `, [
437
+ commit.hash,
438
+ commit.parentHash,
439
+ commit.author,
440
+ commit.message,
441
+ JSON.stringify(commit.schema),
442
+ JSON.stringify(commit.stats),
443
+ ]);
444
+ }
445
+ finally {
446
+ await pool.end();
447
+ }
448
+ }
449
+ async function getRepoStatus(connection, projectRoot = process.cwd()) {
450
+ const initialized = isInitialized(projectRoot);
451
+ const head = getHead(projectRoot);
452
+ const staged = getStaged(projectRoot);
453
+ const localCommits = getAllCommits(projectRoot).length;
454
+ let aheadBy = 0;
455
+ let behindBy = 0;
456
+ if (initialized && head) {
457
+ try {
458
+ const remoteHead = await getRemoteHead(connection);
459
+ const localHashes = new Set(getAllCommits(projectRoot).map(c => c.hash));
460
+ const remoteCommits = await fetchRemoteCommits(connection, 100);
461
+ const remoteHashes = new Set(remoteCommits.map(c => c.hash));
462
+ aheadBy = [...localHashes].filter(h => !remoteHashes.has(h)).length;
463
+ behindBy = [...remoteHashes].filter(h => !localHashes.has(h)).length;
464
+ }
465
+ catch {
466
+ }
467
+ }
468
+ return {
469
+ initialized,
470
+ head,
471
+ staged,
472
+ localCommits,
473
+ aheadBy,
474
+ behindBy,
475
+ };
476
+ }
477
+ function createEmptySchema() {
478
+ return {
479
+ extensions: [],
480
+ enums: [],
481
+ domains: [],
482
+ compositeTypes: [],
483
+ sequences: [],
484
+ collations: [],
485
+ tables: [],
486
+ functions: [],
487
+ triggers: [],
488
+ views: [],
489
+ materializedViews: [],
490
+ foreignTables: [],
491
+ };
492
+ }
493
+ function migrateSnapshot(snapshot) {
494
+ const extensions = (snapshot.extensions || []).map(ext => typeof ext === 'string' ? { name: ext } : ext);
495
+ const triggers = (snapshot.triggers || []).map((t) => ({
496
+ ...t,
497
+ events: t.events || (t.event ? [t.event] : []),
498
+ forEach: t.forEach || 'STATEMENT',
499
+ functionName: t.functionName || '',
500
+ }));
501
+ return {
502
+ extensions,
503
+ enums: snapshot.enums || [],
504
+ domains: snapshot.domains || [],
505
+ compositeTypes: snapshot.compositeTypes || [],
506
+ sequences: snapshot.sequences || [],
507
+ collations: snapshot.collations || [],
508
+ tables: snapshot.tables || [],
509
+ functions: snapshot.functions || [],
510
+ triggers,
511
+ views: snapshot.views || [],
512
+ materializedViews: snapshot.materializedViews || [],
513
+ foreignTables: snapshot.foreignTables || [],
514
+ };
515
+ }