@pikku/kysely 0.12.6 → 0.12.7

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.
@@ -98,14 +98,14 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
98
98
  async createRun(workflowName, input, inline, graphHash, wire) {
99
99
  const id = crypto.randomUUID();
100
100
  await this.db
101
- .insertInto('workflow_runs')
101
+ .insertInto('workflowRuns')
102
102
  .values({
103
- workflow_run_id: id,
103
+ workflowRunId: id,
104
104
  workflow: workflowName,
105
105
  status: 'running',
106
106
  input: JSON.stringify(input),
107
107
  inline,
108
- graph_hash: graphHash,
108
+ graphHash: graphHash,
109
109
  wire: JSON.stringify(wire),
110
110
  })
111
111
  .execute();
@@ -116,32 +116,32 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
116
116
  }
117
117
  async updateRunStatus(id, status, output, error) {
118
118
  await this.db
119
- .updateTable('workflow_runs')
119
+ .updateTable('workflowRuns')
120
120
  .set({
121
121
  status,
122
122
  output: output ? JSON.stringify(output) : null,
123
123
  error: error ? JSON.stringify(error) : null,
124
- updated_at: new Date(),
124
+ updatedAt: new Date(),
125
125
  })
126
- .where('workflow_run_id', '=', id)
126
+ .where('workflowRunId', '=', id)
127
127
  .execute();
128
128
  }
129
129
  async insertStepState(runId, stepName, rpcName, data, stepOptions) {
130
130
  const stepId = crypto.randomUUID();
131
131
  const now = new Date();
132
132
  await this.db
133
- .insertInto('workflow_step')
133
+ .insertInto('workflowStep')
134
134
  .values({
135
- workflow_step_id: stepId,
136
- workflow_run_id: runId,
137
- step_name: stepName,
138
- rpc_name: rpcName,
135
+ workflowStepId: stepId,
136
+ workflowRunId: runId,
137
+ stepName: stepName,
138
+ rpcName: rpcName,
139
139
  data: data != null ? JSON.stringify(data) : null,
140
140
  status: 'pending',
141
141
  retries: stepOptions?.retries ?? null,
142
- retry_delay: stepOptions?.retryDelay?.toString() ?? null,
143
- created_at: now,
144
- updated_at: now,
142
+ retryDelay: stepOptions?.retryDelay?.toString() ?? null,
143
+ createdAt: now,
144
+ updatedAt: now,
145
145
  })
146
146
  .execute();
147
147
  await this.insertHistoryRecord(stepId, 'pending');
@@ -159,38 +159,38 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
159
159
  }
160
160
  async getStepState(runId, stepName) {
161
161
  const row = await this.db
162
- .selectFrom('workflow_step as s')
162
+ .selectFrom('workflowStep as s')
163
163
  .select([
164
- 's.workflow_step_id',
164
+ 's.workflowStepId',
165
165
  's.status',
166
166
  's.result',
167
167
  's.error',
168
168
  's.retries',
169
- 's.retry_delay',
170
- 's.created_at',
171
- 's.updated_at',
169
+ 's.retryDelay',
170
+ 's.createdAt',
171
+ 's.updatedAt',
172
172
  ])
173
173
  .select((eb) => eb
174
- .selectFrom('workflow_step_history')
174
+ .selectFrom('workflowStepHistory')
175
175
  .select(eb.fn.countAll().as('cnt'))
176
- .whereRef('workflow_step_history.workflow_step_id', '=', 's.workflow_step_id')
177
- .as('attempt_count'))
178
- .where('s.workflow_run_id', '=', runId)
179
- .where('s.step_name', '=', stepName)
176
+ .whereRef('workflowStepHistory.workflowStepId', '=', 's.workflowStepId')
177
+ .as('attemptCount'))
178
+ .where('s.workflowRunId', '=', runId)
179
+ .where('s.stepName', '=', stepName)
180
180
  .executeTakeFirst();
181
181
  if (!row) {
182
182
  throw new Error(`Step not found: runId=${runId}, stepName=${stepName}. Use insertStepState to create it.`);
183
183
  }
184
184
  return {
185
- stepId: row.workflow_step_id,
185
+ stepId: row.workflowStepId,
186
186
  status: row.status,
187
187
  result: parseJson(row.result),
188
188
  error: parseJson(row.error),
189
- attemptCount: Number(row.attempt_count),
189
+ attemptCount: Number(row.attemptCount),
190
190
  retries: row.retries != null ? Number(row.retries) : undefined,
191
- retryDelay: row.retry_delay ?? undefined,
192
- createdAt: new Date(row.created_at),
193
- updatedAt: new Date(row.updated_at),
191
+ retryDelay: row.retryDelay ?? undefined,
192
+ createdAt: new Date(row.createdAt),
193
+ updatedAt: new Date(row.updatedAt),
194
194
  };
195
195
  }
196
196
  async getRunHistory(runId) {
@@ -198,99 +198,99 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
198
198
  }
199
199
  async setStepRunning(stepId) {
200
200
  await this.db
201
- .updateTable('workflow_step')
202
- .set({ status: 'running', updated_at: new Date() })
203
- .where('workflow_step_id', '=', stepId)
201
+ .updateTable('workflowStep')
202
+ .set({ status: 'running', updatedAt: new Date() })
203
+ .where('workflowStepId', '=', stepId)
204
204
  .execute();
205
205
  const latestHistory = await this.db
206
- .selectFrom('workflow_step_history')
207
- .select('history_id')
208
- .where('workflow_step_id', '=', stepId)
209
- .orderBy('created_at', 'desc')
206
+ .selectFrom('workflowStepHistory')
207
+ .select('historyId')
208
+ .where('workflowStepId', '=', stepId)
209
+ .orderBy('createdAt', 'desc')
210
210
  .limit(1)
211
211
  .executeTakeFirst();
212
212
  if (latestHistory) {
213
213
  await this.db
214
- .updateTable('workflow_step_history')
214
+ .updateTable('workflowStepHistory')
215
215
  .set({ status: 'running' })
216
- .where('history_id', '=', latestHistory.history_id)
216
+ .where('historyId', '=', latestHistory.historyId)
217
217
  .execute();
218
218
  }
219
219
  }
220
220
  async setStepScheduled(stepId) {
221
221
  await this.db
222
- .updateTable('workflow_step')
223
- .set({ status: 'scheduled', updated_at: new Date() })
224
- .where('workflow_step_id', '=', stepId)
222
+ .updateTable('workflowStep')
223
+ .set({ status: 'scheduled', updatedAt: new Date() })
224
+ .where('workflowStepId', '=', stepId)
225
225
  .execute();
226
226
  }
227
227
  async insertHistoryRecord(stepId, status, result, error) {
228
228
  const now = new Date();
229
229
  const values = {
230
- history_id: crypto.randomUUID(),
231
- workflow_step_id: stepId,
230
+ historyId: crypto.randomUUID(),
231
+ workflowStepId: stepId,
232
232
  status,
233
233
  result: result != null ? JSON.stringify(result) : null,
234
234
  error: error != null ? JSON.stringify(error) : null,
235
- created_at: now,
235
+ createdAt: now,
236
236
  };
237
237
  const timestampField = this.getTimestampFieldForStatus(status);
238
- if (timestampField !== 'created_at') {
238
+ if (timestampField !== 'createdAt') {
239
239
  values[timestampField] = now;
240
240
  }
241
241
  await this.db
242
- .insertInto('workflow_step_history')
242
+ .insertInto('workflowStepHistory')
243
243
  .values(values)
244
244
  .execute();
245
245
  }
246
246
  getTimestampFieldForStatus(status) {
247
247
  switch (status) {
248
248
  case 'running':
249
- return 'running_at';
249
+ return 'runningAt';
250
250
  case 'scheduled':
251
- return 'scheduled_at';
251
+ return 'scheduledAt';
252
252
  case 'succeeded':
253
- return 'succeeded_at';
253
+ return 'succeededAt';
254
254
  case 'failed':
255
- return 'failed_at';
255
+ return 'failedAt';
256
256
  default:
257
- return 'created_at';
257
+ return 'createdAt';
258
258
  }
259
259
  }
260
260
  async setStepChildRunId(stepId, childRunId) {
261
261
  await this.db
262
- .updateTable('workflow_step')
262
+ .updateTable('workflowStep')
263
263
  .set({
264
- child_run_id: childRunId,
265
- updated_at: new Date(),
264
+ childRunId: childRunId,
265
+ updatedAt: new Date(),
266
266
  })
267
- .where('workflow_step_id', '=', stepId)
267
+ .where('workflowStepId', '=', stepId)
268
268
  .execute();
269
269
  }
270
270
  async setStepResult(stepId, result) {
271
271
  const resultJson = JSON.stringify(result);
272
272
  await this.db
273
- .updateTable('workflow_step')
273
+ .updateTable('workflowStep')
274
274
  .set({
275
275
  status: 'succeeded',
276
276
  result: resultJson,
277
277
  error: null,
278
- updated_at: new Date(),
278
+ updatedAt: new Date(),
279
279
  })
280
- .where('workflow_step_id', '=', stepId)
280
+ .where('workflowStepId', '=', stepId)
281
281
  .execute();
282
282
  const latestHistory = await this.db
283
- .selectFrom('workflow_step_history')
284
- .select('history_id')
285
- .where('workflow_step_id', '=', stepId)
286
- .orderBy('created_at', 'desc')
283
+ .selectFrom('workflowStepHistory')
284
+ .select('historyId')
285
+ .where('workflowStepId', '=', stepId)
286
+ .orderBy('createdAt', 'desc')
287
287
  .limit(1)
288
288
  .executeTakeFirst();
289
289
  if (latestHistory) {
290
290
  await this.db
291
- .updateTable('workflow_step_history')
291
+ .updateTable('workflowStepHistory')
292
292
  .set({ status: 'succeeded', result: resultJson })
293
- .where('history_id', '=', latestHistory.history_id)
293
+ .where('historyId', '=', latestHistory.historyId)
294
294
  .execute();
295
295
  }
296
296
  }
@@ -302,66 +302,66 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
302
302
  };
303
303
  const errorJson = JSON.stringify(serializedError);
304
304
  await this.db
305
- .updateTable('workflow_step')
305
+ .updateTable('workflowStep')
306
306
  .set({
307
307
  status: 'failed',
308
308
  error: errorJson,
309
309
  result: null,
310
- updated_at: new Date(),
310
+ updatedAt: new Date(),
311
311
  })
312
- .where('workflow_step_id', '=', stepId)
312
+ .where('workflowStepId', '=', stepId)
313
313
  .execute();
314
314
  const latestHistory = await this.db
315
- .selectFrom('workflow_step_history')
316
- .select('history_id')
317
- .where('workflow_step_id', '=', stepId)
318
- .orderBy('created_at', 'desc')
315
+ .selectFrom('workflowStepHistory')
316
+ .select('historyId')
317
+ .where('workflowStepId', '=', stepId)
318
+ .orderBy('createdAt', 'desc')
319
319
  .limit(1)
320
320
  .executeTakeFirst();
321
321
  if (latestHistory) {
322
322
  await this.db
323
- .updateTable('workflow_step_history')
323
+ .updateTable('workflowStepHistory')
324
324
  .set({ status: 'failed', error: errorJson })
325
- .where('history_id', '=', latestHistory.history_id)
325
+ .where('historyId', '=', latestHistory.historyId)
326
326
  .execute();
327
327
  }
328
328
  }
329
329
  async createRetryAttempt(stepId, status) {
330
330
  await this.db
331
- .updateTable('workflow_step')
332
- .set({ status, result: null, error: null, updated_at: new Date() })
333
- .where('workflow_step_id', '=', stepId)
331
+ .updateTable('workflowStep')
332
+ .set({ status, result: null, error: null, updatedAt: new Date() })
333
+ .where('workflowStepId', '=', stepId)
334
334
  .execute();
335
335
  await this.insertHistoryRecord(stepId, status);
336
336
  const row = await this.db
337
- .selectFrom('workflow_step as s')
337
+ .selectFrom('workflowStep as s')
338
338
  .select([
339
- 's.workflow_step_id',
339
+ 's.workflowStepId',
340
340
  's.status',
341
341
  's.result',
342
342
  's.error',
343
343
  's.retries',
344
- 's.retry_delay',
345
- 's.created_at',
346
- 's.updated_at',
344
+ 's.retryDelay',
345
+ 's.createdAt',
346
+ 's.updatedAt',
347
347
  ])
348
348
  .select((eb) => eb
349
- .selectFrom('workflow_step_history')
349
+ .selectFrom('workflowStepHistory')
350
350
  .select(eb.fn.countAll().as('cnt'))
351
- .whereRef('workflow_step_history.workflow_step_id', '=', 's.workflow_step_id')
352
- .as('attempt_count'))
353
- .where('s.workflow_step_id', '=', stepId)
351
+ .whereRef('workflowStepHistory.workflowStepId', '=', 's.workflowStepId')
352
+ .as('attemptCount'))
353
+ .where('s.workflowStepId', '=', stepId)
354
354
  .executeTakeFirstOrThrow();
355
355
  return {
356
- stepId: row.workflow_step_id,
356
+ stepId: row.workflowStepId,
357
357
  status: row.status,
358
358
  result: parseJson(row.result),
359
359
  error: parseJson(row.error),
360
- attemptCount: Number(row.attempt_count),
360
+ attemptCount: Number(row.attemptCount),
361
361
  retries: row.retries != null ? Number(row.retries) : undefined,
362
- retryDelay: row.retry_delay ?? undefined,
363
- createdAt: new Date(row.created_at),
364
- updatedAt: new Date(row.updated_at),
362
+ retryDelay: row.retryDelay ?? undefined,
363
+ createdAt: new Date(row.createdAt),
364
+ updatedAt: new Date(row.updatedAt),
365
365
  };
366
366
  }
367
367
  async withRunLock(_id, fn) {
@@ -372,30 +372,30 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
372
372
  }
373
373
  async getCompletedGraphState(runId) {
374
374
  const results = await this.db
375
- .selectFrom('workflow_step as ws')
376
- .select(['ws.step_name', 'ws.status', 'ws.branch_taken', 'ws.retries'])
375
+ .selectFrom('workflowStep as ws')
376
+ .select(['ws.stepName', 'ws.status', 'ws.branchTaken', 'ws.retries'])
377
377
  .select((eb) => eb
378
- .selectFrom('workflow_step_history as h')
378
+ .selectFrom('workflowStepHistory as h')
379
379
  .select(eb.fn.countAll().as('cnt'))
380
- .whereRef('h.workflow_step_id', '=', 'ws.workflow_step_id')
381
- .as('attempt_count'))
382
- .where('ws.workflow_run_id', '=', runId)
380
+ .whereRef('h.workflowStepId', '=', 'ws.workflowStepId')
381
+ .as('attemptCount'))
382
+ .where('ws.workflowRunId', '=', runId)
383
383
  .where('ws.status', 'in', ['succeeded', 'failed'])
384
384
  .execute();
385
385
  const completedNodeIds = [];
386
386
  const failedNodeIds = [];
387
387
  const branchKeys = {};
388
388
  for (const row of results) {
389
- const nodeId = row.step_name;
389
+ const nodeId = row.stepName;
390
390
  if (row.status === 'succeeded') {
391
391
  completedNodeIds.push(nodeId);
392
- if (row.branch_taken) {
393
- branchKeys[nodeId] = row.branch_taken;
392
+ if (row.branchTaken) {
393
+ branchKeys[nodeId] = row.branchTaken;
394
394
  }
395
395
  }
396
396
  else if (row.status === 'failed') {
397
397
  const maxAttempts = (row.retries ?? 0) + 1;
398
- if (Number(row.attempt_count) >= maxAttempts) {
398
+ if (Number(row.attemptCount) >= maxAttempts) {
399
399
  failedNodeIds.push(nodeId);
400
400
  }
401
401
  }
@@ -406,56 +406,56 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
406
406
  if (nodeIds.length === 0)
407
407
  return [];
408
408
  const result = await this.db
409
- .selectFrom('workflow_step')
410
- .select('step_name')
411
- .where('workflow_run_id', '=', runId)
412
- .where('step_name', 'in', nodeIds)
409
+ .selectFrom('workflowStep')
410
+ .select('stepName')
411
+ .where('workflowRunId', '=', runId)
412
+ .where('stepName', 'in', nodeIds)
413
413
  .execute();
414
- const existingStepNames = new Set(result.map((r) => r.step_name));
414
+ const existingStepNames = new Set(result.map((r) => r.stepName));
415
415
  return nodeIds.filter((id) => !existingStepNames.has(id));
416
416
  }
417
417
  async getNodeResults(runId, nodeIds) {
418
418
  if (nodeIds.length === 0)
419
419
  return {};
420
420
  const result = await this.db
421
- .selectFrom('workflow_step')
422
- .select(['step_name', 'result'])
423
- .where('workflow_run_id', '=', runId)
424
- .where('step_name', 'in', nodeIds)
421
+ .selectFrom('workflowStep')
422
+ .select(['stepName', 'result'])
423
+ .where('workflowRunId', '=', runId)
424
+ .where('stepName', 'in', nodeIds)
425
425
  .where('status', '=', 'succeeded')
426
426
  .execute();
427
427
  const results = {};
428
428
  for (const row of result) {
429
- results[row.step_name] = parseJson(row.result);
429
+ results[row.stepName] = parseJson(row.result);
430
430
  }
431
431
  return results;
432
432
  }
433
433
  async setBranchTaken(stepId, branchKey) {
434
434
  await this.db
435
- .updateTable('workflow_step')
436
- .set({ branch_taken: branchKey, updated_at: new Date() })
437
- .where('workflow_step_id', '=', stepId)
435
+ .updateTable('workflowStep')
436
+ .set({ branchTaken: branchKey, updatedAt: new Date() })
437
+ .where('workflowStepId', '=', stepId)
438
438
  .execute();
439
439
  }
440
440
  async updateRunState(runId, name, value) {
441
441
  const row = await this.db
442
- .selectFrom('workflow_runs')
442
+ .selectFrom('workflowRuns')
443
443
  .select('state')
444
- .where('workflow_run_id', '=', runId)
444
+ .where('workflowRunId', '=', runId)
445
445
  .executeTakeFirst();
446
446
  const state = parseJson(row?.state) ?? {};
447
447
  state[name] = value;
448
448
  await this.db
449
- .updateTable('workflow_runs')
450
- .set({ state: JSON.stringify(state), updated_at: new Date() })
451
- .where('workflow_run_id', '=', runId)
449
+ .updateTable('workflowRuns')
450
+ .set({ state: JSON.stringify(state), updatedAt: new Date() })
451
+ .where('workflowRunId', '=', runId)
452
452
  .execute();
453
453
  }
454
454
  async getRunState(runId) {
455
455
  const row = await this.db
456
- .selectFrom('workflow_runs')
456
+ .selectFrom('workflowRuns')
457
457
  .select('state')
458
- .where('workflow_run_id', '=', runId)
458
+ .where('workflowRunId', '=', runId)
459
459
  .executeTakeFirst();
460
460
  if (!row)
461
461
  return {};
@@ -463,23 +463,23 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
463
463
  }
464
464
  async upsertWorkflowVersion(name, graphHash, graph, source, status) {
465
465
  await this.db
466
- .insertInto('workflow_versions')
466
+ .insertInto('workflowVersions')
467
467
  .values({
468
- workflow_name: name,
469
- graph_hash: graphHash,
468
+ workflowName: name,
469
+ graphHash: graphHash,
470
470
  graph: JSON.stringify(graph),
471
471
  source,
472
472
  status: status ?? 'active',
473
473
  })
474
- .onConflict((oc) => oc.columns(['workflow_name', 'graph_hash']).doNothing())
474
+ .onConflict((oc) => oc.columns(['workflowName', 'graphHash']).doNothing())
475
475
  .execute();
476
476
  }
477
477
  async updateWorkflowVersionStatus(name, graphHash, status) {
478
478
  await this.db
479
- .updateTable('workflow_versions')
479
+ .updateTable('workflowVersions')
480
480
  .set({ status })
481
- .where('workflow_name', '=', name)
482
- .where('graph_hash', '=', graphHash)
481
+ .where('workflowName', '=', name)
482
+ .where('graphHash', '=', graphHash)
483
483
  .execute();
484
484
  }
485
485
  async getWorkflowVersion(name, graphHash) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pikku/kysely",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "author": "yasser.fadl@gmail.com",
5
5
  "license": "MIT",
6
6
  "module": "dist/src/index.js",