realitydb 1.8.0 → 1.9.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/dist/index.js +495 -107
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -20958,7 +20958,7 @@ var require_pool_connection = __commonJS({
|
|
|
20958
20958
|
var require_make_done_cb = __commonJS({
|
|
20959
20959
|
"../../node_modules/.pnpm/mysql2@3.19.1_@types+node@25.3.5/node_modules/mysql2/lib/promise/make_done_cb.js"(exports2, module2) {
|
|
20960
20960
|
"use strict";
|
|
20961
|
-
function makeDoneCb(
|
|
20961
|
+
function makeDoneCb(resolve14, reject, localErr) {
|
|
20962
20962
|
return function(err, rows, fields) {
|
|
20963
20963
|
if (err) {
|
|
20964
20964
|
localErr.message = err.message;
|
|
@@ -20969,7 +20969,7 @@ var require_make_done_cb = __commonJS({
|
|
|
20969
20969
|
localErr.sqlMessage = err.sqlMessage;
|
|
20970
20970
|
reject(localErr);
|
|
20971
20971
|
} else {
|
|
20972
|
-
|
|
20972
|
+
resolve14([rows, fields]);
|
|
20973
20973
|
}
|
|
20974
20974
|
};
|
|
20975
20975
|
}
|
|
@@ -20990,8 +20990,8 @@ var require_prepared_statement_info = __commonJS({
|
|
|
20990
20990
|
execute(parameters) {
|
|
20991
20991
|
const s = this.statement;
|
|
20992
20992
|
const localErr = new Error();
|
|
20993
|
-
return new this.Promise((
|
|
20994
|
-
const done = makeDoneCb(
|
|
20993
|
+
return new this.Promise((resolve14, reject) => {
|
|
20994
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
20995
20995
|
if (parameters) {
|
|
20996
20996
|
s.execute(parameters, done);
|
|
20997
20997
|
} else {
|
|
@@ -21000,9 +21000,9 @@ var require_prepared_statement_info = __commonJS({
|
|
|
21000
21000
|
});
|
|
21001
21001
|
}
|
|
21002
21002
|
close() {
|
|
21003
|
-
return new this.Promise((
|
|
21003
|
+
return new this.Promise((resolve14) => {
|
|
21004
21004
|
this.statement.close();
|
|
21005
|
-
|
|
21005
|
+
resolve14();
|
|
21006
21006
|
});
|
|
21007
21007
|
}
|
|
21008
21008
|
};
|
|
@@ -21071,8 +21071,8 @@ var require_connection2 = __commonJS({
|
|
|
21071
21071
|
"Callback function is not available with promise clients."
|
|
21072
21072
|
);
|
|
21073
21073
|
}
|
|
21074
|
-
return new this.Promise((
|
|
21075
|
-
const done = makeDoneCb(
|
|
21074
|
+
return new this.Promise((resolve14, reject) => {
|
|
21075
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21076
21076
|
if (params !== void 0) {
|
|
21077
21077
|
c.query(query, params, done);
|
|
21078
21078
|
} else {
|
|
@@ -21088,8 +21088,8 @@ var require_connection2 = __commonJS({
|
|
|
21088
21088
|
"Callback function is not available with promise clients."
|
|
21089
21089
|
);
|
|
21090
21090
|
}
|
|
21091
|
-
return new this.Promise((
|
|
21092
|
-
const done = makeDoneCb(
|
|
21091
|
+
return new this.Promise((resolve14, reject) => {
|
|
21092
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21093
21093
|
if (params !== void 0) {
|
|
21094
21094
|
c.execute(query, params, done);
|
|
21095
21095
|
} else {
|
|
@@ -21098,8 +21098,8 @@ var require_connection2 = __commonJS({
|
|
|
21098
21098
|
});
|
|
21099
21099
|
}
|
|
21100
21100
|
end() {
|
|
21101
|
-
return new this.Promise((
|
|
21102
|
-
this.connection.end(
|
|
21101
|
+
return new this.Promise((resolve14) => {
|
|
21102
|
+
this.connection.end(resolve14);
|
|
21103
21103
|
});
|
|
21104
21104
|
}
|
|
21105
21105
|
async [Symbol.asyncDispose]() {
|
|
@@ -21110,31 +21110,31 @@ var require_connection2 = __commonJS({
|
|
|
21110
21110
|
beginTransaction() {
|
|
21111
21111
|
const c = this.connection;
|
|
21112
21112
|
const localErr = new Error();
|
|
21113
|
-
return new this.Promise((
|
|
21114
|
-
const done = makeDoneCb(
|
|
21113
|
+
return new this.Promise((resolve14, reject) => {
|
|
21114
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21115
21115
|
c.beginTransaction(done);
|
|
21116
21116
|
});
|
|
21117
21117
|
}
|
|
21118
21118
|
commit() {
|
|
21119
21119
|
const c = this.connection;
|
|
21120
21120
|
const localErr = new Error();
|
|
21121
|
-
return new this.Promise((
|
|
21122
|
-
const done = makeDoneCb(
|
|
21121
|
+
return new this.Promise((resolve14, reject) => {
|
|
21122
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21123
21123
|
c.commit(done);
|
|
21124
21124
|
});
|
|
21125
21125
|
}
|
|
21126
21126
|
rollback() {
|
|
21127
21127
|
const c = this.connection;
|
|
21128
21128
|
const localErr = new Error();
|
|
21129
|
-
return new this.Promise((
|
|
21130
|
-
const done = makeDoneCb(
|
|
21129
|
+
return new this.Promise((resolve14, reject) => {
|
|
21130
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21131
21131
|
c.rollback(done);
|
|
21132
21132
|
});
|
|
21133
21133
|
}
|
|
21134
21134
|
ping() {
|
|
21135
21135
|
const c = this.connection;
|
|
21136
21136
|
const localErr = new Error();
|
|
21137
|
-
return new this.Promise((
|
|
21137
|
+
return new this.Promise((resolve14, reject) => {
|
|
21138
21138
|
c.ping((err) => {
|
|
21139
21139
|
if (err) {
|
|
21140
21140
|
localErr.message = err.message;
|
|
@@ -21144,7 +21144,7 @@ var require_connection2 = __commonJS({
|
|
|
21144
21144
|
localErr.sqlMessage = err.sqlMessage;
|
|
21145
21145
|
reject(localErr);
|
|
21146
21146
|
} else {
|
|
21147
|
-
|
|
21147
|
+
resolve14(true);
|
|
21148
21148
|
}
|
|
21149
21149
|
});
|
|
21150
21150
|
});
|
|
@@ -21152,7 +21152,7 @@ var require_connection2 = __commonJS({
|
|
|
21152
21152
|
connect() {
|
|
21153
21153
|
const c = this.connection;
|
|
21154
21154
|
const localErr = new Error();
|
|
21155
|
-
return new this.Promise((
|
|
21155
|
+
return new this.Promise((resolve14, reject) => {
|
|
21156
21156
|
c.connect((err, param) => {
|
|
21157
21157
|
if (err) {
|
|
21158
21158
|
localErr.message = err.message;
|
|
@@ -21162,7 +21162,7 @@ var require_connection2 = __commonJS({
|
|
|
21162
21162
|
localErr.sqlMessage = err.sqlMessage;
|
|
21163
21163
|
reject(localErr);
|
|
21164
21164
|
} else {
|
|
21165
|
-
|
|
21165
|
+
resolve14(param);
|
|
21166
21166
|
}
|
|
21167
21167
|
});
|
|
21168
21168
|
});
|
|
@@ -21171,7 +21171,7 @@ var require_connection2 = __commonJS({
|
|
|
21171
21171
|
const c = this.connection;
|
|
21172
21172
|
const promiseImpl = this.Promise;
|
|
21173
21173
|
const localErr = new Error();
|
|
21174
|
-
return new this.Promise((
|
|
21174
|
+
return new this.Promise((resolve14, reject) => {
|
|
21175
21175
|
c.prepare(options, (err, statement) => {
|
|
21176
21176
|
if (err) {
|
|
21177
21177
|
localErr.message = err.message;
|
|
@@ -21185,7 +21185,7 @@ var require_connection2 = __commonJS({
|
|
|
21185
21185
|
statement,
|
|
21186
21186
|
promiseImpl
|
|
21187
21187
|
);
|
|
21188
|
-
|
|
21188
|
+
resolve14(wrappedStatement);
|
|
21189
21189
|
}
|
|
21190
21190
|
});
|
|
21191
21191
|
});
|
|
@@ -21193,7 +21193,7 @@ var require_connection2 = __commonJS({
|
|
|
21193
21193
|
changeUser(options) {
|
|
21194
21194
|
const c = this.connection;
|
|
21195
21195
|
const localErr = new Error();
|
|
21196
|
-
return new this.Promise((
|
|
21196
|
+
return new this.Promise((resolve14, reject) => {
|
|
21197
21197
|
c.changeUser(options, (err) => {
|
|
21198
21198
|
if (err) {
|
|
21199
21199
|
localErr.message = err.message;
|
|
@@ -21203,7 +21203,7 @@ var require_connection2 = __commonJS({
|
|
|
21203
21203
|
localErr.sqlMessage = err.sqlMessage;
|
|
21204
21204
|
reject(localErr);
|
|
21205
21205
|
} else {
|
|
21206
|
-
|
|
21206
|
+
resolve14();
|
|
21207
21207
|
}
|
|
21208
21208
|
});
|
|
21209
21209
|
});
|
|
@@ -21546,12 +21546,12 @@ var require_pool2 = __commonJS({
|
|
|
21546
21546
|
}
|
|
21547
21547
|
getConnection() {
|
|
21548
21548
|
const corePool = this.pool;
|
|
21549
|
-
return new this.Promise((
|
|
21549
|
+
return new this.Promise((resolve14, reject) => {
|
|
21550
21550
|
corePool.getConnection((err, coreConnection) => {
|
|
21551
21551
|
if (err) {
|
|
21552
21552
|
reject(err);
|
|
21553
21553
|
} else {
|
|
21554
|
-
|
|
21554
|
+
resolve14(new PromisePoolConnection(coreConnection, this.Promise));
|
|
21555
21555
|
}
|
|
21556
21556
|
});
|
|
21557
21557
|
});
|
|
@@ -21567,8 +21567,8 @@ var require_pool2 = __commonJS({
|
|
|
21567
21567
|
"Callback function is not available with promise clients."
|
|
21568
21568
|
);
|
|
21569
21569
|
}
|
|
21570
|
-
return new this.Promise((
|
|
21571
|
-
const done = makeDoneCb(
|
|
21570
|
+
return new this.Promise((resolve14, reject) => {
|
|
21571
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21572
21572
|
if (args !== void 0) {
|
|
21573
21573
|
corePool.query(sql, args, done);
|
|
21574
21574
|
} else {
|
|
@@ -21584,8 +21584,8 @@ var require_pool2 = __commonJS({
|
|
|
21584
21584
|
"Callback function is not available with promise clients."
|
|
21585
21585
|
);
|
|
21586
21586
|
}
|
|
21587
|
-
return new this.Promise((
|
|
21588
|
-
const done = makeDoneCb(
|
|
21587
|
+
return new this.Promise((resolve14, reject) => {
|
|
21588
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
21589
21589
|
if (args) {
|
|
21590
21590
|
corePool.execute(sql, args, done);
|
|
21591
21591
|
} else {
|
|
@@ -21596,7 +21596,7 @@ var require_pool2 = __commonJS({
|
|
|
21596
21596
|
end() {
|
|
21597
21597
|
const corePool = this.pool;
|
|
21598
21598
|
const localErr = new Error();
|
|
21599
|
-
return new this.Promise((
|
|
21599
|
+
return new this.Promise((resolve14, reject) => {
|
|
21600
21600
|
corePool.end((err) => {
|
|
21601
21601
|
if (err) {
|
|
21602
21602
|
localErr.message = err.message;
|
|
@@ -21606,7 +21606,7 @@ var require_pool2 = __commonJS({
|
|
|
21606
21606
|
localErr.sqlMessage = err.sqlMessage;
|
|
21607
21607
|
reject(localErr);
|
|
21608
21608
|
} else {
|
|
21609
|
-
|
|
21609
|
+
resolve14();
|
|
21610
21610
|
}
|
|
21611
21611
|
});
|
|
21612
21612
|
});
|
|
@@ -22051,12 +22051,12 @@ var require_pool_cluster2 = __commonJS({
|
|
|
22051
22051
|
}
|
|
22052
22052
|
getConnection() {
|
|
22053
22053
|
const corePoolNamespace = this.poolNamespace;
|
|
22054
|
-
return new this.Promise((
|
|
22054
|
+
return new this.Promise((resolve14, reject) => {
|
|
22055
22055
|
corePoolNamespace.getConnection((err, coreConnection) => {
|
|
22056
22056
|
if (err) {
|
|
22057
22057
|
reject(err);
|
|
22058
22058
|
} else {
|
|
22059
|
-
|
|
22059
|
+
resolve14(new PromisePoolConnection(coreConnection, this.Promise));
|
|
22060
22060
|
}
|
|
22061
22061
|
});
|
|
22062
22062
|
});
|
|
@@ -22069,8 +22069,8 @@ var require_pool_cluster2 = __commonJS({
|
|
|
22069
22069
|
"Callback function is not available with promise clients."
|
|
22070
22070
|
);
|
|
22071
22071
|
}
|
|
22072
|
-
return new this.Promise((
|
|
22073
|
-
const done = makeDoneCb(
|
|
22072
|
+
return new this.Promise((resolve14, reject) => {
|
|
22073
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
22074
22074
|
corePoolNamespace.query(sql, values, done);
|
|
22075
22075
|
});
|
|
22076
22076
|
}
|
|
@@ -22082,8 +22082,8 @@ var require_pool_cluster2 = __commonJS({
|
|
|
22082
22082
|
"Callback function is not available with promise clients."
|
|
22083
22083
|
);
|
|
22084
22084
|
}
|
|
22085
|
-
return new this.Promise((
|
|
22086
|
-
const done = makeDoneCb(
|
|
22085
|
+
return new this.Promise((resolve14, reject) => {
|
|
22086
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
22087
22087
|
corePoolNamespace.execute(sql, values, done);
|
|
22088
22088
|
});
|
|
22089
22089
|
}
|
|
@@ -22118,9 +22118,9 @@ var require_promise = __commonJS({
|
|
|
22118
22118
|
"no Promise implementation available.Use promise-enabled node version or pass userland Promise implementation as parameter, for example: { Promise: require('bluebird') }"
|
|
22119
22119
|
);
|
|
22120
22120
|
}
|
|
22121
|
-
return new thePromise((
|
|
22121
|
+
return new thePromise((resolve14, reject) => {
|
|
22122
22122
|
coreConnection.once("connect", () => {
|
|
22123
|
-
|
|
22123
|
+
resolve14(new PromiseConnection(coreConnection, thePromise));
|
|
22124
22124
|
});
|
|
22125
22125
|
coreConnection.once("error", (err) => {
|
|
22126
22126
|
createConnectionErr.message = err.message;
|
|
@@ -22150,7 +22150,7 @@ var require_promise = __commonJS({
|
|
|
22150
22150
|
}
|
|
22151
22151
|
getConnection(pattern, selector) {
|
|
22152
22152
|
const corePoolCluster = this.poolCluster;
|
|
22153
|
-
return new this.Promise((
|
|
22153
|
+
return new this.Promise((resolve14, reject) => {
|
|
22154
22154
|
corePoolCluster.getConnection(
|
|
22155
22155
|
pattern,
|
|
22156
22156
|
selector,
|
|
@@ -22158,7 +22158,7 @@ var require_promise = __commonJS({
|
|
|
22158
22158
|
if (err) {
|
|
22159
22159
|
reject(err);
|
|
22160
22160
|
} else {
|
|
22161
|
-
|
|
22161
|
+
resolve14(new PromisePoolConnection(coreConnection, this.Promise));
|
|
22162
22162
|
}
|
|
22163
22163
|
}
|
|
22164
22164
|
);
|
|
@@ -22172,8 +22172,8 @@ var require_promise = __commonJS({
|
|
|
22172
22172
|
"Callback function is not available with promise clients."
|
|
22173
22173
|
);
|
|
22174
22174
|
}
|
|
22175
|
-
return new this.Promise((
|
|
22176
|
-
const done = makeDoneCb(
|
|
22175
|
+
return new this.Promise((resolve14, reject) => {
|
|
22176
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
22177
22177
|
corePoolCluster.query(sql, args, done);
|
|
22178
22178
|
});
|
|
22179
22179
|
}
|
|
@@ -22185,8 +22185,8 @@ var require_promise = __commonJS({
|
|
|
22185
22185
|
"Callback function is not available with promise clients."
|
|
22186
22186
|
);
|
|
22187
22187
|
}
|
|
22188
|
-
return new this.Promise((
|
|
22189
|
-
const done = makeDoneCb(
|
|
22188
|
+
return new this.Promise((resolve14, reject) => {
|
|
22189
|
+
const done = makeDoneCb(resolve14, reject, localErr);
|
|
22190
22190
|
corePoolCluster.execute(sql, args, done);
|
|
22191
22191
|
});
|
|
22192
22192
|
}
|
|
@@ -22199,7 +22199,7 @@ var require_promise = __commonJS({
|
|
|
22199
22199
|
end() {
|
|
22200
22200
|
const corePoolCluster = this.poolCluster;
|
|
22201
22201
|
const localErr = new Error();
|
|
22202
|
-
return new this.Promise((
|
|
22202
|
+
return new this.Promise((resolve14, reject) => {
|
|
22203
22203
|
corePoolCluster.end((err) => {
|
|
22204
22204
|
if (err) {
|
|
22205
22205
|
localErr.message = err.message;
|
|
@@ -22209,7 +22209,7 @@ var require_promise = __commonJS({
|
|
|
22209
22209
|
localErr.sqlMessage = err.sqlMessage;
|
|
22210
22210
|
reject(localErr);
|
|
22211
22211
|
} else {
|
|
22212
|
-
|
|
22212
|
+
resolve14();
|
|
22213
22213
|
}
|
|
22214
22214
|
});
|
|
22215
22215
|
});
|
|
@@ -31779,7 +31779,7 @@ async function uploadToGist(content, options) {
|
|
|
31779
31779
|
[options.filename]: { content }
|
|
31780
31780
|
}
|
|
31781
31781
|
});
|
|
31782
|
-
return new Promise((
|
|
31782
|
+
return new Promise((resolve14, reject) => {
|
|
31783
31783
|
const req = import_node_https.default.request({
|
|
31784
31784
|
hostname: "api.github.com",
|
|
31785
31785
|
path: "/gists",
|
|
@@ -31801,7 +31801,7 @@ async function uploadToGist(content, options) {
|
|
|
31801
31801
|
try {
|
|
31802
31802
|
const parsed = JSON.parse(data);
|
|
31803
31803
|
const fileEntry = parsed.files[options.filename];
|
|
31804
|
-
|
|
31804
|
+
resolve14({
|
|
31805
31805
|
url: parsed.html_url,
|
|
31806
31806
|
rawUrl: fileEntry?.raw_url ?? parsed.html_url,
|
|
31807
31807
|
gistId: parsed.id
|
|
@@ -31928,7 +31928,7 @@ function fetchUrl(url, redirectCount = 0) {
|
|
|
31928
31928
|
throw new Error("Too many redirects");
|
|
31929
31929
|
}
|
|
31930
31930
|
const lib = url.startsWith("https") ? import_node_https2.default : import_node_http.default;
|
|
31931
|
-
return new Promise((
|
|
31931
|
+
return new Promise((resolve14, reject) => {
|
|
31932
31932
|
const req = lib.get(url, {
|
|
31933
31933
|
headers: {
|
|
31934
31934
|
"User-Agent": "realitydb-cli",
|
|
@@ -31936,7 +31936,7 @@ function fetchUrl(url, redirectCount = 0) {
|
|
|
31936
31936
|
}
|
|
31937
31937
|
}, (res) => {
|
|
31938
31938
|
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
31939
|
-
|
|
31939
|
+
resolve14(fetchUrl(res.headers.location, redirectCount + 1));
|
|
31940
31940
|
return;
|
|
31941
31941
|
}
|
|
31942
31942
|
if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
|
|
@@ -31949,7 +31949,7 @@ function fetchUrl(url, redirectCount = 0) {
|
|
|
31949
31949
|
});
|
|
31950
31950
|
res.on("end", () => {
|
|
31951
31951
|
const buffer = Buffer.concat(chunks);
|
|
31952
|
-
|
|
31952
|
+
resolve14(buffer.toString("utf-8"));
|
|
31953
31953
|
});
|
|
31954
31954
|
});
|
|
31955
31955
|
req.on("error", (err) => {
|
|
@@ -32457,9 +32457,9 @@ var DEFAULT_CONNECTIONS = {
|
|
|
32457
32457
|
};
|
|
32458
32458
|
var SUPPORTED_CLIENTS = ["postgres", "mysql"];
|
|
32459
32459
|
function ask(rl, prompt) {
|
|
32460
|
-
return new Promise((
|
|
32460
|
+
return new Promise((resolve14) => {
|
|
32461
32461
|
rl.question(prompt, (answer) => {
|
|
32462
|
-
|
|
32462
|
+
resolve14(answer);
|
|
32463
32463
|
});
|
|
32464
32464
|
});
|
|
32465
32465
|
}
|
|
@@ -34418,12 +34418,396 @@ async function analyzeCommand(options) {
|
|
|
34418
34418
|
}
|
|
34419
34419
|
}
|
|
34420
34420
|
|
|
34421
|
-
// src/commands/
|
|
34421
|
+
// src/commands/run.ts
|
|
34422
34422
|
var import_node_fs12 = require("fs");
|
|
34423
34423
|
var import_node_path17 = require("path");
|
|
34424
|
+
var VERSION13 = "1.0.0";
|
|
34425
|
+
function strategyToSqlType(strategy) {
|
|
34426
|
+
switch (strategy) {
|
|
34427
|
+
case "uuid":
|
|
34428
|
+
case "foreign_key":
|
|
34429
|
+
return { dataType: "UUID", maxLength: null, numericPrecision: null, numericScale: null };
|
|
34430
|
+
case "full_name":
|
|
34431
|
+
case "first_name":
|
|
34432
|
+
case "last_name":
|
|
34433
|
+
case "email":
|
|
34434
|
+
case "phone":
|
|
34435
|
+
case "text":
|
|
34436
|
+
case "company_name":
|
|
34437
|
+
case "address":
|
|
34438
|
+
case "custom":
|
|
34439
|
+
return { dataType: "VARCHAR", maxLength: 255, numericPrecision: null, numericScale: null };
|
|
34440
|
+
case "integer":
|
|
34441
|
+
case "auto_increment":
|
|
34442
|
+
return { dataType: "INTEGER", maxLength: null, numericPrecision: null, numericScale: null };
|
|
34443
|
+
case "float":
|
|
34444
|
+
case "money":
|
|
34445
|
+
return { dataType: "NUMERIC", maxLength: null, numericPrecision: 12, numericScale: 2 };
|
|
34446
|
+
case "boolean":
|
|
34447
|
+
return { dataType: "BOOLEAN", maxLength: null, numericPrecision: null, numericScale: null };
|
|
34448
|
+
case "timestamp":
|
|
34449
|
+
return { dataType: "TIMESTAMPTZ", maxLength: null, numericPrecision: null, numericScale: null };
|
|
34450
|
+
case "enum":
|
|
34451
|
+
return { dataType: "VARCHAR", maxLength: 50, numericPrecision: null, numericScale: null };
|
|
34452
|
+
default:
|
|
34453
|
+
return { dataType: "VARCHAR", maxLength: 255, numericPrecision: null, numericScale: null };
|
|
34454
|
+
}
|
|
34455
|
+
}
|
|
34456
|
+
function collectNullableFromLifecycle(columns) {
|
|
34457
|
+
const nullableFields = /* @__PURE__ */ new Set();
|
|
34458
|
+
for (const col of Object.values(columns)) {
|
|
34459
|
+
const opts = col.options;
|
|
34460
|
+
if (opts?.lifecycleRules && Array.isArray(opts.lifecycleRules)) {
|
|
34461
|
+
for (const rule of opts.lifecycleRules) {
|
|
34462
|
+
const r = rule;
|
|
34463
|
+
if (r.nullFields) {
|
|
34464
|
+
for (const f of r.nullFields) {
|
|
34465
|
+
nullableFields.add(f);
|
|
34466
|
+
}
|
|
34467
|
+
}
|
|
34468
|
+
}
|
|
34469
|
+
}
|
|
34470
|
+
}
|
|
34471
|
+
return nullableFields;
|
|
34472
|
+
}
|
|
34473
|
+
function extractSchemaFromTemplate(template) {
|
|
34474
|
+
const tables = [];
|
|
34475
|
+
const foreignKeys = [];
|
|
34476
|
+
for (const [tableName, tableJson] of Object.entries(template.tables)) {
|
|
34477
|
+
const lifecycleNullable = collectNullableFromLifecycle(tableJson.columns);
|
|
34478
|
+
const columns = [];
|
|
34479
|
+
let ordinal = 1;
|
|
34480
|
+
for (const [colName, colJson] of Object.entries(tableJson.columns)) {
|
|
34481
|
+
const strategy = colJson.foreignKey ? "foreign_key" : colJson.strategy;
|
|
34482
|
+
const typeInfo = strategyToSqlType(strategy);
|
|
34483
|
+
const isPK = strategy === "uuid" && colName === "id";
|
|
34484
|
+
const isNullable = lifecycleNullable.has(colName);
|
|
34485
|
+
columns.push({
|
|
34486
|
+
name: colName,
|
|
34487
|
+
dataType: typeInfo.dataType,
|
|
34488
|
+
udtName: typeInfo.dataType.toLowerCase(),
|
|
34489
|
+
isNullable: isPK ? false : isNullable,
|
|
34490
|
+
hasDefault: false,
|
|
34491
|
+
defaultValue: null,
|
|
34492
|
+
maxLength: typeInfo.maxLength,
|
|
34493
|
+
numericPrecision: typeInfo.numericPrecision,
|
|
34494
|
+
numericScale: typeInfo.numericScale,
|
|
34495
|
+
isPrimaryKey: isPK,
|
|
34496
|
+
isUnique: isPK,
|
|
34497
|
+
ordinalPosition: ordinal++
|
|
34498
|
+
});
|
|
34499
|
+
if (colJson.foreignKey) {
|
|
34500
|
+
foreignKeys.push({
|
|
34501
|
+
constraintName: `fk_${tableName}_${colName}`,
|
|
34502
|
+
sourceTable: tableName,
|
|
34503
|
+
sourceColumn: colName,
|
|
34504
|
+
targetTable: colJson.foreignKey.table,
|
|
34505
|
+
targetColumn: colJson.foreignKey.column
|
|
34506
|
+
});
|
|
34507
|
+
}
|
|
34508
|
+
}
|
|
34509
|
+
tables.push({
|
|
34510
|
+
name: tableName,
|
|
34511
|
+
schema: "public",
|
|
34512
|
+
columns,
|
|
34513
|
+
primaryKey: columns.find((c) => c.isPrimaryKey) ? { columnName: "id", constraintName: `pk_${tableName}` } : null,
|
|
34514
|
+
estimatedRowCount: 0
|
|
34515
|
+
});
|
|
34516
|
+
}
|
|
34517
|
+
return {
|
|
34518
|
+
tables,
|
|
34519
|
+
foreignKeys,
|
|
34520
|
+
tableCount: tables.length,
|
|
34521
|
+
foreignKeyCount: foreignKeys.length
|
|
34522
|
+
};
|
|
34523
|
+
}
|
|
34524
|
+
function getDropOrder(schema) {
|
|
34525
|
+
const createOrder = getCreateOrder(schema);
|
|
34526
|
+
return [...createOrder].reverse();
|
|
34527
|
+
}
|
|
34528
|
+
function getCreateOrder(schema) {
|
|
34529
|
+
const tableNames = new Set(schema.tables.map((t) => t.name));
|
|
34530
|
+
const deps = /* @__PURE__ */ new Map();
|
|
34531
|
+
for (const name of tableNames) {
|
|
34532
|
+
deps.set(name, /* @__PURE__ */ new Set());
|
|
34533
|
+
}
|
|
34534
|
+
for (const fk of schema.foreignKeys) {
|
|
34535
|
+
if (fk.sourceTable !== fk.targetTable && tableNames.has(fk.targetTable)) {
|
|
34536
|
+
deps.get(fk.sourceTable).add(fk.targetTable);
|
|
34537
|
+
}
|
|
34538
|
+
}
|
|
34539
|
+
const result = [];
|
|
34540
|
+
const visited = /* @__PURE__ */ new Set();
|
|
34541
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
34542
|
+
function visit(name) {
|
|
34543
|
+
if (visited.has(name)) return;
|
|
34544
|
+
if (visiting.has(name)) return;
|
|
34545
|
+
visiting.add(name);
|
|
34546
|
+
for (const dep of deps.get(name) ?? []) {
|
|
34547
|
+
visit(dep);
|
|
34548
|
+
}
|
|
34549
|
+
visiting.delete(name);
|
|
34550
|
+
visited.add(name);
|
|
34551
|
+
result.push(name);
|
|
34552
|
+
}
|
|
34553
|
+
for (const name of tableNames) {
|
|
34554
|
+
visit(name);
|
|
34555
|
+
}
|
|
34556
|
+
return result;
|
|
34557
|
+
}
|
|
34558
|
+
async function runCommand(options) {
|
|
34559
|
+
const start = performance.now();
|
|
34560
|
+
const packPath = (0, import_node_path17.resolve)(options.pack);
|
|
34561
|
+
const masked = maskConnectionString(options.connection);
|
|
34562
|
+
const records = options.records ? parseInt(options.records, 10) : void 0;
|
|
34563
|
+
const seed = options.seed ? parseInt(options.seed, 10) : void 0;
|
|
34564
|
+
if (!(0, import_node_fs12.existsSync)(packPath)) {
|
|
34565
|
+
const msg = `Pack file not found: ${packPath}`;
|
|
34566
|
+
if (options.ci) {
|
|
34567
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: 0, error: msg }));
|
|
34568
|
+
process.exit(1);
|
|
34569
|
+
}
|
|
34570
|
+
console.error(`[realitydb] ${msg}`);
|
|
34571
|
+
console.error("Hint: Provide the path to a Studio-exported template JSON file.");
|
|
34572
|
+
process.exit(1);
|
|
34573
|
+
}
|
|
34574
|
+
let raw;
|
|
34575
|
+
try {
|
|
34576
|
+
raw = (0, import_node_fs12.readFileSync)(packPath, "utf-8");
|
|
34577
|
+
} catch (err) {
|
|
34578
|
+
const msg = `Cannot read pack file: ${err instanceof Error ? err.message : String(err)}`;
|
|
34579
|
+
if (options.ci) {
|
|
34580
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: 0, error: msg }));
|
|
34581
|
+
process.exit(1);
|
|
34582
|
+
}
|
|
34583
|
+
console.error(`[realitydb] ${msg}`);
|
|
34584
|
+
process.exit(1);
|
|
34585
|
+
}
|
|
34586
|
+
let json;
|
|
34587
|
+
try {
|
|
34588
|
+
json = JSON.parse(raw);
|
|
34589
|
+
} catch {
|
|
34590
|
+
const msg = `Pack file is not valid JSON: ${packPath}`;
|
|
34591
|
+
if (options.ci) {
|
|
34592
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: 0, error: msg }));
|
|
34593
|
+
process.exit(1);
|
|
34594
|
+
}
|
|
34595
|
+
console.error(`[realitydb] ${msg}`);
|
|
34596
|
+
console.error("Hint: Ensure the file is a valid Studio-exported template JSON.");
|
|
34597
|
+
process.exit(1);
|
|
34598
|
+
}
|
|
34599
|
+
let template;
|
|
34600
|
+
try {
|
|
34601
|
+
template = assertValidTemplate(json);
|
|
34602
|
+
} catch (err) {
|
|
34603
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
34604
|
+
if (options.ci) {
|
|
34605
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: 0, error: msg }));
|
|
34606
|
+
process.exit(1);
|
|
34607
|
+
}
|
|
34608
|
+
console.error(`[realitydb] ${msg}`);
|
|
34609
|
+
process.exit(1);
|
|
34610
|
+
}
|
|
34611
|
+
const schema = extractSchemaFromTemplate(template);
|
|
34612
|
+
const ddl = generateCreateTableDDL(schema);
|
|
34613
|
+
const effectiveRecords = records ?? template.generationConfig?.seed?.defaultRecords ?? 1e3;
|
|
34614
|
+
const effectiveSeed = seed ?? template.generationConfig?.seed?.randomSeed ?? 42;
|
|
34615
|
+
if (!options.ci) {
|
|
34616
|
+
console.log("");
|
|
34617
|
+
console.log("RealityDB Run");
|
|
34618
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
34619
|
+
console.log(`Pack: ${packPath}`);
|
|
34620
|
+
console.log(`Database: ${masked}`);
|
|
34621
|
+
console.log(`Records per table: ${effectiveRecords}`);
|
|
34622
|
+
console.log(`Seed: ${effectiveSeed}`);
|
|
34623
|
+
if (options.dropExisting) console.log("Drop existing: yes");
|
|
34624
|
+
if (options.dryRun) console.log("Mode: dry run");
|
|
34625
|
+
console.log("");
|
|
34626
|
+
}
|
|
34627
|
+
if (options.dryRun) {
|
|
34628
|
+
if (options.ci) {
|
|
34629
|
+
const tableNames = Object.keys(template.tables);
|
|
34630
|
+
const planSummary = tableNames.map((name) => ({
|
|
34631
|
+
table: name,
|
|
34632
|
+
columns: Object.keys(template.tables[name].columns).length,
|
|
34633
|
+
records: effectiveRecords
|
|
34634
|
+
}));
|
|
34635
|
+
console.log(formatCIOutput({
|
|
34636
|
+
success: true,
|
|
34637
|
+
command: "run",
|
|
34638
|
+
version: VERSION13,
|
|
34639
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34640
|
+
durationMs: Math.round(performance.now() - start),
|
|
34641
|
+
data: { dryRun: true, ddl, plan: planSummary }
|
|
34642
|
+
}));
|
|
34643
|
+
return;
|
|
34644
|
+
}
|
|
34645
|
+
console.log("DDL that would be executed:");
|
|
34646
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
34647
|
+
if (options.dropExisting) {
|
|
34648
|
+
const dropOrder = getDropOrder(schema);
|
|
34649
|
+
for (const tableName of dropOrder) {
|
|
34650
|
+
console.log(`DROP TABLE IF EXISTS "${tableName}" CASCADE;`);
|
|
34651
|
+
}
|
|
34652
|
+
console.log("");
|
|
34653
|
+
}
|
|
34654
|
+
console.log(ddl);
|
|
34655
|
+
console.log("Generation Plan:");
|
|
34656
|
+
console.log("\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
34657
|
+
for (const [tableName, tableJson] of Object.entries(template.tables)) {
|
|
34658
|
+
const colCount = Object.keys(tableJson.columns).length;
|
|
34659
|
+
const strategies = Object.values(tableJson.columns).map((c) => c.strategy);
|
|
34660
|
+
const uniqueStrategies = [...new Set(strategies)].join(", ");
|
|
34661
|
+
console.log(` ${tableName}: ${effectiveRecords} rows, ${colCount} columns [${uniqueStrategies}]`);
|
|
34662
|
+
}
|
|
34663
|
+
console.log("");
|
|
34664
|
+
console.log("Dry run complete. No changes were made.");
|
|
34665
|
+
return;
|
|
34666
|
+
}
|
|
34667
|
+
const clientType = template.generationConfig?.database?.client ?? "postgres";
|
|
34668
|
+
const pool = createDatabaseClient(clientType, options.connection);
|
|
34669
|
+
try {
|
|
34670
|
+
try {
|
|
34671
|
+
await testConnection(pool);
|
|
34672
|
+
} catch (err) {
|
|
34673
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
34674
|
+
if (options.ci) {
|
|
34675
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: Math.round(performance.now() - start), error: msg }));
|
|
34676
|
+
process.exit(1);
|
|
34677
|
+
}
|
|
34678
|
+
console.error(`[realitydb] Cannot connect to database: ${msg}`);
|
|
34679
|
+
console.error("Hint: Check your connection string and ensure the database is running.");
|
|
34680
|
+
process.exit(1);
|
|
34681
|
+
}
|
|
34682
|
+
if (!options.dropExisting) {
|
|
34683
|
+
const existingTables = [];
|
|
34684
|
+
for (const table of schema.tables) {
|
|
34685
|
+
try {
|
|
34686
|
+
const client = await pool.connect();
|
|
34687
|
+
try {
|
|
34688
|
+
const result2 = await client.query(
|
|
34689
|
+
`SELECT to_regclass('"${table.name}"') AS exists_check`
|
|
34690
|
+
);
|
|
34691
|
+
if (result2.rows[0]?.exists_check) {
|
|
34692
|
+
existingTables.push(table.name);
|
|
34693
|
+
}
|
|
34694
|
+
} finally {
|
|
34695
|
+
client.release();
|
|
34696
|
+
}
|
|
34697
|
+
} catch {
|
|
34698
|
+
}
|
|
34699
|
+
}
|
|
34700
|
+
if (existingTables.length > 0) {
|
|
34701
|
+
const msg = `Tables already exist: ${existingTables.join(", ")}. Use --drop-existing to recreate them.`;
|
|
34702
|
+
if (options.ci) {
|
|
34703
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: Math.round(performance.now() - start), error: msg }));
|
|
34704
|
+
process.exit(1);
|
|
34705
|
+
}
|
|
34706
|
+
console.error(`[realitydb] ${msg}`);
|
|
34707
|
+
process.exit(1);
|
|
34708
|
+
}
|
|
34709
|
+
}
|
|
34710
|
+
if (!options.ci) {
|
|
34711
|
+
console.log("Creating schema...");
|
|
34712
|
+
}
|
|
34713
|
+
try {
|
|
34714
|
+
await withTransaction(pool, async (client) => {
|
|
34715
|
+
if (options.dropExisting) {
|
|
34716
|
+
const dropOrder = getDropOrder(schema);
|
|
34717
|
+
for (const tableName of dropOrder) {
|
|
34718
|
+
await client.query(`DROP TABLE IF EXISTS "${tableName}" CASCADE`);
|
|
34719
|
+
}
|
|
34720
|
+
}
|
|
34721
|
+
const statements = ddl.split(";").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
34722
|
+
for (const stmt of statements) {
|
|
34723
|
+
await client.query(stmt + ";");
|
|
34724
|
+
}
|
|
34725
|
+
});
|
|
34726
|
+
} catch (err) {
|
|
34727
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
34728
|
+
if (options.ci) {
|
|
34729
|
+
console.log(formatCIOutput({ success: false, command: "run", version: VERSION13, timestamp: (/* @__PURE__ */ new Date()).toISOString(), durationMs: Math.round(performance.now() - start), error: `DDL failed: ${msg}` }));
|
|
34730
|
+
process.exit(1);
|
|
34731
|
+
}
|
|
34732
|
+
console.error(`[realitydb] DDL failed: ${msg}`);
|
|
34733
|
+
console.error("Database was not modified (transaction rolled back).");
|
|
34734
|
+
process.exit(1);
|
|
34735
|
+
}
|
|
34736
|
+
if (!options.ci) {
|
|
34737
|
+
for (const table of schema.tables) {
|
|
34738
|
+
console.log(` Created table: ${table.name} (${table.columns.length} columns)`);
|
|
34739
|
+
}
|
|
34740
|
+
console.log("");
|
|
34741
|
+
}
|
|
34742
|
+
if (!options.ci) {
|
|
34743
|
+
console.log("Seeding data...");
|
|
34744
|
+
}
|
|
34745
|
+
const config = {
|
|
34746
|
+
database: {
|
|
34747
|
+
client: clientType,
|
|
34748
|
+
connectionString: options.connection
|
|
34749
|
+
},
|
|
34750
|
+
seed: {
|
|
34751
|
+
defaultRecords: effectiveRecords,
|
|
34752
|
+
batchSize: 500,
|
|
34753
|
+
environment: "development",
|
|
34754
|
+
randomSeed: effectiveSeed
|
|
34755
|
+
},
|
|
34756
|
+
template: packPath
|
|
34757
|
+
};
|
|
34758
|
+
const result = await seedDatabase(config, {
|
|
34759
|
+
records: effectiveRecords,
|
|
34760
|
+
seed: effectiveSeed,
|
|
34761
|
+
template: packPath
|
|
34762
|
+
});
|
|
34763
|
+
const durationMs = Math.round(performance.now() - start);
|
|
34764
|
+
const totalTime = (durationMs / 1e3).toFixed(1);
|
|
34765
|
+
if (options.ci) {
|
|
34766
|
+
console.log(formatCIOutput({
|
|
34767
|
+
success: true,
|
|
34768
|
+
command: "run",
|
|
34769
|
+
version: VERSION13,
|
|
34770
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34771
|
+
durationMs,
|
|
34772
|
+
data: {
|
|
34773
|
+
tablesCreated: schema.tables.length,
|
|
34774
|
+
totalRows: result.totalRows,
|
|
34775
|
+
pack: packPath,
|
|
34776
|
+
database: masked,
|
|
34777
|
+
tables: result.insertResult.tables.map((t) => ({
|
|
34778
|
+
name: t.tableName,
|
|
34779
|
+
rowsInserted: t.rowsInserted,
|
|
34780
|
+
batchCount: t.batchCount,
|
|
34781
|
+
durationMs: t.durationMs
|
|
34782
|
+
}))
|
|
34783
|
+
}
|
|
34784
|
+
}));
|
|
34785
|
+
return;
|
|
34786
|
+
}
|
|
34787
|
+
for (const tableResult of result.insertResult.tables) {
|
|
34788
|
+
console.log(
|
|
34789
|
+
` ${tableResult.tableName}: ${tableResult.rowsInserted} rows inserted (${tableResult.batchCount} batches, ${tableResult.durationMs}ms)`
|
|
34790
|
+
);
|
|
34791
|
+
}
|
|
34792
|
+
console.log("");
|
|
34793
|
+
console.log("RealityDB Run Complete");
|
|
34794
|
+
console.log("\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
34795
|
+
console.log(`Schema: ${schema.tables.length} tables created`);
|
|
34796
|
+
console.log(`Data: ${result.totalRows} total rows in ${totalTime}s`);
|
|
34797
|
+
console.log(`Pack: ${packPath}`);
|
|
34798
|
+
console.log(`Database: ${masked}`);
|
|
34799
|
+
console.log("");
|
|
34800
|
+
} finally {
|
|
34801
|
+
await closeConnection(pool);
|
|
34802
|
+
}
|
|
34803
|
+
}
|
|
34804
|
+
|
|
34805
|
+
// src/commands/mask.ts
|
|
34806
|
+
var import_node_fs13 = require("fs");
|
|
34807
|
+
var import_node_path18 = require("path");
|
|
34424
34808
|
var import_node_readline2 = require("readline");
|
|
34425
34809
|
var import_node_process2 = require("process");
|
|
34426
|
-
var
|
|
34810
|
+
var VERSION14 = "1.3.1";
|
|
34427
34811
|
function askPassphrase(prompt) {
|
|
34428
34812
|
return new Promise((resolvePromise) => {
|
|
34429
34813
|
const rl = (0, import_node_readline2.createInterface)({ input: import_node_process2.stdin, output: import_node_process2.stdout });
|
|
@@ -34460,7 +34844,7 @@ async function maskCommand(options) {
|
|
|
34460
34844
|
console.log(formatCIOutput({
|
|
34461
34845
|
success: false,
|
|
34462
34846
|
command: "mask",
|
|
34463
|
-
version:
|
|
34847
|
+
version: VERSION14,
|
|
34464
34848
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34465
34849
|
durationMs: Math.round(performance.now() - start),
|
|
34466
34850
|
error: msg
|
|
@@ -34476,7 +34860,7 @@ async function maskCommand(options) {
|
|
|
34476
34860
|
console.log(formatCIOutput({
|
|
34477
34861
|
success: false,
|
|
34478
34862
|
command: "mask",
|
|
34479
|
-
version:
|
|
34863
|
+
version: VERSION14,
|
|
34480
34864
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34481
34865
|
durationMs: Math.round(performance.now() - start),
|
|
34482
34866
|
error: msg
|
|
@@ -34527,8 +34911,8 @@ async function maskCommand(options) {
|
|
|
34527
34911
|
});
|
|
34528
34912
|
const durationMs = Math.round(performance.now() - start);
|
|
34529
34913
|
if (options.auditLog) {
|
|
34530
|
-
const auditPath = (0,
|
|
34531
|
-
(0,
|
|
34914
|
+
const auditPath = (0, import_node_path18.resolve)(options.auditLog);
|
|
34915
|
+
(0, import_node_fs13.writeFileSync)(auditPath, serializeAuditLog(result.auditLog) + "\n", "utf-8");
|
|
34532
34916
|
}
|
|
34533
34917
|
if (options.tokenMap && result.tokenMap) {
|
|
34534
34918
|
const passphrase = await askPassphrase("Enter passphrase for token map encryption: ");
|
|
@@ -34536,8 +34920,8 @@ async function maskCommand(options) {
|
|
|
34536
34920
|
console.error("[realitydb] Passphrase cannot be empty. Token map not written.");
|
|
34537
34921
|
} else {
|
|
34538
34922
|
const encryptedData = encryptTokenMap(result.tokenMap, passphrase);
|
|
34539
|
-
const tokenMapPath = (0,
|
|
34540
|
-
(0,
|
|
34923
|
+
const tokenMapPath = (0, import_node_path18.resolve)(options.tokenMap);
|
|
34924
|
+
(0, import_node_fs13.writeFileSync)(tokenMapPath, encryptedData + "\n", "utf-8");
|
|
34541
34925
|
if (!options.ci) {
|
|
34542
34926
|
console.log(`Token map exported (AES-256-GCM encrypted) \u2192 ${tokenMapPath}`);
|
|
34543
34927
|
console.log(` ${result.tokenMap.totalTokens} unique tokens generated`);
|
|
@@ -34550,7 +34934,7 @@ async function maskCommand(options) {
|
|
|
34550
34934
|
console.log(formatCIOutput({
|
|
34551
34935
|
success: true,
|
|
34552
34936
|
command: "mask",
|
|
34553
|
-
version:
|
|
34937
|
+
version: VERSION14,
|
|
34554
34938
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34555
34939
|
durationMs,
|
|
34556
34940
|
data: {
|
|
@@ -34582,7 +34966,7 @@ async function maskCommand(options) {
|
|
|
34582
34966
|
console.log("");
|
|
34583
34967
|
}
|
|
34584
34968
|
if (options.auditLog) {
|
|
34585
|
-
console.log(`Audit log written to: ${(0,
|
|
34969
|
+
console.log(`Audit log written to: ${(0, import_node_path18.resolve)(options.auditLog)}`);
|
|
34586
34970
|
console.log("");
|
|
34587
34971
|
}
|
|
34588
34972
|
const totalTime = (durationMs / 1e3).toFixed(1);
|
|
@@ -34598,7 +34982,7 @@ async function maskCommand(options) {
|
|
|
34598
34982
|
console.log(formatCIOutput({
|
|
34599
34983
|
success: false,
|
|
34600
34984
|
command: "mask",
|
|
34601
|
-
version:
|
|
34985
|
+
version: VERSION14,
|
|
34602
34986
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34603
34987
|
durationMs: Math.round(performance.now() - start),
|
|
34604
34988
|
error: message
|
|
@@ -34619,8 +35003,8 @@ async function maskCommand(options) {
|
|
|
34619
35003
|
}
|
|
34620
35004
|
|
|
34621
35005
|
// src/commands/audit.ts
|
|
34622
|
-
var
|
|
34623
|
-
var
|
|
35006
|
+
var import_node_fs14 = require("fs");
|
|
35007
|
+
var import_node_path19 = require("path");
|
|
34624
35008
|
var import_node_readline3 = require("readline");
|
|
34625
35009
|
var import_node_process3 = require("process");
|
|
34626
35010
|
function askPassphrase2(prompt) {
|
|
@@ -34646,8 +35030,8 @@ function askPassphrase2(prompt) {
|
|
|
34646
35030
|
}
|
|
34647
35031
|
async function auditVerifyCommand(logFile, options) {
|
|
34648
35032
|
try {
|
|
34649
|
-
const filePath = (0,
|
|
34650
|
-
const raw = (0,
|
|
35033
|
+
const filePath = (0, import_node_path19.resolve)(logFile);
|
|
35034
|
+
const raw = (0, import_node_fs14.readFileSync)(filePath, "utf-8");
|
|
34651
35035
|
const log = JSON.parse(raw);
|
|
34652
35036
|
const result = verifyAuditLogIntegrity(log);
|
|
34653
35037
|
const entryCount = log.tables?.length ?? 0;
|
|
@@ -34681,8 +35065,8 @@ async function auditVerifyCommand(logFile, options) {
|
|
|
34681
35065
|
}
|
|
34682
35066
|
async function auditSummaryCommand(logFile, options) {
|
|
34683
35067
|
try {
|
|
34684
|
-
const filePath = (0,
|
|
34685
|
-
const raw = (0,
|
|
35068
|
+
const filePath = (0, import_node_path19.resolve)(logFile);
|
|
35069
|
+
const raw = (0, import_node_fs14.readFileSync)(filePath, "utf-8");
|
|
34686
35070
|
const log = JSON.parse(raw);
|
|
34687
35071
|
if (options.ci) {
|
|
34688
35072
|
console.log(JSON.stringify({
|
|
@@ -34712,8 +35096,8 @@ async function auditReIdentifyCommand(options) {
|
|
|
34712
35096
|
console.error("[realitydb] --token-map <file> is required for re-identify");
|
|
34713
35097
|
process.exit(1);
|
|
34714
35098
|
}
|
|
34715
|
-
const filePath = (0,
|
|
34716
|
-
const encryptedData = (0,
|
|
35099
|
+
const filePath = (0, import_node_path19.resolve)(options.tokenMap);
|
|
35100
|
+
const encryptedData = (0, import_node_fs14.readFileSync)(filePath, "utf-8").trim();
|
|
34717
35101
|
const passphrase = await askPassphrase2("Enter passphrase to decrypt token map: ");
|
|
34718
35102
|
if (!passphrase) {
|
|
34719
35103
|
console.error("[realitydb] Passphrase cannot be empty.");
|
|
@@ -34765,9 +35149,9 @@ async function auditReIdentifyCommand(options) {
|
|
|
34765
35149
|
}
|
|
34766
35150
|
|
|
34767
35151
|
// src/commands/classroom.ts
|
|
34768
|
-
var
|
|
34769
|
-
var
|
|
34770
|
-
var
|
|
35152
|
+
var import_node_fs15 = require("fs");
|
|
35153
|
+
var import_node_path20 = require("path");
|
|
35154
|
+
var VERSION15 = "1.3.1";
|
|
34771
35155
|
async function classroomListCommand(options) {
|
|
34772
35156
|
const start = performance.now();
|
|
34773
35157
|
try {
|
|
@@ -34777,7 +35161,7 @@ async function classroomListCommand(options) {
|
|
|
34777
35161
|
console.log(formatCIOutput({
|
|
34778
35162
|
success: true,
|
|
34779
35163
|
command: "classroom list",
|
|
34780
|
-
version:
|
|
35164
|
+
version: VERSION15,
|
|
34781
35165
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34782
35166
|
durationMs,
|
|
34783
35167
|
data: {
|
|
@@ -34813,7 +35197,7 @@ async function classroomListCommand(options) {
|
|
|
34813
35197
|
console.log(formatCIOutput({
|
|
34814
35198
|
success: false,
|
|
34815
35199
|
command: "classroom list",
|
|
34816
|
-
version:
|
|
35200
|
+
version: VERSION15,
|
|
34817
35201
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34818
35202
|
durationMs: Math.round(performance.now() - start),
|
|
34819
35203
|
error: message
|
|
@@ -34844,7 +35228,7 @@ async function classroomStartCommand(courseName, options) {
|
|
|
34844
35228
|
console.log(formatCIOutput({
|
|
34845
35229
|
success: true,
|
|
34846
35230
|
command: "classroom start",
|
|
34847
|
-
version:
|
|
35231
|
+
version: VERSION15,
|
|
34848
35232
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34849
35233
|
durationMs,
|
|
34850
35234
|
data: {
|
|
@@ -34878,7 +35262,7 @@ async function classroomStartCommand(courseName, options) {
|
|
|
34878
35262
|
console.log(formatCIOutput({
|
|
34879
35263
|
success: false,
|
|
34880
35264
|
command: "classroom start",
|
|
34881
|
-
version:
|
|
35265
|
+
version: VERSION15,
|
|
34882
35266
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34883
35267
|
durationMs: Math.round(performance.now() - start),
|
|
34884
35268
|
error: message
|
|
@@ -34908,7 +35292,7 @@ async function classroomStatusCommand(courseName, options) {
|
|
|
34908
35292
|
console.log(formatCIOutput({
|
|
34909
35293
|
success: true,
|
|
34910
35294
|
command: "classroom status",
|
|
34911
|
-
version:
|
|
35295
|
+
version: VERSION15,
|
|
34912
35296
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34913
35297
|
durationMs,
|
|
34914
35298
|
data: { courses: result.courses }
|
|
@@ -34935,7 +35319,7 @@ async function classroomStatusCommand(courseName, options) {
|
|
|
34935
35319
|
console.log(formatCIOutput({
|
|
34936
35320
|
success: false,
|
|
34937
35321
|
command: "classroom status",
|
|
34938
|
-
version:
|
|
35322
|
+
version: VERSION15,
|
|
34939
35323
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34940
35324
|
durationMs: Math.round(performance.now() - start),
|
|
34941
35325
|
error: message
|
|
@@ -34955,7 +35339,7 @@ async function classroomCompleteCommand(courseName, exerciseId, options) {
|
|
|
34955
35339
|
console.log(formatCIOutput({
|
|
34956
35340
|
success: true,
|
|
34957
35341
|
command: "classroom complete",
|
|
34958
|
-
version:
|
|
35342
|
+
version: VERSION15,
|
|
34959
35343
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34960
35344
|
durationMs,
|
|
34961
35345
|
data: { courseName, exerciseId, completed: true }
|
|
@@ -34978,7 +35362,7 @@ async function classroomCompleteCommand(courseName, exerciseId, options) {
|
|
|
34978
35362
|
console.log(formatCIOutput({
|
|
34979
35363
|
success: false,
|
|
34980
35364
|
command: "classroom complete",
|
|
34981
|
-
version:
|
|
35365
|
+
version: VERSION15,
|
|
34982
35366
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34983
35367
|
durationMs: Math.round(performance.now() - start),
|
|
34984
35368
|
error: message
|
|
@@ -34998,7 +35382,7 @@ async function classroomResetCommand(courseName, options) {
|
|
|
34998
35382
|
console.log(formatCIOutput({
|
|
34999
35383
|
success: true,
|
|
35000
35384
|
command: "classroom reset",
|
|
35001
|
-
version:
|
|
35385
|
+
version: VERSION15,
|
|
35002
35386
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35003
35387
|
durationMs,
|
|
35004
35388
|
data: { courseName, reset: true }
|
|
@@ -35013,7 +35397,7 @@ async function classroomResetCommand(courseName, options) {
|
|
|
35013
35397
|
console.log(formatCIOutput({
|
|
35014
35398
|
success: false,
|
|
35015
35399
|
command: "classroom reset",
|
|
35016
|
-
version:
|
|
35400
|
+
version: VERSION15,
|
|
35017
35401
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35018
35402
|
durationMs: Math.round(performance.now() - start),
|
|
35019
35403
|
error: message
|
|
@@ -35029,14 +35413,14 @@ async function classroomCreateCommand(name, options) {
|
|
|
35029
35413
|
try {
|
|
35030
35414
|
const content = classroomCreate(name);
|
|
35031
35415
|
const filename = `${name}.course.json`;
|
|
35032
|
-
const filePath = (0,
|
|
35033
|
-
(0,
|
|
35416
|
+
const filePath = (0, import_node_path20.resolve)(filename);
|
|
35417
|
+
(0, import_node_fs15.writeFileSync)(filePath, content + "\n", "utf-8");
|
|
35034
35418
|
const durationMs = Math.round(performance.now() - start);
|
|
35035
35419
|
if (options.ci) {
|
|
35036
35420
|
console.log(formatCIOutput({
|
|
35037
35421
|
success: true,
|
|
35038
35422
|
command: "classroom create",
|
|
35039
|
-
version:
|
|
35423
|
+
version: VERSION15,
|
|
35040
35424
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35041
35425
|
durationMs,
|
|
35042
35426
|
data: { name, file: filePath }
|
|
@@ -35055,7 +35439,7 @@ async function classroomCreateCommand(name, options) {
|
|
|
35055
35439
|
console.log(formatCIOutput({
|
|
35056
35440
|
success: false,
|
|
35057
35441
|
command: "classroom create",
|
|
35058
|
-
version:
|
|
35442
|
+
version: VERSION15,
|
|
35059
35443
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35060
35444
|
durationMs: Math.round(performance.now() - start),
|
|
35061
35445
|
error: message
|
|
@@ -35074,7 +35458,7 @@ function buildProgressBar(percent) {
|
|
|
35074
35458
|
}
|
|
35075
35459
|
|
|
35076
35460
|
// src/commands/simulate.ts
|
|
35077
|
-
var
|
|
35461
|
+
var VERSION16 = "1.3.1";
|
|
35078
35462
|
async function simulateRunCommand(options) {
|
|
35079
35463
|
const start = performance.now();
|
|
35080
35464
|
try {
|
|
@@ -35106,7 +35490,7 @@ async function simulateRunCommand(options) {
|
|
|
35106
35490
|
console.log(formatCIOutput({
|
|
35107
35491
|
success: true,
|
|
35108
35492
|
command: "simulate run",
|
|
35109
|
-
version:
|
|
35493
|
+
version: VERSION16,
|
|
35110
35494
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35111
35495
|
durationMs,
|
|
35112
35496
|
data: {
|
|
@@ -35130,7 +35514,7 @@ async function simulateRunCommand(options) {
|
|
|
35130
35514
|
console.log(formatCIOutput({
|
|
35131
35515
|
success: false,
|
|
35132
35516
|
command: "simulate run",
|
|
35133
|
-
version:
|
|
35517
|
+
version: VERSION16,
|
|
35134
35518
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35135
35519
|
durationMs: Math.round(performance.now() - start),
|
|
35136
35520
|
error: message
|
|
@@ -35150,7 +35534,7 @@ async function simulateProfilesCommand(options) {
|
|
|
35150
35534
|
console.log(formatCIOutput({
|
|
35151
35535
|
success: true,
|
|
35152
35536
|
command: "simulate profiles",
|
|
35153
|
-
version:
|
|
35537
|
+
version: VERSION16,
|
|
35154
35538
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35155
35539
|
durationMs,
|
|
35156
35540
|
data: {
|
|
@@ -35185,7 +35569,7 @@ async function simulateProfilesCommand(options) {
|
|
|
35185
35569
|
console.log(formatCIOutput({
|
|
35186
35570
|
success: false,
|
|
35187
35571
|
command: "simulate profiles",
|
|
35188
|
-
version:
|
|
35572
|
+
version: VERSION16,
|
|
35189
35573
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35190
35574
|
durationMs: Math.round(performance.now() - start),
|
|
35191
35575
|
error: message
|
|
@@ -35209,7 +35593,7 @@ async function simulateWebhooksCommand(options) {
|
|
|
35209
35593
|
console.log(formatCIOutput({
|
|
35210
35594
|
success: false,
|
|
35211
35595
|
command: "simulate webhooks",
|
|
35212
|
-
version:
|
|
35596
|
+
version: VERSION16,
|
|
35213
35597
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35214
35598
|
durationMs: Math.round(performance.now() - start),
|
|
35215
35599
|
error: msg
|
|
@@ -35242,7 +35626,7 @@ async function simulateWebhooksCommand(options) {
|
|
|
35242
35626
|
console.log(formatCIOutput({
|
|
35243
35627
|
success: true,
|
|
35244
35628
|
command: "simulate webhooks",
|
|
35245
|
-
version:
|
|
35629
|
+
version: VERSION16,
|
|
35246
35630
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35247
35631
|
durationMs,
|
|
35248
35632
|
data: {
|
|
@@ -35267,7 +35651,7 @@ async function simulateWebhooksCommand(options) {
|
|
|
35267
35651
|
console.log(formatCIOutput({
|
|
35268
35652
|
success: false,
|
|
35269
35653
|
command: "simulate webhooks",
|
|
35270
|
-
version:
|
|
35654
|
+
version: VERSION16,
|
|
35271
35655
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
35272
35656
|
durationMs: Math.round(performance.now() - start),
|
|
35273
35657
|
error: message
|
|
@@ -35280,11 +35664,11 @@ async function simulateWebhooksCommand(options) {
|
|
|
35280
35664
|
}
|
|
35281
35665
|
|
|
35282
35666
|
// src/cli.ts
|
|
35283
|
-
var
|
|
35667
|
+
var VERSION17 = "1.9.0";
|
|
35284
35668
|
function run(argv) {
|
|
35285
35669
|
const program2 = new Command();
|
|
35286
|
-
program2.name("realitydb").description("RealityDB
|
|
35287
|
-
program2.command("init").description("Interactive setup wizard
|
|
35670
|
+
program2.name("realitydb").description("RealityDB -- Developer Reality Platform").version(VERSION17).option("--config <path>", "Path to config file").option("--ci", "CI mode: JSON output, no prompts, proper exit codes", false).option("--verbose", "Enable verbose output", false);
|
|
35671
|
+
program2.command("init").description("Interactive setup wizard -- connect, scan, and seed in one step").action(async () => {
|
|
35288
35672
|
await initCommand();
|
|
35289
35673
|
});
|
|
35290
35674
|
program2.command("scan").description("Scan database schema").action(async () => {
|
|
@@ -35295,7 +35679,7 @@ function run(argv) {
|
|
|
35295
35679
|
const opts = program2.opts();
|
|
35296
35680
|
await analyzeCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
|
|
35297
35681
|
});
|
|
35298
|
-
program2.command("seed").description("Seed database with generated data").option("--records <count>", "Number of records per table").option("--template <name|path>", "Template name or path to custom .json file").option("--seed <number>", "Random seed for reproducibility").option("--timeline <duration>", 'Timeline duration (e.g., "12-months", "1-year")').option("--scenario <names>", "Scenarios to apply (comma-separated)").option("--scenario-intensity <level>", "Scenario intensity (low|medium|high)", "medium").option("--scenario-schedule <schedule>", 'Timeline-scheduled scenarios (e.g., "fraud-spike:month-6,churn-spike:month-9")').option("--lifecycle", "Enable lifecycle simulation for causally-connected data").option("--auto-template", "Run analyze
|
|
35682
|
+
program2.command("seed").description("Seed database with generated data").option("--records <count>", "Number of records per table").option("--template <name|path>", "Template name or path to custom .json file").option("--seed <number>", "Random seed for reproducibility").option("--timeline <duration>", 'Timeline duration (e.g., "12-months", "1-year")').option("--scenario <names>", "Scenarios to apply (comma-separated)").option("--scenario-intensity <level>", "Scenario intensity (low|medium|high)", "medium").option("--scenario-schedule <schedule>", 'Timeline-scheduled scenarios (e.g., "fraud-spike:month-6,churn-spike:month-9")').option("--lifecycle", "Enable lifecycle simulation for causally-connected data").option("--auto-template", "Run analyze, generate template, and seed in one command").action(async (cmdOpts) => {
|
|
35299
35683
|
const opts = program2.opts();
|
|
35300
35684
|
await seedCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
|
|
35301
35685
|
});
|
|
@@ -35311,6 +35695,10 @@ function run(argv) {
|
|
|
35311
35695
|
const opts = program2.opts();
|
|
35312
35696
|
await generateCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
|
|
35313
35697
|
});
|
|
35698
|
+
program2.command("run").description("Create schema and seed database from a Studio-exported template pack").requiredOption("--pack <path>", "Path to Studio template JSON file").requiredOption("--connection <url>", "Database connection string").option("--records <count>", "Number of records per table (overrides template config)").option("--seed <number>", "Random seed for reproducibility (overrides template config)").option("--drop-existing", "Drop and recreate tables if they already exist").option("--dry-run", "Show DDL and plan without executing").action(async (cmdOpts) => {
|
|
35699
|
+
const opts = program2.opts();
|
|
35700
|
+
await runCommand({ ...cmdOpts, ci: opts.ci });
|
|
35701
|
+
});
|
|
35314
35702
|
const templates = program2.command("templates").description("Template management");
|
|
35315
35703
|
templates.command("list", { isDefault: true }).description("List available domain templates").action(templatesCommand);
|
|
35316
35704
|
templates.command("init").description("Scaffold a new custom template JSON file").action(templatesInitCommand);
|
|
@@ -35407,10 +35795,10 @@ function run(argv) {
|
|
|
35407
35795
|
program2.action(() => {
|
|
35408
35796
|
const opts = program2.opts();
|
|
35409
35797
|
if (opts.ci) {
|
|
35410
|
-
console.log(JSON.stringify({ name: "realitydb", version:
|
|
35798
|
+
console.log(JSON.stringify({ name: "realitydb", version: VERSION17 }));
|
|
35411
35799
|
} else {
|
|
35412
35800
|
console.log("");
|
|
35413
|
-
console.log(`RealityDB v${
|
|
35801
|
+
console.log(`RealityDB v${VERSION17} -- Developer Reality Platform`);
|
|
35414
35802
|
console.log("Run `realitydb --help` for available commands.");
|
|
35415
35803
|
console.log("");
|
|
35416
35804
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "realitydb",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Developer Reality Platform - realistic database environments from your schema",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@databox/config": "workspace:^",
|
|
49
49
|
"@databox/core": "workspace:^",
|
|
50
|
+
"@databox/db": "workspace:^",
|
|
50
51
|
"@databox/generators": "workspace:^",
|
|
51
52
|
"@databox/schema": "workspace:^",
|
|
52
53
|
"@databox/shared": "workspace:^",
|