@pikku/kysely 0.13.33 → 0.13.35
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.
- package/CHANGELOG.md +48 -0
- package/dist/bin/pikku-kysely-pure.js +4 -1
- package/dist/src/classification-crypto.js +16 -2
- package/dist/src/kysely-deployment-service.js +4 -1
- package/dist/src/kysely-virtual-user-run-store.js +1 -2
- package/dist/src/kysely-workflow-service.d.ts +5 -0
- package/dist/src/kysely-workflow-service.js +3 -0
- package/dist/src/schema/agent.schema.js +43 -36
- package/dist/src/schema/analytics.schema.js +17 -17
- package/dist/src/schema/audit.schema.js +22 -22
- package/dist/src/schema/channel.schema.js +13 -10
- package/dist/src/schema/credential.schema.js +6 -6
- package/dist/src/schema/deployment.schema.js +12 -12
- package/dist/src/schema/flag.schema.js +15 -12
- package/dist/src/schema/incoming-webhook.schema.js +7 -7
- package/dist/src/schema/index.js +30 -7
- package/dist/src/schema/lease.schema.js +3 -3
- package/dist/src/schema/pikku-schema.types.d.ts +42 -2
- package/dist/src/schema/pikku-schema.types.js +23 -7
- package/dist/src/schema/scope.schema.js +34 -22
- package/dist/src/schema/secret.schema.js +5 -5
- package/dist/src/schema/session.schema.js +3 -3
- package/dist/src/schema/trigger-source.schema.js +8 -8
- package/dist/src/schema/virtual-user-schedule.schema.js +4 -4
- package/dist/src/schema/virtual-user.schema.js +14 -14
- package/dist/src/schema/webhook.schema.js +17 -17
- package/dist/src/schema/workflow.schema.js +49 -49
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
+
## 0.13.35
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- 15c4968: The default runtime path no longer needs `node:*`, `Buffer` or an unguarded `process`, so it loads on edge runtimes (Web APIs only).
|
|
6
|
+
|
|
7
|
+
**Breaking:** `FileScenarioRunStore`, `scenarioArtifactContentType` and `scenarioRunSummary` leave the `@pikku/core/services` barrel because they use `node:fs`. Import them from `@pikku/core/services/file-scenario-run-store`. Pre-0.13 breaking changes still ship as a patch.
|
|
8
|
+
|
|
9
|
+
**Breaking:** the HMAC helpers in `@pikku/core/hmac` run on Web Crypto, which is async. `hmacSha256Hex`, `hmacDigest`, `verifyHmacSignature` and `verifyPublicKeySignature` now return a Promise; `timingSafeStringEqual` stays synchronous. `WebhookService.sign` and `WebhookService.verify` return a Promise, and so does `verifySlackSignature` in `@pikku/gateway-slack`: `await` them. A function-style `verify` on a webhook source may return a Promise as well. `verifyPublicKeySignature` accepts RSA and EC (P-256, P-384, P-521) PEM keys; Ed25519 and RSA-PSS keys verify as false.
|
|
10
|
+
|
|
11
|
+
`isProduction()` (and the `PIKKU_MODEL_ALIASES` and `PIKKU_ENV` reads) now ask the registered singleton services' `variables` service first, then `process.env` when `process` exists. With neither, `isProduction()` is true, so an edge deployment never exposes error details by accident. `LocalVariablesService` resolves its `process.env` default when constructed and falls back to an empty store without `process`.
|
|
12
|
+
|
|
13
|
+
Workflow invocation ids use a built-in SHA-1 and stay byte-identical. `@pikku/kysely` and the Cloudflare hibernation server use `globalThis.crypto.randomUUID()` and no `Buffer`; `@pikku/kysely` is marked `sideEffects: false`. `@pikku/ai-deepinfra` reads `DEEPINFRA_API_KEY` only when `process` exists and decodes base64 audio without `Buffer`.
|
|
14
|
+
|
|
15
|
+
Runtime tiers. A package declares where it can run in `package.json`: `"pikku": { "runtime": "edge" | "serverless" | "server" }`, with optional per-subpath overrides (`"exports": { "./dev": "server" }`). `server` is the default. `@pikku/core` and the default services are `edge` (core's Node-only subpaths are `server`), `@pikku/better-auth`, `@pikku/addon-admin` and `@pikku/cloudflare` are `serverless` (better-auth statically imports `node:crypto` scrypt), and `@pikku/addon-console` is `server` and must never land in a deployed unit.
|
|
16
|
+
|
|
17
|
+
`pikku deploy` now verifies each deployed unit before bundling it. The unit is bundled with esbuild (neutral platform, `workerd`/`worker`/`browser` conditions) under its tier's profile, ahead of the adapter's aliases and stubs so they cannot hide anything, and the build fails when the bundle holds a package declared above the unit's tier or a Node built-in the runtime does not provide. The error names the unit, package, import chain and the fix. A built-in the provider stubs is a warning. On an edge unit, a bundled `InMemory*` class also fails the build. The unit's tier is its `runtime`, else the project's own `pikku.runtime`, else the provider default (`serverless` on Cloudflare). Packages that declare nothing are judged by their imports only.
|
|
18
|
+
|
|
19
|
+
`ProviderAdapter.getRuntimeProfile(tier?)` returns the compat date, compat flags, the built-ins the runtime provides (keyed by compat date), the stubbed ones and the externals. The Cloudflare adapter derives `wrangler.toml`, the upload metadata and the bundle externals from it; `node:os` and `node:fs` are not provided before compat date 2025-09-15. The default is `nodejs_compat_v2` with compat date 2024-12-18, which is what `wrangler.toml` and Fabric's live workers already use, so Fabric deploys see no runtime change. Only the direct-API upload in `@pikku/deploy-cloudflare` (`createWorker`, used by its own `deploy()`) moves: it sent `nodejs_compat` with 2024-01-01 before. A newer date or flag is opt-in through the adapter option `new CloudflareProviderAdapter({ compatDate })` or `getCloudflareRuntimeProfile(tier, compatDate)`. From 2025-08-15 `node:http` and `node:https` exist, and from 2025-09-15 `node:os`, `node:fs` (stubbed by the build regardless) and `node:perf_hooks`; the verifier's allowed built-ins follow the effective date. A newer date changes the runtime of every worker deployed with it.
|
|
20
|
+
|
|
21
|
+
`declareScopes(['pikku:console'])` (from `@pikku/core/scope`) declares scopes by id without wiring anything. `wireAddon({ scopes })` only requires a scope of an addon's functions; the tree arrives with the addon's metadata, so a role granting `pikku:console` used to fail PKU124 unless the addon was wired, and a wired `@pikku/addon-console` lands in every unit carrying the `/rpc` catch-all. An app that grants the scope without the console now calls `declareScopes` and no longer needs the scaffold or the addon. When the addon is wired its tree and descriptions win and the bare id adds nothing.
|
|
22
|
+
|
|
23
|
+
More packages declare a tier after bundling each with the edge profile. `edge`: `@pikku/addon-graph`, `@pikku/pino`, `@pikku/jose`, `@pikku/ai-vercel`, `@pikku/ai-voice`. `serverless`: `@pikku/kysely-postgres` (postgres.js needs `node:buffer`, `stream`, `events`), `@pikku/backblaze` (`copyFile` reads a local file, which the build stubs), `@pikku/gateway-slack` (`@slack/web-api` imports `node:os` and `zlib`). `server`: `@pikku/schedule` (`cron` imports `child_process`), `@pikku/aws-services` (the AWS SDK's Node handler needs `node:http2`), `@pikku/browser` (puppeteer), and `@pikku/modelcontextprotocol` except its `./fetch` subpath, which is `edge`.
|
|
24
|
+
|
|
25
|
+
`@pikku/addon-graph` no longer needs `node:crypto` or `Buffer`: the Crypto function hashes and HMACs on Web Crypto (MD5 is built in, since Web Crypto has none) and encodes with `TextEncoder`/`atob`/`btoa`, with output unchanged.
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [6f11bb5]
|
|
28
|
+
- Updated dependencies [0c67e33]
|
|
29
|
+
- Updated dependencies [15c4968]
|
|
30
|
+
- Updated dependencies [d75a23d]
|
|
31
|
+
- Updated dependencies [9b12c8a]
|
|
32
|
+
- @pikku/core@0.12.138
|
|
33
|
+
|
|
34
|
+
## 0.13.34
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 80c94f9: MySQL is a third dialect for the `pikku db` commands, beside sqlite and postgres.
|
|
39
|
+
|
|
40
|
+
Set `mysqlUrl` in `createConfig` and `db migrate`, `generate`, `check`, `baseline`, `reset`, `codegen` and the dev seed behave as they do elsewhere, with migrations in `db/mysql/` and the seed in `db/mysql-dev-seed.sql`. MySQL has no embedded engine, so a command that needs a throwaway database creates and drops a `pikku_scratch_<hex>` one on your server — the account needs `CREATE` and `DROP`. DDL is not transactional there, so a migration that fails halfway is replayed from the top. `db.schema` is refused, because a MySQL schema is a database.
|
|
41
|
+
|
|
42
|
+
`@pikku/migrator-sql` gains `@pikku/migrator-sql/mysql`. The runtime schemas in `@pikku/kysely` now compile for MySQL without changing what sqlite and postgres get: keys are `varchar(255)`, free text is `longtext`, literal text defaults are expressions, and foreign keys are table-level constraints, because MySQL parses an inline `REFERENCES` and silently drops it. A foreign key onto a column another source owns takes that column's full type (`varchar(36)`), not the bare `varchar` the introspector reports.
|
|
43
|
+
|
|
44
|
+
An addon that ships `db/mysql` migrations needs `db.mysqlUrl` in its `pikku.config.json` for `pikku all` to publish them. The standalone bundle does not support MySQL yet and refuses a MySQL project by name.
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [149faae]
|
|
47
|
+
- @pikku/core@0.12.136
|
|
48
|
+
|
|
1
49
|
## 0.13.33
|
|
2
50
|
|
|
3
51
|
### Patch Changes
|
|
@@ -12,8 +12,22 @@ import { DEFAULT_KEY_ID } from '@pikku/core/classification';
|
|
|
12
12
|
*/
|
|
13
13
|
export { DEFAULT_KEY_ID };
|
|
14
14
|
const ENVELOPE_PREFIX = 'pikku1';
|
|
15
|
-
|
|
16
|
-
const
|
|
15
|
+
/** base64url of the UTF-8 bytes, unpadded: `Buffer`-free, so it runs on edge runtimes. */
|
|
16
|
+
const encodePart = (value) => {
|
|
17
|
+
let binary = '';
|
|
18
|
+
for (const byte of new TextEncoder().encode(value)) {
|
|
19
|
+
binary += String.fromCharCode(byte);
|
|
20
|
+
}
|
|
21
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
22
|
+
};
|
|
23
|
+
const decodePart = (value) => {
|
|
24
|
+
const base64 = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
25
|
+
const binary = atob(base64 + '='.repeat((4 - (base64.length % 4)) % 4));
|
|
26
|
+
const bytes = new Uint8Array(binary.length);
|
|
27
|
+
for (let i = 0; i < binary.length; i++)
|
|
28
|
+
bytes[i] = binary.charCodeAt(i);
|
|
29
|
+
return new TextDecoder().decode(bytes);
|
|
30
|
+
};
|
|
17
31
|
const serializeEnvelope = (envelope) => [
|
|
18
32
|
ENVELOPE_PREFIX,
|
|
19
33
|
encodePart(envelope.keyId),
|
|
@@ -54,7 +54,10 @@ export class KyselyDeploymentService {
|
|
|
54
54
|
.execute();
|
|
55
55
|
}
|
|
56
56
|
});
|
|
57
|
-
this.heartbeatTimer = setInterval(() =>
|
|
57
|
+
this.heartbeatTimer = setInterval(() => {
|
|
58
|
+
// sendHeartbeat catches its own errors; it retries on the next tick
|
|
59
|
+
void this.sendHeartbeat();
|
|
60
|
+
}, this.heartbeatInterval);
|
|
58
61
|
}
|
|
59
62
|
async stop() {
|
|
60
63
|
if (this.heartbeatTimer) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
1
|
import { parseJson } from './kysely-json.js';
|
|
3
2
|
import { requirePikkuSchema } from './schema/index.js';
|
|
4
3
|
import { virtualUserSchema } from './schema/virtual-user.schema.js';
|
|
@@ -49,7 +48,7 @@ export class KyselyVirtualUserRunStore {
|
|
|
49
48
|
}
|
|
50
49
|
async start(run) {
|
|
51
50
|
await this.init();
|
|
52
|
-
const runId = randomUUID();
|
|
51
|
+
const runId = globalThis.crypto.randomUUID();
|
|
53
52
|
await this.db
|
|
54
53
|
.insertInto('virtualUserRun')
|
|
55
54
|
.values({
|
|
@@ -23,6 +23,11 @@ export declare class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
23
23
|
protected listStepStates(runId: string): Promise<Array<StepState & {
|
|
24
24
|
stepName: string;
|
|
25
25
|
}>>;
|
|
26
|
+
getRunSteps(runId: string): Promise<Array<StepState & {
|
|
27
|
+
stepName: string;
|
|
28
|
+
rpcName?: string;
|
|
29
|
+
data?: any;
|
|
30
|
+
}>>;
|
|
26
31
|
getRunHistory(runId: string): Promise<Array<StepState & {
|
|
27
32
|
stepName: string;
|
|
28
33
|
}>>;
|
|
@@ -147,6 +147,9 @@ export class KyselyWorkflowService extends PikkuWorkflowService {
|
|
|
147
147
|
.execute();
|
|
148
148
|
return rows.map((row) => ({ ...toStepState(row), stepName: row.stepName }));
|
|
149
149
|
}
|
|
150
|
+
async getRunSteps(runId) {
|
|
151
|
+
return this.runService.getRunSteps(runId);
|
|
152
|
+
}
|
|
150
153
|
async getRunHistory(runId) {
|
|
151
154
|
return this.runService.getRunHistory(runId);
|
|
152
155
|
}
|
|
@@ -13,89 +13,96 @@ export const agentSchema = {
|
|
|
13
13
|
name: 'agent',
|
|
14
14
|
ownedBy: ['agentStorage', 'agentRunState', 'agentRunService'],
|
|
15
15
|
statements: [
|
|
16
|
-
(db) => db.schema
|
|
16
|
+
(db, _types, ctx) => db.schema
|
|
17
17
|
.createTable('agentThreads')
|
|
18
18
|
.addColumn('id', 'varchar(36)', (col) => col.primaryKey())
|
|
19
19
|
.addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
|
|
20
|
-
.addColumn('title',
|
|
21
|
-
.addColumn('metadata',
|
|
20
|
+
.addColumn('title', ctx.text)
|
|
21
|
+
.addColumn('metadata', ctx.text)
|
|
22
22
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
23
23
|
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
24
|
-
(db) => db.schema
|
|
24
|
+
(db, _types, ctx) => db.schema
|
|
25
25
|
.createIndex('idx_agent_threads_resource')
|
|
26
26
|
.on('agentThreads')
|
|
27
27
|
.column('resourceId'),
|
|
28
|
-
(db) => db.schema
|
|
28
|
+
(db, _types, ctx) => db.schema
|
|
29
29
|
.createTable('agentMessage')
|
|
30
30
|
.addColumn('id', 'varchar(36)', (col) => col.primaryKey())
|
|
31
|
-
.addColumn('threadId', 'varchar(36)', (col) => col.notNull()
|
|
31
|
+
.addColumn('threadId', 'varchar(36)', (col) => ctx.references(col.notNull(), 'agentThreads.id'))
|
|
32
32
|
.addColumn('role', 'varchar(50)', (col) => col.notNull())
|
|
33
|
-
.addColumn('content',
|
|
34
|
-
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
35
|
-
|
|
33
|
+
.addColumn('content', ctx.text)
|
|
34
|
+
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
35
|
+
.$call(ctx.foreignKeys('agentMessage', { threadId: 'agentThreads.id' })),
|
|
36
|
+
(db, _types, ctx) => db.schema
|
|
36
37
|
.createIndex('idx_agent_message_thread')
|
|
37
38
|
.on('agentMessage')
|
|
38
39
|
.columns(['threadId', 'createdAt']),
|
|
39
|
-
(db) => db.schema
|
|
40
|
+
(db, _types, ctx) => db.schema
|
|
40
41
|
.createTable('agentToolCall')
|
|
41
42
|
.addColumn('id', 'varchar(36)', (col) => col.primaryKey())
|
|
42
|
-
.addColumn('threadId', 'varchar(36)', (col) => col.notNull()
|
|
43
|
-
.addColumn('messageId', 'varchar(36)', (col) => col.notNull()
|
|
43
|
+
.addColumn('threadId', 'varchar(36)', (col) => ctx.references(col.notNull(), 'agentThreads.id'))
|
|
44
|
+
.addColumn('messageId', 'varchar(36)', (col) => ctx.references(col.notNull(), 'agentMessage.id'))
|
|
44
45
|
.addColumn('runId', 'varchar(36)')
|
|
45
46
|
.addColumn('toolName', 'varchar(255)', (col) => col.notNull())
|
|
46
|
-
.addColumn('args',
|
|
47
|
-
.addColumn('result',
|
|
47
|
+
.addColumn('args', ctx.text, (col) => col.notNull())
|
|
48
|
+
.addColumn('result', ctx.text)
|
|
48
49
|
.addColumn('approvalStatus', 'varchar(50)')
|
|
49
50
|
.addColumn('approvalType', 'varchar(50)')
|
|
50
51
|
.addColumn('agentRunId', 'varchar(36)')
|
|
51
52
|
.addColumn('displayToolName', 'varchar(255)')
|
|
52
|
-
.addColumn('displayArgs',
|
|
53
|
-
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
54
|
-
|
|
53
|
+
.addColumn('displayArgs', ctx.text)
|
|
54
|
+
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
55
|
+
.$call(ctx.foreignKeys('agentToolCall', {
|
|
56
|
+
threadId: 'agentThreads.id',
|
|
57
|
+
messageId: 'agentMessage.id',
|
|
58
|
+
})),
|
|
59
|
+
(db, _types, ctx) => db.schema
|
|
55
60
|
.createIndex('idx_agent_tool_call_thread')
|
|
56
61
|
.on('agentToolCall')
|
|
57
62
|
.column('threadId'),
|
|
58
|
-
(db) => db.schema
|
|
63
|
+
(db, _types, ctx) => db.schema
|
|
59
64
|
.createIndex('idx_agent_tool_call_message')
|
|
60
65
|
.on('agentToolCall')
|
|
61
66
|
.column('messageId'),
|
|
62
|
-
(db) => db.schema
|
|
67
|
+
(db, _types, ctx) => db.schema
|
|
63
68
|
.createTable('agentWorkingMemory')
|
|
64
69
|
.addColumn('id', 'varchar(255)', (col) => col.notNull())
|
|
65
70
|
.addColumn('scope', 'varchar(50)', (col) => col.notNull())
|
|
66
|
-
.addColumn('data',
|
|
71
|
+
.addColumn('data', ctx.text, (col) => col.notNull())
|
|
67
72
|
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
68
73
|
.addPrimaryKeyConstraint('agent_working_memory_pk', ['id', 'scope']),
|
|
69
|
-
(db) => db.schema
|
|
74
|
+
(db, _types, ctx) => db.schema
|
|
70
75
|
.createTable('agentRun')
|
|
71
76
|
.addColumn('runId', 'varchar(36)', (col) => col.primaryKey())
|
|
72
77
|
.addColumn('agentName', 'varchar(255)', (col) => col.notNull())
|
|
73
|
-
.addColumn('threadId', 'varchar(36)', (col) => col.notNull()
|
|
78
|
+
.addColumn('threadId', 'varchar(36)', (col) => ctx.references(col.notNull(), 'agentThreads.id'))
|
|
74
79
|
.addColumn('resourceId', 'varchar(255)', (col) => col.notNull())
|
|
75
|
-
.addColumn('status', 'varchar(50)', (col) => col.notNull().defaultTo('running'))
|
|
76
|
-
.addColumn('errorMessage',
|
|
77
|
-
.addColumn('suspendReason',
|
|
78
|
-
.addColumn('missingRpcs',
|
|
79
|
-
.addColumn('pendingApprovals',
|
|
80
|
+
.addColumn('status', 'varchar(50)', (col) => col.notNull().defaultTo(ctx.defaultText('running')))
|
|
81
|
+
.addColumn('errorMessage', ctx.text)
|
|
82
|
+
.addColumn('suspendReason', ctx.text)
|
|
83
|
+
.addColumn('missingRpcs', ctx.text)
|
|
84
|
+
.addColumn('pendingApprovals', ctx.text)
|
|
80
85
|
.addColumn('usageInputTokens', 'integer', (col) => col.notNull().defaultTo(0))
|
|
81
86
|
.addColumn('usageOutputTokens', 'integer', (col) => col.notNull().defaultTo(0))
|
|
82
|
-
.addColumn('usageModel', 'varchar(255)', (col) => col.notNull().defaultTo(''))
|
|
87
|
+
.addColumn('usageModel', 'varchar(255)', (col) => col.notNull().defaultTo(ctx.defaultText('')))
|
|
83
88
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
84
|
-
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
85
|
-
|
|
89
|
+
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
90
|
+
.$call(ctx.foreignKeys('agentRun', { threadId: 'agentThreads.id' })),
|
|
91
|
+
(db, _types, ctx) => db.schema
|
|
86
92
|
.createIndex('idx_agent_run_thread')
|
|
87
93
|
.on('agentRun')
|
|
88
94
|
.columns(['threadId', 'createdAt']),
|
|
89
|
-
(db) => db.schema
|
|
95
|
+
(db, _types, ctx) => db.schema
|
|
90
96
|
.createTable('agentRunScore')
|
|
91
97
|
.addColumn('id', 'varchar(36)', (col) => col.primaryKey())
|
|
92
|
-
.addColumn('runId', 'varchar(36)', (col) => col.notNull()
|
|
98
|
+
.addColumn('runId', 'varchar(36)', (col) => ctx.references(col.notNull(), 'agentRun.runId'))
|
|
93
99
|
.addColumn('scorerName', 'varchar(255)', (col) => col.notNull())
|
|
94
100
|
.addColumn('score', 'real', (col) => col.notNull())
|
|
95
|
-
.addColumn('reason',
|
|
96
|
-
.addColumn('metadata',
|
|
97
|
-
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
98
|
-
|
|
101
|
+
.addColumn('reason', ctx.text)
|
|
102
|
+
.addColumn('metadata', ctx.text)
|
|
103
|
+
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
104
|
+
.$call(ctx.foreignKeys('agentRunScore', { runId: 'agentRun.runId' })),
|
|
105
|
+
(db, _types, ctx) => db.schema
|
|
99
106
|
.createIndex('idx_agent_run_score_run')
|
|
100
107
|
.on('agentRunScore')
|
|
101
108
|
.columns(['runId', 'createdAt']),
|
|
@@ -17,30 +17,30 @@ export const analyticsSchema = {
|
|
|
17
17
|
name: 'analytics',
|
|
18
18
|
ownedBy: ['analyticsService'],
|
|
19
19
|
statements: [
|
|
20
|
-
(db) => db.schema
|
|
20
|
+
(db, _types, ctx) => db.schema
|
|
21
21
|
.createTable('pikkuAnalyticsEvents')
|
|
22
|
-
.addColumn('eventId',
|
|
23
|
-
.addColumn('name',
|
|
24
|
-
.addColumn('occurredAt',
|
|
25
|
-
.addColumn('source',
|
|
26
|
-
.addColumn('functionId',
|
|
27
|
-
.addColumn('wireType',
|
|
28
|
-
.addColumn('traceId',
|
|
29
|
-
.addColumn('userId',
|
|
30
|
-
.addColumn('orgId',
|
|
31
|
-
.addColumn('pikkuUserId',
|
|
22
|
+
.addColumn('eventId', ctx.key, (col) => col.primaryKey())
|
|
23
|
+
.addColumn('name', ctx.key, (col) => col.notNull())
|
|
24
|
+
.addColumn('occurredAt', ctx.key, (col) => col.notNull())
|
|
25
|
+
.addColumn('source', ctx.text, (col) => col.notNull())
|
|
26
|
+
.addColumn('functionId', ctx.text)
|
|
27
|
+
.addColumn('wireType', ctx.text)
|
|
28
|
+
.addColumn('traceId', ctx.text)
|
|
29
|
+
.addColumn('userId', ctx.text)
|
|
30
|
+
.addColumn('orgId', ctx.text)
|
|
31
|
+
.addColumn('pikkuUserId', ctx.text)
|
|
32
32
|
// The device id for a visitor with no session. Its own column beside
|
|
33
33
|
// `userId` and not folded into it: the whole point of the anonymous id
|
|
34
34
|
// is the traffic that has no user to be attributed to yet.
|
|
35
|
-
.addColumn('anonymousId',
|
|
36
|
-
.addColumn('vendorIds',
|
|
37
|
-
.addColumn('consent',
|
|
38
|
-
.addColumn('props',
|
|
39
|
-
(db) => db.schema
|
|
35
|
+
.addColumn('anonymousId', ctx.text)
|
|
36
|
+
.addColumn('vendorIds', ctx.text)
|
|
37
|
+
.addColumn('consent', ctx.text)
|
|
38
|
+
.addColumn('props', ctx.text),
|
|
39
|
+
(db, _types, ctx) => db.schema
|
|
40
40
|
.createIndex('idx_pikku_analytics_events_occurred_at')
|
|
41
41
|
.on('pikkuAnalyticsEvents')
|
|
42
42
|
.column('occurredAt'),
|
|
43
|
-
(db) => db.schema
|
|
43
|
+
(db, _types, ctx) => db.schema
|
|
44
44
|
.createIndex('idx_pikku_analytics_events_name')
|
|
45
45
|
.on('pikkuAnalyticsEvents')
|
|
46
46
|
.column('name'),
|
|
@@ -17,33 +17,33 @@ export const auditSchema = {
|
|
|
17
17
|
name: 'audit',
|
|
18
18
|
ownedBy: ['audit', 'auditLog'],
|
|
19
19
|
statements: [
|
|
20
|
-
(db) => db.schema
|
|
20
|
+
(db, _types, ctx) => db.schema
|
|
21
21
|
.createTable('audit')
|
|
22
|
-
.addColumn('auditId',
|
|
23
|
-
.addColumn('occurredAt',
|
|
24
|
-
.addColumn('type',
|
|
25
|
-
.addColumn('source',
|
|
26
|
-
.addColumn('outcome',
|
|
27
|
-
.addColumn('functionId',
|
|
28
|
-
.addColumn('wireType',
|
|
29
|
-
.addColumn('traceId',
|
|
30
|
-
.addColumn('transactionId',
|
|
31
|
-
.addColumn('queryId',
|
|
32
|
-
.addColumn('userId',
|
|
33
|
-
.addColumn('orgId',
|
|
34
|
-
.addColumn('pikkuUserId',
|
|
35
|
-
.addColumn('tables',
|
|
36
|
-
.addColumn('changedCols',
|
|
37
|
-
.addColumn('event',
|
|
38
|
-
.addColumn('old',
|
|
39
|
-
.addColumn('data',
|
|
22
|
+
.addColumn('auditId', ctx.key, (col) => col.primaryKey())
|
|
23
|
+
.addColumn('occurredAt', ctx.key, (col) => col.notNull())
|
|
24
|
+
.addColumn('type', ctx.key, (col) => col.notNull())
|
|
25
|
+
.addColumn('source', ctx.text, (col) => col.defaultTo(ctx.defaultText('auto')).notNull())
|
|
26
|
+
.addColumn('outcome', ctx.text)
|
|
27
|
+
.addColumn('functionId', ctx.text)
|
|
28
|
+
.addColumn('wireType', ctx.text)
|
|
29
|
+
.addColumn('traceId', ctx.text)
|
|
30
|
+
.addColumn('transactionId', ctx.text)
|
|
31
|
+
.addColumn('queryId', ctx.text)
|
|
32
|
+
.addColumn('userId', ctx.key)
|
|
33
|
+
.addColumn('orgId', ctx.text)
|
|
34
|
+
.addColumn('pikkuUserId', ctx.text)
|
|
35
|
+
.addColumn('tables', ctx.text)
|
|
36
|
+
.addColumn('changedCols', ctx.text)
|
|
37
|
+
.addColumn('event', ctx.text)
|
|
38
|
+
.addColumn('old', ctx.text)
|
|
39
|
+
.addColumn('data', ctx.text),
|
|
40
40
|
// The trail is only ever read newest-first, and the two filters the console
|
|
41
41
|
// offers are user and type.
|
|
42
|
-
(db) => db.schema
|
|
42
|
+
(db, _types, ctx) => db.schema
|
|
43
43
|
.createIndex('idx_audit_occurred_at')
|
|
44
44
|
.on('audit')
|
|
45
45
|
.column('occurredAt'),
|
|
46
|
-
(db) => db.schema.createIndex('idx_audit_user_id').on('audit').column('userId'),
|
|
47
|
-
(db) => db.schema.createIndex('idx_audit_type').on('audit').column('type'),
|
|
46
|
+
(db, _types, ctx) => db.schema.createIndex('idx_audit_user_id').on('audit').column('userId'),
|
|
47
|
+
(db, _types, ctx) => db.schema.createIndex('idx_audit_type').on('audit').column('type'),
|
|
48
48
|
],
|
|
49
49
|
};
|
|
@@ -4,22 +4,25 @@ export const channelSchema = {
|
|
|
4
4
|
name: 'channel',
|
|
5
5
|
ownedBy: ['channelStore', 'eventHub'],
|
|
6
6
|
statements: [
|
|
7
|
-
(db) => db.schema
|
|
7
|
+
(db, _types, ctx) => db.schema
|
|
8
8
|
.createTable('channels')
|
|
9
|
-
.addColumn('channelId',
|
|
10
|
-
.addColumn('channelName',
|
|
9
|
+
.addColumn('channelId', ctx.key, (col) => col.primaryKey())
|
|
10
|
+
.addColumn('channelName', ctx.text, (col) => col.notNull())
|
|
11
11
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
12
|
-
.addColumn('openingData',
|
|
13
|
-
.addColumn('pikkuUserId',
|
|
14
|
-
.addColumn('state',
|
|
12
|
+
.addColumn('openingData', ctx.text, (col) => col.notNull().defaultTo(ctx.defaultText('{}')))
|
|
13
|
+
.addColumn('pikkuUserId', ctx.text)
|
|
14
|
+
.addColumn('state', ctx.text)
|
|
15
15
|
.addColumn('lastWire', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
16
|
-
(db) => db.schema
|
|
16
|
+
(db, _types, ctx) => db.schema
|
|
17
17
|
.createTable('channelSubscriptions')
|
|
18
|
-
.addColumn('channelId',
|
|
19
|
-
.addColumn('topic',
|
|
18
|
+
.addColumn('channelId', ctx.key, (col) => ctx.references(col.notNull(), 'channels.channelId'))
|
|
19
|
+
.addColumn('topic', ctx.key, (col) => col.notNull())
|
|
20
20
|
.addPrimaryKeyConstraint('channel_subscriptions_pk', [
|
|
21
21
|
'channelId',
|
|
22
22
|
'topic',
|
|
23
|
-
])
|
|
23
|
+
])
|
|
24
|
+
.$call(ctx.foreignKeys('channelSubscriptions', {
|
|
25
|
+
channelId: 'channels.channelId',
|
|
26
|
+
})),
|
|
24
27
|
],
|
|
25
28
|
};
|
|
@@ -14,22 +14,22 @@ export const credentialSchema = {
|
|
|
14
14
|
name: 'credential',
|
|
15
15
|
ownedBy: ['credentialService'],
|
|
16
16
|
statements: [
|
|
17
|
-
(db) => db.schema
|
|
17
|
+
(db, _types, ctx) => db.schema
|
|
18
18
|
.createTable('credentials')
|
|
19
19
|
.addColumn('name', 'varchar(255)', (col) => col.notNull())
|
|
20
20
|
.addColumn('userId', 'varchar(255)')
|
|
21
|
-
.addColumn('ciphertext',
|
|
22
|
-
.addColumn('wrappedDek',
|
|
21
|
+
.addColumn('ciphertext', ctx.text, (col) => col.notNull())
|
|
22
|
+
.addColumn('wrappedDek', ctx.text, (col) => col.notNull())
|
|
23
23
|
.addColumn('keyVersion', 'integer', (col) => col.notNull())
|
|
24
24
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
25
25
|
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
26
|
-
rawStatement(({ table }) => sql `CREATE UNIQUE INDEX credentials_name_user_id_unique ON ${table('credentials')} (name, COALESCE(user_id, ''))`),
|
|
27
|
-
(db) => db.schema
|
|
26
|
+
rawStatement(({ table, mysql }) => sql `CREATE UNIQUE INDEX credentials_name_user_id_unique ON ${table('credentials')} (name, ${mysql ? sql `(COALESCE(user_id, ''))` : sql `COALESCE(user_id, '')`})`),
|
|
27
|
+
(db, _types, ctx) => db.schema
|
|
28
28
|
.createTable('credentialKekSalts')
|
|
29
29
|
.addColumn('keyVersion', 'integer', (col) => col.primaryKey())
|
|
30
30
|
.addColumn('salt', 'varchar(64)', (col) => col.notNull())
|
|
31
31
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
32
|
-
(db) => db.schema
|
|
32
|
+
(db, _types, ctx) => db.schema
|
|
33
33
|
.createTable('credentialsAudit')
|
|
34
34
|
.addColumn('id', 'varchar(36)', (col) => col.primaryKey())
|
|
35
35
|
.addColumn('credentialName', 'varchar(255)', (col) => col.notNull())
|
|
@@ -3,28 +3,28 @@ import { sql } from 'kysely';
|
|
|
3
3
|
export const deploymentSchema = {
|
|
4
4
|
name: 'deployment',
|
|
5
5
|
statements: [
|
|
6
|
-
(db) => db.schema
|
|
6
|
+
(db, _types, ctx) => db.schema
|
|
7
7
|
.createTable('pikkuDeployments')
|
|
8
|
-
.addColumn('deploymentId',
|
|
9
|
-
.addColumn('endpoint',
|
|
8
|
+
.addColumn('deploymentId', ctx.key, (col) => col.primaryKey())
|
|
9
|
+
.addColumn('endpoint', ctx.text, (col) => col.notNull())
|
|
10
10
|
.addColumn('lastHeartbeat', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
11
11
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
12
|
-
(db) => db.schema
|
|
12
|
+
(db, _types, ctx) => db.schema
|
|
13
13
|
.createTable('pikkuDeploymentFunctions')
|
|
14
|
-
.addColumn('deploymentId',
|
|
15
|
-
.notNull()
|
|
16
|
-
.references('pikkuDeployments.deploymentId')
|
|
17
|
-
.onDelete('cascade'))
|
|
18
|
-
.addColumn('functionName', 'text', (col) => col.notNull())
|
|
14
|
+
.addColumn('deploymentId', ctx.key, (col) => ctx.references(col.notNull(), 'pikkuDeployments.deploymentId'))
|
|
15
|
+
.addColumn('functionName', ctx.key, (col) => col.notNull())
|
|
19
16
|
.addPrimaryKeyConstraint('pikku_deployment_functions_pk', [
|
|
20
17
|
'deploymentId',
|
|
21
18
|
'functionName',
|
|
22
|
-
])
|
|
23
|
-
|
|
19
|
+
])
|
|
20
|
+
.$call(ctx.foreignKeys('pikkuDeploymentFunctions', {
|
|
21
|
+
deploymentId: 'pikkuDeployments.deploymentId',
|
|
22
|
+
})),
|
|
23
|
+
(db, _types, ctx) => db.schema
|
|
24
24
|
.createIndex('idx_pikku_deployments_heartbeat')
|
|
25
25
|
.on('pikkuDeployments')
|
|
26
26
|
.column('lastHeartbeat'),
|
|
27
|
-
(db) => db.schema
|
|
27
|
+
(db, _types, ctx) => db.schema
|
|
28
28
|
.createIndex('idx_pikku_deployment_functions_name')
|
|
29
29
|
.on('pikkuDeploymentFunctions')
|
|
30
30
|
.column('functionName'),
|
|
@@ -17,14 +17,14 @@ export const flagSchema = {
|
|
|
17
17
|
name: 'flag',
|
|
18
18
|
ownedBy: ['featureFlags'],
|
|
19
19
|
statements: [
|
|
20
|
-
(db) => db.schema
|
|
20
|
+
(db, _types, ctx) => db.schema
|
|
21
21
|
.createTable('pikkuFeatureFlags')
|
|
22
|
-
.addColumn('name',
|
|
23
|
-
.addColumn('description',
|
|
22
|
+
.addColumn('name', ctx.key, (col) => col.primaryKey())
|
|
23
|
+
.addColumn('description', ctx.text)
|
|
24
24
|
// The declared `anyOf` scope list, as JSON. Read by the console to say
|
|
25
25
|
// who would see the feature; never read on the request path, where the
|
|
26
26
|
// capability half comes from the session's own scopes.
|
|
27
|
-
.addColumn('anyOf',
|
|
27
|
+
.addColumn('anyOf', ctx.text)
|
|
28
28
|
// Off until somebody turns it on. A flag exists so a feature can ship
|
|
29
29
|
// dark, so the row a deploy creates has to start closed — the opposite
|
|
30
30
|
// default would make merging the declaration the moment of launch.
|
|
@@ -37,26 +37,29 @@ export const flagSchema = {
|
|
|
37
37
|
// longer offered, awaiting `pikku flags prune`. The same additive
|
|
38
38
|
// contract as `pikkuScopes.declared`.
|
|
39
39
|
.addColumn('declared', 'boolean', (col) => col.defaultTo(true).notNull())
|
|
40
|
-
.addColumn('updatedBy',
|
|
40
|
+
.addColumn('updatedBy', ctx.text)
|
|
41
41
|
// Why it was flipped. A kill switch is pulled during an incident, and
|
|
42
42
|
// the one question afterwards is always who turned it off and why.
|
|
43
|
-
.addColumn('note',
|
|
43
|
+
.addColumn('note', ctx.text)
|
|
44
44
|
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
45
|
-
(db) => db.schema
|
|
45
|
+
(db, _types, ctx) => db.schema
|
|
46
46
|
.createTable('pikkuFeatureFlagOverrides')
|
|
47
|
-
.addColumn('flag',
|
|
48
|
-
.addColumn('subjectId',
|
|
47
|
+
.addColumn('flag', ctx.key, (col) => ctx.references(col.notNull(), 'pikkuFeatureFlags.name'))
|
|
48
|
+
.addColumn('subjectId', ctx.key, (col) => col.notNull())
|
|
49
49
|
// Which id this is, for the console to render. Resolution keys on the
|
|
50
50
|
// id alone, because that is all the resolver has: it prefers the
|
|
51
51
|
// organization and falls back to the user, and by then the two are one
|
|
52
52
|
// string.
|
|
53
|
-
.addColumn('subjectKind',
|
|
53
|
+
.addColumn('subjectKind', ctx.text, (col) => col.notNull())
|
|
54
54
|
.addColumn('enabled', 'boolean', (col) => col.notNull())
|
|
55
|
-
.addColumn('grantedBy',
|
|
55
|
+
.addColumn('grantedBy', ctx.text)
|
|
56
56
|
.addColumn('grantedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
57
57
|
.addPrimaryKeyConstraint('pikku_feature_flag_overrides_pk', [
|
|
58
58
|
'flag',
|
|
59
59
|
'subjectId',
|
|
60
|
-
])
|
|
60
|
+
])
|
|
61
|
+
.$call(ctx.foreignKeys('pikkuFeatureFlagOverrides', {
|
|
62
|
+
flag: 'pikkuFeatureFlags.name',
|
|
63
|
+
})),
|
|
61
64
|
],
|
|
62
65
|
};
|
|
@@ -4,15 +4,15 @@ export const incomingWebhookSchema = {
|
|
|
4
4
|
name: 'incoming-webhook',
|
|
5
5
|
ownedBy: ['incomingWebhookService'],
|
|
6
6
|
statements: [
|
|
7
|
-
(db) => db.schema
|
|
7
|
+
(db, _types, ctx) => db.schema
|
|
8
8
|
.createTable('webhookReceipt')
|
|
9
|
-
.addColumn('receiptId',
|
|
10
|
-
.addColumn('source',
|
|
11
|
-
.addColumn('event',
|
|
12
|
-
.addColumn('providerEventId',
|
|
13
|
-
.addColumn('status',
|
|
9
|
+
.addColumn('receiptId', ctx.key, (col) => col.primaryKey())
|
|
10
|
+
.addColumn('source', ctx.key, (col) => col.notNull())
|
|
11
|
+
.addColumn('event', ctx.key, (col) => col.notNull())
|
|
12
|
+
.addColumn('providerEventId', ctx.key)
|
|
13
|
+
.addColumn('status', ctx.text, (col) => col.defaultTo(ctx.defaultText('pending')).notNull())
|
|
14
14
|
.addColumn('attempts', 'integer', (col) => col.defaultTo(0).notNull())
|
|
15
|
-
.addColumn('lastError',
|
|
15
|
+
.addColumn('lastError', ctx.text)
|
|
16
16
|
.addColumn('createdAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull())
|
|
17
17
|
.addColumn('deliveredAt', 'timestamp'),
|
|
18
18
|
(db) => db.schema
|