weave-typescript 0.16.0 → 0.18.0
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/dist/weaveapi/atc/v1/event.pb.d.ts +101 -0
- package/dist/weaveapi/atc/v1/event.pb.js +862 -1
- package/dist/weaveapi/atc/v1/service.pb.d.ts +75 -1
- package/dist/weaveapi/atc/v1/service.pb.js +759 -1
- package/dist/weavesql/atcdb/event_sql.d.ts +8 -0
- package/dist/weavesql/atcdb/event_sql.js +20 -1
- package/dist/weavesql/atcdb/inspection_sql.d.ts +139 -0
- package/dist/weavesql/atcdb/inspection_sql.js +316 -0
- package/package.json +2 -2
|
@@ -166,4 +166,12 @@ export interface CountEventsByTypeRow {
|
|
|
166
166
|
total: string;
|
|
167
167
|
}
|
|
168
168
|
export declare function countEventsByType(client: Client, args: CountEventsByTypeArgs): Promise<CountEventsByTypeRow | null>;
|
|
169
|
+
export declare const listRunIDsQuery = "-- name: ListRunIDs :many\nSELECT DISTINCT run_id\nFROM atc.events\nWHERE tenant_id = $1\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY run_id";
|
|
170
|
+
export interface ListRunIDsArgs {
|
|
171
|
+
tenantId: string;
|
|
172
|
+
}
|
|
173
|
+
export interface ListRunIDsRow {
|
|
174
|
+
runId: string;
|
|
175
|
+
}
|
|
176
|
+
export declare function listRunIDs(client: Client, args: ListRunIDsArgs): Promise<ListRunIDsRow[]>;
|
|
169
177
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.countEventsByTypeQuery = exports.queryEventsByRunAndTypesQuery = exports.queryEventsByTimeRangeQuery = exports.queryEventsByTypeQuery = exports.lockRunQuery = exports.listEventsByTypeQuery = exports.loadAllEventsQuery = exports.loadEventsQuery = exports.getCurrentVersionQuery = exports.insertEventQuery = void 0;
|
|
3
|
+
exports.listRunIDsQuery = exports.countEventsByTypeQuery = exports.queryEventsByRunAndTypesQuery = exports.queryEventsByTimeRangeQuery = exports.queryEventsByTypeQuery = exports.lockRunQuery = exports.listEventsByTypeQuery = exports.loadAllEventsQuery = exports.loadEventsQuery = exports.getCurrentVersionQuery = exports.insertEventQuery = void 0;
|
|
4
4
|
exports.insertEvent = insertEvent;
|
|
5
5
|
exports.getCurrentVersion = getCurrentVersion;
|
|
6
6
|
exports.loadEvents = loadEvents;
|
|
@@ -11,6 +11,7 @@ exports.queryEventsByType = queryEventsByType;
|
|
|
11
11
|
exports.queryEventsByTimeRange = queryEventsByTimeRange;
|
|
12
12
|
exports.queryEventsByRunAndTypes = queryEventsByRunAndTypes;
|
|
13
13
|
exports.countEventsByType = countEventsByType;
|
|
14
|
+
exports.listRunIDs = listRunIDs;
|
|
14
15
|
exports.insertEventQuery = `-- name: InsertEvent :one
|
|
15
16
|
INSERT INTO atc.events (
|
|
16
17
|
id,
|
|
@@ -331,3 +332,21 @@ async function countEventsByType(client, args) {
|
|
|
331
332
|
total: row[0]
|
|
332
333
|
};
|
|
333
334
|
}
|
|
335
|
+
exports.listRunIDsQuery = `-- name: ListRunIDs :many
|
|
336
|
+
SELECT DISTINCT run_id
|
|
337
|
+
FROM atc.events
|
|
338
|
+
WHERE tenant_id = $1
|
|
339
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
340
|
+
ORDER BY run_id`;
|
|
341
|
+
async function listRunIDs(client, args) {
|
|
342
|
+
const result = await client.query({
|
|
343
|
+
text: exports.listRunIDsQuery,
|
|
344
|
+
values: [args.tenantId],
|
|
345
|
+
rowMode: "array"
|
|
346
|
+
});
|
|
347
|
+
return result.rows.map(row => {
|
|
348
|
+
return {
|
|
349
|
+
runId: row[0]
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertInspectionEventQuery = "-- name: InsertInspectionEvent :one\nINSERT INTO atc.inspection_events (\n id,\n tenant_id,\n occurred_at,\n type,\n category,\n subject_kind,\n subject_id,\n actor_kind,\n actor_id,\n run_id,\n process_id,\n action,\n outcome,\n reason,\n correlation_id,\n causation_id,\n schema_version,\n data,\n expires_at\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10,\n $11,\n $12,\n $13,\n $14,\n $15,\n $16,\n $17,\n $18,\n $19\n)\nRETURNING\n id,\n tenant_id,\n occurred_at,\n type,\n category,\n subject_kind,\n subject_id,\n actor_kind,\n actor_id,\n run_id,\n process_id,\n action,\n outcome,\n reason,\n correlation_id,\n causation_id,\n schema_version,\n data,\n expires_at,\n sequence";
|
|
6
|
+
export interface InsertInspectionEventArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
occurredAt: Date;
|
|
10
|
+
type: string;
|
|
11
|
+
category: string;
|
|
12
|
+
subjectKind: string;
|
|
13
|
+
subjectId: string;
|
|
14
|
+
actorKind: string;
|
|
15
|
+
actorId: string;
|
|
16
|
+
runId: string | null;
|
|
17
|
+
processId: string | null;
|
|
18
|
+
action: string;
|
|
19
|
+
outcome: string;
|
|
20
|
+
reason: string | null;
|
|
21
|
+
correlationId: string | null;
|
|
22
|
+
causationId: string | null;
|
|
23
|
+
schemaVersion: number;
|
|
24
|
+
data: any;
|
|
25
|
+
expiresAt: Date;
|
|
26
|
+
}
|
|
27
|
+
export interface InsertInspectionEventRow {
|
|
28
|
+
id: string;
|
|
29
|
+
tenantId: string;
|
|
30
|
+
occurredAt: Date;
|
|
31
|
+
type: string;
|
|
32
|
+
category: string;
|
|
33
|
+
subjectKind: string;
|
|
34
|
+
subjectId: string;
|
|
35
|
+
actorKind: string;
|
|
36
|
+
actorId: string;
|
|
37
|
+
runId: string | null;
|
|
38
|
+
processId: string | null;
|
|
39
|
+
action: string;
|
|
40
|
+
outcome: string;
|
|
41
|
+
reason: string | null;
|
|
42
|
+
correlationId: string | null;
|
|
43
|
+
causationId: string | null;
|
|
44
|
+
schemaVersion: number;
|
|
45
|
+
data: any;
|
|
46
|
+
expiresAt: Date;
|
|
47
|
+
sequence: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function insertInspectionEvent(client: Client, args: InsertInspectionEventArgs): Promise<InsertInspectionEventRow | null>;
|
|
50
|
+
export declare const queryInspectionEventsQuery = "-- name: QueryInspectionEvents :many\nSELECT\n id,\n tenant_id,\n occurred_at,\n type,\n category,\n subject_kind,\n subject_id,\n actor_kind,\n actor_id,\n run_id,\n process_id,\n action,\n outcome,\n reason,\n correlation_id,\n causation_id,\n schema_version,\n data,\n expires_at,\n sequence\nFROM atc.inspection_events\nWHERE tenant_id = $1\n AND (\n $2::text IS NULL\n OR (\n subject_kind = $2::text\n AND subject_id = $3::text\n )\n )\n AND (\n $4::text IS NULL\n OR (\n actor_kind = $4::text\n AND actor_id = $5::text\n )\n )\n AND ($6::text IS NULL OR run_id = $6::text)\n AND ($7::text IS NULL OR process_id = $7::text)\n AND ($8::text IS NULL OR action = $8::text)\n AND ($9::text IS NULL OR outcome = $9::text)\n AND (\n $10::timestamptz IS NULL\n OR occurred_at >= $10::timestamptz\n )\n AND (\n $11::timestamptz IS NULL\n OR occurred_at < $11::timestamptz\n )\n AND (\n $12::text IS NULL\n OR type LIKE replace(replace($12::text, '*', '%'), '?', '_')\n )\n AND (\n $13::timestamptz IS NULL\n OR (\n occurred_at,\n sequence\n ) < (\n $13::timestamptz,\n $14::bigint\n )\n )\nORDER BY occurred_at DESC, sequence DESC\nLIMIT $15";
|
|
51
|
+
export interface QueryInspectionEventsArgs {
|
|
52
|
+
tenantId: string;
|
|
53
|
+
subjectKind: string | null;
|
|
54
|
+
subjectId: string | null;
|
|
55
|
+
actorKind: string | null;
|
|
56
|
+
actorId: string | null;
|
|
57
|
+
runId: string | null;
|
|
58
|
+
processId: string | null;
|
|
59
|
+
action: string | null;
|
|
60
|
+
outcome: string | null;
|
|
61
|
+
startTime: Date | null;
|
|
62
|
+
endTime: Date | null;
|
|
63
|
+
typeFilter: string | null;
|
|
64
|
+
afterOccurredAt: Date | null;
|
|
65
|
+
afterSequence: string;
|
|
66
|
+
pageSize: string;
|
|
67
|
+
}
|
|
68
|
+
export interface QueryInspectionEventsRow {
|
|
69
|
+
id: string;
|
|
70
|
+
tenantId: string;
|
|
71
|
+
occurredAt: Date;
|
|
72
|
+
type: string;
|
|
73
|
+
category: string;
|
|
74
|
+
subjectKind: string;
|
|
75
|
+
subjectId: string;
|
|
76
|
+
actorKind: string;
|
|
77
|
+
actorId: string;
|
|
78
|
+
runId: string | null;
|
|
79
|
+
processId: string | null;
|
|
80
|
+
action: string;
|
|
81
|
+
outcome: string;
|
|
82
|
+
reason: string | null;
|
|
83
|
+
correlationId: string | null;
|
|
84
|
+
causationId: string | null;
|
|
85
|
+
schemaVersion: number;
|
|
86
|
+
data: any;
|
|
87
|
+
expiresAt: Date;
|
|
88
|
+
sequence: string;
|
|
89
|
+
}
|
|
90
|
+
export declare function queryInspectionEvents(client: Client, args: QueryInspectionEventsArgs): Promise<QueryInspectionEventsRow[]>;
|
|
91
|
+
export declare const loadInspectionEventsFromSequenceQuery = "-- name: LoadInspectionEventsFromSequence :many\nSELECT\n id,\n tenant_id,\n occurred_at,\n type,\n category,\n subject_kind,\n subject_id,\n actor_kind,\n actor_id,\n run_id,\n process_id,\n action,\n outcome,\n reason,\n correlation_id,\n causation_id,\n schema_version,\n data,\n expires_at,\n sequence\nFROM atc.inspection_events\nWHERE tenant_id = $1\n AND sequence > $2\n AND (\n $3::text IS NULL\n OR (\n subject_kind = $3::text\n AND subject_id = $4::text\n )\n )\n AND (\n $5::text IS NULL\n OR (\n actor_kind = $5::text\n AND actor_id = $6::text\n )\n )\n AND ($7::text IS NULL OR run_id = $7::text)\n AND ($8::text IS NULL OR process_id = $8::text)\n AND ($9::text IS NULL OR action = $9::text)\n AND ($10::text IS NULL OR outcome = $10::text)\n AND (\n $11::timestamptz IS NULL\n OR occurred_at >= $11::timestamptz\n )\n AND (\n $12::timestamptz IS NULL\n OR occurred_at < $12::timestamptz\n )\n AND (\n $13::text IS NULL\n OR type LIKE replace(replace($13::text, '*', '%'), '?', '_')\n )\nORDER BY sequence ASC";
|
|
92
|
+
export interface LoadInspectionEventsFromSequenceArgs {
|
|
93
|
+
tenantId: string;
|
|
94
|
+
afterSequence: string;
|
|
95
|
+
subjectKind: string | null;
|
|
96
|
+
subjectId: string | null;
|
|
97
|
+
actorKind: string | null;
|
|
98
|
+
actorId: string | null;
|
|
99
|
+
runId: string | null;
|
|
100
|
+
processId: string | null;
|
|
101
|
+
action: string | null;
|
|
102
|
+
outcome: string | null;
|
|
103
|
+
startTime: Date | null;
|
|
104
|
+
endTime: Date | null;
|
|
105
|
+
typeFilter: string | null;
|
|
106
|
+
}
|
|
107
|
+
export interface LoadInspectionEventsFromSequenceRow {
|
|
108
|
+
id: string;
|
|
109
|
+
tenantId: string;
|
|
110
|
+
occurredAt: Date;
|
|
111
|
+
type: string;
|
|
112
|
+
category: string;
|
|
113
|
+
subjectKind: string;
|
|
114
|
+
subjectId: string;
|
|
115
|
+
actorKind: string;
|
|
116
|
+
actorId: string;
|
|
117
|
+
runId: string | null;
|
|
118
|
+
processId: string | null;
|
|
119
|
+
action: string;
|
|
120
|
+
outcome: string;
|
|
121
|
+
reason: string | null;
|
|
122
|
+
correlationId: string | null;
|
|
123
|
+
causationId: string | null;
|
|
124
|
+
schemaVersion: number;
|
|
125
|
+
data: any;
|
|
126
|
+
expiresAt: Date;
|
|
127
|
+
sequence: string;
|
|
128
|
+
}
|
|
129
|
+
export declare function loadInspectionEventsFromSequence(client: Client, args: LoadInspectionEventsFromSequenceArgs): Promise<LoadInspectionEventsFromSequenceRow[]>;
|
|
130
|
+
export declare const deleteExpiredInspectionEventsQuery = "-- name: DeleteExpiredInspectionEvents :one\nWITH expired AS (\n SELECT id\n FROM atc.inspection_events\n WHERE expires_at < $1::timestamptz\n ORDER BY expires_at ASC\n LIMIT $2\n),\ndeleted AS (\n DELETE FROM atc.inspection_events\n WHERE id IN (SELECT id FROM expired)\n RETURNING id\n)\nSELECT COUNT(*)::BIGINT AS total\nFROM deleted";
|
|
131
|
+
export interface DeleteExpiredInspectionEventsArgs {
|
|
132
|
+
expiresBefore: Date;
|
|
133
|
+
deleteLimit: string;
|
|
134
|
+
}
|
|
135
|
+
export interface DeleteExpiredInspectionEventsRow {
|
|
136
|
+
total: string;
|
|
137
|
+
}
|
|
138
|
+
export declare function deleteExpiredInspectionEvents(client: Client, args: DeleteExpiredInspectionEventsArgs): Promise<DeleteExpiredInspectionEventsRow | null>;
|
|
139
|
+
export {};
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteExpiredInspectionEventsQuery = exports.loadInspectionEventsFromSequenceQuery = exports.queryInspectionEventsQuery = exports.insertInspectionEventQuery = void 0;
|
|
4
|
+
exports.insertInspectionEvent = insertInspectionEvent;
|
|
5
|
+
exports.queryInspectionEvents = queryInspectionEvents;
|
|
6
|
+
exports.loadInspectionEventsFromSequence = loadInspectionEventsFromSequence;
|
|
7
|
+
exports.deleteExpiredInspectionEvents = deleteExpiredInspectionEvents;
|
|
8
|
+
exports.insertInspectionEventQuery = `-- name: InsertInspectionEvent :one
|
|
9
|
+
INSERT INTO atc.inspection_events (
|
|
10
|
+
id,
|
|
11
|
+
tenant_id,
|
|
12
|
+
occurred_at,
|
|
13
|
+
type,
|
|
14
|
+
category,
|
|
15
|
+
subject_kind,
|
|
16
|
+
subject_id,
|
|
17
|
+
actor_kind,
|
|
18
|
+
actor_id,
|
|
19
|
+
run_id,
|
|
20
|
+
process_id,
|
|
21
|
+
action,
|
|
22
|
+
outcome,
|
|
23
|
+
reason,
|
|
24
|
+
correlation_id,
|
|
25
|
+
causation_id,
|
|
26
|
+
schema_version,
|
|
27
|
+
data,
|
|
28
|
+
expires_at
|
|
29
|
+
) VALUES (
|
|
30
|
+
$1,
|
|
31
|
+
$2,
|
|
32
|
+
$3,
|
|
33
|
+
$4,
|
|
34
|
+
$5,
|
|
35
|
+
$6,
|
|
36
|
+
$7,
|
|
37
|
+
$8,
|
|
38
|
+
$9,
|
|
39
|
+
$10,
|
|
40
|
+
$11,
|
|
41
|
+
$12,
|
|
42
|
+
$13,
|
|
43
|
+
$14,
|
|
44
|
+
$15,
|
|
45
|
+
$16,
|
|
46
|
+
$17,
|
|
47
|
+
$18,
|
|
48
|
+
$19
|
|
49
|
+
)
|
|
50
|
+
RETURNING
|
|
51
|
+
id,
|
|
52
|
+
tenant_id,
|
|
53
|
+
occurred_at,
|
|
54
|
+
type,
|
|
55
|
+
category,
|
|
56
|
+
subject_kind,
|
|
57
|
+
subject_id,
|
|
58
|
+
actor_kind,
|
|
59
|
+
actor_id,
|
|
60
|
+
run_id,
|
|
61
|
+
process_id,
|
|
62
|
+
action,
|
|
63
|
+
outcome,
|
|
64
|
+
reason,
|
|
65
|
+
correlation_id,
|
|
66
|
+
causation_id,
|
|
67
|
+
schema_version,
|
|
68
|
+
data,
|
|
69
|
+
expires_at,
|
|
70
|
+
sequence`;
|
|
71
|
+
async function insertInspectionEvent(client, args) {
|
|
72
|
+
const result = await client.query({
|
|
73
|
+
text: exports.insertInspectionEventQuery,
|
|
74
|
+
values: [args.id, args.tenantId, args.occurredAt, args.type, args.category, args.subjectKind, args.subjectId, args.actorKind, args.actorId, args.runId, args.processId, args.action, args.outcome, args.reason, args.correlationId, args.causationId, args.schemaVersion, args.data, args.expiresAt],
|
|
75
|
+
rowMode: "array"
|
|
76
|
+
});
|
|
77
|
+
if (result.rows.length !== 1) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const row = result.rows[0];
|
|
81
|
+
return {
|
|
82
|
+
id: row[0],
|
|
83
|
+
tenantId: row[1],
|
|
84
|
+
occurredAt: row[2],
|
|
85
|
+
type: row[3],
|
|
86
|
+
category: row[4],
|
|
87
|
+
subjectKind: row[5],
|
|
88
|
+
subjectId: row[6],
|
|
89
|
+
actorKind: row[7],
|
|
90
|
+
actorId: row[8],
|
|
91
|
+
runId: row[9],
|
|
92
|
+
processId: row[10],
|
|
93
|
+
action: row[11],
|
|
94
|
+
outcome: row[12],
|
|
95
|
+
reason: row[13],
|
|
96
|
+
correlationId: row[14],
|
|
97
|
+
causationId: row[15],
|
|
98
|
+
schemaVersion: row[16],
|
|
99
|
+
data: row[17],
|
|
100
|
+
expiresAt: row[18],
|
|
101
|
+
sequence: row[19]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
exports.queryInspectionEventsQuery = `-- name: QueryInspectionEvents :many
|
|
105
|
+
SELECT
|
|
106
|
+
id,
|
|
107
|
+
tenant_id,
|
|
108
|
+
occurred_at,
|
|
109
|
+
type,
|
|
110
|
+
category,
|
|
111
|
+
subject_kind,
|
|
112
|
+
subject_id,
|
|
113
|
+
actor_kind,
|
|
114
|
+
actor_id,
|
|
115
|
+
run_id,
|
|
116
|
+
process_id,
|
|
117
|
+
action,
|
|
118
|
+
outcome,
|
|
119
|
+
reason,
|
|
120
|
+
correlation_id,
|
|
121
|
+
causation_id,
|
|
122
|
+
schema_version,
|
|
123
|
+
data,
|
|
124
|
+
expires_at,
|
|
125
|
+
sequence
|
|
126
|
+
FROM atc.inspection_events
|
|
127
|
+
WHERE tenant_id = $1
|
|
128
|
+
AND (
|
|
129
|
+
$2::text IS NULL
|
|
130
|
+
OR (
|
|
131
|
+
subject_kind = $2::text
|
|
132
|
+
AND subject_id = $3::text
|
|
133
|
+
)
|
|
134
|
+
)
|
|
135
|
+
AND (
|
|
136
|
+
$4::text IS NULL
|
|
137
|
+
OR (
|
|
138
|
+
actor_kind = $4::text
|
|
139
|
+
AND actor_id = $5::text
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
AND ($6::text IS NULL OR run_id = $6::text)
|
|
143
|
+
AND ($7::text IS NULL OR process_id = $7::text)
|
|
144
|
+
AND ($8::text IS NULL OR action = $8::text)
|
|
145
|
+
AND ($9::text IS NULL OR outcome = $9::text)
|
|
146
|
+
AND (
|
|
147
|
+
$10::timestamptz IS NULL
|
|
148
|
+
OR occurred_at >= $10::timestamptz
|
|
149
|
+
)
|
|
150
|
+
AND (
|
|
151
|
+
$11::timestamptz IS NULL
|
|
152
|
+
OR occurred_at < $11::timestamptz
|
|
153
|
+
)
|
|
154
|
+
AND (
|
|
155
|
+
$12::text IS NULL
|
|
156
|
+
OR type LIKE replace(replace($12::text, '*', '%'), '?', '_')
|
|
157
|
+
)
|
|
158
|
+
AND (
|
|
159
|
+
$13::timestamptz IS NULL
|
|
160
|
+
OR (
|
|
161
|
+
occurred_at,
|
|
162
|
+
sequence
|
|
163
|
+
) < (
|
|
164
|
+
$13::timestamptz,
|
|
165
|
+
$14::bigint
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
ORDER BY occurred_at DESC, sequence DESC
|
|
169
|
+
LIMIT $15`;
|
|
170
|
+
async function queryInspectionEvents(client, args) {
|
|
171
|
+
const result = await client.query({
|
|
172
|
+
text: exports.queryInspectionEventsQuery,
|
|
173
|
+
values: [args.tenantId, args.subjectKind, args.subjectId, args.actorKind, args.actorId, args.runId, args.processId, args.action, args.outcome, args.startTime, args.endTime, args.typeFilter, args.afterOccurredAt, args.afterSequence, args.pageSize],
|
|
174
|
+
rowMode: "array"
|
|
175
|
+
});
|
|
176
|
+
return result.rows.map(row => {
|
|
177
|
+
return {
|
|
178
|
+
id: row[0],
|
|
179
|
+
tenantId: row[1],
|
|
180
|
+
occurredAt: row[2],
|
|
181
|
+
type: row[3],
|
|
182
|
+
category: row[4],
|
|
183
|
+
subjectKind: row[5],
|
|
184
|
+
subjectId: row[6],
|
|
185
|
+
actorKind: row[7],
|
|
186
|
+
actorId: row[8],
|
|
187
|
+
runId: row[9],
|
|
188
|
+
processId: row[10],
|
|
189
|
+
action: row[11],
|
|
190
|
+
outcome: row[12],
|
|
191
|
+
reason: row[13],
|
|
192
|
+
correlationId: row[14],
|
|
193
|
+
causationId: row[15],
|
|
194
|
+
schemaVersion: row[16],
|
|
195
|
+
data: row[17],
|
|
196
|
+
expiresAt: row[18],
|
|
197
|
+
sequence: row[19]
|
|
198
|
+
};
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.loadInspectionEventsFromSequenceQuery = `-- name: LoadInspectionEventsFromSequence :many
|
|
202
|
+
SELECT
|
|
203
|
+
id,
|
|
204
|
+
tenant_id,
|
|
205
|
+
occurred_at,
|
|
206
|
+
type,
|
|
207
|
+
category,
|
|
208
|
+
subject_kind,
|
|
209
|
+
subject_id,
|
|
210
|
+
actor_kind,
|
|
211
|
+
actor_id,
|
|
212
|
+
run_id,
|
|
213
|
+
process_id,
|
|
214
|
+
action,
|
|
215
|
+
outcome,
|
|
216
|
+
reason,
|
|
217
|
+
correlation_id,
|
|
218
|
+
causation_id,
|
|
219
|
+
schema_version,
|
|
220
|
+
data,
|
|
221
|
+
expires_at,
|
|
222
|
+
sequence
|
|
223
|
+
FROM atc.inspection_events
|
|
224
|
+
WHERE tenant_id = $1
|
|
225
|
+
AND sequence > $2
|
|
226
|
+
AND (
|
|
227
|
+
$3::text IS NULL
|
|
228
|
+
OR (
|
|
229
|
+
subject_kind = $3::text
|
|
230
|
+
AND subject_id = $4::text
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
AND (
|
|
234
|
+
$5::text IS NULL
|
|
235
|
+
OR (
|
|
236
|
+
actor_kind = $5::text
|
|
237
|
+
AND actor_id = $6::text
|
|
238
|
+
)
|
|
239
|
+
)
|
|
240
|
+
AND ($7::text IS NULL OR run_id = $7::text)
|
|
241
|
+
AND ($8::text IS NULL OR process_id = $8::text)
|
|
242
|
+
AND ($9::text IS NULL OR action = $9::text)
|
|
243
|
+
AND ($10::text IS NULL OR outcome = $10::text)
|
|
244
|
+
AND (
|
|
245
|
+
$11::timestamptz IS NULL
|
|
246
|
+
OR occurred_at >= $11::timestamptz
|
|
247
|
+
)
|
|
248
|
+
AND (
|
|
249
|
+
$12::timestamptz IS NULL
|
|
250
|
+
OR occurred_at < $12::timestamptz
|
|
251
|
+
)
|
|
252
|
+
AND (
|
|
253
|
+
$13::text IS NULL
|
|
254
|
+
OR type LIKE replace(replace($13::text, '*', '%'), '?', '_')
|
|
255
|
+
)
|
|
256
|
+
ORDER BY sequence ASC`;
|
|
257
|
+
async function loadInspectionEventsFromSequence(client, args) {
|
|
258
|
+
const result = await client.query({
|
|
259
|
+
text: exports.loadInspectionEventsFromSequenceQuery,
|
|
260
|
+
values: [args.tenantId, args.afterSequence, args.subjectKind, args.subjectId, args.actorKind, args.actorId, args.runId, args.processId, args.action, args.outcome, args.startTime, args.endTime, args.typeFilter],
|
|
261
|
+
rowMode: "array"
|
|
262
|
+
});
|
|
263
|
+
return result.rows.map(row => {
|
|
264
|
+
return {
|
|
265
|
+
id: row[0],
|
|
266
|
+
tenantId: row[1],
|
|
267
|
+
occurredAt: row[2],
|
|
268
|
+
type: row[3],
|
|
269
|
+
category: row[4],
|
|
270
|
+
subjectKind: row[5],
|
|
271
|
+
subjectId: row[6],
|
|
272
|
+
actorKind: row[7],
|
|
273
|
+
actorId: row[8],
|
|
274
|
+
runId: row[9],
|
|
275
|
+
processId: row[10],
|
|
276
|
+
action: row[11],
|
|
277
|
+
outcome: row[12],
|
|
278
|
+
reason: row[13],
|
|
279
|
+
correlationId: row[14],
|
|
280
|
+
causationId: row[15],
|
|
281
|
+
schemaVersion: row[16],
|
|
282
|
+
data: row[17],
|
|
283
|
+
expiresAt: row[18],
|
|
284
|
+
sequence: row[19]
|
|
285
|
+
};
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
exports.deleteExpiredInspectionEventsQuery = `-- name: DeleteExpiredInspectionEvents :one
|
|
289
|
+
WITH expired AS (
|
|
290
|
+
SELECT id
|
|
291
|
+
FROM atc.inspection_events
|
|
292
|
+
WHERE expires_at < $1::timestamptz
|
|
293
|
+
ORDER BY expires_at ASC
|
|
294
|
+
LIMIT $2
|
|
295
|
+
),
|
|
296
|
+
deleted AS (
|
|
297
|
+
DELETE FROM atc.inspection_events
|
|
298
|
+
WHERE id IN (SELECT id FROM expired)
|
|
299
|
+
RETURNING id
|
|
300
|
+
)
|
|
301
|
+
SELECT COUNT(*)::BIGINT AS total
|
|
302
|
+
FROM deleted`;
|
|
303
|
+
async function deleteExpiredInspectionEvents(client, args) {
|
|
304
|
+
const result = await client.query({
|
|
305
|
+
text: exports.deleteExpiredInspectionEventsQuery,
|
|
306
|
+
values: [args.expiresBefore, args.deleteLimit],
|
|
307
|
+
rowMode: "array"
|
|
308
|
+
});
|
|
309
|
+
if (result.rows.length !== 1) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
const row = result.rows[0];
|
|
313
|
+
return {
|
|
314
|
+
total: row[0]
|
|
315
|
+
};
|
|
316
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "weave-typescript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^25.2.0",
|
|
33
33
|
"@types/pg": "^8.15.5",
|
|
34
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
34
|
+
"@typescript/native-preview": "7.0.0-dev.20260416.2"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"test": "node tools/sqlcgen.test.js",
|