@tradejs/cli 3.1.3 → 3.1.5

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.
@@ -5013,8 +5013,7 @@ var persistTestSummariesIndex = async () => {
5013
5013
  };
5014
5014
  var validateBacktestRuntimeDeployment = ({
5015
5015
  deployment,
5016
- deploymentId,
5017
- requestedInterval
5016
+ deploymentId
5018
5017
  }) => {
5019
5018
  if (deploymentId && !deployment) {
5020
5019
  throw new Error(`Runtime deployment not found: ${deploymentId}`);
@@ -5022,18 +5021,12 @@ var validateBacktestRuntimeDeployment = ({
5022
5021
  if (deployment && !deployment.enabled) {
5023
5022
  throw new Error(`Runtime deployment is disabled: ${deployment.id}`);
5024
5023
  }
5025
- if (deployment && String(deployment.interval) !== String(requestedInterval)) {
5026
- throw new Error(
5027
- `Deployment ${deployment.id} requires timeframe ${deployment.interval}; received ${requestedInterval}`
5028
- );
5029
- }
5030
5024
  return deployment;
5031
5025
  };
5032
5026
  var prepareRunEnvironment2 = async () => {
5033
5027
  const deployment = validateBacktestRuntimeDeployment({
5034
5028
  deployment: flags.deployment ? await (0, import_runtimeDeployments.getRuntimeDeployment)(userName, String(flags.deployment)) : null,
5035
- deploymentId: typeof flags.deployment === "string" ? flags.deployment : void 0,
5036
- requestedInterval: interval
5029
+ deploymentId: typeof flags.deployment === "string" ? flags.deployment : void 0
5037
5030
  });
5038
5031
  const preparedRun = await prepareRunEnvironment({
5039
5032
  connector: deployment?.connectorName ?? flags.connector,
@@ -5048,7 +5041,7 @@ var prepareRunEnvironment2 = async () => {
5048
5041
  cacheOnly: flags.cacheOnly,
5049
5042
  interval,
5050
5043
  projectRoot,
5051
- universe: deployment?.universe ?? marketUniverse,
5044
+ universe: marketUniverse,
5052
5045
  accountId: deployment?.accountId ?? flags.account,
5053
5046
  deploymentId: deployment?.id,
5054
5047
  assetClasses: deployment?.assetClasses,
@@ -5708,15 +5701,7 @@ var backtest = async () => {
5708
5701
  preparedRun.connectorName,
5709
5702
  interval
5710
5703
  ).map((test) => {
5711
- const deploymentStrategy = preparedRun.deployment?.strategies.find(
5712
- ({ strategyName }) => strategyName === config.strategyName
5713
- );
5714
- if (deploymentStrategy?.enabled === false) {
5715
- throw new Error(
5716
- `Strategy ${config.strategyName} is disabled in deployment ${preparedRun.deployment?.id}`
5717
- );
5718
- }
5719
- const policyProfileId = (typeof flags.policyProfile === "string" && flags.policyProfile.trim() ? flags.policyProfile.trim() : deploymentStrategy?.policyProfileId) || void 0;
5704
+ const policyProfileId = (typeof flags.policyProfile === "string" && flags.policyProfile.trim() ? flags.policyProfile.trim() : void 0) || void 0;
5720
5705
  return {
5721
5706
  ...test,
5722
5707
  instrument: preparedRun.instrumentsBySymbol.get(
@@ -5728,7 +5713,6 @@ var backtest = async () => {
5728
5713
  policyProfileId,
5729
5714
  strategyConfig: {
5730
5715
  ...test.strategyConfig,
5731
- ...deploymentStrategy?.config,
5732
5716
  ...policyProfileId ? { POLICY_PROFILE_ID: policyProfileId } : {}
5733
5717
  }
5734
5718
  };
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/scripts/runtimeConfig.ts
31
31
  var runtimeConfig_exports = {};
32
32
  __export(runtimeConfig_exports, {
33
- buildBootstrapRuntimeDeployment: () => buildBootstrapRuntimeDeployment,
33
+ RUNTIME_CONFIG_ACTIONS: () => RUNTIME_CONFIG_ACTIONS,
34
+ buildProvisionedRuntimeDeployment: () => buildProvisionedRuntimeDeployment,
34
35
  isEquivalentRuntimeStrategyRelease: () => isEquivalentRuntimeStrategyRelease,
35
36
  main: () => main,
36
37
  pointRuntimeDeploymentAtRelease: () => pointRuntimeDeploymentAtRelease,
@@ -42,11 +43,19 @@ var import_promises = require("fs/promises");
42
43
  var import_node_path = __toESM(require("path"));
43
44
  var import_node_util = require("util");
44
45
  var import_runtimeDeployments = require("@tradejs/infra/runtimeDeployments");
45
- var import_runtimeStrategyConfigs = require("@tradejs/infra/runtimeStrategyConfigs");
46
46
  var import_runtimeStrategyReleases = require("@tradejs/infra/runtimeStrategyReleases");
47
47
  var import_runtimeStrategies = require("@tradejs/node/runtimeStrategies");
48
48
  var import_strategies = require("@tradejs/node/strategies");
49
49
  var argv = process.argv.slice(2);
50
+ var RUNTIME_CONFIG_ACTIONS = [
51
+ "inspect",
52
+ "verify",
53
+ "provision",
54
+ "rollout",
55
+ "pause",
56
+ "resume",
57
+ "rollback"
58
+ ];
50
59
  var action = argv[0] ?? "inspect";
51
60
  var option = (name) => {
52
61
  const index = argv.indexOf(`--${name}`);
@@ -67,28 +76,26 @@ var OPERATIONAL_CONFIG_KEYS = [
67
76
  "ENABLE",
68
77
  "ENV",
69
78
  "MAKE_ORDERS",
70
- "RECORD_RUNTIME_TRADES",
71
- "configId"
79
+ "RECORD_RUNTIME_TRADES"
72
80
  ];
81
+ var requireRuntimePackageIdentity = (strategyName, metadata) => {
82
+ if (!metadata.strategyPackage || !metadata.strategyPackageVersion || !metadata.runtimePackageVersion) {
83
+ throw new Error(
84
+ `Runtime package manifest is incomplete for ${strategyName}`
85
+ );
86
+ }
87
+ return {
88
+ strategyPackage: metadata.strategyPackage,
89
+ strategyPackageVersion: metadata.strategyPackageVersion,
90
+ runtimePackageVersion: metadata.runtimePackageVersion
91
+ };
92
+ };
73
93
  var toReleaseConfig = async (strategyName, sourceConfig) => {
74
94
  const defaults = await (0, import_strategies.getStrategyDefaults)(strategyName, projectRoot) ?? {};
75
95
  const config = { ...defaults, ...sourceConfig };
76
96
  for (const key of OPERATIONAL_CONFIG_KEYS) delete config[key];
77
97
  return config;
78
98
  };
79
- var writeMigrationBackup = async (payload) => {
80
- const directory = import_node_path.default.join(projectRoot, "data", "runtime-config-backups");
81
- await (0, import_promises.mkdir)(directory, { recursive: true });
82
- const backupPath = import_node_path.default.join(
83
- directory,
84
- `${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.json`
85
- );
86
- await (0, import_promises.writeFile)(backupPath, `${JSON.stringify(payload, null, 2)}
87
- `, {
88
- flag: "wx"
89
- });
90
- return backupPath;
91
- };
92
99
  var publish = async ({
93
100
  strategyName,
94
101
  sourceConfig
@@ -98,31 +105,29 @@ var publish = async ({
98
105
  strategyName,
99
106
  projectRoot
100
107
  });
108
+ const packageIdentity = requireRuntimePackageIdentity(strategyName, metadata);
101
109
  return (0, import_runtimeStrategyReleases.publishRuntimeStrategyRelease)({
102
110
  userName,
103
111
  strategyName,
104
112
  config,
105
- ...metadata,
113
+ ...packageIdentity,
106
114
  createdBy: `cli:${userName}`
107
115
  });
108
116
  };
109
- var buildBootstrapRuntimeDeployment = ({
117
+ var buildProvisionedRuntimeDeployment = ({
110
118
  deploymentId,
111
119
  label,
112
120
  connectorName,
113
121
  provider,
114
122
  accountId,
115
123
  strategyName,
116
- releaseVersion,
117
- config
124
+ releaseVersion
118
125
  }) => ({
119
126
  id: deploymentId,
120
127
  label,
121
128
  connectorName,
122
129
  provider,
123
130
  accountId,
124
- universe: config.UNIVERSE,
125
- interval: String(config.INTERVAL),
126
131
  enabled: true,
127
132
  strategies: [
128
133
  {
@@ -139,7 +144,7 @@ var isEquivalentRuntimeStrategyRelease = ({
139
144
  strategyPackageVersion,
140
145
  runtimePackageVersion
141
146
  }) => Boolean(
142
- release && (0, import_node_util.isDeepStrictEqual)(release.config, config) && (release.strategyPackage ?? null) === (strategyPackage ?? null) && (release.strategyPackageVersion ?? null) === (strategyPackageVersion ?? null) && (release.runtimePackageVersion ?? null) === (runtimePackageVersion ?? null)
147
+ release && (0, import_node_util.isDeepStrictEqual)(release.config, config) && release.strategyPackage === strategyPackage && release.strategyPackageVersion === strategyPackageVersion && release.runtimePackageVersion === runtimePackageVersion
143
148
  );
144
149
  var pointRuntimeDeploymentAtRelease = ({
145
150
  deployment,
@@ -155,7 +160,7 @@ var pointRuntimeDeploymentAtRelease = ({
155
160
  } : strategy
156
161
  )
157
162
  });
158
- var bootstrap = async () => {
163
+ var provision = async () => {
159
164
  const strategyName = required("strategy");
160
165
  const deploymentId = required("deployment");
161
166
  const accountId = required("account");
@@ -173,15 +178,14 @@ var bootstrap = async () => {
173
178
  );
174
179
  }
175
180
  const releaseConfig = await toReleaseConfig(strategyName, sourceConfig);
176
- const previewDeployment = buildBootstrapRuntimeDeployment({
181
+ const previewDeployment = buildProvisionedRuntimeDeployment({
177
182
  deploymentId,
178
183
  label,
179
184
  connectorName,
180
185
  provider,
181
186
  accountId,
182
187
  strategyName,
183
- releaseVersion: 1,
184
- config: releaseConfig
188
+ releaseVersion: 1
185
189
  });
186
190
  if (!hasFlag("write")) {
187
191
  console.log(
@@ -203,93 +207,21 @@ var bootstrap = async () => {
203
207
  );
204
208
  return;
205
209
  }
206
- const backupPath = await writeMigrationBackup({
207
- userName,
208
- capturedAt: Date.now(),
209
- reason: "bootstrap",
210
- sourceConfig
211
- });
212
210
  const release = await publish({ strategyName, sourceConfig });
213
211
  const deployment = await (0, import_runtimeDeployments.saveRuntimeDeployment)(
214
212
  userName,
215
- buildBootstrapRuntimeDeployment({
213
+ buildProvisionedRuntimeDeployment({
216
214
  deploymentId,
217
215
  label,
218
216
  connectorName,
219
217
  provider,
220
218
  accountId,
221
219
  strategyName,
222
- releaseVersion: release.releaseVersion,
223
- config: release.config
220
+ releaseVersion: release.releaseVersion
224
221
  })
225
222
  );
226
223
  console.log(
227
- JSON.stringify(
228
- { bootstrapped: true, backupPath, release, deployment },
229
- null,
230
- 2
231
- )
232
- );
233
- };
234
- var migrate = async () => {
235
- const strategyName = required("strategy");
236
- const configId = option("config") ?? "config";
237
- const deploymentId = required("deployment");
238
- const [sourceConfig, deployment] = await Promise.all([
239
- (0, import_runtimeStrategyConfigs.getRuntimeStrategyConfig)(userName, strategyName, configId),
240
- (0, import_runtimeDeployments.getRuntimeDeployment)(userName, deploymentId)
241
- ]);
242
- if (!sourceConfig) {
243
- throw new Error(`Legacy config not found: ${strategyName}:${configId}`);
244
- }
245
- if (!deployment) throw new Error(`Deployment not found: ${deploymentId}`);
246
- const reference = deployment.strategies.find(
247
- (strategy) => strategy.strategyName === strategyName
248
- );
249
- if (!reference) {
250
- throw new Error(`${strategyName} is not bound to ${deploymentId}`);
251
- }
252
- const preview = {
253
- source: { configId, config: sourceConfig },
254
- releaseConfig: await toReleaseConfig(strategyName, sourceConfig),
255
- deployment: {
256
- id: deployment.id,
257
- accountId: deployment.accountId,
258
- strategy: {
259
- strategyName,
260
- releaseVersion: "<allocated on write>",
261
- controlState: "entries_paused"
262
- }
263
- }
264
- };
265
- if (!hasFlag("write")) {
266
- console.log(JSON.stringify({ dryRun: true, ...preview }, null, 2));
267
- return;
268
- }
269
- const backupPath = await writeMigrationBackup({
270
- userName,
271
- capturedAt: Date.now(),
272
- deployment,
273
- legacyConfig: sourceConfig
274
- });
275
- const release = await publish({ strategyName, sourceConfig });
276
- const updatedDeployment = {
277
- ...deployment,
278
- strategies: deployment.strategies.map(
279
- (strategy) => strategy.strategyName === strategyName ? {
280
- strategyName,
281
- releaseVersion: release.releaseVersion,
282
- controlState: "entries_paused"
283
- } : strategy
284
- )
285
- };
286
- await (0, import_runtimeDeployments.saveRuntimeDeployment)(userName, updatedDeployment);
287
- console.log(
288
- JSON.stringify(
289
- { migrated: true, backupPath, release, deployment: updatedDeployment },
290
- null,
291
- 2
292
- )
224
+ JSON.stringify({ provisioned: true, release, deployment }, null, 2)
293
225
  );
294
226
  };
295
227
  var rollout = async () => {
@@ -306,18 +238,18 @@ var rollout = async () => {
306
238
  const reference = deployment.strategies.find(
307
239
  (strategy) => strategy.strategyName === strategyName
308
240
  );
309
- if (!reference?.releaseVersion) {
310
- throw new Error(`${strategyName} is not a versioned deployment reference`);
311
- }
241
+ if (!reference)
242
+ throw new Error(`${strategyName} is not bound to ${deploymentId}`);
312
243
  const [config, metadata, currentRelease] = await Promise.all([
313
244
  toReleaseConfig(strategyName, sourceConfig),
314
245
  (0, import_runtimeStrategies.getRuntimeStrategyPackageMetadata)({ strategyName, projectRoot }),
315
246
  (0, import_runtimeStrategyReleases.getRuntimeStrategyRelease)(userName, strategyName, reference.releaseVersion)
316
247
  ]);
248
+ const packageIdentity = requireRuntimePackageIdentity(strategyName, metadata);
317
249
  const unchanged = isEquivalentRuntimeStrategyRelease({
318
250
  release: currentRelease,
319
251
  config,
320
- ...metadata
252
+ ...packageIdentity
321
253
  });
322
254
  const preview = {
323
255
  deploymentId,
@@ -326,7 +258,7 @@ var rollout = async () => {
326
258
  nextControlState: "entries_paused",
327
259
  unchanged,
328
260
  config,
329
- ...metadata
261
+ ...packageIdentity
330
262
  };
331
263
  if (!hasFlag("write")) {
332
264
  console.log(JSON.stringify({ dryRun: true, ...preview }, null, 2));
@@ -347,19 +279,11 @@ var rollout = async () => {
347
279
  );
348
280
  return;
349
281
  }
350
- const backupPath = await writeMigrationBackup({
351
- userName,
352
- capturedAt: Date.now(),
353
- reason: "rollout",
354
- deployment,
355
- currentRelease,
356
- sourceConfig
357
- });
358
282
  const release = await (0, import_runtimeStrategyReleases.publishRuntimeStrategyRelease)({
359
283
  userName,
360
284
  strategyName,
361
285
  config,
362
- ...metadata,
286
+ ...packageIdentity,
363
287
  createdBy: `cli:${userName}`
364
288
  });
365
289
  const updatedDeployment = pointRuntimeDeploymentAtRelease({
@@ -372,7 +296,6 @@ var rollout = async () => {
372
296
  JSON.stringify(
373
297
  {
374
298
  rolledOut: true,
375
- backupPath,
376
299
  release,
377
300
  deployment: updatedDeployment
378
301
  },
@@ -381,13 +304,6 @@ var rollout = async () => {
381
304
  )
382
305
  );
383
306
  };
384
- var publishDraft = async () => {
385
- const strategyName = required("strategy");
386
- const draft = await (0, import_runtimeStrategyReleases.getRuntimeStrategyDraft)(userName, strategyName);
387
- if (!draft) throw new Error(`Draft not found: ${strategyName}`);
388
- const release = await publish({ strategyName, sourceConfig: draft.config });
389
- console.log(JSON.stringify({ release }, null, 2));
390
- };
391
307
  var updateControlState = async (nextState) => {
392
308
  const strategyName = required("strategy");
393
309
  const deploymentId = required("deployment");
@@ -396,10 +312,9 @@ var updateControlState = async (nextState) => {
396
312
  const reference = deployment.strategies.find(
397
313
  (strategy) => strategy.strategyName === strategyName
398
314
  );
399
- if (!reference?.releaseVersion) {
400
- throw new Error(`${strategyName} is not a versioned deployment reference`);
401
- }
402
- const previousState = reference.controlState ?? "active";
315
+ if (!reference)
316
+ throw new Error(`${strategyName} is not bound to ${deploymentId}`);
317
+ const previousState = reference.controlState;
403
318
  const updated = await (0, import_runtimeDeployments.saveRuntimeDeployment)(userName, {
404
319
  ...deployment,
405
320
  strategies: deployment.strategies.map(
@@ -429,12 +344,6 @@ var rollback = async () => {
429
344
  const release = (await (0, import_runtimeStrategyReleases.listRuntimeStrategyReleases)(userName, strategyName)).find((candidate) => candidate.releaseVersion === releaseVersion);
430
345
  if (!release)
431
346
  throw new Error(`Release not found: ${strategyName} v${releaseVersion}`);
432
- const backupPath = await writeMigrationBackup({
433
- userName,
434
- capturedAt: Date.now(),
435
- deployment,
436
- reason: "rollback"
437
- });
438
347
  const updated = await (0, import_runtimeDeployments.saveRuntimeDeployment)(userName, {
439
348
  ...deployment,
440
349
  strategies: deployment.strategies.map(
@@ -445,7 +354,7 @@ var rollback = async () => {
445
354
  } : strategy
446
355
  )
447
356
  });
448
- console.log(JSON.stringify({ backupPath, deployment: updated }, null, 2));
357
+ console.log(JSON.stringify({ deployment: updated }, null, 2));
449
358
  };
450
359
  var verify = async () => {
451
360
  const deployments = await (0, import_runtimeDeployments.listRuntimeDeployments)(userName);
@@ -456,8 +365,7 @@ var verify = async () => {
456
365
  const strategies = await (0, import_runtimeStrategies.loadResolvedRuntimeStrategies)({
457
366
  userName,
458
367
  projectRoot,
459
- deployment,
460
- connectorName: deployment.connectorName
368
+ deployment
461
369
  });
462
370
  results.push({
463
371
  deploymentId: deployment.id,
@@ -489,23 +397,22 @@ var inspect = async () => {
489
397
  console.log(JSON.stringify({ userName, deployments, releases }, null, 2));
490
398
  };
491
399
  var runtimeConfig = async () => {
492
- if (action === "bootstrap") return bootstrap();
493
- if (action === "migrate") return migrate();
400
+ if (action === "provision") return provision();
494
401
  if (action === "rollout") return rollout();
495
- if (action === "publish-draft") return publishDraft();
496
402
  if (action === "verify") return verify();
497
403
  if (action === "pause") return updateControlState("entries_paused");
498
404
  if (action === "resume") return updateControlState("active");
499
405
  if (action === "rollback") return rollback();
500
406
  if (action === "inspect") return inspect();
501
407
  throw new Error(
502
- "Usage: tradejs runtime-config inspect|verify|bootstrap|migrate|rollout|publish-draft|pause|resume|rollback"
408
+ `Usage: tradejs runtime-config ${RUNTIME_CONFIG_ACTIONS.join("|")}`
503
409
  );
504
410
  };
505
411
  var main = runtimeConfig;
506
412
  // Annotate the CommonJS export names for ESM import in node:
507
413
  0 && (module.exports = {
508
- buildBootstrapRuntimeDeployment,
414
+ RUNTIME_CONFIG_ACTIONS,
415
+ buildProvisionedRuntimeDeployment,
509
416
  isEquivalentRuntimeStrategyRelease,
510
417
  main,
511
418
  pointRuntimeDeploymentAtRelease,