@pikku/kysely 0.13.23 → 0.13.27

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 +248 -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-tables.d.ts +45 -0
  9. package/dist/src/kysely-webhook-service.d.ts +1 -1
  10. package/dist/src/kysely-webhook-service.js +1 -1
  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 -124
  58. package/src/kysely-webhook-service.ts +0 -137
  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,162 +0,0 @@
1
- import { sql } from 'kysely'
2
- import type { PikkuSchema } from './pikku-schema.types.js'
3
-
4
- /**
5
- * Threads, messages, tool calls, working memory and agent runs.
6
- *
7
- * `agentRun` carries `pendingApprovals` even though the two services that used to
8
- * create this table disagreed about it: `KyselyAgentStorageService` omitted the
9
- * column while `KyselyAgentRunStateService` declared it and read it back through
10
- * casts. Whichever service happened to run first decided the shape, and on a
11
- * database where the storage service won, resolving an approval failed. One
12
- * declaration ends that — the column is here because live code reads it.
13
- */
14
- export const agentSchema: PikkuSchema = {
15
- name: 'agent',
16
- ownedBy: ['agentStorage', 'agentRunState', 'agentRunService'],
17
- statements: [
18
- (db) =>
19
- db.schema
20
- .createTable('agentThreads')
21
- .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
22
- .addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
23
- .addColumn('title', 'text')
24
- .addColumn('metadata', 'text')
25
- .addColumn('createdAt', 'timestamp', (col) =>
26
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
27
- )
28
- .addColumn('updatedAt', 'timestamp', (col) =>
29
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
30
- ),
31
-
32
- (db) =>
33
- db.schema
34
- .createIndex('idx_agent_threads_resource')
35
- .on('agentThreads')
36
- .column('resourceId'),
37
-
38
- (db) =>
39
- db.schema
40
- .createTable('agentMessage')
41
- .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
42
- .addColumn('threadId', 'varchar(36)', (col) =>
43
- col.notNull().references('agentThreads.id').onDelete('cascade')
44
- )
45
- .addColumn('role', 'varchar(50)', (col) => col.notNull())
46
- .addColumn('content', 'text')
47
- .addColumn('createdAt', 'timestamp', (col) =>
48
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
49
- ),
50
-
51
- (db) =>
52
- db.schema
53
- .createIndex('idx_agent_message_thread')
54
- .on('agentMessage')
55
- .columns(['threadId', 'createdAt']),
56
-
57
- (db) =>
58
- db.schema
59
- .createTable('agentToolCall')
60
- .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
61
- .addColumn('threadId', 'varchar(36)', (col) =>
62
- col.notNull().references('agentThreads.id').onDelete('cascade')
63
- )
64
- .addColumn('messageId', 'varchar(36)', (col) =>
65
- col.notNull().references('agentMessage.id').onDelete('cascade')
66
- )
67
- .addColumn('runId', 'varchar(36)')
68
- .addColumn('toolName', 'varchar(255)', (col) => col.notNull())
69
- .addColumn('args', 'text', (col) => col.notNull())
70
- .addColumn('result', 'text')
71
- .addColumn('approvalStatus', 'varchar(50)')
72
- .addColumn('approvalType', 'varchar(50)')
73
- .addColumn('agentRunId', 'varchar(36)')
74
- .addColumn('displayToolName', 'varchar(255)')
75
- .addColumn('displayArgs', 'text')
76
- .addColumn('createdAt', 'timestamp', (col) =>
77
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
78
- ),
79
-
80
- (db) =>
81
- db.schema
82
- .createIndex('idx_agent_tool_call_thread')
83
- .on('agentToolCall')
84
- .column('threadId'),
85
-
86
- (db) =>
87
- db.schema
88
- .createIndex('idx_agent_tool_call_message')
89
- .on('agentToolCall')
90
- .column('messageId'),
91
-
92
- (db) =>
93
- db.schema
94
- .createTable('agentWorkingMemory')
95
- .addColumn('id', 'varchar(255)', (col) => col.notNull())
96
- .addColumn('scope', 'varchar(50)', (col) => col.notNull())
97
- .addColumn('data', 'text', (col) => col.notNull())
98
- .addColumn('updatedAt', 'timestamp', (col) =>
99
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
100
- )
101
- .addPrimaryKeyConstraint('agent_working_memory_pk', ['id', 'scope']),
102
-
103
- (db) =>
104
- db.schema
105
- .createTable('agentRun')
106
- .addColumn('runId', 'varchar(36)', (col) => col.primaryKey())
107
- .addColumn('agentName', 'varchar(255)', (col) => col.notNull())
108
- .addColumn('threadId', 'varchar(36)', (col) =>
109
- col.notNull().references('agentThreads.id').onDelete('cascade')
110
- )
111
- .addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
112
- .addColumn('status', 'varchar(50)', (col) =>
113
- col.notNull().defaultTo('running')
114
- )
115
- .addColumn('errorMessage', 'text')
116
- .addColumn('suspendReason', 'text')
117
- .addColumn('missingRpcs', 'text')
118
- .addColumn('pendingApprovals', 'text')
119
- .addColumn('usageInputTokens', 'integer', (col) =>
120
- col.notNull().defaultTo(0)
121
- )
122
- .addColumn('usageOutputTokens', 'integer', (col) =>
123
- col.notNull().defaultTo(0)
124
- )
125
- .addColumn('usageModel', 'varchar(255)', (col) =>
126
- col.notNull().defaultTo('')
127
- )
128
- .addColumn('createdAt', 'timestamp', (col) =>
129
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
130
- )
131
- .addColumn('updatedAt', 'timestamp', (col) =>
132
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
133
- ),
134
-
135
- (db) =>
136
- db.schema
137
- .createIndex('idx_agent_run_thread')
138
- .on('agentRun')
139
- .columns(['threadId', 'createdAt']),
140
-
141
- (db) =>
142
- db.schema
143
- .createTable('agentRunScore')
144
- .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
145
- .addColumn('runId', 'varchar(36)', (col) =>
146
- col.notNull().references('agentRun.runId').onDelete('cascade')
147
- )
148
- .addColumn('scorerName', 'varchar(255)', (col) => col.notNull())
149
- .addColumn('score', 'real', (col) => col.notNull())
150
- .addColumn('reason', 'text')
151
- .addColumn('metadata', 'text')
152
- .addColumn('createdAt', 'timestamp', (col) =>
153
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
154
- ),
155
-
156
- (db) =>
157
- db.schema
158
- .createIndex('idx_agent_run_score_run')
159
- .on('agentRunScore')
160
- .columns(['runId', 'createdAt']),
161
- ],
162
- }
@@ -1,57 +0,0 @@
1
- import type { PikkuSchema } from './pikku-schema.types.js'
2
-
3
- /**
4
- * The `audit` table {@link KyselyAuditService} writes to and reads back.
5
- *
6
- * Gated by `ownedBy` rather than written for everyone: only a project that has
7
- * wired a durable audit sink needs this table, and generating it for the rest
8
- * would put an empty table in every database. `KyselyAuditService.init()`
9
- * requires it and never creates it, so it arrives with the migration `pikku db
10
- * generate` writes for the sink that fills it.
11
- *
12
- * Every column is text on every engine, matching the platform audit-queue
13
- * consumer's row shape — a locally-run project and a deployed stage write rows
14
- * the same reader can read. `occurredAt` is an ISO 8601 string rather than a
15
- * timestamp for that reason: string ordering is chronological ordering, and the
16
- * queue consumer has no shared type to agree on.
17
- */
18
- export const auditSchema: PikkuSchema = {
19
- name: 'audit',
20
- ownedBy: ['audit', 'auditLog'],
21
- statements: [
22
- (db) =>
23
- db.schema
24
- .createTable('audit')
25
- .addColumn('auditId', 'text', (col) => col.primaryKey())
26
- .addColumn('occurredAt', 'text', (col) => col.notNull())
27
- .addColumn('type', 'text', (col) => col.notNull())
28
- .addColumn('source', 'text', (col) => col.defaultTo('auto').notNull())
29
- .addColumn('outcome', 'text')
30
- .addColumn('functionId', 'text')
31
- .addColumn('wireType', 'text')
32
- .addColumn('traceId', 'text')
33
- .addColumn('transactionId', 'text')
34
- .addColumn('queryId', 'text')
35
- .addColumn('userId', 'text')
36
- .addColumn('orgId', 'text')
37
- .addColumn('pikkuUserId', 'text')
38
- .addColumn('tables', 'text')
39
- .addColumn('changedCols', 'text')
40
- .addColumn('event', 'text')
41
- .addColumn('old', 'text')
42
- .addColumn('data', 'text'),
43
-
44
- // The trail is only ever read newest-first, and the two filters the console
45
- // offers are user and type.
46
- (db) =>
47
- db.schema
48
- .createIndex('idx_audit_occurred_at')
49
- .on('audit')
50
- .column('occurredAt'),
51
-
52
- (db) =>
53
- db.schema.createIndex('idx_audit_user_id').on('audit').column('userId'),
54
-
55
- (db) => db.schema.createIndex('idx_audit_type').on('audit').column('type'),
56
- ],
57
- }
@@ -1,38 +0,0 @@
1
- import { sql } from 'kysely'
2
- import type { PikkuSchema } from './pikku-schema.types.js'
3
-
4
- /** Channels and their topic subscriptions, also read by the event-hub store. */
5
- export const channelSchema: PikkuSchema = {
6
- name: 'channel',
7
- ownedBy: ['channelStore', 'eventHub'],
8
- statements: [
9
- (db) =>
10
- db.schema
11
- .createTable('channels')
12
- .addColumn('channelId', 'text', (col) => col.primaryKey())
13
- .addColumn('channelName', 'text', (col) => col.notNull())
14
- .addColumn('createdAt', 'timestamp', (col) =>
15
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
16
- )
17
- .addColumn('openingData', 'text', (col) =>
18
- col.notNull().defaultTo('{}')
19
- )
20
- .addColumn('pikkuUserId', 'text')
21
- .addColumn('state', 'text')
22
- .addColumn('lastWire', 'timestamp', (col) =>
23
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
24
- ),
25
-
26
- (db) =>
27
- db.schema
28
- .createTable('channelSubscriptions')
29
- .addColumn('channelId', 'text', (col) =>
30
- col.notNull().references('channels.channelId').onDelete('cascade')
31
- )
32
- .addColumn('topic', 'text', (col) => col.notNull())
33
- .addPrimaryKeyConstraint('channel_subscriptions_pk', [
34
- 'channelId',
35
- 'topic',
36
- ]),
37
- ],
38
- }
@@ -1,58 +0,0 @@
1
- import { sql } from 'kysely'
2
- import { rawStatement, type PikkuSchema } from './pikku-schema.types.js'
3
-
4
- /**
5
- * Encrypted per-user credentials and their audit trail.
6
- *
7
- * The uniqueness rule is an expression index — `user_id` is nullable and two
8
- * rows with a null user must still collide on name — which the schema builder
9
- * cannot express, so it stays raw. Raw SQL is not rewritten by `withSchema`,
10
- * which is why the table goes through `ctx.table` rather than being left to the
11
- * search path. The index's own name stays unqualified: an index belongs to the
12
- * schema of the table it is on, and postgres rejects one that says otherwise.
13
- */
14
- export const credentialSchema: PikkuSchema = {
15
- name: 'credential',
16
- ownedBy: ['credentialService'],
17
- statements: [
18
- (db) =>
19
- db.schema
20
- .createTable('credentials')
21
- .addColumn('name', 'varchar(255)', (col) => col.notNull())
22
- .addColumn('userId', 'varchar(255)')
23
- .addColumn('ciphertext', 'text', (col) => col.notNull())
24
- .addColumn('wrappedDek', 'text', (col) => col.notNull())
25
- .addColumn('keyVersion', 'integer', (col) => col.notNull())
26
- .addColumn('createdAt', 'timestamp', (col) =>
27
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
28
- )
29
- .addColumn('updatedAt', 'timestamp', (col) =>
30
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
31
- ),
32
-
33
- rawStatement(
34
- ({ table }) =>
35
- sql`CREATE UNIQUE INDEX credentials_name_user_id_unique ON ${table('credentials')} (name, COALESCE(user_id, ''))`
36
- ),
37
-
38
- (db) =>
39
- db.schema
40
- .createTable('credentialKekSalts')
41
- .addColumn('keyVersion', 'integer', (col) => col.primaryKey())
42
- .addColumn('salt', 'varchar(64)', (col) => col.notNull())
43
- .addColumn('createdAt', 'timestamp', (col) =>
44
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
45
- ),
46
-
47
- (db) =>
48
- db.schema
49
- .createTable('credentialsAudit')
50
- .addColumn('id', 'varchar(36)', (col) => col.primaryKey())
51
- .addColumn('credentialName', 'varchar(255)', (col) => col.notNull())
52
- .addColumn('userId', 'varchar(255)')
53
- .addColumn('action', 'varchar(20)', (col) => col.notNull())
54
- .addColumn('performedAt', 'timestamp', (col) =>
55
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
56
- ),
57
- ],
58
- }
@@ -1,47 +0,0 @@
1
- import { sql } from 'kysely'
2
- import type { PikkuSchema } from './pikku-schema.types.js'
3
-
4
- /** Registered deployments and the functions each one serves. */
5
- export const deploymentSchema: PikkuSchema = {
6
- name: 'deployment',
7
- statements: [
8
- (db) =>
9
- db.schema
10
- .createTable('pikkuDeployments')
11
- .addColumn('deploymentId', 'text', (col) => col.primaryKey())
12
- .addColumn('endpoint', 'text', (col) => col.notNull())
13
- .addColumn('lastHeartbeat', 'timestamp', (col) =>
14
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
15
- )
16
- .addColumn('createdAt', 'timestamp', (col) =>
17
- col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
18
- ),
19
-
20
- (db) =>
21
- db.schema
22
- .createTable('pikkuDeploymentFunctions')
23
- .addColumn('deploymentId', 'text', (col) =>
24
- col
25
- .notNull()
26
- .references('pikkuDeployments.deploymentId')
27
- .onDelete('cascade')
28
- )
29
- .addColumn('functionName', 'text', (col) => col.notNull())
30
- .addPrimaryKeyConstraint('pikku_deployment_functions_pk', [
31
- 'deploymentId',
32
- 'functionName',
33
- ]),
34
-
35
- (db) =>
36
- db.schema
37
- .createIndex('idx_pikku_deployments_heartbeat')
38
- .on('pikkuDeployments')
39
- .column('lastHeartbeat'),
40
-
41
- (db) =>
42
- db.schema
43
- .createIndex('idx_pikku_deployment_functions_name')
44
- .on('pikkuDeploymentFunctions')
45
- .column('functionName'),
46
- ],
47
- }