@karmaniverous/jeeves-runner 0.7.2 → 0.7.3

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.
@@ -1006,8 +1006,10 @@ function parseResultLines(stdout) {
1006
1006
  }
1007
1007
  return { tokens, resultMeta };
1008
1008
  }
1009
+ /** TypeScript file extensions that should be executed via tsRunner. */
1010
+ const TS_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
1009
1011
  /** Resolve the command and arguments for a script based on its file extension. */
1010
- function resolveCommand(script) {
1012
+ function resolveCommand(script, tsRunner = 'tsx') {
1011
1013
  const ext = extname(script).toLowerCase();
1012
1014
  switch (ext) {
1013
1015
  case '.ps1':
@@ -1019,6 +1021,9 @@ function resolveCommand(script) {
1019
1021
  case '.bat':
1020
1022
  return { command: 'cmd.exe', args: ['/c', script] };
1021
1023
  default:
1024
+ if (TS_EXTENSIONS.has(ext)) {
1025
+ return { command: tsRunner, args: [script] };
1026
+ }
1022
1027
  // .js, .mjs, .cjs, or anything else: run with node
1023
1028
  return { command: 'node', args: [script] };
1024
1029
  }
@@ -1027,7 +1032,7 @@ function resolveCommand(script) {
1027
1032
  * Execute a job script as a child process. Captures output, parses metadata, enforces timeout.
1028
1033
  */
1029
1034
  function executeJob(options) {
1030
- const { script, dbPath, jobId, runId, timeoutMs, commandResolver, sourceType = 'path', } = options;
1035
+ const { script, dbPath, jobId, runId, timeoutMs, commandResolver, sourceType = 'path', tsRunner, } = options;
1031
1036
  const startTime = Date.now();
1032
1037
  // For inline scripts, write to a temp file and clean up after.
1033
1038
  let tempFile = null;
@@ -1043,7 +1048,7 @@ function executeJob(options) {
1043
1048
  const stderrBuffer = new RingBuffer(100);
1044
1049
  const { command, args } = commandResolver
1045
1050
  ? commandResolver(effectiveScript)
1046
- : resolveCommand(effectiveScript);
1051
+ : resolveCommand(effectiveScript, tsRunner);
1047
1052
  const child = spawn(command, args, {
1048
1053
  env: {
1049
1054
  ...process.env,
@@ -1445,6 +1450,7 @@ function createScheduler(deps) {
1445
1450
  runId,
1446
1451
  timeoutMs: timeout_ms ?? undefined,
1447
1452
  sourceType: source_type ?? 'path',
1453
+ tsRunner: config.tsRunner,
1448
1454
  });
1449
1455
  }
1450
1456
  runRepository.finishRun(runId, result);
@@ -1712,6 +1718,8 @@ const runnerConfigSchema = z.object({
1712
1718
  log: logSchema.default({ level: 'info' }),
1713
1719
  /** Gateway configuration for session-type jobs. */
1714
1720
  gateway: gatewaySchema.default({ url: 'http://127.0.0.1:18789' }),
1721
+ /** Command used to execute .ts/.tsx/.mts/.cts scripts. Defaults to 'tsx'. Can be an absolute path. */
1722
+ tsRunner: z.string().default('tsx'),
1715
1723
  });
1716
1724
 
1717
1725
  /**
package/dist/index.d.ts CHANGED
@@ -25,11 +25,11 @@ declare const runnerConfigSchema: z.ZodObject<{
25
25
  }, z.core.$strip>>;
26
26
  log: z.ZodDefault<z.ZodObject<{
27
27
  level: z.ZodDefault<z.ZodEnum<{
28
- error: "error";
29
28
  trace: "trace";
30
29
  debug: "debug";
31
30
  info: "info";
32
31
  warn: "warn";
32
+ error: "error";
33
33
  fatal: "fatal";
34
34
  }>>;
35
35
  file: z.ZodOptional<z.ZodString>;
@@ -38,6 +38,7 @@ declare const runnerConfigSchema: z.ZodObject<{
38
38
  url: z.ZodDefault<z.ZodString>;
39
39
  tokenPath: z.ZodOptional<z.ZodString>;
40
40
  }, z.core.$strip>>;
41
+ tsRunner: z.ZodDefault<z.ZodString>;
41
42
  }, z.core.$strip>;
42
43
  /** Inferred runner configuration type. */
43
44
  type RunnerConfig = z.infer<typeof runnerConfigSchema>;
@@ -102,10 +103,10 @@ type Queue = z.infer<typeof queueSchema>;
102
103
 
103
104
  /** Run status enumeration schema (pending, running, ok, error, timeout, skipped). */
104
105
  declare const runStatusSchema: z.ZodEnum<{
106
+ error: "error";
105
107
  pending: "pending";
106
108
  running: "running";
107
109
  ok: "ok";
108
- error: "error";
109
110
  timeout: "timeout";
110
111
  skipped: "skipped";
111
112
  }>;
@@ -120,10 +121,10 @@ declare const runSchema: z.ZodObject<{
120
121
  id: z.ZodNumber;
121
122
  jobId: z.ZodString;
122
123
  status: z.ZodEnum<{
124
+ error: "error";
123
125
  pending: "pending";
124
126
  running: "running";
125
127
  ok: "ok";
126
- error: "error";
127
128
  timeout: "timeout";
128
129
  skipped: "skipped";
129
130
  }>;
@@ -289,7 +290,13 @@ interface ExecutionOptions {
289
290
  commandResolver?: (script: string) => ResolvedCommand;
290
291
  /** Source type: 'path' uses script as file path, 'inline' writes script content to a temp file. */
291
292
  sourceType?: 'path' | 'inline';
293
+ /** Command used to execute TypeScript files. Defaults to 'tsx'. */
294
+ tsRunner?: string;
292
295
  }
296
+ /** TypeScript file extensions that should be executed via tsRunner. */
297
+ declare const TS_EXTENSIONS: Set<string>;
298
+ /** Resolve the command and arguments for a script based on its file extension. */
299
+ declare function resolveCommand(script: string, tsRunner?: string): ResolvedCommand;
293
300
  /**
294
301
  * Execute a job script as a child process. Captures output, parses metadata, enforces timeout.
295
302
  */
@@ -544,5 +551,5 @@ declare function createMaintenance(db: DatabaseSync, config: MaintenanceConfig,
544
551
  */
545
552
  declare function runMigrations(db: DatabaseSync): void;
546
553
 
547
- export { closeConnection, createClient, createConnection, createGatewayClient, createMaintenance, createNotifier, createRunner, createScheduler, executeJob, executeSession, getNextFireTime, jobSchema, queueSchema, runMigrations, runSchema, runStatusSchema, runTriggerSchema, runnerConfigSchema, validateSchedule };
554
+ export { TS_EXTENSIONS, closeConnection, createClient, createConnection, createGatewayClient, createMaintenance, createNotifier, createRunner, createScheduler, executeJob, executeSession, getNextFireTime, jobSchema, queueSchema, resolveCommand, runMigrations, runSchema, runStatusSchema, runTriggerSchema, runnerConfigSchema, validateSchedule };
548
555
  export type { ExecutionOptions, ExecutionResult, GatewayClient, GatewayClientOptions, Job, Maintenance, MaintenanceConfig, Notifier, NotifyConfig, NotifyLogger, Queue, QueueItem, ResolvedCommand, Run, RunStatus, RunTrigger, Runner, RunnerClient, RunnerConfig, RunnerDeps, ScheduleInvalid, ScheduleValid, ScheduleValidation, Scheduler, SchedulerDeps, SessionExecutionOptions, SessionInfo, SessionMessage, SpawnSessionOptions, SpawnSessionResult };
package/dist/mjs/index.js CHANGED
@@ -71,6 +71,8 @@ const runnerConfigSchema = z.object({
71
71
  log: logSchema.default({ level: 'info' }),
72
72
  /** Gateway configuration for session-type jobs. */
73
73
  gateway: gatewaySchema.default({ url: 'http://127.0.0.1:18789' }),
74
+ /** Command used to execute .ts/.tsx/.mts/.cts scripts. Defaults to 'tsx'. Can be an absolute path. */
75
+ tsRunner: z.string().default('tsx'),
74
76
  });
75
77
 
76
78
  /**
@@ -1165,8 +1167,10 @@ function parseResultLines(stdout) {
1165
1167
  }
1166
1168
  return { tokens, resultMeta };
1167
1169
  }
1170
+ /** TypeScript file extensions that should be executed via tsRunner. */
1171
+ const TS_EXTENSIONS = new Set(['.ts', '.tsx', '.mts', '.cts']);
1168
1172
  /** Resolve the command and arguments for a script based on its file extension. */
1169
- function resolveCommand(script) {
1173
+ function resolveCommand(script, tsRunner = 'tsx') {
1170
1174
  const ext = extname(script).toLowerCase();
1171
1175
  switch (ext) {
1172
1176
  case '.ps1':
@@ -1178,6 +1182,9 @@ function resolveCommand(script) {
1178
1182
  case '.bat':
1179
1183
  return { command: 'cmd.exe', args: ['/c', script] };
1180
1184
  default:
1185
+ if (TS_EXTENSIONS.has(ext)) {
1186
+ return { command: tsRunner, args: [script] };
1187
+ }
1181
1188
  // .js, .mjs, .cjs, or anything else: run with node
1182
1189
  return { command: 'node', args: [script] };
1183
1190
  }
@@ -1186,7 +1193,7 @@ function resolveCommand(script) {
1186
1193
  * Execute a job script as a child process. Captures output, parses metadata, enforces timeout.
1187
1194
  */
1188
1195
  function executeJob(options) {
1189
- const { script, dbPath, jobId, runId, timeoutMs, commandResolver, sourceType = 'path', } = options;
1196
+ const { script, dbPath, jobId, runId, timeoutMs, commandResolver, sourceType = 'path', tsRunner, } = options;
1190
1197
  const startTime = Date.now();
1191
1198
  // For inline scripts, write to a temp file and clean up after.
1192
1199
  let tempFile = null;
@@ -1202,7 +1209,7 @@ function executeJob(options) {
1202
1209
  const stderrBuffer = new RingBuffer(100);
1203
1210
  const { command, args } = commandResolver
1204
1211
  ? commandResolver(effectiveScript)
1205
- : resolveCommand(effectiveScript);
1212
+ : resolveCommand(effectiveScript, tsRunner);
1206
1213
  const child = spawn(command, args, {
1207
1214
  env: {
1208
1215
  ...process.env,
@@ -1604,6 +1611,7 @@ function createScheduler(deps) {
1604
1611
  runId,
1605
1612
  timeoutMs: timeout_ms ?? undefined,
1606
1613
  sourceType: source_type ?? 'path',
1614
+ tsRunner: config.tsRunner,
1607
1615
  });
1608
1616
  }
1609
1617
  runRepository.finishRun(runId, result);
@@ -2052,4 +2060,4 @@ function createClient(dbPath) {
2052
2060
  };
2053
2061
  }
2054
2062
 
2055
- export { closeConnection, createClient, createConnection, createGatewayClient, createMaintenance, createNotifier, createRunner, createScheduler, executeJob, executeSession, getNextFireTime, jobSchema, queueSchema, runMigrations, runSchema, runStatusSchema, runTriggerSchema, runnerConfigSchema, validateSchedule };
2063
+ export { TS_EXTENSIONS, closeConnection, createClient, createConnection, createGatewayClient, createMaintenance, createNotifier, createRunner, createScheduler, executeJob, executeSession, getNextFireTime, jobSchema, queueSchema, resolveCommand, runMigrations, runSchema, runStatusSchema, runTriggerSchema, runnerConfigSchema, validateSchedule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jeeves-runner",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "author": "Jason Williscroft",
5
5
  "description": "Graph-aware job execution engine with SQLite state. Part of the Jeeves platform.",
6
6
  "license": "BSD-3-Clause",