@pikku/kysely 0.13.24 → 0.13.28

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 (80) hide show
  1. package/CHANGELOG.md +271 -0
  2. package/dist/src/index.d.ts +4 -1
  3. package/dist/src/index.js +3 -1
  4. package/dist/src/kysely-analytics-service.d.ts +30 -0
  5. package/dist/src/kysely-analytics-service.js +80 -0
  6. package/dist/src/kysely-feature-flag-store.d.ts +37 -0
  7. package/dist/src/kysely-feature-flag-store.js +239 -0
  8. package/dist/src/kysely-scope-service.d.ts +1 -0
  9. package/dist/src/kysely-scope-service.js +29 -0
  10. package/dist/src/kysely-tables.d.ts +45 -0
  11. package/dist/src/schema/analytics.schema.d.ts +17 -0
  12. package/dist/src/schema/analytics.schema.js +48 -0
  13. package/dist/src/schema/flag.schema.d.ts +16 -0
  14. package/dist/src/schema/flag.schema.js +62 -0
  15. package/dist/src/schema/index.d.ts +2 -0
  16. package/dist/src/schema/index.js +6 -0
  17. package/package.json +11 -6
  18. package/run-tests.sh +9 -1
  19. package/bin/pikku-kysely-pure.ts +0 -59
  20. package/dist/src/kysely-lock-vault.d.ts +0 -34
  21. package/dist/src/kysely-lock-vault.js +0 -77
  22. package/dist/src/schema/data-lock.schema.d.ts +0 -15
  23. package/dist/src/schema/data-lock.schema.js +0 -27
  24. package/dist/tsconfig.tsbuildinfo +0 -1
  25. package/src/classification-crypto.test.ts +0 -143
  26. package/src/classification-crypto.ts +0 -163
  27. package/src/classification-plugin.pglite.test.ts +0 -226
  28. package/src/classification-plugin.test.ts +0 -265
  29. package/src/classification-plugin.ts +0 -249
  30. package/src/coercion-plugin.test.ts +0 -160
  31. package/src/coercion-plugin.ts +0 -187
  32. package/src/create-audited-kysely.test.ts +0 -560
  33. package/src/create-audited-kysely.ts +0 -254
  34. package/src/index.ts +0 -81
  35. package/src/kysely-agent-run-scores.ts +0 -47
  36. package/src/kysely-agent-run-service.ts +0 -244
  37. package/src/kysely-agent-run-state-service.ts +0 -200
  38. package/src/kysely-agent-storage-service.ts +0 -632
  39. package/src/kysely-audit-service.test.ts +0 -352
  40. package/src/kysely-audit-service.ts +0 -237
  41. package/src/kysely-channel-store.ts +0 -107
  42. package/src/kysely-credential-service.ts +0 -286
  43. package/src/kysely-deployment-service.ts +0 -163
  44. package/src/kysely-eventhub-store.ts +0 -53
  45. package/src/kysely-json.ts +0 -5
  46. package/src/kysely-scope-service.test.ts +0 -418
  47. package/src/kysely-scope-service.ts +0 -425
  48. package/src/kysely-secret-service.ts +0 -242
  49. package/src/kysely-services.test.ts +0 -405
  50. package/src/kysely-session-store.ts +0 -57
  51. package/src/kysely-tables.test.ts +0 -110
  52. package/src/kysely-tables.ts +0 -434
  53. package/src/kysely-virtual-user-run-store.test.ts +0 -369
  54. package/src/kysely-virtual-user-run-store.ts +0 -235
  55. package/src/kysely-virtual-user-schedule-store.test.ts +0 -187
  56. package/src/kysely-virtual-user-schedule-store.ts +0 -187
  57. package/src/kysely-webhook-service.test.ts +0 -153
  58. package/src/kysely-webhook-service.ts +0 -139
  59. package/src/kysely-workflow-mirror.test.ts +0 -259
  60. package/src/kysely-workflow-mirror.ts +0 -374
  61. package/src/kysely-workflow-run-service.ts +0 -305
  62. package/src/kysely-workflow-service.test.ts +0 -544
  63. package/src/kysely-workflow-service.ts +0 -820
  64. package/src/schema/agent.schema.ts +0 -162
  65. package/src/schema/audit.schema.ts +0 -57
  66. package/src/schema/channel.schema.ts +0 -38
  67. package/src/schema/credential.schema.ts +0 -58
  68. package/src/schema/deployment.schema.ts +0 -47
  69. package/src/schema/index.ts +0 -441
  70. package/src/schema/pikku-schema.types.ts +0 -169
  71. package/src/schema/schema.test.ts +0 -591
  72. package/src/schema/scope.schema.ts +0 -110
  73. package/src/schema/secret.schema.ts +0 -49
  74. package/src/schema/session.schema.ts +0 -20
  75. package/src/schema/virtual-user-schedule.schema.ts +0 -48
  76. package/src/schema/virtual-user.schema.ts +0 -106
  77. package/src/schema/webhook.schema.ts +0 -58
  78. package/src/schema/workflow.schema.ts +0 -150
  79. package/src/serialize-plugin.ts +0 -233
  80. package/tsconfig.json +0 -17
@@ -1,305 +0,0 @@
1
- import type {
2
- WorkflowRun,
3
- StepState,
4
- WorkflowStatus,
5
- WorkflowRunService,
6
- } from '@pikku/core/workflow'
7
- import type { Kysely } from 'kysely'
8
- import type { KyselyPikkuDB } from './kysely-tables.js'
9
- import { parseJson } from './kysely-json.js'
10
-
11
- export class KyselyWorkflowRunService implements WorkflowRunService {
12
- constructor(private db: Kysely<KyselyPikkuDB>) {}
13
-
14
- async listRuns(options?: {
15
- workflowName?: string
16
- status?: string
17
- limit?: number
18
- offset?: number
19
- }): Promise<WorkflowRun[]> {
20
- const { workflowName, status, limit = 50, offset = 0 } = options ?? {}
21
-
22
- let query = this.db
23
- .selectFrom('workflowRuns')
24
- .select([
25
- 'workflowRunId',
26
- 'workflow',
27
- 'status',
28
- 'input',
29
- 'output',
30
- 'error',
31
- 'inline',
32
- 'graphHash',
33
- 'deterministic',
34
- 'plannedSteps',
35
- 'wire',
36
- 'createdAt',
37
- 'updatedAt',
38
- ])
39
-
40
- if (workflowName) {
41
- query = query.where('workflow', '=', workflowName)
42
- }
43
-
44
- if (status) {
45
- query = query.where('status', '=', status as WorkflowStatus)
46
- }
47
-
48
- const result = await query
49
- .orderBy('createdAt', 'desc')
50
- .limit(limit)
51
- .offset(offset)
52
- .execute()
53
-
54
- return result.map((row) => this.mapRunRow(row))
55
- }
56
-
57
- async getRun(id: string): Promise<WorkflowRun | null> {
58
- const row = await this.db
59
- .selectFrom('workflowRuns')
60
- .select([
61
- 'workflowRunId',
62
- 'workflow',
63
- 'status',
64
- 'input',
65
- 'output',
66
- 'error',
67
- 'inline',
68
- 'graphHash',
69
- 'deterministic',
70
- 'plannedSteps',
71
- 'wire',
72
- 'createdAt',
73
- 'updatedAt',
74
- ])
75
- .where('workflowRunId', '=', id)
76
- .executeTakeFirst()
77
-
78
- if (!row) return null
79
- return this.mapRunRow(row)
80
- }
81
-
82
- async getRunSteps(
83
- runId: string
84
- ): Promise<
85
- Array<StepState & { stepName: string; rpcName?: string; data?: any }>
86
- > {
87
- const result = await this.db
88
- .selectFrom('workflowStep as s')
89
- .select([
90
- 's.workflowStepId',
91
- 's.stepName',
92
- 's.rpcName',
93
- 's.data',
94
- 's.status',
95
- 's.result',
96
- 's.error',
97
- 's.childRunId',
98
- 's.retries',
99
- 's.retryDelay',
100
- 's.createdAt',
101
- 's.updatedAt',
102
- ])
103
- .select((eb) =>
104
- eb
105
- .selectFrom('workflowStepHistory')
106
- .select(eb.fn.countAll<number>().as('cnt'))
107
- .whereRef(
108
- 'workflowStepHistory.workflowStepId',
109
- '=',
110
- 's.workflowStepId'
111
- )
112
- .as('attemptCount')
113
- )
114
- // Build these correlated subqueries through the query builder rather
115
- // than a raw `sql` fragment so the active schema (e.g.
116
- // `withSchema('app')`) is applied to `workflow_step_history`. A raw
117
- // fragment hardcodes an unqualified table name and dies against a
118
- // connection whose search_path does not include the schema.
119
- .select((eb) =>
120
- eb
121
- .selectFrom('workflowStepHistory')
122
- .select((eb2) => eb2.fn.max('workflowStepHistory.runningAt').as('m'))
123
- .whereRef(
124
- 'workflowStepHistory.workflowStepId',
125
- '=',
126
- 's.workflowStepId'
127
- )
128
- .as('runningAt')
129
- )
130
- .select((eb) =>
131
- eb
132
- .selectFrom('workflowStepHistory')
133
- .select((eb2) =>
134
- eb2.fn.max('workflowStepHistory.succeededAt').as('m')
135
- )
136
- .whereRef(
137
- 'workflowStepHistory.workflowStepId',
138
- '=',
139
- 's.workflowStepId'
140
- )
141
- .as('succeededAt')
142
- )
143
- .select((eb) =>
144
- eb
145
- .selectFrom('workflowStepHistory')
146
- .select((eb2) => eb2.fn.max('workflowStepHistory.failedAt').as('m'))
147
- .whereRef(
148
- 'workflowStepHistory.workflowStepId',
149
- '=',
150
- 's.workflowStepId'
151
- )
152
- .as('failedAt')
153
- )
154
- .where('s.workflowRunId', '=', runId)
155
- .orderBy('s.createdAt', 'asc')
156
- .execute()
157
-
158
- return result.map((row) => ({
159
- stepId: row.workflowStepId,
160
- stepName: row.stepName,
161
- rpcName: row.rpcName ?? undefined,
162
- data: parseJson(row.data),
163
- status: row.status as StepState['status'],
164
- result: parseJson(row.result),
165
- error: parseJson(row.error),
166
- childRunId: row.childRunId ?? undefined,
167
- attemptCount: Number(row.attemptCount || 1),
168
- retries: row.retries != null ? Number(row.retries) : undefined,
169
- retryDelay: row.retryDelay ?? undefined,
170
- createdAt: new Date(row.createdAt as unknown as string),
171
- updatedAt: new Date(row.updatedAt as unknown as string),
172
- runningAt: row.runningAt
173
- ? new Date(row.runningAt as unknown as string)
174
- : undefined,
175
- succeededAt: row.succeededAt
176
- ? new Date(row.succeededAt as unknown as string)
177
- : undefined,
178
- failedAt: row.failedAt
179
- ? new Date(row.failedAt as unknown as string)
180
- : undefined,
181
- }))
182
- }
183
-
184
- async getRunHistory(
185
- runId: string
186
- ): Promise<Array<StepState & { stepName: string }>> {
187
- const result = await this.db
188
- .selectFrom('workflowStep as s')
189
- .innerJoin(
190
- 'workflowStepHistory as h',
191
- 'h.workflowStepId',
192
- 's.workflowStepId'
193
- )
194
- .select([
195
- 's.workflowStepId',
196
- 's.stepName',
197
- 's.fromStepName',
198
- 's.retries',
199
- 's.retryDelay',
200
- 'h.status',
201
- 'h.result',
202
- 'h.error',
203
- 'h.attempt',
204
- 'h.createdAt',
205
- 'h.runningAt',
206
- 'h.scheduledAt',
207
- 'h.succeededAt',
208
- 'h.failedAt',
209
- ])
210
- .where('s.workflowRunId', '=', runId)
211
- // `attempt` breaks the tie when a retry lands in the same millisecond as
212
- // the attempt it replaces, which `createdAt` alone cannot order.
213
- .orderBy('h.createdAt', 'asc')
214
- .orderBy('h.attempt', 'asc')
215
- .execute()
216
-
217
- let attemptCounters: Record<string, number> = {}
218
- return result.map((row) => {
219
- const stepId = row.workflowStepId
220
- attemptCounters[stepId] = (attemptCounters[stepId] ?? 0) + 1
221
-
222
- return {
223
- stepId,
224
- stepName: row.stepName,
225
- fromStepName: row.fromStepName ?? undefined,
226
- status: row.status as StepState['status'],
227
- result: parseJson(row.result),
228
- error: parseJson(row.error),
229
- attemptCount: attemptCounters[stepId]!,
230
- retries: row.retries != null ? Number(row.retries) : undefined,
231
- retryDelay: row.retryDelay ?? undefined,
232
- createdAt: new Date(row.createdAt as unknown as string),
233
- updatedAt: new Date(row.createdAt as unknown as string),
234
- runningAt: row.runningAt
235
- ? new Date(row.runningAt as unknown as string)
236
- : undefined,
237
- scheduledAt: row.scheduledAt
238
- ? new Date(row.scheduledAt as unknown as string)
239
- : undefined,
240
- succeededAt: row.succeededAt
241
- ? new Date(row.succeededAt as unknown as string)
242
- : undefined,
243
- failedAt: row.failedAt
244
- ? new Date(row.failedAt as unknown as string)
245
- : undefined,
246
- }
247
- })
248
- }
249
-
250
- async getDistinctWorkflowNames(): Promise<string[]> {
251
- const result = await this.db
252
- .selectFrom('workflowRuns')
253
- .select('workflow')
254
- .distinct()
255
- .orderBy('workflow')
256
- .execute()
257
-
258
- return result.map((row) => row.workflow)
259
- }
260
-
261
- async getWorkflowVersion(
262
- name: string,
263
- graphHash: string
264
- ): Promise<{ graph: any; source: string } | null> {
265
- const row = await this.db
266
- .selectFrom('workflowVersions')
267
- .select(['graph', 'source'])
268
- .where('workflowName', '=', name)
269
- .where('graphHash', '=', graphHash)
270
- .executeTakeFirst()
271
-
272
- if (!row) return null
273
- return {
274
- graph: parseJson(row.graph),
275
- source: row.source,
276
- }
277
- }
278
-
279
- async deleteRun(id: string): Promise<boolean> {
280
- const result = await this.db
281
- .deleteFrom('workflowRuns')
282
- .where('workflowRunId', '=', id)
283
- .executeTakeFirst()
284
-
285
- return BigInt(result.numDeletedRows) > 0n
286
- }
287
-
288
- private mapRunRow(row: any): WorkflowRun {
289
- return {
290
- id: row.workflowRunId as string,
291
- workflow: row.workflow as string,
292
- status: row.status as WorkflowStatus,
293
- input: parseJson(row.input),
294
- output: parseJson(row.output),
295
- error: parseJson(row.error),
296
- inline: row.inline as boolean | undefined,
297
- graphHash: row.graphHash as string | undefined,
298
- deterministic: row.deterministic as boolean | undefined,
299
- plannedSteps: parseJson(row.plannedSteps),
300
- wire: parseJson(row.wire) ?? { type: 'unknown' },
301
- createdAt: new Date(row.createdAt as string),
302
- updatedAt: new Date(row.updatedAt as string),
303
- }
304
- }
305
- }