weave-typescript 0.15.0 → 0.16.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/service.pb.d.ts +24 -0
- package/dist/weaveapi/atc/v1/service.pb.js +163 -1
- package/dist/weaveapi/provider/v1/provider.pb.d.ts +123 -0
- package/dist/weaveapi/provider/v1/provider.pb.js +914 -0
- package/dist/weaveapi/provider/v1/service.pb.d.ts +198 -0
- package/dist/weaveapi/provider/v1/service.pb.js +1569 -0
- package/dist/weavesql/atcdb/event_sql.d.ts +68 -0
- package/dist/weavesql/atcdb/event_sql.js +143 -1
- package/dist/weavesql/atcdb/run_template_sql.d.ts +122 -0
- package/dist/weavesql/atcdb/run_template_sql.js +197 -0
- package/dist/weavesql/atcdb/snapshot_sql.d.ts +58 -0
- package/dist/weavesql/atcdb/snapshot_sql.js +124 -0
- package/dist/weavesql/atcdb/team_sql.d.ts +111 -0
- package/dist/weavesql/atcdb/team_sql.js +235 -0
- package/dist/weavesql/atcdb/workflow_template_sql.d.ts +122 -0
- package/dist/weavesql/atcdb/workflow_template_sql.js +197 -0
- package/dist/weavesql/weavedb/provider_sql.d.ts +162 -0
- package/dist/weavesql/weavedb/provider_sql.js +358 -0
- package/package.json +2 -2
|
@@ -98,4 +98,72 @@ export interface LockRunRow {
|
|
|
98
98
|
pgAdvisoryXactLock: string;
|
|
99
99
|
}
|
|
100
100
|
export declare function lockRun(client: Client, args: LockRunArgs): Promise<void>;
|
|
101
|
+
export declare const queryEventsByTypeQuery = "-- name: QueryEventsByType :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND type = $2\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\n AND (\n $3::timestamptz IS NULL\n OR (occurred_at, sequence) < ($3::timestamptz, $4::bigint)\n )\nORDER BY occurred_at DESC, sequence DESC\nLIMIT $5";
|
|
102
|
+
export interface QueryEventsByTypeArgs {
|
|
103
|
+
tenantId: string;
|
|
104
|
+
eventType: string;
|
|
105
|
+
afterOccurredAt: Date;
|
|
106
|
+
afterSequence: string;
|
|
107
|
+
pageSize: string;
|
|
108
|
+
}
|
|
109
|
+
export interface QueryEventsByTypeRow {
|
|
110
|
+
id: string;
|
|
111
|
+
tenantId: string;
|
|
112
|
+
runId: string;
|
|
113
|
+
sequence: string;
|
|
114
|
+
type: string;
|
|
115
|
+
data: any | null;
|
|
116
|
+
causationId: string | null;
|
|
117
|
+
correlationId: string | null;
|
|
118
|
+
occurredAt: Date;
|
|
119
|
+
}
|
|
120
|
+
export declare function queryEventsByType(client: Client, args: QueryEventsByTypeArgs): Promise<QueryEventsByTypeRow[]>;
|
|
121
|
+
export declare const queryEventsByTimeRangeQuery = "-- name: QueryEventsByTimeRange :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND occurred_at >= $2\n AND occurred_at < $3\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY occurred_at ASC, sequence ASC\nLIMIT $4";
|
|
122
|
+
export interface QueryEventsByTimeRangeArgs {
|
|
123
|
+
tenantId: string;
|
|
124
|
+
startTime: Date;
|
|
125
|
+
endTime: Date;
|
|
126
|
+
pageSize: string;
|
|
127
|
+
}
|
|
128
|
+
export interface QueryEventsByTimeRangeRow {
|
|
129
|
+
id: string;
|
|
130
|
+
tenantId: string;
|
|
131
|
+
runId: string;
|
|
132
|
+
sequence: string;
|
|
133
|
+
type: string;
|
|
134
|
+
data: any | null;
|
|
135
|
+
causationId: string | null;
|
|
136
|
+
correlationId: string | null;
|
|
137
|
+
occurredAt: Date;
|
|
138
|
+
}
|
|
139
|
+
export declare function queryEventsByTimeRange(client: Client, args: QueryEventsByTimeRangeArgs): Promise<QueryEventsByTimeRangeRow[]>;
|
|
140
|
+
export declare const queryEventsByRunAndTypesQuery = "-- name: QueryEventsByRunAndTypes :many\nSELECT\n id,\n tenant_id,\n run_id,\n sequence,\n type,\n data,\n causation_id,\n correlation_id,\n occurred_at\nFROM atc.events\nWHERE tenant_id = $1\n AND run_id = $2\n AND type = ANY($3::text[])\n AND sequence > $4\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())\nORDER BY sequence ASC\nLIMIT $5";
|
|
141
|
+
export interface QueryEventsByRunAndTypesArgs {
|
|
142
|
+
tenantId: string;
|
|
143
|
+
runId: string;
|
|
144
|
+
eventTypes: string[];
|
|
145
|
+
afterSequence: string;
|
|
146
|
+
pageSize: string;
|
|
147
|
+
}
|
|
148
|
+
export interface QueryEventsByRunAndTypesRow {
|
|
149
|
+
id: string;
|
|
150
|
+
tenantId: string;
|
|
151
|
+
runId: string;
|
|
152
|
+
sequence: string;
|
|
153
|
+
type: string;
|
|
154
|
+
data: any | null;
|
|
155
|
+
causationId: string | null;
|
|
156
|
+
correlationId: string | null;
|
|
157
|
+
occurredAt: Date;
|
|
158
|
+
}
|
|
159
|
+
export declare function queryEventsByRunAndTypes(client: Client, args: QueryEventsByRunAndTypesArgs): Promise<QueryEventsByRunAndTypesRow[]>;
|
|
160
|
+
export declare const countEventsByTypeQuery = "-- name: CountEventsByType :one\nSELECT COUNT(*)::BIGINT AS total\nFROM atc.events\nWHERE tenant_id = $1\n AND type = $2\n AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())";
|
|
161
|
+
export interface CountEventsByTypeArgs {
|
|
162
|
+
tenantId: string;
|
|
163
|
+
eventType: string;
|
|
164
|
+
}
|
|
165
|
+
export interface CountEventsByTypeRow {
|
|
166
|
+
total: string;
|
|
167
|
+
}
|
|
168
|
+
export declare function countEventsByType(client: Client, args: CountEventsByTypeArgs): Promise<CountEventsByTypeRow | null>;
|
|
101
169
|
export {};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lockRunQuery = exports.listEventsByTypeQuery = exports.loadAllEventsQuery = exports.loadEventsQuery = exports.getCurrentVersionQuery = exports.insertEventQuery = void 0;
|
|
3
|
+
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;
|
|
7
7
|
exports.loadAllEvents = loadAllEvents;
|
|
8
8
|
exports.listEventsByType = listEventsByType;
|
|
9
9
|
exports.lockRun = lockRun;
|
|
10
|
+
exports.queryEventsByType = queryEventsByType;
|
|
11
|
+
exports.queryEventsByTimeRange = queryEventsByTimeRange;
|
|
12
|
+
exports.queryEventsByRunAndTypes = queryEventsByRunAndTypes;
|
|
13
|
+
exports.countEventsByType = countEventsByType;
|
|
10
14
|
exports.insertEventQuery = `-- name: InsertEvent :one
|
|
11
15
|
INSERT INTO atc.events (
|
|
12
16
|
id,
|
|
@@ -189,3 +193,141 @@ async function lockRun(client, args) {
|
|
|
189
193
|
rowMode: "array"
|
|
190
194
|
});
|
|
191
195
|
}
|
|
196
|
+
exports.queryEventsByTypeQuery = `-- name: QueryEventsByType :many
|
|
197
|
+
SELECT
|
|
198
|
+
id,
|
|
199
|
+
tenant_id,
|
|
200
|
+
run_id,
|
|
201
|
+
sequence,
|
|
202
|
+
type,
|
|
203
|
+
data,
|
|
204
|
+
causation_id,
|
|
205
|
+
correlation_id,
|
|
206
|
+
occurred_at
|
|
207
|
+
FROM atc.events
|
|
208
|
+
WHERE tenant_id = $1
|
|
209
|
+
AND type = $2
|
|
210
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
211
|
+
AND (
|
|
212
|
+
$3::timestamptz IS NULL
|
|
213
|
+
OR (occurred_at, sequence) < ($3::timestamptz, $4::bigint)
|
|
214
|
+
)
|
|
215
|
+
ORDER BY occurred_at DESC, sequence DESC
|
|
216
|
+
LIMIT $5`;
|
|
217
|
+
async function queryEventsByType(client, args) {
|
|
218
|
+
const result = await client.query({
|
|
219
|
+
text: exports.queryEventsByTypeQuery,
|
|
220
|
+
values: [args.tenantId, args.eventType, args.afterOccurredAt, args.afterSequence, args.pageSize],
|
|
221
|
+
rowMode: "array"
|
|
222
|
+
});
|
|
223
|
+
return result.rows.map(row => {
|
|
224
|
+
return {
|
|
225
|
+
id: row[0],
|
|
226
|
+
tenantId: row[1],
|
|
227
|
+
runId: row[2],
|
|
228
|
+
sequence: row[3],
|
|
229
|
+
type: row[4],
|
|
230
|
+
data: row[5],
|
|
231
|
+
causationId: row[6],
|
|
232
|
+
correlationId: row[7],
|
|
233
|
+
occurredAt: row[8]
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
exports.queryEventsByTimeRangeQuery = `-- name: QueryEventsByTimeRange :many
|
|
238
|
+
SELECT
|
|
239
|
+
id,
|
|
240
|
+
tenant_id,
|
|
241
|
+
run_id,
|
|
242
|
+
sequence,
|
|
243
|
+
type,
|
|
244
|
+
data,
|
|
245
|
+
causation_id,
|
|
246
|
+
correlation_id,
|
|
247
|
+
occurred_at
|
|
248
|
+
FROM atc.events
|
|
249
|
+
WHERE tenant_id = $1
|
|
250
|
+
AND occurred_at >= $2
|
|
251
|
+
AND occurred_at < $3
|
|
252
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
253
|
+
ORDER BY occurred_at ASC, sequence ASC
|
|
254
|
+
LIMIT $4`;
|
|
255
|
+
async function queryEventsByTimeRange(client, args) {
|
|
256
|
+
const result = await client.query({
|
|
257
|
+
text: exports.queryEventsByTimeRangeQuery,
|
|
258
|
+
values: [args.tenantId, args.startTime, args.endTime, args.pageSize],
|
|
259
|
+
rowMode: "array"
|
|
260
|
+
});
|
|
261
|
+
return result.rows.map(row => {
|
|
262
|
+
return {
|
|
263
|
+
id: row[0],
|
|
264
|
+
tenantId: row[1],
|
|
265
|
+
runId: row[2],
|
|
266
|
+
sequence: row[3],
|
|
267
|
+
type: row[4],
|
|
268
|
+
data: row[5],
|
|
269
|
+
causationId: row[6],
|
|
270
|
+
correlationId: row[7],
|
|
271
|
+
occurredAt: row[8]
|
|
272
|
+
};
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
exports.queryEventsByRunAndTypesQuery = `-- name: QueryEventsByRunAndTypes :many
|
|
276
|
+
SELECT
|
|
277
|
+
id,
|
|
278
|
+
tenant_id,
|
|
279
|
+
run_id,
|
|
280
|
+
sequence,
|
|
281
|
+
type,
|
|
282
|
+
data,
|
|
283
|
+
causation_id,
|
|
284
|
+
correlation_id,
|
|
285
|
+
occurred_at
|
|
286
|
+
FROM atc.events
|
|
287
|
+
WHERE tenant_id = $1
|
|
288
|
+
AND run_id = $2
|
|
289
|
+
AND type = ANY($3::text[])
|
|
290
|
+
AND sequence > $4
|
|
291
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())
|
|
292
|
+
ORDER BY sequence ASC
|
|
293
|
+
LIMIT $5`;
|
|
294
|
+
async function queryEventsByRunAndTypes(client, args) {
|
|
295
|
+
const result = await client.query({
|
|
296
|
+
text: exports.queryEventsByRunAndTypesQuery,
|
|
297
|
+
values: [args.tenantId, args.runId, args.eventTypes, args.afterSequence, args.pageSize],
|
|
298
|
+
rowMode: "array"
|
|
299
|
+
});
|
|
300
|
+
return result.rows.map(row => {
|
|
301
|
+
return {
|
|
302
|
+
id: row[0],
|
|
303
|
+
tenantId: row[1],
|
|
304
|
+
runId: row[2],
|
|
305
|
+
sequence: row[3],
|
|
306
|
+
type: row[4],
|
|
307
|
+
data: row[5],
|
|
308
|
+
causationId: row[6],
|
|
309
|
+
correlationId: row[7],
|
|
310
|
+
occurredAt: row[8]
|
|
311
|
+
};
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
exports.countEventsByTypeQuery = `-- name: CountEventsByType :one
|
|
315
|
+
SELECT COUNT(*)::BIGINT AS total
|
|
316
|
+
FROM atc.events
|
|
317
|
+
WHERE tenant_id = $1
|
|
318
|
+
AND type = $2
|
|
319
|
+
AND transaction_id < pg_snapshot_xmin(pg_current_snapshot())`;
|
|
320
|
+
async function countEventsByType(client, args) {
|
|
321
|
+
const result = await client.query({
|
|
322
|
+
text: exports.countEventsByTypeQuery,
|
|
323
|
+
values: [args.tenantId, args.eventType],
|
|
324
|
+
rowMode: "array"
|
|
325
|
+
});
|
|
326
|
+
if (result.rows.length !== 1) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
const row = result.rows[0];
|
|
330
|
+
return {
|
|
331
|
+
total: row[0]
|
|
332
|
+
};
|
|
333
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const insertRunTemplateQuery = "-- name: InsertRunTemplate :one\nINSERT INTO atc.run_templates (\n id,\n tenant_id,\n name,\n version,\n handler_type,\n config,\n security_context,\n budget_context,\n pinned_caller,\n created_by\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5,\n $6,\n $7,\n $8,\n $9,\n $10\n)\nRETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at";
|
|
6
|
+
export interface InsertRunTemplateArgs {
|
|
7
|
+
id: string;
|
|
8
|
+
tenantId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
version: number;
|
|
11
|
+
handlerType: string;
|
|
12
|
+
config: any;
|
|
13
|
+
securityContext: any | null;
|
|
14
|
+
budgetContext: any | null;
|
|
15
|
+
pinnedCaller: any | null;
|
|
16
|
+
createdBy: string;
|
|
17
|
+
}
|
|
18
|
+
export interface InsertRunTemplateRow {
|
|
19
|
+
id: string;
|
|
20
|
+
tenantId: string;
|
|
21
|
+
name: string;
|
|
22
|
+
version: number;
|
|
23
|
+
handlerType: string;
|
|
24
|
+
config: any;
|
|
25
|
+
securityContext: any | null;
|
|
26
|
+
budgetContext: any | null;
|
|
27
|
+
pinnedCaller: any | null;
|
|
28
|
+
createdBy: string;
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
updatedAt: Date;
|
|
31
|
+
}
|
|
32
|
+
export declare function insertRunTemplate(client: Client, args: InsertRunTemplateArgs): Promise<InsertRunTemplateRow | null>;
|
|
33
|
+
export declare const getRunTemplateQuery = "-- name: GetRunTemplate :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.run_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
34
|
+
export interface GetRunTemplateArgs {
|
|
35
|
+
tenantId: string;
|
|
36
|
+
id: string;
|
|
37
|
+
}
|
|
38
|
+
export interface GetRunTemplateRow {
|
|
39
|
+
id: string;
|
|
40
|
+
tenantId: string;
|
|
41
|
+
name: string;
|
|
42
|
+
version: number;
|
|
43
|
+
handlerType: string;
|
|
44
|
+
config: any;
|
|
45
|
+
securityContext: any | null;
|
|
46
|
+
budgetContext: any | null;
|
|
47
|
+
pinnedCaller: any | null;
|
|
48
|
+
createdBy: string;
|
|
49
|
+
createdAt: Date;
|
|
50
|
+
updatedAt: Date;
|
|
51
|
+
}
|
|
52
|
+
export declare function getRunTemplate(client: Client, args: GetRunTemplateArgs): Promise<GetRunTemplateRow | null>;
|
|
53
|
+
export declare const getRunTemplateByNameQuery = "-- name: GetRunTemplateByName :one\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.run_templates\nWHERE tenant_id = $1\n AND name = $2\nORDER BY version DESC\nLIMIT 1";
|
|
54
|
+
export interface GetRunTemplateByNameArgs {
|
|
55
|
+
tenantId: string;
|
|
56
|
+
name: string;
|
|
57
|
+
}
|
|
58
|
+
export interface GetRunTemplateByNameRow {
|
|
59
|
+
id: string;
|
|
60
|
+
tenantId: string;
|
|
61
|
+
name: string;
|
|
62
|
+
version: number;
|
|
63
|
+
handlerType: string;
|
|
64
|
+
config: any;
|
|
65
|
+
securityContext: any | null;
|
|
66
|
+
budgetContext: any | null;
|
|
67
|
+
pinnedCaller: any | null;
|
|
68
|
+
createdBy: string;
|
|
69
|
+
createdAt: Date;
|
|
70
|
+
updatedAt: Date;
|
|
71
|
+
}
|
|
72
|
+
export declare function getRunTemplateByName(client: Client, args: GetRunTemplateByNameArgs): Promise<GetRunTemplateByNameRow | null>;
|
|
73
|
+
export declare const listRunTemplatesQuery = "-- name: ListRunTemplates :many\nSELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at\nFROM atc.run_templates\nWHERE tenant_id = $1\nORDER BY name ASC, version DESC";
|
|
74
|
+
export interface ListRunTemplatesArgs {
|
|
75
|
+
tenantId: string;
|
|
76
|
+
}
|
|
77
|
+
export interface ListRunTemplatesRow {
|
|
78
|
+
id: string;
|
|
79
|
+
tenantId: string;
|
|
80
|
+
name: string;
|
|
81
|
+
version: number;
|
|
82
|
+
handlerType: string;
|
|
83
|
+
config: any;
|
|
84
|
+
securityContext: any | null;
|
|
85
|
+
budgetContext: any | null;
|
|
86
|
+
pinnedCaller: any | null;
|
|
87
|
+
createdBy: string;
|
|
88
|
+
createdAt: Date;
|
|
89
|
+
updatedAt: Date;
|
|
90
|
+
}
|
|
91
|
+
export declare function listRunTemplates(client: Client, args: ListRunTemplatesArgs): Promise<ListRunTemplatesRow[]>;
|
|
92
|
+
export declare const updateRunTemplateQuery = "-- name: UpdateRunTemplate :one\nUPDATE atc.run_templates\nSET\n config = $1,\n security_context = $2,\n budget_context = $3,\n pinned_caller = $4,\n version = version + 1,\n updated_at = now()\nWHERE tenant_id = $5\n AND id = $6\nRETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at";
|
|
93
|
+
export interface UpdateRunTemplateArgs {
|
|
94
|
+
config: any;
|
|
95
|
+
securityContext: any | null;
|
|
96
|
+
budgetContext: any | null;
|
|
97
|
+
pinnedCaller: any | null;
|
|
98
|
+
tenantId: string;
|
|
99
|
+
id: string;
|
|
100
|
+
}
|
|
101
|
+
export interface UpdateRunTemplateRow {
|
|
102
|
+
id: string;
|
|
103
|
+
tenantId: string;
|
|
104
|
+
name: string;
|
|
105
|
+
version: number;
|
|
106
|
+
handlerType: string;
|
|
107
|
+
config: any;
|
|
108
|
+
securityContext: any | null;
|
|
109
|
+
budgetContext: any | null;
|
|
110
|
+
pinnedCaller: any | null;
|
|
111
|
+
createdBy: string;
|
|
112
|
+
createdAt: Date;
|
|
113
|
+
updatedAt: Date;
|
|
114
|
+
}
|
|
115
|
+
export declare function updateRunTemplate(client: Client, args: UpdateRunTemplateArgs): Promise<UpdateRunTemplateRow | null>;
|
|
116
|
+
export declare const deleteRunTemplateQuery = "-- name: DeleteRunTemplate :exec\nDELETE FROM atc.run_templates\nWHERE tenant_id = $1\n AND id = $2";
|
|
117
|
+
export interface DeleteRunTemplateArgs {
|
|
118
|
+
tenantId: string;
|
|
119
|
+
id: string;
|
|
120
|
+
}
|
|
121
|
+
export declare function deleteRunTemplate(client: Client, args: DeleteRunTemplateArgs): Promise<void>;
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteRunTemplateQuery = exports.updateRunTemplateQuery = exports.listRunTemplatesQuery = exports.getRunTemplateByNameQuery = exports.getRunTemplateQuery = exports.insertRunTemplateQuery = void 0;
|
|
4
|
+
exports.insertRunTemplate = insertRunTemplate;
|
|
5
|
+
exports.getRunTemplate = getRunTemplate;
|
|
6
|
+
exports.getRunTemplateByName = getRunTemplateByName;
|
|
7
|
+
exports.listRunTemplates = listRunTemplates;
|
|
8
|
+
exports.updateRunTemplate = updateRunTemplate;
|
|
9
|
+
exports.deleteRunTemplate = deleteRunTemplate;
|
|
10
|
+
exports.insertRunTemplateQuery = `-- name: InsertRunTemplate :one
|
|
11
|
+
INSERT INTO atc.run_templates (
|
|
12
|
+
id,
|
|
13
|
+
tenant_id,
|
|
14
|
+
name,
|
|
15
|
+
version,
|
|
16
|
+
handler_type,
|
|
17
|
+
config,
|
|
18
|
+
security_context,
|
|
19
|
+
budget_context,
|
|
20
|
+
pinned_caller,
|
|
21
|
+
created_by
|
|
22
|
+
) VALUES (
|
|
23
|
+
$1,
|
|
24
|
+
$2,
|
|
25
|
+
$3,
|
|
26
|
+
$4,
|
|
27
|
+
$5,
|
|
28
|
+
$6,
|
|
29
|
+
$7,
|
|
30
|
+
$8,
|
|
31
|
+
$9,
|
|
32
|
+
$10
|
|
33
|
+
)
|
|
34
|
+
RETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at`;
|
|
35
|
+
async function insertRunTemplate(client, args) {
|
|
36
|
+
const result = await client.query({
|
|
37
|
+
text: exports.insertRunTemplateQuery,
|
|
38
|
+
values: [args.id, args.tenantId, args.name, args.version, args.handlerType, args.config, args.securityContext, args.budgetContext, args.pinnedCaller, args.createdBy],
|
|
39
|
+
rowMode: "array"
|
|
40
|
+
});
|
|
41
|
+
if (result.rows.length !== 1) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const row = result.rows[0];
|
|
45
|
+
return {
|
|
46
|
+
id: row[0],
|
|
47
|
+
tenantId: row[1],
|
|
48
|
+
name: row[2],
|
|
49
|
+
version: row[3],
|
|
50
|
+
handlerType: row[4],
|
|
51
|
+
config: row[5],
|
|
52
|
+
securityContext: row[6],
|
|
53
|
+
budgetContext: row[7],
|
|
54
|
+
pinnedCaller: row[8],
|
|
55
|
+
createdBy: row[9],
|
|
56
|
+
createdAt: row[10],
|
|
57
|
+
updatedAt: row[11]
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
exports.getRunTemplateQuery = `-- name: GetRunTemplate :one
|
|
61
|
+
SELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at
|
|
62
|
+
FROM atc.run_templates
|
|
63
|
+
WHERE tenant_id = $1
|
|
64
|
+
AND id = $2`;
|
|
65
|
+
async function getRunTemplate(client, args) {
|
|
66
|
+
const result = await client.query({
|
|
67
|
+
text: exports.getRunTemplateQuery,
|
|
68
|
+
values: [args.tenantId, args.id],
|
|
69
|
+
rowMode: "array"
|
|
70
|
+
});
|
|
71
|
+
if (result.rows.length !== 1) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const row = result.rows[0];
|
|
75
|
+
return {
|
|
76
|
+
id: row[0],
|
|
77
|
+
tenantId: row[1],
|
|
78
|
+
name: row[2],
|
|
79
|
+
version: row[3],
|
|
80
|
+
handlerType: row[4],
|
|
81
|
+
config: row[5],
|
|
82
|
+
securityContext: row[6],
|
|
83
|
+
budgetContext: row[7],
|
|
84
|
+
pinnedCaller: row[8],
|
|
85
|
+
createdBy: row[9],
|
|
86
|
+
createdAt: row[10],
|
|
87
|
+
updatedAt: row[11]
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
exports.getRunTemplateByNameQuery = `-- name: GetRunTemplateByName :one
|
|
91
|
+
SELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at
|
|
92
|
+
FROM atc.run_templates
|
|
93
|
+
WHERE tenant_id = $1
|
|
94
|
+
AND name = $2
|
|
95
|
+
ORDER BY version DESC
|
|
96
|
+
LIMIT 1`;
|
|
97
|
+
async function getRunTemplateByName(client, args) {
|
|
98
|
+
const result = await client.query({
|
|
99
|
+
text: exports.getRunTemplateByNameQuery,
|
|
100
|
+
values: [args.tenantId, args.name],
|
|
101
|
+
rowMode: "array"
|
|
102
|
+
});
|
|
103
|
+
if (result.rows.length !== 1) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const row = result.rows[0];
|
|
107
|
+
return {
|
|
108
|
+
id: row[0],
|
|
109
|
+
tenantId: row[1],
|
|
110
|
+
name: row[2],
|
|
111
|
+
version: row[3],
|
|
112
|
+
handlerType: row[4],
|
|
113
|
+
config: row[5],
|
|
114
|
+
securityContext: row[6],
|
|
115
|
+
budgetContext: row[7],
|
|
116
|
+
pinnedCaller: row[8],
|
|
117
|
+
createdBy: row[9],
|
|
118
|
+
createdAt: row[10],
|
|
119
|
+
updatedAt: row[11]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
exports.listRunTemplatesQuery = `-- name: ListRunTemplates :many
|
|
123
|
+
SELECT id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at
|
|
124
|
+
FROM atc.run_templates
|
|
125
|
+
WHERE tenant_id = $1
|
|
126
|
+
ORDER BY name ASC, version DESC`;
|
|
127
|
+
async function listRunTemplates(client, args) {
|
|
128
|
+
const result = await client.query({
|
|
129
|
+
text: exports.listRunTemplatesQuery,
|
|
130
|
+
values: [args.tenantId],
|
|
131
|
+
rowMode: "array"
|
|
132
|
+
});
|
|
133
|
+
return result.rows.map(row => {
|
|
134
|
+
return {
|
|
135
|
+
id: row[0],
|
|
136
|
+
tenantId: row[1],
|
|
137
|
+
name: row[2],
|
|
138
|
+
version: row[3],
|
|
139
|
+
handlerType: row[4],
|
|
140
|
+
config: row[5],
|
|
141
|
+
securityContext: row[6],
|
|
142
|
+
budgetContext: row[7],
|
|
143
|
+
pinnedCaller: row[8],
|
|
144
|
+
createdBy: row[9],
|
|
145
|
+
createdAt: row[10],
|
|
146
|
+
updatedAt: row[11]
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
exports.updateRunTemplateQuery = `-- name: UpdateRunTemplate :one
|
|
151
|
+
UPDATE atc.run_templates
|
|
152
|
+
SET
|
|
153
|
+
config = $1,
|
|
154
|
+
security_context = $2,
|
|
155
|
+
budget_context = $3,
|
|
156
|
+
pinned_caller = $4,
|
|
157
|
+
version = version + 1,
|
|
158
|
+
updated_at = now()
|
|
159
|
+
WHERE tenant_id = $5
|
|
160
|
+
AND id = $6
|
|
161
|
+
RETURNING id, tenant_id, name, version, handler_type, config, security_context, budget_context, pinned_caller, created_by, created_at, updated_at`;
|
|
162
|
+
async function updateRunTemplate(client, args) {
|
|
163
|
+
const result = await client.query({
|
|
164
|
+
text: exports.updateRunTemplateQuery,
|
|
165
|
+
values: [args.config, args.securityContext, args.budgetContext, args.pinnedCaller, args.tenantId, args.id],
|
|
166
|
+
rowMode: "array"
|
|
167
|
+
});
|
|
168
|
+
if (result.rows.length !== 1) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const row = result.rows[0];
|
|
172
|
+
return {
|
|
173
|
+
id: row[0],
|
|
174
|
+
tenantId: row[1],
|
|
175
|
+
name: row[2],
|
|
176
|
+
version: row[3],
|
|
177
|
+
handlerType: row[4],
|
|
178
|
+
config: row[5],
|
|
179
|
+
securityContext: row[6],
|
|
180
|
+
budgetContext: row[7],
|
|
181
|
+
pinnedCaller: row[8],
|
|
182
|
+
createdBy: row[9],
|
|
183
|
+
createdAt: row[10],
|
|
184
|
+
updatedAt: row[11]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
exports.deleteRunTemplateQuery = `-- name: DeleteRunTemplate :exec
|
|
188
|
+
DELETE FROM atc.run_templates
|
|
189
|
+
WHERE tenant_id = $1
|
|
190
|
+
AND id = $2`;
|
|
191
|
+
async function deleteRunTemplate(client, args) {
|
|
192
|
+
await client.query({
|
|
193
|
+
text: exports.deleteRunTemplateQuery,
|
|
194
|
+
values: [args.tenantId, args.id],
|
|
195
|
+
rowMode: "array"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { QueryArrayConfig, QueryArrayResult } from "pg";
|
|
2
|
+
interface Client {
|
|
3
|
+
query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
|
|
4
|
+
}
|
|
5
|
+
export declare const upsertSnapshotQuery = "-- name: UpsertSnapshot :one\nINSERT INTO atc.event_snapshots (\n tenant_id,\n run_id,\n sequence,\n snapshot_type,\n data\n) VALUES (\n $1,\n $2,\n $3,\n $4,\n $5\n)\nON CONFLICT (tenant_id, run_id, snapshot_type)\nDO UPDATE\nSET\n sequence = CASE\n WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.sequence\n ELSE atc.event_snapshots.sequence\n END,\n data = CASE\n WHEN EXCLUDED.sequence > atc.event_snapshots.sequence THEN EXCLUDED.data\n ELSE atc.event_snapshots.data\n END\nRETURNING tenant_id, run_id, sequence, snapshot_type, data, created_at";
|
|
6
|
+
export interface UpsertSnapshotArgs {
|
|
7
|
+
tenantId: string;
|
|
8
|
+
runId: string;
|
|
9
|
+
sequence: string;
|
|
10
|
+
snapshotType: string;
|
|
11
|
+
data: any;
|
|
12
|
+
}
|
|
13
|
+
export interface UpsertSnapshotRow {
|
|
14
|
+
tenantId: string;
|
|
15
|
+
runId: string;
|
|
16
|
+
sequence: string;
|
|
17
|
+
snapshotType: string;
|
|
18
|
+
data: any;
|
|
19
|
+
createdAt: Date;
|
|
20
|
+
}
|
|
21
|
+
export declare function upsertSnapshot(client: Client, args: UpsertSnapshotArgs): Promise<UpsertSnapshotRow | null>;
|
|
22
|
+
export declare const loadSnapshotQuery = "-- name: LoadSnapshot :one\nSELECT\n tenant_id,\n run_id,\n sequence,\n snapshot_type,\n data,\n created_at\nFROM atc.event_snapshots\nWHERE tenant_id = $1\n AND run_id = $2\n AND snapshot_type = $3";
|
|
23
|
+
export interface LoadSnapshotArgs {
|
|
24
|
+
tenantId: string;
|
|
25
|
+
runId: string;
|
|
26
|
+
snapshotType: string;
|
|
27
|
+
}
|
|
28
|
+
export interface LoadSnapshotRow {
|
|
29
|
+
tenantId: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
sequence: string;
|
|
32
|
+
snapshotType: string;
|
|
33
|
+
data: any;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
}
|
|
36
|
+
export declare function loadSnapshot(client: Client, args: LoadSnapshotArgs): Promise<LoadSnapshotRow | null>;
|
|
37
|
+
export declare const deleteSnapshotQuery = "-- name: DeleteSnapshot :exec\nDELETE FROM atc.event_snapshots\nWHERE tenant_id = $1\n AND run_id = $2\n AND snapshot_type = $3";
|
|
38
|
+
export interface DeleteSnapshotArgs {
|
|
39
|
+
tenantId: string;
|
|
40
|
+
runId: string;
|
|
41
|
+
snapshotType: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function deleteSnapshot(client: Client, args: DeleteSnapshotArgs): Promise<void>;
|
|
44
|
+
export declare const listRunSnapshotsQuery = "-- name: ListRunSnapshots :many\nSELECT\n tenant_id,\n run_id,\n sequence,\n snapshot_type,\n data,\n created_at\nFROM atc.event_snapshots\nWHERE tenant_id = $1\n AND run_id = $2\nORDER BY snapshot_type ASC";
|
|
45
|
+
export interface ListRunSnapshotsArgs {
|
|
46
|
+
tenantId: string;
|
|
47
|
+
runId: string;
|
|
48
|
+
}
|
|
49
|
+
export interface ListRunSnapshotsRow {
|
|
50
|
+
tenantId: string;
|
|
51
|
+
runId: string;
|
|
52
|
+
sequence: string;
|
|
53
|
+
snapshotType: string;
|
|
54
|
+
data: any;
|
|
55
|
+
createdAt: Date;
|
|
56
|
+
}
|
|
57
|
+
export declare function listRunSnapshots(client: Client, args: ListRunSnapshotsArgs): Promise<ListRunSnapshotsRow[]>;
|
|
58
|
+
export {};
|