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.
- package/LICENSE +21 -0
- package/README.md +862 -0
- package/dist/addons/buffer.js +1869 -0
- package/dist/addons/pg-cursor.js +1425 -0
- package/dist/addons/pg-format.js +2248 -0
- package/dist/addons/pg.js +4790 -0
- package/dist/bin/relq.js +2 -0
- package/dist/cjs/cache/index.cjs +9 -0
- package/dist/cjs/cache/query-cache.cjs +311 -0
- package/dist/cjs/cli/commands/add.cjs +82 -0
- package/dist/cjs/cli/commands/commit.cjs +145 -0
- package/dist/cjs/cli/commands/diff.cjs +84 -0
- package/dist/cjs/cli/commands/export.cjs +333 -0
- package/dist/cjs/cli/commands/fetch.cjs +59 -0
- package/dist/cjs/cli/commands/generate.cjs +242 -0
- package/dist/cjs/cli/commands/history.cjs +165 -0
- package/dist/cjs/cli/commands/import.cjs +524 -0
- package/dist/cjs/cli/commands/init.cjs +437 -0
- package/dist/cjs/cli/commands/introspect.cjs +142 -0
- package/dist/cjs/cli/commands/log.cjs +62 -0
- package/dist/cjs/cli/commands/migrate.cjs +167 -0
- package/dist/cjs/cli/commands/pull.cjs +410 -0
- package/dist/cjs/cli/commands/push.cjs +165 -0
- package/dist/cjs/cli/commands/rollback.cjs +169 -0
- package/dist/cjs/cli/commands/status.cjs +110 -0
- package/dist/cjs/cli/commands/sync.cjs +79 -0
- package/dist/cjs/cli/index.cjs +275 -0
- package/dist/cjs/cli/utils/change-tracker.cjs +446 -0
- package/dist/cjs/cli/utils/commit-manager.cjs +239 -0
- package/dist/cjs/cli/utils/config-loader.cjs +127 -0
- package/dist/cjs/cli/utils/env-loader.cjs +62 -0
- package/dist/cjs/cli/utils/fast-introspect.cjs +398 -0
- package/dist/cjs/cli/utils/git-utils.cjs +404 -0
- package/dist/cjs/cli/utils/migration-generator.cjs +269 -0
- package/dist/cjs/cli/utils/relqignore.cjs +114 -0
- package/dist/cjs/cli/utils/repo-manager.cjs +515 -0
- package/dist/cjs/cli/utils/schema-comparator.cjs +313 -0
- package/dist/cjs/cli/utils/schema-diff.cjs +284 -0
- package/dist/cjs/cli/utils/schema-hash.cjs +108 -0
- package/dist/cjs/cli/utils/schema-introspect.cjs +455 -0
- package/dist/cjs/cli/utils/snapshot-manager.cjs +223 -0
- package/dist/cjs/cli/utils/spinner.cjs +108 -0
- package/dist/cjs/cli/utils/sql-generator.cjs +520 -0
- package/dist/cjs/cli/utils/sql-parser.cjs +999 -0
- package/dist/cjs/cli/utils/type-generator.cjs +2061 -0
- package/dist/cjs/condition/array-condition-builder.cjs +503 -0
- package/dist/cjs/condition/array-numeric-condition-builder.cjs +186 -0
- package/dist/cjs/condition/array-specialized-condition-builder.cjs +206 -0
- package/dist/cjs/condition/array-string-condition-builder.cjs +146 -0
- package/dist/cjs/condition/base-condition-builder.cjs +2 -0
- package/dist/cjs/condition/condition-collector.cjs +284 -0
- package/dist/cjs/condition/fulltext-condition-builder.cjs +61 -0
- package/dist/cjs/condition/geometric-condition-builder.cjs +208 -0
- package/dist/cjs/condition/index.cjs +25 -0
- package/dist/cjs/condition/jsonb-condition-builder.cjs +160 -0
- package/dist/cjs/condition/network-condition-builder.cjs +230 -0
- package/dist/cjs/condition/range-condition-builder.cjs +82 -0
- package/dist/cjs/config/config.cjs +190 -0
- package/dist/cjs/config/index.cjs +9 -0
- package/dist/cjs/constants/pg-values.cjs +68 -0
- package/dist/cjs/copy/copy-builder.cjs +316 -0
- package/dist/cjs/copy/index.cjs +6 -0
- package/dist/cjs/core/query-builder.cjs +440 -0
- package/dist/cjs/core/relq-client.cjs +1831 -0
- package/dist/cjs/core/typed-kuery-client.cjs +2 -0
- package/dist/cjs/count/count-builder.cjs +88 -0
- package/dist/cjs/count/index.cjs +5 -0
- package/dist/cjs/cte/cte-builder.cjs +89 -0
- package/dist/cjs/cte/index.cjs +5 -0
- package/dist/cjs/ddl/function.cjs +48 -0
- package/dist/cjs/ddl/index.cjs +7 -0
- package/dist/cjs/ddl/sql.cjs +54 -0
- package/dist/cjs/delete/delete-builder.cjs +135 -0
- package/dist/cjs/delete/index.cjs +5 -0
- package/dist/cjs/errors/relq-errors.cjs +329 -0
- package/dist/cjs/examples/fulltext-search-test.cjs +122 -0
- package/dist/cjs/explain/explain-builder.cjs +99 -0
- package/dist/cjs/explain/index.cjs +5 -0
- package/dist/cjs/function/create-function-builder.cjs +196 -0
- package/dist/cjs/function/index.cjs +6 -0
- package/dist/cjs/functions/advanced-functions.cjs +241 -0
- package/dist/cjs/functions/case-builder.cjs +66 -0
- package/dist/cjs/functions/geometric-functions.cjs +104 -0
- package/dist/cjs/functions/index.cjs +184 -0
- package/dist/cjs/functions/network-functions.cjs +86 -0
- package/dist/cjs/functions/sql-functions.cjs +431 -0
- package/dist/cjs/index.cjs +164 -0
- package/dist/cjs/indexing/create-index-builder.cjs +187 -0
- package/dist/cjs/indexing/drop-index-builder.cjs +89 -0
- package/dist/cjs/indexing/index-types.cjs +2 -0
- package/dist/cjs/indexing/index.cjs +8 -0
- package/dist/cjs/insert/conflict-builder.cjs +173 -0
- package/dist/cjs/insert/index.cjs +5 -0
- package/dist/cjs/insert/insert-builder.cjs +254 -0
- package/dist/cjs/introspect/index.cjs +229 -0
- package/dist/cjs/maintenance/index.cjs +6 -0
- package/dist/cjs/maintenance/vacuum-builder.cjs +166 -0
- package/dist/cjs/pubsub/index.cjs +7 -0
- package/dist/cjs/pubsub/listen-notify-builder.cjs +57 -0
- package/dist/cjs/pubsub/listener-connection.cjs +180 -0
- package/dist/cjs/raw/index.cjs +5 -0
- package/dist/cjs/raw/raw-query-builder.cjs +27 -0
- package/dist/cjs/schema/index.cjs +15 -0
- package/dist/cjs/schema/schema-builder.cjs +1167 -0
- package/dist/cjs/schema-builder.cjs +21 -0
- package/dist/cjs/schema-definition/column-types.cjs +829 -0
- package/dist/cjs/schema-definition/index.cjs +62 -0
- package/dist/cjs/schema-definition/introspection.cjs +620 -0
- package/dist/cjs/schema-definition/partitions.cjs +129 -0
- package/dist/cjs/schema-definition/pg-enum.cjs +76 -0
- package/dist/cjs/schema-definition/pg-function.cjs +91 -0
- package/dist/cjs/schema-definition/pg-sequence.cjs +56 -0
- package/dist/cjs/schema-definition/pg-trigger.cjs +108 -0
- package/dist/cjs/schema-definition/relations.cjs +98 -0
- package/dist/cjs/schema-definition/sql-expressions.cjs +202 -0
- package/dist/cjs/schema-definition/table-definition.cjs +636 -0
- package/dist/cjs/select/aggregate-builder.cjs +179 -0
- package/dist/cjs/select/index.cjs +5 -0
- package/dist/cjs/select/select-builder.cjs +233 -0
- package/dist/cjs/sequence/index.cjs +7 -0
- package/dist/cjs/sequence/sequence-builder.cjs +264 -0
- package/dist/cjs/table/alter-table-builder.cjs +146 -0
- package/dist/cjs/table/constraint-builder.cjs +102 -0
- package/dist/cjs/table/create-table-builder.cjs +248 -0
- package/dist/cjs/table/index.cjs +17 -0
- package/dist/cjs/table/partition-builder.cjs +131 -0
- package/dist/cjs/table/truncate-builder.cjs +70 -0
- package/dist/cjs/transaction/index.cjs +6 -0
- package/dist/cjs/transaction/transaction-builder.cjs +78 -0
- package/dist/cjs/trigger/create-trigger-builder.cjs +174 -0
- package/dist/cjs/trigger/index.cjs +6 -0
- package/dist/cjs/types/aggregate-types.cjs +2 -0
- package/dist/cjs/types/config-types.cjs +40 -0
- package/dist/cjs/types/inference-types.cjs +18 -0
- package/dist/cjs/types/pagination-types.cjs +7 -0
- package/dist/cjs/types/result-types.cjs +2 -0
- package/dist/cjs/types/schema-types.cjs +2 -0
- package/dist/cjs/types/subscription-types.cjs +2 -0
- package/dist/cjs/types.cjs +2 -0
- package/dist/cjs/update/array-update-builder.cjs +205 -0
- package/dist/cjs/update/index.cjs +13 -0
- package/dist/cjs/update/update-builder.cjs +195 -0
- package/dist/cjs/utils/case-converter.cjs +58 -0
- package/dist/cjs/utils/environment-detection.cjs +120 -0
- package/dist/cjs/utils/index.cjs +10 -0
- package/dist/cjs/utils/pool-defaults.cjs +106 -0
- package/dist/cjs/utils/type-coercion.cjs +118 -0
- package/dist/cjs/view/create-view-builder.cjs +180 -0
- package/dist/cjs/view/index.cjs +7 -0
- package/dist/cjs/window/index.cjs +5 -0
- package/dist/cjs/window/window-builder.cjs +80 -0
- package/dist/config.cjs +1 -0
- package/dist/config.d.ts +655 -0
- package/dist/config.js +1 -0
- package/dist/esm/cache/index.js +1 -0
- package/dist/esm/cache/query-cache.js +303 -0
- package/dist/esm/cli/commands/add.js +78 -0
- package/dist/esm/cli/commands/commit.js +109 -0
- package/dist/esm/cli/commands/diff.js +81 -0
- package/dist/esm/cli/commands/export.js +297 -0
- package/dist/esm/cli/commands/fetch.js +56 -0
- package/dist/esm/cli/commands/generate.js +206 -0
- package/dist/esm/cli/commands/history.js +129 -0
- package/dist/esm/cli/commands/import.js +488 -0
- package/dist/esm/cli/commands/init.js +401 -0
- package/dist/esm/cli/commands/introspect.js +106 -0
- package/dist/esm/cli/commands/log.js +59 -0
- package/dist/esm/cli/commands/migrate.js +131 -0
- package/dist/esm/cli/commands/pull.js +374 -0
- package/dist/esm/cli/commands/push.js +129 -0
- package/dist/esm/cli/commands/rollback.js +133 -0
- package/dist/esm/cli/commands/status.js +107 -0
- package/dist/esm/cli/commands/sync.js +76 -0
- package/dist/esm/cli/index.js +240 -0
- package/dist/esm/cli/utils/change-tracker.js +405 -0
- package/dist/esm/cli/utils/commit-manager.js +191 -0
- package/dist/esm/cli/utils/config-loader.js +86 -0
- package/dist/esm/cli/utils/env-loader.js +57 -0
- package/dist/esm/cli/utils/fast-introspect.js +362 -0
- package/dist/esm/cli/utils/git-utils.js +347 -0
- package/dist/esm/cli/utils/migration-generator.js +263 -0
- package/dist/esm/cli/utils/relqignore.js +74 -0
- package/dist/esm/cli/utils/repo-manager.js +444 -0
- package/dist/esm/cli/utils/schema-comparator.js +307 -0
- package/dist/esm/cli/utils/schema-diff.js +276 -0
- package/dist/esm/cli/utils/schema-hash.js +69 -0
- package/dist/esm/cli/utils/schema-introspect.js +418 -0
- package/dist/esm/cli/utils/snapshot-manager.js +179 -0
- package/dist/esm/cli/utils/spinner.js +101 -0
- package/dist/esm/cli/utils/sql-generator.js +504 -0
- package/dist/esm/cli/utils/sql-parser.js +992 -0
- package/dist/esm/cli/utils/type-generator.js +2058 -0
- package/dist/esm/condition/array-condition-builder.js +495 -0
- package/dist/esm/condition/array-numeric-condition-builder.js +182 -0
- package/dist/esm/condition/array-specialized-condition-builder.js +200 -0
- package/dist/esm/condition/array-string-condition-builder.js +142 -0
- package/dist/esm/condition/base-condition-builder.js +1 -0
- package/dist/esm/condition/condition-collector.js +275 -0
- package/dist/esm/condition/fulltext-condition-builder.js +53 -0
- package/dist/esm/condition/geometric-condition-builder.js +200 -0
- package/dist/esm/condition/index.js +7 -0
- package/dist/esm/condition/jsonb-condition-builder.js +152 -0
- package/dist/esm/condition/network-condition-builder.js +222 -0
- package/dist/esm/condition/range-condition-builder.js +74 -0
- package/dist/esm/config/config.js +150 -0
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/constants/pg-values.js +63 -0
- package/dist/esm/copy/copy-builder.js +308 -0
- package/dist/esm/copy/index.js +1 -0
- package/dist/esm/core/query-builder.js +426 -0
- package/dist/esm/core/relq-client.js +1791 -0
- package/dist/esm/core/typed-kuery-client.js +1 -0
- package/dist/esm/count/count-builder.js +81 -0
- package/dist/esm/count/index.js +1 -0
- package/dist/esm/cte/cte-builder.js +82 -0
- package/dist/esm/cte/index.js +1 -0
- package/dist/esm/ddl/function.js +45 -0
- package/dist/esm/ddl/index.js +2 -0
- package/dist/esm/ddl/sql.js +51 -0
- package/dist/esm/delete/delete-builder.js +128 -0
- package/dist/esm/delete/index.js +1 -0
- package/dist/esm/errors/relq-errors.js +310 -0
- package/dist/esm/examples/fulltext-search-test.js +117 -0
- package/dist/esm/explain/explain-builder.js +95 -0
- package/dist/esm/explain/index.js +1 -0
- package/dist/esm/function/create-function-builder.js +188 -0
- package/dist/esm/function/index.js +1 -0
- package/dist/esm/functions/advanced-functions.js +231 -0
- package/dist/esm/functions/case-builder.js +58 -0
- package/dist/esm/functions/geometric-functions.js +97 -0
- package/dist/esm/functions/index.js +171 -0
- package/dist/esm/functions/network-functions.js +79 -0
- package/dist/esm/functions/sql-functions.js +421 -0
- package/dist/esm/index.js +34 -0
- package/dist/esm/indexing/create-index-builder.js +180 -0
- package/dist/esm/indexing/drop-index-builder.js +81 -0
- package/dist/esm/indexing/index-types.js +1 -0
- package/dist/esm/indexing/index.js +2 -0
- package/dist/esm/insert/conflict-builder.js +162 -0
- package/dist/esm/insert/index.js +1 -0
- package/dist/esm/insert/insert-builder.js +247 -0
- package/dist/esm/introspect/index.js +224 -0
- package/dist/esm/maintenance/index.js +1 -0
- package/dist/esm/maintenance/vacuum-builder.js +158 -0
- package/dist/esm/pubsub/index.js +1 -0
- package/dist/esm/pubsub/listen-notify-builder.js +48 -0
- package/dist/esm/pubsub/listener-connection.js +173 -0
- package/dist/esm/raw/index.js +1 -0
- package/dist/esm/raw/raw-query-builder.js +20 -0
- package/dist/esm/schema/index.js +1 -0
- package/dist/esm/schema/schema-builder.js +1150 -0
- package/dist/esm/schema-builder.js +2 -0
- package/dist/esm/schema-definition/column-types.js +738 -0
- package/dist/esm/schema-definition/index.js +10 -0
- package/dist/esm/schema-definition/introspection.js +614 -0
- package/dist/esm/schema-definition/partitions.js +123 -0
- package/dist/esm/schema-definition/pg-enum.js +70 -0
- package/dist/esm/schema-definition/pg-function.js +85 -0
- package/dist/esm/schema-definition/pg-sequence.js +50 -0
- package/dist/esm/schema-definition/pg-trigger.js +102 -0
- package/dist/esm/schema-definition/relations.js +90 -0
- package/dist/esm/schema-definition/sql-expressions.js +193 -0
- package/dist/esm/schema-definition/table-definition.js +630 -0
- package/dist/esm/select/aggregate-builder.js +172 -0
- package/dist/esm/select/index.js +1 -0
- package/dist/esm/select/select-builder.js +226 -0
- package/dist/esm/sequence/index.js +1 -0
- package/dist/esm/sequence/sequence-builder.js +255 -0
- package/dist/esm/table/alter-table-builder.js +138 -0
- package/dist/esm/table/constraint-builder.js +95 -0
- package/dist/esm/table/create-table-builder.js +241 -0
- package/dist/esm/table/index.js +5 -0
- package/dist/esm/table/partition-builder.js +121 -0
- package/dist/esm/table/truncate-builder.js +63 -0
- package/dist/esm/transaction/index.js +1 -0
- package/dist/esm/transaction/transaction-builder.js +70 -0
- package/dist/esm/trigger/create-trigger-builder.js +166 -0
- package/dist/esm/trigger/index.js +1 -0
- package/dist/esm/types/aggregate-types.js +1 -0
- package/dist/esm/types/config-types.js +36 -0
- package/dist/esm/types/inference-types.js +12 -0
- package/dist/esm/types/pagination-types.js +4 -0
- package/dist/esm/types/result-types.js +1 -0
- package/dist/esm/types/schema-types.js +1 -0
- package/dist/esm/types/subscription-types.js +1 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/update/array-update-builder.js +192 -0
- package/dist/esm/update/index.js +2 -0
- package/dist/esm/update/update-builder.js +188 -0
- package/dist/esm/utils/case-converter.js +55 -0
- package/dist/esm/utils/environment-detection.js +113 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/pool-defaults.js +100 -0
- package/dist/esm/utils/type-coercion.js +110 -0
- package/dist/esm/view/create-view-builder.js +171 -0
- package/dist/esm/view/index.js +1 -0
- package/dist/esm/window/index.js +1 -0
- package/dist/esm/window/window-builder.js +73 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +10341 -0
- package/dist/index.js +1 -0
- package/dist/schema-builder.cjs +1 -0
- package/dist/schema-builder.d.ts +2272 -0
- package/dist/schema-builder.js +1 -0
- package/package.json +55 -0
package/dist/bin/relq.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTableCache = exports.withCache = exports.createQueryCacheMiddleware = exports.CacheKeyBuilder = exports.QueryCache = void 0;
|
|
4
|
+
var query_cache_1 = require("./query-cache.cjs");
|
|
5
|
+
Object.defineProperty(exports, "QueryCache", { enumerable: true, get: function () { return query_cache_1.QueryCache; } });
|
|
6
|
+
Object.defineProperty(exports, "CacheKeyBuilder", { enumerable: true, get: function () { return query_cache_1.CacheKeyBuilder; } });
|
|
7
|
+
Object.defineProperty(exports, "createQueryCacheMiddleware", { enumerable: true, get: function () { return query_cache_1.createQueryCacheMiddleware; } });
|
|
8
|
+
Object.defineProperty(exports, "withCache", { enumerable: true, get: function () { return query_cache_1.withCache; } });
|
|
9
|
+
Object.defineProperty(exports, "createTableCache", { enumerable: true, get: function () { return query_cache_1.createTableCache; } });
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheKeyBuilder = exports.QueryCache = void 0;
|
|
4
|
+
exports.createQueryCacheMiddleware = createQueryCacheMiddleware;
|
|
5
|
+
exports.withCache = withCache;
|
|
6
|
+
exports.createTableCache = createTableCache;
|
|
7
|
+
class QueryCache {
|
|
8
|
+
cache = new Map();
|
|
9
|
+
options;
|
|
10
|
+
stats = { hits: 0, misses: 0, evictions: 0 };
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = {
|
|
13
|
+
strategy: options.strategy ?? 'lru',
|
|
14
|
+
maxSize: options.maxSize ?? 100 * 1024 * 1024,
|
|
15
|
+
maxItems: options.maxItems ?? 1000,
|
|
16
|
+
ttl: options.ttl ?? 60000,
|
|
17
|
+
onEvict: options.onEvict ?? (() => { }),
|
|
18
|
+
keyGenerator: options.keyGenerator ?? this.defaultKeyGenerator
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
defaultKeyGenerator(query, params) {
|
|
22
|
+
const normalized = query.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
23
|
+
const paramStr = params ? JSON.stringify(params) : '';
|
|
24
|
+
return `${normalized}::${paramStr}`;
|
|
25
|
+
}
|
|
26
|
+
generateKey(query, params) {
|
|
27
|
+
return this.options.keyGenerator(query, params);
|
|
28
|
+
}
|
|
29
|
+
get(key) {
|
|
30
|
+
const entry = this.cache.get(key);
|
|
31
|
+
if (!entry) {
|
|
32
|
+
this.stats.misses++;
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
if (this.options.strategy === 'ttl' || this.options.strategy === 'lru') {
|
|
36
|
+
const now = Date.now();
|
|
37
|
+
if (this.options.ttl > 0 && now - entry.createdAt > this.options.ttl) {
|
|
38
|
+
this.delete(key);
|
|
39
|
+
this.stats.misses++;
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
entry.accessedAt = Date.now();
|
|
44
|
+
entry.accessCount++;
|
|
45
|
+
this.stats.hits++;
|
|
46
|
+
if (this.options.strategy === 'lru') {
|
|
47
|
+
this.cache.delete(key);
|
|
48
|
+
this.cache.set(key, entry);
|
|
49
|
+
}
|
|
50
|
+
return entry.value;
|
|
51
|
+
}
|
|
52
|
+
set(key, value) {
|
|
53
|
+
const size = this.estimateSize(value);
|
|
54
|
+
this.evictIfNeeded(size);
|
|
55
|
+
const entry = {
|
|
56
|
+
value,
|
|
57
|
+
createdAt: Date.now(),
|
|
58
|
+
accessedAt: Date.now(),
|
|
59
|
+
accessCount: 1,
|
|
60
|
+
size
|
|
61
|
+
};
|
|
62
|
+
this.cache.set(key, entry);
|
|
63
|
+
}
|
|
64
|
+
has(key) {
|
|
65
|
+
const entry = this.cache.get(key);
|
|
66
|
+
if (!entry)
|
|
67
|
+
return false;
|
|
68
|
+
if (this.options.strategy === 'ttl' || this.options.strategy === 'lru') {
|
|
69
|
+
const now = Date.now();
|
|
70
|
+
if (this.options.ttl > 0 && now - entry.createdAt > this.options.ttl) {
|
|
71
|
+
this.delete(key);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
delete(key) {
|
|
78
|
+
const entry = this.cache.get(key);
|
|
79
|
+
if (entry) {
|
|
80
|
+
this.options.onEvict(key, entry);
|
|
81
|
+
this.stats.evictions++;
|
|
82
|
+
return this.cache.delete(key);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
clear() {
|
|
87
|
+
this.cache.forEach((entry, key) => {
|
|
88
|
+
this.options.onEvict(key, entry);
|
|
89
|
+
});
|
|
90
|
+
this.cache.clear();
|
|
91
|
+
this.stats.evictions = 0;
|
|
92
|
+
}
|
|
93
|
+
invalidateByPattern(pattern) {
|
|
94
|
+
let count = 0;
|
|
95
|
+
const keysToDelete = [];
|
|
96
|
+
this.cache.forEach((_, key) => {
|
|
97
|
+
if (pattern.test(key)) {
|
|
98
|
+
keysToDelete.push(key);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
keysToDelete.forEach(key => {
|
|
102
|
+
this.delete(key);
|
|
103
|
+
count++;
|
|
104
|
+
});
|
|
105
|
+
return count;
|
|
106
|
+
}
|
|
107
|
+
invalidateByTable(tableName) {
|
|
108
|
+
const pattern = new RegExp(`\\b${tableName.toLowerCase()}\\b`, 'i');
|
|
109
|
+
return this.invalidateByPattern(pattern);
|
|
110
|
+
}
|
|
111
|
+
getStats() {
|
|
112
|
+
const totalSize = Array.from(this.cache.values()).reduce((sum, e) => sum + e.size, 0);
|
|
113
|
+
const total = this.stats.hits + this.stats.misses;
|
|
114
|
+
return {
|
|
115
|
+
hits: this.stats.hits,
|
|
116
|
+
misses: this.stats.misses,
|
|
117
|
+
evictions: this.stats.evictions,
|
|
118
|
+
size: totalSize,
|
|
119
|
+
itemCount: this.cache.size,
|
|
120
|
+
hitRate: total > 0 ? this.stats.hits / total : 0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
resetStats() {
|
|
124
|
+
this.stats = { hits: 0, misses: 0, evictions: 0 };
|
|
125
|
+
}
|
|
126
|
+
keys() {
|
|
127
|
+
return Array.from(this.cache.keys());
|
|
128
|
+
}
|
|
129
|
+
values() {
|
|
130
|
+
return Array.from(this.cache.values()).map(e => e.value);
|
|
131
|
+
}
|
|
132
|
+
entries() {
|
|
133
|
+
return Array.from(this.cache.entries());
|
|
134
|
+
}
|
|
135
|
+
evictIfNeeded(incomingSize) {
|
|
136
|
+
if (this.options.strategy === 'none')
|
|
137
|
+
return;
|
|
138
|
+
while (this.cache.size >= this.options.maxItems) {
|
|
139
|
+
this.evictOne();
|
|
140
|
+
}
|
|
141
|
+
if (this.options.strategy === 'size') {
|
|
142
|
+
const currentSize = Array.from(this.cache.values()).reduce((sum, e) => sum + e.size, 0);
|
|
143
|
+
while (currentSize + incomingSize > this.options.maxSize && this.cache.size > 0) {
|
|
144
|
+
this.evictOne();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
evictOne() {
|
|
149
|
+
if (this.cache.size === 0)
|
|
150
|
+
return;
|
|
151
|
+
let keyToEvict;
|
|
152
|
+
let entryToEvict;
|
|
153
|
+
switch (this.options.strategy) {
|
|
154
|
+
case 'lru':
|
|
155
|
+
keyToEvict = this.cache.keys().next().value;
|
|
156
|
+
break;
|
|
157
|
+
case 'ttl':
|
|
158
|
+
let oldestTime = Infinity;
|
|
159
|
+
this.cache.forEach((entry, key) => {
|
|
160
|
+
if (entry.createdAt < oldestTime) {
|
|
161
|
+
oldestTime = entry.createdAt;
|
|
162
|
+
keyToEvict = key;
|
|
163
|
+
entryToEvict = entry;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
case 'size':
|
|
168
|
+
let largestSize = -1;
|
|
169
|
+
this.cache.forEach((entry, key) => {
|
|
170
|
+
if (entry.size > largestSize) {
|
|
171
|
+
largestSize = entry.size;
|
|
172
|
+
keyToEvict = key;
|
|
173
|
+
entryToEvict = entry;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
break;
|
|
177
|
+
default:
|
|
178
|
+
keyToEvict = this.cache.keys().next().value;
|
|
179
|
+
}
|
|
180
|
+
if (keyToEvict) {
|
|
181
|
+
this.delete(keyToEvict);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
estimateSize(value) {
|
|
185
|
+
if (value === null || value === undefined)
|
|
186
|
+
return 8;
|
|
187
|
+
if (typeof value === 'boolean')
|
|
188
|
+
return 4;
|
|
189
|
+
if (typeof value === 'number')
|
|
190
|
+
return 8;
|
|
191
|
+
if (typeof value === 'string')
|
|
192
|
+
return value.length * 2;
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
return value.reduce((sum, item) => sum + this.estimateSize(item), 16);
|
|
195
|
+
}
|
|
196
|
+
if (typeof value === 'object') {
|
|
197
|
+
return JSON.stringify(value).length * 2;
|
|
198
|
+
}
|
|
199
|
+
return 64;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
exports.QueryCache = QueryCache;
|
|
203
|
+
class CacheKeyBuilder {
|
|
204
|
+
parts = [];
|
|
205
|
+
table(name) {
|
|
206
|
+
this.parts.push(`t:${name}`);
|
|
207
|
+
return this;
|
|
208
|
+
}
|
|
209
|
+
operation(op) {
|
|
210
|
+
this.parts.push(`o:${op}`);
|
|
211
|
+
return this;
|
|
212
|
+
}
|
|
213
|
+
columns(...cols) {
|
|
214
|
+
if (cols.length > 0) {
|
|
215
|
+
this.parts.push(`c:${cols.sort().join(',')}`);
|
|
216
|
+
}
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
where(condition) {
|
|
220
|
+
this.parts.push(`w:${condition}`);
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
orderBy(order) {
|
|
224
|
+
this.parts.push(`ob:${order}`);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
limit(n) {
|
|
228
|
+
this.parts.push(`l:${n}`);
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
offset(n) {
|
|
232
|
+
this.parts.push(`of:${n}`);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
params(...values) {
|
|
236
|
+
if (values.length > 0) {
|
|
237
|
+
this.parts.push(`p:${JSON.stringify(values)}`);
|
|
238
|
+
}
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
custom(key, value) {
|
|
242
|
+
this.parts.push(`${key}:${value}`);
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
build() {
|
|
246
|
+
return this.parts.join('|');
|
|
247
|
+
}
|
|
248
|
+
static from(query, params) {
|
|
249
|
+
const normalized = query.replace(/\s+/g, ' ').trim();
|
|
250
|
+
const hash = this.simpleHash(normalized + (params ? JSON.stringify(params) : ''));
|
|
251
|
+
return `q:${hash}`;
|
|
252
|
+
}
|
|
253
|
+
static simpleHash(str) {
|
|
254
|
+
let hash = 0;
|
|
255
|
+
for (let i = 0; i < str.length; i++) {
|
|
256
|
+
const char = str.charCodeAt(i);
|
|
257
|
+
hash = ((hash << 5) - hash) + char;
|
|
258
|
+
hash = hash & hash;
|
|
259
|
+
}
|
|
260
|
+
return Math.abs(hash).toString(36);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
exports.CacheKeyBuilder = CacheKeyBuilder;
|
|
264
|
+
function createQueryCacheMiddleware(options) {
|
|
265
|
+
const { cache, keyPrefix = '', invalidateOn = [] } = options;
|
|
266
|
+
return {
|
|
267
|
+
beforeQuery: (query, params) => {
|
|
268
|
+
const key = keyPrefix + CacheKeyBuilder.from(query, params);
|
|
269
|
+
const cached = cache.get(key);
|
|
270
|
+
if (cached !== undefined) {
|
|
271
|
+
return { cached: true, value: cached, key };
|
|
272
|
+
}
|
|
273
|
+
return { cached: false, key };
|
|
274
|
+
},
|
|
275
|
+
afterQuery: (key, result) => {
|
|
276
|
+
cache.set(key, result);
|
|
277
|
+
},
|
|
278
|
+
afterMutation: (tableName) => {
|
|
279
|
+
cache.invalidateByTable(tableName);
|
|
280
|
+
invalidateOn.forEach(pattern => {
|
|
281
|
+
if (pattern.includes(tableName)) {
|
|
282
|
+
cache.invalidateByPattern(new RegExp(pattern, 'i'));
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
function withCache(cache, key, fn, ttl) {
|
|
289
|
+
const cached = cache.get(key);
|
|
290
|
+
if (cached !== undefined) {
|
|
291
|
+
return cached;
|
|
292
|
+
}
|
|
293
|
+
const result = fn();
|
|
294
|
+
if (result instanceof Promise) {
|
|
295
|
+
return result.then(value => {
|
|
296
|
+
cache.set(key, value);
|
|
297
|
+
return value;
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
cache.set(key, result);
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
function createTableCache(tableName, options = {}) {
|
|
304
|
+
const cache = new QueryCache({
|
|
305
|
+
...options,
|
|
306
|
+
keyGenerator: (query, params) => {
|
|
307
|
+
return `${tableName}::${query.replace(/\s+/g, ' ').trim()}::${params ? JSON.stringify(params) : ''}`;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
return Object.assign(cache, { table: tableName });
|
|
311
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addCommand = addCommand;
|
|
4
|
+
exports.getRelatedChanges = getRelatedChanges;
|
|
5
|
+
const spinner_1 = require("../utils/spinner.cjs");
|
|
6
|
+
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
7
|
+
const change_tracker_1 = require("../utils/change-tracker.cjs");
|
|
8
|
+
async function addCommand(context) {
|
|
9
|
+
const { args } = context;
|
|
10
|
+
const projectRoot = process.cwd();
|
|
11
|
+
console.log('');
|
|
12
|
+
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
13
|
+
console.log(`${spinner_1.colors.red('error:')} relq not initialized`);
|
|
14
|
+
console.log('');
|
|
15
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq init')} ${spinner_1.colors.muted('first.')}`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const unstaged = (0, repo_manager_1.getUnstagedChanges)(projectRoot);
|
|
19
|
+
const staged = (0, repo_manager_1.getStagedChanges)(projectRoot);
|
|
20
|
+
if (unstaged.length === 0) {
|
|
21
|
+
if (staged.length > 0) {
|
|
22
|
+
console.log(`${spinner_1.colors.green('✓')} All changes are already staged`);
|
|
23
|
+
console.log(`${spinner_1.colors.muted(`${staged.length} change(s) ready to commit`)}`);
|
|
24
|
+
console.log('');
|
|
25
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq commit -m "message"')} ${spinner_1.colors.muted('to commit.')}`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
console.log(`${spinner_1.colors.green('✓')} No changes to stage`);
|
|
29
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq pull')} ${spinner_1.colors.muted('or')} ${spinner_1.colors.cyan('relq import')} ${spinner_1.colors.muted('to detect changes.')}`);
|
|
30
|
+
}
|
|
31
|
+
console.log('');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const patterns = args.length > 0 ? args : ['.'];
|
|
35
|
+
const addAll = patterns.includes('.') || patterns.includes('*');
|
|
36
|
+
console.log(`${spinner_1.colors.cyan('Unstaged changes:')} ${unstaged.length}`);
|
|
37
|
+
console.log('');
|
|
38
|
+
for (const change of unstaged) {
|
|
39
|
+
const display = (0, change_tracker_1.getChangeDisplayName)(change);
|
|
40
|
+
const color = change.type === 'CREATE' ? spinner_1.colors.green :
|
|
41
|
+
change.type === 'DROP' ? spinner_1.colors.red :
|
|
42
|
+
spinner_1.colors.yellow;
|
|
43
|
+
console.log(` ${color(display)}`);
|
|
44
|
+
}
|
|
45
|
+
console.log('');
|
|
46
|
+
const stagedNow = (0, repo_manager_1.stageChanges)(patterns, projectRoot);
|
|
47
|
+
if (stagedNow.length === 0) {
|
|
48
|
+
console.log(`${spinner_1.colors.yellow('⚠')} No changes matched the pattern(s): ${patterns.join(', ')}`);
|
|
49
|
+
console.log('');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.log(`${spinner_1.colors.green('✓')} Staged ${stagedNow.length} change(s):`);
|
|
53
|
+
console.log('');
|
|
54
|
+
for (const change of stagedNow) {
|
|
55
|
+
const display = (0, change_tracker_1.getChangeDisplayName)(change);
|
|
56
|
+
const color = change.type === 'CREATE' ? spinner_1.colors.green :
|
|
57
|
+
change.type === 'DROP' ? spinner_1.colors.red :
|
|
58
|
+
spinner_1.colors.yellow;
|
|
59
|
+
console.log(` ${color(display)}`);
|
|
60
|
+
}
|
|
61
|
+
console.log('');
|
|
62
|
+
const remainingUnstaged = (0, repo_manager_1.getUnstagedChanges)(projectRoot);
|
|
63
|
+
if (remainingUnstaged.length > 0) {
|
|
64
|
+
console.log(`${spinner_1.colors.muted(`${remainingUnstaged.length} change(s) still unstaged`)}`);
|
|
65
|
+
console.log('');
|
|
66
|
+
}
|
|
67
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq commit -m "message"')} ${spinner_1.colors.muted('to commit.')}`);
|
|
68
|
+
console.log('');
|
|
69
|
+
}
|
|
70
|
+
function getRelatedChanges(tableName, changes) {
|
|
71
|
+
return changes.filter(c => {
|
|
72
|
+
if (c.objectName === tableName)
|
|
73
|
+
return true;
|
|
74
|
+
if (c.parentName === tableName)
|
|
75
|
+
return true;
|
|
76
|
+
const data = c.after;
|
|
77
|
+
if (data?.tableName === tableName)
|
|
78
|
+
return true;
|
|
79
|
+
return false;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
exports.default = addCommand;
|
|
@@ -0,0 +1,145 @@
|
|
|
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.commitCommand = commitCommand;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const spinner_1 = require("../utils/spinner.cjs");
|
|
39
|
+
const repo_manager_1 = require("../utils/repo-manager.cjs");
|
|
40
|
+
const change_tracker_1 = require("../utils/change-tracker.cjs");
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
async function commitCommand(context) {
|
|
44
|
+
const { config, flags, args } = context;
|
|
45
|
+
const projectRoot = process.cwd();
|
|
46
|
+
const author = config?.author || 'Developer <dev@example.com>';
|
|
47
|
+
console.log('');
|
|
48
|
+
if (!(0, repo_manager_1.isInitialized)(projectRoot)) {
|
|
49
|
+
console.log(`${spinner_1.colors.red('error:')} relq not initialized`);
|
|
50
|
+
console.log('');
|
|
51
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq init')} ${spinner_1.colors.muted('first.')}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const staged = (0, repo_manager_1.getStagedChanges)(projectRoot);
|
|
55
|
+
if (staged.length === 0) {
|
|
56
|
+
console.log(`${spinner_1.colors.yellow('Nothing to commit')}`);
|
|
57
|
+
console.log('');
|
|
58
|
+
const unstaged = (0, repo_manager_1.getUnstagedChanges)(projectRoot);
|
|
59
|
+
if (unstaged.length > 0) {
|
|
60
|
+
console.log(`${spinner_1.colors.muted(`${unstaged.length} unstaged change(s).`)}`);
|
|
61
|
+
console.log(`${spinner_1.colors.muted('Use')} ${spinner_1.colors.cyan('relq add .')} ${spinner_1.colors.muted('to stage all changes.')}`);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log(`${spinner_1.colors.muted('Use')} ${spinner_1.colors.cyan('relq add <table>')} ${spinner_1.colors.muted('to stage changes.')}`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
let message = flags['m'] || flags['message'];
|
|
69
|
+
if (!message) {
|
|
70
|
+
if (args.length > 0) {
|
|
71
|
+
message = args.join(' ');
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log(`${spinner_1.colors.red('error:')} commit message required`);
|
|
75
|
+
console.log('');
|
|
76
|
+
console.log(`${spinner_1.colors.muted('Usage:')} relq commit -m "message"`);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const sortedChanges = (0, change_tracker_1.sortChangesByDependency)(staged);
|
|
81
|
+
const sql = (0, change_tracker_1.generateCombinedSQL)(sortedChanges);
|
|
82
|
+
const creates = staged.filter(c => c.type === 'CREATE').length;
|
|
83
|
+
const alters = staged.filter(c => c.type === 'ALTER').length;
|
|
84
|
+
const drops = staged.filter(c => c.type === 'DROP').length;
|
|
85
|
+
const parentHash = (0, repo_manager_1.getHead)(projectRoot);
|
|
86
|
+
const hashInput = JSON.stringify({
|
|
87
|
+
changes: staged.map(c => c.id),
|
|
88
|
+
message,
|
|
89
|
+
timestamp: new Date().toISOString(),
|
|
90
|
+
parent: parentHash,
|
|
91
|
+
});
|
|
92
|
+
const hash = crypto.createHash('sha1').update(hashInput).digest('hex');
|
|
93
|
+
const commit = {
|
|
94
|
+
hash,
|
|
95
|
+
parentHash,
|
|
96
|
+
author,
|
|
97
|
+
message,
|
|
98
|
+
timestamp: new Date().toISOString(),
|
|
99
|
+
changes: sortedChanges,
|
|
100
|
+
sql,
|
|
101
|
+
snapshotHash: hash.substring(0, 12),
|
|
102
|
+
stats: {
|
|
103
|
+
creates,
|
|
104
|
+
alters,
|
|
105
|
+
drops,
|
|
106
|
+
total: staged.length,
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
const commitsDir = path.join(projectRoot, '.relq', 'commits');
|
|
110
|
+
if (!fs.existsSync(commitsDir)) {
|
|
111
|
+
fs.mkdirSync(commitsDir, { recursive: true });
|
|
112
|
+
}
|
|
113
|
+
fs.writeFileSync(path.join(commitsDir, `${hash}.json`), JSON.stringify(commit, null, 2), 'utf-8');
|
|
114
|
+
fs.writeFileSync(path.join(projectRoot, '.relq', 'HEAD'), hash, 'utf-8');
|
|
115
|
+
const workingPath = path.join(projectRoot, '.relq', 'working.json');
|
|
116
|
+
const unstaged = (0, repo_manager_1.getUnstagedChanges)(projectRoot);
|
|
117
|
+
if (unstaged.length > 0) {
|
|
118
|
+
fs.writeFileSync(workingPath, JSON.stringify({
|
|
119
|
+
timestamp: new Date().toISOString(),
|
|
120
|
+
staged: [],
|
|
121
|
+
unstaged,
|
|
122
|
+
}, null, 2), 'utf-8');
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
if (fs.existsSync(workingPath)) {
|
|
126
|
+
fs.unlinkSync(workingPath);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
console.log(`${spinner_1.colors.yellow(`[${(0, repo_manager_1.shortHash)(hash)}]`)} ${message}`);
|
|
130
|
+
console.log('');
|
|
131
|
+
if (creates > 0) {
|
|
132
|
+
console.log(` ${spinner_1.colors.green(`${creates} created`)}`);
|
|
133
|
+
}
|
|
134
|
+
if (alters > 0) {
|
|
135
|
+
console.log(` ${spinner_1.colors.yellow(`${alters} altered`)}`);
|
|
136
|
+
}
|
|
137
|
+
if (drops > 0) {
|
|
138
|
+
console.log(` ${spinner_1.colors.red(`${drops} dropped`)}`);
|
|
139
|
+
}
|
|
140
|
+
console.log('');
|
|
141
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq push')} ${spinner_1.colors.muted('to apply changes to database.')}`);
|
|
142
|
+
console.log(`${spinner_1.colors.muted('Run')} ${spinner_1.colors.cyan('relq export')} ${spinner_1.colors.muted('to export as SQL file.')}`);
|
|
143
|
+
console.log('');
|
|
144
|
+
}
|
|
145
|
+
exports.default = commitCommand;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.diffCommand = diffCommand;
|
|
4
|
+
const config_loader_1 = require("../utils/config-loader.cjs");
|
|
5
|
+
const schema_introspect_1 = require("../utils/schema-introspect.cjs");
|
|
6
|
+
const snapshot_manager_1 = require("../utils/snapshot-manager.cjs");
|
|
7
|
+
const schema_diff_1 = require("../utils/schema-diff.cjs");
|
|
8
|
+
const schema_hash_1 = require("../utils/schema-hash.cjs");
|
|
9
|
+
const schema_diff_2 = require("../utils/schema-diff.cjs");
|
|
10
|
+
const migration_generator_1 = require("../utils/migration-generator.cjs");
|
|
11
|
+
const env_loader_1 = require("../utils/env-loader.cjs");
|
|
12
|
+
const colors = {
|
|
13
|
+
reset: '\x1b[0m',
|
|
14
|
+
bold: '\x1b[1m',
|
|
15
|
+
dim: '\x1b[2m',
|
|
16
|
+
red: '\x1b[31m',
|
|
17
|
+
green: '\x1b[32m',
|
|
18
|
+
yellow: '\x1b[33m',
|
|
19
|
+
blue: '\x1b[34m',
|
|
20
|
+
cyan: '\x1b[36m',
|
|
21
|
+
magenta: '\x1b[35m',
|
|
22
|
+
};
|
|
23
|
+
function filterDiff(diff, ignorePatterns) {
|
|
24
|
+
const patterns = ignorePatterns.map(p => {
|
|
25
|
+
const regexStr = p.replace(/\*/g, '.*').replace(/\?/g, '.');
|
|
26
|
+
return new RegExp(`^${regexStr}$`, 'i');
|
|
27
|
+
});
|
|
28
|
+
const matchesPattern = (name) => patterns.some(p => p.test(name));
|
|
29
|
+
const tables = diff.tables.filter(t => !matchesPattern(t.name));
|
|
30
|
+
const hasChanges = tables.length > 0 || diff.extensions.length > 0;
|
|
31
|
+
return {
|
|
32
|
+
...diff,
|
|
33
|
+
tables,
|
|
34
|
+
hasChanges,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async function diffCommand(context) {
|
|
38
|
+
const { config, flags } = context;
|
|
39
|
+
if (!config) {
|
|
40
|
+
console.error('Error: No configuration found.');
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
(0, config_loader_1.requireValidConfig)(config);
|
|
44
|
+
const connection = config.connection;
|
|
45
|
+
const snapshotPath = config.sync?.snapshot || '.relq/snapshot.json';
|
|
46
|
+
const ignorePatterns = config.sync?.ignore || ['_relq_*'];
|
|
47
|
+
const showSQL = flags['sql'] === true;
|
|
48
|
+
console.log(`${colors.bold}Comparing:${colors.reset} local snapshot ↔ ${(0, env_loader_1.getConnectionDescription)(connection)}`);
|
|
49
|
+
console.log('');
|
|
50
|
+
try {
|
|
51
|
+
const dbSchema = await (0, schema_introspect_1.introspectDatabase)(connection);
|
|
52
|
+
const snapshot = (0, snapshot_manager_1.loadSnapshot)(snapshotPath);
|
|
53
|
+
if (!snapshot) {
|
|
54
|
+
console.log(`${colors.yellow}No snapshot found.${colors.reset}`);
|
|
55
|
+
console.log(`Run "${colors.cyan}relq pull${colors.reset}" to create initial snapshot.`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const localSchema = (0, snapshot_manager_1.snapshotToDatabaseSchema)(snapshot);
|
|
59
|
+
const normalizedLocal = (0, schema_hash_1.normalizeSchema)(localSchema);
|
|
60
|
+
const normalizedDb = (0, schema_hash_1.normalizeSchema)(dbSchema);
|
|
61
|
+
const diff = (0, schema_diff_2.diffSchemas)(normalizedLocal, normalizedDb);
|
|
62
|
+
const filteredDiff = filterDiff(diff, ignorePatterns);
|
|
63
|
+
if (!filteredDiff.hasChanges) {
|
|
64
|
+
console.log(`${colors.green}No differences.${colors.reset}`);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
console.log((0, schema_diff_1.formatDiff)(filteredDiff));
|
|
68
|
+
if (showSQL) {
|
|
69
|
+
console.log('');
|
|
70
|
+
console.log(`${colors.bold}Generated SQL:${colors.reset}`);
|
|
71
|
+
console.log('');
|
|
72
|
+
const { up } = (0, migration_generator_1.generateMigration)(filteredDiff, { includeDown: false });
|
|
73
|
+
for (const sql of up) {
|
|
74
|
+
console.log(`${colors.cyan}${sql}${colors.reset}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
console.log('');
|
|
78
|
+
console.log(`${colors.dim}Use "relq diff --sql" to see generated SQL statements.${colors.reset}`);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('Error:', error instanceof Error ? error.message : error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|