@pikku/kysely 0.12.6 → 0.12.8

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.
@@ -143,14 +143,14 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
143
143
  ): Promise<string> {
144
144
  const id = crypto.randomUUID()
145
145
  await this.db
146
- .insertInto('workflow_runs')
146
+ .insertInto('workflowRuns')
147
147
  .values({
148
- workflow_run_id: id,
148
+ workflowRunId: id,
149
149
  workflow: workflowName,
150
150
  status: 'running',
151
151
  input: JSON.stringify(input),
152
152
  inline,
153
- graph_hash: graphHash,
153
+ graphHash: graphHash,
154
154
  wire: JSON.stringify(wire),
155
155
  })
156
156
  .execute()
@@ -169,14 +169,14 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
169
169
  error?: SerializedError
170
170
  ): Promise<void> {
171
171
  await this.db
172
- .updateTable('workflow_runs')
172
+ .updateTable('workflowRuns')
173
173
  .set({
174
174
  status,
175
175
  output: output ? JSON.stringify(output) : null,
176
176
  error: error ? JSON.stringify(error) : null,
177
- updated_at: new Date(),
177
+ updatedAt: new Date(),
178
178
  })
179
- .where('workflow_run_id', '=', id)
179
+ .where('workflowRunId', '=', id)
180
180
  .execute()
181
181
  }
182
182
 
@@ -191,18 +191,18 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
191
191
  const now = new Date()
192
192
 
193
193
  await this.db
194
- .insertInto('workflow_step')
194
+ .insertInto('workflowStep')
195
195
  .values({
196
- workflow_step_id: stepId,
197
- workflow_run_id: runId,
198
- step_name: stepName,
199
- rpc_name: rpcName,
196
+ workflowStepId: stepId,
197
+ workflowRunId: runId,
198
+ stepName: stepName,
199
+ rpcName: rpcName,
200
200
  data: data != null ? JSON.stringify(data) : null,
201
201
  status: 'pending',
202
202
  retries: stepOptions?.retries ?? null,
203
- retry_delay: stepOptions?.retryDelay?.toString() ?? null,
204
- created_at: now,
205
- updated_at: now,
203
+ retryDelay: stepOptions?.retryDelay?.toString() ?? null,
204
+ createdAt: now,
205
+ updatedAt: now,
206
206
  })
207
207
  .execute()
208
208
 
@@ -223,30 +223,30 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
223
223
 
224
224
  async getStepState(runId: string, stepName: string): Promise<StepState> {
225
225
  const row = await this.db
226
- .selectFrom('workflow_step as s')
226
+ .selectFrom('workflowStep as s')
227
227
  .select([
228
- 's.workflow_step_id',
228
+ 's.workflowStepId',
229
229
  's.status',
230
230
  's.result',
231
231
  's.error',
232
232
  's.retries',
233
- 's.retry_delay',
234
- 's.created_at',
235
- 's.updated_at',
233
+ 's.retryDelay',
234
+ 's.createdAt',
235
+ 's.updatedAt',
236
236
  ])
237
237
  .select((eb) =>
238
238
  eb
239
- .selectFrom('workflow_step_history')
239
+ .selectFrom('workflowStepHistory')
240
240
  .select(eb.fn.countAll<number>().as('cnt'))
241
241
  .whereRef(
242
- 'workflow_step_history.workflow_step_id',
242
+ 'workflowStepHistory.workflowStepId',
243
243
  '=',
244
- 's.workflow_step_id'
244
+ 's.workflowStepId'
245
245
  )
246
- .as('attempt_count')
246
+ .as('attemptCount')
247
247
  )
248
- .where('s.workflow_run_id', '=', runId)
249
- .where('s.step_name', '=', stepName)
248
+ .where('s.workflowRunId', '=', runId)
249
+ .where('s.stepName', '=', stepName)
250
250
  .executeTakeFirst()
251
251
 
252
252
  if (!row) {
@@ -256,15 +256,15 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
256
256
  }
257
257
 
258
258
  return {
259
- stepId: row.workflow_step_id,
259
+ stepId: row.workflowStepId,
260
260
  status: row.status as StepState['status'],
261
261
  result: parseJson(row.result),
262
262
  error: parseJson(row.error),
263
- attemptCount: Number(row.attempt_count),
263
+ attemptCount: Number(row.attemptCount),
264
264
  retries: row.retries != null ? Number(row.retries) : undefined,
265
- retryDelay: row.retry_delay ?? undefined,
266
- createdAt: new Date(row.created_at),
267
- updatedAt: new Date(row.updated_at),
265
+ retryDelay: row.retryDelay ?? undefined,
266
+ createdAt: new Date(row.createdAt),
267
+ updatedAt: new Date(row.updatedAt),
268
268
  }
269
269
  }
270
270
 
@@ -276,33 +276,33 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
276
276
 
277
277
  async setStepRunning(stepId: string): Promise<void> {
278
278
  await this.db
279
- .updateTable('workflow_step')
280
- .set({ status: 'running', updated_at: new Date() })
281
- .where('workflow_step_id', '=', stepId)
279
+ .updateTable('workflowStep')
280
+ .set({ status: 'running', updatedAt: new Date() })
281
+ .where('workflowStepId', '=', stepId)
282
282
  .execute()
283
283
 
284
284
  const latestHistory = await this.db
285
- .selectFrom('workflow_step_history')
286
- .select('history_id')
287
- .where('workflow_step_id', '=', stepId)
288
- .orderBy('created_at', 'desc')
285
+ .selectFrom('workflowStepHistory')
286
+ .select('historyId')
287
+ .where('workflowStepId', '=', stepId)
288
+ .orderBy('createdAt', 'desc')
289
289
  .limit(1)
290
290
  .executeTakeFirst()
291
291
 
292
292
  if (latestHistory) {
293
293
  await this.db
294
- .updateTable('workflow_step_history')
294
+ .updateTable('workflowStepHistory')
295
295
  .set({ status: 'running' })
296
- .where('history_id', '=', latestHistory.history_id)
296
+ .where('historyId', '=', latestHistory.historyId)
297
297
  .execute()
298
298
  }
299
299
  }
300
300
 
301
301
  async setStepScheduled(stepId: string): Promise<void> {
302
302
  await this.db
303
- .updateTable('workflow_step')
304
- .set({ status: 'scheduled', updated_at: new Date() })
305
- .where('workflow_step_id', '=', stepId)
303
+ .updateTable('workflowStep')
304
+ .set({ status: 'scheduled', updatedAt: new Date() })
305
+ .where('workflowStepId', '=', stepId)
306
306
  .execute()
307
307
  }
308
308
 
@@ -314,21 +314,21 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
314
314
  ): Promise<void> {
315
315
  const now = new Date()
316
316
  const values: Record<string, any> = {
317
- history_id: crypto.randomUUID(),
318
- workflow_step_id: stepId,
317
+ historyId: crypto.randomUUID(),
318
+ workflowStepId: stepId,
319
319
  status,
320
320
  result: result != null ? JSON.stringify(result) : null,
321
321
  error: error != null ? JSON.stringify(error) : null,
322
- created_at: now,
322
+ createdAt: now,
323
323
  }
324
324
 
325
325
  const timestampField = this.getTimestampFieldForStatus(status)
326
- if (timestampField !== 'created_at') {
326
+ if (timestampField !== 'createdAt') {
327
327
  values[timestampField] = now
328
328
  }
329
329
 
330
330
  await this.db
331
- .insertInto('workflow_step_history')
331
+ .insertInto('workflowStepHistory')
332
332
  .values(values as any)
333
333
  .execute()
334
334
  }
@@ -336,26 +336,26 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
336
336
  private getTimestampFieldForStatus(status: string): string {
337
337
  switch (status) {
338
338
  case 'running':
339
- return 'running_at'
339
+ return 'runningAt'
340
340
  case 'scheduled':
341
- return 'scheduled_at'
341
+ return 'scheduledAt'
342
342
  case 'succeeded':
343
- return 'succeeded_at'
343
+ return 'succeededAt'
344
344
  case 'failed':
345
- return 'failed_at'
345
+ return 'failedAt'
346
346
  default:
347
- return 'created_at'
347
+ return 'createdAt'
348
348
  }
349
349
  }
350
350
 
351
351
  async setStepChildRunId(stepId: string, childRunId: string): Promise<void> {
352
352
  await this.db
353
- .updateTable('workflow_step')
353
+ .updateTable('workflowStep')
354
354
  .set({
355
- child_run_id: childRunId,
356
- updated_at: new Date(),
355
+ childRunId: childRunId,
356
+ updatedAt: new Date(),
357
357
  })
358
- .where('workflow_step_id', '=', stepId)
358
+ .where('workflowStepId', '=', stepId)
359
359
  .execute()
360
360
  }
361
361
 
@@ -363,29 +363,29 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
363
363
  const resultJson = JSON.stringify(result)
364
364
 
365
365
  await this.db
366
- .updateTable('workflow_step')
366
+ .updateTable('workflowStep')
367
367
  .set({
368
368
  status: 'succeeded',
369
369
  result: resultJson,
370
370
  error: null,
371
- updated_at: new Date(),
371
+ updatedAt: new Date(),
372
372
  })
373
- .where('workflow_step_id', '=', stepId)
373
+ .where('workflowStepId', '=', stepId)
374
374
  .execute()
375
375
 
376
376
  const latestHistory = await this.db
377
- .selectFrom('workflow_step_history')
378
- .select('history_id')
379
- .where('workflow_step_id', '=', stepId)
380
- .orderBy('created_at', 'desc')
377
+ .selectFrom('workflowStepHistory')
378
+ .select('historyId')
379
+ .where('workflowStepId', '=', stepId)
380
+ .orderBy('createdAt', 'desc')
381
381
  .limit(1)
382
382
  .executeTakeFirst()
383
383
 
384
384
  if (latestHistory) {
385
385
  await this.db
386
- .updateTable('workflow_step_history')
386
+ .updateTable('workflowStepHistory')
387
387
  .set({ status: 'succeeded', result: resultJson })
388
- .where('history_id', '=', latestHistory.history_id)
388
+ .where('historyId', '=', latestHistory.historyId)
389
389
  .execute()
390
390
  }
391
391
  }
@@ -399,29 +399,29 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
399
399
  const errorJson = JSON.stringify(serializedError)
400
400
 
401
401
  await this.db
402
- .updateTable('workflow_step')
402
+ .updateTable('workflowStep')
403
403
  .set({
404
404
  status: 'failed',
405
405
  error: errorJson,
406
406
  result: null,
407
- updated_at: new Date(),
407
+ updatedAt: new Date(),
408
408
  })
409
- .where('workflow_step_id', '=', stepId)
409
+ .where('workflowStepId', '=', stepId)
410
410
  .execute()
411
411
 
412
412
  const latestHistory = await this.db
413
- .selectFrom('workflow_step_history')
414
- .select('history_id')
415
- .where('workflow_step_id', '=', stepId)
416
- .orderBy('created_at', 'desc')
413
+ .selectFrom('workflowStepHistory')
414
+ .select('historyId')
415
+ .where('workflowStepId', '=', stepId)
416
+ .orderBy('createdAt', 'desc')
417
417
  .limit(1)
418
418
  .executeTakeFirst()
419
419
 
420
420
  if (latestHistory) {
421
421
  await this.db
422
- .updateTable('workflow_step_history')
422
+ .updateTable('workflowStepHistory')
423
423
  .set({ status: 'failed', error: errorJson })
424
- .where('history_id', '=', latestHistory.history_id)
424
+ .where('historyId', '=', latestHistory.historyId)
425
425
  .execute()
426
426
  }
427
427
  }
@@ -431,49 +431,49 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
431
431
  status: 'pending' | 'running'
432
432
  ): Promise<StepState> {
433
433
  await this.db
434
- .updateTable('workflow_step')
435
- .set({ status, result: null, error: null, updated_at: new Date() })
436
- .where('workflow_step_id', '=', stepId)
434
+ .updateTable('workflowStep')
435
+ .set({ status, result: null, error: null, updatedAt: new Date() })
436
+ .where('workflowStepId', '=', stepId)
437
437
  .execute()
438
438
 
439
439
  await this.insertHistoryRecord(stepId, status)
440
440
 
441
441
  const row = await this.db
442
- .selectFrom('workflow_step as s')
442
+ .selectFrom('workflowStep as s')
443
443
  .select([
444
- 's.workflow_step_id',
444
+ 's.workflowStepId',
445
445
  's.status',
446
446
  's.result',
447
447
  's.error',
448
448
  's.retries',
449
- 's.retry_delay',
450
- 's.created_at',
451
- 's.updated_at',
449
+ 's.retryDelay',
450
+ 's.createdAt',
451
+ 's.updatedAt',
452
452
  ])
453
453
  .select((eb) =>
454
454
  eb
455
- .selectFrom('workflow_step_history')
455
+ .selectFrom('workflowStepHistory')
456
456
  .select(eb.fn.countAll<number>().as('cnt'))
457
457
  .whereRef(
458
- 'workflow_step_history.workflow_step_id',
458
+ 'workflowStepHistory.workflowStepId',
459
459
  '=',
460
- 's.workflow_step_id'
460
+ 's.workflowStepId'
461
461
  )
462
- .as('attempt_count')
462
+ .as('attemptCount')
463
463
  )
464
- .where('s.workflow_step_id', '=', stepId)
464
+ .where('s.workflowStepId', '=', stepId)
465
465
  .executeTakeFirstOrThrow()
466
466
 
467
467
  return {
468
- stepId: row.workflow_step_id,
468
+ stepId: row.workflowStepId,
469
469
  status: row.status as StepState['status'],
470
470
  result: parseJson(row.result),
471
471
  error: parseJson(row.error),
472
- attemptCount: Number(row.attempt_count),
472
+ attemptCount: Number(row.attemptCount),
473
473
  retries: row.retries != null ? Number(row.retries) : undefined,
474
- retryDelay: row.retry_delay ?? undefined,
475
- createdAt: new Date(row.created_at),
476
- updatedAt: new Date(row.updated_at),
474
+ retryDelay: row.retryDelay ?? undefined,
475
+ createdAt: new Date(row.createdAt),
476
+ updatedAt: new Date(row.updatedAt),
477
477
  }
478
478
  }
479
479
 
@@ -495,16 +495,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
495
495
  branchKeys: Record<string, string>
496
496
  }> {
497
497
  const results = await this.db
498
- .selectFrom('workflow_step as ws')
499
- .select(['ws.step_name', 'ws.status', 'ws.branch_taken', 'ws.retries'])
498
+ .selectFrom('workflowStep as ws')
499
+ .select(['ws.stepName', 'ws.status', 'ws.branchTaken', 'ws.retries'])
500
500
  .select((eb) =>
501
501
  eb
502
- .selectFrom('workflow_step_history as h')
502
+ .selectFrom('workflowStepHistory as h')
503
503
  .select(eb.fn.countAll<number>().as('cnt'))
504
- .whereRef('h.workflow_step_id', '=', 'ws.workflow_step_id')
505
- .as('attempt_count')
504
+ .whereRef('h.workflowStepId', '=', 'ws.workflowStepId')
505
+ .as('attemptCount')
506
506
  )
507
- .where('ws.workflow_run_id', '=', runId)
507
+ .where('ws.workflowRunId', '=', runId)
508
508
  .where('ws.status', 'in', ['succeeded', 'failed'])
509
509
  .execute()
510
510
 
@@ -513,16 +513,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
513
513
  const branchKeys: Record<string, string> = {}
514
514
 
515
515
  for (const row of results) {
516
- const nodeId = row.step_name
516
+ const nodeId = row.stepName
517
517
 
518
518
  if (row.status === 'succeeded') {
519
519
  completedNodeIds.push(nodeId)
520
- if (row.branch_taken) {
521
- branchKeys[nodeId] = row.branch_taken
520
+ if (row.branchTaken) {
521
+ branchKeys[nodeId] = row.branchTaken
522
522
  }
523
523
  } else if (row.status === 'failed') {
524
524
  const maxAttempts = (row.retries ?? 0) + 1
525
- if (Number(row.attempt_count) >= maxAttempts) {
525
+ if (Number(row.attemptCount) >= maxAttempts) {
526
526
  failedNodeIds.push(nodeId)
527
527
  }
528
528
  }
@@ -538,13 +538,13 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
538
538
  if (nodeIds.length === 0) return []
539
539
 
540
540
  const result = await this.db
541
- .selectFrom('workflow_step')
542
- .select('step_name')
543
- .where('workflow_run_id', '=', runId)
544
- .where('step_name', 'in', nodeIds)
541
+ .selectFrom('workflowStep')
542
+ .select('stepName')
543
+ .where('workflowRunId', '=', runId)
544
+ .where('stepName', 'in', nodeIds)
545
545
  .execute()
546
546
 
547
- const existingStepNames = new Set(result.map((r) => r.step_name))
547
+ const existingStepNames = new Set(result.map((r) => r.stepName))
548
548
  return nodeIds.filter((id) => !existingStepNames.has(id))
549
549
  }
550
550
 
@@ -555,25 +555,25 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
555
555
  if (nodeIds.length === 0) return {}
556
556
 
557
557
  const result = await this.db
558
- .selectFrom('workflow_step')
559
- .select(['step_name', 'result'])
560
- .where('workflow_run_id', '=', runId)
561
- .where('step_name', 'in', nodeIds)
558
+ .selectFrom('workflowStep')
559
+ .select(['stepName', 'result'])
560
+ .where('workflowRunId', '=', runId)
561
+ .where('stepName', 'in', nodeIds)
562
562
  .where('status', '=', 'succeeded')
563
563
  .execute()
564
564
 
565
565
  const results: Record<string, any> = {}
566
566
  for (const row of result) {
567
- results[row.step_name] = parseJson(row.result)
567
+ results[row.stepName] = parseJson(row.result)
568
568
  }
569
569
  return results
570
570
  }
571
571
 
572
572
  async setBranchTaken(stepId: string, branchKey: string): Promise<void> {
573
573
  await this.db
574
- .updateTable('workflow_step')
575
- .set({ branch_taken: branchKey, updated_at: new Date() })
576
- .where('workflow_step_id', '=', stepId)
574
+ .updateTable('workflowStep')
575
+ .set({ branchTaken: branchKey, updatedAt: new Date() })
576
+ .where('workflowStepId', '=', stepId)
577
577
  .execute()
578
578
  }
579
579
 
@@ -583,26 +583,26 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
583
583
  value: unknown
584
584
  ): Promise<void> {
585
585
  const row = await this.db
586
- .selectFrom('workflow_runs')
586
+ .selectFrom('workflowRuns')
587
587
  .select('state')
588
- .where('workflow_run_id', '=', runId)
588
+ .where('workflowRunId', '=', runId)
589
589
  .executeTakeFirst()
590
590
 
591
591
  const state: Record<string, unknown> = parseJson(row?.state) ?? {}
592
592
  state[name] = value
593
593
 
594
594
  await this.db
595
- .updateTable('workflow_runs')
596
- .set({ state: JSON.stringify(state), updated_at: new Date() })
597
- .where('workflow_run_id', '=', runId)
595
+ .updateTable('workflowRuns')
596
+ .set({ state: JSON.stringify(state), updatedAt: new Date() })
597
+ .where('workflowRunId', '=', runId)
598
598
  .execute()
599
599
  }
600
600
 
601
601
  async getRunState(runId: string): Promise<Record<string, unknown>> {
602
602
  const row = await this.db
603
- .selectFrom('workflow_runs')
603
+ .selectFrom('workflowRuns')
604
604
  .select('state')
605
- .where('workflow_run_id', '=', runId)
605
+ .where('workflowRunId', '=', runId)
606
606
  .executeTakeFirst()
607
607
 
608
608
  if (!row) return {}
@@ -617,16 +617,16 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
617
617
  status?: WorkflowVersionStatus
618
618
  ): Promise<void> {
619
619
  await this.db
620
- .insertInto('workflow_versions')
620
+ .insertInto('workflowVersions')
621
621
  .values({
622
- workflow_name: name,
623
- graph_hash: graphHash,
622
+ workflowName: name,
623
+ graphHash: graphHash,
624
624
  graph: JSON.stringify(graph),
625
625
  source,
626
626
  status: status ?? 'active',
627
627
  })
628
628
  .onConflict((oc) =>
629
- oc.columns(['workflow_name', 'graph_hash']).doNothing()
629
+ oc.columns(['workflowName', 'graphHash']).doNothing()
630
630
  )
631
631
  .execute()
632
632
  }
@@ -637,10 +637,10 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
637
637
  status: WorkflowVersionStatus
638
638
  ): Promise<void> {
639
639
  await this.db
640
- .updateTable('workflow_versions')
640
+ .updateTable('workflowVersions')
641
641
  .set({ status })
642
- .where('workflow_name', '=', name)
643
- .where('graph_hash', '=', graphHash)
642
+ .where('workflowName', '=', name)
643
+ .where('graphHash', '=', graphHash)
644
644
  .execute()
645
645
  }
646
646