@pikku/kysely 0.13.29 → 0.13.30
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 +13 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/kysely-tables.d.ts +12 -0
- package/dist/src/kysely-trigger-source-store.d.ts +14 -0
- package/dist/src/kysely-trigger-source-store.js +92 -0
- package/dist/src/schema/index.d.ts +1 -0
- package/dist/src/schema/index.js +3 -0
- package/dist/src/schema/trigger-source.schema.d.ts +6 -0
- package/dist/src/schema/trigger-source.schema.js +20 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## 0.13.30
|
|
2
|
+
|
|
3
|
+
### Patch Changes
|
|
4
|
+
|
|
5
|
+
- 658f047: A declared webhook source is a registered one. `reconcileTriggerSources` sets up every declared source with its provider (check, then setup where missing or drifted) and `teardownTriggerSources` removes named ones, recording what was registered in a `TriggerSourceStore` (in-memory, or `KyselyTriggerSourceStore` on `pikku_trigger_source`). The admin addon exposes list, reconcile, teardown and forget under the new `admin:triggers` scopes.
|
|
6
|
+
- Updated dependencies [658f047]
|
|
7
|
+
- Updated dependencies [de63ab2]
|
|
8
|
+
- Updated dependencies [658f047]
|
|
9
|
+
- Updated dependencies [658f047]
|
|
10
|
+
- Updated dependencies [658f047]
|
|
11
|
+
- Updated dependencies [658f047]
|
|
12
|
+
- @pikku/core@0.12.128
|
|
13
|
+
|
|
1
14
|
## 0.13.29
|
|
2
15
|
|
|
3
16
|
### Patch Changes
|
package/dist/src/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export { KyselyScopeService } from './kysely-scope-service.js';
|
|
|
14
14
|
export { KyselyFeatureFlagStore } from './kysely-feature-flag-store.js';
|
|
15
15
|
export type { KyselyFeatureFlagStoreOptions } from './kysely-feature-flag-store.js';
|
|
16
16
|
export { KyselyWebhookService } from './kysely-webhook-service.js';
|
|
17
|
+
export { KyselyTriggerSourceStore } from './kysely-trigger-source-store.js';
|
|
17
18
|
export { KyselyIncomingWebhookService } from './kysely-incoming-webhook-service.js';
|
|
18
19
|
export { createAuditedKysely, type CreateAuditedKyselyOptions, } from './create-audited-kysely.js';
|
|
19
20
|
export { KyselyAuditService } from './kysely-audit-service.js';
|
package/dist/src/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export { KyselySessionStore } from './kysely-session-store.js';
|
|
|
13
13
|
export { KyselyScopeService } from './kysely-scope-service.js';
|
|
14
14
|
export { KyselyFeatureFlagStore } from './kysely-feature-flag-store.js';
|
|
15
15
|
export { KyselyWebhookService } from './kysely-webhook-service.js';
|
|
16
|
+
export { KyselyTriggerSourceStore } from './kysely-trigger-source-store.js';
|
|
16
17
|
export { KyselyIncomingWebhookService } from './kysely-incoming-webhook-service.js';
|
|
17
18
|
export { createAuditedKysely, } from './create-audited-kysely.js';
|
|
18
19
|
export { KyselyAuditService } from './kysely-audit-service.js';
|
|
@@ -236,6 +236,17 @@ export interface PikkuFeatureFlagsTable {
|
|
|
236
236
|
note: string | null;
|
|
237
237
|
updatedAt: Generated<Date>;
|
|
238
238
|
}
|
|
239
|
+
/** What a declared trigger source registered with its provider. */
|
|
240
|
+
export interface PikkuTriggerSourceTable {
|
|
241
|
+
name: string;
|
|
242
|
+
kind: string;
|
|
243
|
+
declared: Generated<boolean>;
|
|
244
|
+
status: string | null;
|
|
245
|
+
/** The last setup's provider identifiers as JSON; never a secret. */
|
|
246
|
+
state: string | null;
|
|
247
|
+
detail: string | null;
|
|
248
|
+
updatedAt: Generated<Date>;
|
|
249
|
+
}
|
|
239
250
|
/** One subject's short-circuit, in either direction, over a flag's rollout. */
|
|
240
251
|
export interface PikkuFeatureFlagOverridesTable {
|
|
241
252
|
flag: string;
|
|
@@ -421,6 +432,7 @@ export interface KyselyPikkuDB {
|
|
|
421
432
|
pikkuUserScope: PikkuUserScopeTable;
|
|
422
433
|
pikkuFeatureFlags: PikkuFeatureFlagsTable;
|
|
423
434
|
pikkuFeatureFlagOverrides: PikkuFeatureFlagOverridesTable;
|
|
435
|
+
pikkuTriggerSource: PikkuTriggerSourceTable;
|
|
424
436
|
channels: ChannelsTable;
|
|
425
437
|
channelSubscriptions: ChannelSubscriptionsTable;
|
|
426
438
|
workflowRuns: WorkflowRunsTable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DeclaredTriggerSource, TriggerSourceResult, TriggerSourceRow, TriggerSourceStore } from '@pikku/core/services';
|
|
2
|
+
import type { Kysely } from 'kysely';
|
|
3
|
+
import type { KyselyPikkuDB } from './kysely-tables.js';
|
|
4
|
+
export declare class KyselyTriggerSourceStore implements TriggerSourceStore {
|
|
5
|
+
private db;
|
|
6
|
+
private initialized;
|
|
7
|
+
constructor(db: Kysely<KyselyPikkuDB>);
|
|
8
|
+
init(): Promise<void>;
|
|
9
|
+
syncTriggerSources(sources: DeclaredTriggerSource[]): Promise<void>;
|
|
10
|
+
listTriggerSources(): Promise<TriggerSourceRow[]>;
|
|
11
|
+
getTriggerSource(name: string): Promise<TriggerSourceRow | null>;
|
|
12
|
+
recordTriggerSource(name: string, result: TriggerSourceResult): Promise<void>;
|
|
13
|
+
deleteTriggerSource(name: string): Promise<void>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { requirePikkuSchema } from './schema/index.js';
|
|
2
|
+
import { triggerSourceSchema } from './schema/trigger-source.schema.js';
|
|
3
|
+
const parseState = (value) => {
|
|
4
|
+
if (!value)
|
|
5
|
+
return null;
|
|
6
|
+
if (typeof value !== 'string')
|
|
7
|
+
return value;
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(value);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const toRow = (row) => ({
|
|
16
|
+
name: row.name,
|
|
17
|
+
kind: row.kind,
|
|
18
|
+
declared: !!row.declared,
|
|
19
|
+
status: row.status,
|
|
20
|
+
state: parseState(row.state),
|
|
21
|
+
detail: row.detail,
|
|
22
|
+
updatedAt: row.updatedAt ? new Date(row.updatedAt).toISOString() : null,
|
|
23
|
+
});
|
|
24
|
+
export class KyselyTriggerSourceStore {
|
|
25
|
+
db;
|
|
26
|
+
initialized = false;
|
|
27
|
+
constructor(db) {
|
|
28
|
+
this.db = db;
|
|
29
|
+
}
|
|
30
|
+
async init() {
|
|
31
|
+
if (this.initialized)
|
|
32
|
+
return;
|
|
33
|
+
await requirePikkuSchema(this.db, triggerSourceSchema);
|
|
34
|
+
this.initialized = true;
|
|
35
|
+
}
|
|
36
|
+
async syncTriggerSources(sources) {
|
|
37
|
+
await this.db.transaction().execute(async (trx) => {
|
|
38
|
+
for (const { name, kind } of sources) {
|
|
39
|
+
await trx
|
|
40
|
+
.insertInto('pikkuTriggerSource')
|
|
41
|
+
.values({ name, kind, declared: true })
|
|
42
|
+
.onConflict((oc) => oc.column('name').doUpdateSet({ kind, declared: true }))
|
|
43
|
+
.execute();
|
|
44
|
+
}
|
|
45
|
+
const markStale = trx
|
|
46
|
+
.updateTable('pikkuTriggerSource')
|
|
47
|
+
.set({ declared: false });
|
|
48
|
+
await (sources.length > 0
|
|
49
|
+
? markStale.where('name', 'not in', sources.map((s) => s.name))
|
|
50
|
+
: markStale).execute();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async listTriggerSources() {
|
|
54
|
+
const rows = await this.db
|
|
55
|
+
.selectFrom('pikkuTriggerSource')
|
|
56
|
+
.selectAll()
|
|
57
|
+
.orderBy('name')
|
|
58
|
+
.execute();
|
|
59
|
+
return rows.map(toRow);
|
|
60
|
+
}
|
|
61
|
+
async getTriggerSource(name) {
|
|
62
|
+
const row = await this.db
|
|
63
|
+
.selectFrom('pikkuTriggerSource')
|
|
64
|
+
.selectAll()
|
|
65
|
+
.where('name', '=', name)
|
|
66
|
+
.executeTakeFirst();
|
|
67
|
+
return row ? toRow(row) : null;
|
|
68
|
+
}
|
|
69
|
+
async recordTriggerSource(name, result) {
|
|
70
|
+
const { numUpdatedRows } = await this.db
|
|
71
|
+
.updateTable('pikkuTriggerSource')
|
|
72
|
+
.set({
|
|
73
|
+
status: result.status,
|
|
74
|
+
...(result.state !== undefined
|
|
75
|
+
? { state: result.state ? JSON.stringify(result.state) : null }
|
|
76
|
+
: {}),
|
|
77
|
+
detail: result.detail ?? null,
|
|
78
|
+
updatedAt: new Date(),
|
|
79
|
+
})
|
|
80
|
+
.where('name', '=', name)
|
|
81
|
+
.executeTakeFirst();
|
|
82
|
+
if (!numUpdatedRows) {
|
|
83
|
+
throw new Error(`Unknown trigger source: ${name}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async deleteTriggerSource(name) {
|
|
87
|
+
await this.db
|
|
88
|
+
.deleteFrom('pikkuTriggerSource')
|
|
89
|
+
.where('name', '=', name)
|
|
90
|
+
.execute();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -24,6 +24,7 @@ export { channelSchema } from './channel.schema.js';
|
|
|
24
24
|
export { credentialSchema } from './credential.schema.js';
|
|
25
25
|
export { deploymentSchema } from './deployment.schema.js';
|
|
26
26
|
export { flagSchema } from './flag.schema.js';
|
|
27
|
+
export { triggerSourceSchema } from './trigger-source.schema.js';
|
|
27
28
|
export { incomingWebhookSchema } from './incoming-webhook.schema.js';
|
|
28
29
|
export { scopeSchema } from './scope.schema.js';
|
|
29
30
|
export { secretSchema } from './secret.schema.js';
|
package/dist/src/schema/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { credentialSchema } from './credential.schema.js';
|
|
|
8
8
|
import { deploymentSchema } from './deployment.schema.js';
|
|
9
9
|
import { scopeSchema } from './scope.schema.js';
|
|
10
10
|
import { flagSchema } from './flag.schema.js';
|
|
11
|
+
import { triggerSourceSchema } from './trigger-source.schema.js';
|
|
11
12
|
import { incomingWebhookSchema } from './incoming-webhook.schema.js';
|
|
12
13
|
import { secretSchema } from './secret.schema.js';
|
|
13
14
|
import { sessionSchema } from './session.schema.js';
|
|
@@ -42,6 +43,7 @@ export const pikkuSchemas = [
|
|
|
42
43
|
agentSchema,
|
|
43
44
|
scopeSchema,
|
|
44
45
|
flagSchema,
|
|
46
|
+
triggerSourceSchema,
|
|
45
47
|
auditSchema,
|
|
46
48
|
analyticsSchema,
|
|
47
49
|
virtualUserSchema,
|
|
@@ -54,6 +56,7 @@ export { channelSchema } from './channel.schema.js';
|
|
|
54
56
|
export { credentialSchema } from './credential.schema.js';
|
|
55
57
|
export { deploymentSchema } from './deployment.schema.js';
|
|
56
58
|
export { flagSchema } from './flag.schema.js';
|
|
59
|
+
export { triggerSourceSchema } from './trigger-source.schema.js';
|
|
57
60
|
export { incomingWebhookSchema } from './incoming-webhook.schema.js';
|
|
58
61
|
export { scopeSchema } from './scope.schema.js';
|
|
59
62
|
export { secretSchema } from './secret.schema.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PikkuSchema } from './pikku-schema.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* What each declared trigger source registered with its provider. `state` holds provider identifiers only: a signing secret a
|
|
4
|
+
* provider issues goes to the credential service.
|
|
5
|
+
*/
|
|
6
|
+
export declare const triggerSourceSchema: PikkuSchema;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
/**
|
|
3
|
+
* What each declared trigger source registered with its provider. `state` holds provider identifiers only: a signing secret a
|
|
4
|
+
* provider issues goes to the credential service.
|
|
5
|
+
*/
|
|
6
|
+
export const triggerSourceSchema = {
|
|
7
|
+
name: 'trigger-source',
|
|
8
|
+
ownedBy: ['triggerSourceStore'],
|
|
9
|
+
statements: [
|
|
10
|
+
(db) => db.schema
|
|
11
|
+
.createTable('pikkuTriggerSource')
|
|
12
|
+
.addColumn('name', 'text', (col) => col.primaryKey())
|
|
13
|
+
.addColumn('kind', 'text', (col) => col.notNull())
|
|
14
|
+
.addColumn('declared', 'boolean', (col) => col.defaultTo(true).notNull())
|
|
15
|
+
.addColumn('status', 'text')
|
|
16
|
+
.addColumn('state', 'text')
|
|
17
|
+
.addColumn('detail', 'text')
|
|
18
|
+
.addColumn('updatedAt', 'timestamp', (col) => col.defaultTo(sql `CURRENT_TIMESTAMP`).notNull()),
|
|
19
|
+
],
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikku/kysely",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.30",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/pikkujs/pikku.git",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"prepublishOnly": "bun run build"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@pikku/core": "^0.12.
|
|
29
|
+
"@pikku/core": "^0.12.128"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"kysely": "^0.29.5"
|