realitydb 1.7.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.
Files changed (2) hide show
  1. package/dist/index.js +634 -120
  2. 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(resolve13, reject, localErr) {
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
- resolve13([rows, fields]);
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((resolve13, reject) => {
20994
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13) => {
21003
+ return new this.Promise((resolve14) => {
21004
21004
  this.statement.close();
21005
- resolve13();
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((resolve13, reject) => {
21075
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
21092
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13) => {
21102
- this.connection.end(resolve13);
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((resolve13, reject) => {
21114
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
21122
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
21130
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
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
- resolve13(true);
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((resolve13, reject) => {
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
- resolve13(param);
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((resolve13, reject) => {
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
- resolve13(wrappedStatement);
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((resolve13, reject) => {
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
- resolve13();
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((resolve13, reject) => {
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
- resolve13(new PromisePoolConnection(coreConnection, this.Promise));
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((resolve13, reject) => {
21571
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
21588
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
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
- resolve13();
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((resolve13, reject) => {
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
- resolve13(new PromisePoolConnection(coreConnection, this.Promise));
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((resolve13, reject) => {
22073
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
22086
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
22121
+ return new thePromise((resolve14, reject) => {
22122
22122
  coreConnection.once("connect", () => {
22123
- resolve13(new PromiseConnection(coreConnection, thePromise));
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((resolve13, reject) => {
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
- resolve13(new PromisePoolConnection(coreConnection, this.Promise));
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((resolve13, reject) => {
22176
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
22189
- const done = makeDoneCb(resolve13, reject, localErr);
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((resolve13, reject) => {
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
- resolve13();
22212
+ resolve14();
22213
22213
  }
22214
22214
  });
22215
22215
  });
@@ -22938,11 +22938,13 @@ function generateEnum(ctx, values, weights) {
22938
22938
  if (!weights || weights.length === 0) {
22939
22939
  result = ctx.seed.pick(values);
22940
22940
  } else {
22941
+ const sum = weights.reduce((a, b) => a + b, 0);
22942
+ const normalized = sum > 0 && Math.abs(sum - 1) > 1e-3 ? weights.map((w) => w / sum) : weights;
22941
22943
  const roll = ctx.seed.next();
22942
22944
  let cumulative = 0;
22943
22945
  result = values[values.length - 1];
22944
22946
  for (let i = 0; i < values.length; i++) {
22945
- cumulative += weights[i];
22947
+ cumulative += normalized[i];
22946
22948
  if (roll < cumulative) {
22947
22949
  result = values[i];
22948
22950
  break;
@@ -23185,6 +23187,10 @@ function generateDataset(plan) {
23185
23187
  }
23186
23188
  }
23187
23189
  }
23190
+ if (tablePlan.temporalConstraints && tablePlan.temporalConstraints.length > 0) {
23191
+ applyTemporalFixup(row, tablePlan.temporalConstraints, seed);
23192
+ }
23193
+ applyLifecycleRules(row, tablePlan.columns);
23188
23194
  rows.push(row);
23189
23195
  }
23190
23196
  const generatedTable = {
@@ -23206,6 +23212,49 @@ function generateDataset(plan) {
23206
23212
  totalRows
23207
23213
  };
23208
23214
  }
23215
+ function applyTemporalFixup(row, constraints, seed) {
23216
+ for (const constraint of constraints) {
23217
+ if (constraint.mode !== "dependent" || !constraint.afterColumn)
23218
+ continue;
23219
+ const baseValue = row[constraint.afterColumn];
23220
+ const depValue = row[constraint.columnName];
23221
+ if (baseValue == null || depValue == null)
23222
+ continue;
23223
+ if (typeof baseValue !== "string" && !(baseValue instanceof Date))
23224
+ continue;
23225
+ const baseDate = new Date(baseValue);
23226
+ if (isNaN(baseDate.getTime()))
23227
+ continue;
23228
+ const depDate = new Date(depValue);
23229
+ const withinDays = constraint.withinDays ?? 90;
23230
+ if (isNaN(depDate.getTime()) || depDate <= baseDate) {
23231
+ const offsetMs = (1 + Math.floor(seed.next() * withinDays)) * 864e5;
23232
+ const newDate = new Date(baseDate.getTime() + offsetMs);
23233
+ row[constraint.columnName] = newDate.toISOString();
23234
+ }
23235
+ }
23236
+ }
23237
+ function applyLifecycleRules(row, columns) {
23238
+ for (const colPlan of columns) {
23239
+ if (colPlan.strategy.kind !== "enum")
23240
+ continue;
23241
+ const lifecycleRules = colPlan.strategy.options?.["lifecycleRules"];
23242
+ if (!lifecycleRules || !Array.isArray(lifecycleRules))
23243
+ continue;
23244
+ const currentValue = row[colPlan.columnName];
23245
+ if (typeof currentValue !== "string")
23246
+ continue;
23247
+ for (const rule of lifecycleRules) {
23248
+ if (rule.value === currentValue && Array.isArray(rule.nullFields)) {
23249
+ for (const field of rule.nullFields) {
23250
+ if (field in row) {
23251
+ row[field] = null;
23252
+ }
23253
+ }
23254
+ }
23255
+ }
23256
+ }
23257
+ }
23209
23258
 
23210
23259
  // ../../packages/generators/dist/exporters/json.js
23211
23260
  var import_promises = require("fs/promises");
@@ -29554,6 +29603,19 @@ function validateTemplateJSON(json) {
29554
29603
  if (c.options !== void 0 && (typeof c.options !== "object" || Array.isArray(c.options))) {
29555
29604
  errors.push(`Table "${tableName}".columns."${colName}": "options" must be an object`);
29556
29605
  }
29606
+ if (c.foreignKey !== void 0) {
29607
+ if (typeof c.foreignKey !== "object" || Array.isArray(c.foreignKey) || c.foreignKey === null) {
29608
+ errors.push(`Table "${tableName}".columns."${colName}": "foreignKey" must be an object`);
29609
+ } else {
29610
+ const fk = c.foreignKey;
29611
+ if (typeof fk.table !== "string" || !fk.table) {
29612
+ errors.push(`Table "${tableName}".columns."${colName}": "foreignKey.table" must be a non-empty string`);
29613
+ }
29614
+ if (typeof fk.column !== "string" || !fk.column) {
29615
+ errors.push(`Table "${tableName}".columns."${colName}": "foreignKey.column" must be a non-empty string`);
29616
+ }
29617
+ }
29618
+ }
29557
29619
  }
29558
29620
  }
29559
29621
  return { valid: errors.length === 0, errors };
@@ -29594,15 +29656,31 @@ function convertToDomainTemplate(json) {
29594
29656
  const columnOverrides = [];
29595
29657
  for (const [colName, colJson] of Object.entries(tableJson.columns)) {
29596
29658
  const col = colJson;
29597
- columnOverrides.push({
29598
- columnName: colName,
29599
- matchPattern: col.match,
29600
- strategy: {
29601
- kind: col.strategy,
29602
- options: col.options
29603
- },
29604
- description: col.description
29605
- });
29659
+ if (col.foreignKey) {
29660
+ columnOverrides.push({
29661
+ columnName: colName,
29662
+ matchPattern: col.match,
29663
+ strategy: {
29664
+ kind: "foreign_key",
29665
+ options: {
29666
+ ...col.options,
29667
+ referencedTable: col.foreignKey.table,
29668
+ referencedColumn: col.foreignKey.column
29669
+ }
29670
+ },
29671
+ description: col.description
29672
+ });
29673
+ } else {
29674
+ columnOverrides.push({
29675
+ columnName: colName,
29676
+ matchPattern: col.match,
29677
+ strategy: {
29678
+ kind: col.strategy,
29679
+ options: col.options
29680
+ },
29681
+ description: col.description
29682
+ });
29683
+ }
29606
29684
  }
29607
29685
  tableConfigs.set(tableName, {
29608
29686
  tableName,
@@ -29616,7 +29694,9 @@ function convertToDomainTemplate(json) {
29616
29694
  version: json.version,
29617
29695
  description: json.description,
29618
29696
  targetTables,
29619
- tableConfigs
29697
+ tableConfigs,
29698
+ simulation: json.simulation,
29699
+ generationConfig: json.generationConfig
29620
29700
  };
29621
29701
  }
29622
29702
 
@@ -29973,7 +30053,7 @@ var fintechLifecycle = {
29973
30053
 
29974
30054
  // ../../packages/core/dist/planning/buildPlan.js
29975
30055
  function buildGenerationPlan(schema, config, timelineConfig) {
29976
- const defaultRowCount = config.seed.defaultRecords;
30056
+ let defaultRowCount = config.seed.defaultRecords;
29977
30057
  const batchSize = config.seed.batchSize;
29978
30058
  const environment = config.seed.environment ?? "dev";
29979
30059
  const randomSeed = config.seed.randomSeed ?? 42;
@@ -30090,18 +30170,41 @@ function buildGenerationPlan(schema, config, timelineConfig) {
30090
30170
  selectionMode: "uniform"
30091
30171
  };
30092
30172
  columnPlan.foreignKeyRef = ref;
30173
+ } else if (strategy.kind === "foreign_key" && strategy.options?.["referencedTable"] && strategy.options?.["referencedColumn"]) {
30174
+ columnPlan.strategy = { kind: "foreign_key" };
30175
+ columnPlan.foreignKeyRef = {
30176
+ referencedTable: strategy.options["referencedTable"],
30177
+ referencedColumn: strategy.options["referencedColumn"],
30178
+ selectionMode: "uniform"
30179
+ };
30093
30180
  }
30094
30181
  return columnPlan;
30095
30182
  });
30183
+ const templateTemporalConstraints = [];
30184
+ for (const colPlan of columns) {
30185
+ const opts = colPlan.strategy.options;
30186
+ if (opts?.["dependsOn"] && typeof opts["dependsOn"] === "string") {
30187
+ templateTemporalConstraints.push({
30188
+ columnName: colPlan.columnName,
30189
+ afterColumn: opts["dependsOn"],
30190
+ mode: "dependent",
30191
+ withinDays: 90
30192
+ });
30193
+ }
30194
+ }
30096
30195
  const rowCount = tableConfig?.rowCountMultiplier ? Math.round(defaultRowCount * tableConfig.rowCountMultiplier) : defaultRowCount;
30097
30196
  const enabled = template ? tableConfig !== null : true;
30098
- return {
30197
+ const tablePlan = {
30099
30198
  tableName: table.name,
30100
30199
  rowCount,
30101
30200
  dependencies: uniqueDeps,
30102
30201
  columns,
30103
30202
  enabled
30104
30203
  };
30204
+ if (templateTemporalConstraints.length > 0) {
30205
+ tablePlan.temporalConstraints = templateTemporalConstraints;
30206
+ }
30207
+ return tablePlan;
30105
30208
  });
30106
30209
  if (template) {
30107
30210
  const enabledSet = new Set(tables.filter((t) => t.enabled).map((t) => t.tableName));
@@ -30452,6 +30555,17 @@ async function batchInsertDataset(client, dataset, tableOrder, batchSize, dialec
30452
30555
  const start = performance.now();
30453
30556
  const results = [];
30454
30557
  let totalRows = 0;
30558
+ const targetTables = tableOrder.filter((name) => dataset.tables.has(name));
30559
+ for (let i = targetTables.length - 1; i >= 0; i--) {
30560
+ const tableName = quoteIdent(dialect, targetTables[i]);
30561
+ if (dialect === "mysql") {
30562
+ await client.query("SET FOREIGN_KEY_CHECKS = 0");
30563
+ await client.query(`TRUNCATE TABLE ${tableName}`);
30564
+ await client.query("SET FOREIGN_KEY_CHECKS = 1");
30565
+ } else {
30566
+ await client.query(`TRUNCATE TABLE ${tableName} CASCADE`);
30567
+ }
30568
+ }
30455
30569
  for (const tableName of tableOrder) {
30456
30570
  const table = dataset.tables.get(tableName);
30457
30571
  if (!table)
@@ -31136,6 +31250,18 @@ async function seedDatabase(config, options) {
31136
31250
  if (options?.template !== void 0) {
31137
31251
  effectiveConfig.template = options.template;
31138
31252
  }
31253
+ if (options?.records === void 0 && effectiveConfig.template) {
31254
+ const isFilePath = effectiveConfig.template.includes("/") || effectiveConfig.template.includes("\\") || effectiveConfig.template.endsWith(".json");
31255
+ if (isFilePath) {
31256
+ try {
31257
+ const tmpl = loadTemplateFromJSON(effectiveConfig.template);
31258
+ if (tmpl.generationConfig?.seed?.defaultRecords) {
31259
+ effectiveConfig.seed.defaultRecords = tmpl.generationConfig.seed.defaultRecords;
31260
+ }
31261
+ } catch {
31262
+ }
31263
+ }
31264
+ }
31139
31265
  const timelineConfig = options?.timeline ? parseTimelineString(options.timeline) : void 0;
31140
31266
  if (timelineConfig) {
31141
31267
  timelineConfig.growthModel.finalCount = effectiveConfig.seed.defaultRecords;
@@ -31653,7 +31779,7 @@ async function uploadToGist(content, options) {
31653
31779
  [options.filename]: { content }
31654
31780
  }
31655
31781
  });
31656
- return new Promise((resolve13, reject) => {
31782
+ return new Promise((resolve14, reject) => {
31657
31783
  const req = import_node_https.default.request({
31658
31784
  hostname: "api.github.com",
31659
31785
  path: "/gists",
@@ -31675,7 +31801,7 @@ async function uploadToGist(content, options) {
31675
31801
  try {
31676
31802
  const parsed = JSON.parse(data);
31677
31803
  const fileEntry = parsed.files[options.filename];
31678
- resolve13({
31804
+ resolve14({
31679
31805
  url: parsed.html_url,
31680
31806
  rawUrl: fileEntry?.raw_url ?? parsed.html_url,
31681
31807
  gistId: parsed.id
@@ -31802,7 +31928,7 @@ function fetchUrl(url, redirectCount = 0) {
31802
31928
  throw new Error("Too many redirects");
31803
31929
  }
31804
31930
  const lib = url.startsWith("https") ? import_node_https2.default : import_node_http.default;
31805
- return new Promise((resolve13, reject) => {
31931
+ return new Promise((resolve14, reject) => {
31806
31932
  const req = lib.get(url, {
31807
31933
  headers: {
31808
31934
  "User-Agent": "realitydb-cli",
@@ -31810,7 +31936,7 @@ function fetchUrl(url, redirectCount = 0) {
31810
31936
  }
31811
31937
  }, (res) => {
31812
31938
  if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
31813
- resolve13(fetchUrl(res.headers.location, redirectCount + 1));
31939
+ resolve14(fetchUrl(res.headers.location, redirectCount + 1));
31814
31940
  return;
31815
31941
  }
31816
31942
  if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
@@ -31823,7 +31949,7 @@ function fetchUrl(url, redirectCount = 0) {
31823
31949
  });
31824
31950
  res.on("end", () => {
31825
31951
  const buffer = Buffer.concat(chunks);
31826
- resolve13(buffer.toString("utf-8"));
31952
+ resolve14(buffer.toString("utf-8"));
31827
31953
  });
31828
31954
  });
31829
31955
  req.on("error", (err) => {
@@ -32331,9 +32457,9 @@ var DEFAULT_CONNECTIONS = {
32331
32457
  };
32332
32458
  var SUPPORTED_CLIENTS = ["postgres", "mysql"];
32333
32459
  function ask(rl, prompt) {
32334
- return new Promise((resolve13) => {
32460
+ return new Promise((resolve14) => {
32335
32461
  rl.question(prompt, (answer) => {
32336
- resolve13(answer);
32462
+ resolve14(answer);
32337
32463
  });
32338
32464
  });
32339
32465
  }
@@ -34292,12 +34418,396 @@ async function analyzeCommand(options) {
34292
34418
  }
34293
34419
  }
34294
34420
 
34295
- // src/commands/mask.ts
34421
+ // src/commands/run.ts
34296
34422
  var import_node_fs12 = require("fs");
34297
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");
34298
34808
  var import_node_readline2 = require("readline");
34299
34809
  var import_node_process2 = require("process");
34300
- var VERSION13 = "1.3.1";
34810
+ var VERSION14 = "1.3.1";
34301
34811
  function askPassphrase(prompt) {
34302
34812
  return new Promise((resolvePromise) => {
34303
34813
  const rl = (0, import_node_readline2.createInterface)({ input: import_node_process2.stdin, output: import_node_process2.stdout });
@@ -34334,7 +34844,7 @@ async function maskCommand(options) {
34334
34844
  console.log(formatCIOutput({
34335
34845
  success: false,
34336
34846
  command: "mask",
34337
- version: VERSION13,
34847
+ version: VERSION14,
34338
34848
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34339
34849
  durationMs: Math.round(performance.now() - start),
34340
34850
  error: msg
@@ -34350,7 +34860,7 @@ async function maskCommand(options) {
34350
34860
  console.log(formatCIOutput({
34351
34861
  success: false,
34352
34862
  command: "mask",
34353
- version: VERSION13,
34863
+ version: VERSION14,
34354
34864
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34355
34865
  durationMs: Math.round(performance.now() - start),
34356
34866
  error: msg
@@ -34401,8 +34911,8 @@ async function maskCommand(options) {
34401
34911
  });
34402
34912
  const durationMs = Math.round(performance.now() - start);
34403
34913
  if (options.auditLog) {
34404
- const auditPath = (0, import_node_path17.resolve)(options.auditLog);
34405
- (0, import_node_fs12.writeFileSync)(auditPath, serializeAuditLog(result.auditLog) + "\n", "utf-8");
34914
+ const auditPath = (0, import_node_path18.resolve)(options.auditLog);
34915
+ (0, import_node_fs13.writeFileSync)(auditPath, serializeAuditLog(result.auditLog) + "\n", "utf-8");
34406
34916
  }
34407
34917
  if (options.tokenMap && result.tokenMap) {
34408
34918
  const passphrase = await askPassphrase("Enter passphrase for token map encryption: ");
@@ -34410,8 +34920,8 @@ async function maskCommand(options) {
34410
34920
  console.error("[realitydb] Passphrase cannot be empty. Token map not written.");
34411
34921
  } else {
34412
34922
  const encryptedData = encryptTokenMap(result.tokenMap, passphrase);
34413
- const tokenMapPath = (0, import_node_path17.resolve)(options.tokenMap);
34414
- (0, import_node_fs12.writeFileSync)(tokenMapPath, encryptedData + "\n", "utf-8");
34923
+ const tokenMapPath = (0, import_node_path18.resolve)(options.tokenMap);
34924
+ (0, import_node_fs13.writeFileSync)(tokenMapPath, encryptedData + "\n", "utf-8");
34415
34925
  if (!options.ci) {
34416
34926
  console.log(`Token map exported (AES-256-GCM encrypted) \u2192 ${tokenMapPath}`);
34417
34927
  console.log(` ${result.tokenMap.totalTokens} unique tokens generated`);
@@ -34424,7 +34934,7 @@ async function maskCommand(options) {
34424
34934
  console.log(formatCIOutput({
34425
34935
  success: true,
34426
34936
  command: "mask",
34427
- version: VERSION13,
34937
+ version: VERSION14,
34428
34938
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34429
34939
  durationMs,
34430
34940
  data: {
@@ -34456,7 +34966,7 @@ async function maskCommand(options) {
34456
34966
  console.log("");
34457
34967
  }
34458
34968
  if (options.auditLog) {
34459
- console.log(`Audit log written to: ${(0, import_node_path17.resolve)(options.auditLog)}`);
34969
+ console.log(`Audit log written to: ${(0, import_node_path18.resolve)(options.auditLog)}`);
34460
34970
  console.log("");
34461
34971
  }
34462
34972
  const totalTime = (durationMs / 1e3).toFixed(1);
@@ -34472,7 +34982,7 @@ async function maskCommand(options) {
34472
34982
  console.log(formatCIOutput({
34473
34983
  success: false,
34474
34984
  command: "mask",
34475
- version: VERSION13,
34985
+ version: VERSION14,
34476
34986
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34477
34987
  durationMs: Math.round(performance.now() - start),
34478
34988
  error: message
@@ -34493,8 +35003,8 @@ async function maskCommand(options) {
34493
35003
  }
34494
35004
 
34495
35005
  // src/commands/audit.ts
34496
- var import_node_fs13 = require("fs");
34497
- var import_node_path18 = require("path");
35006
+ var import_node_fs14 = require("fs");
35007
+ var import_node_path19 = require("path");
34498
35008
  var import_node_readline3 = require("readline");
34499
35009
  var import_node_process3 = require("process");
34500
35010
  function askPassphrase2(prompt) {
@@ -34520,8 +35030,8 @@ function askPassphrase2(prompt) {
34520
35030
  }
34521
35031
  async function auditVerifyCommand(logFile, options) {
34522
35032
  try {
34523
- const filePath = (0, import_node_path18.resolve)(logFile);
34524
- const raw = (0, import_node_fs13.readFileSync)(filePath, "utf-8");
35033
+ const filePath = (0, import_node_path19.resolve)(logFile);
35034
+ const raw = (0, import_node_fs14.readFileSync)(filePath, "utf-8");
34525
35035
  const log = JSON.parse(raw);
34526
35036
  const result = verifyAuditLogIntegrity(log);
34527
35037
  const entryCount = log.tables?.length ?? 0;
@@ -34555,8 +35065,8 @@ async function auditVerifyCommand(logFile, options) {
34555
35065
  }
34556
35066
  async function auditSummaryCommand(logFile, options) {
34557
35067
  try {
34558
- const filePath = (0, import_node_path18.resolve)(logFile);
34559
- const raw = (0, import_node_fs13.readFileSync)(filePath, "utf-8");
35068
+ const filePath = (0, import_node_path19.resolve)(logFile);
35069
+ const raw = (0, import_node_fs14.readFileSync)(filePath, "utf-8");
34560
35070
  const log = JSON.parse(raw);
34561
35071
  if (options.ci) {
34562
35072
  console.log(JSON.stringify({
@@ -34586,8 +35096,8 @@ async function auditReIdentifyCommand(options) {
34586
35096
  console.error("[realitydb] --token-map <file> is required for re-identify");
34587
35097
  process.exit(1);
34588
35098
  }
34589
- const filePath = (0, import_node_path18.resolve)(options.tokenMap);
34590
- const encryptedData = (0, import_node_fs13.readFileSync)(filePath, "utf-8").trim();
35099
+ const filePath = (0, import_node_path19.resolve)(options.tokenMap);
35100
+ const encryptedData = (0, import_node_fs14.readFileSync)(filePath, "utf-8").trim();
34591
35101
  const passphrase = await askPassphrase2("Enter passphrase to decrypt token map: ");
34592
35102
  if (!passphrase) {
34593
35103
  console.error("[realitydb] Passphrase cannot be empty.");
@@ -34639,9 +35149,9 @@ async function auditReIdentifyCommand(options) {
34639
35149
  }
34640
35150
 
34641
35151
  // src/commands/classroom.ts
34642
- var import_node_fs14 = require("fs");
34643
- var import_node_path19 = require("path");
34644
- var VERSION14 = "1.3.1";
35152
+ var import_node_fs15 = require("fs");
35153
+ var import_node_path20 = require("path");
35154
+ var VERSION15 = "1.3.1";
34645
35155
  async function classroomListCommand(options) {
34646
35156
  const start = performance.now();
34647
35157
  try {
@@ -34651,7 +35161,7 @@ async function classroomListCommand(options) {
34651
35161
  console.log(formatCIOutput({
34652
35162
  success: true,
34653
35163
  command: "classroom list",
34654
- version: VERSION14,
35164
+ version: VERSION15,
34655
35165
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34656
35166
  durationMs,
34657
35167
  data: {
@@ -34687,7 +35197,7 @@ async function classroomListCommand(options) {
34687
35197
  console.log(formatCIOutput({
34688
35198
  success: false,
34689
35199
  command: "classroom list",
34690
- version: VERSION14,
35200
+ version: VERSION15,
34691
35201
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34692
35202
  durationMs: Math.round(performance.now() - start),
34693
35203
  error: message
@@ -34718,7 +35228,7 @@ async function classroomStartCommand(courseName, options) {
34718
35228
  console.log(formatCIOutput({
34719
35229
  success: true,
34720
35230
  command: "classroom start",
34721
- version: VERSION14,
35231
+ version: VERSION15,
34722
35232
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34723
35233
  durationMs,
34724
35234
  data: {
@@ -34752,7 +35262,7 @@ async function classroomStartCommand(courseName, options) {
34752
35262
  console.log(formatCIOutput({
34753
35263
  success: false,
34754
35264
  command: "classroom start",
34755
- version: VERSION14,
35265
+ version: VERSION15,
34756
35266
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34757
35267
  durationMs: Math.round(performance.now() - start),
34758
35268
  error: message
@@ -34782,7 +35292,7 @@ async function classroomStatusCommand(courseName, options) {
34782
35292
  console.log(formatCIOutput({
34783
35293
  success: true,
34784
35294
  command: "classroom status",
34785
- version: VERSION14,
35295
+ version: VERSION15,
34786
35296
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34787
35297
  durationMs,
34788
35298
  data: { courses: result.courses }
@@ -34809,7 +35319,7 @@ async function classroomStatusCommand(courseName, options) {
34809
35319
  console.log(formatCIOutput({
34810
35320
  success: false,
34811
35321
  command: "classroom status",
34812
- version: VERSION14,
35322
+ version: VERSION15,
34813
35323
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34814
35324
  durationMs: Math.round(performance.now() - start),
34815
35325
  error: message
@@ -34829,7 +35339,7 @@ async function classroomCompleteCommand(courseName, exerciseId, options) {
34829
35339
  console.log(formatCIOutput({
34830
35340
  success: true,
34831
35341
  command: "classroom complete",
34832
- version: VERSION14,
35342
+ version: VERSION15,
34833
35343
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34834
35344
  durationMs,
34835
35345
  data: { courseName, exerciseId, completed: true }
@@ -34852,7 +35362,7 @@ async function classroomCompleteCommand(courseName, exerciseId, options) {
34852
35362
  console.log(formatCIOutput({
34853
35363
  success: false,
34854
35364
  command: "classroom complete",
34855
- version: VERSION14,
35365
+ version: VERSION15,
34856
35366
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34857
35367
  durationMs: Math.round(performance.now() - start),
34858
35368
  error: message
@@ -34872,7 +35382,7 @@ async function classroomResetCommand(courseName, options) {
34872
35382
  console.log(formatCIOutput({
34873
35383
  success: true,
34874
35384
  command: "classroom reset",
34875
- version: VERSION14,
35385
+ version: VERSION15,
34876
35386
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34877
35387
  durationMs,
34878
35388
  data: { courseName, reset: true }
@@ -34887,7 +35397,7 @@ async function classroomResetCommand(courseName, options) {
34887
35397
  console.log(formatCIOutput({
34888
35398
  success: false,
34889
35399
  command: "classroom reset",
34890
- version: VERSION14,
35400
+ version: VERSION15,
34891
35401
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34892
35402
  durationMs: Math.round(performance.now() - start),
34893
35403
  error: message
@@ -34903,14 +35413,14 @@ async function classroomCreateCommand(name, options) {
34903
35413
  try {
34904
35414
  const content = classroomCreate(name);
34905
35415
  const filename = `${name}.course.json`;
34906
- const filePath = (0, import_node_path19.resolve)(filename);
34907
- (0, import_node_fs14.writeFileSync)(filePath, content + "\n", "utf-8");
35416
+ const filePath = (0, import_node_path20.resolve)(filename);
35417
+ (0, import_node_fs15.writeFileSync)(filePath, content + "\n", "utf-8");
34908
35418
  const durationMs = Math.round(performance.now() - start);
34909
35419
  if (options.ci) {
34910
35420
  console.log(formatCIOutput({
34911
35421
  success: true,
34912
35422
  command: "classroom create",
34913
- version: VERSION14,
35423
+ version: VERSION15,
34914
35424
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34915
35425
  durationMs,
34916
35426
  data: { name, file: filePath }
@@ -34929,7 +35439,7 @@ async function classroomCreateCommand(name, options) {
34929
35439
  console.log(formatCIOutput({
34930
35440
  success: false,
34931
35441
  command: "classroom create",
34932
- version: VERSION14,
35442
+ version: VERSION15,
34933
35443
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34934
35444
  durationMs: Math.round(performance.now() - start),
34935
35445
  error: message
@@ -34948,7 +35458,7 @@ function buildProgressBar(percent) {
34948
35458
  }
34949
35459
 
34950
35460
  // src/commands/simulate.ts
34951
- var VERSION15 = "1.3.1";
35461
+ var VERSION16 = "1.3.1";
34952
35462
  async function simulateRunCommand(options) {
34953
35463
  const start = performance.now();
34954
35464
  try {
@@ -34980,7 +35490,7 @@ async function simulateRunCommand(options) {
34980
35490
  console.log(formatCIOutput({
34981
35491
  success: true,
34982
35492
  command: "simulate run",
34983
- version: VERSION15,
35493
+ version: VERSION16,
34984
35494
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
34985
35495
  durationMs,
34986
35496
  data: {
@@ -35004,7 +35514,7 @@ async function simulateRunCommand(options) {
35004
35514
  console.log(formatCIOutput({
35005
35515
  success: false,
35006
35516
  command: "simulate run",
35007
- version: VERSION15,
35517
+ version: VERSION16,
35008
35518
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35009
35519
  durationMs: Math.round(performance.now() - start),
35010
35520
  error: message
@@ -35024,7 +35534,7 @@ async function simulateProfilesCommand(options) {
35024
35534
  console.log(formatCIOutput({
35025
35535
  success: true,
35026
35536
  command: "simulate profiles",
35027
- version: VERSION15,
35537
+ version: VERSION16,
35028
35538
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35029
35539
  durationMs,
35030
35540
  data: {
@@ -35059,7 +35569,7 @@ async function simulateProfilesCommand(options) {
35059
35569
  console.log(formatCIOutput({
35060
35570
  success: false,
35061
35571
  command: "simulate profiles",
35062
- version: VERSION15,
35572
+ version: VERSION16,
35063
35573
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35064
35574
  durationMs: Math.round(performance.now() - start),
35065
35575
  error: message
@@ -35083,7 +35593,7 @@ async function simulateWebhooksCommand(options) {
35083
35593
  console.log(formatCIOutput({
35084
35594
  success: false,
35085
35595
  command: "simulate webhooks",
35086
- version: VERSION15,
35596
+ version: VERSION16,
35087
35597
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35088
35598
  durationMs: Math.round(performance.now() - start),
35089
35599
  error: msg
@@ -35116,7 +35626,7 @@ async function simulateWebhooksCommand(options) {
35116
35626
  console.log(formatCIOutput({
35117
35627
  success: true,
35118
35628
  command: "simulate webhooks",
35119
- version: VERSION15,
35629
+ version: VERSION16,
35120
35630
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35121
35631
  durationMs,
35122
35632
  data: {
@@ -35141,7 +35651,7 @@ async function simulateWebhooksCommand(options) {
35141
35651
  console.log(formatCIOutput({
35142
35652
  success: false,
35143
35653
  command: "simulate webhooks",
35144
- version: VERSION15,
35654
+ version: VERSION16,
35145
35655
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
35146
35656
  durationMs: Math.round(performance.now() - start),
35147
35657
  error: message
@@ -35154,11 +35664,11 @@ async function simulateWebhooksCommand(options) {
35154
35664
  }
35155
35665
 
35156
35666
  // src/cli.ts
35157
- var VERSION16 = "1.7.0";
35667
+ var VERSION17 = "1.9.0";
35158
35668
  function run(argv) {
35159
35669
  const program2 = new Command();
35160
- program2.name("realitydb").description("RealityDB \xC3\u0192\xC6\u2019\xC3\u2020\xE2\u20AC\u2122\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xA2\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u20AC\u0161\xC2\xAC\xC3\u2026\xC2\xA1\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xAC\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u201A\xAC\xC5\xA1\xC3\u201A\xC2\xAC\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\x9D Developer Reality Platform").version(VERSION16).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);
35161
- program2.command("init").description("Interactive setup wizard \xC3\u0192\xC6\u2019\xC3\u2020\xE2\u20AC\u2122\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xA2\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u20AC\u0161\xC2\xAC\xC3\u2026\xC2\xA1\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xAC\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u201A\xAC\xC5\xA1\xC3\u201A\xC2\xAC\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\x9D connect, scan, and seed in one step").action(async () => {
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 () => {
35162
35672
  await initCommand();
35163
35673
  });
35164
35674
  program2.command("scan").description("Scan database schema").action(async () => {
@@ -35169,7 +35679,7 @@ function run(argv) {
35169
35679
  const opts = program2.opts();
35170
35680
  await analyzeCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
35171
35681
  });
35172
- 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 \xE2\u2020\u2019 generate template \xE2\u2020\u2019 seed in one command").action(async (cmdOpts) => {
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) => {
35173
35683
  const opts = program2.opts();
35174
35684
  await seedCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
35175
35685
  });
@@ -35185,6 +35695,10 @@ function run(argv) {
35185
35695
  const opts = program2.opts();
35186
35696
  await generateCommand({ ...cmdOpts, ci: opts.ci, configPath: opts.config });
35187
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
+ });
35188
35702
  const templates = program2.command("templates").description("Template management");
35189
35703
  templates.command("list", { isDefault: true }).description("List available domain templates").action(templatesCommand);
35190
35704
  templates.command("init").description("Scaffold a new custom template JSON file").action(templatesInitCommand);
@@ -35281,10 +35795,10 @@ function run(argv) {
35281
35795
  program2.action(() => {
35282
35796
  const opts = program2.opts();
35283
35797
  if (opts.ci) {
35284
- console.log(JSON.stringify({ name: "realitydb", version: VERSION16 }));
35798
+ console.log(JSON.stringify({ name: "realitydb", version: VERSION17 }));
35285
35799
  } else {
35286
35800
  console.log("");
35287
- console.log(`RealityDB v${VERSION16} \xC3\u0192\xC6\u2019\xC3\u2020\xE2\u20AC\u2122\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xA2\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u20AC\u0161\xC2\xAC\xC3\u2026\xC2\xA1\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\xAC\xC3\u0192\xC6\u2019\xC3\u201A\xC2\xA2\xC3\u0192\xC2\xA2\xC3\xA2\xE2\u201A\xAC\xC5\xA1\xC3\u201A\xC2\xAC\xC3\u0192\xE2\u20AC\u0161\xC3\u201A\xC2\x9D Developer Reality Platform`);
35801
+ console.log(`RealityDB v${VERSION17} -- Developer Reality Platform`);
35288
35802
  console.log("Run `realitydb --help` for available commands.");
35289
35803
  console.log("");
35290
35804
  }