@pikku/kysely 0.13.3 → 0.13.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/src/index.d.ts +1 -0
  3. package/dist/src/index.js +1 -0
  4. package/dist/src/kysely-ai-run-state-service.js +3 -18
  5. package/dist/src/kysely-ai-storage-service.d.ts +0 -1
  6. package/dist/src/kysely-ai-storage-service.js +4 -101
  7. package/dist/src/kysely-channel-store.js +4 -24
  8. package/dist/src/kysely-credential-service.js +3 -24
  9. package/dist/src/kysely-deployment-service.d.ts +0 -1
  10. package/dist/src/kysely-deployment-service.js +4 -48
  11. package/dist/src/kysely-scope-service.js +4 -54
  12. package/dist/src/kysely-secret-service.js +3 -21
  13. package/dist/src/kysely-session-store.js +4 -11
  14. package/dist/src/kysely-tables.d.ts +2 -0
  15. package/dist/src/kysely-webhook-service.d.ts +0 -1
  16. package/dist/src/kysely-webhook-service.js +4 -51
  17. package/dist/src/kysely-workflow-mirror.d.ts +7 -3
  18. package/dist/src/kysely-workflow-mirror.js +10 -87
  19. package/dist/src/kysely-workflow-service.js +9 -93
  20. package/dist/src/schema/ai.schema.d.ts +12 -0
  21. package/dist/src/schema/ai.schema.js +89 -0
  22. package/dist/src/schema/channel.schema.d.ts +3 -0
  23. package/dist/src/schema/channel.schema.js +24 -0
  24. package/dist/src/schema/credential.schema.d.ts +11 -0
  25. package/dist/src/schema/credential.schema.js +33 -0
  26. package/dist/src/schema/deployment.schema.d.ts +3 -0
  27. package/dist/src/schema/deployment.schema.js +32 -0
  28. package/dist/src/schema/index.d.ts +99 -0
  29. package/dist/src/schema/index.js +274 -0
  30. package/dist/src/schema/pikku-schema.types.d.ts +75 -0
  31. package/dist/src/schema/pikku-schema.types.js +21 -0
  32. package/dist/src/schema/scope.schema.d.ts +18 -0
  33. package/dist/src/schema/scope.schema.js +61 -0
  34. package/dist/src/schema/secret.schema.d.ts +11 -0
  35. package/dist/src/schema/secret.schema.js +29 -0
  36. package/dist/src/schema/session.schema.d.ts +3 -0
  37. package/dist/src/schema/session.schema.js +13 -0
  38. package/dist/src/schema/webhook.schema.d.ts +3 -0
  39. package/dist/src/schema/webhook.schema.js +38 -0
  40. package/dist/src/schema/workflow.schema.d.ts +15 -0
  41. package/dist/src/schema/workflow.schema.js +86 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +1 -1
  44. package/src/index.ts +18 -0
  45. package/src/kysely-ai-run-state-service.ts +7 -28
  46. package/src/kysely-ai-storage-service.ts +4 -152
  47. package/src/kysely-channel-store.ts +4 -34
  48. package/src/kysely-credential-service.ts +3 -36
  49. package/src/kysely-deployment-service.ts +4 -63
  50. package/src/kysely-scope-service.ts +4 -81
  51. package/src/kysely-secret-service.ts +6 -33
  52. package/src/kysely-session-store.ts +4 -18
  53. package/src/kysely-tables.test.ts +110 -0
  54. package/src/kysely-tables.ts +2 -0
  55. package/src/kysely-webhook-service.ts +4 -67
  56. package/src/kysely-workflow-mirror.test.ts +7 -7
  57. package/src/kysely-workflow-mirror.ts +10 -109
  58. package/src/kysely-workflow-service.ts +12 -123
  59. package/src/schema/ai.schema.ts +140 -0
  60. package/src/schema/channel.schema.ts +37 -0
  61. package/src/schema/credential.schema.ts +46 -0
  62. package/src/schema/deployment.schema.ts +47 -0
  63. package/src/schema/index.ts +374 -0
  64. package/src/schema/pikku-schema.types.ts +94 -0
  65. package/src/schema/schema.test.ts +456 -0
  66. package/src/schema/scope.schema.ts +95 -0
  67. package/src/schema/secret.schema.ts +40 -0
  68. package/src/schema/session.schema.ts +20 -0
  69. package/src/schema/webhook.schema.ts +57 -0
  70. package/src/schema/workflow.schema.ts +113 -0
@@ -0,0 +1,20 @@
1
+ import { sql } from 'kysely'
2
+ import type { PikkuSchema } from './pikku-schema.types.js'
3
+
4
+ /** Server-side session storage. */
5
+ export const sessionSchema: PikkuSchema = {
6
+ name: 'session',
7
+ statements: [
8
+ (db) =>
9
+ db.schema
10
+ .createTable('pikkuUserSessions')
11
+ .addColumn('pikkuUserId', 'text', (col) => col.primaryKey())
12
+ .addColumn('session', 'text', (col) => col.notNull())
13
+ .addColumn('createdAt', 'timestamp', (col) =>
14
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
15
+ )
16
+ .addColumn('updatedAt', 'timestamp', (col) =>
17
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
18
+ ),
19
+ ],
20
+ }
@@ -0,0 +1,57 @@
1
+ import { sql } from 'kysely'
2
+ import type { PikkuSchema } from './pikku-schema.types.js'
3
+
4
+ /** Webhook deliveries and one row per delivery attempt. */
5
+ export const webhookSchema: PikkuSchema = {
6
+ name: 'webhook',
7
+ statements: [
8
+ (db) =>
9
+ db.schema
10
+ .createTable('webhookDelivery')
11
+ .addColumn('deliveryId', 'text', (col) => col.primaryKey())
12
+ .addColumn('organizationId', 'text')
13
+ .addColumn('url', 'text', (col) => col.notNull())
14
+ .addColumn('event', 'text')
15
+ .addColumn('status', 'text', (col) =>
16
+ col.defaultTo('pending').notNull()
17
+ )
18
+ .addColumn('attempts', 'integer', (col) => col.defaultTo(0).notNull())
19
+ .addColumn('createdAt', 'timestamp', (col) =>
20
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
21
+ )
22
+ .addColumn('updatedAt', 'timestamp', (col) =>
23
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
24
+ )
25
+ .addColumn('deliveredAt', 'timestamp'),
26
+
27
+ (db) =>
28
+ db.schema
29
+ .createTable('webhookDeliveryAttempt')
30
+ .addColumn('attemptId', 'text', (col) => col.primaryKey())
31
+ .addColumn('deliveryId', 'text', (col) =>
32
+ col
33
+ .notNull()
34
+ .references('webhookDelivery.deliveryId')
35
+ .onDelete('cascade')
36
+ )
37
+ .addColumn('attemptNumber', 'integer', (col) => col.notNull())
38
+ .addColumn('statusCode', 'integer')
39
+ .addColumn('responseBody', 'text')
40
+ .addColumn('error', 'text')
41
+ .addColumn('createdAt', 'timestamp', (col) =>
42
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
43
+ ),
44
+
45
+ (db) =>
46
+ db.schema
47
+ .createIndex('idx_webhook_delivery_org')
48
+ .on('webhookDelivery')
49
+ .column('organizationId'),
50
+
51
+ (db) =>
52
+ db.schema
53
+ .createIndex('idx_webhook_delivery_attempt_delivery')
54
+ .on('webhookDeliveryAttempt')
55
+ .column('deliveryId'),
56
+ ],
57
+ }
@@ -0,0 +1,113 @@
1
+ import { sql } from 'kysely'
2
+ import type { PikkuSchema } from './pikku-schema.types.js'
3
+
4
+ /**
5
+ * Workflow runs, their steps, per-step history and the versioned graphs.
6
+ *
7
+ * Two things from the boot-time DDL are deliberately not carried over. The
8
+ * primary keys had `defaultTo(sql.raw("'" + crypto.randomUUID() + "'"))`, which
9
+ * evaluates once while the statement is built — every row would have taken the
10
+ * same default, so it was never a generator; the services supply the id. And
11
+ * `workflowStep.fromStepName` was backfilled by an `alterTable(...).catch(() =>
12
+ * {})` bolted on after the fact, which is the job a migration does.
13
+ *
14
+ * `KyselyWorkflowMirror` created these same four tables separately. There is one
15
+ * declaration now, and both services read it.
16
+ */
17
+ export const workflowSchema: PikkuSchema = {
18
+ name: 'workflow',
19
+ statements: [
20
+ (db) =>
21
+ db.schema
22
+ .createTable('workflowRuns')
23
+ .addColumn('workflowRunId', 'text', (col) => col.primaryKey())
24
+ .addColumn('workflow', 'text', (col) => col.notNull())
25
+ .addColumn('status', 'text', (col) => col.notNull())
26
+ .addColumn('input', 'text', (col) => col.notNull())
27
+ .addColumn('output', 'text')
28
+ .addColumn('error', 'text')
29
+ .addColumn('state', 'text', (col) => col.defaultTo('{}'))
30
+ .addColumn('inline', 'boolean', (col) => col.defaultTo(false))
31
+ .addColumn('graphHash', 'text')
32
+ .addColumn('deterministic', 'boolean', (col) => col.defaultTo(false))
33
+ .addColumn('plannedSteps', 'text')
34
+ .addColumn('wire', 'text')
35
+ .addColumn('createdAt', 'timestamp', (col) =>
36
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
37
+ )
38
+ .addColumn('updatedAt', 'timestamp', (col) =>
39
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
40
+ ),
41
+
42
+ (db) =>
43
+ db.schema
44
+ .createTable('workflowStep')
45
+ .addColumn('workflowStepId', 'text', (col) => col.primaryKey())
46
+ .addColumn('workflowRunId', 'text', (col) =>
47
+ col
48
+ .notNull()
49
+ .references('workflowRuns.workflowRunId')
50
+ .onDelete('cascade')
51
+ )
52
+ .addColumn('stepName', 'text', (col) => col.notNull())
53
+ .addColumn('rpcName', 'text')
54
+ .addColumn('data', 'text')
55
+ .addColumn('status', 'text', (col) =>
56
+ col.notNull().defaultTo('pending')
57
+ )
58
+ .addColumn('result', 'text')
59
+ .addColumn('error', 'text')
60
+ .addColumn('childRunId', 'text')
61
+ .addColumn('branchTaken', 'text')
62
+ .addColumn('retries', 'integer')
63
+ .addColumn('retryDelay', 'text')
64
+ .addColumn('fromStepName', 'text')
65
+ .addColumn('createdAt', 'timestamp', (col) =>
66
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
67
+ )
68
+ .addColumn('updatedAt', 'timestamp', (col) =>
69
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
70
+ )
71
+ .addUniqueConstraint('workflow_step_run_name_unique', [
72
+ 'workflowRunId',
73
+ 'stepName',
74
+ ]),
75
+
76
+ (db) =>
77
+ db.schema
78
+ .createTable('workflowStepHistory')
79
+ .addColumn('historyId', 'text', (col) => col.primaryKey())
80
+ .addColumn('workflowStepId', 'text', (col) =>
81
+ col
82
+ .notNull()
83
+ .references('workflowStep.workflowStepId')
84
+ .onDelete('cascade')
85
+ )
86
+ .addColumn('status', 'text', (col) => col.notNull())
87
+ .addColumn('result', 'text')
88
+ .addColumn('error', 'text')
89
+ .addColumn('createdAt', 'timestamp', (col) =>
90
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
91
+ )
92
+ .addColumn('runningAt', 'timestamp')
93
+ .addColumn('scheduledAt', 'timestamp')
94
+ .addColumn('succeededAt', 'timestamp')
95
+ .addColumn('failedAt', 'timestamp'),
96
+
97
+ (db) =>
98
+ db.schema
99
+ .createTable('workflowVersions')
100
+ .addColumn('workflowName', 'text', (col) => col.notNull())
101
+ .addColumn('graphHash', 'text', (col) => col.notNull())
102
+ .addColumn('graph', 'text', (col) => col.notNull())
103
+ .addColumn('source', 'text', (col) => col.notNull())
104
+ .addColumn('status', 'text', (col) => col.notNull().defaultTo('active'))
105
+ .addColumn('createdAt', 'timestamp', (col) =>
106
+ col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
107
+ )
108
+ .addPrimaryKeyConstraint('workflow_versions_pk', [
109
+ 'workflowName',
110
+ 'graphHash',
111
+ ]),
112
+ ],
113
+ }